mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +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 {
|
if err != nil {
|
||||||
log.Warn(err.Error())
|
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)
|
buyOrders, err := s.generateGridBuyOrders(session)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn(err.Error())
|
log.Warn(err.Error())
|
||||||
}
|
}
|
||||||
|
createdBuyOrders, err := orderExecutor.SubmitOrders(context.Background(), buyOrders...)
|
||||||
orders := append(sellOrders, buyOrders...)
|
|
||||||
|
|
||||||
createdOrders, err := orderExecutor.SubmitOrders(context.Background(), orders...)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Errorf("can not place orders")
|
log.WithError(err).Errorf("can not place buy orders")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createdOrders := append(createdSellOrders, createdBuyOrders...)
|
||||||
s.activeOrders.Add(createdOrders...)
|
s.activeOrders.Add(createdOrders...)
|
||||||
s.orders.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")
|
log.Infof("connected, submitting the first round of the orders")
|
||||||
s.updateOrders(orderExecutor, session)
|
s.updateOrders(orderExecutor, session)
|
||||||
})
|
})
|
||||||
|
|
|
@ -317,11 +317,10 @@ func (s *Strategy) placeGridSellOrders(orderExecutor bbgo.OrderExecutor, session
|
||||||
|
|
||||||
if len(orderForms) > 0 {
|
if len(orderForms) > 0 {
|
||||||
createdOrders, err := orderExecutor.SubmitOrders(context.Background(), orderForms...)
|
createdOrders, err := orderExecutor.SubmitOrders(context.Background(), orderForms...)
|
||||||
|
s.activeOrders.Add(createdOrders...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
s.activeOrders.Add(createdOrders...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -335,10 +334,9 @@ func (s *Strategy) placeGridBuyOrders(orderExecutor bbgo.OrderExecutor, session
|
||||||
|
|
||||||
if len(orderForms) > 0 {
|
if len(orderForms) > 0 {
|
||||||
createdOrders, err := orderExecutor.SubmitOrders(context.Background(), orderForms...)
|
createdOrders, err := orderExecutor.SubmitOrders(context.Background(), orderForms...)
|
||||||
|
s.activeOrders.Add(createdOrders...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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())
|
log.Infof("submitting arbitrage order: %s against filled order %s", submitOrder.String(), filledOrder.String())
|
||||||
|
|
||||||
createdOrders, err := s.OrderExecutor.SubmitOrders(context.Background(), submitOrder)
|
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
|
// create one-way link from the newly created orders
|
||||||
for _, o := range createdOrders {
|
for _, o := range createdOrders {
|
||||||
|
@ -444,6 +438,11 @@ func (s *Strategy) handleFilledOrder(filledOrder types.Order) {
|
||||||
s.orderStore.Add(createdOrders...)
|
s.orderStore.Add(createdOrders...)
|
||||||
s.activeOrders.Add(createdOrders...)
|
s.activeOrders.Add(createdOrders...)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.WithError(err).Errorf("can not place orders")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// calculate arbitrage profit
|
// calculate arbitrage profit
|
||||||
// TODO: apply fee rate here
|
// TODO: apply fee rate here
|
||||||
if s.Long {
|
if s.Long {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user