AutoTrader is an automated trading software (API) connecting to many Indian stock trading platforms.
This article explains how AutoTrader works with AmiBroker. Primarily targeted for users of AutoTrader to improve their understanding & make them better prepared to debug any issues that they may face.
The demo is available on YouTube.
You need to install AutoTrader & AmiBroker software.
There is a 2-way communication that happens.
- Your commands like (place/cancel order, square off position etc.) flow from AmiBroker to AutoTrader & they are executed on your trading platform by AutoTrader.
- You portfolio details (orders, positions, margin etc.) are read by AutoTrader from your trading platform & sent to AmiBroker.
More details of this architecture can be read at Connecting AutoTrader with other softwares
API functions provided by AutoTrader can be found at AutoTrader Functions
How AmiBroker & AutoTrader communicate?
All functions provided by AutoTrader are included in algotrader-util.afl file. In order to make these functions available to your strategy afl, you must include this afl. Write following line at the top of your afl.
Now you can use AutoTrader functions. Let us see an example below:
orderId = placeOrderUsingParams(“NSE”, “SBIN”, “BUY”, “MARKET”, 10, 250.20, defaultTriggerPrice(), 1);
You can see that all placeOrder* functions return an order_id once an order is successfully passed to AutoTrader.
This order_id can then be stored for later use.
Later, we can use this id in all functions that accept an order_id. For example, we can retrieve order details or cancel the order.
buyOrderId = atStaticVarGetText(“BUY_ORDER_ID”);
buyOrderStatus = getOrderStatus(buyOrderId);
How does the code work?
The placeOrder* function will simply write order details into a file (C:\autotrader\data\order\orders.csv). A new line with the order details is appended to the file. AutoTrader software keeps a watch on this file, as soon as it is changed; AutoTrader reads it & parses the line. AutoTrader understands that there is a request to place an order. AutoTrader parses order details from the line & then places an order onto the trading terminal.
All functions that require reading of portfolio data work in a reverse way. As seen from the architecture diagram, AutoTrader will write the platform details to respective files. This process is repeated every N seconds (defined by AutoTrader setting SYNC_INTERVAL). For example, getOrderStatus(orderId) function will read the platform_orders.csv file, find the row with given order id & then read its status.
You can also look at Connecting AutoTrader with other softwares to get more insights.
As you can see from the article, all communication takes place via simple csv files. So whenever you are debugging an issue; you can view these files to find a root cause.