This commit is contained in:
chiahung 2023-04-28 16:02:22 +08:00
parent 93d35cc423
commit 61892eb2df
2 changed files with 13 additions and 4 deletions

View File

@ -313,8 +313,8 @@ func addOrdersIntoPinOrderMap(pinOrders PinOrderMap, orders []types.Order) error
func (s *Strategy) verifyFilledTwinGrid(pins []Pin, twinOrders TwinOrderMap, filledOrders []types.Order) error { func (s *Strategy) verifyFilledTwinGrid(pins []Pin, twinOrders TwinOrderMap, filledOrders []types.Order) error {
s.debugLog("verifying filled grid - pins: %+v", pins) s.debugLog("verifying filled grid - pins: %+v", pins)
s.debugLog("verifying filled grid - open twin orders:\n%s", twinOrders.String())
s.debugOrders("verifying filled grid - filled orders", filledOrders) s.debugOrders("verifying filled grid - filled orders", filledOrders)
s.debugLog("verifying filled grid - open twin orders:\n%s", twinOrders.String())
if err := s.addOrdersIntoTwinOrderMap(twinOrders, filledOrders); err != nil { if err := s.addOrdersIntoTwinOrderMap(twinOrders, filledOrders); err != nil {
return errors.Wrapf(err, "verifying filled grid error when add orders into twin order map") return errors.Wrapf(err, "verifying filled grid error when add orders into twin order map")
@ -323,6 +323,7 @@ func (s *Strategy) verifyFilledTwinGrid(pins []Pin, twinOrders TwinOrderMap, fil
s.debugLog("verifying filled grid - filled twin orders:\n%+v", twinOrders.String()) s.debugLog("verifying filled grid - filled twin orders:\n%+v", twinOrders.String())
for i, pin := range pins { for i, pin := range pins {
// we use twinOrderMap to make sure there are no duplicated order at one grid, and we use the sell price as key so we skip the pins[0] which is only for buy price
if i == 0 { if i == 0 {
continue continue
} }
@ -335,6 +336,10 @@ func (s *Strategy) verifyFilledTwinGrid(pins []Pin, twinOrders TwinOrderMap, fil
if !twin.Exist() { if !twin.Exist() {
return fmt.Errorf("all the price need a twin") return fmt.Errorf("all the price need a twin")
} }
if !twin.IsValid() {
return fmt.Errorf("all the twins need to be valid")
}
} }
return nil return nil
@ -421,6 +426,10 @@ func (s *Strategy) buildFilledTwinOrderMapFromTrades(ctx context.Context, histor
// avoid query this order again // avoid query this order again
existedOrders.Add(*order) existedOrders.Add(*order)
if order.GroupID != s.OrderGroupID {
continue
}
// add 1 to avoid duplicate // add 1 to avoid duplicate
fromTradeID = trade.ID + 1 fromTradeID = trade.ID + 1

View File

@ -68,13 +68,13 @@ func findTwinOrderMapKey(grid *Grid, order types.Order) (fixedpoint.Value, error
func (m TwinOrderMap) AscendingOrders() []types.Order { func (m TwinOrderMap) AscendingOrders() []types.Order {
var orders []types.Order var orders []types.Order
for _, order := range m { for _, twinOrder := range m {
// skip empty order // skip empty order
if !order.Exist() { if !twinOrder.Exist() {
continue continue
} }
orders = append(orders, order.GetOrder()) orders = append(orders, twinOrder.GetOrder())
} }
types.SortOrdersUpdateTimeAscending(orders) types.SortOrdersUpdateTimeAscending(orders)