exchanges: Initial context propagation (#744)

* gct: phase one context awareness pass

* exchanges: context propagation pass

* common/requester: force context requirement

* gctcli/exchanges: linter fix

* rpcserver: fix test using dummy rpc server

* backtester: fix comments

* grpc: add correct cancel and timeout for commands

* rpcserver_test: add comment on dummy server

* common: deprecated SendHTTPGetRequest

* linter: fix

* linter: turn on no context check

* apichecker: fix context linter issue

* binance: use param context

* common: remove checks as this gets executed before main

* common: change mutex to RW as clients can be used by multiple go routines.

* common: remove init and JIT default client. Unexport global variables and add protection.

* common: Add comments

* bithumb: after dinner mints fix
This commit is contained in:
Ryan O'Hara-Reid
2021-09-11 13:52:07 +10:00
committed by GitHub
parent 72516f7268
commit d636049fb2
168 changed files with 8085 additions and 6996 deletions

View File

@@ -48,10 +48,10 @@ type Gateio struct {
}
// GetSymbols returns all supported symbols
func (g *Gateio) GetSymbols() ([]string, error) {
func (g *Gateio) GetSymbols(ctx context.Context) ([]string, error) {
var result []string
urlPath := fmt.Sprintf("/%s/%s", gateioAPIVersion, gateioSymbol)
err := g.SendHTTPRequest(exchange.RestSpotSupplementary, urlPath, &result)
err := g.SendHTTPRequest(ctx, exchange.RestSpotSupplementary, urlPath, &result)
if err != nil {
return nil, nil
}
@@ -60,7 +60,7 @@ func (g *Gateio) GetSymbols() ([]string, error) {
// GetMarketInfo returns information about all trading pairs, including
// transaction fee, minimum order quantity, price accuracy and so on
func (g *Gateio) GetMarketInfo() (MarketInfoResponse, error) {
func (g *Gateio) GetMarketInfo(ctx context.Context) (MarketInfoResponse, error) {
type response struct {
Result string `json:"result"`
Pairs []interface{} `json:"pairs"`
@@ -69,7 +69,7 @@ func (g *Gateio) GetMarketInfo() (MarketInfoResponse, error) {
urlPath := fmt.Sprintf("/%s/%s", gateioAPIVersion, gateioMarketInfo)
var res response
var result MarketInfoResponse
err := g.SendHTTPRequest(exchange.RestSpotSupplementary, urlPath, &res)
err := g.SendHTTPRequest(ctx, exchange.RestSpotSupplementary, urlPath, &res)
if err != nil {
return result, err
}
@@ -94,8 +94,8 @@ func (g *Gateio) GetMarketInfo() (MarketInfoResponse, error) {
// updated every 10 seconds
//
// symbol: string of currency pair
func (g *Gateio) GetLatestSpotPrice(symbol string) (float64, error) {
res, err := g.GetTicker(symbol)
func (g *Gateio) GetLatestSpotPrice(ctx context.Context, symbol string) (float64, error) {
res, err := g.GetTicker(ctx, symbol)
if err != nil {
return 0, err
}
@@ -105,17 +105,17 @@ func (g *Gateio) GetLatestSpotPrice(symbol string) (float64, error) {
// GetTicker returns a ticker for the supplied symbol
// updated every 10 seconds
func (g *Gateio) GetTicker(symbol string) (TickerResponse, error) {
func (g *Gateio) GetTicker(ctx context.Context, symbol string) (TickerResponse, error) {
urlPath := fmt.Sprintf("/%s/%s/%s", gateioAPIVersion, gateioTicker, symbol)
var res TickerResponse
return res, g.SendHTTPRequest(exchange.RestSpotSupplementary, urlPath, &res)
return res, g.SendHTTPRequest(ctx, exchange.RestSpotSupplementary, urlPath, &res)
}
// GetTickers returns tickers for all symbols
func (g *Gateio) GetTickers() (map[string]TickerResponse, error) {
func (g *Gateio) GetTickers(ctx context.Context) (map[string]TickerResponse, error) {
urlPath := fmt.Sprintf("/%s/%s", gateioAPIVersion, gateioTickers)
resp := make(map[string]TickerResponse)
err := g.SendHTTPRequest(exchange.RestSpotSupplementary, urlPath, &resp)
err := g.SendHTTPRequest(ctx, exchange.RestSpotSupplementary, urlPath, &resp)
if err != nil {
return nil, err
}
@@ -123,10 +123,10 @@ func (g *Gateio) GetTickers() (map[string]TickerResponse, error) {
}
// GetTrades returns trades for symbols
func (g *Gateio) GetTrades(symbol string) (TradeHistory, error) {
func (g *Gateio) GetTrades(ctx context.Context, symbol string) (TradeHistory, error) {
urlPath := fmt.Sprintf("/%s/%s/%s", gateioAPIVersion, gateioTrades, symbol)
var resp TradeHistory
err := g.SendHTTPRequest(exchange.RestSpotSupplementary, urlPath, &resp)
err := g.SendHTTPRequest(ctx, exchange.RestSpotSupplementary, urlPath, &resp)
if err != nil {
return TradeHistory{}, err
}
@@ -134,10 +134,10 @@ func (g *Gateio) GetTrades(symbol string) (TradeHistory, error) {
}
// GetOrderbook returns the orderbook data for a suppled symbol
func (g *Gateio) GetOrderbook(symbol string) (Orderbook, error) {
func (g *Gateio) GetOrderbook(ctx context.Context, symbol string) (Orderbook, error) {
urlPath := fmt.Sprintf("/%s/%s/%s", gateioAPIVersion, gateioOrderbook, symbol)
var resp OrderbookResponse
err := g.SendHTTPRequest(exchange.RestSpotSupplementary, urlPath, &resp)
err := g.SendHTTPRequest(ctx, exchange.RestSpotSupplementary, urlPath, &resp)
if err != nil {
return Orderbook{}, err
}
@@ -195,7 +195,7 @@ func (g *Gateio) GetOrderbook(symbol string) (Orderbook, error) {
}
// GetSpotKline returns kline data for the most recent time period
func (g *Gateio) GetSpotKline(arg KlinesRequestParams) (kline.Item, error) {
func (g *Gateio) GetSpotKline(ctx context.Context, arg KlinesRequestParams) (kline.Item, error) {
urlPath := fmt.Sprintf("/%s/%s/%s?group_sec=%s&range_hour=%d",
gateioAPIVersion,
gateioKline,
@@ -204,7 +204,7 @@ func (g *Gateio) GetSpotKline(arg KlinesRequestParams) (kline.Item, error) {
arg.HourSize)
var rawKlines map[string]interface{}
err := g.SendHTTPRequest(exchange.RestSpotSupplementary, urlPath, &rawKlines)
err := g.SendHTTPRequest(ctx, exchange.RestSpotSupplementary, urlPath, &rawKlines)
if err != nil {
return kline.Item{}, err
}
@@ -265,15 +265,14 @@ func (g *Gateio) GetSpotKline(arg KlinesRequestParams) (kline.Item, error) {
}
// GetBalances obtains the users account balance
func (g *Gateio) GetBalances() (BalancesResponse, error) {
func (g *Gateio) GetBalances(ctx context.Context) (BalancesResponse, error) {
var result BalancesResponse
return result,
g.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, gateioBalances, "", &result)
g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, gateioBalances, "", &result)
}
// SpotNewOrder places a new order
func (g *Gateio) SpotNewOrder(arg SpotNewOrderRequestParams) (SpotNewOrderResponse, error) {
func (g *Gateio) SpotNewOrder(ctx context.Context, arg SpotNewOrderRequestParams) (SpotNewOrderResponse, error) {
var result SpotNewOrderResponse
// Be sure to use the correct price precision before calling this
@@ -284,13 +283,13 @@ func (g *Gateio) SpotNewOrder(arg SpotNewOrderRequestParams) (SpotNewOrderRespon
)
urlPath := fmt.Sprintf("%s/%s", gateioOrder, arg.Type)
return result, g.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, urlPath, params, &result)
return result, g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, urlPath, params, &result)
}
// CancelExistingOrder cancels an order given the supplied orderID and symbol
// orderID order ID number
// symbol trade pair (ltc_btc)
func (g *Gateio) CancelExistingOrder(orderID int64, symbol string) (bool, error) {
func (g *Gateio) CancelExistingOrder(ctx context.Context, orderID int64, symbol string) (bool, error) {
type response struct {
Result bool `json:"result"`
Code int `json:"code"`
@@ -303,7 +302,7 @@ func (g *Gateio) CancelExistingOrder(orderID int64, symbol string) (bool, error)
orderID,
symbol,
)
err := g.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, gateioCancelOrder, params, &result)
err := g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, gateioCancelOrder, params, &result)
if err != nil {
return false, err
}
@@ -315,7 +314,7 @@ func (g *Gateio) CancelExistingOrder(orderID int64, symbol string) (bool, error)
}
// SendHTTPRequest sends an unauthenticated HTTP request
func (g *Gateio) SendHTTPRequest(ep exchange.URL, path string, result interface{}) error {
func (g *Gateio) SendHTTPRequest(ctx context.Context, ep exchange.URL, path string, result interface{}) error {
endpoint, err := g.API.Endpoints.GetURL(ep)
if err != nil {
return err
@@ -328,14 +327,14 @@ func (g *Gateio) SendHTTPRequest(ep exchange.URL, path string, result interface{
HTTPDebugging: g.HTTPDebugging,
HTTPRecording: g.HTTPRecording,
}
return g.SendPayload(context.Background(), request.Unset, func() (*request.Item, error) {
return g.SendPayload(ctx, request.Unset, func() (*request.Item, error) {
return item, nil
})
}
// CancelAllExistingOrders all orders for a given symbol and side
// orderType (0: sell,1: buy,-1: unlimited)
func (g *Gateio) CancelAllExistingOrders(orderType int64, symbol string) error {
func (g *Gateio) CancelAllExistingOrders(ctx context.Context, orderType int64, symbol string) error {
type response struct {
Result bool `json:"result"`
Code int `json:"code"`
@@ -347,7 +346,7 @@ func (g *Gateio) CancelAllExistingOrders(orderType int64, symbol string) error {
orderType,
symbol,
)
err := g.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, gateioCancelAllOrders, params, &result)
err := g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, gateioCancelAllOrders, params, &result)
if err != nil {
return err
}
@@ -360,7 +359,7 @@ func (g *Gateio) CancelAllExistingOrders(orderType int64, symbol string) error {
}
// GetOpenOrders retrieves all open orders with an optional symbol filter
func (g *Gateio) GetOpenOrders(symbol string) (OpenOrdersResponse, error) {
func (g *Gateio) GetOpenOrders(ctx context.Context, symbol string) (OpenOrdersResponse, error) {
var params string
var result OpenOrdersResponse
@@ -368,7 +367,7 @@ func (g *Gateio) GetOpenOrders(symbol string) (OpenOrdersResponse, error) {
params = fmt.Sprintf("currencyPair=%s", symbol)
}
err := g.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, gateioOpenOrders, params, &result)
err := g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, gateioOpenOrders, params, &result)
if err != nil {
return result, err
}
@@ -381,12 +380,12 @@ func (g *Gateio) GetOpenOrders(symbol string) (OpenOrdersResponse, error) {
}
// GetTradeHistory retrieves all orders with an optional symbol filter
func (g *Gateio) GetTradeHistory(symbol string) (TradHistoryResponse, error) {
func (g *Gateio) GetTradeHistory(ctx context.Context, symbol string) (TradHistoryResponse, error) {
var params string
var result TradHistoryResponse
params = fmt.Sprintf("currencyPair=%s", symbol)
err := g.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, gateioTradeHistory, params, &result)
err := g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, gateioTradeHistory, params, &result)
if err != nil {
return result, err
}
@@ -406,7 +405,7 @@ func (g *Gateio) GenerateSignature(message string) ([]byte, error) {
// SendAuthenticatedHTTPRequest sends authenticated requests to the Gateio API
// To use this you must setup an APIKey and APISecret from the exchange
func (g *Gateio) SendAuthenticatedHTTPRequest(ep exchange.URL, method, endpoint, param string, result interface{}) error {
func (g *Gateio) SendAuthenticatedHTTPRequest(ctx context.Context, ep exchange.URL, method, endpoint, param string, result interface{}) error {
if !g.AllowAuthenticatedRequest() {
return fmt.Errorf("%s %w", g.Name, exchange.ErrAuthenticatedRequestWithoutCredentialsSet)
}
@@ -438,7 +437,7 @@ func (g *Gateio) SendAuthenticatedHTTPRequest(ep exchange.URL, method, endpoint,
HTTPDebugging: g.HTTPDebugging,
HTTPRecording: g.HTTPRecording,
}
err = g.SendPayload(context.Background(), request.Unset, func() (*request.Item, error) {
err = g.SendPayload(ctx, request.Unset, func() (*request.Item, error) {
item.Body = strings.NewReader(param)
return item, nil
})
@@ -465,10 +464,10 @@ func (g *Gateio) SendAuthenticatedHTTPRequest(ep exchange.URL, method, endpoint,
}
// GetFee returns an estimate of fee based on type of transaction
func (g *Gateio) GetFee(feeBuilder *exchange.FeeBuilder) (fee float64, err error) {
func (g *Gateio) GetFee(ctx context.Context, feeBuilder *exchange.FeeBuilder) (fee float64, err error) {
switch feeBuilder.FeeType {
case exchange.CryptocurrencyTradeFee:
feePairs, err := g.GetMarketInfo()
feePairs, err := g.GetMarketInfo(ctx)
if err != nil {
return 0, err
}
@@ -520,7 +519,7 @@ func getCryptocurrencyWithdrawalFee(c currency.Code) float64 {
}
// WithdrawCrypto withdraws cryptocurrency to your selected wallet
func (g *Gateio) WithdrawCrypto(currency, address string, amount float64) (*withdraw.ExchangeResponse, error) {
func (g *Gateio) WithdrawCrypto(ctx context.Context, currency, address string, amount float64) (*withdraw.ExchangeResponse, error) {
type response struct {
Result bool `json:"result"`
Message string `json:"message"`
@@ -533,7 +532,7 @@ func (g *Gateio) WithdrawCrypto(currency, address string, amount float64) (*with
address,
amount,
)
err := g.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, gateioWithdraw, params, &result)
err := g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, gateioWithdraw, params, &result)
if err != nil {
return nil, err
}
@@ -547,7 +546,7 @@ func (g *Gateio) WithdrawCrypto(currency, address string, amount float64) (*with
}
// GetCryptoDepositAddress returns a deposit address for a cryptocurrency
func (g *Gateio) GetCryptoDepositAddress(currency string) (string, error) {
func (g *Gateio) GetCryptoDepositAddress(ctx context.Context, currency string) (string, error) {
type response struct {
Result bool `json:"result,string"`
Code int `json:"code"`
@@ -559,7 +558,7 @@ func (g *Gateio) GetCryptoDepositAddress(currency string) (string, error) {
params := fmt.Sprintf("currency=%s",
currency)
err := g.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, gateioDepositAddress, params, &result)
err := g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, gateioDepositAddress, params, &result)
if err != nil {
return "", err
}

View File

@@ -1,6 +1,7 @@
package gateio
import (
"context"
"log"
"net/http"
"os"
@@ -59,7 +60,7 @@ func TestMain(m *testing.M) {
func TestGetSymbols(t *testing.T) {
t.Parallel()
_, err := g.GetSymbols()
_, err := g.GetSymbols(context.Background())
if err != nil {
t.Errorf("Gateio TestGetSymbols: %s", err)
}
@@ -67,7 +68,7 @@ func TestGetSymbols(t *testing.T) {
func TestGetMarketInfo(t *testing.T) {
t.Parallel()
_, err := g.GetMarketInfo()
_, err := g.GetMarketInfo(context.Background())
if err != nil {
t.Errorf("Gateio GetMarketInfo: %s", err)
}
@@ -80,12 +81,13 @@ func TestSpotNewOrder(t *testing.T) {
t.Skip()
}
_, err := g.SpotNewOrder(SpotNewOrderRequestParams{
Symbol: "btc_usdt",
Amount: -1,
Price: 100000,
Type: order.Sell.Lower(),
})
_, err := g.SpotNewOrder(context.Background(),
SpotNewOrderRequestParams{
Symbol: "btc_usdt",
Amount: -1,
Price: 100000,
Type: order.Sell.Lower(),
})
if err != nil {
t.Errorf("Gateio SpotNewOrder: %s", err)
}
@@ -98,7 +100,7 @@ func TestCancelExistingOrder(t *testing.T) {
t.Skip()
}
_, err := g.CancelExistingOrder(917591554, "btc_usdt")
_, err := g.CancelExistingOrder(context.Background(), 917591554, "btc_usdt")
if err != nil {
t.Errorf("Gateio CancelExistingOrder: %s", err)
}
@@ -111,7 +113,7 @@ func TestGetBalances(t *testing.T) {
t.Skip()
}
_, err := g.GetBalances()
_, err := g.GetBalances(context.Background())
if err != nil {
t.Errorf("Gateio GetBalances: %s", err)
}
@@ -119,7 +121,7 @@ func TestGetBalances(t *testing.T) {
func TestGetLatestSpotPrice(t *testing.T) {
t.Parallel()
_, err := g.GetLatestSpotPrice("btc_usdt")
_, err := g.GetLatestSpotPrice(context.Background(), "btc_usdt")
if err != nil {
t.Errorf("Gateio GetLatestSpotPrice: %s", err)
}
@@ -127,7 +129,7 @@ func TestGetLatestSpotPrice(t *testing.T) {
func TestGetTicker(t *testing.T) {
t.Parallel()
_, err := g.GetTicker("btc_usdt")
_, err := g.GetTicker(context.Background(), "btc_usdt")
if err != nil {
t.Errorf("Gateio GetTicker: %s", err)
}
@@ -135,7 +137,7 @@ func TestGetTicker(t *testing.T) {
func TestGetTickers(t *testing.T) {
t.Parallel()
_, err := g.GetTickers()
_, err := g.GetTickers(context.Background())
if err != nil {
t.Errorf("Gateio GetTicker: %s", err)
}
@@ -143,7 +145,7 @@ func TestGetTickers(t *testing.T) {
func TestGetOrderbook(t *testing.T) {
t.Parallel()
_, err := g.GetOrderbook("btc_usdt")
_, err := g.GetOrderbook(context.Background(), "btc_usdt")
if err != nil {
t.Errorf("Gateio GetTicker: %s", err)
}
@@ -151,11 +153,12 @@ func TestGetOrderbook(t *testing.T) {
func TestGetSpotKline(t *testing.T) {
t.Parallel()
_, err := g.GetSpotKline(KlinesRequestParams{
Symbol: "btc_usdt",
GroupSec: "5", // 5 minutes or less
HourSize: 1, // 1 hour data
})
_, err := g.GetSpotKline(context.Background(),
KlinesRequestParams{
Symbol: "btc_usdt",
GroupSec: "5", // 5 minutes or less
HourSize: 1, // 1 hour data
})
if err != nil {
t.Errorf("Gateio GetSpotKline: %s", err)
@@ -176,8 +179,9 @@ func setFeeBuilder() *exchange.FeeBuilder {
}
func TestGetTradeHistory(t *testing.T) {
_, err := g.GetTrades(currency.NewPairWithDelimiter(currency.BTC.String(),
currency.USDT.String(), "_").String())
_, err := g.GetTrades(context.Background(),
currency.NewPairWithDelimiter(currency.BTC.String(),
currency.USDT.String(), "_").String())
if err != nil {
t.Error(err)
}
@@ -186,7 +190,7 @@ func TestGetTradeHistory(t *testing.T) {
// TestGetFeeByTypeOfflineTradeFee logic test
func TestGetFeeByTypeOfflineTradeFee(t *testing.T) {
var feeBuilder = setFeeBuilder()
_, err := g.GetFeeByType(feeBuilder)
_, err := g.GetFeeByType(context.Background(), feeBuilder)
if err != nil {
t.Fatal(err)
}
@@ -205,7 +209,7 @@ func TestGetFee(t *testing.T) {
var feeBuilder = setFeeBuilder()
if areTestAPIKeysSet() {
// CryptocurrencyTradeFee Basic
if _, err := g.GetFee(feeBuilder); err != nil {
if _, err := g.GetFee(context.Background(), feeBuilder); err != nil {
t.Error(err)
}
@@ -213,28 +217,28 @@ func TestGetFee(t *testing.T) {
feeBuilder = setFeeBuilder()
feeBuilder.Amount = 1000
feeBuilder.PurchasePrice = 1000
if _, err := g.GetFee(feeBuilder); err != nil {
if _, err := g.GetFee(context.Background(), feeBuilder); err != nil {
t.Error(err)
}
// CryptocurrencyTradeFee IsMaker
feeBuilder = setFeeBuilder()
feeBuilder.IsMaker = true
if _, err := g.GetFee(feeBuilder); err != nil {
if _, err := g.GetFee(context.Background(), feeBuilder); err != nil {
t.Error(err)
}
// CryptocurrencyTradeFee Negative purchase price
feeBuilder = setFeeBuilder()
feeBuilder.PurchasePrice = -1000
if _, err := g.GetFee(feeBuilder); err != nil {
if _, err := g.GetFee(context.Background(), feeBuilder); err != nil {
t.Error(err)
}
}
// CryptocurrencyWithdrawalFee Basic
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.CryptocurrencyWithdrawalFee
if _, err := g.GetFee(feeBuilder); err != nil {
if _, err := g.GetFee(context.Background(), feeBuilder); err != nil {
t.Error(err)
}
@@ -242,21 +246,21 @@ func TestGetFee(t *testing.T) {
feeBuilder = setFeeBuilder()
feeBuilder.Pair.Base = currency.NewCode("hello")
feeBuilder.FeeType = exchange.CryptocurrencyWithdrawalFee
if _, err := g.GetFee(feeBuilder); err != nil {
if _, err := g.GetFee(context.Background(), feeBuilder); err != nil {
t.Error(err)
}
// CryptocurrencyDepositFee Basic
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.CryptocurrencyDepositFee
if _, err := g.GetFee(feeBuilder); err != nil {
if _, err := g.GetFee(context.Background(), feeBuilder); err != nil {
t.Error(err)
}
// InternationalBankDepositFee Basic
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.InternationalBankDepositFee
if _, err := g.GetFee(feeBuilder); err != nil {
if _, err := g.GetFee(context.Background(), feeBuilder); err != nil {
t.Error(err)
}
@@ -264,7 +268,7 @@ func TestGetFee(t *testing.T) {
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.InternationalBankWithdrawalFee
feeBuilder.FiatCurrency = currency.USD
if _, err := g.GetFee(feeBuilder); err != nil {
if _, err := g.GetFee(context.Background(), feeBuilder); err != nil {
t.Error(err)
}
}
@@ -283,7 +287,7 @@ func TestGetActiveOrders(t *testing.T) {
AssetType: asset.Spot,
}
_, err := g.GetActiveOrders(&getOrdersRequest)
_, err := g.GetActiveOrders(context.Background(), &getOrdersRequest)
if areTestAPIKeysSet() && err != nil {
t.Errorf("Could not get open orders: %s", err)
} else if !areTestAPIKeysSet() && err == nil {
@@ -301,7 +305,7 @@ func TestGetOrderHistory(t *testing.T) {
currPair.Delimiter = "_"
getOrdersRequest.Pairs = []currency.Pair{currPair}
_, err := g.GetOrderHistory(&getOrdersRequest)
_, err := g.GetOrderHistory(context.Background(), &getOrdersRequest)
if areTestAPIKeysSet() && err != nil {
t.Errorf("Could not get order history: %s", err)
} else if !areTestAPIKeysSet() && err == nil {
@@ -333,7 +337,7 @@ func TestSubmitOrder(t *testing.T) {
ClientID: "meowOrder",
AssetType: asset.Spot,
}
response, err := g.SubmitOrder(orderSubmission)
response, err := g.SubmitOrder(context.Background(), orderSubmission)
if areTestAPIKeysSet() && (err != nil || !response.IsOrderPlaced) {
t.Errorf("Order failed to be placed: %v", err)
} else if !areTestAPIKeysSet() && err == nil {
@@ -355,7 +359,7 @@ func TestCancelExchangeOrder(t *testing.T) {
AssetType: asset.Spot,
}
err := g.CancelOrder(orderCancellation)
err := g.CancelOrder(context.Background(), orderCancellation)
if !areTestAPIKeysSet() && err == nil {
t.Error("Expecting an error when no keys are set")
}
@@ -378,7 +382,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
AssetType: asset.Spot,
}
resp, err := g.CancelAllOrders(orderCancellation)
resp, err := g.CancelAllOrders(context.Background(), orderCancellation)
if !areTestAPIKeysSet() && err == nil {
t.Error("Expecting an error when no keys are set")
@@ -394,12 +398,12 @@ func TestCancelAllExchangeOrders(t *testing.T) {
func TestGetAccountInfo(t *testing.T) {
if apiSecret == "" || apiKey == "" {
_, err := g.UpdateAccountInfo(asset.Spot)
_, err := g.UpdateAccountInfo(context.Background(), asset.Spot)
if err == nil {
t.Error("GetAccountInfo() Expected error")
}
} else {
_, err := g.UpdateAccountInfo(asset.Spot)
_, err := g.UpdateAccountInfo(context.Background(), asset.Spot)
if err != nil {
t.Error("GetAccountInfo() error", err)
}
@@ -410,7 +414,8 @@ func TestModifyOrder(t *testing.T) {
if areTestAPIKeysSet() && !canManipulateRealOrders {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}
_, err := g.ModifyOrder(&order.Modify{AssetType: asset.Spot})
_, err := g.ModifyOrder(context.Background(),
&order.Modify{AssetType: asset.Spot})
if err == nil {
t.Error("ModifyOrder() Expected error")
}
@@ -430,7 +435,8 @@ func TestWithdraw(t *testing.T) {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}
_, err := g.WithdrawCryptocurrencyFunds(&withdrawCryptoRequest)
_, err := g.WithdrawCryptocurrencyFunds(context.Background(),
&withdrawCryptoRequest)
if !areTestAPIKeysSet() && err == nil {
t.Error("Expecting an error when no keys are set")
}
@@ -445,7 +451,7 @@ func TestWithdrawFiat(t *testing.T) {
}
var withdrawFiatRequest = withdraw.Request{}
_, err := g.WithdrawFiatFunds(&withdrawFiatRequest)
_, err := g.WithdrawFiatFunds(context.Background(), &withdrawFiatRequest)
if err != common.ErrFunctionNotSupported {
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
}
@@ -457,7 +463,8 @@ func TestWithdrawInternationalBank(t *testing.T) {
}
var withdrawFiatRequest = withdraw.Request{}
_, err := g.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
_, err := g.WithdrawFiatFundsToInternationalBank(context.Background(),
&withdrawFiatRequest)
if err != common.ErrFunctionNotSupported {
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
}
@@ -465,12 +472,12 @@ func TestWithdrawInternationalBank(t *testing.T) {
func TestGetDepositAddress(t *testing.T) {
if areTestAPIKeysSet() {
_, err := g.GetDepositAddress(currency.ETC, "")
_, err := g.GetDepositAddress(context.Background(), currency.ETC, "")
if err != nil {
t.Error("Test Fail - GetDepositAddress error", err)
}
} else {
_, err := g.GetDepositAddress(currency.ETC, "")
_, err := g.GetDepositAddress(context.Background(), currency.ETC, "")
if err == nil {
t.Error("Test Fail - GetDepositAddress error cannot be nil")
}
@@ -481,7 +488,8 @@ func TestGetOrderInfo(t *testing.T) {
t.Skip("no API keys set skipping test")
}
_, err := g.GetOrderInfo("917591554", currency.Pair{}, asset.Spot)
_, err := g.GetOrderInfo(context.Background(),
"917591554", currency.Pair{}, asset.Spot)
if err != nil {
if err.Error() != "no order found with id 917591554" && err.Error() != "failed to get open orders" {
t.Fatalf("GetOrderInfo() returned an error skipping test: %v", err)
@@ -742,7 +750,8 @@ func TestGetHistoricCandles(t *testing.T) {
t.Fatal(err)
}
startTime := time.Now().Add(-time.Hour * 6)
_, err = g.GetHistoricCandles(currencyPair, asset.Spot, startTime, time.Now(), kline.OneMin)
_, err = g.GetHistoricCandles(context.Background(),
currencyPair, asset.Spot, startTime, time.Now(), kline.OneMin)
if err != nil {
t.Fatal(err)
}
@@ -754,7 +763,8 @@ func TestGetHistoricCandlesExtended(t *testing.T) {
t.Fatal(err)
}
startTime := time.Now().Add(-time.Minute * 2)
_, err = g.GetHistoricCandlesExtended(currencyPair, asset.Spot, startTime, time.Now(), kline.OneMin)
_, err = g.GetHistoricCandlesExtended(context.Background(),
currencyPair, asset.Spot, startTime, time.Now(), kline.OneMin)
if err != nil {
t.Fatal(err)
}
@@ -820,7 +830,7 @@ func TestGetRecentTrades(t *testing.T) {
if err != nil {
t.Fatal(err)
}
_, err = g.GetRecentTrades(currencyPair, asset.Spot)
_, err = g.GetRecentTrades(context.Background(), currencyPair, asset.Spot)
if err != nil {
t.Error(err)
}
@@ -832,7 +842,8 @@ func TestGetHistoricTrades(t *testing.T) {
if err != nil {
t.Fatal(err)
}
_, err = g.GetHistoricTrades(currencyPair, asset.Spot, time.Now().Add(-time.Minute*15), time.Now())
_, err = g.GetHistoricTrades(context.Background(),
currencyPair, asset.Spot, time.Now().Add(-time.Minute*15), time.Now())
if err != nil && err != common.ErrFunctionNotSupported {
t.Error(err)
}
@@ -844,14 +855,14 @@ func TestUpdateTicker(t *testing.T) {
if err != nil {
t.Fatal(err)
}
_, err = g.UpdateTicker(cp, asset.Spot)
_, err = g.UpdateTicker(context.Background(), cp, asset.Spot)
if err != nil {
t.Error(err)
}
}
func TestUpdateTickers(t *testing.T) {
err := g.UpdateTickers(asset.Spot)
err := g.UpdateTickers(context.Background(), asset.Spot)
if err != nil {
t.Error(err)
}

View File

@@ -1,6 +1,7 @@
package gateio
import (
"context"
"errors"
"fmt"
"sort"
@@ -42,7 +43,7 @@ func (g *Gateio) GetDefaultConfig() (*config.ExchangeConfig, error) {
}
if g.Features.Supports.RESTCapabilities.AutoPairUpdates {
err = g.UpdateTradablePairs(true)
err = g.UpdateTradablePairs(context.TODO(), true)
if err != nil {
return nil, err
}
@@ -205,21 +206,21 @@ func (g *Gateio) Run() {
return
}
err := g.UpdateTradablePairs(false)
err := g.UpdateTradablePairs(context.TODO(), false)
if err != nil {
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", g.Name, err)
}
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (g *Gateio) FetchTradablePairs(asset asset.Item) ([]string, error) {
return g.GetSymbols()
func (g *Gateio) FetchTradablePairs(ctx context.Context, asset asset.Item) ([]string, error) {
return g.GetSymbols(ctx)
}
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (g *Gateio) UpdateTradablePairs(forceUpdate bool) error {
pairs, err := g.FetchTradablePairs(asset.Spot)
func (g *Gateio) UpdateTradablePairs(ctx context.Context, forceUpdate bool) error {
pairs, err := g.FetchTradablePairs(ctx, asset.Spot)
if err != nil {
return err
}
@@ -232,8 +233,8 @@ func (g *Gateio) UpdateTradablePairs(forceUpdate bool) error {
}
// UpdateTickers updates the ticker for all currency pairs of a given asset type
func (g *Gateio) UpdateTickers(a asset.Item) error {
result, err := g.GetTickers()
func (g *Gateio) UpdateTickers(ctx context.Context, a asset.Item) error {
result, err := g.GetTickers(ctx)
if err != nil {
return err
}
@@ -268,8 +269,8 @@ func (g *Gateio) UpdateTickers(a asset.Item) error {
}
// UpdateTicker updates and returns the ticker for a currency pair
func (g *Gateio) UpdateTicker(p currency.Pair, a asset.Item) (*ticker.Price, error) {
err := g.UpdateTickers(a)
func (g *Gateio) UpdateTicker(ctx context.Context, p currency.Pair, a asset.Item) (*ticker.Price, error) {
err := g.UpdateTickers(ctx, a)
if err != nil {
return nil, err
}
@@ -277,25 +278,25 @@ func (g *Gateio) UpdateTicker(p currency.Pair, a asset.Item) (*ticker.Price, err
}
// FetchTicker returns the ticker for a currency pair
func (g *Gateio) FetchTicker(p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
func (g *Gateio) FetchTicker(ctx context.Context, p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
tickerNew, err := ticker.GetTicker(g.Name, p, assetType)
if err != nil {
return g.UpdateTicker(p, assetType)
return g.UpdateTicker(ctx, p, assetType)
}
return tickerNew, nil
}
// FetchOrderbook returns orderbook base on the currency pair
func (g *Gateio) FetchOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
func (g *Gateio) FetchOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
ob, err := orderbook.Get(g.Name, p, assetType)
if err != nil {
return g.UpdateOrderbook(p, assetType)
return g.UpdateOrderbook(ctx, p, assetType)
}
return ob, nil
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (g *Gateio) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
func (g *Gateio) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
book := &orderbook.Base{
Exchange: g.Name,
Pair: p,
@@ -307,7 +308,7 @@ func (g *Gateio) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orderb
return book, err
}
orderbookNew, err := g.GetOrderbook(curr.String())
orderbookNew, err := g.GetOrderbook(ctx, curr.String())
if err != nil {
return book, err
}
@@ -334,7 +335,7 @@ func (g *Gateio) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orderb
// UpdateAccountInfo retrieves balances for all enabled currencies for the
// ZB exchange
func (g *Gateio) UpdateAccountInfo(assetType asset.Item) (account.Holdings, error) {
func (g *Gateio) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (account.Holdings, error) {
var info account.Holdings
var balances []account.Balance
@@ -355,7 +356,7 @@ func (g *Gateio) UpdateAccountInfo(assetType asset.Item) (account.Holdings, erro
Currencies: currData,
})
} else {
balance, err := g.GetBalances()
balance, err := g.GetBalances(ctx)
if err != nil {
return info, err
}
@@ -419,10 +420,10 @@ func (g *Gateio) UpdateAccountInfo(assetType asset.Item) (account.Holdings, erro
}
// FetchAccountInfo retrieves balances for all enabled currencies
func (g *Gateio) FetchAccountInfo(assetType asset.Item) (account.Holdings, error) {
func (g *Gateio) FetchAccountInfo(ctx context.Context, assetType asset.Item) (account.Holdings, error) {
acc, err := account.GetHoldings(g.Name, assetType)
if err != nil {
return g.UpdateAccountInfo(assetType)
return g.UpdateAccountInfo(ctx, assetType)
}
return acc, nil
@@ -430,24 +431,24 @@ func (g *Gateio) FetchAccountInfo(assetType asset.Item) (account.Holdings, error
// GetFundingHistory returns funding history, deposits and
// withdrawals
func (g *Gateio) GetFundingHistory() ([]exchange.FundHistory, error) {
func (g *Gateio) GetFundingHistory(ctx context.Context) ([]exchange.FundHistory, error) {
return nil, common.ErrFunctionNotSupported
}
// GetWithdrawalsHistory returns previous withdrawals data
func (g *Gateio) GetWithdrawalsHistory(c currency.Code) (resp []exchange.WithdrawalHistory, err error) {
func (g *Gateio) GetWithdrawalsHistory(ctx context.Context, c currency.Code) (resp []exchange.WithdrawalHistory, err error) {
return nil, common.ErrNotYetImplemented
}
// GetRecentTrades returns the most recent trades for a currency and asset
func (g *Gateio) GetRecentTrades(p currency.Pair, assetType asset.Item) ([]trade.Data, error) {
func (g *Gateio) GetRecentTrades(ctx context.Context, p currency.Pair, assetType asset.Item) ([]trade.Data, error) {
var err error
p, err = g.FormatExchangeCurrency(p, assetType)
if err != nil {
return nil, err
}
var tradeData TradeHistory
tradeData, err = g.GetTrades(p.String())
tradeData, err = g.GetTrades(ctx, p.String())
if err != nil {
return nil, err
}
@@ -480,13 +481,13 @@ func (g *Gateio) GetRecentTrades(p currency.Pair, assetType asset.Item) ([]trade
}
// GetHistoricTrades returns historic trade data within the timeframe provided
func (g *Gateio) GetHistoricTrades(_ currency.Pair, _ asset.Item, _, _ time.Time) ([]trade.Data, error) {
func (g *Gateio) GetHistoricTrades(_ context.Context, _ currency.Pair, _ asset.Item, _, _ time.Time) ([]trade.Data, error) {
return nil, common.ErrFunctionNotSupported
}
// SubmitOrder submits a new order
// TODO: support multiple order types (IOC)
func (g *Gateio) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
func (g *Gateio) SubmitOrder(ctx context.Context, s *order.Submit) (order.SubmitResponse, error) {
var submitOrderResponse order.SubmitResponse
if err := s.Validate(); err != nil {
return submitOrderResponse, err
@@ -511,7 +512,7 @@ func (g *Gateio) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
Type: orderTypeFormat,
}
response, err := g.SpotNewOrder(spotNewOrderRequestParams)
response, err := g.SpotNewOrder(ctx, spotNewOrderRequestParams)
if err != nil {
return submitOrderResponse, err
}
@@ -528,12 +529,12 @@ func (g *Gateio) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
// ModifyOrder will allow of changing orderbook placement and limit to
// market conversion
func (g *Gateio) ModifyOrder(action *order.Modify) (order.Modify, error) {
func (g *Gateio) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) {
return order.Modify{}, common.ErrFunctionNotSupported
}
// CancelOrder cancels an order by its corresponding ID number
func (g *Gateio) CancelOrder(o *order.Cancel) error {
func (g *Gateio) CancelOrder(ctx context.Context, o *order.Cancel) error {
if err := o.Validate(o.StandardCancel()); err != nil {
return err
}
@@ -548,21 +549,21 @@ func (g *Gateio) CancelOrder(o *order.Cancel) error {
return err
}
_, err = g.CancelExistingOrder(orderIDInt, fpair.String())
_, err = g.CancelExistingOrder(ctx, orderIDInt, fpair.String())
return err
}
// CancelBatchOrders cancels an orders by their corresponding ID numbers
func (g *Gateio) CancelBatchOrders(o []order.Cancel) (order.CancelBatchResponse, error) {
func (g *Gateio) CancelBatchOrders(ctx context.Context, o []order.Cancel) (order.CancelBatchResponse, error) {
return order.CancelBatchResponse{}, common.ErrNotYetImplemented
}
// CancelAllOrders cancels all orders associated with a currency pair
func (g *Gateio) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
func (g *Gateio) CancelAllOrders(ctx context.Context, _ *order.Cancel) (order.CancelAllResponse, error) {
cancelAllOrdersResponse := order.CancelAllResponse{
Status: make(map[string]string),
}
openOrders, err := g.GetOpenOrders("")
openOrders, err := g.GetOpenOrders(ctx, "")
if err != nil {
return cancelAllOrdersResponse, err
}
@@ -573,7 +574,7 @@ func (g *Gateio) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, erro
}
for unique := range uniqueSymbols {
err = g.CancelAllExistingOrders(-1, unique)
err = g.CancelAllExistingOrders(ctx, -1, unique)
if err != nil {
cancelAllOrdersResponse.Status[unique] = err.Error()
}
@@ -583,9 +584,9 @@ func (g *Gateio) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, erro
}
// GetOrderInfo returns order information based on order ID
func (g *Gateio) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
func (g *Gateio) GetOrderInfo(ctx context.Context, orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
var orderDetail order.Detail
orders, err := g.GetOpenOrders("")
orders, err := g.GetOpenOrders(ctx, "")
if err != nil {
return orderDetail, errors.New("failed to get open orders")
}
@@ -627,8 +628,8 @@ func (g *Gateio) GetOrderInfo(orderID string, pair currency.Pair, assetType asse
}
// GetDepositAddress returns a deposit address for a specified currency
func (g *Gateio) GetDepositAddress(cryptocurrency currency.Code, _ string) (string, error) {
addr, err := g.GetCryptoDepositAddress(cryptocurrency.String())
func (g *Gateio) GetDepositAddress(ctx context.Context, cryptocurrency currency.Code, _ string) (string, error) {
addr, err := g.GetCryptoDepositAddress(ctx, cryptocurrency.String())
if err != nil {
return "", err
}
@@ -642,38 +643,39 @@ func (g *Gateio) GetDepositAddress(cryptocurrency currency.Code, _ string) (stri
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
// submitted
func (g *Gateio) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
func (g *Gateio) WithdrawCryptocurrencyFunds(ctx context.Context, withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
if err := withdrawRequest.Validate(); err != nil {
return nil, err
}
return g.WithdrawCrypto(withdrawRequest.Currency.String(),
return g.WithdrawCrypto(ctx,
withdrawRequest.Currency.String(),
withdrawRequest.Crypto.Address,
withdrawRequest.Amount)
}
// WithdrawFiatFunds returns a withdrawal ID when a
// withdrawal is submitted
func (g *Gateio) WithdrawFiatFunds(_ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
func (g *Gateio) WithdrawFiatFunds(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
return nil, common.ErrFunctionNotSupported
}
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
// withdrawal is submitted
func (g *Gateio) WithdrawFiatFundsToInternationalBank(_ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
func (g *Gateio) WithdrawFiatFundsToInternationalBank(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
return nil, common.ErrFunctionNotSupported
}
// GetFeeByType returns an estimate of fee based on type of transaction
func (g *Gateio) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error) {
func (g *Gateio) GetFeeByType(ctx context.Context, feeBuilder *exchange.FeeBuilder) (float64, error) {
if !g.AllowAuthenticatedRequest() && // Todo check connection status
feeBuilder.FeeType == exchange.CryptocurrencyTradeFee {
feeBuilder.FeeType = exchange.OfflineTradeFee
}
return g.GetFee(feeBuilder)
return g.GetFee(ctx, feeBuilder)
}
// GetActiveOrders retrieves any orders that are active/open
func (g *Gateio) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
func (g *Gateio) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequest) ([]order.Detail, error) {
if err := req.Validate(); err != nil {
return nil, err
}
@@ -727,7 +729,7 @@ func (g *Gateio) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, e
}
}
} else {
resp, err := g.GetOpenOrders(currPair)
resp, err := g.GetOpenOrders(ctx, currPair)
if err != nil {
return nil, err
}
@@ -769,14 +771,14 @@ func (g *Gateio) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, e
// GetOrderHistory retrieves account order information
// Can Limit response to specific order status
func (g *Gateio) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
func (g *Gateio) GetOrderHistory(ctx context.Context, req *order.GetOrdersRequest) ([]order.Detail, error) {
if err := req.Validate(); err != nil {
return nil, err
}
var trades []TradesResponse
for i := range req.Pairs {
resp, err := g.GetTradeHistory(req.Pairs[i].String())
resp, err := g.GetTradeHistory(ctx, req.Pairs[i].String())
if err != nil {
return nil, err
}
@@ -814,14 +816,14 @@ func (g *Gateio) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, e
}
// AuthenticateWebsocket sends an authentication message to the websocket
func (g *Gateio) AuthenticateWebsocket() error {
func (g *Gateio) AuthenticateWebsocket(_ context.Context) error {
return g.wsServerSignIn()
}
// ValidateCredentials validates current credentials used for wrapper
// functionality
func (g *Gateio) ValidateCredentials(assetType asset.Item) error {
_, err := g.UpdateAccountInfo(assetType)
func (g *Gateio) ValidateCredentials(ctx context.Context, assetType asset.Item) error {
_, err := g.UpdateAccountInfo(ctx, assetType)
return g.CheckTransientError(err)
}
@@ -831,7 +833,7 @@ func (g *Gateio) FormatExchangeKlineInterval(in kline.Interval) string {
}
// GetHistoricCandles returns candles between a time period for a set time interval
func (g *Gateio) GetHistoricCandles(pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
func (g *Gateio) GetHistoricCandles(ctx context.Context, pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
if err := g.ValidateKline(pair, a, interval); err != nil {
return kline.Item{}, err
}
@@ -848,7 +850,7 @@ func (g *Gateio) GetHistoricCandles(pair currency.Pair, a asset.Item, start, end
HourSize: int(hours),
}
klineData, err := g.GetSpotKline(params)
klineData, err := g.GetSpotKline(ctx, params)
if err != nil {
return kline.Item{}, err
}
@@ -862,6 +864,6 @@ func (g *Gateio) GetHistoricCandles(pair currency.Pair, a asset.Item, start, end
}
// GetHistoricCandlesExtended returns candles between a time period for a set time interval
func (g *Gateio) GetHistoricCandlesExtended(pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
return g.GetHistoricCandles(pair, a, start, end, interval)
func (g *Gateio) GetHistoricCandlesExtended(ctx context.Context, pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
return g.GetHistoricCandles(ctx, pair, a, start, end, interval)
}