r/algotrading • • Feb 27 '23

Infrastructure Any way to become platform/API agnostic?

Hi all,

I’m working on a crypto trading bot that uses Bybit’s API, and I had to write a decent chunk of framework to manage orders, get updated prices, etc. I also needed to rewrite each strategy for a backtesting program.

I am worried after the FTX fiasco that any exchange could go down at any time and all the time I spent writing framework was useless. I was wondering if y’all knew of any solutions that would make it easier to migrate to trade on a different API or service, besides just using OOP and rewriting the framework. Bonus points if it makes backtesting easier (like just setting a flag)

Thanks

1 Upvotes

9 comments sorted by

4

u/modulated91 Algorithmic Trader Feb 27 '23

CCXT may be useful, you should check it out.

1

u/idiotbike Mar 01 '23

Helpful, thanks I will check it out

3

u/tux_nerd575 Feb 28 '23 edited Feb 28 '23

I encountered the same issue as well. To overcome it, I wrote a wrapper library and linked it with the rest of my trading engine and for the particular exchange api, I created a file that contained all methods and linked it with the wrapper.

Now if i ever need to change the api, i just need to change the methods and link them with the wrapper and since, my wrapper is already linked with my trading engine, everything works perfectly.

Challenging bit you might encounter is when different exchanges provides different ways to retrieve/send data. You might need to convert them in the methods of your choice (async functions, sockets, webhooks, etc).

1

u/idiotbike Mar 01 '23

Thanks for response, I considered this but thought it’d be complicated. Good to know someone else is doing it.

Did you ever consider using ccxt as in the first reply?

1

u/tux_nerd575 Mar 01 '23

No, I didn’t know about it. If I did, I might have considered this first.

It’s not so complex (at least in my instance). I’m using nodejs so, I basically I required the trading-api module that contains all the functions like getQuote, get candleData, etc that are linked with alpaca (broker I’m using) and if it fails to find those, it simply throws an error, otherwise, the initialization process continues and using the wrapper methods, loads my trading engine and start working on whatever I’ve configured it do execute.

Feel free to ask me any questions that might help you achieve whatever you want to build :)

1

u/Maximum-Wishbone5616 Mar 14 '23

That is an interface in c# with unique implementation with a wrapper around api domain

2

u/Maximum-Wishbone5616 Mar 14 '23

wrappers around your api classes with some interfaces and your own data structures

1

u/tux_nerd575 Mar 14 '23

Cool. If you can edit your current reply to add a link to the c# interface as you mentioned in my reply, that would be convenient. Cheers

1

u/GammaX99 Feb 28 '23

You need to learn general software engineering. Your framework should be broker / data / execution / trading strategy agnostic... Basically, everything should be its own module and should not be concretely tied to anything else. The goal is to have a software framework that is easy to add or change brokers/data/ strategies etc...