Merge pull request #200 from LarryLuTW/fix/track-created-orders

This commit is contained in:
Yo-An Lin 2021-04-15 20:04:19 +08:00 committed by GitHub
commit 52bb684ef8
2 changed files with 17 additions and 15 deletions

View File

@ -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)
})

View File

@ -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 {