Algorithmic trading has become the buzz word in recent years. Growing markets, regulatory approval, increasing number of algorithmic trading platform providers, all have led to a surge in the number of trading firms and retail traders switching to the new way of trading. Algorithmic trading platform providers have played a key role, along with the brokers, in making algorithmic trading accessible to retails traders and firms.
An algorithmic trading platform allows for execution of various types of trading strategies across asset classes like equities, derivatives, currencies etc. It also provides for back-testing, paper trading and live trading with order management and risk management systems in place. Check our article on Top Algo Trading Platforms in India to know more about them.
A trading firm or a retail trader can start trading markets via algo trading by opening a trading account with a broker who provides such an algo trading platform. Apart from this, there are other requirements that need to be fulfilled for algo trading. Check our article on the requirements for Setting-up an Algo Trading Desk.
There are different ways in which one can trade markets using these platforms. One method is using the trading APIs provided by the platform developers. That brings me to the topic of the day, i.e. “Trading markets using APIs”. This post will provide a brief overview of API, its types and examples of some platform providers offering such APIs for trading.
Application Programming Interface (API)Application Programming Interface, commonly referred as API, consists of a set of rules describing how one application can interact with another application.
When trading one needs access to different market quotes, orders are required to be sent based on the buy/sell signals generated by the applied strategy, and the open trading positions need to be continuously monitored till squared off.
A trading API allows a trader to connect his trading application to the algorithmic execution platform situated at the brokers end and in effect connect with the exchange. Thus, a trading API facilitates the interaction between these two software's and allows for the exchange of data and requests.
An API developer (i.e. the algorithmic trading platform provider) may offer different types of trading APIs in different programming languages for the convenience of its users.
- APIs are either SOAP or REST or WebSocket etc.
- People build libraries/frameworks/
wrappers on top of API, which can be in different programming languages. Eg. Zerodha's Kite connect API have different libraries, which are built on different languages (Python, PHP etc)
Types of APIsNow let us take a look at the different API types. I found this chart which gives a good break-up of the API types. We will cover some of the APIs that find usage in trading.
REST APIsREST or REpresentational State Transfer is used for creating API’s for applications in a standardized way. It involves using HTTP for making requests. It is used in applications wherein some information needs to be transferred based on user action. For real time transfer or streaming of data, REST is not the best protocol and WebSockets can be used instead. We have covered WebSockets in the next part.
Zerodha’s Kite Connect offers a set of REST-like APIs that can be used to build a complete trading and investment platform. All requests happen over HTTPs. Inputs are form-encoded parameters and responses from the API server are in JSON. You can read the other details about it here.
WebSocket APIsWebSocket is a protocol that allows for transferring data to and from the servers. The socket that is connected to the server stays open for communication. Thus, data can be pushed or requested in real-time on demand.
Zerodha’s Kite Connect Trading APIs use the WebSocket API for streaming quotes across instruments and markets during live market hours. To connect to the Kite WebSocket API, you will need a WebSocket client library in your choice of programming language (Python, php). Quotes are delivered via the API and are used in the implementation of custom trading strategies. You can read in detail about the streaming WebSocket APIs here.
Library-based APIsThe API is either SOAP or REST, but the person/organization which created the API, has written some libraries so that users can include that library in their code, and use pre-defined functions.
The IBrokers API allows one to trade markets on Interactive Brokers (IB) using R programming. One needs to install the IBrokers library which has various functions to pull market quotes, send/modify orders, extract historical data, contract information, account information etc. We also have the IBridgePy library-based API developed by Dr. Hui Liu which is a wrapper for Interactive Brokers’ C++ API.
Class-based APIs (object oriented) – a special type of library-based APIThese are a special type of library-based APIs which use the Object Oriented Programming (OOP) model. The model revolves around objects which are used to construct programs. The objects consist of attributes (data fields) and methods (actions).
The Presto Fuse XL offered by Symphony Fintech is an EXCEL based API which allows for automated trading. Excel traders can develop custom strategies by writing formulas/macros via VB scripting. Check here to read more about Presto Fuse XL.
Next StepThese were some of the API types that we explored in this article. We hope that it gave you a good introduction to APIs used for trading markets. Considering the wide usage of APIs by traders, we have included dedicated API knowledge sessions in our Executive Programme in Algorithmic Trading (EPAT™) curriculum.
Next up is our post on how to implement Python in Interactive Brokers C++ API using IBridgePy and run algorithmic trading strategies in live market.