mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-03 15:10:49 +00:00
order: slight optimizations (#917)
* order: slight optimizations * orders: add benchmarks, small optimize and change order side to uin8 for comparitive optimizations. * orders: continue to convert string type -> uint * orders/backtester: interim move type to orders package, later can expand or deprecate. * orders: handle errors * orders: optimize filters and remove error returns when its clearly not needed * orders: remove log call * backtester: zero value check * orders/futures: zero value -> flag * linter: fix * linter: more fixes * linters: rides again * glorious: nits * common: Add zero value unix check for time values; also addresses glorious nits * glorious scott: nits Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
This commit is contained in:
@@ -1181,7 +1181,11 @@ func (b *Binance) GetOrderInfo(ctx context.Context, orderID string, pair currenc
|
||||
if err != nil {
|
||||
return respData, err
|
||||
}
|
||||
orderSide := order.Side(resp.Side)
|
||||
var side order.Side
|
||||
side, err = order.StringToOrderSide(resp.Side)
|
||||
if err != nil {
|
||||
return respData, err
|
||||
}
|
||||
status, err := order.StringToOrderStatus(resp.Status)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s %v", b.Name, err)
|
||||
@@ -1196,7 +1200,7 @@ func (b *Binance) GetOrderInfo(ctx context.Context, orderID string, pair currenc
|
||||
Exchange: b.Name,
|
||||
ID: strconv.FormatInt(resp.OrderID, 10),
|
||||
ClientOrderID: resp.ClientOrderID,
|
||||
Side: orderSide,
|
||||
Side: side,
|
||||
Type: orderType,
|
||||
Pair: pair,
|
||||
Cost: resp.CummulativeQuoteQty,
|
||||
@@ -1350,8 +1354,16 @@ func (b *Binance) GetActiveOrders(ctx context.Context, req *order.GetOrdersReque
|
||||
return nil, err
|
||||
}
|
||||
for x := range resp {
|
||||
orderSide := order.Side(strings.ToUpper(resp[x].Side))
|
||||
orderType := order.Type(strings.ToUpper(resp[x].Type))
|
||||
var side order.Side
|
||||
side, err = order.StringToOrderSide(resp[x].Side)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s %v", b.Name, err)
|
||||
}
|
||||
var orderType order.Type
|
||||
orderType, err = order.StringToOrderType(resp[x].Type)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s %v", b.Name, err)
|
||||
}
|
||||
orderStatus, err := order.StringToOrderStatus(resp[i].Status)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s %v", b.Name, err)
|
||||
@@ -1362,7 +1374,7 @@ func (b *Binance) GetActiveOrders(ctx context.Context, req *order.GetOrdersReque
|
||||
Exchange: b.Name,
|
||||
ID: strconv.FormatInt(resp[x].OrderID, 10),
|
||||
ClientOrderID: resp[x].ClientOrderID,
|
||||
Side: orderSide,
|
||||
Side: side,
|
||||
Type: orderType,
|
||||
Price: resp[x].Price,
|
||||
Status: orderStatus,
|
||||
@@ -1441,10 +1453,13 @@ func (b *Binance) GetActiveOrders(ctx context.Context, req *order.GetOrdersReque
|
||||
return orders, fmt.Errorf("assetType not supported")
|
||||
}
|
||||
}
|
||||
order.FilterOrdersByCurrencies(&orders, req.Pairs)
|
||||
order.FilterOrdersByPairs(&orders, req.Pairs)
|
||||
order.FilterOrdersByType(&orders, req.Type)
|
||||
order.FilterOrdersBySide(&orders, req.Side)
|
||||
order.FilterOrdersByTimeRange(&orders, req.StartTime, req.EndTime)
|
||||
err := order.FilterOrdersByTimeRange(&orders, req.StartTime, req.EndTime)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s %v", b.Name, err)
|
||||
}
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
@@ -1470,8 +1485,16 @@ func (b *Binance) GetOrderHistory(ctx context.Context, req *order.GetOrdersReque
|
||||
}
|
||||
|
||||
for i := range resp {
|
||||
orderSide := order.Side(strings.ToUpper(resp[i].Side))
|
||||
orderType := order.Type(strings.ToUpper(resp[i].Type))
|
||||
var side order.Side
|
||||
side, err = order.StringToOrderSide(resp[x].Side)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s %v", b.Name, err)
|
||||
}
|
||||
var orderType order.Type
|
||||
orderType, err = order.StringToOrderType(resp[i].Type)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s %v", b.Name, err)
|
||||
}
|
||||
orderStatus, err := order.StringToOrderStatus(resp[i].Status)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s %v", b.Name, err)
|
||||
@@ -1497,7 +1520,7 @@ func (b *Binance) GetOrderHistory(ctx context.Context, req *order.GetOrdersReque
|
||||
LastUpdated: resp[i].UpdateTime,
|
||||
Exchange: b.Name,
|
||||
ID: strconv.FormatInt(resp[i].OrderID, 10),
|
||||
Side: orderSide,
|
||||
Side: side,
|
||||
Type: orderType,
|
||||
Price: resp[i].Price,
|
||||
Pair: req.Pairs[x],
|
||||
@@ -1628,7 +1651,11 @@ func (b *Binance) GetOrderHistory(ctx context.Context, req *order.GetOrdersReque
|
||||
}
|
||||
order.FilterOrdersByType(&orders, req.Type)
|
||||
order.FilterOrdersBySide(&orders, req.Side)
|
||||
order.FilterOrdersByTimeRange(&orders, req.StartTime, req.EndTime)
|
||||
err := order.FilterOrdersByTimeRange(&orders, req.StartTime, req.EndTime)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s %v", b.Name, err)
|
||||
}
|
||||
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user