Exchange integration layer

MultiTrader platform has capability to connect to 21 cryptocurrency exchanges. Each cryptocurrency exchange exposes its functions for other programs via API. The API stands for Application Programming Interface. MultiTrader is using REST and Websocket API.

Exchange integration layer is part of the MultiTrader platform that is responsible for hiding the complexity of the communication mechanism and the differences of the APIs between the exchanges.

REST and Websocket

REST and Websocket are two different types of protocols that may be used. REST protocol is used to trigger single time read or write operations via the API. REST operations are initiated by MultiTrader. When MultiTrader calls an exchange via REST interface, it receives just single response for its query, a snapshot of the price data of the exchange from the moment when it was called. In case the state of exchange changes, MultiTrader will not receive any updates. This is PULL operations model. If the exchange exposes its data via Websocket connection, than it will PUSH the updates to the MultiTrader. Only few larger exchanges support this protocol, however it becomes more and more popular also across smaller exchanges.

ExchangePublic APIPrivate API
ANXPRORESTREST
BinanceWebsocketREST
BitbayRESTREST
BitFinexWebsocketREST
BitstampWebsocketREST
BittrexRESTREST
Cex IOWebsocketREST
Coinbase PROWebsocketREST
CoinoneRESTREST
CryptopiaRESTREST
ExmoRESTREST
GeminiWebsocketREST
KrakenRESTREST
KucoinRESTREST
LivecoinRESTREST
LunoRESTREST
PoloniexWebsocketREST
UpbitRESTREST
YobitRESTREST
Wex [disabled]RESTREST
Gate.io [disabled]RESTREST

 

 

Exchange operations

Exchange integration layer provides set of functions that are common across all the exchanges:

  • reading ticker prices for each currency pair
  • reading order books
  • placing order requests
  • checking trade history
  • checking funds in the wallets
  • transferring funds between the wallets

Each exchange uses different ways to communicate via its API. Each exchange is using slightly different terminology, can have different logic around order types and has different limits and validations that it applies to orders.  That is why creating single layer that hides  these differences is so challenging. Thanks to this layer, all the differences between exchanges are transparent to other parts of the system.

Exchange API keys

Exchange integration layer can trade on your behalf only in case you provide it with private API keys. Private API key is a mean to access your private wallet and trade on your behalf on the exchange. If you want MultiTrader to act on your behalf – to trade on some exchange or to manage your funds on this exchange, or do any other operation on this exchange that is allowed after user login, you need to provide MultiTrader with the private API keys to these exchanges.

Ticker price and order book monitoring limitations

MulitTrader connects to all the exchanges right after it is started and monitors ticker prices and order books. In case of exchanges that expose data via Websockets, MultiTrader receives updates on their order books any time new order is placed on the exchange. That means that for the exchanges providing Websocket API, MultiTrader always has the freshest data.

For other exchanges that are using REST API, MultiTrader needs to check, poll for the data. All the exchanges have some limitations on the number of queries that can be done to the exchange via the REST API (so called rate limiting). MultiTrader needs to come back to each exchange as often as the rate limits allow. Anyway, this leads to slightly delayed data

For example if the exchange allows just for one call on its public API per second, our price data may be at most 1 second delayed.

There are some worse cases – in case the exchange has poor API that allows to query just for a single currency pair at once, we need to do separate queries for each cryptocurrency pair that we are interested in. If we would like to monitor 10 different currency pairs on this exchange, that means we will be getting updates for each currency pair every ten seconds. Fortunately majority of the exchanges allow to query for prices and order books simultaneously for bigger number of currency pairs.

Working around the limitations

It is not the best idea to rely on the delayed prices in the arbitrage trades. We need to have values that are at most 1 second delayed. That is the most common limit API access limit across many exchanges. We can’t get anything better than this one. But we can work around the problem of combination of poor exchange API that allows just for single ticker query and the rate limiting. In worst case scenario our prices could be delayed by as many seconds as many currency pairs we would like to monitor on that exchange.

So, in order to work around that MultiTrader exchange integration layer has direct market access mode that is enabled for trades. The monitoring of the prices has lower priority than the trading. In case the bot plans to perform the trade it goes to the exchange using direct market access, gets higher priority than the monitoring components and instantly (with at most 1 sec delay) confirms the price on which it wants to perform trading decisions.

Previous articleArbitrage strategies – Part II – Auto Rebalancing
Next articleArbitrage strategies – Part III – Spread Trading