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

@@ -53,17 +53,17 @@ type Gemini struct {
}
// GetSymbols returns all available symbols for trading
func (g *Gemini) GetSymbols() ([]string, error) {
func (g *Gemini) GetSymbols(ctx context.Context) ([]string, error) {
var symbols []string
path := fmt.Sprintf("/v%s/%s", geminiAPIVersion, geminiSymbols)
return symbols, g.SendHTTPRequest(exchange.RestSpot, path, &symbols)
return symbols, g.SendHTTPRequest(ctx, exchange.RestSpot, path, &symbols)
}
// GetTicker returns information about recent trading activity for the symbol
func (g *Gemini) GetTicker(currencyPair string) (TickerV2, error) {
func (g *Gemini) GetTicker(ctx context.Context, currencyPair string) (TickerV2, error) {
ticker := TickerV2{}
path := fmt.Sprintf("/v2/ticker/%s", currencyPair)
err := g.SendHTTPRequest(exchange.RestSpot, path, &ticker)
err := g.SendHTTPRequest(ctx, exchange.RestSpot, path, &ticker)
if err != nil {
return ticker, err
}
@@ -82,7 +82,7 @@ func (g *Gemini) GetTicker(currencyPair string) (TickerV2, error) {
//
// params - limit_bids or limit_asks [OPTIONAL] default 50, 0 returns all Values
// Type is an integer ie "params.Set("limit_asks", 30)"
func (g *Gemini) GetOrderbook(currencyPair string, params url.Values) (Orderbook, error) {
func (g *Gemini) GetOrderbook(ctx context.Context, currencyPair string, params url.Values) (Orderbook, error) {
path := common.EncodeURLValues(
fmt.Sprintf("/v%s/%s/%s",
geminiAPIVersion,
@@ -91,7 +91,7 @@ func (g *Gemini) GetOrderbook(currencyPair string, params url.Values) (Orderbook
params)
var orderbook Orderbook
return orderbook, g.SendHTTPRequest(exchange.RestSpot, path, &orderbook)
return orderbook, g.SendHTTPRequest(ctx, exchange.RestSpot, path, &orderbook)
}
// GetTrades return the trades that have executed since the specified timestamp.
@@ -103,7 +103,7 @@ func (g *Gemini) GetOrderbook(currencyPair string, params url.Values) (Orderbook
// limit_trades integer Optional. The maximum number of trades to return.
// include_breaks boolean Optional. Whether to display broken trades. False by
// default. Can be '1' or 'true' to activate
func (g *Gemini) GetTrades(currencyPair string, since, limit int64, includeBreaks bool) ([]Trade, error) {
func (g *Gemini) GetTrades(ctx context.Context, currencyPair string, since, limit int64, includeBreaks bool) ([]Trade, error) {
params := url.Values{}
if since > 0 {
params.Add("since", strconv.FormatInt(since, 10))
@@ -117,15 +117,15 @@ func (g *Gemini) GetTrades(currencyPair string, since, limit int64, includeBreak
path := common.EncodeURLValues(fmt.Sprintf("/v%s/%s/%s", geminiAPIVersion, geminiTrades, currencyPair), params)
var trades []Trade
return trades, g.SendHTTPRequest(exchange.RestSpot, path, &trades)
return trades, g.SendHTTPRequest(ctx, exchange.RestSpot, path, &trades)
}
// GetAuction returns auction information
func (g *Gemini) GetAuction(currencyPair string) (Auction, error) {
func (g *Gemini) GetAuction(ctx context.Context, currencyPair string) (Auction, error) {
path := fmt.Sprintf("/v%s/%s/%s", geminiAPIVersion, geminiAuction, currencyPair)
auction := Auction{}
return auction, g.SendHTTPRequest(exchange.RestSpot, path, &auction)
return auction, g.SendHTTPRequest(ctx, exchange.RestSpot, path, &auction)
}
// GetAuctionHistory returns the auction events, optionally including
@@ -139,15 +139,15 @@ func (g *Gemini) GetAuction(currencyPair string) (Auction, error) {
// events to return.
// include_indicative - [bool] Whether to include publication of
// indicative prices and quantities.
func (g *Gemini) GetAuctionHistory(currencyPair string, params url.Values) ([]AuctionHistory, error) {
func (g *Gemini) GetAuctionHistory(ctx context.Context, currencyPair string, params url.Values) ([]AuctionHistory, error) {
path := common.EncodeURLValues(fmt.Sprintf("/v%s/%s/%s/%s", geminiAPIVersion, geminiAuction, currencyPair, geminiAuctionHistory), params)
var auctionHist []AuctionHistory
return auctionHist, g.SendHTTPRequest(exchange.RestSpot, path, &auctionHist)
return auctionHist, g.SendHTTPRequest(ctx, exchange.RestSpot, path, &auctionHist)
}
// NewOrder Only limit orders are supported through the API at present.
// returns order ID if successful
func (g *Gemini) NewOrder(symbol string, amount, price float64, side, orderType string) (int64, error) {
func (g *Gemini) NewOrder(ctx context.Context, symbol string, amount, price float64, side, orderType string) (int64, error) {
req := make(map[string]interface{})
req["symbol"] = symbol
req["amount"] = strconv.FormatFloat(amount, 'f', -1, 64)
@@ -156,7 +156,7 @@ func (g *Gemini) NewOrder(symbol string, amount, price float64, side, orderType
req["type"] = orderType
response := Order{}
err := g.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, geminiOrderNew, req, &response)
err := g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, geminiOrderNew, req, &response)
if err != nil {
return 0, err
}
@@ -165,12 +165,12 @@ func (g *Gemini) NewOrder(symbol string, amount, price float64, side, orderType
// CancelExistingOrder will cancel an order. If the order is already canceled, the
// message will succeed but have no effect.
func (g *Gemini) CancelExistingOrder(orderID int64) (Order, error) {
func (g *Gemini) CancelExistingOrder(ctx context.Context, orderID int64) (Order, error) {
req := make(map[string]interface{})
req["order_id"] = orderID
response := Order{}
err := g.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, geminiOrderCancel, req, &response)
err := g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, geminiOrderCancel, req, &response)
if err != nil {
return Order{}, err
}
@@ -185,14 +185,14 @@ func (g *Gemini) CancelExistingOrder(orderID int64) (Order, error) {
// sessions owned by this account, including interactive orders placed through
// the UI. If sessions = true will only cancel the order that is called on this
// session asssociated with the APIKEY
func (g *Gemini) CancelExistingOrders(cancelBySession bool) (OrderResult, error) {
func (g *Gemini) CancelExistingOrders(ctx context.Context, cancelBySession bool) (OrderResult, error) {
path := geminiOrderCancelAll
if cancelBySession {
path = geminiOrderCancelSession
}
var response OrderResult
err := g.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, path, nil, &response)
err := g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, path, nil, &response)
if err != nil {
return response, err
}
@@ -203,13 +203,13 @@ func (g *Gemini) CancelExistingOrders(cancelBySession bool) (OrderResult, error)
}
// GetOrderStatus returns the status for an order
func (g *Gemini) GetOrderStatus(orderID int64) (Order, error) {
func (g *Gemini) GetOrderStatus(ctx context.Context, orderID int64) (Order, error) {
req := make(map[string]interface{})
req["order_id"] = orderID
response := Order{}
err := g.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, geminiOrderStatus, req, &response)
err := g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, geminiOrderStatus, req, &response)
if err != nil {
return response, err
}
@@ -221,14 +221,14 @@ func (g *Gemini) GetOrderStatus(orderID int64) (Order, error) {
}
// GetOrders returns active orders in the market
func (g *Gemini) GetOrders() ([]Order, error) {
func (g *Gemini) GetOrders(ctx context.Context) ([]Order, error) {
var response interface{}
type orders struct {
orders []Order
}
err := g.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, geminiOrders, nil, &response)
err := g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, geminiOrders, nil, &response)
if err != nil {
return nil, err
}
@@ -245,7 +245,7 @@ func (g *Gemini) GetOrders() ([]Order, error) {
//
// currencyPair - example "btcusd"
// timestamp - [optional] Only return trades on or after this timestamp.
func (g *Gemini) GetTradeHistory(currencyPair string, timestamp int64) ([]TradeHistory, error) {
func (g *Gemini) GetTradeHistory(ctx context.Context, currencyPair string, timestamp int64) ([]TradeHistory, error) {
var response []TradeHistory
req := make(map[string]interface{})
req["symbol"] = currencyPair
@@ -255,35 +255,35 @@ func (g *Gemini) GetTradeHistory(currencyPair string, timestamp int64) ([]TradeH
}
return response,
g.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, geminiMyTrades, req, &response)
g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, geminiMyTrades, req, &response)
}
// GetNotionalVolume returns the volume in price currency that has been traded across all pairs over a period of 30 days
func (g *Gemini) GetNotionalVolume() (NotionalVolume, error) {
func (g *Gemini) GetNotionalVolume(ctx context.Context) (NotionalVolume, error) {
response := NotionalVolume{}
return response,
g.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, geminiVolume, nil, &response)
g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, geminiVolume, nil, &response)
}
// GetTradeVolume returns a multi-arrayed volume response
func (g *Gemini) GetTradeVolume() ([][]TradeVolume, error) {
func (g *Gemini) GetTradeVolume(ctx context.Context) ([][]TradeVolume, error) {
var response [][]TradeVolume
return response,
g.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, geminiTradeVolume, nil, &response)
g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, geminiTradeVolume, nil, &response)
}
// GetBalances returns available balances in the supported currencies
func (g *Gemini) GetBalances() ([]Balance, error) {
func (g *Gemini) GetBalances(ctx context.Context) ([]Balance, error) {
var response []Balance
return response,
g.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, geminiBalances, nil, &response)
g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, geminiBalances, nil, &response)
}
// GetCryptoDepositAddress returns a deposit address
func (g *Gemini) GetCryptoDepositAddress(depositAddlabel, currency string) (DepositAddress, error) {
func (g *Gemini) GetCryptoDepositAddress(ctx context.Context, depositAddlabel, currency string) (DepositAddress, error) {
response := DepositAddress{}
req := make(map[string]interface{})
@@ -291,7 +291,7 @@ func (g *Gemini) GetCryptoDepositAddress(depositAddlabel, currency string) (Depo
req["label"] = depositAddlabel
}
err := g.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, geminiDeposit+"/"+currency+"/"+geminiNewAddress, req, &response)
err := g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, geminiDeposit+"/"+currency+"/"+geminiNewAddress, req, &response)
if err != nil {
return response, err
}
@@ -302,13 +302,13 @@ func (g *Gemini) GetCryptoDepositAddress(depositAddlabel, currency string) (Depo
}
// WithdrawCrypto withdraws crypto currency to a whitelisted address
func (g *Gemini) WithdrawCrypto(address, currency string, amount float64) (WithdrawalAddress, error) {
func (g *Gemini) WithdrawCrypto(ctx context.Context, address, currency string, amount float64) (WithdrawalAddress, error) {
response := WithdrawalAddress{}
req := make(map[string]interface{})
req["address"] = address
req["amount"] = strconv.FormatFloat(amount, 'f', -1, 64)
err := g.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, geminiWithdraw+strings.ToLower(currency), req, &response)
err := g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, geminiWithdraw+strings.ToLower(currency), req, &response)
if err != nil {
return response, err
}
@@ -320,14 +320,14 @@ func (g *Gemini) WithdrawCrypto(address, currency string, amount float64) (Withd
// PostHeartbeat sends a maintenance heartbeat to the exchange for all heartbeat
// maintaned sessions
func (g *Gemini) PostHeartbeat() (string, error) {
func (g *Gemini) PostHeartbeat(ctx context.Context) (string, error) {
type Response struct {
Result string `json:"result"`
Message string `json:"message"`
}
response := Response{}
err := g.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, geminiHeartbeat, nil, &response)
err := g.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, geminiHeartbeat, nil, &response)
if err != nil {
return response.Result, err
}
@@ -338,7 +338,7 @@ func (g *Gemini) PostHeartbeat() (string, error) {
}
// SendHTTPRequest sends an unauthenticated request
func (g *Gemini) SendHTTPRequest(ep exchange.URL, path string, result interface{}) error {
func (g *Gemini) SendHTTPRequest(ctx context.Context, ep exchange.URL, path string, result interface{}) error {
endpoint, err := g.API.Endpoints.GetURL(ep)
if err != nil {
return err
@@ -353,14 +353,14 @@ func (g *Gemini) SendHTTPRequest(ep exchange.URL, path string, result interface{
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
})
}
// SendAuthenticatedHTTPRequest sends an authenticated HTTP request to the
// exchange and returns an error
func (g *Gemini) SendAuthenticatedHTTPRequest(ep exchange.URL, method, path string, params map[string]interface{}, result interface{}) (err error) {
func (g *Gemini) SendAuthenticatedHTTPRequest(ctx context.Context, ep exchange.URL, method, path string, params map[string]interface{}, result interface{}) (err error) {
if !g.AllowAuthenticatedRequest() {
return fmt.Errorf("%s %w", g.Name, exchange.ErrAuthenticatedRequestWithoutCredentialsSet)
}
@@ -370,7 +370,7 @@ func (g *Gemini) SendAuthenticatedHTTPRequest(ep exchange.URL, method, path stri
return err
}
return g.SendPayload(context.Background(), request.Auth, func() (*request.Item, error) {
return g.SendPayload(ctx, request.Auth, func() (*request.Item, error) {
req := make(map[string]interface{})
req["request"] = fmt.Sprintf("/v%s/%s", geminiAPIVersion, path)
req["nonce"] = g.Requester.GetNonce(true).String()
@@ -415,11 +415,11 @@ func (g *Gemini) SendAuthenticatedHTTPRequest(ep exchange.URL, method, path stri
}
// GetFee returns an estimate of fee based on type of transaction
func (g *Gemini) GetFee(feeBuilder *exchange.FeeBuilder) (float64, error) {
func (g *Gemini) GetFee(ctx context.Context, feeBuilder *exchange.FeeBuilder) (float64, error) {
var fee float64
switch feeBuilder.FeeType {
case exchange.CryptocurrencyTradeFee:
notionVolume, err := g.GetNotionalVolume()
notionVolume, err := g.GetNotionalVolume(ctx)
if err != nil {
return 0, err
}

View File

@@ -1,6 +1,7 @@
package gemini
import (
"context"
"net/url"
"strings"
"testing"
@@ -33,7 +34,7 @@ var g Gemini
func TestGetSymbols(t *testing.T) {
t.Parallel()
_, err := g.GetSymbols()
_, err := g.GetSymbols(context.Background())
if err != nil {
t.Error("GetSymbols() error", err)
}
@@ -41,7 +42,7 @@ func TestGetSymbols(t *testing.T) {
func TestFetchTradablePairs(t *testing.T) {
t.Parallel()
r, err := g.FetchTradablePairs(asset.Spot)
r, err := g.FetchTradablePairs(context.Background(), asset.Spot)
if err != nil {
t.Fatal(err)
}
@@ -62,11 +63,11 @@ func TestFetchTradablePairs(t *testing.T) {
func TestGetTicker(t *testing.T) {
t.Parallel()
_, err := g.GetTicker("BTCUSD")
_, err := g.GetTicker(context.Background(), "BTCUSD")
if err != nil {
t.Error("GetTicker() error", err)
}
_, err = g.GetTicker("bla")
_, err = g.GetTicker(context.Background(), "bla")
if err == nil {
t.Error("GetTicker() Expected error")
}
@@ -74,7 +75,7 @@ func TestGetTicker(t *testing.T) {
func TestGetOrderbook(t *testing.T) {
t.Parallel()
_, err := g.GetOrderbook(testCurrency, url.Values{})
_, err := g.GetOrderbook(context.Background(), testCurrency, url.Values{})
if err != nil {
t.Error("GetOrderbook() error", err)
}
@@ -82,7 +83,7 @@ func TestGetOrderbook(t *testing.T) {
func TestGetTrades(t *testing.T) {
t.Parallel()
_, err := g.GetTrades(testCurrency, 0, 0, false)
_, err := g.GetTrades(context.Background(), testCurrency, 0, 0, false)
if err != nil {
t.Error("GetTrades() error", err)
}
@@ -90,7 +91,7 @@ func TestGetTrades(t *testing.T) {
func TestGetNotionalVolume(t *testing.T) {
t.Parallel()
_, err := g.GetNotionalVolume()
_, err := g.GetNotionalVolume(context.Background())
if err != nil && mockTests {
t.Error("GetNotionalVolume() error", err)
} else if err == nil && !mockTests {
@@ -100,7 +101,7 @@ func TestGetNotionalVolume(t *testing.T) {
func TestGetAuction(t *testing.T) {
t.Parallel()
_, err := g.GetAuction(testCurrency)
_, err := g.GetAuction(context.Background(), testCurrency)
if err != nil {
t.Error("GetAuction() error", err)
}
@@ -108,7 +109,7 @@ func TestGetAuction(t *testing.T) {
func TestGetAuctionHistory(t *testing.T) {
t.Parallel()
_, err := g.GetAuctionHistory(testCurrency, url.Values{})
_, err := g.GetAuctionHistory(context.Background(), testCurrency, url.Values{})
if err != nil {
t.Error("GetAuctionHistory() error", err)
}
@@ -116,7 +117,8 @@ func TestGetAuctionHistory(t *testing.T) {
func TestNewOrder(t *testing.T) {
t.Parallel()
_, err := g.NewOrder(testCurrency,
_, err := g.NewOrder(context.Background(),
testCurrency,
1,
9000000,
order.Sell.Lower(),
@@ -130,7 +132,7 @@ func TestNewOrder(t *testing.T) {
func TestCancelExistingOrder(t *testing.T) {
t.Parallel()
_, err := g.CancelExistingOrder(265555413)
_, err := g.CancelExistingOrder(context.Background(), 265555413)
if err != nil && mockTests {
t.Error("CancelExistingOrder() error", err)
} else if err == nil && !mockTests {
@@ -140,7 +142,7 @@ func TestCancelExistingOrder(t *testing.T) {
func TestCancelExistingOrders(t *testing.T) {
t.Parallel()
_, err := g.CancelExistingOrders(false)
_, err := g.CancelExistingOrders(context.Background(), false)
if err != nil && mockTests {
t.Error("CancelExistingOrders() error", err)
} else if err == nil && !mockTests {
@@ -150,7 +152,7 @@ func TestCancelExistingOrders(t *testing.T) {
func TestGetOrderStatus(t *testing.T) {
t.Parallel()
_, err := g.GetOrderStatus(265563260)
_, err := g.GetOrderStatus(context.Background(), 265563260)
if err != nil && mockTests {
t.Error("GetOrderStatus() error", err)
} else if err == nil && !mockTests {
@@ -160,7 +162,7 @@ func TestGetOrderStatus(t *testing.T) {
func TestGetOrders(t *testing.T) {
t.Parallel()
_, err := g.GetOrders()
_, err := g.GetOrders(context.Background())
if err != nil && mockTests {
t.Error("GetOrders() error", err)
} else if err == nil && !mockTests {
@@ -170,7 +172,7 @@ func TestGetOrders(t *testing.T) {
func TestGetTradeHistory(t *testing.T) {
t.Parallel()
_, err := g.GetTradeHistory(testCurrency, 0)
_, err := g.GetTradeHistory(context.Background(), testCurrency, 0)
if err != nil && mockTests {
t.Error("GetTradeHistory() error", err)
} else if err == nil && !mockTests {
@@ -180,7 +182,7 @@ func TestGetTradeHistory(t *testing.T) {
func TestGetTradeVolume(t *testing.T) {
t.Parallel()
_, err := g.GetTradeVolume()
_, err := g.GetTradeVolume(context.Background())
if err != nil && mockTests {
t.Error("GetTradeVolume() error", err)
} else if err == nil && !mockTests {
@@ -190,7 +192,7 @@ func TestGetTradeVolume(t *testing.T) {
func TestGetBalances(t *testing.T) {
t.Parallel()
_, err := g.GetBalances()
_, err := g.GetBalances(context.Background())
if err != nil && mockTests {
t.Error("GetBalances() error", err)
} else if err == nil && !mockTests {
@@ -200,7 +202,7 @@ func TestGetBalances(t *testing.T) {
func TestGetCryptoDepositAddress(t *testing.T) {
t.Parallel()
_, err := g.GetCryptoDepositAddress("LOL123", "btc")
_, err := g.GetCryptoDepositAddress(context.Background(), "LOL123", "btc")
if err == nil {
t.Error("GetCryptoDepositAddress() Expected error")
}
@@ -208,7 +210,7 @@ func TestGetCryptoDepositAddress(t *testing.T) {
func TestWithdrawCrypto(t *testing.T) {
t.Parallel()
_, err := g.WithdrawCrypto("LOL123", "btc", 1)
_, err := g.WithdrawCrypto(context.Background(), "LOL123", "btc", 1)
if err == nil {
t.Error("WithdrawCrypto() Expected error")
}
@@ -216,7 +218,7 @@ func TestWithdrawCrypto(t *testing.T) {
func TestPostHeartbeat(t *testing.T) {
t.Parallel()
_, err := g.PostHeartbeat()
_, err := g.PostHeartbeat(context.Background())
if err != nil && mockTests {
t.Error("PostHeartbeat() error", err)
} else if err == nil && !mockTests {
@@ -241,7 +243,7 @@ func setFeeBuilder() *exchange.FeeBuilder {
func TestGetFeeByTypeOfflineTradeFee(t *testing.T) {
t.Parallel()
var feeBuilder = setFeeBuilder()
_, err := g.GetFeeByType(feeBuilder)
_, err := g.GetFeeByType(context.Background(), feeBuilder)
if err != nil {
t.Fatal(err)
}
@@ -265,7 +267,7 @@ func TestGetFee(t *testing.T) {
var feeBuilder = setFeeBuilder()
if areTestAPIKeysSet() || mockTests {
// CryptocurrencyTradeFee Basic
if _, err := g.GetFee(feeBuilder); err != nil {
if _, err := g.GetFee(context.Background(), feeBuilder); err != nil {
t.Error(err)
}
@@ -273,28 +275,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)
}
@@ -302,21 +304,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)
}
@@ -324,7 +326,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)
}
}
@@ -354,7 +356,7 @@ func TestGetActiveOrders(t *testing.T) {
AssetType: asset.Spot,
}
_, err := g.GetActiveOrders(&getOrdersRequest)
_, err := g.GetActiveOrders(context.Background(), &getOrdersRequest)
switch {
case areTestAPIKeysSet() && err != nil && !mockTests:
t.Errorf("Could not get open orders: %s", err)
@@ -373,7 +375,7 @@ func TestGetOrderHistory(t *testing.T) {
AssetType: asset.Spot,
}
_, err := g.GetOrderHistory(&getOrdersRequest)
_, err := g.GetOrderHistory(context.Background(), &getOrdersRequest)
switch {
case areTestAPIKeysSet() && err != nil:
t.Errorf("Could not get order history: %s", err)
@@ -410,7 +412,7 @@ func TestSubmitOrder(t *testing.T) {
AssetType: asset.Spot,
}
response, err := g.SubmitOrder(orderSubmission)
response, err := g.SubmitOrder(context.Background(), orderSubmission)
switch {
case areTestAPIKeysSet() && (err != nil || !response.IsOrderPlaced):
t.Errorf("Order failed to be placed: %v", err)
@@ -432,7 +434,7 @@ func TestCancelExchangeOrder(t *testing.T) {
Pair: currency.NewPair(currency.BTC, currency.USDT),
}
err := g.CancelOrder(orderCancellation)
err := g.CancelOrder(context.Background(), orderCancellation)
switch {
case !areTestAPIKeysSet() && err == nil && !mockTests:
t.Error("Expecting an error when no keys are set")
@@ -458,7 +460,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
AssetType: asset.Spot,
}
resp, err := g.CancelAllOrders(orderCancellation)
resp, err := g.CancelAllOrders(context.Background(), orderCancellation)
switch {
case !areTestAPIKeysSet() && err == nil && !mockTests:
t.Error("Expecting an error when no keys are set")
@@ -475,7 +477,8 @@ func TestCancelAllExchangeOrders(t *testing.T) {
func TestModifyOrder(t *testing.T) {
t.Parallel()
_, 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")
}
@@ -496,7 +499,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")
}
@@ -515,7 +519,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,
@@ -530,7 +534,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,
@@ -540,7 +545,7 @@ func TestWithdrawInternationalBank(t *testing.T) {
func TestGetDepositAddress(t *testing.T) {
t.Parallel()
_, err := g.GetDepositAddress(currency.BTC, "")
_, err := g.GetDepositAddress(context.Background(), currency.BTC, "")
if err == nil {
t.Error("GetDepositAddress error cannot be nil")
}
@@ -1176,7 +1181,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)
}
@@ -1194,7 +1199,8 @@ func TestGetHistoricTrades(t *testing.T) {
tStart = time.Date(time.Now().Year(), time.Now().Month(), 1, 0, 0, 0, 0, time.UTC)
tEnd = time.Date(time.Now().Year(), time.Now().Month(), 1, 0, 15, 0, 0, time.UTC)
}
_, err = g.GetHistoricTrades(currencyPair, asset.Spot, tStart, tEnd)
_, err = g.GetHistoricTrades(context.Background(),
currencyPair, asset.Spot, tStart, tEnd)
if err != nil {
t.Error(err)
}

View File

@@ -1,6 +1,7 @@
package gemini
import (
"context"
"errors"
"fmt"
"net/url"
@@ -42,7 +43,7 @@ func (g *Gemini) 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
}
@@ -256,7 +257,7 @@ func (g *Gemini) Run() {
if !g.GetEnabledFeatures().AutoPairUpdates && !forceUpdate {
return
}
err = g.UpdateTradablePairs(forceUpdate)
err = g.UpdateTradablePairs(context.TODO(), forceUpdate)
if err != nil {
log.Errorf(log.ExchangeSys,
"%s failed to update tradable pairs. Err: %s",
@@ -266,8 +267,8 @@ func (g *Gemini) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (g *Gemini) FetchTradablePairs(asset asset.Item) ([]string, error) {
pairs, err := g.GetSymbols()
func (g *Gemini) FetchTradablePairs(ctx context.Context, asset asset.Item) ([]string, error) {
pairs, err := g.GetSymbols(ctx)
if err != nil {
return nil, err
}
@@ -288,8 +289,8 @@ func (g *Gemini) FetchTradablePairs(asset asset.Item) ([]string, error) {
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (g *Gemini) UpdateTradablePairs(forceUpdate bool) error {
pairs, err := g.FetchTradablePairs(asset.Spot)
func (g *Gemini) UpdateTradablePairs(ctx context.Context, forceUpdate bool) error {
pairs, err := g.FetchTradablePairs(ctx, asset.Spot)
if err != nil {
return err
}
@@ -304,10 +305,10 @@ func (g *Gemini) UpdateTradablePairs(forceUpdate bool) error {
// UpdateAccountInfo Retrieves balances for all enabled currencies for the
// Gemini exchange
func (g *Gemini) UpdateAccountInfo(assetType asset.Item) (account.Holdings, error) {
func (g *Gemini) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (account.Holdings, error) {
var response account.Holdings
response.Exchange = g.Name
accountBalance, err := g.GetBalances()
accountBalance, err := g.GetBalances(ctx)
if err != nil {
return response, err
}
@@ -334,28 +335,28 @@ func (g *Gemini) UpdateAccountInfo(assetType asset.Item) (account.Holdings, erro
}
// FetchAccountInfo retrieves balances for all enabled currencies
func (g *Gemini) FetchAccountInfo(assetType asset.Item) (account.Holdings, error) {
func (g *Gemini) 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
}
// UpdateTickers updates the ticker for all currency pairs of a given asset type
func (g *Gemini) UpdateTickers(a asset.Item) error {
func (g *Gemini) UpdateTickers(ctx context.Context, a asset.Item) error {
return common.ErrFunctionNotSupported
}
// UpdateTicker updates and returns the ticker for a currency pair
func (g *Gemini) UpdateTicker(p currency.Pair, a asset.Item) (*ticker.Price, error) {
func (g *Gemini) UpdateTicker(ctx context.Context, p currency.Pair, a asset.Item) (*ticker.Price, error) {
fPair, err := g.FormatExchangeCurrency(p, a)
if err != nil {
return nil, err
}
tick, err := g.GetTicker(fPair.String())
tick, err := g.GetTicker(ctx, fPair.String())
if err != nil {
return nil, err
}
@@ -378,7 +379,7 @@ func (g *Gemini) UpdateTicker(p currency.Pair, a asset.Item) (*ticker.Price, err
}
// FetchTicker returns the ticker for a currency pair
func (g *Gemini) FetchTicker(p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
func (g *Gemini) FetchTicker(ctx context.Context, p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
fPair, err := g.FormatExchangeCurrency(p, assetType)
if err != nil {
return nil, err
@@ -386,13 +387,13 @@ func (g *Gemini) FetchTicker(p currency.Pair, assetType asset.Item) (*ticker.Pri
tickerNew, err := ticker.GetTicker(g.Name, fPair, assetType)
if err != nil {
return g.UpdateTicker(fPair, assetType)
return g.UpdateTicker(ctx, fPair, assetType)
}
return tickerNew, nil
}
// FetchOrderbook returns orderbook base on the currency pair
func (g *Gemini) FetchOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
func (g *Gemini) FetchOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
fPair, err := g.FormatExchangeCurrency(p, assetType)
if err != nil {
return nil, err
@@ -400,13 +401,13 @@ func (g *Gemini) FetchOrderbook(p currency.Pair, assetType asset.Item) (*orderbo
ob, err := orderbook.Get(g.Name, fPair, assetType)
if err != nil {
return g.UpdateOrderbook(fPair, assetType)
return g.UpdateOrderbook(ctx, fPair, assetType)
}
return ob, nil
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (g *Gemini) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
func (g *Gemini) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
book := &orderbook.Base{
Exchange: g.Name,
Pair: p,
@@ -418,7 +419,7 @@ func (g *Gemini) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orderb
return book, err
}
orderbookNew, err := g.GetOrderbook(fPair.String(), url.Values{})
orderbookNew, err := g.GetOrderbook(ctx, fPair.String(), url.Values{})
if err != nil {
return book, err
}
@@ -443,22 +444,22 @@ func (g *Gemini) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orderb
// GetFundingHistory returns funding history, deposits and
// withdrawals
func (g *Gemini) GetFundingHistory() ([]exchange.FundHistory, error) {
func (g *Gemini) GetFundingHistory(ctx context.Context) ([]exchange.FundHistory, error) {
return nil, common.ErrFunctionNotSupported
}
// GetWithdrawalsHistory returns previous withdrawals data
func (g *Gemini) GetWithdrawalsHistory(c currency.Code) (resp []exchange.WithdrawalHistory, err error) {
func (g *Gemini) 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 *Gemini) GetRecentTrades(currencyPair currency.Pair, assetType asset.Item) ([]trade.Data, error) {
return g.GetHistoricTrades(currencyPair, assetType, time.Time{}, time.Time{})
func (g *Gemini) GetRecentTrades(ctx context.Context, pair currency.Pair, assetType asset.Item) ([]trade.Data, error) {
return g.GetHistoricTrades(ctx, pair, assetType, time.Time{}, time.Time{})
}
// GetHistoricTrades returns historic trade data within the timeframe provided
func (g *Gemini) GetHistoricTrades(p currency.Pair, assetType asset.Item, timestampStart, timestampEnd time.Time) ([]trade.Data, error) {
func (g *Gemini) GetHistoricTrades(ctx context.Context, p currency.Pair, assetType asset.Item, timestampStart, timestampEnd time.Time) ([]trade.Data, error) {
if err := common.StartEndTimeCheck(timestampStart, timestampEnd); err != nil && !errors.Is(err, common.ErrDateUnset) {
return nil, fmt.Errorf("invalid time range supplied. Start: %v End %v %w", timestampStart, timestampEnd, err)
}
@@ -473,7 +474,11 @@ func (g *Gemini) GetHistoricTrades(p currency.Pair, assetType asset.Item, timest
allTrades:
for {
var tradeData []Trade
tradeData, err = g.GetTrades(p.String(), ts.Unix(), int64(limit), false)
tradeData, err = g.GetTrades(ctx,
p.String(),
ts.Unix(),
int64(limit),
false)
if err != nil {
return nil, err
}
@@ -521,7 +526,7 @@ allTrades:
}
// SubmitOrder submits a new order
func (g *Gemini) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
func (g *Gemini) SubmitOrder(ctx context.Context, s *order.Submit) (order.SubmitResponse, error) {
var submitOrderResponse order.SubmitResponse
if err := s.Validate(); err != nil {
return submitOrderResponse, err
@@ -537,7 +542,8 @@ func (g *Gemini) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
return submitOrderResponse, err
}
response, err := g.NewOrder(fpair.String(),
response, err := g.NewOrder(ctx,
fpair.String(),
s.Amount,
s.Price,
s.Side.String(),
@@ -556,12 +562,12 @@ func (g *Gemini) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
// ModifyOrder will allow of changing orderbook placement and limit to
// market conversion
func (g *Gemini) ModifyOrder(action *order.Modify) (order.Modify, error) {
func (g *Gemini) 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 *Gemini) CancelOrder(o *order.Cancel) error {
func (g *Gemini) CancelOrder(ctx context.Context, o *order.Cancel) error {
if err := o.Validate(o.StandardCancel()); err != nil {
return err
}
@@ -571,21 +577,21 @@ func (g *Gemini) CancelOrder(o *order.Cancel) error {
return err
}
_, err = g.CancelExistingOrder(orderIDInt)
_, err = g.CancelExistingOrder(ctx, orderIDInt)
return err
}
// CancelBatchOrders cancels an orders by their corresponding ID numbers
func (g *Gemini) CancelBatchOrders(o []order.Cancel) (order.CancelBatchResponse, error) {
func (g *Gemini) 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 *Gemini) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
func (g *Gemini) CancelAllOrders(ctx context.Context, _ *order.Cancel) (order.CancelAllResponse, error) {
cancelAllOrdersResponse := order.CancelAllResponse{
Status: make(map[string]string),
}
resp, err := g.CancelExistingOrders(false)
resp, err := g.CancelExistingOrders(ctx, false)
if err != nil {
return cancelAllOrdersResponse, err
}
@@ -598,14 +604,14 @@ func (g *Gemini) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, erro
}
// GetOrderInfo returns order information based on order ID
func (g *Gemini) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
func (g *Gemini) GetOrderInfo(ctx context.Context, orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
var orderDetail order.Detail
return orderDetail, common.ErrNotYetImplemented
}
// GetDepositAddress returns a deposit address for a specified currency
func (g *Gemini) GetDepositAddress(cryptocurrency currency.Code, _ string) (string, error) {
addr, err := g.GetCryptoDepositAddress("", cryptocurrency.String())
func (g *Gemini) GetDepositAddress(ctx context.Context, cryptocurrency currency.Code, _ string) (string, error) {
addr, err := g.GetCryptoDepositAddress(ctx, "", cryptocurrency.String())
if err != nil {
return "", err
}
@@ -614,11 +620,14 @@ func (g *Gemini) GetDepositAddress(cryptocurrency currency.Code, _ string) (stri
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
// submitted
func (g *Gemini) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
func (g *Gemini) WithdrawCryptocurrencyFunds(ctx context.Context, withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
if err := withdrawRequest.Validate(); err != nil {
return nil, err
}
resp, err := g.WithdrawCrypto(withdrawRequest.Crypto.Address, withdrawRequest.Currency.String(), withdrawRequest.Amount)
resp, err := g.WithdrawCrypto(ctx,
withdrawRequest.Crypto.Address,
withdrawRequest.Currency.String(),
withdrawRequest.Amount)
if err != nil {
return nil, err
}
@@ -633,32 +642,32 @@ func (g *Gemini) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request)
// WithdrawFiatFunds returns a withdrawal ID when a
// withdrawal is submitted
func (g *Gemini) WithdrawFiatFunds(_ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
func (g *Gemini) WithdrawFiatFunds(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
return nil, common.ErrFunctionNotSupported
}
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
// withdrawal is submitted
func (g *Gemini) WithdrawFiatFundsToInternationalBank(_ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
func (g *Gemini) 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 *Gemini) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error) {
func (g *Gemini) GetFeeByType(ctx context.Context, feeBuilder *exchange.FeeBuilder) (float64, error) {
if (!g.AllowAuthenticatedRequest() || g.SkipAuthCheck) && // 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 *Gemini) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
func (g *Gemini) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequest) ([]order.Detail, error) {
if err := req.Validate(); err != nil {
return nil, err
}
resp, err := g.GetOrders()
resp, err := g.GetOrders(ctx)
if err != nil {
return nil, err
}
@@ -713,7 +722,7 @@ func (g *Gemini) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, e
// GetOrderHistory retrieves account order information
// Can Limit response to specific order status
func (g *Gemini) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
func (g *Gemini) GetOrderHistory(ctx context.Context, req *order.GetOrdersRequest) ([]order.Detail, error) {
if err := req.Validate(); err != nil {
return nil, err
}
@@ -729,7 +738,9 @@ func (g *Gemini) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, e
return nil, err
}
resp, err := g.GetTradeHistory(fpair.String(), req.StartTime.Unix())
resp, err := g.GetTradeHistory(ctx,
fpair.String(),
req.StartTime.Unix())
if err != nil {
return nil, err
}
@@ -772,17 +783,17 @@ func (g *Gemini) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, e
// ValidateCredentials validates current credentials used for wrapper
// functionality
func (g *Gemini) ValidateCredentials(assetType asset.Item) error {
_, err := g.UpdateAccountInfo(assetType)
func (g *Gemini) ValidateCredentials(ctx context.Context, assetType asset.Item) error {
_, err := g.UpdateAccountInfo(ctx, assetType)
return g.CheckTransientError(err)
}
// GetHistoricCandles returns candles between a time period for a set time interval
func (g *Gemini) GetHistoricCandles(pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
func (g *Gemini) GetHistoricCandles(ctx context.Context, pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
return kline.Item{}, common.ErrFunctionNotSupported
}
// GetHistoricCandlesExtended returns candles between a time period for a set time interval
func (g *Gemini) GetHistoricCandlesExtended(pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
func (g *Gemini) GetHistoricCandlesExtended(ctx context.Context, pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
return kline.Item{}, common.ErrFunctionNotSupported
}