Non-tech founder’s guide to choosing the right software development partner Download Ebook
Home>Blog>Technical aspects of algorithmic trading. part #2

Technical Aspects of Algorithmic Trading. Part #2

In the previous article, we discussed some key concepts, such as different markets and their characteristics, trading software, and chart visualizations of the market. 

In this article, I would like to dive a little more into the technical aspects of algo trading and discuss the usage of public APIs.

Generally speaking, one could have only two ways of interacting with trading software: manual or automatic.

Manual ways include:
  • Web interface
  • Mobile application
  • Phone calls to your broker representative (it is still possible for stock markets, yes)
Manual interaction could be good if the amount of trades is relatively small. For example, if I wish to buy some Bitcoin and hold it for months or even years, I’m super comfortable opening a website and making my trade there.

But there are a lot of trading strategies that require frequent operations. For example, any day trading strategy implicitly suggests that a trader will execute some daily trades, be it tens, hundreds, or even thousands. And, of course, in such a situation, the only convenient way is to automate trading activity.

Many crypto exchanges are offering API access to their services. In my experience, roughly 110 out of 220 currently active exchanges have such an option, which means you can automatically trade on half of them. Yes, you are right; this also means that you can’t automatically trade on the other half.
There are the following types of API provided:
  • REST
  • WebSocket
  • FIX
Almost all exchanges offering API access support REST, but its functionality may vary. On some platforms, you can access all available functionality this way, while on many others, it could be limited in a certain way. In my experience, the most common functions, such as getting prices, placing orders, and checking balances, are generally available. But you should check each case independently.

A lot of exchanges, in addition to REST, also support WebSocket protocol. Since working with this technology is not as easy as with REST, its functionality often could be limited. Generally speaking, price quotations via WebSocket are available almost everywhere, but other functionality could or could not be supported.

FIX protocol has its roots in NASDAQ and is widely used in stock markets. Nevertheless, some crypto exchanges also support this technology, among others. But it is a rare situation, so we will not discuss it further.

While working with API, you can face some issues. Some could be easy to overcome, while others could be hard. Let me introduce my list of such issues taken from my experience working with more than a hundred crypto exchanges.

Does the particular exchange have a public API or not?

Usually, if an exchange has an API, you can find a link to its documentation on the main website, most often in the footer part of the website. But in some cases, there could be no such link, which does not necessarily mean there is no public API. Feel free to use your favorite search engine to search for API documentation in this situation. Also, a good practice could be looking at GitHub directly since, if it existed, it would be there.

REST API documentation has issues.

Sometimes you can discover that official documentation is not very clear or confusing. From my experience:
  • Some methods definitely should be there, but they are missing (there is a method for getting candles by ticker, but there is no method to get a list of tickers)
  • Some methods don’t have a clear description of their parameters (timestamp could have plenty of formats, and it is unclear which one should be used)
  • All the methods are described very well, but instead of a real endpoint URL, you see a meaningless placeholder
 Ways to solve the problem:
  • Try to find official repositories with API implementation. If they exist, studying the source code could be of great help.
  • Try to find third-party repositories with API implementation.
  • ccxt is a tremendous open-source project supporting a lot of exchanges. It utilizes languages such as Python, JavaScript, C#, and PHP and could greatly help.
  • If nothing helps, sometimes you could guess some missing information or try to enumerate possible options and see whether this could help (i.e., try every possible format of timestamps)
 Documentation is fine, but the server sends something strange in response.
 In this scenario, everything seems clear until you get a real response from the exchange API. Examples are:
  • Unclear or non-documented error without further clarification (ERROR_42 - what could it really mean?)
  • You get OK as a response, but you didn’t get the data requested (you requested a candles array, and you get just OK and no candles at all, even not an empty array)
  • Just a blank string as a response (“”)
 Ways to solve the problem:
  • Try to contact support for the exchange describing in detail the problem and how you were trying to fix it. The reaction time and quality could vary from fast and decent to nothing at all, but trying it is worth it.
 When placing an order, you get “This ticker doesn’t have API support”.
 This probably means it’s a relatively new market, and while it is fully operational via the website, it has no support via API.
 Ways to solve the problem:
  • Probably you have to wait. Chances are they will add this ticker to API someday
 When you subscribe to some WebSocket channel, your connection interrupts with a 1006 error.
 Despite the fact that error 1006 is clearly defined as reserved in RFC, it is often used by the endpoint if it doesn’t like your activity. Some possible causes could be:
  • You don’t use a heartbeat (or ping-pong) mechanism at all
  • You don’t use a heartbeat (or ping-pong) mechanism properly
  • You are trying to fetch too much data (but the limits are not clearly documented)
  • Or anything else 
Ways to solve the problem:
  • If this is a heartbeat problem, try to use it in a proper way (each exchange could have its own rules)
  • If you are doing everything right, but the endpoint still disconnects you from time to time, catch this event and do connect again.
Conclusion
In this article, we dove into some technical aspects of algo trading via API. We considered different types of API and discussed some technical issues which could arise during interactions with crypto exchanges.
We are going to discuss even more interesting stuff in our next materials. Stay tuned!

P.S. Feel free to contact me via email if you have any questions alexey.chernysh@jetrockets.com

Discover More Reads

Real Stories & Real Success

Do you have a tech idea?

Let’s talk!

By submitting this form, you agree with JetRockets’ Privacy Policy

If you prefer email, write to us at hello@jetrockets.com