mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-27 15:10:30 +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:
@@ -518,9 +518,7 @@ func (m *OrderManager) GetOrdersSnapshot(s order.Status) []order.Detail {
|
||||
var os []order.Detail
|
||||
for _, v := range m.orderStore.Orders {
|
||||
for i := range v {
|
||||
if s != v[i].Status &&
|
||||
s != order.AnyStatus &&
|
||||
s != "" {
|
||||
if s != v[i].Status && s != order.AnyStatus && s != order.UnknownStatus {
|
||||
continue
|
||||
}
|
||||
os = append(os, *v[i])
|
||||
@@ -685,7 +683,7 @@ func (m *OrderManager) processOrders() {
|
||||
Exchange: exchanges[i].GetName(),
|
||||
}
|
||||
orders := m.orderStore.getActiveOrders(filter)
|
||||
order.FilterOrdersByCurrencies(&orders, pairs)
|
||||
order.FilterOrdersByPairs(&orders, pairs)
|
||||
requiresProcessing := make(map[string]bool, len(orders))
|
||||
for x := range orders {
|
||||
requiresProcessing[orders[x].InternalOrderID] = true
|
||||
|
||||
@@ -879,7 +879,7 @@ func TestProcessOrders(t *testing.T) {
|
||||
t.Errorf("Expected 3 result, got: %d", len(res))
|
||||
}
|
||||
if res[0].Status != order.Active {
|
||||
t.Errorf("Order 1 should be active, but status is %s", string(res[0].Status))
|
||||
t.Errorf("Order 1 should be active, but status is %s", res[0].Status)
|
||||
}
|
||||
|
||||
// Order2 is not returned by exch.GetActiveOrders()
|
||||
@@ -892,7 +892,7 @@ func TestProcessOrders(t *testing.T) {
|
||||
t.Errorf("Expected 1 result, got: %d", len(res))
|
||||
}
|
||||
if res[0].Status != order.Cancelled {
|
||||
t.Errorf("Order 2 should be cancelled, but status is %s", string(res[0].Status))
|
||||
t.Errorf("Order 2 should be cancelled, but status is %s", res[0].Status)
|
||||
}
|
||||
|
||||
// Order3 is returned by exch.GetActiveOrders(), which will say it is active
|
||||
@@ -904,7 +904,7 @@ func TestProcessOrders(t *testing.T) {
|
||||
t.Errorf("Expected 1 result, got: %d", len(res))
|
||||
}
|
||||
if res[0].Status != order.Active {
|
||||
t.Errorf("Order 3 should be active, but status is %s", string(res[0].Status))
|
||||
t.Errorf("Order 3 should be active, but status is %s", res[0].Status)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1195,10 +1195,20 @@ func (s *RPCServer) SubmitOrder(ctx context.Context, r *gctrpc.SubmitOrderReques
|
||||
return nil, err
|
||||
}
|
||||
|
||||
side, err := order.StringToOrderSide(r.Side)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
oType, err := order.StringToOrderType(r.OrderType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
submission := &order.Submit{
|
||||
Pair: p,
|
||||
Side: order.Side(r.Side),
|
||||
Type: order.Type(r.OrderType),
|
||||
Side: side,
|
||||
Type: oType,
|
||||
Amount: r.Amount,
|
||||
Price: r.Price,
|
||||
ClientID: r.ClientId,
|
||||
@@ -1362,12 +1372,18 @@ func (s *RPCServer) CancelOrder(ctx context.Context, r *gctrpc.CancelOrderReques
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var side order.Side
|
||||
side, err = order.StringToOrderSide(r.Side)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = s.OrderManager.Cancel(ctx,
|
||||
&order.Cancel{
|
||||
Exchange: r.Exchange,
|
||||
AccountID: r.AccountId,
|
||||
ID: r.OrderId,
|
||||
Side: order.Side(r.Side),
|
||||
Side: side,
|
||||
WalletAddress: r.WalletAddress,
|
||||
Pair: p,
|
||||
AssetType: a,
|
||||
@@ -1402,6 +1418,12 @@ func (s *RPCServer) CancelBatchOrders(ctx context.Context, r *gctrpc.CancelBatch
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var side order.Side
|
||||
side, err = order.StringToOrderSide(r.Side)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
status := make(map[string]string)
|
||||
orders := strings.Split(r.OrdersId, ",")
|
||||
request := make([]order.Cancel, len(orders))
|
||||
@@ -1411,7 +1433,7 @@ func (s *RPCServer) CancelBatchOrders(ctx context.Context, r *gctrpc.CancelBatch
|
||||
request[x] = order.Cancel{
|
||||
AccountID: r.AccountId,
|
||||
ID: orderID,
|
||||
Side: order.Side(r.Side),
|
||||
Side: side,
|
||||
WalletAddress: r.WalletAddress,
|
||||
Pair: pair,
|
||||
AssetType: assetType,
|
||||
|
||||
@@ -1837,7 +1837,7 @@ func TestGetManagedOrders(t *testing.T) {
|
||||
ClientID: "",
|
||||
WalletAddress: "",
|
||||
Type: order.Limit,
|
||||
Side: "SELL",
|
||||
Side: order.Sell,
|
||||
Status: order.New,
|
||||
AssetType: asset.Spot,
|
||||
Pair: currency.NewPair(currency.BTC, currency.USDT),
|
||||
|
||||
Reference in New Issue
Block a user