Points to remember while Trading through API

Below are the most important points that one must remember while trading through API.


  • Renew your API subscription well before its expiry.
  • Thoroughly check and test your code with small quantity for at least 2 weeks before deploying huge capital.
  • Trade API is not any kind of Indicator or Buy/Sell Software.
  • The two most possible reasons for order request fail. 1. API server issue 2. Internet issue
  • Frequently monitor your system for errors and issues. Unattended setup is not recommended.
  • Running trading system in personal computer/laptop is not recommended due to network issues.
  • Highly recommended to run your trading system in cloud server only.
  • Use dedicated computer/server for Trading system and Don’t mix other computer activities with Trading.
  • Use only registered/licensed version of software’s.
  • For downtime, issues, errors and bugs, please contact your stock broker.
  • Trade API is not meant for High Frequency Trading. For throttle information, refer API documentation.
  • Avoid placing orders in first and last five minutes of market hours, brokers will be routing large number of orders (AMO & SqOff) in this time, so your order request will fail most of the time.
  • Monitor your system during high volatility time, your order request may fail due to huge traffic.
  • Our software just acts as an intermediary between you and API server. Any error thrown will be from API server side or from your system.
  • Ensure the system time is set to IST and up-to date
  • System date/time format should be dd-MMM-yyyy and  HH:mm:ss
  • Before start of trading, try firing test order to confirm bridge connectivity.
  • Use Cover Order wherever possible to reduce risk
  • Leverage Cloud Server for low latency (Example: out of 10 orders, we are able to get better price in 8 orders)
  • Use separate cloud server for each trading system.
  • Split big orders to get better price as well as to reduce risk (Example: Instead of placing 100000 Qty in single order, you may place two order with each 50000 Qty. This way even if one order is failed, the other may be executed.)
  • Run your trading system in multiple symbols to diversify.

Cloud Server

  • Change your Cloud Server password frequently and remember the password.
  • If you forgot your server password, then there is no way to retrieve it.
  • Completely shutdown your server everyday morning for 30mins, this will improve server performance on next boot
  • Do not install any software other than what is required for trading.
  • Do not store important and sensitive information in cloud server, if storing anything please do regular backup.
  • Ensure that the server time is set to IST and up-to date, before opening any trading applications.
  • Cloud server date/time format should be dd-MMM-yyyy & HH:mm:ss
  • Do not use the close button of RDP session to exit as this will disconnect the user and all the running applications will stop working.
  • Always use ExitRDP app to exit from server. This will keep your server session on.
  • Don’t click on options like ‘Terminate’ or ‘Delete’ or ‘Destroy’ from Cloud Console. This will permanently delete your server and you can’t retrieve it.
  • Post market hours, properly close all applications and do necessary cleanup
  • Your card will be charged automatically by cloud provider at month end, so keep sufficient balance.
  • For downtime, issues, pricing and charge details, please refer cloud provider website.


  • Download Macro enabled excel files only from trusted source.
  • Scan the downloaded excel file for virus before opening.
  • Disable ‘Auto Save’. Auto saving excel files during real-time data update, may corrupt your excel file.
  • Do not save excel file while real-time data is updating, else excel file may become corrupt.
  • Do not open VBA editor and edit your macro’s while real-time data is updating through RTD or DDE server.
  • Set all required system parameters before starting trading system and never modify any value once trade system is started.
  • Do not rebuild excel calculation tree, while real-time data is updating else your excel workbook may corrupt.
  • Excel should be in maximized state while system is running, if minimized, excel will stop calculating formulas, so your trading system will not work.
  • Ensure RTD interval is set to 0


  • Take real-time data only from Authorized data vendor.
  • Set all required system parameters before starting trading system and never modify any value once trade system is started.
  • Do not edit the AFL code while system is running
  • AmiBroker should be in Maximized state, if minimized AmiBroker will stop executing the AFL code, so your trading system will not work.
  • If you are doing chart based trading, then make sure all charts are tiled and visible. AmiBroker will not execute AFL code in hidden charts.
  • If you are using scanner, then make sure you are dynamically generating un-common parameters in AFL code. (Ex: Trade Symbol etc)
  • Ensure correct settings in AFL scanner.
  • Save your layout, so that the same can be loaded back on next running.
  • Do not change chart interval once trading system is started.
  • Your ‘Time’ Parameters like Trade Start & End Time and SqOff time must be multiples of your chart/scanner time interval. (Ex: Chart Interval: 5Min; SqoffTime: 15:03 = Wrong, it should be 15:05 or 15:00)
  • Set ‘Realtime chart refresh interval’ to 0. Menu –> Tools –> Preferences –> Intraday Settings
  • Select ‘Start Time of Interval’. Menu –> Tools –> Preferences –> Intraday Settings
  • Check ‘Align Minutes Bars to regular Market Hours’. Menu –> Tools –> Preferences –> Intraday Settings
  • Set correct Market hours in Menu –> File –> Database settings –> IntraDay settings

Coding Guidelines (AFL/VBA)

  • Ensure you have declared all four signal types i.e. BUY-SELL-SHORT-COVER
  • Use static variables/dictionaries to restrict multiple order firing.
  • Ensure your signals are not repainting. If your AFL code uses ‘CLOSE’ field, then most probably it will repaint.
  • Ensure your signals are not repeating. Use Exrem in your AFL code to remove repeated signals.
  • Ensure your code does not generate entry and exit signals on same bar. Example BUY and SELL signal in same BAR. To avoid this add Buy == 0 in your SELL conditions and Short == 0 in your COVER conditions.
  • Each entry signal should have corresponding exit signal, and your first signal of the day must be always Entry signal and the last signal of the day must be a exit signal. Example: BUY-SELL-BUY-SELL or SHORT-COVER-SHORT-COVER

Was this article helpful?

Related Articles

Leave A Comment?