Trading APIs Using Websockets

Trading APIs Using Websockets
Photo by Austin Distel / Unsplash

An increasing number of trading venues are now offering websockets as a connectivity medium for the relay of real time messages. It has become easier for traders with technical skills, or vendors supplying applications to integrate dashboarding and trading applications to work with realtime APIs.

While the crypto world with newer generation of exchanges have been closer to the cutting edge, traditional exchanges have also started catching up by deploying websocket conncetivity.

A few notable brokerage firms such as Interactive Brokers, Saxo Bank, Ameritrade and more now offer websocket connectivity to authenticate, stream and send orders to their exchanges. If you have an interest in learning about real time trading, it might be worth setting up an account with a compatible broker and develop inside a sandbox environment.

Particular skills to be successful in this area will be to find the appropraite data will involve sourcing the list of companies, gathering historical market data, testing your system in a sandbox enviroment, logging market data (or finding appropriate historical data), creating a back testing envrionment and testing a variety alogirthms to see that you get the desired performance.

While a large volume of executions on equity exchanges are executed via high frequency traders, the impact of these traders can vary depending on your trading objectives and rigorous analysis. There may be some tickers for which the these traders might not be interested or your holding periods are longer and trades need not to be as frequent for you to operate independently of these traders (while taking advantage of tigher spreads).

Getting Historical Data for Backtesting

Depending on your brokerage some level of historical data with varying levels of granularity depending on time span and how far back you need to look are available. Unfortunately it is not likely that you will be able to stream all instruments concurrently for you to monitor all tickers simultaneously. High resolution historical data maybe available for a fee from the exchange or other data brokers, barring that, it might be necessary to create your own data loggers to record tick by tick data for a select set of instruments which can be replyed to test trading algorithms against.

The IEX exchange is incredibly helpful in this manner as they publish daily a full list of messages eminating from their exchange and for free. Each file is approximately 3~4 GB large compressed and messages can be extracted and replyed to simulate exchange activity.