{"id":524,"date":"2023-02-14T14:04:39","date_gmt":"2023-02-14T14:04:39","guid":{"rendered":"https:\/\/algomojo.com\/blog\/?p=524"},"modified":"2023-09-13T04:30:23","modified_gmt":"2023-09-13T04:30:23","slug":"python-multi-broker-library-for-algomojo-trade-automation","status":"publish","type":"post","link":"https:\/\/algomojo.com\/blog\/python-multi-broker-library-for-algomojo-trade-automation\/","title":{"rendered":"Python Multi-Broker Library for Algomojo &#8211; Trade Automation"},"content":{"rendered":"\n<p>Algomojo Python library facilitates the development of trading algorithms using the&nbsp;<a href=\"https:\/\/algomojo.com\/\">Algomojo Free API<\/a>&nbsp;and Free Algo Trading Platform. The library supports both REST-API interfaces and provides features such as real-time order execution, smartorder execution, placing options orders, placing multi orders, order modification\/cancellation, and access to order book, trade book, open positions, orderstatus, position square-off functionalities, getquotes, profile and fund details. <\/p>\n\n\n\n<p>Algomojo Multi-Broker Library is a robust and versatile trading platform that provides traders with the tools to automate their trading strategies in multiple markets with different brokers.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/algomojo.com\/blog\/wp-content\/uploads\/2023\/02\/python-algomojo-library-1024x576-1.png\"><img loading=\"lazy\" width=\"1024\" height=\"576\" src=\"https:\/\/algomojo.com\/blog\/wp-content\/uploads\/2023\/02\/python-algomojo-library-1024x576-1.png\" alt=\"\" class=\"wp-image-527\"\/><\/a><\/figure>\n\n\n\n<p><strong>Supported Brokers<\/strong>: All Algomojo Supported Brokers<\/p>\n\n\n\n<p><a href=\"https:\/\/pypi.org\/project\/algomojo\/\">Complete Python Documentation<\/a><\/p>\n\n\n\n<p><strong>Basic Features of Python Trading API<\/strong><\/p>\n\n\n\n<ul><li>Execute Orders in Realtime<\/li><li>Place&nbsp;<a href=\"https:\/\/algomojo.com\/blog\/what-is-placesmartorder-feature-in-algomojo-how-to-build-intelligent-trading-systems-using-placesmartorder\/\">Smart Orders<\/a>&nbsp;to match Position Book<\/li><li>Split Larger orders into Multiple Smaller Orders<\/li><li>Single Client Execution Orders<\/li><li>Multi-Client Execution of Orders<\/li><li>Multi-Broker Execution of Orders<\/li><li>Place Multiple Bracket Orders\/Cover Orders<\/li><li>Place ATM\/ITM\/OTM Option Orders<\/li><li>Place Multi Leg Options Orders<\/li><li>Modify\/Cancel Orders<\/li><li>Cancel All Pending Orders<\/li><li>Retrieve Orderbook<\/li><li>Retrieve Tradebook<\/li><li>Retrieve Order History<\/li><li>Retrieve Open Positions<\/li><li>Square off Open Positions<\/li><li>Square off All Open Positions<\/li><li>Exit Bracket Order<\/li><li>Exit Cover Order<\/li><li>Get live quotes for the trading instruments<\/li><li>Access Fund\/Margin Details and many more functionalities.<\/li><\/ul>\n\n\n\n<p>For more details on each API behavior, Pease see the <a href=\"https:\/\/amapi.finfolab.com\/docs\/\">Algomojo API documentation.<\/a><\/p>\n\n\n\n<p>Visit here for more detailed <a href=\"https:\/\/pypi.org\/project\/algomojo\/\">Algomojo python documentation<\/a> for supporting functions<\/p>\n\n\n\n<p><strong>How to Install Algomojo Python Library?<\/strong><\/p>\n\n\n\n<p>Install from PyPI using the simple PIP command<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-powershell\">pip install algomojo<\/code><\/pre>\n\n\n\n<p>It is highly recommended to use Python 3.x versions<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/algomojo.com\/blog\/wp-content\/uploads\/2023\/02\/algomojo-pip-install.png\"><img loading=\"lazy\" width=\"993\" height=\"519\" src=\"https:\/\/algomojo.com\/blog\/wp-content\/uploads\/2023\/02\/algomojo-pip-install.png\" alt=\"\" class=\"wp-image-529\"\/><\/a><\/figure>\n\n\n\n<p><strong>How to Send Orders using Algomojo Python Library?<\/strong><\/p>\n\n\n\n<p>Once the Python Library is installed the next step is to import the python library using the import command and set the api_key and api_secret key with broker shortcode in your python program and place the order.<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-python\">from algomojo.pyapi import *\n                                    \n# Set the API Key and API Secret key obtained from Algomojo MyAPI Section\nalgomojo=api(api_key=&quot;46ad9245cca3dfe957deb235a39d02a3&quot;,\n                api_secret=&quot;d8286408c0ff99fbdbadf549692fc40a&quot;)\n                \n# Place Market Order in the trading symbol RELIANCE-EQ\nalgomojo.PlaceOrder(broker=&quot;an&quot;,\n                strategy=&quot;Python Example&quot;,\n                exchange=&quot;NSE&quot;,\n                symbol=&quot;RELIANCE-EQ&quot;,\n                action=&quot;BUY&quot;,\n                product=&quot;MIS&quot;,\n                quantity=10)\n\n#Place Limit Order in the trading symbol ZOMATO-EQ\nalgomojo.PlaceOrder(broker=&quot;an&quot;,\n                strategy=&quot;Python Example&quot;,\n                exchange=&quot;NSE&quot;,\n                symbol=&quot;ZOMATO-EQ&quot;,\n                action=&quot;BUY&quot;,\n                product=&quot;MIS&quot;,\n                quantity=10,\n                pricetype=&quot;LIMIT&quot;,\n                price=54)<\/code><\/pre>\n\n\n\n<p><strong>How to Send Large Orders in Options using Algomojo<\/strong><\/p>\n\n\n\n<p>Now sending Larget orders is possible using the split order functionality and now traders can punch larger orders very easily with just setting the splitorder mode and split_quantity variable in the placeorder, placesmartorder, placefnooptionsorder codes.<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-python\">#Place Larger Order in options with Split Order mode enabled\nalgomojo.PlaceOrder(broker=&quot;an&quot;,\n                strategy=&quot;Python Example&quot;,\n                exchange=&quot;NFO&quot;,\n                symbol=&quot;NIFTY23FEB2318000CE&quot;,\n                action=&quot;BUY&quot;,\n                product=&quot;NRML&quot;,\n                quantity=10200,\n                pricetype=&quot;MARKET&quot;,\n                splitorder=&quot;YES&quot;,\n                split_quantity=1800)<\/code><\/pre>\n\n\n\n<p><strong>Place Smart Orders to Match the PositionBook &#8211; useful for dynamic position sizing<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-python\">#PlaceSmartOrder to match the open positions\nalgomojo.PlaceSmartOrder(broker=&quot;an&quot;,\n                                    strategy=&quot;Python Example&quot;,\n                                    exchange=&quot;NSE&quot;,\n                                    symbol=&quot;RELIANCE-EQ&quot;,\n                                    action=&quot;BUY&quot;,\n                                    product=&quot;MIS&quot;,\n                                    pricetype=&quot;MARKET&quot;,\n                                    quantity=&quot;10&quot;,\n                                    price=&quot;0&quot;,\n                                    position_size=&quot;10&quot;,\n                                    trigger_price=&quot;0&quot;,\n                                    disclosed_quantity=&quot;0&quot;,\n                                    amo=&quot;NO&quot;,\n                                    splitorder=&quot;NO&quot;,\n                                    split_quantity=&quot;1&quot;) <\/code><\/pre>\n\n\n\n<p><strong>Get Realtime Quotes<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-python\">algomojo.GetQuote(broker=&quot;an&quot;, exchange=&quot;NSE&quot;, symbol= &quot;ZOMATO-EQ&quot;)<\/code><\/pre>\n\n\n\n<p><strong>Sending a Bracket Order<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-python\">#Place Bracket Order\nalgomojo.PlaceBOOrder(broker=&quot;an&quot;,\n                                    strategy=&quot;Python Example&quot;,\n                                    exchange=&quot;NSE&quot;,\n                                    symbol=&quot;YESBANK-EQ&quot;,\n                                    action=&quot;BUY&quot;,\n                                    pricetype=&quot;LIMIT&quot;,\n                                    quantity=&quot;1&quot;,\n                                    price=&quot;16.5&quot;,\n                                    squareoff=&quot;2&quot;,\n                                    stoploss=&quot;2&quot;,\n                                    trailing_stoploss=&quot;1&quot;,\n                                    trigger_price=&quot;0&quot;,\n                                    disclosed_quantity=&quot;0&quot;)   <\/code><\/pre>\n\n\n\n<p><strong>Sending a Cover Order<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-python\">#Place Cover Order\nalgomojo.PlaceCOOrder(broker=&quot;an&quot;,\n                                    strategy=&quot;Python Example&quot;,\n                                    exchange=&quot;NSE&quot;,\n                                    symbol=&quot;YESBANK-EQ&quot;,\n                                    action=&quot;BUY&quot;,\n                                    pricetype=&quot;LIMIT&quot;,\n                                    quantity=&quot;1&quot;,\n                                    price=&quot;16.5&quot;,\n                                    stop_price=&quot;15&quot;) <\/code><\/pre>\n\n\n\n<p><strong>Placing F&amp;O Options Order<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-python\">#Place ATM Call Options Order\n#offset = 0 selects ATM strike price with spot at underlying\nalgomojo.PlaceFOOptionsOrder(broker=&quot;an&quot;,\n                                            strategy=&quot;Python Example&quot;,\n                                            spot_symbol=&quot;NIFTY&quot;,\n                                            expiry_date=&quot;23FEB23&quot;,\n                                            action=&quot;BUY&quot;,\n                                            product=&quot;NRML&quot;,\n                                            pricetype=&quot;MARKET&quot;,\n                                            quantity=&quot;50&quot;,\n                                            price=&quot;0&quot;,\n                                            option_type=&quot;CE&quot;,\n                                            strike_int=&quot;50&quot;,\n                                            offset=&quot;0&quot;,\n                                            splitorder=&quot;NO&quot;,\n                                            split_quantity=&quot;50&quot;)\n\n#Place 2 strike higher OTM Call F&amp;O Options Order\n#offset &gt; 0 selects higher strike price relative to ATM strikes with spot at underlying\nalgomojo.PlaceFOOptionsOrder(broker=&quot;an&quot;,\n                                            strategy=&quot;Python Example&quot;,\n                                            spot_symbol=&quot;NIFTY&quot;,\n                                            expiry_date=&quot;23FEB23&quot;,\n                                            action=&quot;BUY&quot;,\n                                            product=&quot;NRML&quot;,\n                                            pricetype=&quot;MARKET&quot;,\n                                            quantity=&quot;50&quot;,\n                                            price=&quot;0&quot;,\n                                            option_type=&quot;CE&quot;,\n                                            strike_int=&quot;50&quot;,\n                                            offset=&quot;2&quot;,\n                                            splitorder=&quot;NO&quot;,\n                                            split_quantity=&quot;50&quot;)\n\n#Place 3 strike lower ITM Put F&amp;O Options Order \n#offset &lt; 0 selects higher strike price relative to ATM strikes with spot at underlying\nalgomojo.PlaceFOOptionsOrder(broker=&quot;an&quot;,\n                                            strategy=&quot;Python Example&quot;,\n                                            spot_symbol=&quot;NIFTY&quot;,\n                                            expiry_date=&quot;23FEB23&quot;,\n                                            action=&quot;SELL&quot;,\n                                            product=&quot;NRML&quot;,\n                                            pricetype=&quot;MARKET&quot;,\n                                            quantity=&quot;50&quot;,\n                                            price=&quot;0&quot;,\n                                            option_type=&quot;PE&quot;,\n                                            strike_int=&quot;50&quot;,\n                                            offset=&quot;-3&quot;,\n                                            splitorder=&quot;NO&quot;,\n                                            split_quantity=&quot;50&quot;)<\/code><\/pre>\n\n\n\n<p><strong>Multi-Legged Options Order<\/strong> &#8211; <strong>Placing Short Straddle Orders<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-python\">#Place Multiple Options Orders to the Same Broker\/Different Brokers\norders=[{&quot;api_key&quot;:&quot;46ad9245cca3dfe957deb235a39d02a3&quot;,&quot;api_secret&quot;:&quot;bd99a1c4e0a0235b2b9162aa1519a554&quot;,&quot;broker&quot;:&quot;an&quot;,&quot;strategy&quot;:&quot;Options Spread&quot;,&quot;spot_symbol&quot;:&quot;NIFTY&quot;,&quot;expiry_date&quot;:&quot;23FEB23&quot;,&quot;action&quot;:&quot;SELL&quot;,&quot;product&quot;:&quot;NRML&quot;,&quot;pricetype&quot;:&quot;MARKET&quot;,&quot;quantity&quot;:&quot;100&quot;,&quot;option_type&quot;:&quot;CE&quot;,&quot;strike_int&quot;:&quot;50&quot;,&quot;offset&quot;:&quot;0&quot;,&quot;splitorder&quot;:&quot;NO&quot;,&quot;split_quantity&quot;:&quot;50&quot;},\n        {&quot;api_key&quot;:&quot;46ad9245cca3dfe957deb235a39d02a3&quot;,&quot;api_secret&quot;:&quot;bd99a1c4e0a0235b2b9162aa1519a554&quot;,&quot;broker&quot;:&quot;an&quot;,&quot;strategy&quot;:&quot;Options Spread&quot;,&quot;spot_symbol&quot;:&quot;NIFTY&quot;,&quot;expiry_date&quot;:&quot;23FEB23&quot;,&quot;action&quot;:&quot;SELL&quot;, &quot;product&quot;:&quot;NRML&quot;,&quot;pricetype&quot;:&quot;MARKET&quot;, &quot;quantity&quot;:&quot;100&quot;,&quot;option_type&quot;:&quot;PE&quot;,&quot;strike_int&quot;:&quot;50&quot;,&quot;offset&quot;:&quot;0&quot;,&quot;splitorder&quot;:&quot;NO&quot;,&quot;split_quantity&quot;:&quot;50&quot;}]\n\nalgomojo.PlaceMultiFOOptionsOrder(orders) <\/code><\/pre>\n\n\n\n<p><strong>Multi-Legged Options Order<\/strong> &#8211; <strong>Placing Short Strangle Orders<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-python\">#Place Multiple Options Orders to the Same Broker\/Different Brokers\norders=[{&quot;api_key&quot;:&quot;46ad9245cca3dfe957deb235a39d02a3&quot;,&quot;api_secret&quot;:&quot;bd99a1c4e0a0235b2b9162aa1519a554&quot;,&quot;broker&quot;:&quot;an&quot;,&quot;strategy&quot;:&quot;Options Spread&quot;,&quot;spot_symbol&quot;:&quot;NIFTY&quot;,&quot;expiry_date&quot;:&quot;23FEB23&quot;,&quot;action&quot;:&quot;SELL&quot;,&quot;product&quot;:&quot;NRML&quot;,&quot;pricetype&quot;:&quot;MARKET&quot;,&quot;quantity&quot;:&quot;100&quot;,&quot;option_type&quot;:&quot;CE&quot;,&quot;strike_int&quot;:&quot;50&quot;,&quot;offset&quot;:&quot;0&quot;,&quot;splitorder&quot;:&quot;NO&quot;,&quot;split_quantity&quot;:&quot;50&quot;},\n        {&quot;api_key&quot;:&quot;46ad9245cca3dfe957deb235a39d02a3&quot;,&quot;api_secret&quot;:&quot;bd99a1c4e0a0235b2b9162aa1519a554&quot;,&quot;broker&quot;:&quot;an&quot;,&quot;strategy&quot;:&quot;Options Spread&quot;,&quot;spot_symbol&quot;:&quot;NIFTY&quot;,&quot;expiry_date&quot;:&quot;23FEB23&quot;,&quot;action&quot;:&quot;SELL&quot;, &quot;product&quot;:&quot;NRML&quot;,&quot;pricetype&quot;:&quot;MARKET&quot;, &quot;quantity&quot;:&quot;100&quot;,&quot;option_type&quot;:&quot;PE&quot;,&quot;strike_int&quot;:&quot;50&quot;,&quot;offset&quot;:&quot;0&quot;,&quot;splitorder&quot;:&quot;NO&quot;,&quot;split_quantity&quot;:&quot;50&quot;}]\n\nalgomojo.PlaceMultiFOOptionsOrder(orders) <\/code><\/pre>\n\n\n\n<p><strong>Order Modification<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-python\">#Modifying an pending order with order_id\nalgomojo.ModifyOrder(broker=&quot;an&quot;,\n                    exchange=&quot;NFO&quot;,\n                    symbol=&quot;NIFTY23FEB2318050CE&quot;,\n                    order_id=&quot;230214000793679&quot;,\n                    action=&quot;BUY&quot;,\n                    product=&quot;NRML&quot;,\n                    pricetype=&quot;LIMIT&quot;,\n                    price=&quot;50&quot;,\n                    quantity=&quot;50&quot;,\n                    disclosed_quantity=&quot;0&quot;,\n                    trigger_price=&quot;0&quot;) <\/code><\/pre>\n\n\n\n<p><strong>Cancel Orders\/ Cancel All Orders<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-python\">#Cancel Order\nalgomojo.CancelOrder(broker=&quot;an&quot;, order_id=&quot;230214000793679&quot;) \n\n#Cancel All Orders\nalgomojo.CancelOrder(broker=&quot;an&quot;, order_id=&quot;230214000793679&quot;) <\/code><\/pre>\n\n\n\n<p><strong>Retrieving OrderHistory, Orderbook, Tradebook, PositionBook, OrderStatus, OpenPositions<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-python\">#Retriving OrderHistory\nalgomojo.OrderHistory(broker=&quot;an&quot;, order_id=&quot;230214000793679&quot;) \n\n#Retriving Orderbook\nalgomojo.OrderBook(broker=&quot;an&quot;)  \n\n#Retriving Positionbook\nalgomojo.PositionBook(broker=&quot;ab&quot;) \n\n#Retriving Tradebook\nalgomojo.TradeBook(broker=&quot;an&quot;)  \n\n#Retriving OpenPositions\nalgomojo.OpenPositions(broker=&quot;an&quot;, symbol= &quot;YESBANK-EQ&quot;, product=&quot;MIS&quot;)\n\n#Retriving OrderStatus\nalgomojo.OrderStatus(broker=&quot;an&quot;, order_id=&quot;230214000793679&quot;)<\/code><\/pre>\n\n\n\n<p><strong>Squareoff All Open Positions<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-python\">algomojo.SquareOffAllPosition(broker=&quot;an&quot;) <\/code><\/pre>\n\n\n\n<p><strong>Exit Bracket and Cover Order<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-python\">#Exit Bracket Order\nalgomojo.ExitBOOrder(broker=&quot;an&quot;, order_id=&quot;230001063923021&quot;) \n\n#Exit Cover Order\nalgomojo.ExitCOOrder(broker=&quot;an&quot;, order_id=&quot;230001063923021&quot;) <\/code><\/pre>\n\n\n\n<p><strong>Retrieve Holdings, Funds and Profile<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-python\">#Retrieve Holdings\nalgomojo.Holdings(broker=&quot;an&quot;) \n\n#Retrieve Funds\nalgomojo.Funds(broker=&quot;an&quot;) \n\n#Retrieve Profile\nalgomojo.Profile(broker=&quot;an&quot;) \n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Algomojo Python library facilitates the development of trading algorithms using the Algomojo Free API and Free Algo Trading Platform. The library supports both REST-API interfaces and provides features such as real-time order execution, smartorder execution, placing options orders, placing multi orders, order modification\/cancellation, and access to order book, trade book, open positions, orderstatus, position square-off functionalities, getquotes, profile and fund details. <\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[95],"tags":[71,41,226,31,223,225,224],"_links":{"self":[{"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts\/524"}],"collection":[{"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/comments?post=524"}],"version-history":[{"count":6,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts\/524\/revisions"}],"predecessor-version":[{"id":591,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts\/524\/revisions\/591"}],"wp:attachment":[{"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/media?parent=524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/categories?post=524"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/tags?post=524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}