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:
Ryan O'Hara-Reid
2022-05-06 12:27:21 +10:00
committed by GitHub
parent d735effc8e
commit cdcc9630de
60 changed files with 1375 additions and 802 deletions

View File

@@ -896,15 +896,21 @@ func (b *Bitfinex) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequ
orders := make([]order.Detail, len(resp))
for i := range resp {
orderSide := order.Side(strings.ToUpper(resp[i].Side))
timestamp, err := strconv.ParseFloat(resp[i].Timestamp, 64)
var side order.Side
side, err = order.StringToOrderSide(resp[i].Side)
if err != nil {
return nil, err
}
var timestamp float64
timestamp, err = strconv.ParseFloat(resp[i].Timestamp, 64)
if err != nil {
log.Warnf(log.ExchangeSys,
"Unable to convert timestamp '%s', leaving blank",
resp[i].Timestamp)
}
pair, err := currency.NewPairFromString(resp[i].Symbol)
var pair currency.Pair
pair, err = currency.NewPairFromString(resp[i].Symbol)
if err != nil {
return nil, err
}
@@ -914,7 +920,7 @@ func (b *Bitfinex) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequ
Date: time.Unix(int64(timestamp), 0),
Exchange: b.Name,
ID: strconv.FormatInt(resp[i].ID, 10),
Side: orderSide,
Side: side,
Price: resp[i].Price,
RemainingAmount: resp[i].RemainingAmount,
Pair: pair,
@@ -938,7 +944,10 @@ func (b *Bitfinex) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequ
if orderType == "trailing-stop" {
orderDetail.Type = order.TrailingStop
} else {
orderDetail.Type = order.Type(strings.ToUpper(orderType))
orderDetail.Type, err = order.StringToOrderType(orderType)
if err != nil {
log.Errorf(log.ExchangeSys, "%s %v", b.Name, err)
}
}
orders[i] = orderDetail
@@ -946,8 +955,11 @@ func (b *Bitfinex) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequ
order.FilterOrdersBySide(&orders, req.Side)
order.FilterOrdersByType(&orders, req.Type)
order.FilterOrdersByTimeRange(&orders, req.StartTime, req.EndTime)
order.FilterOrdersByCurrencies(&orders, req.Pairs)
err = order.FilterOrdersByTimeRange(&orders, req.StartTime, req.EndTime)
if err != nil {
log.Errorf(log.ExchangeSys, "%s %v", b.Name, err)
}
order.FilterOrdersByPairs(&orders, req.Pairs)
return orders, nil
}
@@ -965,14 +977,20 @@ func (b *Bitfinex) GetOrderHistory(ctx context.Context, req *order.GetOrdersRequ
orders := make([]order.Detail, len(resp))
for i := range resp {
orderSide := order.Side(strings.ToUpper(resp[i].Side))
timestamp, err := strconv.ParseInt(resp[i].Timestamp, 10, 64)
var side order.Side
side, err = order.StringToOrderSide(resp[i].Side)
if err != nil {
return nil, err
}
var timestamp int64
timestamp, err = strconv.ParseInt(resp[i].Timestamp, 10, 64)
if err != nil {
log.Warnf(log.ExchangeSys, "Unable to convert timestamp '%v', leaving blank", resp[i].Timestamp)
}
orderDate := time.Unix(timestamp, 0)
pair, err := currency.NewPairFromString(resp[i].Symbol)
var pair currency.Pair
pair, err = currency.NewPairFromString(resp[i].Symbol)
if err != nil {
return nil, err
}
@@ -982,7 +1000,7 @@ func (b *Bitfinex) GetOrderHistory(ctx context.Context, req *order.GetOrdersRequ
Date: orderDate,
Exchange: b.Name,
ID: strconv.FormatInt(resp[i].ID, 10),
Side: orderSide,
Side: side,
Price: resp[i].Price,
AverageExecutedPrice: resp[i].AverageExecutionPrice,
RemainingAmount: resp[i].RemainingAmount,
@@ -1008,7 +1026,10 @@ func (b *Bitfinex) GetOrderHistory(ctx context.Context, req *order.GetOrdersRequ
if orderType == "trailing-stop" {
orderDetail.Type = order.TrailingStop
} else {
orderDetail.Type = order.Type(strings.ToUpper(orderType))
orderDetail.Type, err = order.StringToOrderType(orderType)
if err != nil {
log.Errorf(log.ExchangeSys, "%s %v", b.Name, err)
}
}
orders[i] = orderDetail
@@ -1016,11 +1037,14 @@ func (b *Bitfinex) GetOrderHistory(ctx context.Context, req *order.GetOrdersRequ
order.FilterOrdersBySide(&orders, req.Side)
order.FilterOrdersByType(&orders, req.Type)
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)
}
for i := range req.Pairs {
b.appendOptionalDelimiter(&req.Pairs[i])
}
order.FilterOrdersByCurrencies(&orders, req.Pairs)
order.FilterOrdersByPairs(&orders, req.Pairs)
return orders, nil
}