AmiBroker AutoTrader workflow

Introduction

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.

Demo Video

The demo is available on YouTube.

Prerequisite

You need to install AutoTrader & AmiBroker software.

Overview

There is a 2-way communication that happens.

  1. Your commands like (place/cancel order, square off position etc.) flow from AmiBroker to AutoTrader & they are executed on your trading platform by AutoTrader.
  2. You portfolio details (orders, positions, margin etc.) are read by AutoTrader from your trading platform & sent to AmiBroker.

Architechture

Amibroker to AutoTrader communication flow

AutoTrader to Amibroker communication flow

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?

Code Explanation

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.

#include <algotrader-util.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.

atStaticVarSetText(“BUY_ORDER_ID”, orderId);

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);

cancelOrder(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.

Conclusion

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.

After spending more than 12 years developing Financial Software, I took a break from my career to start my own algorithmic trading setup. This new journey started well and along with my own proprietary trading systems, I also started building automation systems for retail traders, fund managers and HNIs. I was employed with firms like Morgan Stanley, HSBC & SunGard. I work on various technologies, but my strengths are building server side cloud based algorithmic trading systems built primarily using Java programming language. Apart from all of this, I am a big fan of Formula 1 racing :-)

22 thoughts on “AmiBroker AutoTrader workflow”
  • nice work…Thanks

    November 30, 2018 at 3:33 am
    • Admin says:

      Thanks

      November 30, 2018 at 11:07 am
  • Pawan Kumar says:

    This gave much needed information to us. thanks

    November 30, 2018 at 10:23 am
    • Admin says:

      Thank you

      November 30, 2018 at 11:07 am
  • Siba Swain says:

    if I connect to my office network,itsnot able to connect to zerodha.getting below error
    Failed to connect to ‘ws.zerodha.com:443’: Connection timed out: connect…is there anyway I can configure proxy

    December 3, 2018 at 7:01 am
    • Admin says:

      Not much we can do, as there might a firewall in your office blocking certain types of connections.

      December 8, 2018 at 2:10 am
  • Niraj Patel says:

    I want to create my own customize strategy in AmiBroker for auto trading , is it possible ?
    please contact me on my mobile n. 9825023442 or give me your contact number for more details inquiry.

    February 23, 2019 at 7:25 am
  • Chirag says:

    1. Auto trader software work for zerotha as now the day zerotha close the basket order facility.

    2. Auto trader put order directly on kite without using nest?

    3. Are you providing any strategy?

    4. If I used my strategy, you configured my strategy in auto trade.

    April 3, 2019 at 6:09 pm
    • Admin says:
      1. Yes, configure AutoTrader to use KITE platform
      2. Yes, answer same as previous.
      3. Only sample moving average strategies
      4. Nope, you will have to read the help material and do it yourself
      April 4, 2019 at 9:45 am
  • Atul Mehta says:

    UNFORTUNATELY THERE IS NO CONTACT NO MENTION ON THE WEB SITE, I DON’T KNOW HOW AN INTERESTED PARTY WILL BE ABLE TO CONTACT YOU, A WEEK BEFORE I LEFT A MESSAGE THROUGH A MAIL AS WELL NO RESPONSE RECEIVED IN LAST SEVEN DAYS. I DON’T KNOW WHAT IS THE PURPOSE OF MAKING THIS WEB SITE ?

    June 21, 2019 at 10:49 am
    • Admin says:

      All queries are taken on help@stocksdeveloper.in mail address. We did not find your mail. Please resend it.

      We support 11 systems in total & there is a lot of development work as well. Hence we do not take calls, as people consume too much of our time.

      June 25, 2019 at 5:31 am
  • sudhin says:

    Is it possible to have the feeds into amibroker today?

    May 21, 2020 at 11:43 am
    • Pritesh says:

      Not sure we understand your question.

      May 24, 2020 at 10:02 am
  • AKASH says:

    great sir u r autotrader is awasome…i
    like it..

    June 17, 2020 at 11:29 am
    • Pritesh says:

      Thank you…

      June 17, 2020 at 12:06 pm
  • AKASH says:

    VERY NICE, autotrader & autotrader web bt plz provide call support if possible in future…

    June 17, 2020 at 11:32 am
    • Pritesh says:

      Support is done by developers & providing on-call costs a lot. But we will come up with some solution to this…

      June 17, 2020 at 12:07 pm
  • kumar hosamani says:

    hi!
    Im retail trader I want your assitance regarding amibroker setup , real time data feed, ur auto trader web, and some of my stratergies coded. is it possible to heip me out .
    regards kumar hosamani

    June 19, 2020 at 2:59 pm
    • Pritesh says:

      Sir,

      It is not possible to provide personal consultation. You are advised to go through all the help material available on our website and youtube. In case you face any issue, always write a mail to support.

      June 20, 2020 at 8:16 am
  • Mehdi says:

    Dose it works for iran’s stock

    September 27, 2020 at 11:53 pm
    • Pritesh says:

      What is iran’s stock?

      September 29, 2020 at 7:18 pm
Leave A Comment