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 400 forks source link

Invalid size precision for fill 5 when instrument size precision is 6, on 1.194.0 #1688

Closed rubenmarias closed 1 month ago

rubenmarias commented 1 month ago

Bug Report

Bug occurs in a backtest with quote ticks, when simulating fills of a limit order. See attatched debug logs and quote tick file. quote_ticks.csv backtest.log

Backtest starts normally, and the error is thrown when it tries to apply fill for (see attatched debug logs):

Applying fills to LimitOrder(BUY 0.000200 BTCUSDT.BINANCE LIMIT @ 64_404.06 GTC, status=ACCEPTED, client_order_id=O-20240426-0201-001-000-182, venue_order_id=BINANCE-1-182, position_id=None, tags=None), venue_position_id=None, position=None, fills=[(Price(64404.06), Quantity(0.00010))]

Expected Behavior

Fills can be simulated normally in a backtest

Actual Behavior

Backtest crashes with the above error when trying to simulate a fill.

Steps to Reproduce the Problem

  1. Trying to get an MRE

Specifications

cuberone commented 1 month ago

When I feed strategy TradeTicks from catalog, I have error Invalid price precision for fill 1 when instrument price precision is 2. Check that the data price precision matches the BTCUSDT-PERP.BINANCE instrument In other case when I feed strategy Bars without using catalog, there are no errors

cuberone commented 1 month ago

ok, TradeTick's price object loaded from catalog has precision 1, but backtest engine's instrument has precision 2. I think the error is in wrapping catalog data into TradeTick with wrong precision.

cjdsellers commented 1 month ago

Hi @rubenmarias and @cuberone

So I think as a consequence of fixing an existing bug in price and size precision parsing for Binance instruments here, any existing data in catalogs is now potentially mismatched/incorrect if the price increment of the instrument has trailing zeros (the precision will be off by one per trailing zero).

Unfortunately this means you probably have to re-write the market data and instruments, which should fix this. Or at least just for the instruments which have trailing zeros in the price increment (after parsing them again from Binance post-fix).

Let me know how you go, and if this isn't in fact the cause we can investigate further.

rubenmarias commented 1 month ago

Refreshing the catalog data did solve the issue for me, thanks @cjdsellers!