fix: submit order on userDataStream == nil

This commit is contained in:
zenix 2022-03-15 20:51:15 +09:00
parent ab41891a42
commit d6995e40ff
2 changed files with 10 additions and 2 deletions

View File

@ -151,6 +151,9 @@ func (e *Exchange) NewStream() types.Stream {
}
func (e *Exchange) SubmitOrders(ctx context.Context, orders ...types.SubmitOrder) (createdOrders types.OrderSlice, err error) {
if e.userDataStream == nil {
return createdOrders, fmt.Errorf("SubmitOrders should be called after userDataStream been initialized")
}
for _, order := range orders {
symbol := order.Symbol
matching, ok := e.matchingBook(symbol)
@ -198,6 +201,9 @@ func (e *Exchange) QueryClosedOrders(ctx context.Context, symbol string, since,
}
func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) error {
if e.userDataStream == nil {
return fmt.Errorf("CancelOrders should be called after userDataStream been initialized")
}
for _, order := range orders {
matching, ok := e.matchingBook(order.Symbol)
if !ok {

View File

@ -129,11 +129,13 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
Window: 25,
})
session.UserDataStream.OnStart(func() {
s.updateOrders(orderExecutor, session)
})
session.MarketDataStream.OnKLineClosed(func(kline types.KLine) {
s.updateOrders(orderExecutor, session)
})
// TODO: move this to the stream onConnect handler
s.updateOrders(orderExecutor, session)
return nil
}