├── .gitignore ├── Appendix01 └── images │ ├── 127.0.0.1 - Google Chrome_060.png │ ├── ALGOBULLS - Kite Connect developer - Google Chrome_056.png │ ├── Authorize Kite - Kite - Google Chrome_059.png │ ├── Billing - Kite Connect developer - Google Chrome_053.png │ ├── Create a new app - Kite Connect developer - Google Chrome_052.png │ ├── Dashboard - Kite - Google Chrome_047.png │ ├── Kite - Zerodha's fast and elegant flagship trading platform - Google Chrome_045.png │ ├── Kite - Zerodha's fast and elegant flagship trading platform - Google Chrome_046.png │ ├── Kite - Zerodha's fast and elegant flagship trading platform - Google Chrome_057.png │ ├── Kite - Zerodha's fast and elegant flagship trading platform - Google Chrome_058.png │ ├── Kite Connect – REST-like HTTP trading APIs for individual traders and startups - Google Chrome_048.png │ ├── Kite Connect – REST-like HTTP trading APIs for individual traders and startups - Google Chrome_068 (copy).png │ ├── Kite Connect – REST-like HTTP trading APIs for individual traders and startups - Google Chrome_068.png │ ├── Login - Kite Connect developer - Google Chrome_069.png │ ├── My apps - Kite Connect developer - Billing.png │ ├── My apps - Kite Connect developer - Google Chrome_054.png │ ├── My apps - Kite Connect developer - Google Chrome_055.png │ ├── My apps - Kite Connect developer - Google Chrome_070.png │ ├── Opening a Zerodha account online - YouTube - Google Chrome_044.png │ ├── Signup - Kite Connect developer - Google Chrome_049.png │ ├── hist data not activated.png │ └── old.png ├── Appendix02 └── images │ ├── AlgoBulls | An Algorithmic Trading Platform with Social Trading - Google Chrome_067 (copy 1).png │ ├── AlgoBulls | An Algorithmic Trading Platform with Social Trading - Google Chrome_067.png │ ├── Broking - AlgoBulls - Google Chrome_071.png │ ├── Broking - AlgoBulls - Google Chrome_076.png │ ├── Broking - AlgoBulls - Google Chrome_076v2.png │ ├── Broking - AlgoBulls - Google Chrome_076v3.png │ ├── Broking - AlgoBulls - Google Chrome_077.png │ ├── Broking - AlgoBulls - Google Chrome_079.png │ ├── Broking - AlgoBulls - Google Chrome_080.png │ ├── General - AlgoBulls - Google Chrome_066.png │ ├── Login - AlgoBulls - Google Chrome_061.png │ ├── Register - AlgoBulls - Google Chrome_062.png │ ├── Register - AlgoBulls - Google Chrome_063.png │ ├── Register - AlgoBulls - Google Chrome_064.png │ ├── Register - AlgoBulls - Google Chrome_065.png │ ├── https:--devel.appv2.algobulls.com-account-broking - Google Chrome_082.png │ ├── https:--devel.appv2.algobulls.com-account-broking - Google Chrome_082v2.png │ └── sms.jpg ├── Chapter01 ├── CHAPTER 1.ipynb ├── README.md └── requirements.txt ├── Chapter02 ├── CHAPTER 2.ipynb ├── README.md └── requirements.txt ├── Chapter03 ├── CHAPTER 3.ipynb ├── README.md └── requirements.txt ├── Chapter04 ├── CHAPTER 4.ipynb ├── README.md ├── images │ ├── convert_image_pdf_to_png.sh │ ├── pdf │ │ ├── 1.pdf │ │ ├── 10.pdf │ │ ├── 11.pdf │ │ ├── 12.pdf │ │ ├── 13.pdf │ │ ├── 14.pdf │ │ ├── 15.pdf │ │ ├── 16.pdf │ │ ├── 17.pdf │ │ ├── 18.pdf │ │ ├── 19.pdf │ │ ├── 2.pdf │ │ ├── 20.pdf │ │ ├── 21.pdf │ │ ├── 22.pdf │ │ ├── 23.pdf │ │ ├── 24.pdf │ │ ├── 25.pdf │ │ ├── 26.pdf │ │ ├── 27.pdf │ │ ├── 28.pdf │ │ ├── 29.pdf │ │ ├── 3.pdf │ │ ├── 30.pdf │ │ ├── 31.pdf │ │ ├── 32.pdf │ │ ├── 33.pdf │ │ ├── 34.pdf │ │ ├── 35.pdf │ │ ├── 36.pdf │ │ ├── 37.pdf │ │ ├── 38.pdf │ │ ├── 39.pdf │ │ ├── 4.pdf │ │ ├── 40.pdf │ │ ├── 41.pdf │ │ ├── 42.pdf │ │ ├── 43.pdf │ │ ├── 44.pdf │ │ ├── 45.pdf │ │ ├── 46.pdf │ │ ├── 47.pdf │ │ ├── 48.pdf │ │ ├── 5.pdf │ │ ├── 6.pdf │ │ ├── 7.pdf │ │ ├── 8.pdf │ │ └── 9.pdf │ └── png │ │ ├── 1.pdf.png │ │ ├── 10.pdf.png │ │ ├── 11.pdf.png │ │ ├── 12.pdf.png │ │ ├── 13.pdf.png │ │ ├── 14.pdf.png │ │ ├── 15.pdf.png │ │ ├── 16.pdf.png │ │ ├── 17.pdf.png │ │ ├── 18.pdf.png │ │ ├── 19.pdf.png │ │ ├── 2.pdf.png │ │ ├── 20.pdf.png │ │ ├── 21.pdf.png │ │ ├── 22.pdf.png │ │ ├── 23.pdf.png │ │ ├── 24.pdf.png │ │ ├── 25.pdf.png │ │ ├── 26.pdf.png │ │ ├── 27.pdf.png │ │ ├── 28.pdf.png │ │ ├── 29.pdf.png │ │ ├── 3.pdf.png │ │ ├── 30.pdf.png │ │ ├── 31.pdf.png │ │ ├── 32.pdf.png │ │ ├── 33.pdf.png │ │ ├── 34.pdf.png │ │ ├── 35.pdf.png │ │ ├── 36.pdf.png │ │ ├── 37.pdf.png │ │ ├── 38.pdf.png │ │ ├── 39.pdf.png │ │ ├── 4.pdf.png │ │ ├── 40.pdf.png │ │ ├── 41.pdf.png │ │ ├── 42.pdf.png │ │ ├── 43.pdf.png │ │ ├── 44.pdf.png │ │ ├── 45.pdf.png │ │ ├── 46.pdf.png │ │ ├── 47.pdf.png │ │ ├── 48.pdf.png │ │ ├── 5.pdf.png │ │ ├── 6.pdf.png │ │ ├── 7.pdf.png │ │ ├── 8.pdf.png │ │ └── 9.pdf.png └── requirements.txt ├── Chapter05 ├── CHAPTER 5.ipynb ├── README.md ├── images │ ├── convert_image_pdf_to_png.sh │ ├── pdf │ │ ├── 1.pdf │ │ ├── 10.pdf │ │ ├── 2.pdf │ │ ├── 3.pdf │ │ ├── 4.pdf │ │ ├── 5.pdf │ │ ├── 6.pdf │ │ ├── 7.pdf │ │ ├── 8.pdf │ │ └── 9.pdf │ └── png │ │ ├── 1.png │ │ ├── 10.png │ │ ├── 2.png │ │ ├── 3.png │ │ ├── 4.png │ │ ├── 5.png │ │ ├── 6.png │ │ ├── 7.png │ │ ├── 8.png │ │ └── 9.png └── requirements.txt ├── Chapter06 ├── CHAPTER 6.ipynb ├── README.md ├── images │ ├── diagrams │ │ ├── bracket-order-flowchart.dia │ │ ├── bracket-order-flowchart.png │ │ ├── cover-order-flowchart.dia │ │ ├── cover-order-flowchart.png │ │ ├── regular-limit-order-state-diagram.dia │ │ ├── regular-limit-order-state-diagram.png │ │ ├── regular-limit-order-state-diagram2.png │ │ ├── regular-market-order-state-diagram.dia │ │ ├── regular-market-order-state-diagram.png │ │ ├── regular-stoploss-limit-order-state-diagram.dia │ │ ├── regular-stoploss-limit-order-state-diagram.png │ │ ├── regular-stoploss-market-order-state-diagram.dia │ │ └── regular-stoploss-market-order-state-diagram.png │ ├── screenshots │ │ ├── recipe10_child1_open.png │ │ ├── recipe10_order1_open.png │ │ ├── recipe10_order2_complete.png │ │ ├── recipe10_order2_open.png │ │ ├── recipe1_order1_complete.png │ │ ├── recipe1_order2_complete.png │ │ ├── recipe1_order3_complete.png │ │ ├── recipe1_order4_complete.png │ │ ├── recipe2_order1_complete.png │ │ ├── recipe2_order1_open.png │ │ ├── recipe2_order2_complete.png │ │ ├── recipe2_order2_open.png │ │ ├── recipe2_order3_complete.png │ │ ├── recipe2_order3_open.png │ │ ├── recipe2_order4_complete.png │ │ ├── recipe2_order4_open.png │ │ ├── recipe3_order1_complete.png │ │ ├── recipe3_order1_trigger_pending.png │ │ ├── recipe3_order2_complete.png │ │ ├── recipe3_order2_trigger_pending.png │ │ ├── recipe3_order3_complete.png │ │ ├── recipe3_order3_trigger_pending.png │ │ ├── recipe3_order4_complete.png │ │ ├── recipe4_order1_complete.png │ │ ├── recipe4_order1_trigger_pending.png │ │ ├── recipe4_order1_trigger_pending_old.png │ │ ├── recipe4_order2_complete.png │ │ ├── recipe4_order2_trigger_pending.png │ │ ├── recipe4_order3_complete.png │ │ ├── recipe4_order3_complete_old.png │ │ ├── recipe4_order3_trigger_pending.png │ │ ├── recipe4_order3_trigger_pending_old.png │ │ ├── recipe4_order4_compelte.png │ │ ├── recipe4_order4_trigger_pending.png │ │ ├── recipe5_order1_child1_cancelled_on_exit.png │ │ ├── recipe5_order1_child1_open.png │ │ ├── recipe5_order1_child2_complete_on_exit.png │ │ ├── recipe5_order1_child2_open.png │ │ ├── recipe5_order1_complete.png │ │ ├── recipe5_order1_open.png │ │ ├── recipe5_order2_complete.png │ │ ├── recipe5_order2_open.png │ │ ├── recipe9_order1_child1_open.png │ │ ├── recipe9_order1_child1_trigger_pending.png │ │ ├── recipe9_order1_complete.png │ │ ├── recipe9_order1_open.png │ │ ├── recipe9_order2_child1_trigger_pending.png │ │ └── recipe9_order2_complete.png │ └── unsorted │ │ ├── bankbaroda │ │ ├── Selection_035.png │ │ ├── Selection_045.png │ │ ├── Selection_046.png │ │ └── Selection_047.png │ │ ├── icicibank │ │ └── Selection_034.png │ │ ├── kotak │ │ └── recipe4_order3_trigger_pending.png │ │ └── sbin │ │ ├── Selection_041.png │ │ ├── Selection_042.png │ │ ├── Selection_043.png │ │ ├── Selection_044.png │ │ └── recipe5_order2_complete.png └── requirements.txt ├── Chapter07 ├── CHAPTER 7.ipynb ├── README.md └── requirements.txt ├── Chapter08 ├── CHAPTER 8.ipynb ├── README.md ├── images │ └── diagrams │ │ ├── strategy_execution_flowchart.dia │ │ └── strategy_execution_flowchart.png └── requirements.txt ├── Chapter09 ├── CHAPTER 9.ipynb ├── README.md ├── images │ └── diagrams │ │ ├── abc-job-status-state-diagram.dia │ │ └── abc-job-status-state-diagram.png └── requirements.txt ├── Chapter10 ├── CHAPTER 10.ipynb ├── README.md ├── images │ └── diagrams │ │ ├── abc-job-status-state-diagram.dia │ │ └── abc-job-status-state-diagram.png └── requirements.txt ├── Chapter11 ├── CHAPTER 11.ipynb ├── README.md ├── images │ └── diagrams │ │ ├── abc-job-status-state-diagram.dia │ │ └── abc-job-status-state-diagram.png └── requirements.txt ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | */.ipynb_checkpoints/* 2 | virtualenv/ 3 | .idea/ 4 | -------------------------------------------------------------------------------- /Appendix01/images/127.0.0.1 - Google Chrome_060.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix01/images/127.0.0.1 - Google Chrome_060.png -------------------------------------------------------------------------------- /Appendix01/images/ALGOBULLS - Kite Connect developer - Google Chrome_056.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix01/images/ALGOBULLS - Kite Connect developer - Google Chrome_056.png -------------------------------------------------------------------------------- /Appendix01/images/Authorize Kite - Kite - Google Chrome_059.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix01/images/Authorize Kite - Kite - Google Chrome_059.png -------------------------------------------------------------------------------- /Appendix01/images/Billing - Kite Connect developer - Google Chrome_053.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix01/images/Billing - Kite Connect developer - Google Chrome_053.png -------------------------------------------------------------------------------- /Appendix01/images/Create a new app - Kite Connect developer - Google Chrome_052.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix01/images/Create a new app - Kite Connect developer - Google Chrome_052.png -------------------------------------------------------------------------------- /Appendix01/images/Dashboard - Kite - Google Chrome_047.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix01/images/Dashboard - Kite - Google Chrome_047.png -------------------------------------------------------------------------------- /Appendix01/images/Kite - Zerodha's fast and elegant flagship trading platform - Google Chrome_045.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix01/images/Kite - Zerodha's fast and elegant flagship trading platform - Google Chrome_045.png -------------------------------------------------------------------------------- /Appendix01/images/Kite - Zerodha's fast and elegant flagship trading platform - Google Chrome_046.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix01/images/Kite - Zerodha's fast and elegant flagship trading platform - Google Chrome_046.png -------------------------------------------------------------------------------- /Appendix01/images/Kite - Zerodha's fast and elegant flagship trading platform - Google Chrome_057.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix01/images/Kite - Zerodha's fast and elegant flagship trading platform - Google Chrome_057.png -------------------------------------------------------------------------------- /Appendix01/images/Kite - Zerodha's fast and elegant flagship trading platform - Google Chrome_058.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix01/images/Kite - Zerodha's fast and elegant flagship trading platform - Google Chrome_058.png -------------------------------------------------------------------------------- /Appendix01/images/Kite Connect – REST-like HTTP trading APIs for individual traders and startups - Google Chrome_048.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix01/images/Kite Connect – REST-like HTTP trading APIs for individual traders and startups - Google Chrome_048.png -------------------------------------------------------------------------------- /Appendix01/images/Kite Connect – REST-like HTTP trading APIs for individual traders and startups - Google Chrome_068 (copy).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix01/images/Kite Connect – REST-like HTTP trading APIs for individual traders and startups - Google Chrome_068 (copy).png -------------------------------------------------------------------------------- /Appendix01/images/Kite Connect – REST-like HTTP trading APIs for individual traders and startups - Google Chrome_068.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix01/images/Kite Connect – REST-like HTTP trading APIs for individual traders and startups - Google Chrome_068.png -------------------------------------------------------------------------------- /Appendix01/images/Login - Kite Connect developer - Google Chrome_069.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix01/images/Login - Kite Connect developer - Google Chrome_069.png -------------------------------------------------------------------------------- /Appendix01/images/My apps - Kite Connect developer - Billing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix01/images/My apps - Kite Connect developer - Billing.png -------------------------------------------------------------------------------- /Appendix01/images/My apps - Kite Connect developer - Google Chrome_054.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix01/images/My apps - Kite Connect developer - Google Chrome_054.png -------------------------------------------------------------------------------- /Appendix01/images/My apps - Kite Connect developer - Google Chrome_055.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix01/images/My apps - Kite Connect developer - Google Chrome_055.png -------------------------------------------------------------------------------- /Appendix01/images/My apps - Kite Connect developer - Google Chrome_070.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix01/images/My apps - Kite Connect developer - Google Chrome_070.png -------------------------------------------------------------------------------- /Appendix01/images/Opening a Zerodha account online - YouTube - Google Chrome_044.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix01/images/Opening a Zerodha account online - YouTube - Google Chrome_044.png -------------------------------------------------------------------------------- /Appendix01/images/Signup - Kite Connect developer - Google Chrome_049.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix01/images/Signup - Kite Connect developer - Google Chrome_049.png -------------------------------------------------------------------------------- /Appendix01/images/hist data not activated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix01/images/hist data not activated.png -------------------------------------------------------------------------------- /Appendix01/images/old.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix01/images/old.png -------------------------------------------------------------------------------- /Appendix02/images/AlgoBulls | An Algorithmic Trading Platform with Social Trading - Google Chrome_067 (copy 1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix02/images/AlgoBulls | An Algorithmic Trading Platform with Social Trading - Google Chrome_067 (copy 1).png -------------------------------------------------------------------------------- /Appendix02/images/AlgoBulls | An Algorithmic Trading Platform with Social Trading - Google Chrome_067.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix02/images/AlgoBulls | An Algorithmic Trading Platform with Social Trading - Google Chrome_067.png -------------------------------------------------------------------------------- /Appendix02/images/Broking - AlgoBulls - Google Chrome_071.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix02/images/Broking - AlgoBulls - Google Chrome_071.png -------------------------------------------------------------------------------- /Appendix02/images/Broking - AlgoBulls - Google Chrome_076.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix02/images/Broking - AlgoBulls - Google Chrome_076.png -------------------------------------------------------------------------------- /Appendix02/images/Broking - AlgoBulls - Google Chrome_076v2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix02/images/Broking - AlgoBulls - Google Chrome_076v2.png -------------------------------------------------------------------------------- /Appendix02/images/Broking - AlgoBulls - Google Chrome_076v3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix02/images/Broking - AlgoBulls - Google Chrome_076v3.png -------------------------------------------------------------------------------- /Appendix02/images/Broking - AlgoBulls - Google Chrome_077.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix02/images/Broking - AlgoBulls - Google Chrome_077.png -------------------------------------------------------------------------------- /Appendix02/images/Broking - AlgoBulls - Google Chrome_079.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix02/images/Broking - AlgoBulls - Google Chrome_079.png -------------------------------------------------------------------------------- /Appendix02/images/Broking - AlgoBulls - Google Chrome_080.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix02/images/Broking - AlgoBulls - Google Chrome_080.png -------------------------------------------------------------------------------- /Appendix02/images/General - AlgoBulls - Google Chrome_066.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix02/images/General - AlgoBulls - Google Chrome_066.png -------------------------------------------------------------------------------- /Appendix02/images/Login - AlgoBulls - Google Chrome_061.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix02/images/Login - AlgoBulls - Google Chrome_061.png -------------------------------------------------------------------------------- /Appendix02/images/Register - AlgoBulls - Google Chrome_062.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix02/images/Register - AlgoBulls - Google Chrome_062.png -------------------------------------------------------------------------------- /Appendix02/images/Register - AlgoBulls - Google Chrome_063.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix02/images/Register - AlgoBulls - Google Chrome_063.png -------------------------------------------------------------------------------- /Appendix02/images/Register - AlgoBulls - Google Chrome_064.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix02/images/Register - AlgoBulls - Google Chrome_064.png -------------------------------------------------------------------------------- /Appendix02/images/Register - AlgoBulls - Google Chrome_065.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix02/images/Register - AlgoBulls - Google Chrome_065.png -------------------------------------------------------------------------------- /Appendix02/images/https:--devel.appv2.algobulls.com-account-broking - Google Chrome_082.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix02/images/https:--devel.appv2.algobulls.com-account-broking - Google Chrome_082.png -------------------------------------------------------------------------------- /Appendix02/images/https:--devel.appv2.algobulls.com-account-broking - Google Chrome_082v2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix02/images/https:--devel.appv2.algobulls.com-account-broking - Google Chrome_082v2.png -------------------------------------------------------------------------------- /Appendix02/images/sms.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Appendix02/images/sms.jpg -------------------------------------------------------------------------------- /Chapter01/README.md: -------------------------------------------------------------------------------- 1 | ### Chapter 1: Handling and Manipulating Date, Time, and Time Series Data 2 | Learn everything about the Python DateTime module and Pandas DataFrames required 3 | to handle time series data efficiently. 4 | 5 | ### List of Recipes in this chapter 6 | 1. Creating datetime objects 7 | 2. Creating timedelta objects 8 | 3. Operations on datetime objects 9 | 4. Modifying datetime objects 10 | 5. Converting a datetime object to a string 11 | 6. Creating a datetime object from a string 12 | 7. The datetime object and time zones 13 | 8. Creating a pandas.DataFrame object 14 | 9. DataFrame manipulation: renaming, rearranging, reversing, and slicing 15 | 10. DataFrame manipulation: applying, sorting, iterating and concatenating 16 | 11. Converting a DataFrame into other formats 17 | 12. Creating a DataFrame from other formats 18 | 19 | *[**[Click here to VIEW Chapter 1 Jupyter Notebook on nbviewer](https://nbviewer.jupyter.org/github/PacktPublishing/Python-Algorithmic-Trading-Cookbook/blob/master/Chapter01/CHAPTER%201.ipynb)**]* 20 |
21 | *[**[Click here to RUN Chapter 1 Jupyter Notebook in the cloud using binder. No installation needed on your end.](https://mybinder.org/v2/gh/PacktPublishing/Python-Algorithmic-Trading-Cookbook/master?filepath=Chapter01/CHAPTER%201.ipynb)**]* 22 | 23 | ### Requirements 24 | - Python 3.7+ 25 | - Additional Python Packages required for this chapter can be installed as follows - 26 | 27 | ``` 28 | $ source # optional, if you use a virtualenv 29 | $ cd 30 | $ pip install -r requirements.txt 31 | ``` -------------------------------------------------------------------------------- /Chapter01/requirements.txt: -------------------------------------------------------------------------------- 1 | pandas 2 | -------------------------------------------------------------------------------- /Chapter02/CHAPTER 2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Python Algorithmic Trading Cookbook" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Chapter 2: Stock Markets: Primer on Trading" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "This Jupyter Notebook is created using Python version 3.8.2" 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "----" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "### Requirements" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "You can install the requirements for this Jupyter Notebook by executing the below cell" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 0, 48 | "metadata": {}, 49 | "outputs": [], 50 | "source": [ 51 | "!pip install pyalgotrading" 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": {}, 57 | "source": [ 58 | "----" 59 | ] 60 | }, 61 | { 62 | "cell_type": "markdown", 63 | "metadata": {}, 64 | "source": [ 65 | "### Recipe 1: Setup Python connectivity with Broker" 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": 1, 71 | "metadata": {}, 72 | "outputs": [], 73 | "source": [ 74 | "from pyalgotrading.broker.broker_connection_zerodha import BrokerConnectionZerodha" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": 2, 80 | "metadata": {}, 81 | "outputs": [ 82 | { 83 | "name": "stdout", 84 | "output_type": "stream", 85 | "text": [ 86 | "Installing package kiteconnect via pip...\n", 87 | "Please login to this link to generate your request token: https://kite.trade/connect/login?api_key=&v=3\n" 88 | ] 89 | } 90 | ], 91 | "source": [ 92 | "# Get the api_key & api_secret from broker. These are unique to you & will be used by the broker to identify your demat account.\n", 93 | "api_key = \"\"\n", 94 | "api_secret = \"\"\n", 95 | "broker_connection = BrokerConnectionZerodha(api_key, api_secret)" 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": 3, 101 | "metadata": {}, 102 | "outputs": [], 103 | "source": [ 104 | "# Get the request token from the above URL\n", 105 | "request_token = \"\"\n", 106 | "broker_connection.set_access_token(request_token)" 107 | ] 108 | }, 109 | { 110 | "cell_type": "markdown", 111 | "metadata": {}, 112 | "source": [ 113 | "### Recipe 2: Query list of Instruments" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": 4, 119 | "metadata": {}, 120 | "outputs": [ 121 | { 122 | "data": { 123 | "text/html": [ 124 | "
\n", 125 | "\n", 138 | "\n", 139 | " \n", 140 | " \n", 141 | " \n", 142 | " \n", 143 | " \n", 144 | " \n", 145 | " \n", 146 | " \n", 147 | " \n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | " \n", 158 | " \n", 159 | " \n", 160 | " \n", 161 | " \n", 162 | " \n", 163 | " \n", 164 | " \n", 165 | " \n", 166 | " \n", 167 | " \n", 168 | " \n", 169 | " \n", 170 | " \n", 171 | " \n", 172 | " \n", 173 | " \n", 174 | " \n", 175 | " \n", 176 | " \n", 177 | " \n", 178 | " \n", 179 | " \n", 180 | " \n", 181 | " \n", 182 | " \n", 183 | " \n", 184 | " \n", 185 | " \n", 186 | " \n", 187 | " \n", 188 | " \n", 189 | " \n", 190 | " \n", 191 | " \n", 192 | " \n", 193 | " \n", 194 | " \n", 195 | " \n", 196 | " \n", 197 | " \n", 198 | " \n", 199 | " \n", 200 | " \n", 201 | " \n", 202 | " \n", 203 | " \n", 204 | " \n", 205 | " \n", 206 | " \n", 207 | " \n", 208 | " \n", 209 | " \n", 210 | " \n", 211 | " \n", 212 | " \n", 213 | " \n", 214 | " \n", 215 | " \n", 216 | " \n", 217 | " \n", 218 | " \n", 219 | " \n", 220 | " \n", 221 | " \n", 222 | " \n", 223 | " \n", 224 | " \n", 225 | " \n", 226 | " \n", 227 | " \n", 228 | " \n", 229 | " \n", 230 | " \n", 231 | " \n", 232 | " \n", 233 | " \n", 234 | " \n", 235 | " \n", 236 | " \n", 237 | " \n", 238 | " \n", 239 | " \n", 240 | " \n", 241 | " \n", 242 | " \n", 243 | " \n", 244 | " \n", 245 | " \n", 246 | " \n", 247 | " \n", 248 | " \n", 249 | " \n", 250 | " \n", 251 | " \n", 252 | " \n", 253 | " \n", 254 | " \n", 255 | " \n", 256 | " \n", 257 | " \n", 258 | " \n", 259 | " \n", 260 | " \n", 261 | " \n", 262 | " \n", 263 | " \n", 264 | " \n", 265 | " \n", 266 | " \n", 267 | " \n", 268 | " \n", 269 | " \n", 270 | " \n", 271 | " \n", 272 | " \n", 273 | " \n", 274 | " \n", 275 | " \n", 276 | " \n", 277 | " \n", 278 | " \n", 279 | " \n", 280 | " \n", 281 | " \n", 282 | " \n", 283 | " \n", 284 | " \n", 285 | " \n", 286 | " \n", 287 | " \n", 288 | " \n", 289 | " \n", 290 | " \n", 291 | " \n", 292 | " \n", 293 | " \n", 294 | " \n", 295 | " \n", 296 | " \n", 297 | " \n", 298 | " \n", 299 | " \n", 300 | " \n", 301 | " \n", 302 | " \n", 303 | " \n", 304 | " \n", 305 | " \n", 306 | " \n", 307 | " \n", 308 | " \n", 309 | " \n", 310 | " \n", 311 | " \n", 312 | " \n", 313 | " \n", 314 | " \n", 315 | " \n", 316 | " \n", 317 | " \n", 318 | " \n", 319 | " \n", 320 | " \n", 321 | " \n", 322 | " \n", 323 | "
instrument_tokenexchange_tokentradingsymbolnamelast_priceexpirystriketick_sizelot_sizeinstrument_typesegmentexchange
05405849662111660EURINR20DEC77.7500CEEURINR0.02020-12-2977.750.00251CEBCD-OPTBCD
15405788222111636EURINR20DEC77.7500PEEURINR0.02020-12-2977.750.00251PEBCD-OPTBCD
25405127742111378EURINR20DEC78.0000CEEURINR0.02020-12-2978.000.00251CEBCD-OPTBCD
35405063742111353EURINR20DEC78.0000PEEURINR0.02020-12-2978.000.00251PEBCD-OPTBCD
45406274622111826EURINR20DEC78.2500CEEURINR0.02020-12-2978.250.00251CEBCD-OPTBCD
.......................................
653929789453824ZODJRDMKJZODIAC JRD-MKJ0.00.000.05001EQNSENSE
65393291686511394ZOTAZOTA HEALTH CARE0.00.000.05001EQNSENSE
65394743782529054ZUARI-BEZUARI AGRO CHEMICALS0.00.000.05001EQNSENSE
653959797133827ZUARIGLOBZUARI GLOBAL0.00.000.05001EQNSENSE
65396451456117635ZYDUSWELLZYDUS WELLNESS0.00.000.05001EQNSENSE
\n", 324 | "

65397 rows × 12 columns

\n", 325 | "
" 326 | ], 327 | "text/plain": [ 328 | " instrument_token exchange_token tradingsymbol \\\n", 329 | "0 540584966 2111660 EURINR20DEC77.7500CE \n", 330 | "1 540578822 2111636 EURINR20DEC77.7500PE \n", 331 | "2 540512774 2111378 EURINR20DEC78.0000CE \n", 332 | "3 540506374 2111353 EURINR20DEC78.0000PE \n", 333 | "4 540627462 2111826 EURINR20DEC78.2500CE \n", 334 | "... ... ... ... \n", 335 | "65392 978945 3824 ZODJRDMKJ \n", 336 | "65393 2916865 11394 ZOTA \n", 337 | "65394 7437825 29054 ZUARI-BE \n", 338 | "65395 979713 3827 ZUARIGLOB \n", 339 | "65396 4514561 17635 ZYDUSWELL \n", 340 | "\n", 341 | " name last_price expiry strike tick_size \\\n", 342 | "0 EURINR 0.0 2020-12-29 77.75 0.0025 \n", 343 | "1 EURINR 0.0 2020-12-29 77.75 0.0025 \n", 344 | "2 EURINR 0.0 2020-12-29 78.00 0.0025 \n", 345 | "3 EURINR 0.0 2020-12-29 78.00 0.0025 \n", 346 | "4 EURINR 0.0 2020-12-29 78.25 0.0025 \n", 347 | "... ... ... ... ... ... \n", 348 | "65392 ZODIAC JRD-MKJ 0.0 0.00 0.0500 \n", 349 | "65393 ZOTA HEALTH CARE 0.0 0.00 0.0500 \n", 350 | "65394 ZUARI AGRO CHEMICALS 0.0 0.00 0.0500 \n", 351 | "65395 ZUARI GLOBAL 0.0 0.00 0.0500 \n", 352 | "65396 ZYDUS WELLNESS 0.0 0.00 0.0500 \n", 353 | "\n", 354 | " lot_size instrument_type segment exchange \n", 355 | "0 1 CE BCD-OPT BCD \n", 356 | "1 1 PE BCD-OPT BCD \n", 357 | "2 1 CE BCD-OPT BCD \n", 358 | "3 1 PE BCD-OPT BCD \n", 359 | "4 1 CE BCD-OPT BCD \n", 360 | "... ... ... ... ... \n", 361 | "65392 1 EQ NSE NSE \n", 362 | "65393 1 EQ NSE NSE \n", 363 | "65394 1 EQ NSE NSE \n", 364 | "65395 1 EQ NSE NSE \n", 365 | "65396 1 EQ NSE NSE \n", 366 | "\n", 367 | "[65397 rows x 12 columns]" 368 | ] 369 | }, 370 | "execution_count": 4, 371 | "metadata": {}, 372 | "output_type": "execute_result" 373 | } 374 | ], 375 | "source": [ 376 | "instruments = broker_connection.get_all_instruments()\n", 377 | "instruments" 378 | ] 379 | }, 380 | { 381 | "cell_type": "code", 382 | "execution_count": 5, 383 | "metadata": {}, 384 | "outputs": [ 385 | { 386 | "name": "stdout", 387 | "output_type": "stream", 388 | "text": [ 389 | "Total instruments: 65397\n" 390 | ] 391 | } 392 | ], 393 | "source": [ 394 | "print(f'Total instruments: {len(instruments)}')" 395 | ] 396 | }, 397 | { 398 | "cell_type": "markdown", 399 | "metadata": {}, 400 | "source": [ 401 | "### Recipe 3: Fetch an Instrument" 402 | ] 403 | }, 404 | { 405 | "cell_type": "code", 406 | "execution_count": 6, 407 | "metadata": {}, 408 | "outputs": [ 409 | { 410 | "data": { 411 | "text/plain": [ 412 | "segment: NSE\n", 413 | "exchange: NSE\n", 414 | "tradingsymbol: TATASTEEL\n", 415 | "broker_token: 895745\n", 416 | "tick_size: 0.05\n", 417 | "lot_size: 1\n", 418 | "expiry: \n", 419 | "strike_price: 0.0" 420 | ] 421 | }, 422 | "execution_count": 6, 423 | "metadata": {}, 424 | "output_type": "execute_result" 425 | } 426 | ], 427 | "source": [ 428 | "broker_connection.get_instrument(segment='NSE', tradingsymbol='TATASTEEL')" 429 | ] 430 | }, 431 | { 432 | "cell_type": "markdown", 433 | "metadata": {}, 434 | "source": [ 435 | "### Recipe 4: Query list of Exchanges" 436 | ] 437 | }, 438 | { 439 | "cell_type": "code", 440 | "execution_count": 7, 441 | "metadata": {}, 442 | "outputs": [ 443 | { 444 | "name": "stdout", 445 | "output_type": "stream", 446 | "text": [ 447 | "['BCD' 'BSE' 'NSE' 'CDS' 'MCX' 'NFO']\n" 448 | ] 449 | } 450 | ], 451 | "source": [ 452 | "exchanges = instruments.exchange.unique()\n", 453 | "print(exchanges)" 454 | ] 455 | }, 456 | { 457 | "cell_type": "markdown", 458 | "metadata": {}, 459 | "source": [ 460 | "### Recipe 5: Query list of Segments" 461 | ] 462 | }, 463 | { 464 | "cell_type": "code", 465 | "execution_count": 8, 466 | "metadata": {}, 467 | "outputs": [ 468 | { 469 | "name": "stdout", 470 | "output_type": "stream", 471 | "text": [ 472 | "['BCD-OPT' 'BCD-FUT' 'BCD' 'BSE' 'INDICES' 'CDS-OPT' 'CDS-FUT' 'MCX-FUT'\n", 473 | " 'MCX-OPT' 'NFO-OPT' 'NFO-FUT' 'NSE']\n" 474 | ] 475 | } 476 | ], 477 | "source": [ 478 | "segments = instruments.segment.unique()\n", 479 | "print(segments)" 480 | ] 481 | }, 482 | { 483 | "cell_type": "markdown", 484 | "metadata": {}, 485 | "source": [ 486 | "### Recipe 6: Query support for Order Transaction Types, Order Types, Order Codes & Order Varieties" 487 | ] 488 | }, 489 | { 490 | "cell_type": "code", 491 | "execution_count": 9, 492 | "metadata": {}, 493 | "outputs": [], 494 | "source": [ 495 | "from pyalgotrading.broker.broker_connection_zerodha import BrokerConnectionZerodha" 496 | ] 497 | }, 498 | { 499 | "cell_type": "code", 500 | "execution_count": 10, 501 | "metadata": {}, 502 | "outputs": [ 503 | { 504 | "data": { 505 | "text/plain": [ 506 | "[,\n", 507 | " ]" 508 | ] 509 | }, 510 | "execution_count": 10, 511 | "metadata": {}, 512 | "output_type": "execute_result" 513 | } 514 | ], 515 | "source": [ 516 | "list(BrokerConnectionZerodha.ORDER_TRANSACTION_TYPE_MAP.keys())" 517 | ] 518 | }, 519 | { 520 | "cell_type": "code", 521 | "execution_count": 11, 522 | "metadata": {}, 523 | "outputs": [ 524 | { 525 | "data": { 526 | "text/plain": [ 527 | "[,\n", 528 | " ,\n", 529 | " ,\n", 530 | " ]" 531 | ] 532 | }, 533 | "execution_count": 11, 534 | "metadata": {}, 535 | "output_type": "execute_result" 536 | } 537 | ], 538 | "source": [ 539 | "list(BrokerConnectionZerodha.ORDER_VARIETY_MAP.keys())" 540 | ] 541 | }, 542 | { 543 | "cell_type": "code", 544 | "execution_count": 12, 545 | "metadata": {}, 546 | "outputs": [ 547 | { 548 | "data": { 549 | "text/plain": [ 550 | "[,\n", 551 | " ,\n", 552 | " ,\n", 553 | " ]" 554 | ] 555 | }, 556 | "execution_count": 12, 557 | "metadata": {}, 558 | "output_type": "execute_result" 559 | } 560 | ], 561 | "source": [ 562 | "list(BrokerConnectionZerodha.ORDER_TYPE_MAP.keys())" 563 | ] 564 | }, 565 | { 566 | "cell_type": "code", 567 | "execution_count": 13, 568 | "metadata": {}, 569 | "outputs": [ 570 | { 571 | "data": { 572 | "text/plain": [ 573 | "[,\n", 574 | " ]" 575 | ] 576 | }, 577 | "execution_count": 13, 578 | "metadata": {}, 579 | "output_type": "execute_result" 580 | } 581 | ], 582 | "source": [ 583 | "list(BrokerConnectionZerodha.ORDER_CODE_MAP.keys())" 584 | ] 585 | }, 586 | { 587 | "cell_type": "markdown", 588 | "metadata": {}, 589 | "source": [ 590 | "### Recipe 7: Place a simple REGULAR order" 591 | ] 592 | }, 593 | { 594 | "cell_type": "code", 595 | "execution_count": 14, 596 | "metadata": {}, 597 | "outputs": [], 598 | "source": [ 599 | "from pyalgotrading.constants import *" 600 | ] 601 | }, 602 | { 603 | "cell_type": "code", 604 | "execution_count": 15, 605 | "metadata": {}, 606 | "outputs": [], 607 | "source": [ 608 | "instrument = broker_connection.get_instrument(segment='NSE', tradingsymbol='TATASTEEL')" 609 | ] 610 | }, 611 | { 612 | "cell_type": "code", 613 | "execution_count": 16, 614 | "metadata": {}, 615 | "outputs": [ 616 | { 617 | "name": "stdout", 618 | "output_type": "stream", 619 | "text": [ 620 | "191209000001676\n" 621 | ] 622 | } 623 | ], 624 | "source": [ 625 | "# Place a Simple Regular order - Buy, Regular, Intraday, Market order\n", 626 | "order_id = broker_connection.place_order(instrument=instrument, \n", 627 | " order_transaction_type=BrokerOrderTransactionTypeConstants.BUY, \n", 628 | " order_type=BrokerOrderTypeConstants.REGULAR, \n", 629 | " order_code=BrokerOrderCodeConstants.INTRADAY, \n", 630 | " order_variety=BrokerOrderVarietyConstants.MARKET, \n", 631 | " quantity=1)\n", 632 | "order_id\n", 633 | "\n", 634 | "# Check your broker site & you will see an order placed with these parameters & order_id" 635 | ] 636 | }, 637 | { 638 | "cell_type": "markdown", 639 | "metadata": {}, 640 | "source": [ 641 | "### Recipe 8: Place a simple BRACKET Order" 642 | ] 643 | }, 644 | { 645 | "cell_type": "code", 646 | "execution_count": 17, 647 | "metadata": {}, 648 | "outputs": [], 649 | "source": [ 650 | "from pyalgotrading.constants import *" 651 | ] 652 | }, 653 | { 654 | "cell_type": "code", 655 | "execution_count": 18, 656 | "metadata": {}, 657 | "outputs": [], 658 | "source": [ 659 | "instrument = broker_connection.get_instrument(segment='NSE', tradingsymbol='ICICIBANK')" 660 | ] 661 | }, 662 | { 663 | "cell_type": "code", 664 | "execution_count": 19, 665 | "metadata": {}, 666 | "outputs": [ 667 | { 668 | "name": "stdout", 669 | "output_type": "stream", 670 | "text": [ 671 | "191212001268839\n" 672 | ] 673 | } 674 | ], 675 | "source": [ 676 | "# Place a simple BRACKET order - Buy, Bracket, Intraday, Limit order\n", 677 | "ltp = broker_connection.get_ltp(instrument)\n", 678 | "order_id = broker_connection.place_order(instrument=instrument,\n", 679 | " order_transaction_type=BrokerOrderTransactionTypeConstants.BUY,\n", 680 | " order_type=BrokerOrderTypeConstants.BRACKET,\n", 681 | " order_code=BrokerOrderCodeConstants.INTRADAY,\n", 682 | " order_variety=BrokerOrderVarietyConstants.LIMIT,\n", 683 | " quantity=1,\n", 684 | " price=ltp-1,\n", 685 | " stoploss=2,\n", 686 | " target=2)\n", 687 | "order_id\n", 688 | "\n", 689 | "# Check your broker site & you will see an order placed with these parameters & order_id" 690 | ] 691 | }, 692 | { 693 | "cell_type": "markdown", 694 | "metadata": {}, 695 | "source": [ 696 | "### Recipe 9: Place a simple DELIVERY order" 697 | ] 698 | }, 699 | { 700 | "cell_type": "code", 701 | "execution_count": 20, 702 | "metadata": {}, 703 | "outputs": [], 704 | "source": [ 705 | "from pyalgotrading.constants import *" 706 | ] 707 | }, 708 | { 709 | "cell_type": "code", 710 | "execution_count": 21, 711 | "metadata": {}, 712 | "outputs": [], 713 | "source": [ 714 | "instrument = broker_connection.get_instrument(segment='NSE', tradingsymbol='AXISBANK')" 715 | ] 716 | }, 717 | { 718 | "cell_type": "code", 719 | "execution_count": 22, 720 | "metadata": {}, 721 | "outputs": [ 722 | { 723 | "name": "stdout", 724 | "output_type": "stream", 725 | "text": [ 726 | "191212001268956\n" 727 | ] 728 | } 729 | ], 730 | "source": [ 731 | "# Place a simple DELIVERY order - Sell, Regular, Delivery, Market order\n", 732 | "order_id = broker_connection.place_order(instrument=instrument,\n", 733 | " order_transaction_type=BrokerOrderTransactionTypeConstants.SELL,\n", 734 | " order_type=BrokerOrderTypeConstants.REGULAR,\n", 735 | " order_code=BrokerOrderCodeConstants.DELIVERY,\n", 736 | " order_variety=BrokerOrderVarietyConstants.MARKET,\n", 737 | " quantity=1)\n", 738 | "order_id\n", 739 | "\n", 740 | "# Check your broker site & you will see an order placed with these parameters & order_id" 741 | ] 742 | }, 743 | { 744 | "cell_type": "markdown", 745 | "metadata": {}, 746 | "source": [ 747 | "### Recipe 10: Place a simple INTRADAY order" 748 | ] 749 | }, 750 | { 751 | "cell_type": "code", 752 | "execution_count": 23, 753 | "metadata": {}, 754 | "outputs": [], 755 | "source": [ 756 | "from pyalgotrading.constants import *" 757 | ] 758 | }, 759 | { 760 | "cell_type": "code", 761 | "execution_count": 24, 762 | "metadata": {}, 763 | "outputs": [], 764 | "source": [ 765 | "instrument = broker_connection.get_instrument(segment='NSE', tradingsymbol='HDFCBANK')" 766 | ] 767 | }, 768 | { 769 | "cell_type": "code", 770 | "execution_count": 25, 771 | "metadata": {}, 772 | "outputs": [ 773 | { 774 | "name": "stdout", 775 | "output_type": "stream", 776 | "text": [ 777 | "191212001269042\n" 778 | ] 779 | } 780 | ], 781 | "source": [ 782 | "# Place a simple INTRADAY order - Sell, Bracket, Intraday, Limit order\n", 783 | "ltp = broker_connection.get_ltp(instrument)\n", 784 | "order_id = broker_connection.place_order(instrument=instrument,\n", 785 | " order_transaction_type=BrokerOrderTransactionTypeConstants.SELL,\n", 786 | " order_type=BrokerOrderTypeConstants.BRACKET,\n", 787 | " order_code=BrokerOrderCodeConstants.INTRADAY,\n", 788 | " order_variety=BrokerOrderVarietyConstants.LIMIT,\n", 789 | " quantity=1,\n", 790 | " price=ltp+1,\n", 791 | " stoploss=2,\n", 792 | " target=2)\n", 793 | "order_id\n", 794 | "\n", 795 | "# Check you broker site & you will see an order placed with these parameters & order_id" 796 | ] 797 | }, 798 | { 799 | "cell_type": "markdown", 800 | "metadata": {}, 801 | "source": [ 802 | "### Recipe 11: Query Margins & Funds" 803 | ] 804 | }, 805 | { 806 | "cell_type": "code", 807 | "execution_count": 26, 808 | "metadata": {}, 809 | "outputs": [ 810 | { 811 | "data": { 812 | "text/plain": [ 813 | "{'enabled': True,\n", 814 | " 'net': 1623.67,\n", 815 | " 'available': {'adhoc_margin': 0,\n", 816 | " 'cash': 1623.67,\n", 817 | " 'opening_balance': 1623.67,\n", 818 | " 'live_balance': 1623.67,\n", 819 | " 'collateral': 0,\n", 820 | " 'intraday_payin': 0},\n", 821 | " 'utilised': {'debits': 0,\n", 822 | " 'exposure': 0,\n", 823 | " 'm2m_realised': 0,\n", 824 | " 'm2m_unrealised': 0,\n", 825 | " 'option_premium': 0,\n", 826 | " 'payout': 0,\n", 827 | " 'span': 0,\n", 828 | " 'holding_sales': 0,\n", 829 | " 'turnover': 0,\n", 830 | " 'liquid_collateral': 0,\n", 831 | " 'stock_collateral': 0}}" 832 | ] 833 | }, 834 | "execution_count": 26, 835 | "metadata": {}, 836 | "output_type": "execute_result" 837 | } 838 | ], 839 | "source": [ 840 | "equity_margins = broker_connection.get_margins('equity')\n", 841 | "equity_margins" 842 | ] 843 | }, 844 | { 845 | "cell_type": "code", 846 | "execution_count": 27, 847 | "metadata": {}, 848 | "outputs": [ 849 | { 850 | "data": { 851 | "text/plain": [ 852 | "1623.67" 853 | ] 854 | }, 855 | "execution_count": 27, 856 | "metadata": {}, 857 | "output_type": "execute_result" 858 | } 859 | ], 860 | "source": [ 861 | "equity_funds = broker_connection.get_funds('equity')\n", 862 | "equity_funds" 863 | ] 864 | }, 865 | { 866 | "cell_type": "code", 867 | "execution_count": 28, 868 | "metadata": {}, 869 | "outputs": [ 870 | { 871 | "data": { 872 | "text/plain": [ 873 | "{'enabled': True,\n", 874 | " 'net': 0,\n", 875 | " 'available': {'adhoc_margin': 0,\n", 876 | " 'cash': 0,\n", 877 | " 'opening_balance': 0,\n", 878 | " 'live_balance': 0,\n", 879 | " 'collateral': 0,\n", 880 | " 'intraday_payin': 0},\n", 881 | " 'utilised': {'debits': 0,\n", 882 | " 'exposure': 0,\n", 883 | " 'm2m_realised': 0,\n", 884 | " 'm2m_unrealised': 0,\n", 885 | " 'option_premium': 0,\n", 886 | " 'payout': 0,\n", 887 | " 'span': 0,\n", 888 | " 'holding_sales': 0,\n", 889 | " 'turnover': 0,\n", 890 | " 'liquid_collateral': 0,\n", 891 | " 'stock_collateral': 0}}" 892 | ] 893 | }, 894 | "execution_count": 28, 895 | "metadata": {}, 896 | "output_type": "execute_result" 897 | } 898 | ], 899 | "source": [ 900 | "commodity_margins = broker_connection.get_margins('commodity')\n", 901 | "commodity_margins" 902 | ] 903 | }, 904 | { 905 | "cell_type": "code", 906 | "execution_count": 29, 907 | "metadata": {}, 908 | "outputs": [ 909 | { 910 | "data": { 911 | "text/plain": [ 912 | "0" 913 | ] 914 | }, 915 | "execution_count": 29, 916 | "metadata": {}, 917 | "output_type": "execute_result" 918 | } 919 | ], 920 | "source": [ 921 | "commodity_funds = broker_connection.get_funds('commodity')\n", 922 | "commodity_funds" 923 | ] 924 | }, 925 | { 926 | "cell_type": "markdown", 927 | "metadata": {}, 928 | "source": [ 929 | "### Recipe 12: Calculate Brokerage charged" 930 | ] 931 | }, 932 | { 933 | "cell_type": "code", 934 | "execution_count": 30, 935 | "metadata": {}, 936 | "outputs": [ 937 | { 938 | "name": "stdout", 939 | "output_type": "stream", 940 | "text": [ 941 | "Brokerage charged per trade: 0.1245\n" 942 | ] 943 | } 944 | ], 945 | "source": [ 946 | "entry_price = 1245\n", 947 | "brokerage = (0.01 * 1245)/100\n", 948 | "print(f'Brokerage charged per trade: {brokerage:.4f}')" 949 | ] 950 | }, 951 | { 952 | "cell_type": "code", 953 | "execution_count": 30, 954 | "metadata": {}, 955 | "outputs": [ 956 | { 957 | "name": "stdout", 958 | "output_type": "stream", 959 | "text": [ 960 | "Total Brokerage charged for 10 trades: 1.2450\n" 961 | ] 962 | } 963 | ], 964 | "source": [ 965 | "# Assuming, 10 trades were placed in a day with an average price of 1245, we calculate the total brokerage involved\n", 966 | "total_brokerage = 10 * (0.01 * 1245) / 100\n", 967 | "print(f'Total Brokerage charged for 10 trades: {total_brokerage:.4f}')" 968 | ] 969 | }, 970 | { 971 | "cell_type": "markdown", 972 | "metadata": {}, 973 | "source": [ 974 | "### Recipe 13: Calculate Government taxes charged" 975 | ] 976 | }, 977 | { 978 | "cell_type": "code", 979 | "execution_count": 31, 980 | "metadata": {}, 981 | "outputs": [ 982 | { 983 | "name": "stdout", 984 | "output_type": "stream", 985 | "text": [ 986 | "Government taxes charged per trade: 1.2450\n" 987 | ] 988 | } 989 | ], 990 | "source": [ 991 | "entry_price = 1245\n", 992 | "brokerage = (0.1 * 1245)/100\n", 993 | "print(f'Government taxes charged per trade: {brokerage:.4f}')" 994 | ] 995 | }, 996 | { 997 | "cell_type": "code", 998 | "execution_count": 32, 999 | "metadata": {}, 1000 | "outputs": [ 1001 | { 1002 | "name": "stdout", 1003 | "output_type": "stream", 1004 | "text": [ 1005 | "Total Government taxes charged for 10 trades: 12.4500\n" 1006 | ] 1007 | } 1008 | ], 1009 | "source": [ 1010 | "# Assuming, 10 trades were placed in a day with an average price of 1245, we calculate the total brokerage involved\n", 1011 | "total_brokerage = 10 * (0.1 * 1245) / 100\n", 1012 | "print(f'Total Government taxes charged for 10 trades: {total_brokerage:.4f}')" 1013 | ] 1014 | } 1015 | ], 1016 | "metadata": { 1017 | "kernelspec": { 1018 | "display_name": "Python 3", 1019 | "language": "python", 1020 | "name": "python3" 1021 | }, 1022 | "language_info": { 1023 | "codemirror_mode": { 1024 | "name": "ipython", 1025 | "version": 3 1026 | }, 1027 | "file_extension": ".py", 1028 | "mimetype": "text/x-python", 1029 | "name": "python", 1030 | "nbconvert_exporter": "python", 1031 | "pygments_lexer": "ipython3", 1032 | "version": "3.8.2" 1033 | } 1034 | }, 1035 | "nbformat": 4, 1036 | "nbformat_minor": 2 1037 | } 1038 | -------------------------------------------------------------------------------- /Chapter02/README.md: -------------------------------------------------------------------------------- 1 | ### Chapter 2: Stock Markets: Primer on Trading 2 | Learn how to setup Python connectivity with a broker, fetch financial instruments 3 | and get a quick hands-on at placing simple orders. Also, learn about querying 4 | margins and calculating brokerage and government taxes. 5 | 6 | ### List of Recipes in this chapter 7 | 1. Setting up Python connectivity with the Broker 8 | 2. Querying a list of Instruments 9 | 3. Fetching an instrument 10 | 4. Querying a list of Exchanges 11 | 5. Querying a list of Segments 12 | 6. Variety Types, Product Types and Order Types 13 | 7. Placing a simple REGULAR order 14 | 8. Placing a simple BRACKET order 15 | 9. Placing a simple INTRADAY order 16 | 10. Placing a simple DELIVERY order 17 | 11. Querying Margins and Funds 18 | 12. Calculating the Brokerage charged 19 | 13. Calculating the government taxes charged 20 | 21 | *[**[Click here to VIEW Chapter 2 Jupyter Notebook on nbviewer](https://nbviewer.jupyter.org/github/PacktPublishing/Python-Algorithmic-Trading-Cookbook/blob/master/Chapter02/CHAPTER%202.ipynb)**]* 22 |
23 | *[**[Click here to RUN Chapter 2 Jupyter Notebook in the cloud using binder. No installation needed on your end.](https://mybinder.org/v2/gh/PacktPublishing/Python-Algorithmic-Trading-Cookbook/master?filepath=Chapter02/CHAPTER%202.ipynb)**]* 24 | 25 | ### Requirements 26 | - Python 3.7+ 27 | - Additional Python Packages required for this chapter can be installed as follows - 28 | 29 | ``` 30 | $ source # optional, if you use a virtualenv 31 | $ cd 32 | $ pip install -r requirements.txt 33 | ``` -------------------------------------------------------------------------------- /Chapter02/requirements.txt: -------------------------------------------------------------------------------- 1 | pyalgotrading 2 | -------------------------------------------------------------------------------- /Chapter03/CHAPTER 3.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Python Algorithmic Trading Cookbook" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Chapter 3: Fetching Financial Data" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "This Jupyter Notebook is created using Python version 3.8.2" 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "----" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "### Requirements" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "You can install the requirements for this Jupyter Notebook by executing the below cell" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 0, 48 | "metadata": {}, 49 | "outputs": [], 50 | "source": [ 51 | "!pip install pyalgotrading" 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": {}, 57 | "source": [ 58 | "----" 59 | ] 60 | }, 61 | { 62 | "cell_type": "markdown", 63 | "metadata": {}, 64 | "source": [ 65 | "### Master Recipe\n", 66 | "\n", 67 | "The following code will help you set up the broker connection with Zerodha, which will be used by all the recipes in this chapter. Please make sure you have followed these steps before trying out any recipe. \n" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": 1, 73 | "metadata": {}, 74 | "outputs": [], 75 | "source": [ 76 | "from pyalgotrading.broker.broker_connection_zerodha import BrokerConnectionZerodha" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 2, 82 | "metadata": {}, 83 | "outputs": [ 84 | { 85 | "name": "stdout", 86 | "output_type": "stream", 87 | "text": [ 88 | "Installing package kiteconnect via pip. This may take a while...\n", 89 | "Please login to this link to generate your request token: https://kite.trade/connect/login?api_key=&v=3\n" 90 | ] 91 | } 92 | ], 93 | "source": [ 94 | "# Get the api_key and api_secret from broker. These are unique to you and will be used by the broker to identify your demat account.\n", 95 | "api_key = \"\"\n", 96 | "api_secret = \"\"\n", 97 | "broker_connection = BrokerConnectionZerodha(api_key, api_secret)" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": 3, 103 | "metadata": {}, 104 | "outputs": [], 105 | "source": [ 106 | "# Get the request token from the above URL\n", 107 | "request_token = \"\"\n", 108 | "broker_connection.set_access_token(request_token)" 109 | ] 110 | }, 111 | { 112 | "cell_type": "markdown", 113 | "metadata": {}, 114 | "source": [ 115 | "----" 116 | ] 117 | }, 118 | { 119 | "cell_type": "markdown", 120 | "metadata": {}, 121 | "source": [ 122 | "### Recipe 1: Fetching the list of Financial Instruments" 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": 4, 128 | "metadata": {}, 129 | "outputs": [ 130 | { 131 | "data": { 132 | "text/html": [ 133 | "
\n", 134 | "\n", 147 | "\n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | " \n", 158 | " \n", 159 | " \n", 160 | " \n", 161 | " \n", 162 | " \n", 163 | " \n", 164 | " \n", 165 | " \n", 166 | " \n", 167 | " \n", 168 | " \n", 169 | " \n", 170 | " \n", 171 | " \n", 172 | " \n", 173 | " \n", 174 | " \n", 175 | " \n", 176 | " \n", 177 | " \n", 178 | " \n", 179 | " \n", 180 | " \n", 181 | " \n", 182 | " \n", 183 | " \n", 184 | " \n", 185 | " \n", 186 | " \n", 187 | " \n", 188 | " \n", 189 | " \n", 190 | " \n", 191 | " \n", 192 | " \n", 193 | " \n", 194 | " \n", 195 | " \n", 196 | " \n", 197 | " \n", 198 | " \n", 199 | " \n", 200 | " \n", 201 | " \n", 202 | " \n", 203 | " \n", 204 | " \n", 205 | " \n", 206 | " \n", 207 | " \n", 208 | " \n", 209 | " \n", 210 | " \n", 211 | " \n", 212 | " \n", 213 | " \n", 214 | " \n", 215 | " \n", 216 | " \n", 217 | " \n", 218 | " \n", 219 | " \n", 220 | " \n", 221 | " \n", 222 | " \n", 223 | " \n", 224 | " \n", 225 | " \n", 226 | " \n", 227 | " \n", 228 | " \n", 229 | " \n", 230 | " \n", 231 | " \n", 232 | " \n", 233 | " \n", 234 | " \n", 235 | " \n", 236 | " \n", 237 | " \n", 238 | " \n", 239 | " \n", 240 | " \n", 241 | " \n", 242 | " \n", 243 | " \n", 244 | " \n", 245 | " \n", 246 | " \n", 247 | " \n", 248 | " \n", 249 | " \n", 250 | " \n", 251 | " \n", 252 | " \n", 253 | " \n", 254 | " \n", 255 | " \n", 256 | " \n", 257 | " \n", 258 | " \n", 259 | " \n", 260 | " \n", 261 | " \n", 262 | " \n", 263 | " \n", 264 | " \n", 265 | " \n", 266 | " \n", 267 | " \n", 268 | " \n", 269 | " \n", 270 | " \n", 271 | " \n", 272 | " \n", 273 | " \n", 274 | " \n", 275 | " \n", 276 | " \n", 277 | " \n", 278 | " \n", 279 | " \n", 280 | " \n", 281 | " \n", 282 | " \n", 283 | " \n", 284 | " \n", 285 | " \n", 286 | " \n", 287 | " \n", 288 | " \n", 289 | " \n", 290 | " \n", 291 | " \n", 292 | " \n", 293 | " \n", 294 | " \n", 295 | " \n", 296 | " \n", 297 | " \n", 298 | " \n", 299 | " \n", 300 | " \n", 301 | " \n", 302 | " \n", 303 | " \n", 304 | " \n", 305 | " \n", 306 | " \n", 307 | " \n", 308 | " \n", 309 | " \n", 310 | " \n", 311 | " \n", 312 | " \n", 313 | " \n", 314 | " \n", 315 | " \n", 316 | " \n", 317 | " \n", 318 | " \n", 319 | " \n", 320 | " \n", 321 | " \n", 322 | " \n", 323 | " \n", 324 | " \n", 325 | " \n", 326 | " \n", 327 | " \n", 328 | " \n", 329 | " \n", 330 | " \n", 331 | " \n", 332 | "
instrument_tokenexchange_tokentradingsymbolnamelast_priceexpirystriketick_sizelot_sizeinstrument_typesegmentexchange
05448445502128299EURINR20AUG79.2500CEEURINR0.02020-08-2779.250.00251CEBCD-OPTBCD
15448389182128277EURINR20AUG79.2500PEEURINR0.02020-08-2779.250.00251PEBCD-OPTBCD
25447887422128081EURINR20AUG79.5000CEEURINR0.02020-08-2779.500.00251CEBCD-OPTBCD
35447823422128056EURINR20AUG79.5000PEEURINR0.02020-08-2779.500.00251PEBCD-OPTBCD
45447390782127887EURINR20AUG79.7500CEEURINR0.02020-08-2779.750.00251CEBCD-OPTBCD
.......................................
6529219450897598ZODJRDMKJ-BEZODIAC JRD MKJ-0.00.000.05001EQNSENSE
65293291686511394ZOTAZOTA HEALTH CARE0.00.000.05001EQNSENSE
65294743680129050ZUARIZUARI AGRO CHEMICALS0.00.000.05001EQNSENSE
652959797133827ZUARIGLOBZUARI GLOBAL0.00.000.05001EQNSENSE
65296451456117635ZYDUSWELLZYDUS WELLNESS0.00.000.05001EQNSENSE
\n", 333 | "

65297 rows × 12 columns

\n", 334 | "
" 335 | ], 336 | "text/plain": [ 337 | " instrument_token exchange_token tradingsymbol \\\n", 338 | "0 544844550 2128299 EURINR20AUG79.2500CE \n", 339 | "1 544838918 2128277 EURINR20AUG79.2500PE \n", 340 | "2 544788742 2128081 EURINR20AUG79.5000CE \n", 341 | "3 544782342 2128056 EURINR20AUG79.5000PE \n", 342 | "4 544739078 2127887 EURINR20AUG79.7500CE \n", 343 | "... ... ... ... \n", 344 | "65292 1945089 7598 ZODJRDMKJ-BE \n", 345 | "65293 2916865 11394 ZOTA \n", 346 | "65294 7436801 29050 ZUARI \n", 347 | "65295 979713 3827 ZUARIGLOB \n", 348 | "65296 4514561 17635 ZYDUSWELL \n", 349 | "\n", 350 | " name last_price expiry strike tick_size \\\n", 351 | "0 EURINR 0.0 2020-08-27 79.25 0.0025 \n", 352 | "1 EURINR 0.0 2020-08-27 79.25 0.0025 \n", 353 | "2 EURINR 0.0 2020-08-27 79.50 0.0025 \n", 354 | "3 EURINR 0.0 2020-08-27 79.50 0.0025 \n", 355 | "4 EURINR 0.0 2020-08-27 79.75 0.0025 \n", 356 | "... ... ... ... ... ... \n", 357 | "65292 ZODIAC JRD MKJ- 0.0 0.00 0.0500 \n", 358 | "65293 ZOTA HEALTH CARE 0.0 0.00 0.0500 \n", 359 | "65294 ZUARI AGRO CHEMICALS 0.0 0.00 0.0500 \n", 360 | "65295 ZUARI GLOBAL 0.0 0.00 0.0500 \n", 361 | "65296 ZYDUS WELLNESS 0.0 0.00 0.0500 \n", 362 | "\n", 363 | " lot_size instrument_type segment exchange \n", 364 | "0 1 CE BCD-OPT BCD \n", 365 | "1 1 PE BCD-OPT BCD \n", 366 | "2 1 CE BCD-OPT BCD \n", 367 | "3 1 PE BCD-OPT BCD \n", 368 | "4 1 CE BCD-OPT BCD \n", 369 | "... ... ... ... ... \n", 370 | "65292 1 EQ NSE NSE \n", 371 | "65293 1 EQ NSE NSE \n", 372 | "65294 1 EQ NSE NSE \n", 373 | "65295 1 EQ NSE NSE \n", 374 | "65296 1 EQ NSE NSE \n", 375 | "\n", 376 | "[65297 rows x 12 columns]" 377 | ] 378 | }, 379 | "execution_count": 4, 380 | "metadata": {}, 381 | "output_type": "execute_result" 382 | } 383 | ], 384 | "source": [ 385 | "instruments = broker_connection.get_all_instruments()\n", 386 | "instruments" 387 | ] 388 | }, 389 | { 390 | "cell_type": "markdown", 391 | "metadata": {}, 392 | "source": [ 393 | "### Recipe 2: Attributes of a Financial Instrument" 394 | ] 395 | }, 396 | { 397 | "cell_type": "code", 398 | "execution_count": 5, 399 | "metadata": {}, 400 | "outputs": [ 401 | { 402 | "data": { 403 | "text/plain": [ 404 | "['instrument_token',\n", 405 | " 'exchange_token',\n", 406 | " 'tradingsymbol',\n", 407 | " 'name',\n", 408 | " 'last_price',\n", 409 | " 'expiry',\n", 410 | " 'strike',\n", 411 | " 'tick_size',\n", 412 | " 'lot_size',\n", 413 | " 'instrument_type',\n", 414 | " 'segment',\n", 415 | " 'exchange']" 416 | ] 417 | }, 418 | "execution_count": 5, 419 | "metadata": {}, 420 | "output_type": "execute_result" 421 | } 422 | ], 423 | "source": [ 424 | "# All the attributes of financial instruments provided by the broker\n", 425 | "list(instruments.columns)" 426 | ] 427 | }, 428 | { 429 | "cell_type": "markdown", 430 | "metadata": {}, 431 | "source": [ 432 | "### Recipe 3: Expiry of Financial Instruments" 433 | ] 434 | }, 435 | { 436 | "cell_type": "code", 437 | "execution_count": 6, 438 | "metadata": { 439 | "scrolled": true 440 | }, 441 | "outputs": [], 442 | "source": [ 443 | "instrument1 = broker_connection.get_instrument('NSE', 'TATASTEEL')" 444 | ] 445 | }, 446 | { 447 | "cell_type": "code", 448 | "execution_count": 7, 449 | "metadata": {}, 450 | "outputs": [ 451 | { 452 | "name": "stdout", 453 | "output_type": "stream", 454 | "text": [ 455 | "Instrument expires: False\n" 456 | ] 457 | } 458 | ], 459 | "source": [ 460 | "print(f'Instrument expires: {instrument1.will_expire()}')" 461 | ] 462 | }, 463 | { 464 | "cell_type": "code", 465 | "execution_count": 8, 466 | "metadata": {}, 467 | "outputs": [], 468 | "source": [ 469 | "instrument2 = broker_connection.get_instrument('NFO-FUT', 'TATASTEEL20AUGFUT')" 470 | ] 471 | }, 472 | { 473 | "cell_type": "code", 474 | "execution_count": 9, 475 | "metadata": {}, 476 | "outputs": [ 477 | { 478 | "name": "stdout", 479 | "output_type": "stream", 480 | "text": [ 481 | "Instrument expires: True\n" 482 | ] 483 | } 484 | ], 485 | "source": [ 486 | "print(f'Instrument expires: {instrument2.will_expire()}')" 487 | ] 488 | }, 489 | { 490 | "cell_type": "code", 491 | "execution_count": 10, 492 | "metadata": {}, 493 | "outputs": [ 494 | { 495 | "name": "stdout", 496 | "output_type": "stream", 497 | "text": [ 498 | "Expiry date: 2020-08-27\n" 499 | ] 500 | } 501 | ], 502 | "source": [ 503 | "print(f'Expiry date: {instrument2.expiry}')" 504 | ] 505 | }, 506 | { 507 | "cell_type": "markdown", 508 | "metadata": {}, 509 | "source": [ 510 | "### Recipe 4: Circuit Limits of a Financial Instrument" 511 | ] 512 | }, 513 | { 514 | "cell_type": "code", 515 | "execution_count": 11, 516 | "metadata": {}, 517 | "outputs": [ 518 | { 519 | "name": "stdout", 520 | "output_type": "stream", 521 | "text": [ 522 | "Lower circuit limit: 315.9\n", 523 | "Upper circuit limit: 386\n" 524 | ] 525 | } 526 | ], 527 | "source": [ 528 | "lower_circuit_limit, upper_circuit_limit = broker_connection.get_circuit_limits(instrument1)\n", 529 | "print(f'Lower circuit limit: {lower_circuit_limit}')\n", 530 | "print(f'Upper circuit limit: {upper_circuit_limit}')" 531 | ] 532 | }, 533 | { 534 | "cell_type": "markdown", 535 | "metadata": {}, 536 | "source": [ 537 | "### Recipe 5: Market depth of a Financial Instrument" 538 | ] 539 | }, 540 | { 541 | "cell_type": "code", 542 | "execution_count": 12, 543 | "metadata": {}, 544 | "outputs": [ 545 | { 546 | "name": "stdout", 547 | "output_type": "stream", 548 | "text": [ 549 | "Buy Market Depth:\n", 550 | " orders price quantity\n", 551 | "0 1 350.05 1\n", 552 | "1 16 350.00 43294\n", 553 | "2 5 349.95 1250\n", 554 | "3 8 349.90 3134\n", 555 | "4 5 349.85 1078\n", 556 | "Sell Market Depth:\n", 557 | " orders price quantity\n", 558 | "0 1 350.10 25\n", 559 | "1 7 350.15 1367\n", 560 | "2 13 350.20 4654\n", 561 | "3 13 350.25 2977\n", 562 | "4 21 350.30 5798\n" 563 | ] 564 | } 565 | ], 566 | "source": [ 567 | "buy_market_depth, sell_market_depth = broker_connection.get_market_depth(instrument1)\n", 568 | "print(f'Buy Market Depth:\\n{buy_market_depth}')\n", 569 | "print(f'Sell Market Depth:\\n{sell_market_depth}')" 570 | ] 571 | }, 572 | { 573 | "cell_type": "markdown", 574 | "metadata": {}, 575 | "source": [ 576 | "### Recipe 6: Total Pending Buy Quantity of a Financial Instrument" 577 | ] 578 | }, 579 | { 580 | "cell_type": "code", 581 | "execution_count": 13, 582 | "metadata": {}, 583 | "outputs": [ 584 | { 585 | "name": "stdout", 586 | "output_type": "stream", 587 | "text": [ 588 | "Total pending BUY quantity: 1319590\n" 589 | ] 590 | } 591 | ], 592 | "source": [ 593 | "total_pending_buy_quantity = broker_connection.get_total_pending_buy_quantity(instrument1)\n", 594 | "print(f'Total pending BUY quantity: {total_pending_buy_quantity}')" 595 | ] 596 | }, 597 | { 598 | "cell_type": "markdown", 599 | "metadata": {}, 600 | "source": [ 601 | "### Recipe 7: Total Pending Sell Quantity of a Financial Instrument" 602 | ] 603 | }, 604 | { 605 | "cell_type": "code", 606 | "execution_count": 14, 607 | "metadata": {}, 608 | "outputs": [ 609 | { 610 | "name": "stdout", 611 | "output_type": "stream", 612 | "text": [ 613 | "Total pending SELL quantity: 968602\n" 614 | ] 615 | } 616 | ], 617 | "source": [ 618 | "total_pending_sell_quantity = broker_connection.get_total_pending_sell_quantity(instrument1)\n", 619 | "print(f'Total pending SELL quantity: {total_pending_sell_quantity}')" 620 | ] 621 | }, 622 | { 623 | "cell_type": "markdown", 624 | "metadata": {}, 625 | "source": [ 626 | "### Recipe 8: Total Volume traded for the day of a Financial Instrument" 627 | ] 628 | }, 629 | { 630 | "cell_type": "code", 631 | "execution_count": 15, 632 | "metadata": {}, 633 | "outputs": [ 634 | { 635 | "name": "stdout", 636 | "output_type": "stream", 637 | "text": [ 638 | "Total Volume for the day so far: 24416975\n" 639 | ] 640 | } 641 | ], 642 | "source": [ 643 | "total_volume_day = broker_connection.get_total_volume_day(instrument1)\n", 644 | "print(f'Total Volume for the day so far: {total_volume_day}')" 645 | ] 646 | }, 647 | { 648 | "cell_type": "markdown", 649 | "metadata": {}, 650 | "source": [ 651 | "### Recipe 9: Last Traded Price of a Financial Instrument" 652 | ] 653 | }, 654 | { 655 | "cell_type": "code", 656 | "execution_count": 16, 657 | "metadata": {}, 658 | "outputs": [ 659 | { 660 | "name": "stdout", 661 | "output_type": "stream", 662 | "text": [ 663 | "Last traded price: 350.95\n" 664 | ] 665 | } 666 | ], 667 | "source": [ 668 | "ltp = broker_connection.get_ltp(instrument1)\n", 669 | "print(f'Last traded price: {ltp}')" 670 | ] 671 | }, 672 | { 673 | "cell_type": "markdown", 674 | "metadata": {}, 675 | "source": [ 676 | "### Recipe 10: Last Traded Time of a Financial Instrument" 677 | ] 678 | }, 679 | { 680 | "cell_type": "code", 681 | "execution_count": 17, 682 | "metadata": {}, 683 | "outputs": [ 684 | { 685 | "name": "stdout", 686 | "output_type": "stream", 687 | "text": [ 688 | "Last traded time: 2020-07-17 14:42:54\n" 689 | ] 690 | } 691 | ], 692 | "source": [ 693 | "ltt = broker_connection.get_ltt(instrument1)\n", 694 | "print(f'Last traded time: {ltt}')" 695 | ] 696 | }, 697 | { 698 | "cell_type": "markdown", 699 | "metadata": {}, 700 | "source": [ 701 | "### Recipe 11: Last Traded Quantity of a Financial Instrument" 702 | ] 703 | }, 704 | { 705 | "cell_type": "code", 706 | "execution_count": 18, 707 | "metadata": {}, 708 | "outputs": [ 709 | { 710 | "name": "stdout", 711 | "output_type": "stream", 712 | "text": [ 713 | "Last traded quantity: 19\n" 714 | ] 715 | } 716 | ], 717 | "source": [ 718 | "ltq = broker_connection.get_ltq(instrument1)\n", 719 | "print(f'Last traded quantity: {ltq}')" 720 | ] 721 | }, 722 | { 723 | "cell_type": "markdown", 724 | "metadata": {}, 725 | "source": [ 726 | "### Recipe 12: The recorded Open price of the day of a Financial Instrument" 727 | ] 728 | }, 729 | { 730 | "cell_type": "code", 731 | "execution_count": 19, 732 | "metadata": {}, 733 | "outputs": [ 734 | { 735 | "name": "stdout", 736 | "output_type": "stream", 737 | "text": [ 738 | "Open price today: 346\n" 739 | ] 740 | } 741 | ], 742 | "source": [ 743 | "open_price_day = broker_connection.get_open_price_day(instrument1)\n", 744 | "print(f'Open price today: {open_price_day}')" 745 | ] 746 | }, 747 | { 748 | "cell_type": "markdown", 749 | "metadata": {}, 750 | "source": [ 751 | "### Recipe 13: The recorded Highest price of the day of a Financial Instrument" 752 | ] 753 | }, 754 | { 755 | "cell_type": "code", 756 | "execution_count": 20, 757 | "metadata": {}, 758 | "outputs": [ 759 | { 760 | "name": "stdout", 761 | "output_type": "stream", 762 | "text": [ 763 | "Highest price today: 356.8\n" 764 | ] 765 | } 766 | ], 767 | "source": [ 768 | "high_price_day = broker_connection.get_high_price_day(instrument1)\n", 769 | "print(f'Highest price today: {high_price_day}')" 770 | ] 771 | }, 772 | { 773 | "cell_type": "markdown", 774 | "metadata": {}, 775 | "source": [ 776 | "### Recipe 14: The recorded Lowest price of the day of a Financial Instrument" 777 | ] 778 | }, 779 | { 780 | "cell_type": "code", 781 | "execution_count": 21, 782 | "metadata": {}, 783 | "outputs": [ 784 | { 785 | "name": "stdout", 786 | "output_type": "stream", 787 | "text": [ 788 | "Lowest price today: 345.15\n" 789 | ] 790 | } 791 | ], 792 | "source": [ 793 | "low_price_day = broker_connection.get_low_price_day(instrument1)\n", 794 | "print(f'Lowest price today: {low_price_day}')" 795 | ] 796 | }, 797 | { 798 | "cell_type": "markdown", 799 | "metadata": {}, 800 | "source": [ 801 | "### Recipe 15: The recorded Close price of the last traded day of a Financial Instrument" 802 | ] 803 | }, 804 | { 805 | "cell_type": "code", 806 | "execution_count": 22, 807 | "metadata": {}, 808 | "outputs": [ 809 | { 810 | "name": "stdout", 811 | "output_type": "stream", 812 | "text": [ 813 | "Close price of last trading day: 341.65\n" 814 | ] 815 | } 816 | ], 817 | "source": [ 818 | "close_price_last_day = broker_connection.get_close_price_last_day(instrument1)\n", 819 | "print(f'Close price of last trading day: {close_price_last_day}')" 820 | ] 821 | } 822 | ], 823 | "metadata": { 824 | "kernelspec": { 825 | "display_name": "Python 3", 826 | "language": "python", 827 | "name": "python3" 828 | }, 829 | "language_info": { 830 | "codemirror_mode": { 831 | "name": "ipython", 832 | "version": 3 833 | }, 834 | "file_extension": ".py", 835 | "mimetype": "text/x-python", 836 | "name": "python", 837 | "nbconvert_exporter": "python", 838 | "pygments_lexer": "ipython3", 839 | "version": "3.8.2" 840 | } 841 | }, 842 | "nbformat": 4, 843 | "nbformat_minor": 2 844 | } 845 | -------------------------------------------------------------------------------- /Chapter03/README.md: -------------------------------------------------------------------------------- 1 | ### Chapter 3: Fetching Financial Data 2 | Learn everything about Financial Instruments in-depth. 3 | 4 | ### List of Recipes in this chapter 5 | 1. Fetching the list of Financial Instruments 6 | 2. Attributes of a Financial Instrument 7 | 3. Expiry of Financial Instruments 8 | 4. Circuit Limits of a Financial Instrument 9 | 5. Market depth of a Financial Instrument 10 | 6. Total Pending Buy Quantity of a Financial Instrument 11 | 7. Total Pending Sell Quantity of a Financial Instrument 12 | 8. Total Volume traded for the day of a Financial Instrument 13 | 9. Last Traded Price of a Financial Instrument 14 | 10. Last Traded Time of a Financial Instrument 15 | 11. Last Traded Quantity of a Financial Instrument 16 | 12. The recorded Open price of the day of a Financial Instrument 17 | 13. The recorded Highest price of the day of a Financial Instrument 18 | 14. The recorded Lowest price of the day of a Financial Instrument 19 | 15. The recorded Close price of the last traded day of a Financial Instrument 20 | 21 | *[**[Click here to VIEW Chapter 3 Jupyter Notebook on nbviewer](https://nbviewer.jupyter.org/github/PacktPublishing/Python-Algorithmic-Trading-Cookbook/blob/master/Chapter03/CHAPTER%203.ipynb)**]* 22 |
23 | *[**[Click here to RUN Chapter 3 Jupyter Notebook in the cloud using binder. No installation needed on your end.](https://mybinder.org/v2/gh/PacktPublishing/Python-Algorithmic-Trading-Cookbook/master?filepath=Chapter03/CHAPTER%203.ipynb)**]* 24 | 25 | ### Requirements 26 | - Python 3.7+ 27 | - Additional Python Packages required for this chapter can be installed as follows - 28 | 29 | ``` 30 | $ source # optional, if you use a virtualenv 31 | $ cd 32 | $ pip install -r requirements.txt 33 | ``` -------------------------------------------------------------------------------- /Chapter03/requirements.txt: -------------------------------------------------------------------------------- 1 | pyalgotrading 2 | -------------------------------------------------------------------------------- /Chapter04/README.md: -------------------------------------------------------------------------------- 1 | ### Chapter 4: Computing Candlesticks and Historical Data 2 | Learn how to fetch and understand historical data. Also learn how to fetch, compute 3 | and plot various candlesticks patterns including Japanese (OHLC), Renko, Line Break 4 | and Heikin-Ashi. 5 | 6 | ### List of Recipes in this chapter 7 | 1. Fetching historical data using the broker API 8 | 2. Fetching historical data with the Japanese (OHLC) candlestick pattern 9 | 3. Fetching the Japanese candlestick pattern with variations in candle intervals 10 | 4. Fetching historical data with the Line Break candlestick pattern 11 | 5. Fetching historical data with the Renko candlestick pattern 12 | 6. Fetching historical data with the Heikin-Ashi candlestick pattern 13 | 7. Fetching historical data using Quandl 14 | 15 | *[**[Click here to VIEW Chapter 4 Jupyter Notebook & interact with charts on nbviewer](https://nbviewer.jupyter.org/github/PacktPublishing/Python-Algorithmic-Trading-Cookbook/blob/master/Chapter04/CHAPTER%204.ipynb)**]* 16 |
17 | *[**[Click here to RUN Chapter 4 Jupyter Notebook in the cloud using binder. No installation needed on your end.](https://mybinder.org/v2/gh/PacktPublishing/Python-Algorithmic-Trading-Cookbook/master?filepath=Chapter04/CHAPTER%204.ipynb)**]* 18 | 19 | ### Requirements 20 | - Python 3.7+ 21 | - Additional Python Packages required for this chapter can be installed as follows - 22 | 23 | ``` 24 | $ source # optional, if you use a virtualenv 25 | $ cd 26 | $ pip install -r requirements.txt 27 | ``` -------------------------------------------------------------------------------- /Chapter04/images/convert_image_pdf_to_png.sh: -------------------------------------------------------------------------------- 1 | # A bash script to convert pdf to png 2 | echo $1 3 | pdftoppm "$1" "$1" -png -r 500 -singlefile 4 | convert "$1".png -trim "$1".png 5 | -------------------------------------------------------------------------------- /Chapter04/images/pdf/1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/1.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/10.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/10.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/11.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/11.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/12.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/12.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/13.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/13.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/14.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/14.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/15.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/15.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/16.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/16.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/17.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/17.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/18.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/18.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/19.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/19.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/2.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/20.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/20.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/21.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/21.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/22.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/22.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/23.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/23.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/24.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/24.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/25.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/25.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/26.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/26.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/27.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/27.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/28.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/28.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/29.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/29.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/3.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/30.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/30.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/31.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/31.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/32.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/32.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/33.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/33.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/34.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/34.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/35.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/35.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/36.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/36.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/37.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/37.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/38.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/38.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/39.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/39.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/4.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/40.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/40.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/41.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/41.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/42.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/42.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/43.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/43.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/44.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/44.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/45.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/45.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/46.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/46.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/47.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/47.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/48.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/48.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/5.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/6.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/6.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/7.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/7.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/8.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/8.pdf -------------------------------------------------------------------------------- /Chapter04/images/pdf/9.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/pdf/9.pdf -------------------------------------------------------------------------------- /Chapter04/images/png/1.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/1.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/10.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/10.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/11.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/11.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/12.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/12.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/13.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/13.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/14.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/14.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/15.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/15.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/16.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/16.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/17.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/17.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/18.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/18.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/19.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/19.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/2.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/2.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/20.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/20.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/21.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/21.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/22.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/22.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/23.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/23.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/24.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/24.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/25.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/25.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/26.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/26.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/27.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/27.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/28.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/28.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/29.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/29.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/3.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/3.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/30.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/30.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/31.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/31.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/32.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/32.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/33.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/33.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/34.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/34.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/35.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/35.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/36.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/36.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/37.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/37.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/38.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/38.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/39.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/39.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/4.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/4.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/40.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/40.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/41.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/41.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/42.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/42.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/43.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/43.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/44.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/44.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/45.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/45.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/46.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/46.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/47.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/47.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/48.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/48.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/5.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/5.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/6.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/6.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/7.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/7.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/8.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/8.pdf.png -------------------------------------------------------------------------------- /Chapter04/images/png/9.pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter04/images/png/9.pdf.png -------------------------------------------------------------------------------- /Chapter04/requirements.txt: -------------------------------------------------------------------------------- 1 | pyalgotrading 2 | quandl 3 | -------------------------------------------------------------------------------- /Chapter05/README.md: -------------------------------------------------------------------------------- 1 | ### Chapter 5: Computing and Plotting Technical Indicators 2 | Learn how to compute and plot 10 types of Technical Indicators including Trend 3 | Indicators, Momentum Indicators, Volatility Indicators and Volume Indicators. 4 | 5 | ### List of Recipes in this chapter 6 | 1. Trend Indicator: Simple Moving Average 7 | 2. Trend Indicator: Exponential Moving Average 8 | 3. Trend Indicator: Moving Average Convergence Divergence 9 | 4. Trend Indicator: Parabolic Stop and Reverse 10 | 5. Momentum Indicator: Relative Strength Index 11 | 6. Momentum Indicator: Stochastic Oscillator 12 | 7. Volatility Indicator: Bollinger Bands 13 | 8. Volatility Indicator: Average True Range 14 | 9. Volume Indicator: On Balance Volume 15 | 10. Volume Indicator: Volume Weighted Average Price 16 | 17 | *[**[Click here to VIEW Chapter 5 Jupyter Notebook & interact with charts on nbviewer](https://nbviewer.jupyter.org/github/PacktPublishing/Python-Algorithmic-Trading-Cookbook/blob/master/Chapter05/CHAPTER%205.ipynb)**]* 18 | 19 | ### Requirements 20 | - Python 3.7+ 21 | - Additional Python Packages required for this chapter can be installed as follows - 22 | 23 | ``` 24 | $ source # optional, if you use a virtualenv 25 | $ cd 26 | $ pip install -r requirements.txt 27 | ``` -------------------------------------------------------------------------------- /Chapter05/images/convert_image_pdf_to_png.sh: -------------------------------------------------------------------------------- 1 | # A bash script to convert pdf to png 2 | echo $1 3 | pdftoppm "$1" "$1" -png -r 500 -singlefile 4 | convert "$1".png -trim "$1".png 5 | -------------------------------------------------------------------------------- /Chapter05/images/pdf/1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter05/images/pdf/1.pdf -------------------------------------------------------------------------------- /Chapter05/images/pdf/10.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter05/images/pdf/10.pdf -------------------------------------------------------------------------------- /Chapter05/images/pdf/2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter05/images/pdf/2.pdf -------------------------------------------------------------------------------- /Chapter05/images/pdf/3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter05/images/pdf/3.pdf -------------------------------------------------------------------------------- /Chapter05/images/pdf/4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter05/images/pdf/4.pdf -------------------------------------------------------------------------------- /Chapter05/images/pdf/5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter05/images/pdf/5.pdf -------------------------------------------------------------------------------- /Chapter05/images/pdf/6.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter05/images/pdf/6.pdf -------------------------------------------------------------------------------- /Chapter05/images/pdf/7.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter05/images/pdf/7.pdf -------------------------------------------------------------------------------- /Chapter05/images/pdf/8.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter05/images/pdf/8.pdf -------------------------------------------------------------------------------- /Chapter05/images/pdf/9.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter05/images/pdf/9.pdf -------------------------------------------------------------------------------- /Chapter05/images/png/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter05/images/png/1.png -------------------------------------------------------------------------------- /Chapter05/images/png/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter05/images/png/10.png -------------------------------------------------------------------------------- /Chapter05/images/png/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter05/images/png/2.png -------------------------------------------------------------------------------- /Chapter05/images/png/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter05/images/png/3.png -------------------------------------------------------------------------------- /Chapter05/images/png/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter05/images/png/4.png -------------------------------------------------------------------------------- /Chapter05/images/png/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter05/images/png/5.png -------------------------------------------------------------------------------- /Chapter05/images/png/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter05/images/png/6.png -------------------------------------------------------------------------------- /Chapter05/images/png/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter05/images/png/7.png -------------------------------------------------------------------------------- /Chapter05/images/png/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter05/images/png/8.png -------------------------------------------------------------------------------- /Chapter05/images/png/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter05/images/png/9.png -------------------------------------------------------------------------------- /Chapter05/requirements.txt: -------------------------------------------------------------------------------- 1 | pyalgotrading 2 | TA-Lib 3 | -------------------------------------------------------------------------------- /Chapter06/README.md: -------------------------------------------------------------------------------- 1 | ### Chapter 6: Placing Regular Orders on the Exchange 2 | Learn how to place 16 types of Regular Orders across two transaction types, 3 | two order codes and four order varieties. Learn to query the order status in 4 | real-time. Also, learn about the possible order states supported by the broker 5 | and the order life-cycle for Regular Orders. 6 | 7 | ### List of Recipes in this chapter 8 | 1. Placing a Regular Market Order 9 | - Buy, Regular, Intraday, Market Order 10 | - Sell, Regular, Intraday, Market Order 11 | - Buy, Regular, Delivery, Market Order 12 | - Sell, Regular, Delivery, Market Order 13 | 2. Placing a Regular Limit Order 14 | - Buy, Regular, Intraday, Limit Order 15 | - Sell, Regular, Intraday, Limit Order 16 | - Buy, Regular, Delivery, Limit Order 17 | - Sell, Regular, Delivery, Limit Order 18 | 3. Placing a Regular Stoploss-Limit Order 19 | - Buy, Regular, Intraday, Stoploss-Limit Order 20 | - Sell, Regular, Intraday, Stoploss-Limit Order 21 | - Buy, Regular, Delivery, Stoploss-Limit Order 22 | - Sell, Regular, Delivery, Stoploss-Limit Order 23 | 4. Placing a Regular Stoploss-Market Order 24 | - Buy, Regular, Intraday, Stoploss-Market Order 25 | - Sell, Regular, Intraday, Stoploss-Market Order 26 | - Buy, Regular, Delivery, Stoploss-Market Order 27 | - Sell, Regular, Delivery, Stoploss-Market Order 28 | 29 | *[**[Click here to VIEW Chapter 6 Jupyter Notebook on nbviewer](https://nbviewer.jupyter.org/github/PacktPublishing/Python-Algorithmic-Trading-Cookbook/blob/master/Chapter06/CHAPTER%206.ipynb)**]* 30 |
31 | *[**[Click here to RUN Chapter 6 Jupyter Notebook in the cloud using binder. No installation needed on your end.](https://mybinder.org/v2/gh/PacktPublishing/Python-Algorithmic-Trading-Cookbook/master?filepath=Chapter06/CHAPTER%206.ipynb)**]* 32 | 33 | ### Requirements 34 | - Python 3.7+ 35 | - Additional Python Packages required for this chapter can be installed as follows - 36 | 37 | ``` 38 | $ source # optional, if you use a virtualenv 39 | $ cd 40 | $ pip install -r requirements.txt 41 | ``` -------------------------------------------------------------------------------- /Chapter06/images/diagrams/bracket-order-flowchart.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/diagrams/bracket-order-flowchart.dia -------------------------------------------------------------------------------- /Chapter06/images/diagrams/bracket-order-flowchart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/diagrams/bracket-order-flowchart.png -------------------------------------------------------------------------------- /Chapter06/images/diagrams/cover-order-flowchart.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/diagrams/cover-order-flowchart.dia -------------------------------------------------------------------------------- /Chapter06/images/diagrams/cover-order-flowchart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/diagrams/cover-order-flowchart.png -------------------------------------------------------------------------------- /Chapter06/images/diagrams/regular-limit-order-state-diagram.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/diagrams/regular-limit-order-state-diagram.dia -------------------------------------------------------------------------------- /Chapter06/images/diagrams/regular-limit-order-state-diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/diagrams/regular-limit-order-state-diagram.png -------------------------------------------------------------------------------- /Chapter06/images/diagrams/regular-limit-order-state-diagram2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/diagrams/regular-limit-order-state-diagram2.png -------------------------------------------------------------------------------- /Chapter06/images/diagrams/regular-market-order-state-diagram.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/diagrams/regular-market-order-state-diagram.dia -------------------------------------------------------------------------------- /Chapter06/images/diagrams/regular-market-order-state-diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/diagrams/regular-market-order-state-diagram.png -------------------------------------------------------------------------------- /Chapter06/images/diagrams/regular-stoploss-limit-order-state-diagram.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/diagrams/regular-stoploss-limit-order-state-diagram.dia -------------------------------------------------------------------------------- /Chapter06/images/diagrams/regular-stoploss-limit-order-state-diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/diagrams/regular-stoploss-limit-order-state-diagram.png -------------------------------------------------------------------------------- /Chapter06/images/diagrams/regular-stoploss-market-order-state-diagram.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/diagrams/regular-stoploss-market-order-state-diagram.dia -------------------------------------------------------------------------------- /Chapter06/images/diagrams/regular-stoploss-market-order-state-diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/diagrams/regular-stoploss-market-order-state-diagram.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe10_child1_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe10_child1_open.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe10_order1_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe10_order1_open.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe10_order2_complete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe10_order2_complete.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe10_order2_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe10_order2_open.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe1_order1_complete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe1_order1_complete.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe1_order2_complete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe1_order2_complete.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe1_order3_complete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe1_order3_complete.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe1_order4_complete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe1_order4_complete.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe2_order1_complete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe2_order1_complete.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe2_order1_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe2_order1_open.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe2_order2_complete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe2_order2_complete.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe2_order2_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe2_order2_open.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe2_order3_complete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe2_order3_complete.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe2_order3_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe2_order3_open.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe2_order4_complete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe2_order4_complete.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe2_order4_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe2_order4_open.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe3_order1_complete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe3_order1_complete.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe3_order1_trigger_pending.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe3_order1_trigger_pending.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe3_order2_complete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe3_order2_complete.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe3_order2_trigger_pending.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe3_order2_trigger_pending.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe3_order3_complete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe3_order3_complete.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe3_order3_trigger_pending.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe3_order3_trigger_pending.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe3_order4_complete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe3_order4_complete.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe4_order1_complete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe4_order1_complete.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe4_order1_trigger_pending.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe4_order1_trigger_pending.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe4_order1_trigger_pending_old.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe4_order1_trigger_pending_old.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe4_order2_complete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe4_order2_complete.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe4_order2_trigger_pending.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe4_order2_trigger_pending.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe4_order3_complete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe4_order3_complete.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe4_order3_complete_old.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe4_order3_complete_old.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe4_order3_trigger_pending.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe4_order3_trigger_pending.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe4_order3_trigger_pending_old.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe4_order3_trigger_pending_old.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe4_order4_compelte.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe4_order4_compelte.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe4_order4_trigger_pending.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe4_order4_trigger_pending.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe5_order1_child1_cancelled_on_exit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe5_order1_child1_cancelled_on_exit.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe5_order1_child1_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe5_order1_child1_open.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe5_order1_child2_complete_on_exit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe5_order1_child2_complete_on_exit.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe5_order1_child2_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe5_order1_child2_open.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe5_order1_complete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe5_order1_complete.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe5_order1_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe5_order1_open.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe5_order2_complete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe5_order2_complete.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe5_order2_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe5_order2_open.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe9_order1_child1_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe9_order1_child1_open.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe9_order1_child1_trigger_pending.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe9_order1_child1_trigger_pending.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe9_order1_complete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe9_order1_complete.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe9_order1_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe9_order1_open.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe9_order2_child1_trigger_pending.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe9_order2_child1_trigger_pending.png -------------------------------------------------------------------------------- /Chapter06/images/screenshots/recipe9_order2_complete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/screenshots/recipe9_order2_complete.png -------------------------------------------------------------------------------- /Chapter06/images/unsorted/bankbaroda/Selection_035.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/unsorted/bankbaroda/Selection_035.png -------------------------------------------------------------------------------- /Chapter06/images/unsorted/bankbaroda/Selection_045.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/unsorted/bankbaroda/Selection_045.png -------------------------------------------------------------------------------- /Chapter06/images/unsorted/bankbaroda/Selection_046.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/unsorted/bankbaroda/Selection_046.png -------------------------------------------------------------------------------- /Chapter06/images/unsorted/bankbaroda/Selection_047.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/unsorted/bankbaroda/Selection_047.png -------------------------------------------------------------------------------- /Chapter06/images/unsorted/icicibank/Selection_034.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/unsorted/icicibank/Selection_034.png -------------------------------------------------------------------------------- /Chapter06/images/unsorted/kotak/recipe4_order3_trigger_pending.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/unsorted/kotak/recipe4_order3_trigger_pending.png -------------------------------------------------------------------------------- /Chapter06/images/unsorted/sbin/Selection_041.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/unsorted/sbin/Selection_041.png -------------------------------------------------------------------------------- /Chapter06/images/unsorted/sbin/Selection_042.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/unsorted/sbin/Selection_042.png -------------------------------------------------------------------------------- /Chapter06/images/unsorted/sbin/Selection_043.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/unsorted/sbin/Selection_043.png -------------------------------------------------------------------------------- /Chapter06/images/unsorted/sbin/Selection_044.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/unsorted/sbin/Selection_044.png -------------------------------------------------------------------------------- /Chapter06/images/unsorted/sbin/recipe5_order2_complete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter06/images/unsorted/sbin/recipe5_order2_complete.png -------------------------------------------------------------------------------- /Chapter06/requirements.txt: -------------------------------------------------------------------------------- 1 | pyalgotrading 2 | -------------------------------------------------------------------------------- /Chapter07/CHAPTER 7.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Python Algorithmic Trading Cookbook" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Chapter 7: Placing Bracket and Cover Orders on the Exchange" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "This Jupyter Notebook is created using Python version 3.8.2" 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "----" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "### Requirements" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "You can install the requirements for this Jupyter Notebook by executing the below cell" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 0, 48 | "metadata": {}, 49 | "outputs": [], 50 | "source": [ 51 | "!pip install pyalgotrading" 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": {}, 57 | "source": [ 58 | "----" 59 | ] 60 | }, 61 | { 62 | "cell_type": "markdown", 63 | "metadata": {}, 64 | "source": [ 65 | "### Master Recipe\n", 66 | "\n", 67 | "The following code will help you set up the broker connection with Zerodha, which will be used by all the recipes in this chapter. Please make sure you have followed these steps before trying out any recipe. " 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": 1, 73 | "metadata": {}, 74 | "outputs": [], 75 | "source": [ 76 | "from pyalgotrading.broker.broker_connection_zerodha import BrokerConnectionZerodha\n", 77 | "from pyalgotrading.constants import *" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 2, 83 | "metadata": {}, 84 | "outputs": [ 85 | { 86 | "name": "stdout", 87 | "output_type": "stream", 88 | "text": [ 89 | "Installing package kiteconnect via pip. This may take a while...\n", 90 | "Please login to this link to generate your request token: https://kite.trade/connect/login?api_key=&v=3\n" 91 | ] 92 | } 93 | ], 94 | "source": [ 95 | "# Get the api_key and api_secret from broker. These are unique to you and will be used by the broker to identify your demat account.\n", 96 | "api_key = \"\"\n", 97 | "api_secret = \"\"\n", 98 | "broker_connection = BrokerConnectionZerodha(api_key, api_secret)" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": 3, 104 | "metadata": {}, 105 | "outputs": [], 106 | "source": [ 107 | "# Get the request token from the above URL\n", 108 | "request_token = \"\"\n", 109 | "broker_connection.set_access_token(request_token)" 110 | ] 111 | }, 112 | { 113 | "cell_type": "markdown", 114 | "metadata": {}, 115 | "source": [ 116 | "----" 117 | ] 118 | }, 119 | { 120 | "cell_type": "markdown", 121 | "metadata": {}, 122 | "source": [ 123 | "### Recipe 1: Placing a Bracket Limit Order" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": 4, 129 | "metadata": {}, 130 | "outputs": [], 131 | "source": [ 132 | "instrument = broker_connection.get_instrument('NSE', 'SBIN')" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": 5, 138 | "metadata": {}, 139 | "outputs": [ 140 | { 141 | "data": { 142 | "text/plain": [ 143 | "'2003030003491923'" 144 | ] 145 | }, 146 | "execution_count": 5, 147 | "metadata": {}, 148 | "output_type": "execute_result" 149 | } 150 | ], 151 | "source": [ 152 | "# Place a Buy, Bracket, Intraday, Limit order\n", 153 | "ltp = broker_connection.get_ltp(instrument)\n", 154 | "\n", 155 | "order1_id = broker_connection.place_order(instrument=instrument,\n", 156 | " order_transaction_type=BrokerOrderTransactionTypeConstants.BUY,\n", 157 | " order_type=BrokerOrderTypeConstants.BRACKET,\n", 158 | " order_code=BrokerOrderCodeConstants.INTRADAY,\n", 159 | " order_variety=BrokerOrderVarietyConstants.LIMIT,\n", 160 | " quantity=1,\n", 161 | " price=ltp-1,\n", 162 | " stoploss=2,\n", 163 | " target=2)\n", 164 | "\n", 165 | "order1_id" 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": 6, 171 | "metadata": {}, 172 | "outputs": [ 173 | { 174 | "data": { 175 | "text/plain": [ 176 | "'OPEN'" 177 | ] 178 | }, 179 | "execution_count": 6, 180 | "metadata": {}, 181 | "output_type": "execute_result" 182 | } 183 | ], 184 | "source": [ 185 | "broker_connection.get_order_status(order1_id)" 186 | ] 187 | }, 188 | { 189 | "cell_type": "code", 190 | "execution_count": 7, 191 | "metadata": {}, 192 | "outputs": [ 193 | { 194 | "data": { 195 | "text/plain": [ 196 | "'COMPLETE'" 197 | ] 198 | }, 199 | "execution_count": 7, 200 | "metadata": {}, 201 | "output_type": "execute_result" 202 | } 203 | ], 204 | "source": [ 205 | "broker_connection.get_order_status(order1_id)" 206 | ] 207 | }, 208 | { 209 | "cell_type": "code", 210 | "execution_count": 8, 211 | "metadata": {}, 212 | "outputs": [ 213 | { 214 | "data": { 215 | "text/plain": [ 216 | "'200303003639902'" 217 | ] 218 | }, 219 | "execution_count": 8, 220 | "metadata": {}, 221 | "output_type": "execute_result" 222 | } 223 | ], 224 | "source": [ 225 | "# Place a Sell, Bracket, Intraday, Limit order\n", 226 | "ltp = broker_connection.get_ltp(instrument)\n", 227 | "\n", 228 | "order2_id = broker_connection.place_order(instrument=instrument,\n", 229 | " order_transaction_type=BrokerOrderTransactionTypeConstants.SELL,\n", 230 | " order_type=BrokerOrderTypeConstants.BRACKET,\n", 231 | " order_code=BrokerOrderCodeConstants.INTRADAY,\n", 232 | " order_variety=BrokerOrderVarietyConstants.LIMIT,\n", 233 | " quantity=1,\n", 234 | " price=ltp+1,\n", 235 | " stoploss=2,\n", 236 | " target=2)\n", 237 | "\n", 238 | "order2_id" 239 | ] 240 | }, 241 | { 242 | "cell_type": "code", 243 | "execution_count": 9, 244 | "metadata": {}, 245 | "outputs": [ 246 | { 247 | "data": { 248 | "text/plain": [ 249 | "'OPEN'" 250 | ] 251 | }, 252 | "execution_count": 9, 253 | "metadata": {}, 254 | "output_type": "execute_result" 255 | } 256 | ], 257 | "source": [ 258 | "broker_connection.get_order_status(order2_id)" 259 | ] 260 | }, 261 | { 262 | "cell_type": "code", 263 | "execution_count": 10, 264 | "metadata": {}, 265 | "outputs": [ 266 | { 267 | "data": { 268 | "text/plain": [ 269 | "'COMPLETE'" 270 | ] 271 | }, 272 | "execution_count": 10, 273 | "metadata": {}, 274 | "output_type": "execute_result" 275 | } 276 | ], 277 | "source": [ 278 | "broker_connection.get_order_status(order2_id)" 279 | ] 280 | }, 281 | { 282 | "cell_type": "markdown", 283 | "metadata": {}, 284 | "source": [ 285 | "### Recipe 2: Placing a Bracket Stoploss-Limit Order" 286 | ] 287 | }, 288 | { 289 | "cell_type": "code", 290 | "execution_count": 11, 291 | "metadata": {}, 292 | "outputs": [], 293 | "source": [ 294 | "instrument = broker_connection.get_instrument('NSE', 'INDUSINDBK')" 295 | ] 296 | }, 297 | { 298 | "cell_type": "code", 299 | "execution_count": 12, 300 | "metadata": {}, 301 | "outputs": [ 302 | { 303 | "data": { 304 | "text/plain": [ 305 | "'200226003619998'" 306 | ] 307 | }, 308 | "execution_count": 12, 309 | "metadata": {}, 310 | "output_type": "execute_result" 311 | } 312 | ], 313 | "source": [ 314 | "# Place a Buy, Bracket, Intraday, Stoploss Limit order\n", 315 | "ltp = broker_connection.get_ltp(instrument)\n", 316 | "\n", 317 | "order1_id = broker_connection.place_order(instrument=instrument,\n", 318 | " order_transaction_type=BrokerOrderTransactionTypeConstants.BUY,\n", 319 | " order_type=BrokerOrderTypeConstants.BRACKET,\n", 320 | " order_code=BrokerOrderCodeConstants.INTRADAY,\n", 321 | " order_variety=BrokerOrderVarietyConstants.STOPLOSS_LIMIT,\n", 322 | " quantity=1,\n", 323 | " price=ltp+1,\n", 324 | " trigger_price=ltp+1,\n", 325 | " stoploss=2,\n", 326 | " target=2)\n", 327 | "\n", 328 | "order1_id" 329 | ] 330 | }, 331 | { 332 | "cell_type": "code", 333 | "execution_count": 13, 334 | "metadata": {}, 335 | "outputs": [ 336 | { 337 | "data": { 338 | "text/plain": [ 339 | "'TRIGGER PENDING'" 340 | ] 341 | }, 342 | "execution_count": 13, 343 | "metadata": {}, 344 | "output_type": "execute_result" 345 | } 346 | ], 347 | "source": [ 348 | "broker_connection.get_order_status(order1_id)" 349 | ] 350 | }, 351 | { 352 | "cell_type": "code", 353 | "execution_count": 14, 354 | "metadata": {}, 355 | "outputs": [ 356 | { 357 | "data": { 358 | "text/plain": [ 359 | "'COMPLETE'" 360 | ] 361 | }, 362 | "execution_count": 14, 363 | "metadata": {}, 364 | "output_type": "execute_result" 365 | } 366 | ], 367 | "source": [ 368 | "broker_connection.get_order_status(order1_id)" 369 | ] 370 | }, 371 | { 372 | "cell_type": "code", 373 | "execution_count": 15, 374 | "metadata": {}, 375 | "outputs": [ 376 | { 377 | "data": { 378 | "text/plain": [ 379 | "'200226003620002'" 380 | ] 381 | }, 382 | "execution_count": 15, 383 | "metadata": {}, 384 | "output_type": "execute_result" 385 | } 386 | ], 387 | "source": [ 388 | "# Place a Sell, Bracket, Intraday, Stoploss Limit order\n", 389 | "ltp = broker_connection.get_ltp(instrument)\n", 390 | "\n", 391 | "order2_id = broker_connection.place_order(instrument=instrument,\n", 392 | " order_transaction_type=BrokerOrderTransactionTypeConstants.SELL,\n", 393 | " order_type=BrokerOrderTypeConstants.BRACKET,\n", 394 | " order_code=BrokerOrderCodeConstants.INTRADAY,\n", 395 | " order_variety=BrokerOrderVarietyConstants.STOPLOSS_LIMIT,\n", 396 | " quantity=1,\n", 397 | " price=ltp-1,\n", 398 | " trigger_price=ltp-1,\n", 399 | " stoploss=2,\n", 400 | " target=2)\n", 401 | "\n", 402 | "order2_id" 403 | ] 404 | }, 405 | { 406 | "cell_type": "code", 407 | "execution_count": 16, 408 | "metadata": {}, 409 | "outputs": [ 410 | { 411 | "data": { 412 | "text/plain": [ 413 | "'TRIGGER PENDING'" 414 | ] 415 | }, 416 | "execution_count": 16, 417 | "metadata": {}, 418 | "output_type": "execute_result" 419 | } 420 | ], 421 | "source": [ 422 | "broker_connection.get_order_status(order2_id)" 423 | ] 424 | }, 425 | { 426 | "cell_type": "code", 427 | "execution_count": 17, 428 | "metadata": {}, 429 | "outputs": [ 430 | { 431 | "data": { 432 | "text/plain": [ 433 | "'COMPLETE'" 434 | ] 435 | }, 436 | "execution_count": 17, 437 | "metadata": {}, 438 | "output_type": "execute_result" 439 | } 440 | ], 441 | "source": [ 442 | "broker_connection.get_order_status(order2_id)" 443 | ] 444 | }, 445 | { 446 | "cell_type": "markdown", 447 | "metadata": {}, 448 | "source": [ 449 | "### Recipe 3: Placing a Bracket Limit Order with Trailing Stoploss" 450 | ] 451 | }, 452 | { 453 | "cell_type": "code", 454 | "execution_count": 18, 455 | "metadata": {}, 456 | "outputs": [], 457 | "source": [ 458 | "instrument = broker_connection.get_instrument('NSE', 'FEDERALBNK')" 459 | ] 460 | }, 461 | { 462 | "cell_type": "code", 463 | "execution_count": 19, 464 | "metadata": {}, 465 | "outputs": [ 466 | { 467 | "data": { 468 | "text/plain": [ 469 | "'200226003620004'" 470 | ] 471 | }, 472 | "execution_count": 19, 473 | "metadata": {}, 474 | "output_type": "execute_result" 475 | } 476 | ], 477 | "source": [ 478 | "# Place a Buy, Bracket, Intraday, Limit order\n", 479 | "ltp = broker_connection.get_ltp(instrument)\n", 480 | "\n", 481 | "order1_id = broker_connection.place_order(instrument=instrument,\n", 482 | " order_transaction_type=BrokerOrderTransactionTypeConstants.BUY,\n", 483 | " order_type=BrokerOrderTypeConstants.BRACKET,\n", 484 | " order_code=BrokerOrderCodeConstants.INTRADAY,\n", 485 | " order_variety=BrokerOrderVarietyConstants.LIMIT,\n", 486 | " quantity=1,\n", 487 | " price=ltp-1,\n", 488 | " trigger_price=ltp-1,\n", 489 | " stoploss=2,\n", 490 | " target=2,\n", 491 | " trailing_stoploss=1)\n", 492 | "\n", 493 | "order1_id" 494 | ] 495 | }, 496 | { 497 | "cell_type": "code", 498 | "execution_count": 20, 499 | "metadata": {}, 500 | "outputs": [ 501 | { 502 | "data": { 503 | "text/plain": [ 504 | "'OPEN'" 505 | ] 506 | }, 507 | "execution_count": 20, 508 | "metadata": {}, 509 | "output_type": "execute_result" 510 | } 511 | ], 512 | "source": [ 513 | "broker_connection.get_order_status(order1_id)" 514 | ] 515 | }, 516 | { 517 | "cell_type": "code", 518 | "execution_count": 21, 519 | "metadata": {}, 520 | "outputs": [ 521 | { 522 | "data": { 523 | "text/plain": [ 524 | "'COMPLETE'" 525 | ] 526 | }, 527 | "execution_count": 21, 528 | "metadata": {}, 529 | "output_type": "execute_result" 530 | } 531 | ], 532 | "source": [ 533 | "broker_connection.get_order_status(order1_id)" 534 | ] 535 | }, 536 | { 537 | "cell_type": "code", 538 | "execution_count": 22, 539 | "metadata": {}, 540 | "outputs": [ 541 | { 542 | "data": { 543 | "text/plain": [ 544 | "'200226003620009'" 545 | ] 546 | }, 547 | "execution_count": 22, 548 | "metadata": {}, 549 | "output_type": "execute_result" 550 | } 551 | ], 552 | "source": [ 553 | "# Place a Sell, Bracket, Intraday, Limit order\n", 554 | "ltp = broker_connection.get_ltp(instrument)\n", 555 | "\n", 556 | "order2_id = broker_connection.place_order(instrument=instrument,\n", 557 | " order_transaction_type=BrokerOrderTransactionTypeConstants.SELL,\n", 558 | " order_type=BrokerOrderTypeConstants.BRACKET,\n", 559 | " order_code=BrokerOrderCodeConstants.INTRADAY,\n", 560 | " order_variety=BrokerOrderVarietyConstants.LIMIT,\n", 561 | " quantity=1,\n", 562 | " price=ltp+1,\n", 563 | " trigger_price=ltp+1,\n", 564 | " stoploss=2,\n", 565 | " target=2,\n", 566 | " trailing_stoploss=1)\n", 567 | "\n", 568 | "order1_id" 569 | ] 570 | }, 571 | { 572 | "cell_type": "code", 573 | "execution_count": 23, 574 | "metadata": {}, 575 | "outputs": [ 576 | { 577 | "data": { 578 | "text/plain": [ 579 | "'OPEN'" 580 | ] 581 | }, 582 | "execution_count": 23, 583 | "metadata": {}, 584 | "output_type": "execute_result" 585 | } 586 | ], 587 | "source": [ 588 | "broker_connection.get_order_status(order2_id)" 589 | ] 590 | }, 591 | { 592 | "cell_type": "code", 593 | "execution_count": 24, 594 | "metadata": {}, 595 | "outputs": [ 596 | { 597 | "data": { 598 | "text/plain": [ 599 | "'COMPLETE'" 600 | ] 601 | }, 602 | "execution_count": 24, 603 | "metadata": {}, 604 | "output_type": "execute_result" 605 | } 606 | ], 607 | "source": [ 608 | "broker_connection.get_order_status(order2_id)" 609 | ] 610 | }, 611 | { 612 | "cell_type": "markdown", 613 | "metadata": {}, 614 | "source": [ 615 | "### Recipe 4: Placing a Bracket Stoploss-Limit Order with Trailing Stoploss" 616 | ] 617 | }, 618 | { 619 | "cell_type": "code", 620 | "execution_count": 25, 621 | "metadata": {}, 622 | "outputs": [], 623 | "source": [ 624 | "instrument = broker_connection.get_instrument('NSE', 'RBLBANK')" 625 | ] 626 | }, 627 | { 628 | "cell_type": "code", 629 | "execution_count": 26, 630 | "metadata": {}, 631 | "outputs": [ 632 | { 633 | "data": { 634 | "text/plain": [ 635 | "'200226003620011'" 636 | ] 637 | }, 638 | "execution_count": 26, 639 | "metadata": {}, 640 | "output_type": "execute_result" 641 | } 642 | ], 643 | "source": [ 644 | "# Place a Buy, Bracket, Intraday, Limit order\n", 645 | "ltp = broker_connection.get_ltp(instrument)\n", 646 | "\n", 647 | "order1_id = broker_connection.place_order(instrument=instrument,\n", 648 | " order_transaction_type=BrokerOrderTransactionTypeConstants.BUY,\n", 649 | " order_type=BrokerOrderTypeConstants.BRACKET,\n", 650 | " order_code=BrokerOrderCodeConstants.INTRADAY,\n", 651 | " order_variety=BrokerOrderVarietyConstants.STOPLOSS_LIMIT,\n", 652 | " quantity=1,\n", 653 | " price=ltp+1,\n", 654 | " trigger_price=ltp+1,\n", 655 | " stoploss=2,\n", 656 | " target=2,\n", 657 | " trailing_stoploss=1)\n", 658 | "\n", 659 | "order1_id" 660 | ] 661 | }, 662 | { 663 | "cell_type": "code", 664 | "execution_count": 27, 665 | "metadata": {}, 666 | "outputs": [ 667 | { 668 | "data": { 669 | "text/plain": [ 670 | "'TRIGGER PENDING'" 671 | ] 672 | }, 673 | "execution_count": 27, 674 | "metadata": {}, 675 | "output_type": "execute_result" 676 | } 677 | ], 678 | "source": [ 679 | "broker_connection.get_order_status(order1_id)" 680 | ] 681 | }, 682 | { 683 | "cell_type": "code", 684 | "execution_count": 28, 685 | "metadata": {}, 686 | "outputs": [ 687 | { 688 | "data": { 689 | "text/plain": [ 690 | "'COMPLETE'" 691 | ] 692 | }, 693 | "execution_count": 28, 694 | "metadata": {}, 695 | "output_type": "execute_result" 696 | } 697 | ], 698 | "source": [ 699 | "broker_connection.get_order_status(order1_id)" 700 | ] 701 | }, 702 | { 703 | "cell_type": "code", 704 | "execution_count": 29, 705 | "metadata": {}, 706 | "outputs": [ 707 | { 708 | "data": { 709 | "text/plain": [ 710 | "'200226003620023'" 711 | ] 712 | }, 713 | "execution_count": 29, 714 | "metadata": {}, 715 | "output_type": "execute_result" 716 | } 717 | ], 718 | "source": [ 719 | "# Place a Sell, Bracket, Intraday, Limit order\n", 720 | "ltp = broker_connection.get_ltp(instrument)\n", 721 | "\n", 722 | "order2_id = broker_connection.place_order(instrument=instrument,\n", 723 | " order_transaction_type=BrokerOrderTransactionTypeConstants.SELL,\n", 724 | " order_type=BrokerOrderTypeConstants.BRACKET,\n", 725 | " order_code=BrokerOrderCodeConstants.INTRADAY,\n", 726 | " order_variety=BrokerOrderVarietyConstants.STOPLOSS_LIMIT,\n", 727 | " quantity=1,\n", 728 | " price=ltp-1,\n", 729 | " trigger_price=ltp-1,\n", 730 | " stoploss=2,\n", 731 | " target=2,\n", 732 | " trailing_stoploss=1)\n", 733 | "\n", 734 | "order2_id" 735 | ] 736 | }, 737 | { 738 | "cell_type": "code", 739 | "execution_count": 30, 740 | "metadata": {}, 741 | "outputs": [ 742 | { 743 | "data": { 744 | "text/plain": [ 745 | "'TRIGGER PENDING'" 746 | ] 747 | }, 748 | "execution_count": 30, 749 | "metadata": {}, 750 | "output_type": "execute_result" 751 | } 752 | ], 753 | "source": [ 754 | "broker_connection.get_order_status(order2_id)" 755 | ] 756 | }, 757 | { 758 | "cell_type": "code", 759 | "execution_count": 31, 760 | "metadata": {}, 761 | "outputs": [ 762 | { 763 | "data": { 764 | "text/plain": [ 765 | "'COMPLETE'" 766 | ] 767 | }, 768 | "execution_count": 31, 769 | "metadata": {}, 770 | "output_type": "execute_result" 771 | } 772 | ], 773 | "source": [ 774 | "broker_connection.get_order_status(order2_id)" 775 | ] 776 | }, 777 | { 778 | "cell_type": "markdown", 779 | "metadata": {}, 780 | "source": [ 781 | "### Recipe 5: Placing a Cover Market Order" 782 | ] 783 | }, 784 | { 785 | "cell_type": "code", 786 | "execution_count": 32, 787 | "metadata": {}, 788 | "outputs": [], 789 | "source": [ 790 | "instrument = broker_connection.get_instrument('NSE', 'BANKBARODA')" 791 | ] 792 | }, 793 | { 794 | "cell_type": "code", 795 | "execution_count": 33, 796 | "metadata": {}, 797 | "outputs": [ 798 | { 799 | "data": { 800 | "text/plain": [ 801 | "'200303003717532'" 802 | ] 803 | }, 804 | "execution_count": 33, 805 | "metadata": {}, 806 | "output_type": "execute_result" 807 | } 808 | ], 809 | "source": [ 810 | "# Place a Buy, Cover, Intraday, Market order\n", 811 | "ltp = broker_connection.get_ltp(instrument)\n", 812 | "\n", 813 | "order1_id = broker_connection.place_order(instrument=instrument,\n", 814 | " order_transaction_type=BrokerOrderTransactionTypeConstants.BUY,\n", 815 | " order_type=BrokerOrderTypeConstants.COVER,\n", 816 | " order_code=BrokerOrderCodeConstants.INTRADAY,\n", 817 | " order_variety=BrokerOrderVarietyConstants.MARKET,\n", 818 | " quantity=1,\n", 819 | " trigger_price=ltp-1)\n", 820 | "\n", 821 | "order1_id" 822 | ] 823 | }, 824 | { 825 | "cell_type": "code", 826 | "execution_count": 34, 827 | "metadata": {}, 828 | "outputs": [ 829 | { 830 | "data": { 831 | "text/plain": [ 832 | "'COMPLETE'" 833 | ] 834 | }, 835 | "execution_count": 34, 836 | "metadata": {}, 837 | "output_type": "execute_result" 838 | } 839 | ], 840 | "source": [ 841 | "broker_connection.get_order_status(order1_id)" 842 | ] 843 | }, 844 | { 845 | "cell_type": "code", 846 | "execution_count": 35, 847 | "metadata": {}, 848 | "outputs": [ 849 | { 850 | "data": { 851 | "text/plain": [ 852 | "'200303003732941'" 853 | ] 854 | }, 855 | "execution_count": 35, 856 | "metadata": {}, 857 | "output_type": "execute_result" 858 | } 859 | ], 860 | "source": [ 861 | "# Place a Sell, Cover, Intraday, Market order\n", 862 | "ltp = broker_connection.get_ltp(instrument)\n", 863 | "\n", 864 | "order2_id = broker_connection.place_order(instrument=instrument,\n", 865 | " order_transaction_type=BrokerOrderTransactionTypeConstants.SELL,\n", 866 | " order_type=BrokerOrderTypeConstants.COVER,\n", 867 | " order_code=BrokerOrderCodeConstants.INTRADAY,\n", 868 | " order_variety=BrokerOrderVarietyConstants.MARKET,\n", 869 | " quantity=1,\n", 870 | " trigger_price=ltp+1)\n", 871 | "\n", 872 | "order2_id" 873 | ] 874 | }, 875 | { 876 | "cell_type": "code", 877 | "execution_count": 36, 878 | "metadata": {}, 879 | "outputs": [ 880 | { 881 | "data": { 882 | "text/plain": [ 883 | "'COMPLETE'" 884 | ] 885 | }, 886 | "execution_count": 36, 887 | "metadata": {}, 888 | "output_type": "execute_result" 889 | } 890 | ], 891 | "source": [ 892 | "broker_connection.get_order_status(order2_id)" 893 | ] 894 | }, 895 | { 896 | "cell_type": "markdown", 897 | "metadata": {}, 898 | "source": [ 899 | "### Recipe 6: Placing a Cover Limit Order" 900 | ] 901 | }, 902 | { 903 | "cell_type": "code", 904 | "execution_count": 37, 905 | "metadata": {}, 906 | "outputs": [], 907 | "source": [ 908 | "instrument = broker_connection.get_instrument('NSE', 'YESBANK')" 909 | ] 910 | }, 911 | { 912 | "cell_type": "code", 913 | "execution_count": 38, 914 | "metadata": {}, 915 | "outputs": [ 916 | { 917 | "data": { 918 | "text/plain": [ 919 | "'200303003749622’" 920 | ] 921 | }, 922 | "execution_count": 38, 923 | "metadata": {}, 924 | "output_type": "execute_result" 925 | } 926 | ], 927 | "source": [ 928 | "# Place a Buy, Cover, Intraday, Limit order\n", 929 | "ltp = broker_connection.get_ltp(instrument)\n", 930 | "\n", 931 | "order1_id = broker_connection.place_order(instrument=instrument,\n", 932 | " order_transaction_type=BrokerOrderTransactionTypeConstants.BUY,\n", 933 | " order_type=BrokerOrderTypeConstants.COVER,\n", 934 | " order_code=BrokerOrderCodeConstants.INTRADAY,\n", 935 | " order_variety=BrokerOrderVarietyConstants.LIMIT,\n", 936 | " quantity=1,\n", 937 | " price=ltp-0.5,\n", 938 | " trigger_price=ltp-1)\n", 939 | "\n", 940 | "order1_id" 941 | ] 942 | }, 943 | { 944 | "cell_type": "code", 945 | "execution_count": 39, 946 | "metadata": {}, 947 | "outputs": [ 948 | { 949 | "data": { 950 | "text/plain": [ 951 | "'OPEN'" 952 | ] 953 | }, 954 | "execution_count": 39, 955 | "metadata": {}, 956 | "output_type": "execute_result" 957 | } 958 | ], 959 | "source": [ 960 | "broker_connection.get_order_status(order1_id)" 961 | ] 962 | }, 963 | { 964 | "cell_type": "code", 965 | "execution_count": 40, 966 | "metadata": {}, 967 | "outputs": [ 968 | { 969 | "data": { 970 | "text/plain": [ 971 | "'COMPLETE'" 972 | ] 973 | }, 974 | "execution_count": 40, 975 | "metadata": {}, 976 | "output_type": "execute_result" 977 | } 978 | ], 979 | "source": [ 980 | "broker_connection.get_order_status(order1_id)" 981 | ] 982 | }, 983 | { 984 | "cell_type": "code", 985 | "execution_count": 41, 986 | "metadata": {}, 987 | "outputs": [ 988 | { 989 | "data": { 990 | "text/plain": [ 991 | "'200303003751757'" 992 | ] 993 | }, 994 | "execution_count": 41, 995 | "metadata": {}, 996 | "output_type": "execute_result" 997 | } 998 | ], 999 | "source": [ 1000 | "# Place a Sell, Cover, Intraday, Limit order\n", 1001 | "ltp = broker_connection.get_ltp(instrument)\n", 1002 | "\n", 1003 | "order2_id = broker_connection.place_order(instrument=instrument,\n", 1004 | " order_transaction_type=BrokerOrderTransactionTypeConstants.SELL,\n", 1005 | " order_type=BrokerOrderTypeConstants.COVER,\n", 1006 | " order_code=BrokerOrderCodeConstants.INTRADAY,\n", 1007 | " order_variety=BrokerOrderVarietyConstants.LIMIT,\n", 1008 | " quantity=1,\n", 1009 | " price=ltp+0.5,\n", 1010 | " trigger_price=ltp+1)\n", 1011 | "\n", 1012 | "order2_id" 1013 | ] 1014 | }, 1015 | { 1016 | "cell_type": "code", 1017 | "execution_count": 42, 1018 | "metadata": {}, 1019 | "outputs": [ 1020 | { 1021 | "data": { 1022 | "text/plain": [ 1023 | "'OPEN'" 1024 | ] 1025 | }, 1026 | "execution_count": 42, 1027 | "metadata": {}, 1028 | "output_type": "execute_result" 1029 | } 1030 | ], 1031 | "source": [ 1032 | "broker_connection.get_order_status(order2_id)" 1033 | ] 1034 | }, 1035 | { 1036 | "cell_type": "code", 1037 | "execution_count": 43, 1038 | "metadata": {}, 1039 | "outputs": [ 1040 | { 1041 | "data": { 1042 | "text/plain": [ 1043 | "'COMPLETE'" 1044 | ] 1045 | }, 1046 | "execution_count": 43, 1047 | "metadata": {}, 1048 | "output_type": "execute_result" 1049 | } 1050 | ], 1051 | "source": [ 1052 | "broker_connection.get_order_status(order2_id)" 1053 | ] 1054 | } 1055 | ], 1056 | "metadata": { 1057 | "kernelspec": { 1058 | "display_name": "Python 3", 1059 | "language": "python", 1060 | "name": "python3" 1061 | }, 1062 | "language_info": { 1063 | "codemirror_mode": { 1064 | "name": "ipython", 1065 | "version": 3 1066 | }, 1067 | "file_extension": ".py", 1068 | "mimetype": "text/x-python", 1069 | "name": "python", 1070 | "nbconvert_exporter": "python", 1071 | "pygments_lexer": "ipython3", 1072 | "version": "3.8.2" 1073 | } 1074 | }, 1075 | "nbformat": 4, 1076 | "nbformat_minor": 2 1077 | } 1078 | -------------------------------------------------------------------------------- /Chapter07/README.md: -------------------------------------------------------------------------------- 1 | ### Chapter 7: Placing Bracket and Cover Orders on the Exchange 2 | Learn how to place 8 types of Bracket Orders and 4 types of Cover orders 3 | across two transaction types and multiple order varieties and query the 4 | order status in real-time. Learn about target, stoploss and trailing stoploss. 5 | Also, learn about the possible order states supported by the broker and the 6 | order life-cycle for both Bracket and Cover Orders. 7 | 8 | ### List of Recipes in this chapter 9 | 1. Placing a Bracket Limit Order 10 | - Buy, Bracket, Intraday, Limit Order (without Trailing Stoploss) 11 | - Sell, Bracket, Intraday, Limit Order (without Trailing Stoploss) 12 | 2. Placing a Bracket Stoploss-Limit Order 13 | - Buy, Bracket, Intraday, Stoploss-Limit Order (without Trailing Stoploss) 14 | - Sell, Bracket, Intraday, Stoploss-Limit Order (without Trailing Stoploss) 15 | 3. Placing a Bracket Limit Order with Trailing Stoploss 16 | - Buy, Bracket, Intraday, Limit Order with Trailing Stoploss 17 | - Sell, Bracket, Intraday, Limit Order with Trailing Stoploss 18 | 4. Placing a Bracket Stoploss-Limit Order with Trailing Stoploss 19 | - Buy, Bracket, Intraday, Stoploss-Limit Order with Trailing Stoploss 20 | - Sell, Bracket, Intraday, Stoploss-Limit Order with Trailing Stoploss 21 | 5. Placing a Cover Market Order 22 | - Buy, Cover, Intraday, Market Order 23 | - Sell, Cover, Intraday, Market Order 24 | 6. Placing a Cover Limit Order 25 | - Buy, Cover, Intraday, Limit Order 26 | - Sell, Cover, Intraday, Limit Order 27 | 28 | *[**[Click here to VIEW Chapter 7 Jupyter Notebook on nbviewer](https://nbviewer.jupyter.org/github/PacktPublishing/Python-Algorithmic-Trading-Cookbook/blob/master/Chapter07/CHAPTER%207.ipynb)**]* 29 |
30 | *[**[Click here to RUN Chapter 7 Jupyter Notebook in the cloud using binder. No installation needed on your end.](https://mybinder.org/v2/gh/PacktPublishing/Python-Algorithmic-Trading-Cookbook/master?filepath=Chapter07/CHAPTER%207.ipynb)**]* 31 | 32 | ### Requirements 33 | - Python 3.7+ 34 | - Additional Python Packages required for this chapter can be installed as follows - 35 | 36 | ``` 37 | $ source # optional, if you use a virtualenv 38 | $ cd 39 | $ pip install -r requirements.txt 40 | ``` -------------------------------------------------------------------------------- /Chapter07/requirements.txt: -------------------------------------------------------------------------------- 1 | pyalgotrading 2 | -------------------------------------------------------------------------------- /Chapter08/README.md: -------------------------------------------------------------------------------- 1 | ### Chapter 8: Algorithmic Trading: Coding Strategies Step-by-Step 2 | Learn how to code your own algorithmic trading strategy from scratch using 3 | two strategy coding examples involving Regular and Bracket orders respectively. 4 | 5 | ### List of Recipes in this chapter 6 | 1. EMA-Regular-Order Strategy: Coding the `__init__`, `initialize`, `name` and `versions_supported` methods 7 | 2. EMA-Regular-Order Strategy: Coding the `strategy_select_instruments_for_entry` method 8 | 3. EMA-Regular-Order Strategy: Coding the `strategy_enter_position` method 9 | 4. EMA-Regular-Order Strategy: Coding the `strategy_select_instruments_for_exit` method 10 | 5. EMA-Regular-Order Strategy: Coding the `strategy_exit_position` method 11 | 6. EMA-Regular-Order Strategy: Uploading the strategy on AlgoBulls Trading Platform 12 | 7. MACD-Bracket-Order Strategy: Coding the `__init__`, `initialize`, `name` and `versions_supported` method 13 | 8. MACD-Bracket-Order Strategy: Coding the `strategy_select_instruments_for_entry` method 14 | 9. MACD-Bracket-Order Strategy: Coding the `strategy_enter_position` method 15 | 10. MACD-Bracket-Order Strategy: Coding the `strategy_select_instruments_for_exit` method 16 | 11. MACD-Bracket-Order Strategy: Coding the `strategy_exit_position` method 17 | 12. MACD-Bracket-Order Strategy: Uploading the strategy on AlgoBulls Trading Platform 18 | 19 | *[**[Click here to VIEW Chapter 8 Jupyter Notebook on nbviewer](https://nbviewer.jupyter.org/github/PacktPublishing/Python-Algorithmic-Trading-Cookbook/blob/master/Chapter08/CHAPTER%208.ipynb)**]* 20 | 21 | ### Requirements 22 | - Python 3.7+ 23 | - Additional Python Packages required for this chapter can be installed as follows - 24 | 25 | ``` 26 | $ source # optional, if you use a virtualenv 27 | $ cd 28 | $ pip install -r requirements.txt 29 | ``` -------------------------------------------------------------------------------- /Chapter08/images/diagrams/strategy_execution_flowchart.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter08/images/diagrams/strategy_execution_flowchart.dia -------------------------------------------------------------------------------- /Chapter08/images/diagrams/strategy_execution_flowchart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter08/images/diagrams/strategy_execution_flowchart.png -------------------------------------------------------------------------------- /Chapter08/requirements.txt: -------------------------------------------------------------------------------- 1 | pyalgotrading 2 | pyalgostrategypool 3 | TA-Lib 4 | -------------------------------------------------------------------------------- /Chapter09/README.md: -------------------------------------------------------------------------------- 1 | ### Chapter 9: Algorithmic Trading: Backtesting 2 | Learn how to Backtest your own algorithmic trading strategy using two 3 | strategy coding examples involving Regular and Bracket orders respectively. 4 | Also, learn to fetch execution logs and various types of Backtesting reports 5 | including P&L report, statistics report and order history log for your strategy. 6 | 7 | ### List of Recipes in this chapter 8 | 1. EMA-Regular-Order Strategy: Fetching the Strategy 9 | 2. EMA-Regular-Order Strategy: Backtesting the Strategy 10 | 3. EMA-Regular-Order Strategy: Fetching Backtesting Logs in real time 11 | 4. EMA-Regular-Order Strategy: Fetching Backtesting Report - Profit-&-Loss Table 12 | 5. EMA-Regular-Order Strategy: Fetching Backtesting Report - Statistics Table 13 | 6. EMA-Regular-Order Strategy: Fetching Backtesting Report - Order History 14 | 7. MACD-Bracket-Order Strategy: Fetching the Strategy 15 | 8. MACD-Bracket-Order Strategy: Backtesting the Strategy 16 | 9. MACD-Bracket-Order Strategy: Fetching Backtesting Logs in real time 17 | 10. MACD-Bracket-Order Strategy: Fetching Backtesting Report - Profit-&-Loss Table 18 | 11. MACD-Bracket-Order Strategy: Fetching Backtesting Report - Statistics Table 19 | 12. MACD-Bracket-Order Strategy: Fetching Backtesting Report - Order History 20 | 21 | *[**[Click here to VIEW Chapter 9 Jupyter Notebook on nbviewer](https://nbviewer.jupyter.org/github/PacktPublishing/Python-Algorithmic-Trading-Cookbook/blob/master/Chapter09/CHAPTER%209.ipynb)**]* 22 |
23 | *[**[Click here to RUN Chapter 9 Jupyter Notebook in the cloud using binder. No installation needed on your end.](https://mybinder.org/v2/gh/PacktPublishing/Python-Algorithmic-Trading-Cookbook/master?filepath=Chapter09/CHAPTER%209.ipynb)**]* 24 | 25 | ### Requirements 26 | - Python 3.7+ 27 | - Additional Python Packages required for this chapter can be installed as follows - 28 | 29 | ``` 30 | $ source # optional, if you use a virtualenv 31 | $ cd 32 | $ pip install -r requirements.txt 33 | ``` -------------------------------------------------------------------------------- /Chapter09/images/diagrams/abc-job-status-state-diagram.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter09/images/diagrams/abc-job-status-state-diagram.dia -------------------------------------------------------------------------------- /Chapter09/images/diagrams/abc-job-status-state-diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter09/images/diagrams/abc-job-status-state-diagram.png -------------------------------------------------------------------------------- /Chapter09/requirements.txt: -------------------------------------------------------------------------------- 1 | pyalgotrading 2 | -------------------------------------------------------------------------------- /Chapter10/README.md: -------------------------------------------------------------------------------- 1 | ### Chapter 10: Algorithmic Trading: Paper Trading 2 | Learn how to Paper Trade your own algorithmic trading strategy in live 3 | markets using two strategy coding examples involving Regular and Bracket 4 | orders respectively. Also, learn to fetch execution logs and various 5 | types of Paper Trading reports including P&L report, statistics report 6 | and order history log in real-time for your strategy. 7 | 8 | ### List of Recipes in this chapter 9 | 1. EMA-Regular-Order Strategy: Fetching the Strategy 10 | 2. EMA-Regular-Order Strategy: Paper Trading the Strategy 11 | 3. EMA-Regular-Order Strategy: Fetching Paper Trading Logs in real time 12 | 4. EMA-Regular-Order Strategy: Fetching Paper Trading Report - Profit-&-Loss Table 13 | 5. EMA-Regular-Order Strategy: Fetching Paper Trading Report - Statistics Table 14 | 6. EMA-Regular-Order Strategy: Fetching Paper Trading Report - Order History 15 | 7. MACD-Bracket-Order Strategy: Fetching the Strategy 16 | 8. MACD-Bracket-Order Strategy: Paper Trading the Strategy 17 | 9. MACD-Bracket-Order Strategy: Fetching Paper Trading Logs in real time 18 | 10. MACD-Bracket-Order Strategy: Fetching Paper Trading Report - Profit-&-Loss Table 19 | 11. MACD-Bracket-Order Strategy: Fetching Paper Trading Report - Statistics Table 20 | 12. MACD-Bracket-Order Strategy: Fetching Paper Trading Report - Order History 21 | 22 | *[**[Click here to VIEW Chapter 10 Jupyter Notebook on nbviewer](https://nbviewer.jupyter.org/github/PacktPublishing/Python-Algorithmic-Trading-Cookbook/blob/master/Chapter10/CHAPTER%2010.ipynb)**]* 23 |
24 | *[**[Click here to RUN Chapter 10 Jupyter Notebook in the cloud using binder. No installation needed on your end.](https://mybinder.org/v2/gh/PacktPublishing/Python-Algorithmic-Trading-Cookbook/master?filepath=Chapter10/CHAPTER%2010.ipynb)**]* 25 | 26 | ### Requirements 27 | - Python 3.7+ 28 | - Additional Python Packages required for this chapter can be installed as follows - 29 | 30 | ``` 31 | $ source # optional, if you use a virtualenv 32 | $ cd 33 | $ pip install -r requirements.txt 34 | ``` -------------------------------------------------------------------------------- /Chapter10/images/diagrams/abc-job-status-state-diagram.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter10/images/diagrams/abc-job-status-state-diagram.dia -------------------------------------------------------------------------------- /Chapter10/images/diagrams/abc-job-status-state-diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter10/images/diagrams/abc-job-status-state-diagram.png -------------------------------------------------------------------------------- /Chapter10/requirements.txt: -------------------------------------------------------------------------------- 1 | pyalgotrading 2 | -------------------------------------------------------------------------------- /Chapter11/README.md: -------------------------------------------------------------------------------- 1 | ### Chapter 11: Algorithmic Trading: Real Trading 2 | Finally, learn how to Real Trade your own algorithmic trading strategy 3 | in live markets and real money using two strategy coding examples 4 | involving Regular and Bracket orders respectively. Also, learn to fetch 5 | execution logs and various types of Real Trading reports including P&L 6 | reports and statistics reports in real-time for your strategy. 7 | 8 | ### List of Recipes in this chapter 9 | 1. EMA-Regular-Order Strategy: Fetching the Strategy 10 | 2. EMA-Regular-Order Strategy: Real Trading the Strategy 11 | 3. EMA-Regular-Order Strategy: Fetching Real Trading Logs in real time 12 | 4. EMA-Regular-Order Strategy: Fetching Real Trading Report - Profit-&-Loss Table 13 | 5. EMA-Regular-Order Strategy: Fetching Real Trading Report - Statistics Table 14 | 6. MACD-Bracket-Order Strategy: Fetching the Strategy 15 | 7. MACD-Bracket-Order Strategy: Real Trading the Strategy 16 | 8. MACD-Bracket-Order Strategy: Fetching Real Trading Logs in real time 17 | 9. MACD-Bracket-Order Strategy: Fetching Real Trading Report - Profit-&-Loss Table 18 | 10. MACD-Bracket-Order Strategy: Fetching Real Trading Report - Statistics Table 19 | 20 | *[**[Click here to VIEW Chapter 11 Jupyter Notebook on nbviewer](https://nbviewer.jupyter.org/github/PacktPublishing/Python-Algorithmic-Trading-Cookbook/blob/master/Chapter11/CHAPTER%2011.ipynb)**]* 21 |
22 | *[**[Click here to RUN Chapter 11 Jupyter Notebook in the cloud using binder. No installation needed on your end.](https://mybinder.org/v2/gh/PacktPublishing/Python-Algorithmic-Trading-Cookbook/master?filepath=Chapter11/CHAPTER%2011.ipynb)**]* 23 | 24 | ### Requirements 25 | - Python 3.7+ 26 | - Additional Python Packages required for this chapter can be installed as follows - 27 | 28 | ``` 29 | $ source # optional, if you use a virtualenv 30 | $ cd 31 | $ pip install -r requirements.txt 32 | ``` -------------------------------------------------------------------------------- /Chapter11/images/diagrams/abc-job-status-state-diagram.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter11/images/diagrams/abc-job-status-state-diagram.dia -------------------------------------------------------------------------------- /Chapter11/images/diagrams/abc-job-status-state-diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Algorithmic-Trading-Cookbook/a67301b414f00fcd3b34e061bc89e0926bbd31e6/Chapter11/images/diagrams/abc-job-status-state-diagram.png -------------------------------------------------------------------------------- /Chapter11/requirements.txt: -------------------------------------------------------------------------------- 1 | pyalgotrading 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Packt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # Python Algorithmic Trading Cookbook 5 | 6 | Python Algorithmic Trading Cookbook 7 | 8 | This is the code repository for [Python Algorithmic Trading Cookbook](https://www.packtpub.com/product/python-algorithmic-trading-cookbook/9781838989354?utm_source=github&utm_medium=repository&utm_campaign=9781838989354), published by Packt. 9 | 10 | **All the recipes you need to implement your own algorithmic trading strategies in Python** 11 | 12 | ## What is this book about? 13 | Python is a very popular language used to build and execute algorithmic trading strategies. If you want to find out how you can build a solid foundation in algorithmic trading using the language, this cookbook is here to help. 14 | 15 | Starting by setting up the Python environment for trading and connectivity with brokers, you’ll then learn the important aspects of financial markets. As you progress through this algorithmic trading book, you’ll learn to fetch financial instruments, query and calculate various types of candles and historical data, and finally, compute and plot technical indicators. Next, you’ll discover how to place various types of orders, such as regular, bracket, and cover orders, and understand their state transitions. You’ll also uncover challenges faced while devising and executing powerful algorithmic trading strategies from scratch. Later chapters will take you through backtesting, paper trading, and finally real trading for the algorithmic strategies that you've created from the ground up. You’ll even understand how to automate trading and find the right strategy for making effective decisions that would otherwise be impossible for human traders. 16 | 17 | By the end of this book, you’ll be able to use Python for algorithmic trading by implementing Python libraries to conduct key tasks in the algorithmic trading ecosystem. 18 | 19 | In this repo, you will find the code examples used in the book. I also include here parts of the code omitted in the book, such as the data visualization styling, additional formatting, etc. 20 | 21 | This book covers the following exciting features: 22 | * Use Python to set up connectivity with brokers 23 | * Handle and manipulate time series data using Python 24 | * Fetch a list of exchanges, segments, financial instruments, and historical data to interact with the real market 25 | * Understand, fetch, and calculate various types of candles and use them to compute and plot diverse types of technical indicators 26 | * Develop and improve the performance of algorithmic trading strategies 27 | * Perform backtesting and paper trading on algorithmic trading strategies 28 | * Implement real trading in the live hours of stock markets 29 | 30 | If you feel this book is for you, get your [copy](https://www.amazon.com/dp/B089D1584M) today! 31 | 32 | https://www.packtpub.com/ 33 | 34 | ## Instructions and Navigations 35 | All of the code is organized into folders. 36 | 37 | The code will look like the following: 38 | ``` 39 | >>> plot_candlestick_chart(historical_data, 40 | PlotType.OHLC, 41 | 'Historical Data | ' 42 | 'Japanese Candlesticks Pattern | ' 43 | 'NSE:TATASTEEL | 1st Jan, 2020 | ' 44 | 'Candle Interval: 1 Minute') 45 | 46 | ``` 47 | 48 | **Following is what you need for this book:** 49 | 50 | If you are a financial analyst, financial trader, data analyst, algorithmic trader, trading enthusiast or anyone who wants to learn algorithmic trading with Python and important techniques to address challenges faced in the finance domain, this book is for you. Basic working knowledge of the Python programming language is expected. Although fundamental knowledge of trade-related terminologies will be helpful, it is not mandatory. 51 | 52 | You need to have the latest version of Python 3 installed on your computer. The recipes of this Chapter were tested on Python 3.8.2. They should work on any 53 | future release of Python as well. 54 | 55 | You also need a broking account with Zerodha, a modern broker, to try out the recipes for most of the chapters. Appendix I gives detailed step-by-step information to set up your Zerodha account in case you do not have it. 56 | 57 | For executing trading strategies, you also need an account with AlgoBulls. Appendix II gives detailed step-by-step information to set up your AlgoBulls account in case you do not have it. 58 | 59 | Also, almost every chapter expects you to have additional Python packages installed like ‘pyalgotrading'. You can install them using `pip`. This is explained in the technical requirements section of every chapter. All the recipes in this chapter are provided as Jupyter Notebooks ih this GitHub repository. You can install Jupyter Notebook as well if you would like to try out the recipes directly without typing any code. You can install this using pip - `pip install notebook`. 60 | 61 | ## Requirements: 62 | - Summary of requirements for each Chapter: 63 | 64 | | Chapters | Python 3\.7\+ | Zerodha Account | AlgoBulls Account | 65 | |:-----------:|:-------------:|:----------------:|:-----------------:| 66 | | Chapter 1 | ✓ | ✗ | ✗ | 67 | | Chapter 2 | ✓ | ✓ | ✗ | 68 | | Chapter 3 | ✓ | ✓ | ✗ | 69 | | Chapter 4 | ✓ | ✓ | ✗ | 70 | | Chapter 5 | ✓ | ✓ | ✗ | 71 | | Chapter 6 | ✓ | ✓ | ✗ | 72 | | Chapter 7 | ✓ | ✓ | ✗ | 73 | | Chapter 8 | ✓ | ✗ | ✓ | 74 | | Chapter 9 | ✓ | ✗ | ✓ | 75 | | Chapter 10 | ✓ | ✗ | ✓ | 76 | | Chapter 11 | ✓ | ✗ | ✓ | 77 | 78 | - For each chapter, the additional Python packages required to run the recipes are provided in a `requirements.txt` file in the chapter specific folder. 79 | You can easily install the additional dependencies using `pip`: 80 | 81 | ``` 82 | # For example, to install dependencies needed for Chapter 5: 83 | 84 | $ source # optional, if you use a virtualenv 85 | $ cd /Chapter05 86 | $ pip install -r requirements.txt 87 | ``` 88 | 89 | ## Errata 90 | 91 | * Page 297 (Chapter 7, Recipe 5, Step 5): **TRIGGER PENDING** _should be_ **COMPLETE** 92 | 93 | * Page 379 (Chapter 9, Recipe 8, Step 2): In the code **instrument** _should be_ **instruments** 94 | 95 | * Page 379 (Chapter 9, Recipe 8, Step 3): **instrument = instrument[0]['value']** _should be_ **instrument = instruments[0]['value']** 96 | 97 | * Page 423 (Chapter 10, Recipe 7, Step 6): **49287246f9704bbcbad76ade9e2091d9** _should be_ **4faf514fe096432b8e9f80f5951bd2ea** 98 | 99 | * Page 427 (Chapters 10, Recipe 8, Step 2): In the code **instrument** _should be_ **instruments** 100 | 101 | * Page 427 (Chapters 10, Recipe 8, Step 3): **instrument = instrument[0]['value']** _should be_ **instrument = instruments[0]['value']** 102 | 103 | * Page 471 (Chapter 11, Recipe 7, Step 2): In the code **instrument** _should be_ **instruments** 104 | 105 | * Page 471 (Chapter 11, Recipe 7, Step 3): **instrument = instrument[0]['value']** _should be_ **instrument = instruments[0]['value']** 106 | 107 | * Page 467 (Chapter 11, Recipe 6, Step 6): **49287246f9704bbcbad76ade9e2091d9** _should be_ **4faf514fe096432b8e9f80f5951bd2ea** 108 | 109 | * Chapter 5: All instances of **plot_candlesticks_chart** in the code format (```plot_candlesticks_chart```) _should be_ **plot_candlestick_chart** 110 | 111 | With the following software and hardware list you can run all code files present in the book (Chapters 1-11). 112 | 113 | ### Software and Hardware List 114 | 115 | | Chapter | Software required | OS required | 116 | | :------: | :-----------------------------------------------------------------------------------:| :---------------------------------:| 117 | | 1 - 11 | Python 3.7+, Jupyter Notebook | Windows, Mac OS X, and Linux (Any) | 118 | 119 | 120 | We also provide a PDF file that has color images of the screenshots/diagrams used in this book. [Click here to download it](https://static.packt-cdn.com/downloads/9781838989354_ColorImages.pdf). 121 | 122 | 123 | ### Related products 124 | * Learn Algorithmic Trading [[Packt]](https://www.packtpub.com/product/learn-algorithmic-trading/9781789348347) [[Amazon]](https://www.amazon.com/dp/178934834X) 125 | 126 | * Mastering Python for Finance - Second Edition [[Packt]](https://www.packtpub.com/product/mastering-python-for-finance-second-edition/9781789346466) [[Amazon]](https://www.amazon.com/dp/1789346460) 127 | 128 | ## Get to Know the Author 129 | **[Pushpak Dagade](https://www.linkedin.com/in/pushpak-dagade-47275121/)** 130 | has been working in the area of algorithmic trading for more than 3 years. He is a co-founder and the CEO of AlgoBulls, an algorithmic trading platform. He is also a long time Pythonista with more than a decade of Python experience. He is a pass out from Indian Institute of Technology (Delhi) and holds engineering degrees in the fields of Computer Science, Electronics and Physics. 131 | 132 | If you have any doubts related to the concepts or code samples in the book, you can ask it in the [AlgoBulls forum](https://community.algobulls.com/t/about-the-python-algorithmic-trading-cookbook-category/58) created by the author. 133 | 134 | ### Suggestions and Feedback 135 | [Click here](https://docs.google.com/forms/d/e/1FAIpQLSdy7dATC6QmEL81FIUuymZ0Wy9vH1jHkvpY57OiMeKGqib_Ow/viewform) if you have any feedback or suggestions. 136 | ### Download a free PDF 137 | 138 | If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.
139 |

https://packt.link/free-ebook/9781838989354

--------------------------------------------------------------------------------