7 steps to start a trading API

Written by
Dóra N.
Fact checked by
Adam N.
Updated
Oct 2020

Let’s say you have a trading strategy in mind that is pretty complex and needs automation. You cannot do it manually on the web platform. You may have already started to code it, or at least you know what you want to build. 

In this article we will guide you through seven clear steps to help you connect your code to the markets. At the end you will have a live account with a working automated trading strategy. Yes, you will use a trading API.

API is an acronym for Application Programming Interface. This interface allows the two unrelated systems (your brokerage account and the application you’ve built) to interact with each other. They are pretty popular in the world of algorithmic trading. 

I. Build trading strategies you wish to automate

Let’s say you have already come up with a trading strategy. Now you need to code it. It’s the verge of algorithmic trading. We recommend drafting a pilot trading strategy first — a simple code you can use to test the API and its basics features. If it runs then you can switch a complex one as now you know that problems are not due to the complexity of the strategy. Keep your well-thought-out strategy in your back pocket for now. You want to be sure your simple code runs smoothly on dummy data before you go live with your strategy in the real world. 

II. Filter brokers with relevant trading APIs

In an ideal world all brokers run an impeccable trading API. In reality, only a handful do, so you need to filter them out.

You obviously need one that serves retail clients from your country. Here is an interesting fact: not all brokers serving retail clients provide access to their API for such clients; some keep it for institutional clients only. Sad stuff. 

Make sure the broker provides the asset type you want to trade with via the API. For instance, if you want stocks or options, be certain that the broker provides stock trading api or stock options trading api too, not just FX. Don’t worry there are some exotics who enable trading api for cryptocurrency as well.

Pro tip: unless you have already tried out a handful of brokers with trading APIs and you are expert in algorithmic trading, we recommend you filter brokers that offer a demo account. 

We at BrokerChooser are currently working on a comparison table for trading APIs. Leave a comment below if you want us to speed up our efforts.

III. Rank brokers and select the best fit

If you are lucky you might end up with several brokers after the filtering. Now you need to rank them to select the best one for your needs. Consider these two factors to prepare your ranking:

  • General characteristics. Is the broker reliable and safe to invest with? Do they offer low fees, is account opening simple and fast, etc.?

  • API characteristics. You prefer REST or Websocket? Does the API have good documentation? Is there an active community around the trading API? Does the broker provide support for the API?

As a rule of thumb, if you are a beginner with trading APIs, use a broker with a solid background. For example, it's a great sign for a broker’s safety if it’s in operation for a long time, listed on an exchange, or has a banking background. Be sure that the API characteristics are great and don’t pay too much attention to fees for now. You can always switch to lower fees with less API support later.

IV. Open a demo account and sign up for the API

Once you have selected the preferred broker, you need to open a demo account with them. At most brokers, setting up a demo account is fast and simple. Some, however, will require you to go through a full client onboarding process which can take a couple of days.

Once you have your account up and running, most brokers will ask you to sign up for access to the API separately. You’ll likely need to complete a simple form and you will get your token to access the API. 

Few brokers ask for additional documentation to be attached to the application when you set up the demo account. Others will only require this when you switch to a live account. 

V. Set up the API and start with sample codes

Once you sign up and receive your token, you can start to familiarize yourself with the API. Here are three options for using a trading API:

  • The “Playground” (provided by the broker) is where you can log in and run your basic codes.

  • Install a cross platform (API Client Tool) . This is for cases where you have not yet finalized your application but your code is too complicated for the playground (e.g. Postman or Insomnia).

  • Your own application

Brokers do not necessarily provide all three options for algorithmic trading. To get comfortable with the API, your best bet is the playground or the cross platform.

In the API documentation on the broker’s page there are a couple of sample codes that will help you familiarize yourself with the API. Start with these, then run your simple pilot trading strategy. Once it runs smoothly, move on to your real trading strategy. 

VI. Test your strategy for 2-3 months

This is probably the most important step. You need to test your strategy with the demo account for a longer period of time — we recommend 2-3 months. This is important for two reasons:

  • Weeding out technical glitches. Do the API, the broker and your application work well together in each case? Chances are you will run into some issues, the most common being data set connection problems.

  • Making sure your strategy works. You may need some time to do your backtesting on real historical data. You will also need time to see the market is active enough for your strategy. Thirdly, some assets need a longer timeframe.

Expect a lot of finetuning and hope that only a few errors pop up. Trust us and dedicate this time to testing. 

VII. Start using the trading API on a live account

If it all works out fine, this is your final step. Upgrade your demo account to a live account and start using your trading API. Enter the world of algorithmic trading. Even though your API is ready to use, there are a few things you’ll need to do for the live account. You will have to provide data about yourself and deposit some funds to your account. After that you are good to go. 

Congrats!

This is where the journey starts.

You are done! You have set up your own your trading strategy running via the trading API on a live account with real money. Crazy. 

One last thing: you want to make sure you are making a profit! Monitor your strategy, the broker, and the API. Once you get the hang of it, I bet you will start developing more and more trading strategies. Good luck!

Get a clear view of your entire portfolio
Track all your accounts in one place and get a full picture of your investments.
portfolio tracker screenshot

Everything you find on BrokerChooser is based on reliable data and unbiased information. We combine our 10+ years finance experience with readers feedback. Read more about our methodology.

author
Dóra Nagy
Author of this article
Dóra is a former Product Owner for BrokerChooser. She initially joined us through capstone project work at CEU, focusing on trading APIs provided by brokers. This helped lay solid ground for working with the Tech team in her later role as Product Owner. BrokerChooser relied on her 10 years of Project Management experience, to manage IT and content-related topics.
×
I'd like to trade with...