mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
Merge pull request #200 from LarryLuTW/fix/track-created-orders
This commit is contained in:
commit
52bb684ef8
|
@ -240,18 +240,21 @@ func (s *Strategy) placeGridOrders(orderExecutor bbgo.OrderExecutor, session *bb
|
|||
if err != nil {
|
||||
log.Warn(err.Error())
|
||||
}
|
||||
createdSellOrders, err := orderExecutor.SubmitOrders(context.Background(), sellOrders...)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorf("can not place sell orders")
|
||||
}
|
||||
|
||||
buyOrders, err := s.generateGridBuyOrders(session)
|
||||
if err != nil {
|
||||
log.Warn(err.Error())
|
||||
}
|
||||
|
||||
orders := append(sellOrders, buyOrders...)
|
||||
|
||||
createdOrders, err := orderExecutor.SubmitOrders(context.Background(), orders...)
|
||||
createdBuyOrders, err := orderExecutor.SubmitOrders(context.Background(), buyOrders...)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorf("can not place orders")
|
||||
return
|
||||
log.WithError(err).Errorf("can not place buy orders")
|
||||
}
|
||||
|
||||
createdOrders := append(createdSellOrders, createdBuyOrders...)
|
||||
s.activeOrders.Add(createdOrders...)
|
||||
s.orders.Add(createdOrders...)
|
||||
}
|
||||
|
@ -347,7 +350,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
|||
}
|
||||
})
|
||||
|
||||
session.Stream.OnConnect(func() {
|
||||
session.Stream.OnStart(func() {
|
||||
log.Infof("connected, submitting the first round of the orders")
|
||||
s.updateOrders(orderExecutor, session)
|
||||
})
|
||||
|
|
|
@ -317,11 +317,10 @@ func (s *Strategy) placeGridSellOrders(orderExecutor bbgo.OrderExecutor, session
|
|||
|
||||
if len(orderForms) > 0 {
|
||||
createdOrders, err := orderExecutor.SubmitOrders(context.Background(), orderForms...)
|
||||
s.activeOrders.Add(createdOrders...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s.activeOrders.Add(createdOrders...)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -335,10 +334,9 @@ func (s *Strategy) placeGridBuyOrders(orderExecutor bbgo.OrderExecutor, session
|
|||
|
||||
if len(orderForms) > 0 {
|
||||
createdOrders, err := orderExecutor.SubmitOrders(context.Background(), orderForms...)
|
||||
s.activeOrders.Add(createdOrders...)
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
s.activeOrders.Add(createdOrders...)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -431,10 +429,6 @@ func (s *Strategy) handleFilledOrder(filledOrder types.Order) {
|
|||
log.Infof("submitting arbitrage order: %s against filled order %s", submitOrder.String(), filledOrder.String())
|
||||
|
||||
createdOrders, err := s.OrderExecutor.SubmitOrders(context.Background(), submitOrder)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorf("can not place orders")
|
||||
return
|
||||
}
|
||||
|
||||
// create one-way link from the newly created orders
|
||||
for _, o := range createdOrders {
|
||||
|
@ -444,6 +438,11 @@ func (s *Strategy) handleFilledOrder(filledOrder types.Order) {
|
|||
s.orderStore.Add(createdOrders...)
|
||||
s.activeOrders.Add(createdOrders...)
|
||||
|
||||
if err != nil {
|
||||
log.WithError(err).Errorf("can not place orders")
|
||||
return
|
||||
}
|
||||
|
||||
// calculate arbitrage profit
|
||||
// TODO: apply fee rate here
|
||||
if s.Long {
|
||||
|
|
Loading…
Reference in New Issue
Block a user