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.
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.
Supported Brokers: All Algomojo Supported Brokers
Basic Features of Python Trading API
- Execute Orders in Realtime
- Place Smart Orders to match Position Book
- Split Larger orders into Multiple Smaller Orders
- Single Client Execution Orders
- Multi-Client Execution of Orders
- Multi-Broker Execution of Orders
- Place Multiple Bracket Orders/Cover Orders
- Place ATM/ITM/OTM Option Orders
- Place Multi Leg Options Orders
- Modify/Cancel Orders
- Cancel All Pending Orders
- Retrieve Orderbook
- Retrieve Tradebook
- Retrieve Order History
- Retrieve Open Positions
- Square off Open Positions
- Square off All Open Positions
- Exit Bracket Order
- Exit Cover Order
- Get live quotes for the trading instruments
- Access Fund/Margin Details and many more functionalities.
For more details on each API behavior, Pease see the Algomojo API documentation.
Visit here for more detailed Algomojo python documentation for supporting functions
How to Install Algomojo Python Library?
Install from PyPI using the simple PIP command
pip install algomojo
It is highly recommended to use Python 3.x versions
How to Send Orders using Algomojo Python Library?
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.
from algomojo.pyapi import *
# Set the API Key and API Secret key obtained from Algomojo MyAPI Section
algomojo=api(api_key="46ad9245cca3dfe957deb235a39d02a3",
api_secret="d8286408c0ff99fbdbadf549692fc40a")
# Place Market Order in the trading symbol RELIANCE-EQ
algomojo.PlaceOrder(broker="an",
strategy="Python Example",
exchange="NSE",
symbol="RELIANCE-EQ",
action="BUY",
product="MIS",
quantity=10)
#Place Limit Order in the trading symbol ZOMATO-EQ
algomojo.PlaceOrder(broker="an",
strategy="Python Example",
exchange="NSE",
symbol="ZOMATO-EQ",
action="BUY",
product="MIS",
quantity=10,
pricetype="LIMIT",
price=54)
How to Send Large Orders in Options using Algomojo
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.
#Place Larger Order in options with Split Order mode enabled
algomojo.PlaceOrder(broker="an",
strategy="Python Example",
exchange="NFO",
symbol="NIFTY23FEB2318000CE",
action="BUY",
product="NRML",
quantity=10200,
pricetype="MARKET",
splitorder="YES",
split_quantity=1800)
Place Smart Orders to Match the PositionBook – useful for dynamic position sizing
#PlaceSmartOrder to match the open positions
algomojo.PlaceSmartOrder(broker="an",
strategy="Python Example",
exchange="NSE",
symbol="RELIANCE-EQ",
action="BUY",
product="MIS",
pricetype="MARKET",
quantity="10",
price="0",
position_size="10",
trigger_price="0",
disclosed_quantity="0",
amo="NO",
splitorder="NO",
split_quantity="1")
Get Realtime Quotes
algomojo.GetQuote(broker="an", exchange="NSE", symbol= "ZOMATO-EQ")
Sending a Bracket Order
#Place Bracket Order
algomojo.PlaceBOOrder(broker="an",
strategy="Python Example",
exchange="NSE",
symbol="YESBANK-EQ",
action="BUY",
pricetype="LIMIT",
quantity="1",
price="16.5",
squareoff="2",
stoploss="2",
trailing_stoploss="1",
trigger_price="0",
disclosed_quantity="0")
Sending a Cover Order
#Place Cover Order
algomojo.PlaceCOOrder(broker="an",
strategy="Python Example",
exchange="NSE",
symbol="YESBANK-EQ",
action="BUY",
pricetype="LIMIT",
quantity="1",
price="16.5",
stop_price="15")
Placing F&O Options Order
#Place ATM Call Options Order
#offset = 0 selects ATM strike price with spot at underlying
algomojo.PlaceFOOptionsOrder(broker="an",
strategy="Python Example",
spot_symbol="NIFTY",
expiry_date="23FEB23",
action="BUY",
product="NRML",
pricetype="MARKET",
quantity="50",
price="0",
option_type="CE",
strike_int="50",
offset="0",
splitorder="NO",
split_quantity="50")
#Place 2 strike higher OTM Call F&O Options Order
#offset > 0 selects higher strike price relative to ATM strikes with spot at underlying
algomojo.PlaceFOOptionsOrder(broker="an",
strategy="Python Example",
spot_symbol="NIFTY",
expiry_date="23FEB23",
action="BUY",
product="NRML",
pricetype="MARKET",
quantity="50",
price="0",
option_type="CE",
strike_int="50",
offset="2",
splitorder="NO",
split_quantity="50")
#Place 3 strike lower ITM Put F&O Options Order
#offset < 0 selects higher strike price relative to ATM strikes with spot at underlying
algomojo.PlaceFOOptionsOrder(broker="an",
strategy="Python Example",
spot_symbol="NIFTY",
expiry_date="23FEB23",
action="SELL",
product="NRML",
pricetype="MARKET",
quantity="50",
price="0",
option_type="PE",
strike_int="50",
offset="-3",
splitorder="NO",
split_quantity="50")
Multi-Legged Options Order – Placing Short Straddle Orders
#Place Multiple Options Orders to the Same Broker/Different Brokers
orders=[{"api_key":"46ad9245cca3dfe957deb235a39d02a3","api_secret":"bd99a1c4e0a0235b2b9162aa1519a554","broker":"an","strategy":"Options Spread","spot_symbol":"NIFTY","expiry_date":"23FEB23","action":"SELL","product":"NRML","pricetype":"MARKET","quantity":"100","option_type":"CE","strike_int":"50","offset":"0","splitorder":"NO","split_quantity":"50"},
{"api_key":"46ad9245cca3dfe957deb235a39d02a3","api_secret":"bd99a1c4e0a0235b2b9162aa1519a554","broker":"an","strategy":"Options Spread","spot_symbol":"NIFTY","expiry_date":"23FEB23","action":"SELL", "product":"NRML","pricetype":"MARKET", "quantity":"100","option_type":"PE","strike_int":"50","offset":"0","splitorder":"NO","split_quantity":"50"}]
algomojo.PlaceMultiFOOptionsOrder(orders)
Multi-Legged Options Order – Placing Short Strangle Orders
#Place Multiple Options Orders to the Same Broker/Different Brokers
orders=[{"api_key":"46ad9245cca3dfe957deb235a39d02a3","api_secret":"bd99a1c4e0a0235b2b9162aa1519a554","broker":"an","strategy":"Options Spread","spot_symbol":"NIFTY","expiry_date":"23FEB23","action":"SELL","product":"NRML","pricetype":"MARKET","quantity":"100","option_type":"CE","strike_int":"50","offset":"0","splitorder":"NO","split_quantity":"50"},
{"api_key":"46ad9245cca3dfe957deb235a39d02a3","api_secret":"bd99a1c4e0a0235b2b9162aa1519a554","broker":"an","strategy":"Options Spread","spot_symbol":"NIFTY","expiry_date":"23FEB23","action":"SELL", "product":"NRML","pricetype":"MARKET", "quantity":"100","option_type":"PE","strike_int":"50","offset":"0","splitorder":"NO","split_quantity":"50"}]
algomojo.PlaceMultiFOOptionsOrder(orders)
Order Modification
#Modifying an pending order with order_id
algomojo.ModifyOrder(broker="an",
exchange="NFO",
symbol="NIFTY23FEB2318050CE",
order_id="230214000793679",
action="BUY",
product="NRML",
pricetype="LIMIT",
price="50",
quantity="50",
disclosed_quantity="0",
trigger_price="0")
Cancel Orders/ Cancel All Orders
#Cancel Order
algomojo.CancelOrder(broker="an", order_id="230214000793679")
#Cancel All Orders
algomojo.CancelOrder(broker="an", order_id="230214000793679")
Retrieving OrderHistory, Orderbook, Tradebook, PositionBook, OrderStatus, OpenPositions
#Retriving OrderHistory
algomojo.OrderHistory(broker="an", order_id="230214000793679")
#Retriving Orderbook
algomojo.OrderBook(broker="an")
#Retriving Positionbook
algomojo.PositionBook(broker="ab")
#Retriving Tradebook
algomojo.TradeBook(broker="an")
#Retriving OpenPositions
algomojo.OpenPositions(broker="an", symbol= "YESBANK-EQ", product="MIS")
#Retriving OrderStatus
algomojo.OrderStatus(broker="an", order_id="230214000793679")
Squareoff All Open Positions
algomojo.SquareOffAllPosition(broker="an")
Exit Bracket and Cover Order
#Exit Bracket Order
algomojo.ExitBOOrder(broker="an", order_id="230001063923021")
#Exit Cover Order
algomojo.ExitCOOrder(broker="an", order_id="230001063923021")
Retrieve Holdings, Funds and Profile
#Retrieve Holdings
algomojo.Holdings(broker="an")
#Retrieve Funds
algomojo.Funds(broker="an")
#Retrieve Profile
algomojo.Profile(broker="an")