Quote-quantity MARKET BUY rounding can exceed requested notional in backtest — intended behavior? #5071
Replies: 1 comment
On live Binance spot the adapter sends the amount as quoteOrderQty, so Binance does the conversion, not this code. |
On live Binance spot the adapter sends the amount as quoteOrderQty, so Binance does the conversion, not this code. |
Uh oh!
There was an error while loading. Please reload this page.
I reproduced this with NautilusTrader 2.0.0rc5 using a local backtest with synthetic quotes. No live exchange orders were involved.
Before filing a bug, I would like to clarify whether this behavior is intentional.
Observed behavior
For a spot instrument with:
The backtest converted the order to 0.003633 BTC, producing:
Requested quote amount: 399.600000 USDT
Updated base quantity: 0.003633 BTC
Fill price: 110000.00 USDT
Executed notional: 399.63000000 USDT
Commission: 0.39963000 USDT
Total debit: 400.02963000 USDT
The executed notional exceeds the requested quote amount by 0.03 USDT, before commission.
Source-code observation
In the v2.0.0rc5 source, OrderMatchingEngine::convert_quote_to_base_quantity calls Instrument::calculate_base_quantity.
The underlying try_calculate_base_quantity uses RoundingStrategy::MidpointNearestEven, which appears consistent with the observed result:
399.60 / 110000 = 0.003632727...
Nearest rounding: 0.003633
Rounding down: 0.003632
Questions
I have not tested a development wheel or live Binance execution, and I am not claiming equivalent live behavior.
All reactions