mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
update log message
This commit is contained in:
parent
cc5ebd5b2c
commit
6029bd268d
|
@ -83,16 +83,16 @@ func (s *Strategy) recoverWithOpenOrdersByScanningTrades(ctx context.Context, hi
|
||||||
// add open orders to active order book
|
// add open orders to active order book
|
||||||
s.addOrdersToActiveOrderBook(openOrdersOnGrid)
|
s.addOrdersToActiveOrderBook(openOrdersOnGrid)
|
||||||
|
|
||||||
expectedOrderNums := s.GridNum - 1
|
expectedNumOfOrders := s.GridNum - 1
|
||||||
openOrdersOnGridNums := int64(len(openOrdersOnGrid))
|
numGridOpenOrders := int64(len(openOrdersOnGrid))
|
||||||
s.debugLog("open orders nums: %d, expected nums: %d", openOrdersOnGridNums, expectedOrderNums)
|
s.debugLog("open orders nums: %d, expected nums: %d", numGridOpenOrders, expectedNumOfOrders)
|
||||||
if expectedOrderNums == openOrdersOnGridNums {
|
if expectedNumOfOrders == numGridOpenOrders {
|
||||||
// no need to recover
|
// no need to recover
|
||||||
s.EmitGridReady()
|
s.EmitGridReady()
|
||||||
s.updateGridNumOfOrdersMetricsWithLock()
|
s.updateGridNumOfOrdersMetricsWithLock()
|
||||||
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
|
s.updateOpenOrderPricesMetrics(s.orderExecutor.ActiveMakerOrders().Orders())
|
||||||
return nil
|
return nil
|
||||||
} else if expectedOrderNums < openOrdersOnGridNums {
|
} else if expectedNumOfOrders < numGridOpenOrders {
|
||||||
return fmt.Errorf("amount of grid's open orders should not > amount of expected grid's orders")
|
return fmt.Errorf("amount of grid's open orders should not > amount of expected grid's orders")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,9 +111,10 @@ func (s *Strategy) recoverWithOpenOrdersByScanningTrades(ctx context.Context, hi
|
||||||
// 3. get the filled orders from pin-order map
|
// 3. get the filled orders from pin-order map
|
||||||
filledOrders := pinOrdersFilled.AscendingOrders()
|
filledOrders := pinOrdersFilled.AscendingOrders()
|
||||||
numFilledOrders := len(filledOrders)
|
numFilledOrders := len(filledOrders)
|
||||||
if numFilledOrders == int(expectedOrderNums-openOrdersOnGridNums) {
|
if numFilledOrders == int(expectedNumOfOrders-numGridOpenOrders) {
|
||||||
// nums of filled order is the same as Size - 1 - num(open orders)
|
// nums of filled order is the same as Size - 1 - num(open orders)
|
||||||
} else if numFilledOrders == int(expectedOrderNums-openOrdersOnGridNums+1) {
|
s.logger.Infof("nums of filled order is the same as Size - 1 - len(open orders) : %d = %d - 1 - %d", numFilledOrders, s.grid.Size, numGridOpenOrders)
|
||||||
|
} else if numFilledOrders == int(expectedNumOfOrders-numGridOpenOrders+1) {
|
||||||
filledOrders = filledOrders[1:]
|
filledOrders = filledOrders[1:]
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("not reasonable num of filled orders")
|
return fmt.Errorf("not reasonable num of filled orders")
|
||||||
|
@ -136,24 +137,17 @@ func (s *Strategy) recoverWithOpenOrdersByScanningTrades(ctx context.Context, hi
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Strategy) verifyFilledGrid(pins []Pin, pinOrders PinOrderMap, filledOrders []types.Order) error {
|
func (s *Strategy) verifyFilledGrid(pins []Pin, pinOrders PinOrderMap, filledOrders []types.Order) error {
|
||||||
s.debugLog("pins: %+v", pins)
|
s.debugLog("verifying filled grid - pins: %+v", pins)
|
||||||
s.debugLog("open pin orders:\n%s", pinOrders.String())
|
s.debugLog("verifying filled grid - open pin orders:\n%s", pinOrders.String())
|
||||||
s.debugOrders("filled orders", filledOrders)
|
s.debugOrders("verifying filled grid - filled orders", filledOrders)
|
||||||
|
|
||||||
for _, filledOrder := range filledOrders {
|
if err := addOrdersIntoPinOrderMap(pinOrders, filledOrders); err != nil {
|
||||||
price := filledOrder.Price
|
return errors.Wrapf(err, "verifying filled grid error when add orders into pin order map")
|
||||||
if o, exist := pinOrders[price]; !exist {
|
|
||||||
return fmt.Errorf("the price (%+v) is not in pins", price)
|
|
||||||
} else if o.OrderID != 0 {
|
|
||||||
return fmt.Errorf("there is already an order at this price (%+v)", price)
|
|
||||||
} else {
|
|
||||||
pinOrders[price] = filledOrder
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.debugLog("filled pin orders:\n%+v", pinOrders.String())
|
s.debugLog("verifying filled grid - filled pin orders:\n%+v", pinOrders.String())
|
||||||
|
|
||||||
side := types.SideTypeBuy
|
expectedSide := types.SideTypeBuy
|
||||||
for _, pin := range pins {
|
for _, pin := range pins {
|
||||||
order, exist := pinOrders[fixedpoint.Value(pin)]
|
order, exist := pinOrders[fixedpoint.Value(pin)]
|
||||||
if !exist {
|
if !exist {
|
||||||
|
@ -164,20 +158,20 @@ func (s *Strategy) verifyFilledGrid(pins []Pin, pinOrders PinOrderMap, filledOrd
|
||||||
// there must be only one empty pin in the grid
|
// there must be only one empty pin in the grid
|
||||||
// all orders below this pin need to be bid orders, above this pin need to be ask orders
|
// all orders below this pin need to be bid orders, above this pin need to be ask orders
|
||||||
if order.OrderID == 0 {
|
if order.OrderID == 0 {
|
||||||
if side == types.SideTypeBuy {
|
if expectedSide == types.SideTypeBuy {
|
||||||
side = types.SideTypeSell
|
expectedSide = types.SideTypeSell
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Errorf("not only one empty order in this grid")
|
return fmt.Errorf("found more than one empty pins")
|
||||||
}
|
}
|
||||||
|
|
||||||
if order.Side != side {
|
if order.Side != expectedSide {
|
||||||
return fmt.Errorf("the side is wrong")
|
return fmt.Errorf("the side of order (%s) is wrong, expected: %s", order.Side, expectedSide)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if side != types.SideTypeSell {
|
if expectedSide != types.SideTypeSell {
|
||||||
return fmt.Errorf("there is no empty pin in the grid")
|
return fmt.Errorf("there is no empty pin in the grid")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,9 +272,6 @@ func (s *Strategy) buildFilledPinOrderMapFromTrades(ctx context.Context, history
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
pinOrdersFilled[pin] = *order
|
pinOrdersFilled[pin] = *order
|
||||||
|
|
||||||
// wait 100 ms to avoid rate limit
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop condition
|
// stop condition
|
||||||
|
@ -291,3 +282,18 @@ func (s *Strategy) buildFilledPinOrderMapFromTrades(ctx context.Context, history
|
||||||
|
|
||||||
return pinOrdersFilled, nil
|
return pinOrdersFilled, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addOrdersIntoPinOrderMap(pinOrders PinOrderMap, orders []types.Order) error {
|
||||||
|
for _, order := range orders {
|
||||||
|
price := order.Price
|
||||||
|
if o, exist := pinOrders[price]; !exist {
|
||||||
|
return fmt.Errorf("the price (%+v) is not in pins", price)
|
||||||
|
} else if o.OrderID != 0 {
|
||||||
|
return fmt.Errorf("there is already an order at this price (%+v)", price)
|
||||||
|
} else {
|
||||||
|
pinOrders[price] = order
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -1216,7 +1216,7 @@ func (s *Strategy) debugOrders(desc string, orders []types.Order) {
|
||||||
s.logger.Infof(sb.String())
|
s.logger.Infof(sb.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Strategy) debugGridProfitStats(where string) {
|
func (s *Strategy) debugGridProfitStats(trigger string) {
|
||||||
if !s.Debug {
|
if !s.Debug {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1226,11 +1226,11 @@ func (s *Strategy) debugGridProfitStats(where string) {
|
||||||
stats.ProfitEntries = nil
|
stats.ProfitEntries = nil
|
||||||
b, err := json.Marshal(stats)
|
b, err := json.Marshal(stats)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.WithError(err).Errorf("[%s] failed to debug grid profit stats", where)
|
s.logger.WithError(err).Errorf("[%s] failed to debug grid profit stats", trigger)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
s.logger.Infof("[%s] grid profit stats: %s", where, string(b))
|
s.logger.Infof("trigger %s => grid profit stats : %s", trigger, string(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Strategy) debugLog(format string, args ...interface{}) {
|
func (s *Strategy) debugLog(format string, args ...interface{}) {
|
||||||
|
@ -1941,11 +1941,11 @@ func (s *Strategy) startProcess(ctx context.Context, session *bbgo.ExchangeSessi
|
||||||
|
|
||||||
func (s *Strategy) recoverGrid(ctx context.Context, session *bbgo.ExchangeSession) error {
|
func (s *Strategy) recoverGrid(ctx context.Context, session *bbgo.ExchangeSession) error {
|
||||||
if s.RecoverGridByScanningTrades {
|
if s.RecoverGridByScanningTrades {
|
||||||
s.debugLog("recover grid by scanning trades")
|
s.debugLog("recovering grid by scanning trades")
|
||||||
return s.recoverByScanningTrades(ctx, session)
|
return s.recoverByScanningTrades(ctx, session)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.debugLog("recover grid by scanning orders")
|
s.debugLog("recovering grid by scanning orders")
|
||||||
return s.recoverByScanningOrders(ctx, session)
|
return s.recoverByScanningOrders(ctx, session)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user