nautechsystems / nautilus_trader

A high-performance algorithmic trading platform and event-driven backtester
https://nautilustrader.io
GNU Lesser General Public License v3.0
1.7k stars 398 forks source link

Binance missing candles #1705

Closed OnlyC closed 3 weeks ago

OnlyC commented 3 weeks ago

Bug Report

I'm not really sure if it's Nautilus or Binance's fault but today when BTC dump at 6pm, my bot does nothing and it's cost me a big one. My stop is set to: if close price of 1h candle < stop price. I check bot log at 6h20pm and realized the bar from 5pm-6pm is missing, and bot taking no action. No error showed. (log_level: INFO)

I've run the bot for 2 months and never experienced something like this. The stops alway work before.

Expected Behavior

If this is Binance's error, how can I avoid when Binance does not send new bars or bars being delay through websocket?

Specifications

cjdsellers commented 3 weeks ago

Hey @OnlyC

That's unfortunate and I can understand the frustration.

When it comes to bars, even Binance themselves recommend you don't rely on the kline streams - there can be big delays in fast markets as you saw. I've also seen this myself with bars being either delayed (up to ~30 seconds) or entirely missing - especially on the testnet.

I would recommend you use INTERNAL bar aggregation which will use the much more reliable trades feed from Binance with a Nautilus timer.

For your stop, it sounds like either this is an emulated order or requires a market order to be submitted from the strategy? There's tradeoffs to doing this - with one of them being your stop isn't going to be triggered if the Nautilus instance is down or doesn't receive the expected data.

Also note, I've seen large delays in stop orders becoming active too - which is one reason some traders use Nautilus emulated orders instead of Binance stop orders.

Hope that helps.

OnlyC commented 3 weeks ago

@cjdsellers Thanks for the suggestion! I use market order for stops and yes, I have to take that tradeoffs because this strategy not working good with hard stop. For the INTERNAL bar, sometimes I see them missing trades, leading to mismatch candle's OHLC. Looks like I dont have many choices, its better to have mismatch candle vs no candle at all. Thought I will need to set an alert when Nautilus doesn't receive any data in 1 min or smt.

cjdsellers commented 3 weeks ago

Yes, it wouldn't surprise me if there was a difference in Binance externally aggregated and Nautilus internally aggregated bars.

Sure you could add backups, I recommend doing this as minimally and simply as possible, backtest and test on sandbox before going live.