@@ -42,11 +42,16 @@ func (o *BlockOrders) GetSortedMarketOrders(direction types.PositionDirection, i
42
42
o .mu .Lock ()
43
43
defer o .mu .Unlock ()
44
44
45
- res := o .getOrdersByCriteria (types .OrderType_MARKET , direction )
46
- res = append (res , o .getOrdersByCriteria (types .OrderType_FOKMARKET , direction )... )
45
+ orderTypes := map [types.OrderType ]bool {
46
+ types .OrderType_MARKET : true ,
47
+ types .OrderType_FOKMARKET : true ,
48
+ types .OrderType_FOKMARKETBYVALUE : true ,
49
+ }
47
50
if includeLiquidationOrders {
48
- res = append ( res , o . getOrdersByCriteria ( types .OrderType_LIQUIDATION , direction ) ... )
51
+ orderTypes [ types .OrderType_LIQUIDATION ] = true
49
52
}
53
+ res := o .getOrdersByCriteriaMap (orderTypes , map [types.PositionDirection ]bool {direction : true })
54
+
50
55
sort .Slice (res , func (i , j int ) bool {
51
56
// a price of 0 indicates that there is no worst price for the order, so it should
52
57
// always be ranked at the top.
@@ -86,3 +91,20 @@ func (o *BlockOrders) getOrdersByCriteria(orderType types.OrderType, direction t
86
91
}
87
92
return res
88
93
}
94
+
95
+ func (o * BlockOrders ) getOrdersByCriteriaMap (orderType map [types.OrderType ]bool , direction map [types.PositionDirection ]bool ) []* types.Order {
96
+ res := []* types.Order {}
97
+ for _ , order := range o .internal {
98
+ if _ , ok := orderType [order .OrderType ]; ! ok {
99
+ continue
100
+ }
101
+ if _ , ok := direction [order .PositionDirection ]; ! ok {
102
+ continue
103
+ }
104
+ if order .Status == types .OrderStatus_FAILED_TO_PLACE {
105
+ continue
106
+ }
107
+ res = append (res , order )
108
+ }
109
+ return res
110
+ }
0 commit comments