So you are writing a trading bot, an exchange service, an investment platform, or another application requiring interaction with crypto exchanges. Business logic is ready and tested, an existing or self-written crypto exchange API wrapper is integrated and seems to be compliant with official docs. It’s time to try your app in battle! But suddenly you start getting such problems that you could not even think about.

Here are few examples.

Connection reset error

It’s ok if this happens while requesting some data, you can just retry. But if you are sending an order it won’t help. An error can happen before the order is placed or after, so you have to determine what is the case before resending the request.

Fee charging scheme

Different exchanges have different fee charging scheme, some take commission at the end of the trade in the resulting currency, others charge from the remaining balance on your account and always in BTC, third use their own token for that purpose. It’s often not specified in the docs, so you have to do the math on your own.

Missing response fields

API documentation covers very few scenarios and is often out of sync, so you can find out that some of the response fields have different names or are absent in some cases. This usually happens when you have an open position :)

How to deal with it

So you need to debug these problems one by one in production and write tests for them. Some of them will be simple, others will require a lot of stubs. The amount of additional logic for tests will increase with the count of application scenarios and supported exchanges. Eventually, you will write an own mock, like many others. Unfortunately, none have much time to properly struct it as a standalone project, write docs, cover with tests, etc.

We spent some time with our team to do this work and made TestEx, a universal crypto exchange mock. It is at the MVP stage, and we want to collect feedback to see if this is really a useful project.

Using TestEx

TestEx is dead simple to install and use, it ships in a docker container and requires only a slight change of the API base url in your application.

Installation



$ cd testex

$ docker-compose up -d --build $ git clone https://github.com/m-kus/testex.git $ cd testex$ docker-compose up -d --build

Usage

Service is running on 127.0.0.1:8008 and you need to change api urls in the following way.

Was:

https://bittrex.com/api/v1.1/public/getmarkets

https://poloniex.com/public?command=returnTicker

Become:

You will also need to deposit your test account via http://127.0.0.1:8008/deposit.

That’s all!

Conclusion

There are many thoughts on how to develop this project. One can add such features as complicated execution, rate limit emulation, websocket api, deposits/withdrawals in testnet, increase supported exchange list. Now the goal is to get feedback to understand what functionality developers need, and whether they need it at all.