implement QueryOrder on the backtest exchange

This commit is contained in:
c9s 2022-06-26 16:10:10 +08:00
parent 88059016b4
commit 4c02d8f729
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -30,6 +30,7 @@ package backtest
import (
"context"
"fmt"
"strconv"
"sync"
"time"
@ -71,6 +72,20 @@ type Exchange struct {
markets types.MarketMap
}
func (e *Exchange) QueryOrder(ctx context.Context, q types.OrderQuery) (*types.Order, error) {
book := e.matchingBooks[q.Symbol]
oid, err := strconv.ParseUint(q.OrderID, 10, 64)
if err != nil {
return nil, err
}
order, ok := book.getOrder(oid)
if ok {
return &order, nil
}
return nil, nil
}
func NewExchange(sourceName types.ExchangeName, sourceExchange types.Exchange, srv *service.BacktestService, config *bbgo.Backtest) (*Exchange, error) {
ex := sourceExchange
@ -144,9 +159,10 @@ func (e *Exchange) addMatchingBook(symbol string, market types.Market) {
func (e *Exchange) _addMatchingBook(symbol string, market types.Market) {
e.matchingBooks[symbol] = &SimplePriceMatching{
CurrentTime: e.startTime,
Account: e.account,
Market: market,
CurrentTime: e.startTime,
Account: e.account,
Market: market,
closedOrders: make(map[uint64]types.Order),
}
}