mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-08 15:11:07 +00:00
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:
@@ -77,27 +77,27 @@ const (
|
||||
)
|
||||
|
||||
// GetAllPairs gets all pairs on the exchange
|
||||
func (c *Coinbene) GetAllPairs() ([]PairData, error) {
|
||||
func (c *Coinbene) GetAllPairs(ctx context.Context) ([]PairData, error) {
|
||||
resp := struct {
|
||||
Data []PairData `json:"data"`
|
||||
}{}
|
||||
path := coinbeneAPIVersion + coinbeneGetAllPairs
|
||||
return resp.Data, c.SendHTTPRequest(exchange.RestSpot, path, spotPairs, &resp)
|
||||
return resp.Data, c.SendHTTPRequest(ctx, exchange.RestSpot, path, spotPairs, &resp)
|
||||
}
|
||||
|
||||
// GetPairInfo gets info about a single pair
|
||||
func (c *Coinbene) GetPairInfo(symbol string) (PairData, error) {
|
||||
func (c *Coinbene) GetPairInfo(ctx context.Context, symbol string) (PairData, error) {
|
||||
resp := struct {
|
||||
Data PairData `json:"data"`
|
||||
}{}
|
||||
params := url.Values{}
|
||||
params.Set("symbol", symbol)
|
||||
path := common.EncodeURLValues(coinbeneAPIVersion+coinbenePairInfo, params)
|
||||
return resp.Data, c.SendHTTPRequest(exchange.RestSpot, path, spotPairInfo, &resp)
|
||||
return resp.Data, c.SendHTTPRequest(ctx, exchange.RestSpot, path, spotPairInfo, &resp)
|
||||
}
|
||||
|
||||
// GetOrderbook gets and stores orderbook data for given pair
|
||||
func (c *Coinbene) GetOrderbook(symbol string, size int64) (Orderbook, error) {
|
||||
func (c *Coinbene) GetOrderbook(ctx context.Context, symbol string, size int64) (Orderbook, error) {
|
||||
resp := struct {
|
||||
Data struct {
|
||||
Asks [][]string `json:"asks"`
|
||||
@@ -110,7 +110,7 @@ func (c *Coinbene) GetOrderbook(symbol string, size int64) (Orderbook, error) {
|
||||
params.Set("symbol", symbol)
|
||||
params.Set("depth", strconv.FormatInt(size, 10))
|
||||
path := common.EncodeURLValues(coinbeneAPIVersion+coinbeneGetOrderBook, params)
|
||||
err := c.SendHTTPRequest(exchange.RestSpot, path, spotOrderbook, &resp)
|
||||
err := c.SendHTTPRequest(ctx, exchange.RestSpot, path, spotOrderbook, &resp)
|
||||
if err != nil {
|
||||
return Orderbook{}, err
|
||||
}
|
||||
@@ -149,28 +149,28 @@ func (c *Coinbene) GetOrderbook(symbol string, size int64) (Orderbook, error) {
|
||||
}
|
||||
|
||||
// GetTicker gets and stores ticker data for a currency pair
|
||||
func (c *Coinbene) GetTicker(symbol string) (TickerData, error) {
|
||||
func (c *Coinbene) GetTicker(ctx context.Context, symbol string) (TickerData, error) {
|
||||
resp := struct {
|
||||
TickerData TickerData `json:"data"`
|
||||
}{}
|
||||
params := url.Values{}
|
||||
params.Set("symbol", symbol)
|
||||
path := common.EncodeURLValues(coinbeneAPIVersion+coinbeneGetTicker, params)
|
||||
return resp.TickerData, c.SendHTTPRequest(exchange.RestSpot, path, spotSpecificTicker, &resp)
|
||||
return resp.TickerData, c.SendHTTPRequest(ctx, exchange.RestSpot, path, spotSpecificTicker, &resp)
|
||||
}
|
||||
|
||||
// GetTickers gets and all spot tickers supported by the exchange
|
||||
func (c *Coinbene) GetTickers() ([]TickerData, error) {
|
||||
func (c *Coinbene) GetTickers(ctx context.Context) ([]TickerData, error) {
|
||||
resp := struct {
|
||||
TickerData []TickerData `json:"data"`
|
||||
}{}
|
||||
|
||||
path := coinbeneAPIVersion + coinbeneGetTickersSpot
|
||||
return resp.TickerData, c.SendHTTPRequest(exchange.RestSpot, path, spotTickerList, &resp)
|
||||
return resp.TickerData, c.SendHTTPRequest(ctx, exchange.RestSpot, path, spotTickerList, &resp)
|
||||
}
|
||||
|
||||
// GetTrades gets recent trades from the exchange
|
||||
func (c *Coinbene) GetTrades(symbol string, limit int64) (Trades, error) {
|
||||
func (c *Coinbene) GetTrades(ctx context.Context, symbol string, limit int64) (Trades, error) {
|
||||
resp := struct {
|
||||
Data [][]string `json:"data"`
|
||||
}{}
|
||||
@@ -179,7 +179,7 @@ func (c *Coinbene) GetTrades(symbol string, limit int64) (Trades, error) {
|
||||
params.Set("symbol", symbol)
|
||||
params.Set("limit", strconv.FormatInt(limit, 10))
|
||||
path := common.EncodeURLValues(coinbeneAPIVersion+coinbeneGetTrades, params)
|
||||
err := c.SendHTTPRequest(exchange.RestSpot, path, spotMarketTrades, &resp)
|
||||
err := c.SendHTTPRequest(ctx, exchange.RestSpot, path, spotMarketTrades, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -210,12 +210,12 @@ func (c *Coinbene) GetTrades(symbol string, limit int64) (Trades, error) {
|
||||
}
|
||||
|
||||
// GetAccountBalances gets user balanace info
|
||||
func (c *Coinbene) GetAccountBalances() ([]UserBalanceData, error) {
|
||||
func (c *Coinbene) GetAccountBalances(ctx context.Context) ([]UserBalanceData, error) {
|
||||
resp := struct {
|
||||
Data []UserBalanceData `json:"data"`
|
||||
}{}
|
||||
path := coinbeneAPIVersion + coinbeneGetUserBalance
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
err := c.SendAuthHTTPRequest(ctx, exchange.RestSpot, http.MethodGet,
|
||||
path,
|
||||
coinbeneGetUserBalance,
|
||||
false,
|
||||
@@ -229,14 +229,16 @@ func (c *Coinbene) GetAccountBalances() ([]UserBalanceData, error) {
|
||||
}
|
||||
|
||||
// GetAccountAssetBalance gets user balanace info
|
||||
func (c *Coinbene) GetAccountAssetBalance(symbol string) (UserBalanceData, error) {
|
||||
func (c *Coinbene) GetAccountAssetBalance(ctx context.Context, symbol string) (UserBalanceData, error) {
|
||||
v := url.Values{}
|
||||
v.Set("asset", symbol)
|
||||
resp := struct {
|
||||
Data UserBalanceData `json:"data"`
|
||||
}{}
|
||||
path := coinbeneAPIVersion + coinbeneAccountBalanceOne
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
err := c.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSpot,
|
||||
http.MethodGet,
|
||||
path,
|
||||
coinbeneAccountBalanceOne,
|
||||
false,
|
||||
@@ -250,7 +252,7 @@ func (c *Coinbene) GetAccountAssetBalance(symbol string) (UserBalanceData, error
|
||||
}
|
||||
|
||||
// PlaceSpotOrder creates an order
|
||||
func (c *Coinbene) PlaceSpotOrder(price, quantity float64, symbol, direction,
|
||||
func (c *Coinbene) PlaceSpotOrder(ctx context.Context, price, quantity float64, symbol, direction,
|
||||
orderType, clientID string, notional int) (OrderPlacementResponse, error) {
|
||||
var resp OrderPlacementResponse
|
||||
params := url.Values{}
|
||||
@@ -291,7 +293,7 @@ func (c *Coinbene) PlaceSpotOrder(price, quantity float64, symbol, direction,
|
||||
params.Set("notional", strconv.Itoa(notional))
|
||||
}
|
||||
path := coinbeneAPIVersion + coinbenePlaceOrder
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
err := c.SendAuthHTTPRequest(ctx, exchange.RestSpot, http.MethodPost,
|
||||
path,
|
||||
coinbenePlaceOrder,
|
||||
false,
|
||||
@@ -305,7 +307,7 @@ func (c *Coinbene) PlaceSpotOrder(price, quantity float64, symbol, direction,
|
||||
}
|
||||
|
||||
// PlaceSpotOrders sets a batchful order request
|
||||
func (c *Coinbene) PlaceSpotOrders(orders []PlaceOrderRequest) ([]OrderPlacementResponse, error) {
|
||||
func (c *Coinbene) PlaceSpotOrders(ctx context.Context, orders []PlaceOrderRequest) ([]OrderPlacementResponse, error) {
|
||||
if len(orders) == 0 {
|
||||
return nil, errors.New("orders is nil")
|
||||
}
|
||||
@@ -361,7 +363,9 @@ func (c *Coinbene) PlaceSpotOrders(orders []PlaceOrderRequest) ([]OrderPlacement
|
||||
Data []OrderPlacementResponse `json:"data"`
|
||||
}{}
|
||||
path := coinbeneAPIVersion + coinbeneBatchPlaceOrder
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
err := c.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSpot,
|
||||
http.MethodPost,
|
||||
path,
|
||||
coinbeneBatchPlaceOrder,
|
||||
false,
|
||||
@@ -375,7 +379,7 @@ func (c *Coinbene) PlaceSpotOrders(orders []PlaceOrderRequest) ([]OrderPlacement
|
||||
}
|
||||
|
||||
// FetchOpenSpotOrders finds open orders
|
||||
func (c *Coinbene) FetchOpenSpotOrders(symbol string) (OrdersInfo, error) {
|
||||
func (c *Coinbene) FetchOpenSpotOrders(ctx context.Context, symbol string) (OrdersInfo, error) {
|
||||
params := url.Values{}
|
||||
params.Set("symbol", symbol)
|
||||
path := coinbeneAPIVersion + coinbeneOpenOrders
|
||||
@@ -385,7 +389,7 @@ func (c *Coinbene) FetchOpenSpotOrders(symbol string) (OrdersInfo, error) {
|
||||
Data OrdersInfo `json:"data"`
|
||||
}{}
|
||||
params.Set("pageNum", strconv.FormatInt(i, 10))
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
err := c.SendAuthHTTPRequest(ctx, exchange.RestSpot, http.MethodGet,
|
||||
path,
|
||||
coinbeneOpenOrders,
|
||||
false,
|
||||
@@ -407,7 +411,7 @@ func (c *Coinbene) FetchOpenSpotOrders(symbol string) (OrdersInfo, error) {
|
||||
}
|
||||
|
||||
// FetchClosedOrders finds open orders
|
||||
func (c *Coinbene) FetchClosedOrders(symbol, latestID string) (OrdersInfo, error) {
|
||||
func (c *Coinbene) FetchClosedOrders(ctx context.Context, symbol, latestID string) (OrdersInfo, error) {
|
||||
params := url.Values{}
|
||||
params.Set("symbol", symbol)
|
||||
params.Set("latestOrderId", latestID)
|
||||
@@ -418,7 +422,9 @@ func (c *Coinbene) FetchClosedOrders(symbol, latestID string) (OrdersInfo, error
|
||||
Data OrdersInfo `json:"data"`
|
||||
}{}
|
||||
params.Set("pageNum", strconv.FormatInt(i, 10))
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
err := c.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSpot,
|
||||
http.MethodGet,
|
||||
path,
|
||||
coinbeneClosedOrders,
|
||||
false,
|
||||
@@ -439,14 +445,16 @@ func (c *Coinbene) FetchClosedOrders(symbol, latestID string) (OrdersInfo, error
|
||||
}
|
||||
|
||||
// FetchSpotOrderInfo gets order info
|
||||
func (c *Coinbene) FetchSpotOrderInfo(orderID string) (OrderInfo, error) {
|
||||
func (c *Coinbene) FetchSpotOrderInfo(ctx context.Context, orderID string) (OrderInfo, error) {
|
||||
resp := struct {
|
||||
Data OrderInfo `json:"data"`
|
||||
}{}
|
||||
params := url.Values{}
|
||||
params.Set("orderId", orderID)
|
||||
path := coinbeneAPIVersion + coinbeneOrderInfo
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
err := c.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSpot,
|
||||
http.MethodGet,
|
||||
path,
|
||||
coinbeneOrderInfo,
|
||||
false,
|
||||
@@ -464,14 +472,16 @@ func (c *Coinbene) FetchSpotOrderInfo(orderID string) (OrderInfo, error) {
|
||||
}
|
||||
|
||||
// GetSpotOrderFills returns a list of fills related to an order ID
|
||||
func (c *Coinbene) GetSpotOrderFills(orderID string) ([]OrderFills, error) {
|
||||
func (c *Coinbene) GetSpotOrderFills(ctx context.Context, orderID string) ([]OrderFills, error) {
|
||||
resp := struct {
|
||||
Data []OrderFills `json:"data"`
|
||||
}{}
|
||||
params := url.Values{}
|
||||
params.Set("orderId", orderID)
|
||||
path := coinbeneAPIVersion + coinbeneTradeFills
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
err := c.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSpot,
|
||||
http.MethodGet,
|
||||
path,
|
||||
coinbeneTradeFills,
|
||||
false,
|
||||
@@ -485,14 +495,16 @@ func (c *Coinbene) GetSpotOrderFills(orderID string) ([]OrderFills, error) {
|
||||
}
|
||||
|
||||
// CancelSpotOrder removes a given order
|
||||
func (c *Coinbene) CancelSpotOrder(orderID string) (string, error) {
|
||||
func (c *Coinbene) CancelSpotOrder(ctx context.Context, orderID string) (string, error) {
|
||||
resp := struct {
|
||||
Data string `json:"data"`
|
||||
}{}
|
||||
req := make(map[string]interface{})
|
||||
req["orderId"] = orderID
|
||||
path := coinbeneAPIVersion + coinbeneCancelOrder
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
err := c.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSpot,
|
||||
http.MethodPost,
|
||||
path,
|
||||
coinbeneCancelOrder,
|
||||
false,
|
||||
@@ -506,7 +518,7 @@ func (c *Coinbene) CancelSpotOrder(orderID string) (string, error) {
|
||||
}
|
||||
|
||||
// CancelSpotOrders cancels a batch of orders
|
||||
func (c *Coinbene) CancelSpotOrders(orderIDs []string) ([]OrderCancellationResponse, error) {
|
||||
func (c *Coinbene) CancelSpotOrders(ctx context.Context, orderIDs []string) ([]OrderCancellationResponse, error) {
|
||||
req := make(map[string]interface{})
|
||||
req["orderIds"] = orderIDs
|
||||
type resp struct {
|
||||
@@ -515,7 +527,9 @@ func (c *Coinbene) CancelSpotOrders(orderIDs []string) ([]OrderCancellationRespo
|
||||
|
||||
var r resp
|
||||
path := coinbeneAPIVersion + coinbeneBatchCancel
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
err := c.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSpot,
|
||||
http.MethodPost,
|
||||
path,
|
||||
coinbeneBatchCancel,
|
||||
false,
|
||||
@@ -529,13 +543,13 @@ func (c *Coinbene) CancelSpotOrders(orderIDs []string) ([]OrderCancellationRespo
|
||||
}
|
||||
|
||||
// GetSwapTickers returns a map of swap tickers
|
||||
func (c *Coinbene) GetSwapTickers() (SwapTickers, error) {
|
||||
func (c *Coinbene) GetSwapTickers(ctx context.Context) (SwapTickers, error) {
|
||||
type resp struct {
|
||||
Data SwapTickers `json:"data"`
|
||||
}
|
||||
var r resp
|
||||
path := coinbeneAPIVersion + coinbeneGetTickers
|
||||
err := c.SendHTTPRequest(exchange.RestSwap, path, contractTickers, &r)
|
||||
err := c.SendHTTPRequest(ctx, exchange.RestSwap, path, contractTickers, &r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -543,8 +557,8 @@ func (c *Coinbene) GetSwapTickers() (SwapTickers, error) {
|
||||
}
|
||||
|
||||
// GetSwapTicker returns a specific swap ticker
|
||||
func (c *Coinbene) GetSwapTicker(symbol string) (SwapTicker, error) {
|
||||
tickers, err := c.GetSwapTickers()
|
||||
func (c *Coinbene) GetSwapTicker(ctx context.Context, symbol string) (SwapTicker, error) {
|
||||
tickers, err := c.GetSwapTickers(ctx)
|
||||
if err != nil {
|
||||
return SwapTicker{}, err
|
||||
}
|
||||
@@ -557,16 +571,20 @@ func (c *Coinbene) GetSwapTicker(symbol string) (SwapTicker, error) {
|
||||
}
|
||||
|
||||
// GetSwapInstruments returns a list of tradable instruments
|
||||
func (c *Coinbene) GetSwapInstruments() ([]Instrument, error) {
|
||||
func (c *Coinbene) GetSwapInstruments(ctx context.Context) ([]Instrument, error) {
|
||||
resp := struct {
|
||||
Data []Instrument `json:"data"`
|
||||
}{}
|
||||
return resp.Data, c.SendHTTPRequest(exchange.RestSwap,
|
||||
coinbeneAPIVersion+coinbeneGetInstruments, contractInstruments, &resp)
|
||||
return resp.Data,
|
||||
c.SendHTTPRequest(ctx,
|
||||
exchange.RestSwap,
|
||||
coinbeneAPIVersion+coinbeneGetInstruments,
|
||||
contractInstruments,
|
||||
&resp)
|
||||
}
|
||||
|
||||
// GetSwapOrderbook returns an orderbook for the specified currency
|
||||
func (c *Coinbene) GetSwapOrderbook(symbol string, size int64) (Orderbook, error) {
|
||||
func (c *Coinbene) GetSwapOrderbook(ctx context.Context, symbol string, size int64) (Orderbook, error) {
|
||||
var s Orderbook
|
||||
if symbol == "" {
|
||||
return s, fmt.Errorf("a symbol must be specified")
|
||||
@@ -589,7 +607,7 @@ func (c *Coinbene) GetSwapOrderbook(symbol string, size int64) (Orderbook, error
|
||||
|
||||
var r resp
|
||||
path := common.EncodeURLValues(coinbeneAPIVersion+coinbeneGetOrderBook, v)
|
||||
err := c.SendHTTPRequest(exchange.RestSwap, path, contractOrderbook, &r)
|
||||
err := c.SendHTTPRequest(ctx, exchange.RestSwap, path, contractOrderbook, &r)
|
||||
if err != nil {
|
||||
return s, err
|
||||
}
|
||||
@@ -633,7 +651,7 @@ func (c *Coinbene) GetSwapOrderbook(symbol string, size int64) (Orderbook, error
|
||||
}
|
||||
|
||||
// GetKlines data returns the kline data for a specific symbol
|
||||
func (c *Coinbene) GetKlines(pair string, start, end time.Time, period string) (resp CandleResponse, err error) {
|
||||
func (c *Coinbene) GetKlines(ctx context.Context, pair string, start, end time.Time, period string) (resp CandleResponse, err error) {
|
||||
v := url.Values{}
|
||||
v.Add("symbol", pair)
|
||||
if !start.IsZero() {
|
||||
@@ -645,7 +663,7 @@ func (c *Coinbene) GetKlines(pair string, start, end time.Time, period string) (
|
||||
v.Add("period", period)
|
||||
|
||||
path := common.EncodeURLValues(coinbeneAPIVersion+coinbeneSpotKlines, v)
|
||||
if err = c.SendHTTPRequest(exchange.RestSpot, path, contractKline, &resp); err != nil {
|
||||
if err = c.SendHTTPRequest(ctx, exchange.RestSpot, path, contractKline, &resp); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -657,7 +675,7 @@ func (c *Coinbene) GetKlines(pair string, start, end time.Time, period string) (
|
||||
}
|
||||
|
||||
// GetSwapKlines data returns the kline data for a specific symbol
|
||||
func (c *Coinbene) GetSwapKlines(symbol string, start, end time.Time, resolution string) (resp CandleResponse, err error) {
|
||||
func (c *Coinbene) GetSwapKlines(ctx context.Context, symbol string, start, end time.Time, resolution string) (resp CandleResponse, err error) {
|
||||
v := url.Values{}
|
||||
v.Set("symbol", symbol)
|
||||
if !start.IsZero() {
|
||||
@@ -669,7 +687,7 @@ func (c *Coinbene) GetSwapKlines(symbol string, start, end time.Time, resolution
|
||||
v.Set("resolution", resolution)
|
||||
|
||||
path := common.EncodeURLValues(coinbeneAPIVersion+coinbeneGetKlines, v)
|
||||
if err = c.SendHTTPRequest(exchange.RestSwap, path, contractKline, &resp); err != nil {
|
||||
if err = c.SendHTTPRequest(ctx, exchange.RestSwap, path, contractKline, &resp); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -677,7 +695,7 @@ func (c *Coinbene) GetSwapKlines(symbol string, start, end time.Time, resolution
|
||||
}
|
||||
|
||||
// GetSwapTrades returns a list of trades for a swap symbol
|
||||
func (c *Coinbene) GetSwapTrades(symbol string, limit int) (SwapTrades, error) {
|
||||
func (c *Coinbene) GetSwapTrades(ctx context.Context, symbol string, limit int) (SwapTrades, error) {
|
||||
v := url.Values{}
|
||||
v.Set("symbol", symbol)
|
||||
if limit != 0 {
|
||||
@@ -688,7 +706,7 @@ func (c *Coinbene) GetSwapTrades(symbol string, limit int) (SwapTrades, error) {
|
||||
}
|
||||
var r resp
|
||||
path := common.EncodeURLValues(coinbeneAPIVersion+coinbeneGetTrades, v)
|
||||
if err := c.SendHTTPRequest(exchange.RestSwap, path, contractTrades, &r); err != nil {
|
||||
if err := c.SendHTTPRequest(ctx, exchange.RestSwap, path, contractTrades, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -721,13 +739,13 @@ func (c *Coinbene) GetSwapTrades(symbol string, limit int) (SwapTrades, error) {
|
||||
}
|
||||
|
||||
// GetSwapAccountInfo returns a users swap account balance info
|
||||
func (c *Coinbene) GetSwapAccountInfo() (SwapAccountInfo, error) {
|
||||
func (c *Coinbene) GetSwapAccountInfo(ctx context.Context) (SwapAccountInfo, error) {
|
||||
type resp struct {
|
||||
Data SwapAccountInfo `json:"data"`
|
||||
}
|
||||
var r resp
|
||||
path := coinbeneAPIVersion + coinbeneAccountInfo
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSwap, http.MethodGet,
|
||||
err := c.SendAuthHTTPRequest(ctx, exchange.RestSwap, http.MethodGet,
|
||||
path,
|
||||
coinbeneAccountInfo,
|
||||
true,
|
||||
@@ -741,7 +759,7 @@ func (c *Coinbene) GetSwapAccountInfo() (SwapAccountInfo, error) {
|
||||
}
|
||||
|
||||
// GetSwapPositions returns a list of open swap positions
|
||||
func (c *Coinbene) GetSwapPositions(symbol string) (SwapPositions, error) {
|
||||
func (c *Coinbene) GetSwapPositions(ctx context.Context, symbol string) (SwapPositions, error) {
|
||||
v := url.Values{}
|
||||
v.Set("symbol", symbol)
|
||||
type resp struct {
|
||||
@@ -749,7 +767,7 @@ func (c *Coinbene) GetSwapPositions(symbol string) (SwapPositions, error) {
|
||||
}
|
||||
var r resp
|
||||
path := coinbeneAPIVersion + coinbeneListSwapPositions
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSwap, http.MethodGet,
|
||||
err := c.SendAuthHTTPRequest(ctx, exchange.RestSwap, http.MethodGet,
|
||||
path,
|
||||
coinbeneListSwapPositions,
|
||||
true,
|
||||
@@ -763,7 +781,7 @@ func (c *Coinbene) GetSwapPositions(symbol string) (SwapPositions, error) {
|
||||
}
|
||||
|
||||
// PlaceSwapOrder places a swap order
|
||||
func (c *Coinbene) PlaceSwapOrder(symbol, direction, orderType, marginMode,
|
||||
func (c *Coinbene) PlaceSwapOrder(ctx context.Context, symbol, direction, orderType, marginMode,
|
||||
clientID string, price, quantity float64, leverage int) (SwapPlaceOrderResponse, error) {
|
||||
v := url.Values{}
|
||||
v.Set("symbol", symbol)
|
||||
@@ -804,7 +822,9 @@ func (c *Coinbene) PlaceSwapOrder(symbol, direction, orderType, marginMode,
|
||||
}
|
||||
var r resp
|
||||
path := coinbeneAPIVersion + coinbenePlaceOrder
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSwap, http.MethodPost,
|
||||
err := c.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSwap,
|
||||
http.MethodPost,
|
||||
path,
|
||||
coinbenePlaceOrder,
|
||||
true,
|
||||
@@ -818,7 +838,7 @@ func (c *Coinbene) PlaceSwapOrder(symbol, direction, orderType, marginMode,
|
||||
}
|
||||
|
||||
// CancelSwapOrder cancels a swap order
|
||||
func (c *Coinbene) CancelSwapOrder(orderID string) (string, error) {
|
||||
func (c *Coinbene) CancelSwapOrder(ctx context.Context, orderID string) (string, error) {
|
||||
params := make(map[string]interface{})
|
||||
params["orderId"] = orderID
|
||||
type resp struct {
|
||||
@@ -826,7 +846,7 @@ func (c *Coinbene) CancelSwapOrder(orderID string) (string, error) {
|
||||
}
|
||||
var r resp
|
||||
path := coinbeneAPIVersion + coinbeneCancelOrder
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSwap, http.MethodPost,
|
||||
err := c.SendAuthHTTPRequest(ctx, exchange.RestSwap, http.MethodPost,
|
||||
path,
|
||||
coinbeneCancelOrder,
|
||||
true,
|
||||
@@ -840,7 +860,7 @@ func (c *Coinbene) CancelSwapOrder(orderID string) (string, error) {
|
||||
}
|
||||
|
||||
// GetSwapOpenOrders gets a list of open swap orders
|
||||
func (c *Coinbene) GetSwapOpenOrders(symbol string, pageNum, pageSize int) (SwapOrders, error) {
|
||||
func (c *Coinbene) GetSwapOpenOrders(ctx context.Context, symbol string, pageNum, pageSize int) (SwapOrders, error) {
|
||||
v := url.Values{}
|
||||
v.Set("symbol", symbol)
|
||||
if pageNum != 0 {
|
||||
@@ -854,7 +874,9 @@ func (c *Coinbene) GetSwapOpenOrders(symbol string, pageNum, pageSize int) (Swap
|
||||
}
|
||||
var r resp
|
||||
path := coinbeneAPIVersion + coinbeneOpenOrders
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSwap, http.MethodGet,
|
||||
err := c.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSwap,
|
||||
http.MethodGet,
|
||||
path,
|
||||
coinbeneOpenOrders,
|
||||
true,
|
||||
@@ -868,7 +890,7 @@ func (c *Coinbene) GetSwapOpenOrders(symbol string, pageNum, pageSize int) (Swap
|
||||
}
|
||||
|
||||
// GetSwapOpenOrdersByPage gets a list of open orders by page
|
||||
func (c *Coinbene) GetSwapOpenOrdersByPage(symbol string, latestOrderID int64) (SwapOrders, error) {
|
||||
func (c *Coinbene) GetSwapOpenOrdersByPage(ctx context.Context, symbol string, latestOrderID int64) (SwapOrders, error) {
|
||||
v := url.Values{}
|
||||
if symbol != "" {
|
||||
v.Set("symbol", symbol)
|
||||
@@ -881,7 +903,9 @@ func (c *Coinbene) GetSwapOpenOrdersByPage(symbol string, latestOrderID int64) (
|
||||
}
|
||||
var r resp
|
||||
path := coinbeneAPIVersion + coinbeneOpenOrdersByPage
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSwap, http.MethodGet,
|
||||
err := c.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSwap,
|
||||
http.MethodGet,
|
||||
path,
|
||||
coinbeneOpenOrdersByPage,
|
||||
true,
|
||||
@@ -895,7 +919,7 @@ func (c *Coinbene) GetSwapOpenOrdersByPage(symbol string, latestOrderID int64) (
|
||||
}
|
||||
|
||||
// GetSwapOrderInfo gets order info for a specific order
|
||||
func (c *Coinbene) GetSwapOrderInfo(orderID string) (SwapOrder, error) {
|
||||
func (c *Coinbene) GetSwapOrderInfo(ctx context.Context, orderID string) (SwapOrder, error) {
|
||||
v := url.Values{}
|
||||
v.Set("orderId", orderID)
|
||||
type resp struct {
|
||||
@@ -903,7 +927,9 @@ func (c *Coinbene) GetSwapOrderInfo(orderID string) (SwapOrder, error) {
|
||||
}
|
||||
var r resp
|
||||
path := coinbeneAPIVersion + coinbeneOrderInfo
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSwap, http.MethodGet,
|
||||
err := c.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSwap,
|
||||
http.MethodGet,
|
||||
path,
|
||||
coinbeneOrderInfo,
|
||||
true,
|
||||
@@ -917,7 +943,7 @@ func (c *Coinbene) GetSwapOrderInfo(orderID string) (SwapOrder, error) {
|
||||
}
|
||||
|
||||
// GetSwapOrderHistory returns the swap order history for a given symbol
|
||||
func (c *Coinbene) GetSwapOrderHistory(beginTime, endTime, symbol string, pageNum,
|
||||
func (c *Coinbene) GetSwapOrderHistory(ctx context.Context, beginTime, endTime, symbol string, pageNum,
|
||||
pageSize int, direction, orderType string) (SwapOrders, error) {
|
||||
v := url.Values{}
|
||||
if beginTime != "" {
|
||||
@@ -946,7 +972,7 @@ func (c *Coinbene) GetSwapOrderHistory(beginTime, endTime, symbol string, pageNu
|
||||
|
||||
var r resp
|
||||
path := coinbeneAPIVersion + coinbeneClosedOrders
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSwap, http.MethodGet,
|
||||
err := c.SendAuthHTTPRequest(ctx, exchange.RestSwap, http.MethodGet,
|
||||
path,
|
||||
coinbeneClosedOrders,
|
||||
true,
|
||||
@@ -960,7 +986,7 @@ func (c *Coinbene) GetSwapOrderHistory(beginTime, endTime, symbol string, pageNu
|
||||
}
|
||||
|
||||
// GetSwapOrderHistoryByOrderID returns a list of historic orders based on user params
|
||||
func (c *Coinbene) GetSwapOrderHistoryByOrderID(beginTime, endTime, symbol, status string,
|
||||
func (c *Coinbene) GetSwapOrderHistoryByOrderID(ctx context.Context, beginTime, endTime, symbol, status string,
|
||||
latestOrderID int64) (SwapOrders, error) {
|
||||
v := url.Values{}
|
||||
if beginTime != "" {
|
||||
@@ -984,7 +1010,9 @@ func (c *Coinbene) GetSwapOrderHistoryByOrderID(beginTime, endTime, symbol, stat
|
||||
|
||||
var r resp
|
||||
path := coinbeneAPIVersion + coinbeneClosedOrdersByPage
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSwap, http.MethodGet,
|
||||
err := c.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSwap,
|
||||
http.MethodGet,
|
||||
path,
|
||||
coinbeneClosedOrdersByPage,
|
||||
true,
|
||||
@@ -998,7 +1026,7 @@ func (c *Coinbene) GetSwapOrderHistoryByOrderID(beginTime, endTime, symbol, stat
|
||||
}
|
||||
|
||||
// CancelSwapOrders cancels multiple swap order IDs
|
||||
func (c *Coinbene) CancelSwapOrders(orderIDs []string) ([]OrderCancellationResponse, error) {
|
||||
func (c *Coinbene) CancelSwapOrders(ctx context.Context, orderIDs []string) ([]OrderCancellationResponse, error) {
|
||||
if len(orderIDs) > 10 {
|
||||
return nil, errors.New("only 10 orderIDs are allowed at a time")
|
||||
}
|
||||
@@ -1010,7 +1038,9 @@ func (c *Coinbene) CancelSwapOrders(orderIDs []string) ([]OrderCancellationRespo
|
||||
|
||||
var r resp
|
||||
path := coinbeneAPIVersion + coinbeneBatchCancel
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSwap, http.MethodPost,
|
||||
err := c.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSwap,
|
||||
http.MethodPost,
|
||||
path,
|
||||
coinbeneBatchCancel,
|
||||
true,
|
||||
@@ -1024,7 +1054,7 @@ func (c *Coinbene) CancelSwapOrders(orderIDs []string) ([]OrderCancellationRespo
|
||||
}
|
||||
|
||||
// GetSwapOrderFills returns a list of swap order fills
|
||||
func (c *Coinbene) GetSwapOrderFills(symbol, orderID string, lastTradeID int64) (SwapOrderFills, error) {
|
||||
func (c *Coinbene) GetSwapOrderFills(ctx context.Context, symbol, orderID string, lastTradeID int64) (SwapOrderFills, error) {
|
||||
v := url.Values{}
|
||||
if symbol != "" {
|
||||
v.Set("symbol", symbol)
|
||||
@@ -1041,7 +1071,9 @@ func (c *Coinbene) GetSwapOrderFills(symbol, orderID string, lastTradeID int64)
|
||||
|
||||
var r resp
|
||||
path := coinbeneAPIVersion + coinbeneOrderFills
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSwap, http.MethodGet,
|
||||
err := c.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSwap,
|
||||
http.MethodGet,
|
||||
path,
|
||||
coinbeneOrderFills,
|
||||
true,
|
||||
@@ -1055,7 +1087,7 @@ func (c *Coinbene) GetSwapOrderFills(symbol, orderID string, lastTradeID int64)
|
||||
}
|
||||
|
||||
// GetSwapFundingRates returns a list of funding rates
|
||||
func (c *Coinbene) GetSwapFundingRates(pageNum, pageSize int) ([]SwapFundingRate, error) {
|
||||
func (c *Coinbene) GetSwapFundingRates(ctx context.Context, pageNum, pageSize int) ([]SwapFundingRate, error) {
|
||||
v := url.Values{}
|
||||
if pageNum != 0 {
|
||||
v.Set("pageNum", strconv.Itoa(pageNum))
|
||||
@@ -1069,7 +1101,9 @@ func (c *Coinbene) GetSwapFundingRates(pageNum, pageSize int) ([]SwapFundingRate
|
||||
|
||||
var r resp
|
||||
path := coinbeneAPIVersion + coinbenePositionFeeRate
|
||||
err := c.SendAuthHTTPRequest(exchange.RestSwap, http.MethodGet,
|
||||
err := c.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSwap,
|
||||
http.MethodGet,
|
||||
path,
|
||||
coinbenePositionFeeRate,
|
||||
true,
|
||||
@@ -1083,7 +1117,7 @@ func (c *Coinbene) GetSwapFundingRates(pageNum, pageSize int) ([]SwapFundingRate
|
||||
}
|
||||
|
||||
// SendHTTPRequest sends an unauthenticated HTTP request
|
||||
func (c *Coinbene) SendHTTPRequest(ep exchange.URL, path string, f request.EndpointLimit, result interface{}) error {
|
||||
func (c *Coinbene) SendHTTPRequest(ctx context.Context, ep exchange.URL, path string, f request.EndpointLimit, result interface{}) error {
|
||||
endpoint, err := c.API.Endpoints.GetURL(ep)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1098,7 +1132,7 @@ func (c *Coinbene) SendHTTPRequest(ep exchange.URL, path string, f request.Endpo
|
||||
HTTPDebugging: c.HTTPDebugging,
|
||||
HTTPRecording: c.HTTPRecording,
|
||||
}
|
||||
if err := c.SendPayload(context.Background(), f, func() (*request.Item, error) {
|
||||
if err := c.SendPayload(ctx, f, func() (*request.Item, error) {
|
||||
return item, nil
|
||||
}); err != nil {
|
||||
return err
|
||||
@@ -1117,7 +1151,7 @@ func (c *Coinbene) SendHTTPRequest(ep exchange.URL, path string, f request.Endpo
|
||||
}
|
||||
|
||||
// SendAuthHTTPRequest sends an authenticated HTTP request
|
||||
func (c *Coinbene) SendAuthHTTPRequest(ep exchange.URL, method, path, epPath string, isSwap bool,
|
||||
func (c *Coinbene) SendAuthHTTPRequest(ctx context.Context, ep exchange.URL, method, path, epPath string, isSwap bool,
|
||||
params, result interface{}, f request.EndpointLimit) error {
|
||||
if !c.AllowAuthenticatedRequest() {
|
||||
return fmt.Errorf("%s %w", c.Name, exchange.ErrAuthenticatedRequestWithoutCredentialsSet)
|
||||
@@ -1192,7 +1226,7 @@ func (c *Coinbene) SendAuthHTTPRequest(ep exchange.URL, method, path, epPath str
|
||||
}, nil
|
||||
}
|
||||
|
||||
if err := c.SendPayload(context.Background(), f, newRequest); err != nil {
|
||||
if err := c.SendPayload(ctx, f, newRequest); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package coinbene
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
@@ -55,7 +56,7 @@ func areTestAPIKeysSet() bool {
|
||||
|
||||
func TestGetAllPairs(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := c.GetAllPairs()
|
||||
_, err := c.GetAllPairs(context.Background())
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -63,7 +64,7 @@ func TestGetAllPairs(t *testing.T) {
|
||||
|
||||
func TestGetPairInfo(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := c.GetPairInfo(spotTestPair)
|
||||
_, err := c.GetPairInfo(context.Background(), spotTestPair)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -71,7 +72,7 @@ func TestGetPairInfo(t *testing.T) {
|
||||
|
||||
func TestGetOrderbook(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := c.GetOrderbook(spotTestPair, 100)
|
||||
_, err := c.GetOrderbook(context.Background(), spotTestPair, 100)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -79,7 +80,7 @@ func TestGetOrderbook(t *testing.T) {
|
||||
|
||||
func TestGetTicker(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := c.GetTicker(spotTestPair)
|
||||
_, err := c.GetTicker(context.Background(), spotTestPair)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -87,7 +88,7 @@ func TestGetTicker(t *testing.T) {
|
||||
|
||||
func TestGetTrades(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := c.GetTrades(spotTestPair, 100)
|
||||
_, err := c.GetTrades(context.Background(), spotTestPair, 100)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -98,7 +99,7 @@ func TestGetAcounntBalances(t *testing.T) {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip("API keys required but not set, skipping test")
|
||||
}
|
||||
_, err := c.GetAccountBalances()
|
||||
_, err := c.GetAccountBalances(context.Background())
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -109,7 +110,7 @@ func TestGetAccountAssetBalance(t *testing.T) {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip("API keys required but not set, skipping test")
|
||||
}
|
||||
_, err := c.GetAccountAssetBalance(currency.BTC.String())
|
||||
_, err := c.GetAccountAssetBalance(context.Background(), currency.BTC.String())
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -120,7 +121,7 @@ func TestPlaceOrder(t *testing.T) {
|
||||
if !areTestAPIKeysSet() || !canManipulateRealOrders {
|
||||
t.Skip("skipping test, either api keys or manipulaterealorders isnt set correctly")
|
||||
}
|
||||
_, err := c.PlaceSpotOrder(
|
||||
_, err := c.PlaceSpotOrder(context.Background(),
|
||||
1,
|
||||
1,
|
||||
spotTestPair,
|
||||
@@ -140,7 +141,7 @@ func TestPlaceOrders(t *testing.T) {
|
||||
t.Skip("skipping test, either api keys or manipulaterealorders isnt set correctly")
|
||||
}
|
||||
|
||||
_, err := c.PlaceSpotOrders(
|
||||
_, err := c.PlaceSpotOrders(context.Background(),
|
||||
[]PlaceOrderRequest{
|
||||
{
|
||||
1,
|
||||
@@ -162,7 +163,7 @@ func TestFetchOpenOrders(t *testing.T) {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip("API keys required but not set, skipping test")
|
||||
}
|
||||
_, err := c.FetchOpenSpotOrders(spotTestPair)
|
||||
_, err := c.FetchOpenSpotOrders(context.Background(), spotTestPair)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -173,7 +174,7 @@ func TestFetchClosedOrders(t *testing.T) {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip("API keys required but not set, skipping test")
|
||||
}
|
||||
_, err := c.FetchClosedOrders(spotTestPair, "")
|
||||
_, err := c.FetchClosedOrders(context.Background(), spotTestPair, "")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -184,7 +185,7 @@ func TestFetchOrderInfo(t *testing.T) {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip("API keys required but not set, skipping test")
|
||||
}
|
||||
_, err := c.FetchSpotOrderInfo("adfjashjgsag")
|
||||
_, err := c.FetchSpotOrderInfo(context.Background(), "adfjashjgsag")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -195,7 +196,7 @@ func TestGetSpotOrderFills(t *testing.T) {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip("API keys required but not set, skipping test")
|
||||
}
|
||||
_, err := c.GetSpotOrderFills("1912131427156307968")
|
||||
_, err := c.GetSpotOrderFills(context.Background(), "1912131427156307968")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -206,7 +207,7 @@ func TestCancelSpotOrder(t *testing.T) {
|
||||
if !areTestAPIKeysSet() || !canManipulateRealOrders {
|
||||
t.Skip("skipping test, either api keys or manipulaterealorders isnt set correctly")
|
||||
}
|
||||
_, err := c.CancelSpotOrder("adfjashjgsag")
|
||||
_, err := c.CancelSpotOrder(context.Background(), "adfjashjgsag")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -218,7 +219,8 @@ func TestCancelSpotOrders(t *testing.T) {
|
||||
t.Skip("skipping test, either api keys or manipulaterealorders isnt set correctly")
|
||||
}
|
||||
|
||||
_, err := c.CancelSpotOrders([]string{"578639816552972288", "578639902896914432"})
|
||||
_, err := c.CancelSpotOrders(context.Background(),
|
||||
[]string{"578639816552972288", "578639902896914432"})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -230,7 +232,7 @@ func TestUpdateTicker(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = c.UpdateTicker(cp, asset.Spot)
|
||||
_, err = c.UpdateTicker(context.Background(), cp, asset.Spot)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -238,7 +240,7 @@ func TestUpdateTicker(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = c.UpdateTicker(cp, asset.PerpetualSwap)
|
||||
_, err = c.UpdateTicker(context.Background(), cp, asset.PerpetualSwap)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -248,12 +250,12 @@ func TestUpdateTickers(t *testing.T) {
|
||||
// TODO: fix Coinbene rate limiting that will allow to uncomment the next line
|
||||
// and enable parallel testing
|
||||
// t.Parallel()
|
||||
err := c.UpdateTickers(asset.Spot)
|
||||
err := c.UpdateTickers(context.Background(), asset.Spot)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = c.UpdateTickers(asset.PerpetualSwap)
|
||||
err = c.UpdateTickers(context.Background(), asset.PerpetualSwap)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -264,7 +266,7 @@ func TestGetAccountInfo(t *testing.T) {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip("API keys required but not set, skipping test")
|
||||
}
|
||||
_, err := c.UpdateAccountInfo(asset.Spot)
|
||||
_, err := c.UpdateAccountInfo(context.Background(), asset.Spot)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -276,7 +278,7 @@ func TestUpdateOrderbook(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = c.UpdateOrderbook(cp, asset.Spot)
|
||||
_, err = c.UpdateOrderbook(context.Background(), cp, asset.Spot)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -284,7 +286,7 @@ func TestUpdateOrderbook(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = c.UpdateOrderbook(cp, asset.PerpetualSwap)
|
||||
_, err = c.UpdateOrderbook(context.Background(), cp, asset.PerpetualSwap)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -292,7 +294,7 @@ func TestUpdateOrderbook(t *testing.T) {
|
||||
|
||||
func TestGetSwapTickers(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := c.GetSwapTickers()
|
||||
_, err := c.GetSwapTickers(context.Background())
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -300,7 +302,7 @@ func TestGetSwapTickers(t *testing.T) {
|
||||
|
||||
func TestGetSwapTicker(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := c.GetSwapTicker(swapTestPair)
|
||||
_, err := c.GetSwapTicker(context.Background(), swapTestPair)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -308,7 +310,7 @@ func TestGetSwapTicker(t *testing.T) {
|
||||
|
||||
func TestGetSwapOrderbook(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := c.GetSwapOrderbook(swapTestPair, 100)
|
||||
_, err := c.GetSwapOrderbook(context.Background(), swapTestPair, 100)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -320,8 +322,11 @@ func TestGetKlines(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = c.GetKlines(p.String(),
|
||||
time.Now().Add(-time.Hour*1), time.Now(), "1")
|
||||
_, err = c.GetKlines(context.Background(),
|
||||
p.String(),
|
||||
time.Now().Add(-time.Hour*1),
|
||||
time.Now(),
|
||||
"1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -333,8 +338,11 @@ func TestGetSwapKlines(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = c.GetSwapKlines(p.String(),
|
||||
time.Now().Add(-time.Hour*1), time.Now(), "1")
|
||||
_, err = c.GetSwapKlines(context.Background(),
|
||||
p.String(),
|
||||
time.Now().Add(-time.Hour*1),
|
||||
time.Now(),
|
||||
"1")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -342,7 +350,7 @@ func TestGetSwapKlines(t *testing.T) {
|
||||
|
||||
func TestGetSwapTrades(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := c.GetSwapTrades(swapTestPair, 10)
|
||||
_, err := c.GetSwapTrades(context.Background(), swapTestPair, 10)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -350,7 +358,7 @@ func TestGetSwapTrades(t *testing.T) {
|
||||
|
||||
func TestGetSwapInstruments(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := c.GetSwapInstruments()
|
||||
_, err := c.GetSwapInstruments(context.Background())
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -361,7 +369,7 @@ func TestGetSwapAccountInfo(t *testing.T) {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip("API keys required but not set, skipping test")
|
||||
}
|
||||
_, err := c.GetSwapAccountInfo()
|
||||
_, err := c.GetSwapAccountInfo(context.Background())
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -372,7 +380,7 @@ func TestGetSwapPositions(t *testing.T) {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip("API keys required but not set, skipping test")
|
||||
}
|
||||
_, err := c.GetSwapPositions(swapTestPair)
|
||||
_, err := c.GetSwapPositions(context.Background(), swapTestPair)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -384,7 +392,8 @@ func TestPlaceSwapOrder(t *testing.T) {
|
||||
t.Skip("skipping test, either api keys or manipulaterealorders isnt set correctly")
|
||||
}
|
||||
|
||||
_, err := c.PlaceSwapOrder(swapTestPair,
|
||||
_, err := c.PlaceSwapOrder(context.Background(),
|
||||
swapTestPair,
|
||||
order.Buy.Lower(),
|
||||
"limit",
|
||||
"fixed",
|
||||
@@ -403,7 +412,7 @@ func TestCancelSwapOrder(t *testing.T) {
|
||||
t.Skip("skipping test, either api keys or manipulaterealorders isnt set correctly")
|
||||
}
|
||||
|
||||
_, err := c.CancelSwapOrder("1337")
|
||||
_, err := c.CancelSwapOrder(context.Background(), "1337")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -415,7 +424,7 @@ func TestGetOpenSwapOrders(t *testing.T) {
|
||||
t.Skip("skipping test, either api keys or manipulaterealorders isnt set correctly")
|
||||
}
|
||||
|
||||
_, err := c.GetSwapOpenOrders(swapTestPair, 0, 0)
|
||||
_, err := c.GetSwapOpenOrders(context.Background(), swapTestPair, 0, 0)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -427,7 +436,7 @@ func TestGetSwapOpenOrdersByPage(t *testing.T) {
|
||||
t.Skip("skipping test, either api keys or manipulaterealorders isnt set correctly")
|
||||
}
|
||||
|
||||
_, err := c.GetSwapOpenOrdersByPage(swapTestPair, 0)
|
||||
_, err := c.GetSwapOpenOrdersByPage(context.Background(), swapTestPair, 0)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -439,7 +448,7 @@ func TestGetSwapOrderInfo(t *testing.T) {
|
||||
t.Skip("skipping test, either api keys or manipulaterealorders isnt set correctly")
|
||||
}
|
||||
|
||||
_, err := c.GetSwapOrderInfo("1337")
|
||||
_, err := c.GetSwapOrderInfo(context.Background(), "1337")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -451,7 +460,8 @@ func TestGetSwapOrderHistory(t *testing.T) {
|
||||
t.Skip("skipping test, either api keys or manipulaterealorders isnt set correctly")
|
||||
}
|
||||
|
||||
_, err := c.GetSwapOrderHistory("", "", swapTestPair, 1, 10, "", "")
|
||||
_, err := c.GetSwapOrderHistory(context.Background(),
|
||||
"", "", swapTestPair, 1, 10, "", "")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -463,7 +473,8 @@ func TestGetSwapOrderHistoryByOrderID(t *testing.T) {
|
||||
t.Skip("skipping test, either api keys or manipulaterealorders isnt set correctly")
|
||||
}
|
||||
|
||||
_, err := c.GetSwapOrderHistoryByOrderID("", "", swapTestPair, "", 0)
|
||||
_, err := c.GetSwapOrderHistoryByOrderID(context.Background(),
|
||||
"", "", swapTestPair, "", 0)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -475,7 +486,8 @@ func TestCancelSwapOrders(t *testing.T) {
|
||||
t.Skip("skipping test, either api keys or manipulaterealorders isnt set correctly")
|
||||
}
|
||||
|
||||
_, err := c.CancelSwapOrders([]string{"578639816552972288", "578639902896914432"})
|
||||
_, err := c.CancelSwapOrders(context.Background(),
|
||||
[]string{"578639816552972288", "578639902896914432"})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -487,7 +499,8 @@ func TestGetSwapOrderFills(t *testing.T) {
|
||||
t.Skip("skipping test, either api keys or manipulaterealorders isnt set correctly")
|
||||
}
|
||||
|
||||
_, err := c.GetSwapOrderFills(swapTestPair, "5807143157122003", 580714315825905664)
|
||||
_, err := c.GetSwapOrderFills(context.Background(),
|
||||
swapTestPair, "5807143157122003", 580714315825905664)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -499,7 +512,7 @@ func TestGetSwapFundingRates(t *testing.T) {
|
||||
t.Skip("skipping test, either api keys or manipulaterealorders isnt set correctly")
|
||||
}
|
||||
|
||||
_, err := c.GetSwapFundingRates(1, 2)
|
||||
_, err := c.GetSwapFundingRates(context.Background(), 1, 2)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -648,7 +661,8 @@ func TestGetHistoricCandles(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
startTime := time.Now().Add(-time.Hour * 24)
|
||||
_, err = c.GetHistoricCandles(currencyPair, asset.Spot, startTime, time.Now(), kline.OneHour)
|
||||
_, err = c.GetHistoricCandles(context.Background(),
|
||||
currencyPair, asset.Spot, startTime, time.Now(), kline.OneHour)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -657,7 +671,8 @@ func TestGetHistoricCandles(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = c.GetHistoricCandles(currencyPairSwap, asset.PerpetualSwap, startTime, time.Now(), kline.OneHour)
|
||||
_, err = c.GetHistoricCandles(context.Background(),
|
||||
currencyPairSwap, asset.PerpetualSwap, startTime, time.Now(), kline.OneHour)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -669,7 +684,8 @@ func TestGetHistoricCandlesExtended(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
startTime := time.Now().Add(-time.Hour * 2)
|
||||
_, err = c.GetHistoricCandlesExtended(currencyPair, asset.Spot, startTime, time.Now(), kline.OneHour)
|
||||
_, err = c.GetHistoricCandlesExtended(context.Background(),
|
||||
currencyPair, asset.Spot, startTime, time.Now(), kline.OneHour)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -780,7 +796,7 @@ func TestGetRecentTrades(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = c.GetRecentTrades(currencyPair, asset.Spot)
|
||||
_, err = c.GetRecentTrades(context.Background(), currencyPair, asset.Spot)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -792,7 +808,8 @@ func TestGetHistoricTrades(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = c.GetHistoricTrades(currencyPair, asset.Spot, time.Now().Add(-time.Minute*15), time.Now())
|
||||
_, err = c.GetHistoricTrades(context.Background(),
|
||||
currencyPair, asset.Spot, time.Now().Add(-time.Minute*15), time.Now())
|
||||
if err != nil && err != common.ErrFunctionNotSupported {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package coinbene
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
@@ -41,7 +42,7 @@ func (c *Coinbene) GetDefaultConfig() (*config.ExchangeConfig, error) {
|
||||
}
|
||||
|
||||
if c.Features.Supports.RESTCapabilities.AutoPairUpdates {
|
||||
err = c.UpdateTradablePairs(true)
|
||||
err = c.UpdateTradablePairs(context.TODO(), true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -231,7 +232,7 @@ func (c *Coinbene) Run() {
|
||||
return
|
||||
}
|
||||
|
||||
err := c.UpdateTradablePairs(false)
|
||||
err := c.UpdateTradablePairs(context.TODO(), false)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s Failed to update tradable pairs. Error: %s",
|
||||
@@ -241,7 +242,7 @@ func (c *Coinbene) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of exchange tradable pairs
|
||||
func (c *Coinbene) FetchTradablePairs(a asset.Item) ([]string, error) {
|
||||
func (c *Coinbene) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string, error) {
|
||||
if !c.SupportsAsset(a) {
|
||||
return nil, fmt.Errorf("%s does not support asset type %s", c.Name, a)
|
||||
}
|
||||
@@ -249,7 +250,7 @@ func (c *Coinbene) FetchTradablePairs(a asset.Item) ([]string, error) {
|
||||
var currencies []string
|
||||
switch a {
|
||||
case asset.Spot:
|
||||
pairs, err := c.GetAllPairs()
|
||||
pairs, err := c.GetAllPairs(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -258,7 +259,7 @@ func (c *Coinbene) FetchTradablePairs(a asset.Item) ([]string, error) {
|
||||
currencies = append(currencies, pairs[x].Symbol)
|
||||
}
|
||||
case asset.PerpetualSwap:
|
||||
instruments, err := c.GetSwapInstruments()
|
||||
instruments, err := c.GetSwapInstruments(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -276,10 +277,10 @@ func (c *Coinbene) FetchTradablePairs(a asset.Item) ([]string, error) {
|
||||
|
||||
// UpdateTradablePairs updates the exchanges available pairs and stores
|
||||
// them
|
||||
func (c *Coinbene) UpdateTradablePairs(forceUpdate bool) error {
|
||||
func (c *Coinbene) UpdateTradablePairs(ctx context.Context, forceUpdate bool) error {
|
||||
assets := c.GetAssetTypes(false)
|
||||
for x := range assets {
|
||||
pairs, err := c.FetchTradablePairs(assets[x])
|
||||
pairs, err := c.FetchTradablePairs(ctx, assets[x])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -298,7 +299,7 @@ func (c *Coinbene) UpdateTradablePairs(forceUpdate bool) error {
|
||||
}
|
||||
|
||||
// UpdateTickers updates the ticker for all currency pairs of a given asset type
|
||||
func (c *Coinbene) UpdateTickers(a asset.Item) error {
|
||||
func (c *Coinbene) UpdateTickers(ctx context.Context, a asset.Item) error {
|
||||
if !c.SupportsAsset(a) {
|
||||
return fmt.Errorf("%s does not support asset type %s", c.Name, a)
|
||||
}
|
||||
@@ -310,7 +311,7 @@ func (c *Coinbene) UpdateTickers(a asset.Item) error {
|
||||
|
||||
switch a {
|
||||
case asset.Spot:
|
||||
tickers, err := c.GetTickers()
|
||||
tickers, err := c.GetTickers(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -341,7 +342,7 @@ func (c *Coinbene) UpdateTickers(a asset.Item) error {
|
||||
}
|
||||
}
|
||||
case asset.PerpetualSwap:
|
||||
tickers, err := c.GetSwapTickers()
|
||||
tickers, err := c.GetSwapTickers(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -380,8 +381,8 @@ func (c *Coinbene) UpdateTickers(a asset.Item) error {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (c *Coinbene) UpdateTicker(p currency.Pair, a asset.Item) (*ticker.Price, error) {
|
||||
err := c.UpdateTickers(a)
|
||||
func (c *Coinbene) UpdateTicker(ctx context.Context, p currency.Pair, a asset.Item) (*ticker.Price, error) {
|
||||
err := c.UpdateTickers(ctx, a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -389,7 +390,7 @@ func (c *Coinbene) UpdateTicker(p currency.Pair, a asset.Item) (*ticker.Price, e
|
||||
}
|
||||
|
||||
// FetchTicker returns the ticker for a currency pair
|
||||
func (c *Coinbene) FetchTicker(p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
|
||||
func (c *Coinbene) FetchTicker(ctx context.Context, p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
|
||||
if !c.SupportsAsset(assetType) {
|
||||
return nil,
|
||||
fmt.Errorf("%s does not support asset type %s", c.Name, assetType)
|
||||
@@ -397,13 +398,13 @@ func (c *Coinbene) FetchTicker(p currency.Pair, assetType asset.Item) (*ticker.P
|
||||
|
||||
tickerNew, err := ticker.GetTicker(c.Name, p, assetType)
|
||||
if err != nil {
|
||||
return c.UpdateTicker(p, assetType)
|
||||
return c.UpdateTicker(ctx, p, assetType)
|
||||
}
|
||||
return tickerNew, nil
|
||||
}
|
||||
|
||||
// FetchOrderbook returns orderbook base on the currency pair
|
||||
func (c *Coinbene) FetchOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
func (c *Coinbene) FetchOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
if !c.SupportsAsset(assetType) {
|
||||
return nil,
|
||||
fmt.Errorf("%s does not support asset type %s", c.Name, assetType)
|
||||
@@ -411,13 +412,13 @@ func (c *Coinbene) FetchOrderbook(p currency.Pair, assetType asset.Item) (*order
|
||||
|
||||
ob, err := orderbook.Get(c.Name, p, assetType)
|
||||
if err != nil {
|
||||
return c.UpdateOrderbook(p, assetType)
|
||||
return c.UpdateOrderbook(ctx, p, assetType)
|
||||
}
|
||||
return ob, nil
|
||||
}
|
||||
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func (c *Coinbene) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
func (c *Coinbene) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
book := &orderbook.Base{
|
||||
Exchange: c.Name,
|
||||
Pair: p,
|
||||
@@ -437,11 +438,13 @@ func (c *Coinbene) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orde
|
||||
var tempResp Orderbook
|
||||
switch assetType {
|
||||
case asset.Spot:
|
||||
tempResp, err = c.GetOrderbook(fpair.String(),
|
||||
tempResp, err = c.GetOrderbook(ctx,
|
||||
fpair.String(),
|
||||
100, // TO-DO: Update this once we support configurable orderbook depth
|
||||
)
|
||||
case asset.PerpetualSwap:
|
||||
tempResp, err = c.GetSwapOrderbook(fpair.String(),
|
||||
tempResp, err = c.GetSwapOrderbook(ctx,
|
||||
fpair.String(),
|
||||
100, // TO-DO: Update this once we support configurable orderbook depth
|
||||
)
|
||||
}
|
||||
@@ -477,9 +480,9 @@ func (c *Coinbene) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orde
|
||||
|
||||
// UpdateAccountInfo retrieves balances for all enabled currencies for the
|
||||
// Coinbene exchange
|
||||
func (c *Coinbene) UpdateAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
func (c *Coinbene) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (account.Holdings, error) {
|
||||
var info account.Holdings
|
||||
balance, err := c.GetAccountBalances()
|
||||
balance, err := c.GetAccountBalances(ctx)
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
@@ -507,10 +510,10 @@ func (c *Coinbene) UpdateAccountInfo(assetType asset.Item) (account.Holdings, er
|
||||
}
|
||||
|
||||
// FetchAccountInfo retrieves balances for all enabled currencies
|
||||
func (c *Coinbene) FetchAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
func (c *Coinbene) FetchAccountInfo(ctx context.Context, assetType asset.Item) (account.Holdings, error) {
|
||||
acc, err := account.GetHoldings(c.Name, assetType)
|
||||
if err != nil {
|
||||
return c.UpdateAccountInfo(assetType)
|
||||
return c.UpdateAccountInfo(ctx, assetType)
|
||||
}
|
||||
|
||||
return acc, nil
|
||||
@@ -518,24 +521,24 @@ func (c *Coinbene) FetchAccountInfo(assetType asset.Item) (account.Holdings, err
|
||||
|
||||
// GetFundingHistory returns funding history, deposits and
|
||||
// withdrawals
|
||||
func (c *Coinbene) GetFundingHistory() ([]exchange.FundHistory, error) {
|
||||
func (c *Coinbene) GetFundingHistory(ctx context.Context) ([]exchange.FundHistory, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetWithdrawalsHistory returns previous withdrawals data
|
||||
func (c *Coinbene) GetWithdrawalsHistory(cur currency.Code) (resp []exchange.WithdrawalHistory, err error) {
|
||||
func (c *Coinbene) GetWithdrawalsHistory(_ context.Context, _ currency.Code) (resp []exchange.WithdrawalHistory, err error) {
|
||||
return nil, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// GetRecentTrades returns the most recent trades for a currency and asset
|
||||
func (c *Coinbene) GetRecentTrades(p currency.Pair, assetType asset.Item) ([]trade.Data, error) {
|
||||
func (c *Coinbene) GetRecentTrades(ctx context.Context, p currency.Pair, assetType asset.Item) ([]trade.Data, error) {
|
||||
var err error
|
||||
p, err = c.FormatExchangeCurrency(p, assetType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var tradeData Trades
|
||||
tradeData, err = c.GetTrades(p.String(), 100)
|
||||
tradeData, err = c.GetTrades(ctx, p.String(), 100)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -566,12 +569,12 @@ func (c *Coinbene) GetRecentTrades(p currency.Pair, assetType asset.Item) ([]tra
|
||||
}
|
||||
|
||||
// GetHistoricTrades returns historic trade data within the timeframe provided
|
||||
func (c *Coinbene) GetHistoricTrades(_ currency.Pair, _ asset.Item, _, _ time.Time) ([]trade.Data, error) {
|
||||
func (c *Coinbene) GetHistoricTrades(_ context.Context, _ currency.Pair, _ asset.Item, _, _ time.Time) ([]trade.Data, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (c *Coinbene) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
func (c *Coinbene) SubmitOrder(ctx context.Context, s *order.Submit) (order.SubmitResponse, error) {
|
||||
var resp order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return resp, err
|
||||
@@ -588,7 +591,8 @@ func (c *Coinbene) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
return resp, err
|
||||
}
|
||||
|
||||
tempResp, err := c.PlaceSpotOrder(s.Price,
|
||||
tempResp, err := c.PlaceSpotOrder(ctx,
|
||||
s.Price,
|
||||
s.Amount,
|
||||
fpair.String(),
|
||||
s.Side.String(),
|
||||
@@ -605,26 +609,26 @@ func (c *Coinbene) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (c *Coinbene) ModifyOrder(action *order.Modify) (order.Modify, error) {
|
||||
func (c *Coinbene) 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 (c *Coinbene) CancelOrder(o *order.Cancel) error {
|
||||
func (c *Coinbene) CancelOrder(ctx context.Context, o *order.Cancel) error {
|
||||
if err := o.Validate(o.StandardCancel()); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := c.CancelSpotOrder(o.ID)
|
||||
_, err := c.CancelSpotOrder(ctx, o.ID)
|
||||
return err
|
||||
}
|
||||
|
||||
// CancelBatchOrders cancels an orders by their corresponding ID numbers
|
||||
func (c *Coinbene) CancelBatchOrders(o []order.Cancel) (order.CancelBatchResponse, error) {
|
||||
func (c *Coinbene) 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 (c *Coinbene) CancelAllOrders(orderCancellation *order.Cancel) (order.CancelAllResponse, error) {
|
||||
func (c *Coinbene) CancelAllOrders(ctx context.Context, orderCancellation *order.Cancel) (order.CancelAllResponse, error) {
|
||||
if err := orderCancellation.Validate(); err != nil {
|
||||
return order.CancelAllResponse{}, err
|
||||
}
|
||||
@@ -636,14 +640,14 @@ func (c *Coinbene) CancelAllOrders(orderCancellation *order.Cancel) (order.Cance
|
||||
return resp, err
|
||||
}
|
||||
|
||||
orders, err := c.FetchOpenSpotOrders(fpair.String())
|
||||
orders, err := c.FetchOpenSpotOrders(ctx, fpair.String())
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
|
||||
tempMap := make(map[string]string)
|
||||
for x := range orders {
|
||||
_, err := c.CancelSpotOrder(orders[x].OrderID)
|
||||
_, err := c.CancelSpotOrder(ctx, orders[x].OrderID)
|
||||
if err != nil {
|
||||
tempMap[orders[x].OrderID] = "Failed"
|
||||
} else {
|
||||
@@ -655,9 +659,9 @@ func (c *Coinbene) CancelAllOrders(orderCancellation *order.Cancel) (order.Cance
|
||||
}
|
||||
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (c *Coinbene) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
func (c *Coinbene) GetOrderInfo(ctx context.Context, orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
var resp order.Detail
|
||||
tempResp, err := c.FetchSpotOrderInfo(orderID)
|
||||
tempResp, err := c.FetchSpotOrderInfo(ctx, orderID)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -674,36 +678,36 @@ func (c *Coinbene) GetOrderInfo(orderID string, pair currency.Pair, assetType as
|
||||
}
|
||||
|
||||
// GetDepositAddress returns a deposit address for a specified currency
|
||||
func (c *Coinbene) GetDepositAddress(_ currency.Code, _ string) (string, error) {
|
||||
func (c *Coinbene) GetDepositAddress(_ context.Context, _ currency.Code, _ string) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (c *Coinbene) WithdrawCryptocurrencyFunds(_ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
func (c *Coinbene) WithdrawCryptocurrencyFunds(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (c *Coinbene) WithdrawFiatFunds(_ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
func (c *Coinbene) WithdrawFiatFunds(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (c *Coinbene) WithdrawFiatFundsToInternationalBank(_ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
func (c *Coinbene) WithdrawFiatFundsToInternationalBank(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (c *Coinbene) GetActiveOrders(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
func (c *Coinbene) GetActiveOrders(ctx context.Context, getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
if err := getOrdersRequest.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(getOrdersRequest.Pairs) == 0 {
|
||||
allPairs, err := c.GetAllPairs()
|
||||
allPairs, err := c.GetAllPairs(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -725,7 +729,7 @@ func (c *Coinbene) GetActiveOrders(getOrdersRequest *order.GetOrdersRequest) ([]
|
||||
}
|
||||
|
||||
var tempData OrdersInfo
|
||||
tempData, err = c.FetchOpenSpotOrders(fpair.String())
|
||||
tempData, err = c.FetchOpenSpotOrders(ctx, fpair.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -753,13 +757,13 @@ func (c *Coinbene) GetActiveOrders(getOrdersRequest *order.GetOrdersRequest) ([]
|
||||
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
func (c *Coinbene) GetOrderHistory(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
func (c *Coinbene) GetOrderHistory(ctx context.Context, getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
if err := getOrdersRequest.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(getOrdersRequest.Pairs) == 0 {
|
||||
allPairs, err := c.GetAllPairs()
|
||||
allPairs, err := c.GetAllPairs(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -782,7 +786,7 @@ func (c *Coinbene) GetOrderHistory(getOrdersRequest *order.GetOrdersRequest) ([]
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tempData, err = c.FetchClosedOrders(fpair.String(), "")
|
||||
tempData, err = c.FetchClosedOrders(ctx, fpair.String(), "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -809,13 +813,13 @@ func (c *Coinbene) GetOrderHistory(getOrdersRequest *order.GetOrdersRequest) ([]
|
||||
}
|
||||
|
||||
// GetFeeByType returns an estimate of fee based on the type of transaction
|
||||
func (c *Coinbene) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error) {
|
||||
func (c *Coinbene) GetFeeByType(ctx context.Context, feeBuilder *exchange.FeeBuilder) (float64, error) {
|
||||
fpair, err := c.FormatExchangeCurrency(feeBuilder.Pair, asset.Spot)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
tempData, err := c.GetPairInfo(fpair.String())
|
||||
tempData, err := c.GetPairInfo(ctx, fpair.String())
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -827,14 +831,14 @@ func (c *Coinbene) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error
|
||||
}
|
||||
|
||||
// AuthenticateWebsocket sends an authentication message to the websocket
|
||||
func (c *Coinbene) AuthenticateWebsocket() error {
|
||||
func (c *Coinbene) AuthenticateWebsocket(_ context.Context) error {
|
||||
return c.Login()
|
||||
}
|
||||
|
||||
// ValidateCredentials validates current credentials used for wrapper
|
||||
// functionality
|
||||
func (c *Coinbene) ValidateCredentials(assetType asset.Item) error {
|
||||
_, err := c.UpdateAccountInfo(assetType)
|
||||
func (c *Coinbene) ValidateCredentials(ctx context.Context, assetType asset.Item) error {
|
||||
_, err := c.UpdateAccountInfo(ctx, assetType)
|
||||
return c.CheckTransientError(err)
|
||||
}
|
||||
|
||||
@@ -855,7 +859,7 @@ func (c *Coinbene) FormatExchangeKlineInterval(in kline.Interval) string {
|
||||
}
|
||||
|
||||
// GetHistoricCandles returns candles between a time period for a set time interval
|
||||
func (c *Coinbene) GetHistoricCandles(pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
|
||||
func (c *Coinbene) GetHistoricCandles(ctx context.Context, pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
|
||||
if err := c.ValidateKline(pair, a, interval); err != nil {
|
||||
return kline.Item{}, err
|
||||
}
|
||||
@@ -867,11 +871,13 @@ func (c *Coinbene) GetHistoricCandles(pair currency.Pair, a asset.Item, start, e
|
||||
|
||||
var candles CandleResponse
|
||||
if a == asset.PerpetualSwap {
|
||||
candles, err = c.GetSwapKlines(formattedPair.String(),
|
||||
candles, err = c.GetSwapKlines(ctx,
|
||||
formattedPair.String(),
|
||||
start, end,
|
||||
c.FormatExchangeKlineInterval(interval))
|
||||
} else {
|
||||
candles, err = c.GetKlines(formattedPair.String(),
|
||||
candles, err = c.GetKlines(ctx,
|
||||
formattedPair.String(),
|
||||
start, end,
|
||||
c.FormatExchangeKlineInterval(interval))
|
||||
}
|
||||
@@ -946,6 +952,6 @@ func (c *Coinbene) GetHistoricCandles(pair currency.Pair, a asset.Item, start, e
|
||||
}
|
||||
|
||||
// GetHistoricCandlesExtended returns candles between a time period for a set time interval
|
||||
func (c *Coinbene) GetHistoricCandlesExtended(pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
|
||||
return c.GetHistoricCandles(pair, a, start, end, interval)
|
||||
func (c *Coinbene) GetHistoricCandlesExtended(ctx context.Context, pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
|
||||
return c.GetHistoricCandles(ctx, pair, a, start, end, interval)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user