backtest: adjust best bid/ask price with tick size

This commit is contained in:
c9s 2023-06-12 16:01:40 +08:00
parent fded41b0ea
commit 0482ade44a
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -12,18 +12,18 @@ for each kline, the backtest engine:
There are 2 ways that a strategy could work with backtest engine:
1. the strategy receives kline from the market data stream, and then it submits the order by the given market data to the backtest engine.
backtest engine receives the order and then pushes the trade and order updates to the user data stream.
1. the strategy receives kline from the market data stream, and then it submits the order by the given market data to the backtest engine.
backtest engine receives the order and then pushes the trade and order updates to the user data stream.
the strategy receives the trade and update its position.
the strategy receives the trade and update its position.
2. the strategy places the orders when it starts. (like grid) the strategy then receives the order updates and then submit a new order
by its order update message.
2. the strategy places the orders when it starts. (like grid) the strategy then receives the order updates and then submit a new order
by its order update message.
We need to ensure that:
1. if the strategy submits the order from the market data stream, since it's a separate goroutine, the strategy should block the backtest engine
to process the trades before the next kline is published.
1. if the strategy submits the order from the market data stream, since it's a separate goroutine, the strategy should block the backtest engine
to process the trades before the next kline is published.
*/
package backtest
@ -270,8 +270,8 @@ func (e *Exchange) QueryTicker(ctx context.Context, symbol string) (*types.Ticke
Open: kline.Open,
High: kline.High,
Low: kline.Low,
Buy: kline.Close,
Sell: kline.Close,
Buy: kline.Close.Sub(matching.Market.TickSize),
Sell: kline.Close.Add(matching.Market.TickSize),
}, nil
}