mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-13 02:23:51 +00:00
fix: submit order on userDataStream == nil
This commit is contained in:
parent
ab41891a42
commit
d6995e40ff
|
@ -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) {
|
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 {
|
for _, order := range orders {
|
||||||
symbol := order.Symbol
|
symbol := order.Symbol
|
||||||
matching, ok := e.matchingBook(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 {
|
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 {
|
for _, order := range orders {
|
||||||
matching, ok := e.matchingBook(order.Symbol)
|
matching, ok := e.matchingBook(order.Symbol)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
|
@ -129,11 +129,13 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
||||||
Window: 25,
|
Window: 25,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
session.UserDataStream.OnStart(func() {
|
||||||
|
s.updateOrders(orderExecutor, session)
|
||||||
|
})
|
||||||
|
|
||||||
session.MarketDataStream.OnKLineClosed(func(kline types.KLine) {
|
session.MarketDataStream.OnKLineClosed(func(kline types.KLine) {
|
||||||
s.updateOrders(orderExecutor, session)
|
s.updateOrders(orderExecutor, session)
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO: move this to the stream onConnect handler
|
|
||||||
s.updateOrders(orderExecutor, session)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user