Can a node.js cryptocurrency bot fall behind the market

443 Views Asked by At

If a trading bot is built on Node.JS is reacting to every single market update won't it immediately start to drift away from reality without any client-side conflation on a separate child thread?

In other words, it will receive a order book update, update its current book, the bot will execute its trading logic, and during that time it won't be handling the next update. So as the bot receives and handles more market data updates won't it immediately start to lag behind and get worse with each update?

I suppose there could be gaps in market activity that would allow it to catch up but that's not guaranteed.

Examples I've seen of NodeJS bots do not handle this so I wonder if it's a non-issue and there is something I do not know or understand.

Of course I could spawn a child process specifically for handling prices and conflating them and another for trading logic and talk via IPC. However, assuming I measured correctly, there's around 500 microseconds in latency last time I tried. And well, we'd like to be faster.

2

There are 2 best solutions below

0
On

Depends on how you make it, if you execute the trading logic on a infinite loop that feeds from database systems ~ and cache systems like redis, you can make parallel requests to the store it to the db, while is calculating, it will always have delay between fetching, storing, calculating, reacting, the question is, is fast enough to make good decisions and react fast enough to execute? the answer is i don't know... it depends

0
On

Everyone has access to the same data when building trading bots, so your bot is on a level playing field with others. There are a few things to keep in mind:

  1. Use a library like the Coygo API to get a direct connection to each exchange's real-time data feeds, don't use any API that creates a middleman since that will add latency and don't spam REST APIs for ticker, order book, or trade data.

  2. Do any data processing in separate threads/web workers so that you continue getting updates in real-time.

  3. You can always just run your bot on beefed up hardware, particularly a fast CPU, for fast data processing.

  4. How fast you have to react really depends on your strategy. A lot of hedge funds only rebalance once or twice a week, whereas some day traders place hundreds of trades a day. Find the strategy that works right for you.