mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
backtest: assign user data stream to backtest.Exchange before we call EmitStart
This commit is contained in:
parent
449b2d8220
commit
ecd4df86f9
|
@ -99,7 +99,6 @@ func (m *SimplePriceMatching) CancelOrder(o types.Order) (types.Order, error) {
|
|||
}
|
||||
m.askOrders = orders
|
||||
m.mu.Unlock()
|
||||
|
||||
}
|
||||
|
||||
if !found {
|
||||
|
@ -191,6 +190,8 @@ func (m *SimplePriceMatching) PlaceOrder(o types.SubmitOrder) (*types.Order, *ty
|
|||
order2.ExecutedQuantity = order2.Quantity
|
||||
order2.IsWorking = false
|
||||
|
||||
m.EmitOrderUpdate(order2)
|
||||
|
||||
// let the exchange emit the "FILLED" order update (we need the closed order)
|
||||
// m.EmitOrderUpdate(order2)
|
||||
return &order2, &trade, nil
|
||||
|
|
|
@ -131,8 +131,6 @@ func (b *ActiveOrderBook) orderUpdateHandler(order types.Order) {
|
|||
return
|
||||
}
|
||||
|
||||
log.Debugf("[ActiveOrderBook] received order update: %+v", order)
|
||||
|
||||
switch order.Status {
|
||||
case types.OrderStatusFilled:
|
||||
// make sure we have the order and we remove it
|
||||
|
|
|
@ -267,6 +267,12 @@ var BacktestCmd = &cobra.Command{
|
|||
return err
|
||||
}
|
||||
|
||||
for _, session := range environ.Sessions() {
|
||||
backtestEx := session.Exchange.(*backtest.Exchange)
|
||||
backtestEx.UserDataStream = session.UserDataStream.(types.StandardStreamEmitter)
|
||||
backtestEx.MarketDataStream = session.MarketDataStream.(types.StandardStreamEmitter)
|
||||
}
|
||||
|
||||
trader := bbgo.NewTrader(environ)
|
||||
if verboseCnt == 0 {
|
||||
trader.DisableLogging()
|
||||
|
@ -642,12 +648,10 @@ func confirmation(s string) bool {
|
|||
|
||||
func toExchangeSources(sessions map[string]*bbgo.ExchangeSession, extraIntervals ...types.Interval) (exchangeSources []backtest.ExchangeDataSource, err error) {
|
||||
for _, session := range sessions {
|
||||
exchange := session.Exchange.(*backtest.Exchange)
|
||||
exchange.UserDataStream = session.UserDataStream.(types.StandardStreamEmitter)
|
||||
exchange.MarketDataStream = session.MarketDataStream.(types.StandardStreamEmitter)
|
||||
exchange.InitMarketData()
|
||||
backtestEx := session.Exchange.(*backtest.Exchange)
|
||||
backtestEx.InitMarketData()
|
||||
|
||||
c, err := exchange.SubscribeMarketData(extraIntervals...)
|
||||
c, err := backtestEx.SubscribeMarketData(extraIntervals...)
|
||||
if err != nil {
|
||||
return exchangeSources, err
|
||||
}
|
||||
|
@ -655,7 +659,7 @@ func toExchangeSources(sessions map[string]*bbgo.ExchangeSession, extraIntervals
|
|||
sessionCopy := session
|
||||
exchangeSources = append(exchangeSources, backtest.ExchangeDataSource{
|
||||
C: c,
|
||||
Exchange: exchange,
|
||||
Exchange: backtestEx,
|
||||
Session: sessionCopy,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user