Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in and Co-Creator of Algomojo (Algorithmic Trading Platform for DIY Traders)

What is PlaceSmartOrder Feature in Algomojo? How to Build Intelligent Trading Systems using PlaceSmartOrder?

4 min read

The world is moving towards Automated trading. However, bringing smartness to automated trading is the major trading requirement for most traders.

Algomojo is an automated trading platform that offers a range of features and tools for traders to build and intelligent automation in their own trading platforms like Amibroker, Tradingview, Python , MT4. MT5. Excel etc. One such feature is the PlaceSmartOrder API function, which allows traders to build intelligent trading systems that can automatically place orders based on existing trade positions in the position book.

Why PlaceSmartOrder API?

1)Place Order Based on the Open Positions in the Position Book

2)Ability to ignore exit trades if there are no Open Positions

3)Ability to Place Larger Orders with Order Slicing feature

4)Squareoff All Positions from the Position Book

Advantages of PlaceSmartOrder

1)Reduced Coding Effort for the Trading System Developers

2)Almost zero coding effort for the Traders who want to implement tradingview strategies

What PlaceSmartOrder Does?

PlaceSmartOrder is an intelligent API control used to match the position book of the trading account

Action (API Parameter)Quantity (API Parameter)Position Size (API Parameter)Current Open Position (Trading Account)Action Taken by Algomojo (Execution)
BUY10000No Open Position Found. Hence Buy +100 qty
BUY100100-100BUY 200 to match the Open Position given in API Parameter
BUY100100100No Action was Taken as the Position is already matched
BUY100200100BUY +100 to match the Open Position given in API Parameter
SELL10000No Open Position Found. Hence SELL -100 qty
SELL100-100+100SELL 200 to match the Open Position given in API Parameter
SELL100-100-100No Action was Taken as the Position is already matched
SELL100-200-100SELL – 100 to match the Open Position given in API Parameter

How to Call PlaceSmartOrder API?

PlaceSmartOrder API endpoint url

https://amapi.algomojo.com/v1/PlaceSmartOrder

PlaceSmartOrder API Sample Request for Placing Smart Orders

Here is a sample JSON message for placing 100 qty when there are no open positions.

1)If there are no open positions found in the positionbook then it places the quantity 100 shares
2)If there are open positions that exist then the position_size (Value = 0) will be matched to the positionbook that is any open position (long/short) will be squared off and brings the current open position to zero quantity.

{
    "api_key":"{your_api_key}",
    "api_secret":"{your_api_secret}",
    "data":
    {
        "broker":"up",
        "strategy":"Smart Strategy",
        "exchange":"NSE",
        "symbol":"RELIANCE-EQ",
        "action":"BUY",
        "product":"MIS",
        "pricetype":"MARKET",
        "quantity":"100",
        "price":"0",
        "position_size":"0",
        "trigger_price":"0",
        "disclosed_quantity":"0",
        "amo":"NO",
        "splitorder":"NO",
        "split_quantity":"1"
    }

}      

Reversing Position from Long to Short

If already there are long open positions say +100 shares then setting the position_size to -100 reverses the trade and matches the position book to net short position

{
    "api_key":"{your_api_key}",
    "api_secret":"{your_api_secret}",
    "data":
    {
        "broker":"up",
        "strategy":"Smart Strategy",
        "exchange":"NSE",
        "symbol":"RELIANCE-EQ",
        "action":"BUY",
        "product":"MIS",
        "pricetype":"MARKET",
        "quantity":"100",
        "price":"0",
        "position_size":"-100",
        "trigger_price":"0",
        "disclosed_quantity":"0",
        "amo":"NO",
        "splitorder":"NO",
        "split_quantity":"1"
    }

}      

Reversing Position from Short to Long

If already there are short open positions say -100 shares then setting the position_size to +100 reverses the trade and matches the position book to net long position

{
    "api_key":"{your_api_key}",
    "api_secret":"{your_api_secret}",
    "data":
    {
        "broker":"up",
        "strategy":"Smart Strategy",
        "exchange":"NSE",
        "symbol":"RELIANCE-EQ",
        "action":"BUY",
        "product":"MIS",
        "pricetype":"MARKET",
        "quantity":"100",
        "price":"0",
        "position_size":"100",
        "trigger_price":"0",
        "disclosed_quantity":"0",
        "amo":"NO",
        "splitorder":"NO",
        "split_quantity":"1"
    }

}      

Adding to the long existing position

If already there are long open positions say +100 shares then setting the position_size to +200 adds another 200 shares to the existing long position. Overall net quantity becomes +300 in this case.

{
    "api_key":"{your_api_key}",
    "api_secret":"{your_api_secret}",
    "data":
    {
        "broker":"up",
        "strategy":"Smart Strategy",
        "exchange":"NSE",
        "symbol":"RELIANCE-EQ",
        "action":"BUY",
        "product":"MIS",
        "pricetype":"MARKET",
        "quantity":"100",
        "price":"0",
        "position_size":"200",
        "trigger_price":"0",
        "disclosed_quantity":"0",
        "amo":"NO",
        "splitorder":"NO",
        "split_quantity":"1"
    }

}      

Reducing from the existing long existing position

If already there are long open positions say +100 shares then setting the position_size to +50 reduces 50 shares from the existing long position. Overall net quantity becomes +50 in this case.

{
    "api_key":"{your_api_key}",
    "api_secret":"{your_api_secret}",
    "data":
    {
        "broker":"up",
        "strategy":"Smart Strategy",
        "exchange":"NSE",
        "symbol":"RELIANCE-EQ",
        "action":"BUY",
        "product":"MIS",
        "pricetype":"MARKET",
        "quantity":"100",
        "price":"0",
        "position_size":"50",
        "trigger_price":"0",
        "disclosed_quantity":"0",
        "amo":"NO",
        "splitorder":"NO",
        "split_quantity":"1"
    }

}      

Squaring off Open Positions

Irrespective of any open positions the following JSON data will bring the open positions to zero. In other words existing positions will be squared off irrespective of net long/short positions. In this example, both quantity and position_size are set to zero.

{
    "api_key":"{your_api_key}",
    "api_secret":"{your_api_secret}",
    "data":
    {
        "broker":"up",
        "strategy":"Smart Strategy",
        "exchange":"NSE",
        "symbol":"RELIANCE-EQ",
        "action":"BUY",
        "product":"MIS",
        "pricetype":"MARKET",
        "quantity":"0",
        "price":"0",
        "position_size":"0",
        "trigger_price":"0",
        "disclosed_quantity":"0",
        "amo":"NO",
        "splitorder":"NO",
        "split_quantity":"1"
    }

}      

For more detailed information visit the Algomojo – Arrow API Documentation and the appendix section for the possible parameters to set in the JSON format.

Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in and Co-Creator of Algomojo (Algorithmic Trading Platform for DIY Traders)

How to Send Bulk Orders from Excel Sheet to…

This video tutorial explores how to send bulk orders from the Excel sheet module to multiple brokers. Bulk Order Entry allows placing multiple orders(MKT,LMT,SL,SL-LMT,CO,BO)...
Rajandran R
2 min read

Sending Futures/Spot – Signals to Two-Legged Options Execution Module…

Thought of making an open-source Tradingview Pinescript code demanded by most of the option traders to control the cost, control the risk, and configure...
Rajandran R
16 min read

Sending Smart Futures/Spot – Signals to Two-Legged Options Execution…

Thought of making an open source AFL code demanded by most of the option traders to control the cost, to control the risk, and...
Rajandran R
12 min read

2 Replies to “What is PlaceSmartOrder Feature in Algomojo? How to Build…”

  1. Hi Rajandran,

    Could you please post Amibroker afl code for Nadaraya-Watson Envelope Indicator available for free on TradingView. Thanks so much.

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More