mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-02 15:10:46 +00:00
orders: add Filter() method to GetOrdersRequest and force FilteredOrders return type on wrapper functions (#1055)
* orders: filter options return on validate * exchanges: force filter usage by wrapper return type and shift method functionality * exchanges: update tests and fix err shadow * exchanges: shadowland * exchanges: more shadow land spookyness * glorious: nits and ftx upgrade * linter: fix * orders: preserve unpopulated fields through filtering operation * glorious: nits Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
This commit is contained in:
@@ -390,9 +390,9 @@ func (g *Gateio) GetOpenOrders(ctx context.Context, symbol string) (OpenOrdersRe
|
||||
}
|
||||
|
||||
// GetTradeHistory retrieves all orders with an optional symbol filter
|
||||
func (g *Gateio) GetTradeHistory(ctx context.Context, symbol string) (TradHistoryResponse, error) {
|
||||
func (g *Gateio) GetTradeHistory(ctx context.Context, symbol string) (TradeHistoryResponse, error) {
|
||||
var params string
|
||||
var result TradHistoryResponse
|
||||
var result TradeHistoryResponse
|
||||
params = fmt.Sprintf("currencyPair=%s", symbol)
|
||||
|
||||
err := g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, gateioTradeHistory, params, &result)
|
||||
|
||||
@@ -301,6 +301,7 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
Type: order.AnyType,
|
||||
AssetType: asset.Spot,
|
||||
Side: order.AnySide,
|
||||
}
|
||||
|
||||
_, err := g.GetActiveOrders(context.Background(), &getOrdersRequest)
|
||||
@@ -315,6 +316,7 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
Type: order.AnyType,
|
||||
AssetType: asset.Spot,
|
||||
Side: order.AnySide,
|
||||
}
|
||||
|
||||
currPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
@@ -147,8 +147,8 @@ type OpenOrder struct {
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
// TradHistoryResponse The full response for retrieving all user trade history
|
||||
type TradHistoryResponse struct {
|
||||
// TradeHistoryResponse The full response for retrieving all user trade history
|
||||
type TradeHistoryResponse struct {
|
||||
Code int `json:"code,omitempty"`
|
||||
Elapsed string `json:"elapsed,omitempty"`
|
||||
Message string `json:"message"`
|
||||
|
||||
@@ -718,15 +718,17 @@ func (g *Gateio) GetFeeByType(ctx context.Context, feeBuilder *exchange.FeeBuild
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (g *Gateio) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
func (g *Gateio) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequest) (order.FilteredOrders, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []order.Detail
|
||||
var currPair string
|
||||
if len(req.Pairs) == 1 {
|
||||
fPair, err := g.FormatExchangeCurrency(req.Pairs[0], asset.Spot)
|
||||
var fPair currency.Pair
|
||||
fPair, err = g.FormatExchangeCurrency(req.Pairs[0], asset.Spot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -734,7 +736,8 @@ func (g *Gateio) GetActiveOrders(ctx context.Context, req *order.GetOrdersReques
|
||||
}
|
||||
if g.Websocket.CanUseAuthenticatedWebsocketForWrapper() {
|
||||
for i := 0; ; i += 100 {
|
||||
resp, err := g.wsGetOrderInfo(req.Type.String(), i, 100)
|
||||
var resp *WebSocketOrderQueryResult
|
||||
resp, err = g.wsGetOrderInfo(req.Type.String(), i, 100)
|
||||
if err != nil {
|
||||
return orders, err
|
||||
}
|
||||
@@ -748,7 +751,8 @@ func (g *Gateio) GetActiveOrders(ctx context.Context, req *order.GetOrdersReques
|
||||
if resp.WebSocketOrderQueryRecords[j].OrderType == 1 {
|
||||
orderType = order.Limit
|
||||
}
|
||||
p, err := currency.NewPairFromString(resp.WebSocketOrderQueryRecords[j].Market)
|
||||
var p currency.Pair
|
||||
p, err = currency.NewPairFromString(resp.WebSocketOrderQueryRecords[j].Market)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -772,12 +776,14 @@ func (g *Gateio) GetActiveOrders(ctx context.Context, req *order.GetOrdersReques
|
||||
}
|
||||
}
|
||||
} else {
|
||||
resp, err := g.GetOpenOrders(ctx, currPair)
|
||||
var resp OpenOrdersResponse
|
||||
resp, err = g.GetOpenOrders(ctx, currPair)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
format, err := g.GetPairFormat(asset.Spot, false)
|
||||
var format currency.PairFormat
|
||||
format, err = g.GetPairFormat(asset.Spot, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -797,7 +803,8 @@ func (g *Gateio) GetActiveOrders(ctx context.Context, req *order.GetOrdersReques
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s %v", g.Name, err)
|
||||
}
|
||||
status, err := order.StringToOrderStatus(resp.Orders[i].Status)
|
||||
var status order.Status
|
||||
status, err = order.StringToOrderStatus(resp.Orders[i].Status)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s %v", g.Name, err)
|
||||
}
|
||||
@@ -816,24 +823,21 @@ func (g *Gateio) GetActiveOrders(ctx context.Context, req *order.GetOrdersReques
|
||||
})
|
||||
}
|
||||
}
|
||||
err := order.FilterOrdersByTimeRange(&orders, req.StartTime, req.EndTime)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s %v", g.Name, err)
|
||||
}
|
||||
order.FilterOrdersBySide(&orders, req.Side)
|
||||
return orders, nil
|
||||
return req.Filter(g.Name, orders), nil
|
||||
}
|
||||
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
func (g *Gateio) GetOrderHistory(ctx context.Context, req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
func (g *Gateio) GetOrderHistory(ctx context.Context, req *order.GetOrdersRequest) (order.FilteredOrders, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var trades []TradesResponse
|
||||
for i := range req.Pairs {
|
||||
resp, err := g.GetTradeHistory(ctx, req.Pairs[i].String())
|
||||
var resp TradeHistoryResponse
|
||||
resp, err = g.GetTradeHistory(ctx, req.Pairs[i].String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -872,13 +876,7 @@ func (g *Gateio) GetOrderHistory(ctx context.Context, req *order.GetOrdersReques
|
||||
detail.InferCostsAndTimes()
|
||||
orders[i] = detail
|
||||
}
|
||||
|
||||
err = order.FilterOrdersByTimeRange(&orders, req.StartTime, req.EndTime)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s %v", g.Name, err)
|
||||
}
|
||||
order.FilterOrdersBySide(&orders, req.Side)
|
||||
return orders, nil
|
||||
return req.Filter(g.Name, orders), nil
|
||||
}
|
||||
|
||||
// AuthenticateWebsocket sends an authentication message to the websocket
|
||||
|
||||
Reference in New Issue
Block a user