mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-31 15:10:42 +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:
@@ -75,34 +75,39 @@ const (
|
||||
)
|
||||
|
||||
// GetInterestHistory gets interest history for currency/currencies provided
|
||||
func (b *Binance) GetInterestHistory() (MarginInfoData, error) {
|
||||
func (b *Binance) GetInterestHistory(ctx context.Context) (MarginInfoData, error) {
|
||||
var resp MarginInfoData
|
||||
if err := b.SendHTTPRequest(exchange.EdgeCase1, undocumentedInterestHistory, spotDefaultRate, &resp); err != nil {
|
||||
if err := b.SendHTTPRequest(ctx, exchange.EdgeCase1, undocumentedInterestHistory, spotDefaultRate, &resp); err != nil {
|
||||
return resp, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetCrossMarginInterestHistory gets cross-margin interest history for currency/currencies provided
|
||||
func (b *Binance) GetCrossMarginInterestHistory() (CrossMarginInterestData, error) {
|
||||
func (b *Binance) GetCrossMarginInterestHistory(ctx context.Context) (CrossMarginInterestData, error) {
|
||||
var resp CrossMarginInterestData
|
||||
if err := b.SendHTTPRequest(exchange.EdgeCase1, undocumentedCrossMarginInterestHistory, spotDefaultRate, &resp); err != nil {
|
||||
if err := b.SendHTTPRequest(ctx,
|
||||
exchange.EdgeCase1,
|
||||
undocumentedCrossMarginInterestHistory,
|
||||
spotDefaultRate, &resp); err != nil {
|
||||
return resp, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetMarginMarkets returns exchange information. Check binance_types for more information
|
||||
func (b *Binance) GetMarginMarkets() (PerpsExchangeInfo, error) {
|
||||
func (b *Binance) GetMarginMarkets(ctx context.Context) (PerpsExchangeInfo, error) {
|
||||
var resp PerpsExchangeInfo
|
||||
return resp, b.SendHTTPRequest(exchange.RestSpot, perpExchangeInfo, spotDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx,
|
||||
exchange.RestSpot, perpExchangeInfo, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetExchangeInfo returns exchange information. Check binance_types for more
|
||||
// information
|
||||
func (b *Binance) GetExchangeInfo() (ExchangeInfo, error) {
|
||||
func (b *Binance) GetExchangeInfo(ctx context.Context) (ExchangeInfo, error) {
|
||||
var resp ExchangeInfo
|
||||
return resp, b.SendHTTPRequest(exchange.RestSpotSupplementary, exchangeInfo, spotExchangeInfo, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary, exchangeInfo, spotExchangeInfo, &resp)
|
||||
}
|
||||
|
||||
// GetOrderBook returns full orderbook information
|
||||
@@ -110,7 +115,7 @@ func (b *Binance) GetExchangeInfo() (ExchangeInfo, error) {
|
||||
// OrderBookDataRequestParams contains the following members
|
||||
// symbol: string of currency pair
|
||||
// limit: returned limit amount
|
||||
func (b *Binance) GetOrderBook(obd OrderBookDataRequestParams) (OrderBook, error) {
|
||||
func (b *Binance) GetOrderBook(ctx context.Context, obd OrderBookDataRequestParams) (OrderBook, error) {
|
||||
var orderbook OrderBook
|
||||
if err := b.CheckLimit(obd.Limit); err != nil {
|
||||
return orderbook, err
|
||||
@@ -125,7 +130,10 @@ func (b *Binance) GetOrderBook(obd OrderBookDataRequestParams) (OrderBook, error
|
||||
params.Set("limit", fmt.Sprintf("%d", obd.Limit))
|
||||
|
||||
var resp OrderBookData
|
||||
if err := b.SendHTTPRequest(exchange.RestSpotSupplementary, orderBookDepth+"?"+params.Encode(), orderbookLimit(obd.Limit), &resp); err != nil {
|
||||
if err := b.SendHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary,
|
||||
orderBookDepth+"?"+params.Encode(),
|
||||
orderbookLimit(obd.Limit), &resp); err != nil {
|
||||
return orderbook, err
|
||||
}
|
||||
|
||||
@@ -169,7 +177,7 @@ func (b *Binance) GetOrderBook(obd OrderBookDataRequestParams) (OrderBook, error
|
||||
|
||||
// GetMostRecentTrades returns recent trade activity
|
||||
// limit: Up to 500 results returned
|
||||
func (b *Binance) GetMostRecentTrades(rtr RecentTradeRequestParams) ([]RecentTrade, error) {
|
||||
func (b *Binance) GetMostRecentTrades(ctx context.Context, rtr RecentTradeRequestParams) ([]RecentTrade, error) {
|
||||
var resp []RecentTrade
|
||||
|
||||
params := url.Values{}
|
||||
@@ -182,7 +190,8 @@ func (b *Binance) GetMostRecentTrades(rtr RecentTradeRequestParams) ([]RecentTra
|
||||
|
||||
path := recentTrades + "?" + params.Encode()
|
||||
|
||||
return resp, b.SendHTTPRequest(exchange.RestSpotSupplementary, path, spotDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary, path, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetHistoricalTrades returns historical trade activity
|
||||
@@ -190,7 +199,7 @@ func (b *Binance) GetMostRecentTrades(rtr RecentTradeRequestParams) ([]RecentTra
|
||||
// symbol: string of currency pair
|
||||
// limit: Optional. Default 500; max 1000.
|
||||
// fromID:
|
||||
func (b *Binance) GetHistoricalTrades(symbol string, limit int, fromID int64) ([]HistoricalTrade, error) {
|
||||
func (b *Binance) GetHistoricalTrades(ctx context.Context, symbol string, limit int, fromID int64) ([]HistoricalTrade, error) {
|
||||
var resp []HistoricalTrade
|
||||
params := url.Values{}
|
||||
|
||||
@@ -202,14 +211,15 @@ func (b *Binance) GetHistoricalTrades(symbol string, limit int, fromID int64) ([
|
||||
}
|
||||
|
||||
path := historicalTrades + "?" + params.Encode()
|
||||
return resp, b.SendAPIKeyHTTPRequest(exchange.RestSpotSupplementary, path, spotDefaultRate, &resp)
|
||||
return resp,
|
||||
b.SendAPIKeyHTTPRequest(ctx, exchange.RestSpotSupplementary, path, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetAggregatedTrades returns aggregated trade activity.
|
||||
// If more than one hour of data is requested or asked limit is not supported by exchange
|
||||
// then the trades are collected with multiple backend requests.
|
||||
// https://binance-docs.github.io/apidocs/spot/en/#compressed-aggregate-trades-list
|
||||
func (b *Binance) GetAggregatedTrades(arg *AggregatedTradeRequestParams) ([]AggregatedTrade, error) {
|
||||
func (b *Binance) GetAggregatedTrades(ctx context.Context, arg *AggregatedTradeRequestParams) ([]AggregatedTrade, error) {
|
||||
params := url.Values{}
|
||||
symbol, err := b.FormatSymbol(arg.Symbol, asset.Spot)
|
||||
if err != nil {
|
||||
@@ -245,7 +255,7 @@ func (b *Binance) GetAggregatedTrades(arg *AggregatedTradeRequestParams) ([]Aggr
|
||||
canBatch := arg.FromID == 0 != arg.StartTime.IsZero()
|
||||
if canBatch {
|
||||
// Split the request into multiple
|
||||
return b.batchAggregateTrades(arg, params)
|
||||
return b.batchAggregateTrades(ctx, arg, params)
|
||||
}
|
||||
|
||||
// Can't handle this request locally or remotely
|
||||
@@ -254,13 +264,14 @@ func (b *Binance) GetAggregatedTrades(arg *AggregatedTradeRequestParams) ([]Aggr
|
||||
}
|
||||
var resp []AggregatedTrade
|
||||
path := aggregatedTrades + "?" + params.Encode()
|
||||
return resp, b.SendHTTPRequest(exchange.RestSpotSupplementary, path, spotDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary, path, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// batchAggregateTrades fetches trades in multiple requests
|
||||
// first phase, hourly requests until the first trade (or end time) is reached
|
||||
// second phase, limit requests from previous trade until end time (or limit) is reached
|
||||
func (b *Binance) batchAggregateTrades(arg *AggregatedTradeRequestParams, params url.Values) ([]AggregatedTrade, error) {
|
||||
func (b *Binance) batchAggregateTrades(ctx context.Context, arg *AggregatedTradeRequestParams, params url.Values) ([]AggregatedTrade, error) {
|
||||
var resp []AggregatedTrade
|
||||
// prepare first request with only first hour and max limit
|
||||
if arg.Limit == 0 || arg.Limit > 1000 {
|
||||
@@ -283,7 +294,8 @@ func (b *Binance) batchAggregateTrades(arg *AggregatedTradeRequestParams, params
|
||||
params.Set("startTime", timeString(start))
|
||||
params.Set("endTime", timeString(start.Add(increment)))
|
||||
path := aggregatedTrades + "?" + params.Encode()
|
||||
err := b.SendHTTPRequest(exchange.RestSpotSupplementary, path, spotDefaultRate, &resp)
|
||||
err := b.SendHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary, path, spotDefaultRate, &resp)
|
||||
if err != nil {
|
||||
log.Warn(log.ExchangeSys, err.Error())
|
||||
return resp, err
|
||||
@@ -301,7 +313,11 @@ func (b *Binance) batchAggregateTrades(arg *AggregatedTradeRequestParams, params
|
||||
params.Set("fromId", strconv.FormatInt(fromID, 10))
|
||||
path := aggregatedTrades + "?" + params.Encode()
|
||||
var additionalTrades []AggregatedTrade
|
||||
err := b.SendHTTPRequest(exchange.RestSpotSupplementary, path, spotDefaultRate, &additionalTrades)
|
||||
err := b.SendHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary,
|
||||
path,
|
||||
spotDefaultRate,
|
||||
&additionalTrades)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -335,7 +351,7 @@ func (b *Binance) batchAggregateTrades(arg *AggregatedTradeRequestParams, params
|
||||
// interval: the interval time for the data
|
||||
// startTime: startTime filter for kline data
|
||||
// endTime: endTime filter for the kline data
|
||||
func (b *Binance) GetSpotKline(arg *KlinesRequestParams) ([]CandleStick, error) {
|
||||
func (b *Binance) GetSpotKline(ctx context.Context, arg *KlinesRequestParams) ([]CandleStick, error) {
|
||||
var resp interface{}
|
||||
var klineData []CandleStick
|
||||
|
||||
@@ -358,7 +374,11 @@ func (b *Binance) GetSpotKline(arg *KlinesRequestParams) ([]CandleStick, error)
|
||||
|
||||
path := candleStick + "?" + params.Encode()
|
||||
|
||||
if err := b.SendHTTPRequest(exchange.RestSpotSupplementary, path, spotDefaultRate, &resp); err != nil {
|
||||
if err := b.SendHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary,
|
||||
path,
|
||||
spotDefaultRate,
|
||||
&resp); err != nil {
|
||||
return klineData, err
|
||||
}
|
||||
|
||||
@@ -408,7 +428,7 @@ func (b *Binance) GetSpotKline(arg *KlinesRequestParams) ([]CandleStick, error)
|
||||
// GetAveragePrice returns current average price for a symbol.
|
||||
//
|
||||
// symbol: string of currency pair
|
||||
func (b *Binance) GetAveragePrice(symbol currency.Pair) (AveragePrice, error) {
|
||||
func (b *Binance) GetAveragePrice(ctx context.Context, symbol currency.Pair) (AveragePrice, error) {
|
||||
resp := AveragePrice{}
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.Spot)
|
||||
@@ -419,13 +439,14 @@ func (b *Binance) GetAveragePrice(symbol currency.Pair) (AveragePrice, error) {
|
||||
|
||||
path := averagePrice + "?" + params.Encode()
|
||||
|
||||
return resp, b.SendHTTPRequest(exchange.RestSpotSupplementary, path, spotDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary, path, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetPriceChangeStats returns price change statistics for the last 24 hours
|
||||
//
|
||||
// symbol: string of currency pair
|
||||
func (b *Binance) GetPriceChangeStats(symbol currency.Pair) (PriceChangeStats, error) {
|
||||
func (b *Binance) GetPriceChangeStats(ctx context.Context, symbol currency.Pair) (PriceChangeStats, error) {
|
||||
resp := PriceChangeStats{}
|
||||
params := url.Values{}
|
||||
rateLimit := spotPriceChangeAllRate
|
||||
@@ -439,19 +460,21 @@ func (b *Binance) GetPriceChangeStats(symbol currency.Pair) (PriceChangeStats, e
|
||||
}
|
||||
path := priceChange + "?" + params.Encode()
|
||||
|
||||
return resp, b.SendHTTPRequest(exchange.RestSpotSupplementary, path, rateLimit, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary, path, rateLimit, &resp)
|
||||
}
|
||||
|
||||
// GetTickers returns the ticker data for the last 24 hrs
|
||||
func (b *Binance) GetTickers() ([]PriceChangeStats, error) {
|
||||
func (b *Binance) GetTickers(ctx context.Context) ([]PriceChangeStats, error) {
|
||||
var resp []PriceChangeStats
|
||||
return resp, b.SendHTTPRequest(exchange.RestSpotSupplementary, priceChange, spotPriceChangeAllRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary, priceChange, spotPriceChangeAllRate, &resp)
|
||||
}
|
||||
|
||||
// GetLatestSpotPrice returns latest spot price of symbol
|
||||
//
|
||||
// symbol: string of currency pair
|
||||
func (b *Binance) GetLatestSpotPrice(symbol currency.Pair) (SymbolPrice, error) {
|
||||
func (b *Binance) GetLatestSpotPrice(ctx context.Context, symbol currency.Pair) (SymbolPrice, error) {
|
||||
resp := SymbolPrice{}
|
||||
params := url.Values{}
|
||||
rateLimit := spotSymbolPriceAllRate
|
||||
@@ -465,13 +488,14 @@ func (b *Binance) GetLatestSpotPrice(symbol currency.Pair) (SymbolPrice, error)
|
||||
}
|
||||
path := symbolPrice + "?" + params.Encode()
|
||||
|
||||
return resp, b.SendHTTPRequest(exchange.RestSpotSupplementary, path, rateLimit, &resp)
|
||||
return resp,
|
||||
b.SendHTTPRequest(ctx, exchange.RestSpotSupplementary, path, rateLimit, &resp)
|
||||
}
|
||||
|
||||
// GetBestPrice returns the latest best price for symbol
|
||||
//
|
||||
// symbol: string of currency pair
|
||||
func (b *Binance) GetBestPrice(symbol currency.Pair) (BestPrice, error) {
|
||||
func (b *Binance) GetBestPrice(ctx context.Context, symbol currency.Pair) (BestPrice, error) {
|
||||
resp := BestPrice{}
|
||||
params := url.Values{}
|
||||
rateLimit := spotOrderbookTickerAllRate
|
||||
@@ -485,13 +509,14 @@ func (b *Binance) GetBestPrice(symbol currency.Pair) (BestPrice, error) {
|
||||
}
|
||||
path := bestPrice + "?" + params.Encode()
|
||||
|
||||
return resp, b.SendHTTPRequest(exchange.RestSpotSupplementary, path, rateLimit, &resp)
|
||||
return resp,
|
||||
b.SendHTTPRequest(ctx, exchange.RestSpotSupplementary, path, rateLimit, &resp)
|
||||
}
|
||||
|
||||
// NewOrder sends a new order to Binance
|
||||
func (b *Binance) NewOrder(o *NewOrderRequest) (NewOrderResponse, error) {
|
||||
func (b *Binance) NewOrder(ctx context.Context, o *NewOrderRequest) (NewOrderResponse, error) {
|
||||
var resp NewOrderResponse
|
||||
if err := b.newOrder(orderEndpoint, o, &resp); err != nil {
|
||||
if err := b.newOrder(ctx, orderEndpoint, o, &resp); err != nil {
|
||||
return resp, err
|
||||
}
|
||||
|
||||
@@ -503,12 +528,12 @@ func (b *Binance) NewOrder(o *NewOrderRequest) (NewOrderResponse, error) {
|
||||
}
|
||||
|
||||
// NewOrderTest sends a new test order to Binance
|
||||
func (b *Binance) NewOrderTest(o *NewOrderRequest) error {
|
||||
func (b *Binance) NewOrderTest(ctx context.Context, o *NewOrderRequest) error {
|
||||
var resp NewOrderResponse
|
||||
return b.newOrder(newOrderTest, o, &resp)
|
||||
return b.newOrder(ctx, newOrderTest, o, &resp)
|
||||
}
|
||||
|
||||
func (b *Binance) newOrder(api string, o *NewOrderRequest, resp *NewOrderResponse) error {
|
||||
func (b *Binance) newOrder(ctx context.Context, api string, o *NewOrderRequest, resp *NewOrderResponse) error {
|
||||
params := url.Values{}
|
||||
symbol, err := b.FormatSymbol(o.Symbol, asset.Spot)
|
||||
if err != nil {
|
||||
@@ -544,11 +569,11 @@ func (b *Binance) newOrder(api string, o *NewOrderRequest, resp *NewOrderRespons
|
||||
if o.NewOrderRespType != "" {
|
||||
params.Set("newOrderRespType", o.NewOrderRespType)
|
||||
}
|
||||
return b.SendAuthHTTPRequest(exchange.RestSpotSupplementary, http.MethodPost, api, params, spotOrderRate, resp)
|
||||
return b.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodPost, api, params, spotOrderRate, resp)
|
||||
}
|
||||
|
||||
// CancelExistingOrder sends a cancel order to Binance
|
||||
func (b *Binance) CancelExistingOrder(symbol currency.Pair, orderID int64, origClientOrderID string) (CancelOrderResponse, error) {
|
||||
func (b *Binance) CancelExistingOrder(ctx context.Context, symbol currency.Pair, orderID int64, origClientOrderID string) (CancelOrderResponse, error) {
|
||||
var resp CancelOrderResponse
|
||||
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.Spot)
|
||||
@@ -565,13 +590,13 @@ func (b *Binance) CancelExistingOrder(symbol currency.Pair, orderID int64, origC
|
||||
if origClientOrderID != "" {
|
||||
params.Set("origClientOrderId", origClientOrderID)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestSpotSupplementary, http.MethodDelete, orderEndpoint, params, spotOrderRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodDelete, orderEndpoint, params, spotOrderRate, &resp)
|
||||
}
|
||||
|
||||
// OpenOrders Current open orders. Get all open orders on a symbol.
|
||||
// Careful when accessing this with no symbol: The number of requests counted
|
||||
// against the rate limiter is significantly higher
|
||||
func (b *Binance) OpenOrders(pair currency.Pair) ([]QueryOrderData, error) {
|
||||
func (b *Binance) OpenOrders(ctx context.Context, pair currency.Pair) ([]QueryOrderData, error) {
|
||||
var resp []QueryOrderData
|
||||
params := url.Values{}
|
||||
var p string
|
||||
@@ -587,7 +612,13 @@ func (b *Binance) OpenOrders(pair currency.Pair) ([]QueryOrderData, error) {
|
||||
// error
|
||||
params.Set("recvWindow", "10000")
|
||||
}
|
||||
if err := b.SendAuthHTTPRequest(exchange.RestSpotSupplementary, http.MethodGet, openOrders, params, openOrdersLimit(p), &resp); err != nil {
|
||||
if err := b.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary,
|
||||
http.MethodGet,
|
||||
openOrders,
|
||||
params,
|
||||
openOrdersLimit(p),
|
||||
&resp); err != nil {
|
||||
return resp, err
|
||||
}
|
||||
|
||||
@@ -597,7 +628,7 @@ func (b *Binance) OpenOrders(pair currency.Pair) ([]QueryOrderData, error) {
|
||||
// AllOrders Get all account orders; active, canceled, or filled.
|
||||
// orderId optional param
|
||||
// limit optional param, default 500; max 500
|
||||
func (b *Binance) AllOrders(symbol currency.Pair, orderID, limit string) ([]QueryOrderData, error) {
|
||||
func (b *Binance) AllOrders(ctx context.Context, symbol currency.Pair, orderID, limit string) ([]QueryOrderData, error) {
|
||||
var resp []QueryOrderData
|
||||
|
||||
params := url.Values{}
|
||||
@@ -612,14 +643,20 @@ func (b *Binance) AllOrders(symbol currency.Pair, orderID, limit string) ([]Quer
|
||||
if limit != "" {
|
||||
params.Set("limit", limit)
|
||||
}
|
||||
if err := b.SendAuthHTTPRequest(exchange.RestSpotSupplementary, http.MethodGet, allOrders, params, spotAllOrdersRate, &resp); err != nil {
|
||||
if err := b.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary,
|
||||
http.MethodGet,
|
||||
allOrders,
|
||||
params,
|
||||
spotAllOrdersRate,
|
||||
&resp); err != nil {
|
||||
return resp, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// QueryOrder returns information on a past order
|
||||
func (b *Binance) QueryOrder(symbol currency.Pair, origClientOrderID string, orderID int64) (QueryOrderData, error) {
|
||||
func (b *Binance) QueryOrder(ctx context.Context, symbol currency.Pair, origClientOrderID string, orderID int64) (QueryOrderData, error) {
|
||||
var resp QueryOrderData
|
||||
|
||||
params := url.Values{}
|
||||
@@ -635,7 +672,11 @@ func (b *Binance) QueryOrder(symbol currency.Pair, origClientOrderID string, ord
|
||||
params.Set("orderId", strconv.FormatInt(orderID, 10))
|
||||
}
|
||||
|
||||
if err := b.SendAuthHTTPRequest(exchange.RestSpotSupplementary, http.MethodGet, orderEndpoint, params, spotOrderQueryRate, &resp); err != nil {
|
||||
if err := b.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary,
|
||||
http.MethodGet, orderEndpoint,
|
||||
params, spotOrderQueryRate,
|
||||
&resp); err != nil {
|
||||
return resp, err
|
||||
}
|
||||
|
||||
@@ -646,7 +687,7 @@ func (b *Binance) QueryOrder(symbol currency.Pair, origClientOrderID string, ord
|
||||
}
|
||||
|
||||
// GetAccount returns binance user accounts
|
||||
func (b *Binance) GetAccount() (*Account, error) {
|
||||
func (b *Binance) GetAccount(ctx context.Context) (*Account, error) {
|
||||
type response struct {
|
||||
Response
|
||||
Account
|
||||
@@ -655,7 +696,11 @@ func (b *Binance) GetAccount() (*Account, error) {
|
||||
var resp response
|
||||
params := url.Values{}
|
||||
|
||||
if err := b.SendAuthHTTPRequest(exchange.RestSpotSupplementary, http.MethodGet, accountInfo, params, spotAccountInformationRate, &resp); err != nil {
|
||||
if err := b.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary,
|
||||
http.MethodGet, accountInfo,
|
||||
params, spotAccountInformationRate,
|
||||
&resp); err != nil {
|
||||
return &resp.Account, err
|
||||
}
|
||||
|
||||
@@ -667,11 +712,15 @@ func (b *Binance) GetAccount() (*Account, error) {
|
||||
}
|
||||
|
||||
// GetMarginAccount returns account information for margin accounts
|
||||
func (b *Binance) GetMarginAccount() (*MarginAccount, error) {
|
||||
func (b *Binance) GetMarginAccount(ctx context.Context) (*MarginAccount, error) {
|
||||
var resp MarginAccount
|
||||
params := url.Values{}
|
||||
|
||||
if err := b.SendAuthHTTPRequest(exchange.RestSpotSupplementary, http.MethodGet, marginAccountInfo, params, spotAccountInformationRate, &resp); err != nil {
|
||||
if err := b.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary,
|
||||
http.MethodGet, marginAccountInfo,
|
||||
params, spotAccountInformationRate,
|
||||
&resp); err != nil {
|
||||
return &resp, err
|
||||
}
|
||||
|
||||
@@ -679,7 +728,7 @@ func (b *Binance) GetMarginAccount() (*MarginAccount, error) {
|
||||
}
|
||||
|
||||
// SendHTTPRequest sends an unauthenticated request
|
||||
func (b *Binance) SendHTTPRequest(ePath exchange.URL, path string, f request.EndpointLimit, result interface{}) error {
|
||||
func (b *Binance) SendHTTPRequest(ctx context.Context, ePath exchange.URL, path string, f request.EndpointLimit, result interface{}) error {
|
||||
endpointPath, err := b.API.Endpoints.GetURL(ePath)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -692,14 +741,14 @@ func (b *Binance) SendHTTPRequest(ePath exchange.URL, path string, f request.End
|
||||
HTTPDebugging: b.HTTPDebugging,
|
||||
HTTPRecording: b.HTTPRecording}
|
||||
|
||||
return b.SendPayload(context.Background(), f, func() (*request.Item, error) {
|
||||
return b.SendPayload(ctx, f, func() (*request.Item, error) {
|
||||
return item, nil
|
||||
})
|
||||
}
|
||||
|
||||
// SendAPIKeyHTTPRequest is a special API request where the api key is
|
||||
// appended to the headers without a secret
|
||||
func (b *Binance) SendAPIKeyHTTPRequest(ePath exchange.URL, path string, f request.EndpointLimit, result interface{}) error {
|
||||
func (b *Binance) SendAPIKeyHTTPRequest(ctx context.Context, ePath exchange.URL, path string, f request.EndpointLimit, result interface{}) error {
|
||||
endpointPath, err := b.API.Endpoints.GetURL(ePath)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -715,13 +764,13 @@ func (b *Binance) SendAPIKeyHTTPRequest(ePath exchange.URL, path string, f reque
|
||||
HTTPDebugging: b.HTTPDebugging,
|
||||
HTTPRecording: b.HTTPRecording}
|
||||
|
||||
return b.SendPayload(context.Background(), f, func() (*request.Item, error) {
|
||||
return b.SendPayload(ctx, f, func() (*request.Item, error) {
|
||||
return item, nil
|
||||
})
|
||||
}
|
||||
|
||||
// SendAuthHTTPRequest sends an authenticated HTTP request
|
||||
func (b *Binance) SendAuthHTTPRequest(ePath exchange.URL, method, path string, params url.Values, f request.EndpointLimit, result interface{}) error {
|
||||
func (b *Binance) SendAuthHTTPRequest(ctx context.Context, ePath exchange.URL, method, path string, params url.Values, f request.EndpointLimit, result interface{}) error {
|
||||
if !b.AllowAuthenticatedRequest() {
|
||||
return fmt.Errorf("%s %w", b.Name, exchange.ErrAuthenticatedRequestWithoutCredentialsSet)
|
||||
}
|
||||
@@ -739,7 +788,7 @@ func (b *Binance) SendAuthHTTPRequest(ePath exchange.URL, method, path string, p
|
||||
}
|
||||
|
||||
interim := json.RawMessage{}
|
||||
err = b.SendPayload(context.Background(), f, func() (*request.Item, error) {
|
||||
err = b.SendPayload(ctx, f, func() (*request.Item, error) {
|
||||
fullPath := endpointPath + path
|
||||
params.Set("timestamp", strconv.FormatInt(time.Now().Unix()*1000, 10))
|
||||
signature := params.Encode()
|
||||
@@ -798,12 +847,12 @@ func (b *Binance) SetValues() {
|
||||
}
|
||||
|
||||
// GetFee returns an estimate of fee based on type of transaction
|
||||
func (b *Binance) GetFee(feeBuilder *exchange.FeeBuilder) (float64, error) {
|
||||
func (b *Binance) GetFee(ctx context.Context, feeBuilder *exchange.FeeBuilder) (float64, error) {
|
||||
var fee float64
|
||||
|
||||
switch feeBuilder.FeeType {
|
||||
case exchange.CryptocurrencyTradeFee:
|
||||
multiplier, err := b.getMultiplier(feeBuilder.IsMaker)
|
||||
multiplier, err := b.getMultiplier(ctx, feeBuilder.IsMaker)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -825,9 +874,9 @@ func getOfflineTradeFee(price, amount float64) float64 {
|
||||
}
|
||||
|
||||
// getMultiplier retrieves account based taker/maker fees
|
||||
func (b *Binance) getMultiplier(isMaker bool) (float64, error) {
|
||||
func (b *Binance) getMultiplier(ctx context.Context, isMaker bool) (float64, error) {
|
||||
var multiplier float64
|
||||
account, err := b.GetAccount()
|
||||
account, err := b.GetAccount(ctx)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -850,7 +899,7 @@ func getCryptocurrencyWithdrawalFee(c currency.Code) float64 {
|
||||
}
|
||||
|
||||
// WithdrawCrypto sends cryptocurrency to the address of your choosing
|
||||
func (b *Binance) WithdrawCrypto(asset, address, addressTag, name, amount string) (string, error) {
|
||||
func (b *Binance) WithdrawCrypto(ctx context.Context, asset, address, addressTag, name, amount string) (string, error) {
|
||||
var resp WithdrawResponse
|
||||
|
||||
params := url.Values{}
|
||||
@@ -864,7 +913,10 @@ func (b *Binance) WithdrawCrypto(asset, address, addressTag, name, amount string
|
||||
params.Set("addressTag", addressTag)
|
||||
}
|
||||
|
||||
if err := b.SendAuthHTTPRequest(exchange.RestSpotSupplementary, http.MethodPost, withdrawEndpoint, params, spotDefaultRate, &resp); err != nil {
|
||||
if err := b.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary,
|
||||
http.MethodPost, withdrawEndpoint,
|
||||
params, spotDefaultRate, &resp); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -877,7 +929,7 @@ func (b *Binance) WithdrawCrypto(asset, address, addressTag, name, amount string
|
||||
|
||||
// WithdrawStatus gets the status of recent withdrawals
|
||||
// status `param` used as string to prevent default value 0 (for int) interpreting as EmailSent status
|
||||
func (b *Binance) WithdrawStatus(c currency.Code, status string, startTime, endTime int64) ([]WithdrawStatusResponse, error) {
|
||||
func (b *Binance) WithdrawStatus(ctx context.Context, c currency.Code, status string, startTime, endTime int64) ([]WithdrawStatusResponse, error) {
|
||||
var response struct {
|
||||
Success bool `json:"success"`
|
||||
WithdrawList []WithdrawStatusResponse `json:"withdrawList"`
|
||||
@@ -909,7 +961,11 @@ func (b *Binance) WithdrawStatus(c currency.Code, status string, startTime, endT
|
||||
params.Set("endTime", strconv.FormatInt(endTime, 10))
|
||||
}
|
||||
|
||||
if err := b.SendAuthHTTPRequest(exchange.RestSpotSupplementary, http.MethodGet, withdrawalHistory, params, spotDefaultRate, &response); err != nil {
|
||||
if err := b.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary,
|
||||
http.MethodGet, withdrawalHistory,
|
||||
params, spotDefaultRate,
|
||||
&response); err != nil {
|
||||
return response.WithdrawList, err
|
||||
}
|
||||
|
||||
@@ -917,7 +973,7 @@ func (b *Binance) WithdrawStatus(c currency.Code, status string, startTime, endT
|
||||
}
|
||||
|
||||
// GetDepositAddressForCurrency retrieves the wallet address for a given currency
|
||||
func (b *Binance) GetDepositAddressForCurrency(currency string) (string, error) {
|
||||
func (b *Binance) GetDepositAddressForCurrency(ctx context.Context, currency string) (string, error) {
|
||||
resp := struct {
|
||||
Address string `json:"address"`
|
||||
Success bool `json:"success"`
|
||||
@@ -930,11 +986,14 @@ func (b *Binance) GetDepositAddressForCurrency(currency string) (string, error)
|
||||
params.Set("recvWindow", "10000")
|
||||
|
||||
return resp.Address,
|
||||
b.SendAuthHTTPRequest(exchange.RestSpotSupplementary, http.MethodGet, depositAddress, params, spotDefaultRate, &resp)
|
||||
b.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary,
|
||||
http.MethodGet, depositAddress,
|
||||
params, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetWsAuthStreamKey will retrieve a key to use for authorised WS streaming
|
||||
func (b *Binance) GetWsAuthStreamKey() (string, error) {
|
||||
func (b *Binance) GetWsAuthStreamKey(ctx context.Context) (string, error) {
|
||||
endpointPath, err := b.API.Endpoints.GetURL(exchange.RestSpotSupplementary)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -954,7 +1013,7 @@ func (b *Binance) GetWsAuthStreamKey() (string, error) {
|
||||
HTTPRecording: b.HTTPRecording,
|
||||
}
|
||||
|
||||
err = b.SendPayload(context.Background(), request.Unset, func() (*request.Item, error) {
|
||||
err = b.SendPayload(ctx, request.Unset, func() (*request.Item, error) {
|
||||
return item, nil
|
||||
})
|
||||
if err != nil {
|
||||
@@ -964,13 +1023,13 @@ func (b *Binance) GetWsAuthStreamKey() (string, error) {
|
||||
}
|
||||
|
||||
// MaintainWsAuthStreamKey will keep the key alive
|
||||
func (b *Binance) MaintainWsAuthStreamKey() error {
|
||||
func (b *Binance) MaintainWsAuthStreamKey(ctx context.Context) error {
|
||||
endpointPath, err := b.API.Endpoints.GetURL(exchange.RestSpotSupplementary)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if listenKey == "" {
|
||||
listenKey, err = b.GetWsAuthStreamKey()
|
||||
listenKey, err = b.GetWsAuthStreamKey(ctx)
|
||||
return err
|
||||
}
|
||||
path := endpointPath + userAccountStream
|
||||
@@ -989,15 +1048,15 @@ func (b *Binance) MaintainWsAuthStreamKey() error {
|
||||
HTTPRecording: b.HTTPRecording,
|
||||
}
|
||||
|
||||
return b.SendPayload(context.Background(), request.Unset, func() (*request.Item, error) {
|
||||
return b.SendPayload(ctx, request.Unset, func() (*request.Item, error) {
|
||||
return item, nil
|
||||
})
|
||||
}
|
||||
|
||||
// FetchSpotExchangeLimits fetches spot order execution limits
|
||||
func (b *Binance) FetchSpotExchangeLimits() ([]order.MinMaxLevel, error) {
|
||||
func (b *Binance) FetchSpotExchangeLimits(ctx context.Context) ([]order.MinMaxLevel, error) {
|
||||
var limits []order.MinMaxLevel
|
||||
spot, err := b.GetExchangeInfo()
|
||||
spot, err := b.GetExchangeInfo(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package binance
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -67,13 +68,13 @@ const (
|
||||
)
|
||||
|
||||
// FuturesExchangeInfo stores CoinMarginedFutures, data
|
||||
func (b *Binance) FuturesExchangeInfo() (CExchangeInfo, error) {
|
||||
func (b *Binance) FuturesExchangeInfo(ctx context.Context) (CExchangeInfo, error) {
|
||||
var resp CExchangeInfo
|
||||
return resp, b.SendHTTPRequest(exchange.RestCoinMargined, cfuturesExchangeInfo, cFuturesDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesExchangeInfo, cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetFuturesOrderbook gets orderbook data for CoinMarginedFutures,
|
||||
func (b *Binance) GetFuturesOrderbook(symbol currency.Pair, limit int64) (OrderBook, error) {
|
||||
func (b *Binance) GetFuturesOrderbook(ctx context.Context, symbol currency.Pair, limit int64) (OrderBook, error) {
|
||||
var resp OrderBook
|
||||
var data OrderbookData
|
||||
params := url.Values{}
|
||||
@@ -96,7 +97,7 @@ func (b *Binance) GetFuturesOrderbook(symbol currency.Pair, limit int64) (OrderB
|
||||
if limit > 0 && limit <= 1000 {
|
||||
params.Set("limit", strconv.FormatInt(limit, 10))
|
||||
}
|
||||
err = b.SendHTTPRequest(exchange.RestCoinMargined, cfuturesOrderbook+params.Encode(), rateBudget, &data)
|
||||
err = b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesOrderbook+params.Encode(), rateBudget, &data)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -133,7 +134,7 @@ func (b *Binance) GetFuturesOrderbook(symbol currency.Pair, limit int64) (OrderB
|
||||
}
|
||||
|
||||
// GetFuturesPublicTrades gets recent public trades for CoinMarginedFutures,
|
||||
func (b *Binance) GetFuturesPublicTrades(symbol currency.Pair, limit int64) ([]FuturesPublicTradesData, error) {
|
||||
func (b *Binance) GetFuturesPublicTrades(ctx context.Context, symbol currency.Pair, limit int64) ([]FuturesPublicTradesData, error) {
|
||||
var resp []FuturesPublicTradesData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
@@ -144,11 +145,11 @@ func (b *Binance) GetFuturesPublicTrades(symbol currency.Pair, limit int64) ([]F
|
||||
if limit > 0 && limit <= 1000 {
|
||||
params.Set("limit", strconv.FormatInt(limit, 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(exchange.RestCoinMargined, cfuturesRecentTrades+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesRecentTrades+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetFuturesHistoricalTrades gets historical public trades for CoinMarginedFutures,
|
||||
func (b *Binance) GetFuturesHistoricalTrades(symbol currency.Pair, fromID string, limit int64) ([]UPublicTradesData, error) {
|
||||
func (b *Binance) GetFuturesHistoricalTrades(ctx context.Context, symbol currency.Pair, fromID string, limit int64) ([]UPublicTradesData, error) {
|
||||
var resp []UPublicTradesData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
@@ -162,11 +163,11 @@ func (b *Binance) GetFuturesHistoricalTrades(symbol currency.Pair, fromID string
|
||||
if limit > 0 && limit < 1000 {
|
||||
params.Set("limit", strconv.FormatInt(limit, 10))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestCoinMargined, http.MethodGet, cfuturesHistoricalTrades, params, cFuturesHistoricalTradesRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesHistoricalTrades, params, cFuturesHistoricalTradesRate, &resp)
|
||||
}
|
||||
|
||||
// GetPastPublicTrades gets past public trades for CoinMarginedFutures,
|
||||
func (b *Binance) GetPastPublicTrades(symbol currency.Pair, limit, fromID int64) ([]FuturesPublicTradesData, error) {
|
||||
func (b *Binance) GetPastPublicTrades(ctx context.Context, symbol currency.Pair, limit, fromID int64) ([]FuturesPublicTradesData, error) {
|
||||
var resp []FuturesPublicTradesData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
@@ -180,11 +181,11 @@ func (b *Binance) GetPastPublicTrades(symbol currency.Pair, limit, fromID int64)
|
||||
if fromID != 0 {
|
||||
params.Set("fromID", strconv.FormatInt(fromID, 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(exchange.RestCoinMargined, cfuturesRecentTrades+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesRecentTrades+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetFuturesAggregatedTradesList gets aggregated trades list for CoinMarginedFutures,
|
||||
func (b *Binance) GetFuturesAggregatedTradesList(symbol currency.Pair, fromID, limit int64, startTime, endTime time.Time) ([]AggregatedTrade, error) {
|
||||
func (b *Binance) GetFuturesAggregatedTradesList(ctx context.Context, symbol currency.Pair, fromID, limit int64, startTime, endTime time.Time) ([]AggregatedTrade, error) {
|
||||
var resp []AggregatedTrade
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
@@ -205,11 +206,11 @@ func (b *Binance) GetFuturesAggregatedTradesList(symbol currency.Pair, fromID, l
|
||||
params.Set("start_time", strconv.FormatInt(startTime.Unix(), 10))
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(exchange.RestCoinMargined, cfuturesCompressedTrades+params.Encode(), cFuturesHistoricalTradesRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesCompressedTrades+params.Encode(), cFuturesHistoricalTradesRate, &resp)
|
||||
}
|
||||
|
||||
// GetIndexAndMarkPrice gets index and mark prices for CoinMarginedFutures,
|
||||
func (b *Binance) GetIndexAndMarkPrice(symbol, pair string) ([]IndexMarkPrice, error) {
|
||||
func (b *Binance) GetIndexAndMarkPrice(ctx context.Context, symbol, pair string) ([]IndexMarkPrice, error) {
|
||||
var resp []IndexMarkPrice
|
||||
params := url.Values{}
|
||||
if symbol != "" {
|
||||
@@ -218,11 +219,11 @@ func (b *Binance) GetIndexAndMarkPrice(symbol, pair string) ([]IndexMarkPrice, e
|
||||
if pair != "" {
|
||||
params.Set("pair", pair)
|
||||
}
|
||||
return resp, b.SendHTTPRequest(exchange.RestCoinMargined, cfuturesMarkPrice+params.Encode(), cFuturesIndexMarkPriceRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesMarkPrice+params.Encode(), cFuturesIndexMarkPriceRate, &resp)
|
||||
}
|
||||
|
||||
// GetFuturesKlineData gets futures kline data for CoinMarginedFutures,
|
||||
func (b *Binance) GetFuturesKlineData(symbol currency.Pair, interval string, limit int64, startTime, endTime time.Time) ([]FuturesCandleStick, error) {
|
||||
func (b *Binance) GetFuturesKlineData(ctx context.Context, symbol currency.Pair, interval string, limit int64, startTime, endTime time.Time) ([]FuturesCandleStick, error) {
|
||||
var data [][10]interface{}
|
||||
var resp []FuturesCandleStick
|
||||
params := url.Values{}
|
||||
@@ -248,7 +249,7 @@ func (b *Binance) GetFuturesKlineData(symbol currency.Pair, interval string, lim
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
rateBudget := getKlineRateBudget(limit)
|
||||
err := b.SendHTTPRequest(exchange.RestCoinMargined, cfuturesKlineData+params.Encode(), rateBudget, &data)
|
||||
err := b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesKlineData+params.Encode(), rateBudget, &data)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -341,7 +342,7 @@ func (b *Binance) GetFuturesKlineData(symbol currency.Pair, interval string, lim
|
||||
}
|
||||
|
||||
// GetContinuousKlineData gets continuous kline data
|
||||
func (b *Binance) GetContinuousKlineData(pair, contractType, interval string, limit int64, startTime, endTime time.Time) ([]FuturesCandleStick, error) {
|
||||
func (b *Binance) GetContinuousKlineData(ctx context.Context, pair, contractType, interval string, limit int64, startTime, endTime time.Time) ([]FuturesCandleStick, error) {
|
||||
var data [][10]interface{}
|
||||
var resp []FuturesCandleStick
|
||||
params := url.Values{}
|
||||
@@ -366,7 +367,7 @@ func (b *Binance) GetContinuousKlineData(pair, contractType, interval string, li
|
||||
}
|
||||
|
||||
rateBudget := getKlineRateBudget(limit)
|
||||
err := b.SendHTTPRequest(exchange.RestCoinMargined, cfuturesContinuousKline+params.Encode(), rateBudget, &data)
|
||||
err := b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesContinuousKline+params.Encode(), rateBudget, &data)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -459,7 +460,7 @@ func (b *Binance) GetContinuousKlineData(pair, contractType, interval string, li
|
||||
}
|
||||
|
||||
// GetIndexPriceKlines gets continuous kline data
|
||||
func (b *Binance) GetIndexPriceKlines(pair, interval string, limit int64, startTime, endTime time.Time) ([]FuturesCandleStick, error) {
|
||||
func (b *Binance) GetIndexPriceKlines(ctx context.Context, pair, interval string, limit int64, startTime, endTime time.Time) ([]FuturesCandleStick, error) {
|
||||
var data [][10]interface{}
|
||||
var resp []FuturesCandleStick
|
||||
params := url.Values{}
|
||||
@@ -479,7 +480,7 @@ func (b *Binance) GetIndexPriceKlines(pair, interval string, limit int64, startT
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
rateBudget := getKlineRateBudget(limit)
|
||||
err := b.SendHTTPRequest(exchange.RestCoinMargined, cfuturesIndexKline+params.Encode(), rateBudget, &data)
|
||||
err := b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesIndexKline+params.Encode(), rateBudget, &data)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -572,7 +573,7 @@ func (b *Binance) GetIndexPriceKlines(pair, interval string, limit int64, startT
|
||||
}
|
||||
|
||||
// GetMarkPriceKline gets mark price kline data
|
||||
func (b *Binance) GetMarkPriceKline(symbol currency.Pair, interval string, limit int64, startTime, endTime time.Time) ([]FuturesCandleStick, error) {
|
||||
func (b *Binance) GetMarkPriceKline(ctx context.Context, symbol currency.Pair, interval string, limit int64, startTime, endTime time.Time) ([]FuturesCandleStick, error) {
|
||||
var data [][10]interface{}
|
||||
var resp []FuturesCandleStick
|
||||
params := url.Values{}
|
||||
@@ -596,7 +597,7 @@ func (b *Binance) GetMarkPriceKline(symbol currency.Pair, interval string, limit
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
rateBudget := getKlineRateBudget(limit)
|
||||
err = b.SendHTTPRequest(exchange.RestCoinMargined, cfuturesMarkPriceKline+params.Encode(), rateBudget, &data)
|
||||
err = b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesMarkPriceKline+params.Encode(), rateBudget, &data)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -704,7 +705,7 @@ func getKlineRateBudget(limit int64) request.EndpointLimit {
|
||||
}
|
||||
|
||||
// GetFuturesSwapTickerChangeStats gets 24hr ticker change stats for CoinMarginedFutures,
|
||||
func (b *Binance) GetFuturesSwapTickerChangeStats(symbol currency.Pair, pair string) ([]PriceChangeStats, error) {
|
||||
func (b *Binance) GetFuturesSwapTickerChangeStats(ctx context.Context, symbol currency.Pair, pair string) ([]PriceChangeStats, error) {
|
||||
var resp []PriceChangeStats
|
||||
params := url.Values{}
|
||||
rateLimit := cFuturesTickerPriceHistoryRate
|
||||
@@ -719,11 +720,11 @@ func (b *Binance) GetFuturesSwapTickerChangeStats(symbol currency.Pair, pair str
|
||||
if pair != "" {
|
||||
params.Set("pair", pair)
|
||||
}
|
||||
return resp, b.SendHTTPRequest(exchange.RestCoinMargined, cfuturesTickerPriceStats+params.Encode(), rateLimit, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesTickerPriceStats+params.Encode(), rateLimit, &resp)
|
||||
}
|
||||
|
||||
// FuturesGetFundingHistory gets funding history for CoinMarginedFutures,
|
||||
func (b *Binance) FuturesGetFundingHistory(symbol currency.Pair, limit int64, startTime, endTime time.Time) ([]FundingRateHistory, error) {
|
||||
func (b *Binance) FuturesGetFundingHistory(ctx context.Context, symbol currency.Pair, limit int64, startTime, endTime time.Time) ([]FundingRateHistory, error) {
|
||||
var resp []FundingRateHistory
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
@@ -743,11 +744,11 @@ func (b *Binance) FuturesGetFundingHistory(symbol currency.Pair, limit int64, st
|
||||
params.Set("start_time", strconv.FormatInt(startTime.Unix(), 10))
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(exchange.RestCoinMargined, cfuturesFundingRateHistory+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesFundingRateHistory+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetFuturesSymbolPriceTicker gets price ticker for symbol
|
||||
func (b *Binance) GetFuturesSymbolPriceTicker(symbol currency.Pair, pair string) ([]SymbolPriceTicker, error) {
|
||||
func (b *Binance) GetFuturesSymbolPriceTicker(ctx context.Context, symbol currency.Pair, pair string) ([]SymbolPriceTicker, error) {
|
||||
var resp []SymbolPriceTicker
|
||||
params := url.Values{}
|
||||
rateLimit := cFuturesOrderbookTickerAllRate
|
||||
@@ -762,11 +763,11 @@ func (b *Binance) GetFuturesSymbolPriceTicker(symbol currency.Pair, pair string)
|
||||
if pair != "" {
|
||||
params.Set("pair", pair)
|
||||
}
|
||||
return resp, b.SendHTTPRequest(exchange.RestCoinMargined, cfuturesSymbolPriceTicker+params.Encode(), rateLimit, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesSymbolPriceTicker+params.Encode(), rateLimit, &resp)
|
||||
}
|
||||
|
||||
// GetFuturesOrderbookTicker gets orderbook ticker for symbol
|
||||
func (b *Binance) GetFuturesOrderbookTicker(symbol currency.Pair, pair string) ([]SymbolOrderBookTicker, error) {
|
||||
func (b *Binance) GetFuturesOrderbookTicker(ctx context.Context, symbol currency.Pair, pair string) ([]SymbolOrderBookTicker, error) {
|
||||
var resp []SymbolOrderBookTicker
|
||||
params := url.Values{}
|
||||
rateLimit := cFuturesOrderbookTickerAllRate
|
||||
@@ -781,11 +782,11 @@ func (b *Binance) GetFuturesOrderbookTicker(symbol currency.Pair, pair string) (
|
||||
if pair != "" {
|
||||
params.Set("pair", pair)
|
||||
}
|
||||
return resp, b.SendHTTPRequest(exchange.RestCoinMargined, cfuturesSymbolOrderbook+params.Encode(), rateLimit, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesSymbolOrderbook+params.Encode(), rateLimit, &resp)
|
||||
}
|
||||
|
||||
// GetFuturesLiquidationOrders gets forced liquidation orders
|
||||
func (b *Binance) GetFuturesLiquidationOrders(symbol currency.Pair, pair string, limit int64, startTime, endTime time.Time) ([]AllLiquidationOrders, error) {
|
||||
func (b *Binance) GetFuturesLiquidationOrders(ctx context.Context, symbol currency.Pair, pair string, limit int64, startTime, endTime time.Time) ([]AllLiquidationOrders, error) {
|
||||
var resp []AllLiquidationOrders
|
||||
params := url.Values{}
|
||||
rateLimit := cFuturesAllForceOrdersRate
|
||||
@@ -810,11 +811,11 @@ func (b *Binance) GetFuturesLiquidationOrders(symbol currency.Pair, pair string,
|
||||
params.Set("start_time", strconv.FormatInt(startTime.Unix(), 10))
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(exchange.RestCoinMargined, cfuturesLiquidationOrders+params.Encode(), rateLimit, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesLiquidationOrders+params.Encode(), rateLimit, &resp)
|
||||
}
|
||||
|
||||
// GetOpenInterest gets open interest data for a symbol
|
||||
func (b *Binance) GetOpenInterest(symbol currency.Pair) (OpenInterestData, error) {
|
||||
func (b *Binance) GetOpenInterest(ctx context.Context, symbol currency.Pair) (OpenInterestData, error) {
|
||||
var resp OpenInterestData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
@@ -822,11 +823,11 @@ func (b *Binance) GetOpenInterest(symbol currency.Pair) (OpenInterestData, error
|
||||
return resp, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
return resp, b.SendHTTPRequest(exchange.RestCoinMargined, cfuturesOpenInterest+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesOpenInterest+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetOpenInterestStats gets open interest stats for a symbol
|
||||
func (b *Binance) GetOpenInterestStats(pair, contractType, period string, limit int64, startTime, endTime time.Time) ([]OpenInterestStats, error) {
|
||||
func (b *Binance) GetOpenInterestStats(ctx context.Context, pair, contractType, period string, limit int64, startTime, endTime time.Time) ([]OpenInterestStats, error) {
|
||||
var resp []OpenInterestStats
|
||||
params := url.Values{}
|
||||
if pair != "" {
|
||||
@@ -850,11 +851,11 @@ func (b *Binance) GetOpenInterestStats(pair, contractType, period string, limit
|
||||
params.Set("start_time", strconv.FormatInt(startTime.Unix(), 10))
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(exchange.RestCoinMargined, cfuturesOpenInterestStats+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesOpenInterestStats+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetTraderFuturesAccountRatio gets a traders futures account long/short ratio
|
||||
func (b *Binance) GetTraderFuturesAccountRatio(pair, period string, limit int64, startTime, endTime time.Time) ([]TopTraderAccountRatio, error) {
|
||||
func (b *Binance) GetTraderFuturesAccountRatio(ctx context.Context, pair, period string, limit int64, startTime, endTime time.Time) ([]TopTraderAccountRatio, error) {
|
||||
var resp []TopTraderAccountRatio
|
||||
params := url.Values{}
|
||||
params.Set("pair", pair)
|
||||
@@ -872,11 +873,11 @@ func (b *Binance) GetTraderFuturesAccountRatio(pair, period string, limit int64,
|
||||
params.Set("start_time", strconv.FormatInt(startTime.Unix(), 10))
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(exchange.RestCoinMargined, cfuturesTopAccountsRatio+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesTopAccountsRatio+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetTraderFuturesPositionsRatio gets a traders futures positions' long/short ratio
|
||||
func (b *Binance) GetTraderFuturesPositionsRatio(pair, period string, limit int64, startTime, endTime time.Time) ([]TopTraderPositionRatio, error) {
|
||||
func (b *Binance) GetTraderFuturesPositionsRatio(ctx context.Context, pair, period string, limit int64, startTime, endTime time.Time) ([]TopTraderPositionRatio, error) {
|
||||
var resp []TopTraderPositionRatio
|
||||
params := url.Values{}
|
||||
params.Set("pair", pair)
|
||||
@@ -894,11 +895,11 @@ func (b *Binance) GetTraderFuturesPositionsRatio(pair, period string, limit int6
|
||||
params.Set("start_time", strconv.FormatInt(startTime.Unix(), 10))
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(exchange.RestCoinMargined, cfuturesTopPositionsRatio+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesTopPositionsRatio+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetMarketRatio gets global long/short ratio
|
||||
func (b *Binance) GetMarketRatio(pair, period string, limit int64, startTime, endTime time.Time) ([]TopTraderPositionRatio, error) {
|
||||
func (b *Binance) GetMarketRatio(ctx context.Context, pair, period string, limit int64, startTime, endTime time.Time) ([]TopTraderPositionRatio, error) {
|
||||
var resp []TopTraderPositionRatio
|
||||
params := url.Values{}
|
||||
params.Set("pair", pair)
|
||||
@@ -916,11 +917,11 @@ func (b *Binance) GetMarketRatio(pair, period string, limit int64, startTime, en
|
||||
params.Set("start_time", strconv.FormatInt(startTime.Unix(), 10))
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(exchange.RestCoinMargined, cfuturesLongShortRatio+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesLongShortRatio+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetFuturesTakerVolume gets futures taker buy/sell volumes
|
||||
func (b *Binance) GetFuturesTakerVolume(pair, contractType, period string, limit int64, startTime, endTime time.Time) ([]TakerBuySellVolume, error) {
|
||||
func (b *Binance) GetFuturesTakerVolume(ctx context.Context, pair, contractType, period string, limit int64, startTime, endTime time.Time) ([]TakerBuySellVolume, error) {
|
||||
var resp []TakerBuySellVolume
|
||||
params := url.Values{}
|
||||
params.Set("pair", pair)
|
||||
@@ -942,11 +943,11 @@ func (b *Binance) GetFuturesTakerVolume(pair, contractType, period string, limit
|
||||
params.Set("start_time", strconv.FormatInt(startTime.Unix(), 10))
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(exchange.RestCoinMargined, cfuturesBuySellVolume+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesBuySellVolume+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetFuturesBasisData gets futures basis data
|
||||
func (b *Binance) GetFuturesBasisData(pair, contractType, period string, limit int64, startTime, endTime time.Time) ([]FuturesBasisData, error) {
|
||||
func (b *Binance) GetFuturesBasisData(ctx context.Context, pair, contractType, period string, limit int64, startTime, endTime time.Time) ([]FuturesBasisData, error) {
|
||||
var resp []FuturesBasisData
|
||||
params := url.Values{}
|
||||
params.Set("pair", pair)
|
||||
@@ -968,11 +969,11 @@ func (b *Binance) GetFuturesBasisData(pair, contractType, period string, limit i
|
||||
params.Set("start_time", strconv.FormatInt(startTime.Unix(), 10))
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(exchange.RestCoinMargined, cfuturesBasis+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesBasis+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesNewOrder sends a new futures order to the exchange
|
||||
func (b *Binance) FuturesNewOrder(symbol currency.Pair, side, positionSide, orderType, timeInForce,
|
||||
func (b *Binance) FuturesNewOrder(ctx context.Context, symbol currency.Pair, side, positionSide, orderType, timeInForce,
|
||||
newClientOrderID, closePosition, workingType, newOrderRespType string,
|
||||
quantity, price, stopPrice, activationPrice, callbackRate float64, reduceOnly bool) (FuturesOrderPlaceData, error) {
|
||||
var resp FuturesOrderPlaceData
|
||||
@@ -1027,11 +1028,11 @@ func (b *Binance) FuturesNewOrder(symbol currency.Pair, side, positionSide, orde
|
||||
if callbackRate != 0 {
|
||||
params.Set("callbackRate", strconv.FormatFloat(callbackRate, 'f', -1, 64))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestCoinMargined, http.MethodPost, cfuturesOrder, params, cFuturesOrdersDefaultRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodPost, cfuturesOrder, params, cFuturesOrdersDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesBatchOrder sends a batch order request
|
||||
func (b *Binance) FuturesBatchOrder(data []PlaceBatchOrderData) ([]FuturesOrderPlaceData, error) {
|
||||
func (b *Binance) FuturesBatchOrder(ctx context.Context, data []PlaceBatchOrderData) ([]FuturesOrderPlaceData, error) {
|
||||
var resp []FuturesOrderPlaceData
|
||||
params := url.Values{}
|
||||
for x := range data {
|
||||
@@ -1065,11 +1066,11 @@ func (b *Binance) FuturesBatchOrder(data []PlaceBatchOrderData) ([]FuturesOrderP
|
||||
return resp, err
|
||||
}
|
||||
params.Set("batchOrders", string(jsonData))
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestCoinMargined, http.MethodPost, cfuturesBatchOrder, params, cFuturesBatchOrdersRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodPost, cfuturesBatchOrder, params, cFuturesBatchOrdersRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesBatchCancelOrders sends a batch request to cancel orders
|
||||
func (b *Binance) FuturesBatchCancelOrders(symbol currency.Pair, orderList, origClientOrderIDList []string) ([]BatchCancelOrderData, error) {
|
||||
func (b *Binance) FuturesBatchCancelOrders(ctx context.Context, symbol currency.Pair, orderList, origClientOrderIDList []string) ([]BatchCancelOrderData, error) {
|
||||
var resp []BatchCancelOrderData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
@@ -1091,11 +1092,11 @@ func (b *Binance) FuturesBatchCancelOrders(symbol currency.Pair, orderList, orig
|
||||
}
|
||||
params.Set("origClientOrderIdList", string(jsonCliOrdIDList))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestCoinMargined, http.MethodDelete, cfuturesBatchOrder, params, cFuturesOrdersDefaultRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodDelete, cfuturesBatchOrder, params, cFuturesOrdersDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesGetOrderData gets futures order data
|
||||
func (b *Binance) FuturesGetOrderData(symbol currency.Pair, orderID, origClientOrderID string) (FuturesOrderGetData, error) {
|
||||
func (b *Binance) FuturesGetOrderData(ctx context.Context, symbol currency.Pair, orderID, origClientOrderID string) (FuturesOrderGetData, error) {
|
||||
var resp FuturesOrderGetData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
@@ -1109,11 +1110,11 @@ func (b *Binance) FuturesGetOrderData(symbol currency.Pair, orderID, origClientO
|
||||
if origClientOrderID != "" {
|
||||
params.Set("origClientOrderId", origClientOrderID)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestCoinMargined, http.MethodGet, cfuturesOrder, params, cFuturesOrdersDefaultRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesOrder, params, cFuturesOrdersDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesCancelOrder cancels a futures order
|
||||
func (b *Binance) FuturesCancelOrder(symbol currency.Pair, orderID, origClientOrderID string) (FuturesOrderGetData, error) {
|
||||
func (b *Binance) FuturesCancelOrder(ctx context.Context, symbol currency.Pair, orderID, origClientOrderID string) (FuturesOrderGetData, error) {
|
||||
var resp FuturesOrderGetData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
@@ -1127,11 +1128,11 @@ func (b *Binance) FuturesCancelOrder(symbol currency.Pair, orderID, origClientOr
|
||||
if origClientOrderID != "" {
|
||||
params.Set("origClientOrderId", origClientOrderID)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestCoinMargined, http.MethodDelete, cfuturesOrder, params, cFuturesOrdersDefaultRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodDelete, cfuturesOrder, params, cFuturesOrdersDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesCancelAllOpenOrders cancels a futures order
|
||||
func (b *Binance) FuturesCancelAllOpenOrders(symbol currency.Pair) (GenericAuthResponse, error) {
|
||||
func (b *Binance) FuturesCancelAllOpenOrders(ctx context.Context, symbol currency.Pair) (GenericAuthResponse, error) {
|
||||
var resp GenericAuthResponse
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
@@ -1139,12 +1140,12 @@ func (b *Binance) FuturesCancelAllOpenOrders(symbol currency.Pair) (GenericAuthR
|
||||
return resp, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestCoinMargined, http.MethodDelete, cfuturesCancelAllOrders, params, cFuturesOrdersDefaultRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodDelete, cfuturesCancelAllOrders, params, cFuturesOrdersDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// AutoCancelAllOpenOrders cancels all open futures orders
|
||||
// countdownTime 1000 = 1s, example - to cancel all orders after 30s (countdownTime: 30000)
|
||||
func (b *Binance) AutoCancelAllOpenOrders(symbol currency.Pair, countdownTime int64) (AutoCancelAllOrdersData, error) {
|
||||
func (b *Binance) AutoCancelAllOpenOrders(ctx context.Context, symbol currency.Pair, countdownTime int64) (AutoCancelAllOrdersData, error) {
|
||||
var resp AutoCancelAllOrdersData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
@@ -1153,11 +1154,11 @@ func (b *Binance) AutoCancelAllOpenOrders(symbol currency.Pair, countdownTime in
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
params.Set("countdownTime", strconv.FormatInt(countdownTime, 10))
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestCoinMargined, http.MethodPost, cfuturesCountdownCancel, params, cFuturesCancelAllOrdersRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodPost, cfuturesCountdownCancel, params, cFuturesCancelAllOrdersRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesOpenOrderData gets open order data for CoinMarginedFutures,
|
||||
func (b *Binance) FuturesOpenOrderData(symbol currency.Pair, orderID, origClientOrderID string) (FuturesOrderGetData, error) {
|
||||
func (b *Binance) FuturesOpenOrderData(ctx context.Context, symbol currency.Pair, orderID, origClientOrderID string) (FuturesOrderGetData, error) {
|
||||
var resp FuturesOrderGetData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
@@ -1171,11 +1172,11 @@ func (b *Binance) FuturesOpenOrderData(symbol currency.Pair, orderID, origClient
|
||||
if origClientOrderID != "" {
|
||||
params.Set("origClientOrderId", origClientOrderID)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestCoinMargined, http.MethodGet, cfuturesOpenOrder, params, cFuturesOrdersDefaultRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesOpenOrder, params, cFuturesOrdersDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetFuturesAllOpenOrders gets all open orders data for CoinMarginedFutures,
|
||||
func (b *Binance) GetFuturesAllOpenOrders(symbol currency.Pair, pair string) ([]FuturesOrderData, error) {
|
||||
func (b *Binance) GetFuturesAllOpenOrders(ctx context.Context, symbol currency.Pair, pair string) ([]FuturesOrderData, error) {
|
||||
var resp []FuturesOrderData
|
||||
params := url.Values{}
|
||||
var p string
|
||||
@@ -1195,11 +1196,11 @@ func (b *Binance) GetFuturesAllOpenOrders(symbol currency.Pair, pair string) ([]
|
||||
if pair != "" {
|
||||
params.Set("pair", pair)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestCoinMargined, http.MethodGet, cfuturesAllOpenOrders, params, rateLimit, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesAllOpenOrders, params, rateLimit, &resp)
|
||||
}
|
||||
|
||||
// GetAllFuturesOrders gets all orders active cancelled or filled
|
||||
func (b *Binance) GetAllFuturesOrders(symbol currency.Pair, pair string, startTime, endTime time.Time, orderID, limit int64) ([]FuturesOrderData, error) {
|
||||
func (b *Binance) GetAllFuturesOrders(ctx context.Context, symbol currency.Pair, pair string, startTime, endTime time.Time, orderID, limit int64) ([]FuturesOrderData, error) {
|
||||
var resp []FuturesOrderData
|
||||
params := url.Values{}
|
||||
rateLimit := cFuturesPairOrdersRate
|
||||
@@ -1227,23 +1228,23 @@ func (b *Binance) GetAllFuturesOrders(symbol currency.Pair, pair string, startTi
|
||||
params.Set("start_time", strconv.FormatInt(startTime.Unix(), 10))
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestCoinMargined, http.MethodGet, cfuturesAllOrders, params, rateLimit, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesAllOrders, params, rateLimit, &resp)
|
||||
}
|
||||
|
||||
// GetFuturesAccountBalance gets account balance data for CoinMarginedFutures, account
|
||||
func (b *Binance) GetFuturesAccountBalance() ([]FuturesAccountBalanceData, error) {
|
||||
func (b *Binance) GetFuturesAccountBalance(ctx context.Context) ([]FuturesAccountBalanceData, error) {
|
||||
var resp []FuturesAccountBalanceData
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestCoinMargined, http.MethodGet, cfuturesAccountBalance, nil, cFuturesDefaultRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesAccountBalance, nil, cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetFuturesAccountInfo gets account info data for CoinMarginedFutures, account
|
||||
func (b *Binance) GetFuturesAccountInfo() (FuturesAccountInformation, error) {
|
||||
func (b *Binance) GetFuturesAccountInfo(ctx context.Context) (FuturesAccountInformation, error) {
|
||||
var resp FuturesAccountInformation
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestCoinMargined, http.MethodGet, cfuturesAccountInfo, nil, cFuturesAccountInformationRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesAccountInfo, nil, cFuturesAccountInformationRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesChangeInitialLeverage changes initial leverage for the account
|
||||
func (b *Binance) FuturesChangeInitialLeverage(symbol currency.Pair, leverage int64) (FuturesLeverageData, error) {
|
||||
func (b *Binance) FuturesChangeInitialLeverage(ctx context.Context, symbol currency.Pair, leverage int64) (FuturesLeverageData, error) {
|
||||
var resp FuturesLeverageData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
@@ -1255,11 +1256,11 @@ func (b *Binance) FuturesChangeInitialLeverage(symbol currency.Pair, leverage in
|
||||
return resp, errors.New("invalid leverage")
|
||||
}
|
||||
params.Set("leverage", strconv.FormatInt(leverage, 10))
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestCoinMargined, http.MethodPost, cfuturesChangeInitialLeverage, params, cFuturesDefaultRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodPost, cfuturesChangeInitialLeverage, params, cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesChangeMarginType changes margin type
|
||||
func (b *Binance) FuturesChangeMarginType(symbol currency.Pair, marginType string) (GenericAuthResponse, error) {
|
||||
func (b *Binance) FuturesChangeMarginType(ctx context.Context, symbol currency.Pair, marginType string) (GenericAuthResponse, error) {
|
||||
var resp GenericAuthResponse
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
@@ -1271,11 +1272,11 @@ func (b *Binance) FuturesChangeMarginType(symbol currency.Pair, marginType strin
|
||||
return resp, errors.New("invalid marginType")
|
||||
}
|
||||
params.Set("marginType", marginType)
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestCoinMargined, http.MethodPost, cfuturesChangeMarginType, params, cFuturesDefaultRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodPost, cfuturesChangeMarginType, params, cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// ModifyIsolatedPositionMargin changes margin for an isolated position
|
||||
func (b *Binance) ModifyIsolatedPositionMargin(symbol currency.Pair, positionSide, changeType string, amount float64) (GenericAuthResponse, error) {
|
||||
func (b *Binance) ModifyIsolatedPositionMargin(ctx context.Context, symbol currency.Pair, positionSide, changeType string, amount float64) (GenericAuthResponse, error) {
|
||||
var resp GenericAuthResponse
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
@@ -1293,11 +1294,11 @@ func (b *Binance) ModifyIsolatedPositionMargin(symbol currency.Pair, positionSid
|
||||
}
|
||||
params.Set("type", strconv.FormatInt(cType, 10))
|
||||
params.Set("amount", strconv.FormatFloat(amount, 'f', -1, 64))
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestCoinMargined, http.MethodPost, cfuturesModifyMargin, params, cFuturesDefaultRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodPost, cfuturesModifyMargin, params, cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesMarginChangeHistory gets past margin changes for positions
|
||||
func (b *Binance) FuturesMarginChangeHistory(symbol currency.Pair, changeType string, startTime, endTime time.Time, limit int64) ([]GetPositionMarginChangeHistoryData, error) {
|
||||
func (b *Binance) FuturesMarginChangeHistory(ctx context.Context, symbol currency.Pair, changeType string, startTime, endTime time.Time, limit int64) ([]GetPositionMarginChangeHistoryData, error) {
|
||||
var resp []GetPositionMarginChangeHistoryData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
@@ -1320,11 +1321,11 @@ func (b *Binance) FuturesMarginChangeHistory(symbol currency.Pair, changeType st
|
||||
if limit != 0 {
|
||||
params.Set("limit", strconv.FormatInt(limit, 10))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestCoinMargined, http.MethodGet, cfuturesMarginChangeHistory, params, cFuturesDefaultRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesMarginChangeHistory, params, cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesPositionsInfo gets futures positions info
|
||||
func (b *Binance) FuturesPositionsInfo(marginAsset, pair string) ([]FuturesPositionInformation, error) {
|
||||
func (b *Binance) FuturesPositionsInfo(ctx context.Context, marginAsset, pair string) ([]FuturesPositionInformation, error) {
|
||||
var resp []FuturesPositionInformation
|
||||
params := url.Values{}
|
||||
if marginAsset != "" {
|
||||
@@ -1333,11 +1334,11 @@ func (b *Binance) FuturesPositionsInfo(marginAsset, pair string) ([]FuturesPosit
|
||||
if pair != "" {
|
||||
params.Set("pair", pair)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestCoinMargined, http.MethodGet, cfuturesPositionInfo, params, cFuturesDefaultRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesPositionInfo, params, cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesTradeHistory gets trade history for CoinMarginedFutures, account
|
||||
func (b *Binance) FuturesTradeHistory(symbol currency.Pair, pair string, startTime, endTime time.Time, limit, fromID int64) ([]FuturesAccountTradeList, error) {
|
||||
func (b *Binance) FuturesTradeHistory(ctx context.Context, symbol currency.Pair, pair string, startTime, endTime time.Time, limit, fromID int64) ([]FuturesAccountTradeList, error) {
|
||||
var resp []FuturesAccountTradeList
|
||||
params := url.Values{}
|
||||
rateLimit := cFuturesPairOrdersRate
|
||||
@@ -1365,11 +1366,11 @@ func (b *Binance) FuturesTradeHistory(symbol currency.Pair, pair string, startTi
|
||||
if fromID != 0 {
|
||||
params.Set("fromId", strconv.FormatInt(fromID, 10))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestCoinMargined, http.MethodGet, cfuturesAccountTradeList, params, rateLimit, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesAccountTradeList, params, rateLimit, &resp)
|
||||
}
|
||||
|
||||
// FuturesIncomeHistory gets income history for CoinMarginedFutures,
|
||||
func (b *Binance) FuturesIncomeHistory(symbol currency.Pair, incomeType string, startTime, endTime time.Time, limit int64) ([]FuturesIncomeHistoryData, error) {
|
||||
func (b *Binance) FuturesIncomeHistory(ctx context.Context, symbol currency.Pair, incomeType string, startTime, endTime time.Time, limit int64) ([]FuturesIncomeHistoryData, error) {
|
||||
var resp []FuturesIncomeHistoryData
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
@@ -1395,21 +1396,21 @@ func (b *Binance) FuturesIncomeHistory(symbol currency.Pair, incomeType string,
|
||||
if limit != 0 {
|
||||
params.Set("limit", strconv.FormatInt(limit, 10))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestCoinMargined, http.MethodGet, cfuturesIncomeHistory, params, cFuturesIncomeHistoryRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesIncomeHistory, params, cFuturesIncomeHistoryRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesNotionalBracket gets futures notional bracket
|
||||
func (b *Binance) FuturesNotionalBracket(pair string) ([]NotionalBracketData, error) {
|
||||
func (b *Binance) FuturesNotionalBracket(ctx context.Context, pair string) ([]NotionalBracketData, error) {
|
||||
var resp []NotionalBracketData
|
||||
params := url.Values{}
|
||||
if pair != "" {
|
||||
params.Set("pair", pair)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestCoinMargined, http.MethodGet, cfuturesNotionalBracket, params, cFuturesDefaultRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesNotionalBracket, params, cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesForceOrders gets futures forced orders
|
||||
func (b *Binance) FuturesForceOrders(symbol currency.Pair, autoCloseType string, startTime, endTime time.Time) ([]ForcedOrdersData, error) {
|
||||
func (b *Binance) FuturesForceOrders(ctx context.Context, symbol currency.Pair, autoCloseType string, startTime, endTime time.Time) ([]ForcedOrdersData, error) {
|
||||
var resp []ForcedOrdersData
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
@@ -1432,11 +1433,11 @@ func (b *Binance) FuturesForceOrders(symbol currency.Pair, autoCloseType string,
|
||||
params.Set("start_time", strconv.FormatInt(startTime.Unix(), 10))
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestCoinMargined, http.MethodGet, cfuturesUsersForceOrders, params, cFuturesDefaultRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesUsersForceOrders, params, cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesPositionsADLEstimate estimates ADL on positions
|
||||
func (b *Binance) FuturesPositionsADLEstimate(symbol currency.Pair) ([]ADLEstimateData, error) {
|
||||
func (b *Binance) FuturesPositionsADLEstimate(ctx context.Context, symbol currency.Pair) ([]ADLEstimateData, error) {
|
||||
var resp []ADLEstimateData
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
@@ -1446,13 +1447,13 @@ func (b *Binance) FuturesPositionsADLEstimate(symbol currency.Pair) ([]ADLEstima
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestCoinMargined, http.MethodGet, cfuturesADLQuantile, params, cFuturesAccountInformationRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesADLQuantile, params, cFuturesAccountInformationRate, &resp)
|
||||
}
|
||||
|
||||
// FetchCoinMarginExchangeLimits fetches coin margined order execution limits
|
||||
func (b *Binance) FetchCoinMarginExchangeLimits() ([]order.MinMaxLevel, error) {
|
||||
func (b *Binance) FetchCoinMarginExchangeLimits(ctx context.Context) ([]order.MinMaxLevel, error) {
|
||||
var limits []order.MinMaxLevel
|
||||
coinFutures, err := b.FuturesExchangeInfo()
|
||||
coinFutures, err := b.FuturesExchangeInfo(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,7 @@
|
||||
package binance
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -65,11 +66,11 @@ const (
|
||||
)
|
||||
|
||||
// UServerTime gets the server time
|
||||
func (b *Binance) UServerTime() (time.Time, error) {
|
||||
func (b *Binance) UServerTime(ctx context.Context) (time.Time, error) {
|
||||
var data struct {
|
||||
ServerTime int64 `json:"serverTime"`
|
||||
}
|
||||
err := b.SendHTTPRequest(exchange.RestUSDTMargined, ufuturesServerTime, uFuturesDefaultRate, &data)
|
||||
err := b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesServerTime, uFuturesDefaultRate, &data)
|
||||
if err != nil {
|
||||
return time.Time{}, err
|
||||
}
|
||||
@@ -77,13 +78,13 @@ func (b *Binance) UServerTime() (time.Time, error) {
|
||||
}
|
||||
|
||||
// UExchangeInfo stores usdt margined futures data
|
||||
func (b *Binance) UExchangeInfo() (UFuturesExchangeInfo, error) {
|
||||
func (b *Binance) UExchangeInfo(ctx context.Context) (UFuturesExchangeInfo, error) {
|
||||
var resp UFuturesExchangeInfo
|
||||
return resp, b.SendHTTPRequest(exchange.RestUSDTMargined, ufuturesExchangeInfo, uFuturesDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesExchangeInfo, uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UFuturesOrderbook gets orderbook data for usdt margined futures
|
||||
func (b *Binance) UFuturesOrderbook(symbol currency.Pair, limit int64) (OrderBook, error) {
|
||||
func (b *Binance) UFuturesOrderbook(ctx context.Context, symbol currency.Pair, limit int64) (OrderBook, error) {
|
||||
var resp OrderBook
|
||||
var data OrderbookData
|
||||
params := url.Values{}
|
||||
@@ -110,7 +111,7 @@ func (b *Binance) UFuturesOrderbook(symbol currency.Pair, limit int64) (OrderBoo
|
||||
case limit == 1000:
|
||||
rateBudget = uFuturesOrderbook1000Rate
|
||||
}
|
||||
err = b.SendHTTPRequest(exchange.RestUSDTMargined, ufuturesOrderbook+params.Encode(), rateBudget, &data)
|
||||
err = b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesOrderbook+params.Encode(), rateBudget, &data)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -149,7 +150,7 @@ func (b *Binance) UFuturesOrderbook(symbol currency.Pair, limit int64) (OrderBoo
|
||||
}
|
||||
|
||||
// URecentTrades gets recent trades for usdt margined futures
|
||||
func (b *Binance) URecentTrades(symbol currency.Pair, fromID string, limit int64) ([]UPublicTradesData, error) {
|
||||
func (b *Binance) URecentTrades(ctx context.Context, symbol currency.Pair, fromID string, limit int64) ([]UPublicTradesData, error) {
|
||||
var resp []UPublicTradesData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
@@ -163,11 +164,11 @@ func (b *Binance) URecentTrades(symbol currency.Pair, fromID string, limit int64
|
||||
if limit > 0 && limit < 1000 {
|
||||
params.Set("limit", strconv.FormatInt(limit, 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(exchange.RestUSDTMargined, ufuturesRecentTrades+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesRecentTrades+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UFuturesHistoricalTrades gets historical public trades for USDTMarginedFutures
|
||||
func (b *Binance) UFuturesHistoricalTrades(symbol currency.Pair, fromID string, limit int64) ([]interface{}, error) {
|
||||
func (b *Binance) UFuturesHistoricalTrades(ctx context.Context, symbol currency.Pair, fromID string, limit int64) ([]interface{}, error) {
|
||||
var resp []interface{}
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
@@ -181,11 +182,11 @@ func (b *Binance) UFuturesHistoricalTrades(symbol currency.Pair, fromID string,
|
||||
if limit > 0 && limit < 1000 {
|
||||
params.Set("limit", strconv.FormatInt(limit, 10))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestUSDTMargined, http.MethodGet, ufuturesHistoricalTrades, params, uFuturesHistoricalTradesRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesHistoricalTrades, params, uFuturesHistoricalTradesRate, &resp)
|
||||
}
|
||||
|
||||
// UCompressedTrades gets compressed public trades for usdt margined futures
|
||||
func (b *Binance) UCompressedTrades(symbol currency.Pair, fromID string, limit int64, startTime, endTime time.Time) ([]UCompressedTradeData, error) {
|
||||
func (b *Binance) UCompressedTrades(ctx context.Context, symbol currency.Pair, fromID string, limit int64, startTime, endTime time.Time) ([]UCompressedTradeData, error) {
|
||||
var resp []UCompressedTradeData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
@@ -206,11 +207,11 @@ func (b *Binance) UCompressedTrades(symbol currency.Pair, fromID string, limit i
|
||||
params.Set("start_time", strconv.FormatInt(startTime.Unix(), 10))
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(exchange.RestUSDTMargined, ufuturesCompressedTrades+params.Encode(), uFuturesHistoricalTradesRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesCompressedTrades+params.Encode(), uFuturesHistoricalTradesRate, &resp)
|
||||
}
|
||||
|
||||
// UKlineData gets kline data for usdt margined futures
|
||||
func (b *Binance) UKlineData(symbol currency.Pair, interval string, limit int64, startTime, endTime time.Time) ([]FuturesCandleStick, error) {
|
||||
func (b *Binance) UKlineData(ctx context.Context, symbol currency.Pair, interval string, limit int64, startTime, endTime time.Time) ([]FuturesCandleStick, error) {
|
||||
var data [][10]interface{}
|
||||
var resp []FuturesCandleStick
|
||||
params := url.Values{}
|
||||
@@ -244,7 +245,7 @@ func (b *Binance) UKlineData(symbol currency.Pair, interval string, limit int64,
|
||||
case limit > 1000:
|
||||
rateBudget = uFuturesKlineMaxRate
|
||||
}
|
||||
err = b.SendHTTPRequest(exchange.RestUSDTMargined, ufuturesKlineData+params.Encode(), rateBudget, &data)
|
||||
err = b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesKlineData+params.Encode(), rateBudget, &data)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -343,7 +344,7 @@ func (b *Binance) UKlineData(symbol currency.Pair, interval string, limit int64,
|
||||
}
|
||||
|
||||
// UGetMarkPrice gets mark price data for USDTMarginedFutures
|
||||
func (b *Binance) UGetMarkPrice(symbol currency.Pair) ([]UMarkPrice, error) {
|
||||
func (b *Binance) UGetMarkPrice(ctx context.Context, symbol currency.Pair) ([]UMarkPrice, error) {
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
@@ -352,14 +353,14 @@ func (b *Binance) UGetMarkPrice(symbol currency.Pair) ([]UMarkPrice, error) {
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
var tempResp UMarkPrice
|
||||
err = b.SendHTTPRequest(exchange.RestUSDTMargined, ufuturesMarkPrice+params.Encode(), uFuturesDefaultRate, &tempResp)
|
||||
err = b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesMarkPrice+params.Encode(), uFuturesDefaultRate, &tempResp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []UMarkPrice{tempResp}, nil
|
||||
}
|
||||
var resp []UMarkPrice
|
||||
err := b.SendHTTPRequest(exchange.RestUSDTMargined, ufuturesMarkPrice+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
err := b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesMarkPrice+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -367,7 +368,7 @@ func (b *Binance) UGetMarkPrice(symbol currency.Pair) ([]UMarkPrice, error) {
|
||||
}
|
||||
|
||||
// UGetFundingHistory gets funding history for USDTMarginedFutures
|
||||
func (b *Binance) UGetFundingHistory(symbol currency.Pair, limit int64, startTime, endTime time.Time) ([]FundingRateHistory, error) {
|
||||
func (b *Binance) UGetFundingHistory(ctx context.Context, symbol currency.Pair, limit int64, startTime, endTime time.Time) ([]FundingRateHistory, error) {
|
||||
var resp []FundingRateHistory
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
@@ -387,11 +388,11 @@ func (b *Binance) UGetFundingHistory(symbol currency.Pair, limit int64, startTim
|
||||
params.Set("start_time", strconv.FormatInt(startTime.Unix(), 10))
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(exchange.RestUSDTMargined, ufuturesFundingRateHistory+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesFundingRateHistory+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// U24HTickerPriceChangeStats gets 24hr ticker price change stats for USDTMarginedFutures
|
||||
func (b *Binance) U24HTickerPriceChangeStats(symbol currency.Pair) ([]U24HrPriceChangeStats, error) {
|
||||
func (b *Binance) U24HTickerPriceChangeStats(ctx context.Context, symbol currency.Pair) ([]U24HrPriceChangeStats, error) {
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
@@ -400,19 +401,19 @@ func (b *Binance) U24HTickerPriceChangeStats(symbol currency.Pair) ([]U24HrPrice
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
var tempResp U24HrPriceChangeStats
|
||||
err = b.SendHTTPRequest(exchange.RestUSDTMargined, ufuturesTickerPriceStats+params.Encode(), uFuturesDefaultRate, &tempResp)
|
||||
err = b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesTickerPriceStats+params.Encode(), uFuturesDefaultRate, &tempResp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []U24HrPriceChangeStats{tempResp}, err
|
||||
}
|
||||
var resp []U24HrPriceChangeStats
|
||||
err := b.SendHTTPRequest(exchange.RestUSDTMargined, ufuturesTickerPriceStats+params.Encode(), uFuturesTickerPriceHistoryRate, &resp)
|
||||
err := b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesTickerPriceStats+params.Encode(), uFuturesTickerPriceHistoryRate, &resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// USymbolPriceTicker gets symbol price ticker for USDTMarginedFutures
|
||||
func (b *Binance) USymbolPriceTicker(symbol currency.Pair) ([]USymbolPriceTicker, error) {
|
||||
func (b *Binance) USymbolPriceTicker(ctx context.Context, symbol currency.Pair) ([]USymbolPriceTicker, error) {
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
@@ -421,19 +422,19 @@ func (b *Binance) USymbolPriceTicker(symbol currency.Pair) ([]USymbolPriceTicker
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
var tempResp USymbolPriceTicker
|
||||
err = b.SendHTTPRequest(exchange.RestUSDTMargined, ufuturesSymbolPriceTicker+params.Encode(), uFuturesDefaultRate, &tempResp)
|
||||
err = b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesSymbolPriceTicker+params.Encode(), uFuturesDefaultRate, &tempResp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []USymbolPriceTicker{tempResp}, err
|
||||
}
|
||||
var resp []USymbolPriceTicker
|
||||
err := b.SendHTTPRequest(exchange.RestUSDTMargined, ufuturesSymbolPriceTicker+params.Encode(), uFuturesOrderbookTickerAllRate, &resp)
|
||||
err := b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesSymbolPriceTicker+params.Encode(), uFuturesOrderbookTickerAllRate, &resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// USymbolOrderbookTicker gets symbol orderbook ticker
|
||||
func (b *Binance) USymbolOrderbookTicker(symbol currency.Pair) ([]USymbolOrderbookTicker, error) {
|
||||
func (b *Binance) USymbolOrderbookTicker(ctx context.Context, symbol currency.Pair) ([]USymbolOrderbookTicker, error) {
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
@@ -442,19 +443,19 @@ func (b *Binance) USymbolOrderbookTicker(symbol currency.Pair) ([]USymbolOrderbo
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
var tempResp USymbolOrderbookTicker
|
||||
err = b.SendHTTPRequest(exchange.RestUSDTMargined, ufuturesSymbolOrderbook+params.Encode(), uFuturesDefaultRate, &tempResp)
|
||||
err = b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesSymbolOrderbook+params.Encode(), uFuturesDefaultRate, &tempResp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []USymbolOrderbookTicker{tempResp}, err
|
||||
}
|
||||
var resp []USymbolOrderbookTicker
|
||||
err := b.SendHTTPRequest(exchange.RestUSDTMargined, ufuturesTickerPriceStats+params.Encode(), uFuturesOrderbookTickerAllRate, &resp)
|
||||
err := b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesTickerPriceStats+params.Encode(), uFuturesOrderbookTickerAllRate, &resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// ULiquidationOrders gets public liquidation orders
|
||||
func (b *Binance) ULiquidationOrders(symbol currency.Pair, limit int64, startTime, endTime time.Time) ([]ULiquidationOrdersData, error) {
|
||||
func (b *Binance) ULiquidationOrders(ctx context.Context, symbol currency.Pair, limit int64, startTime, endTime time.Time) ([]ULiquidationOrdersData, error) {
|
||||
var resp []ULiquidationOrdersData
|
||||
params := url.Values{}
|
||||
rateLimit := uFuturesAllForceOrdersRate
|
||||
@@ -476,11 +477,11 @@ func (b *Binance) ULiquidationOrders(symbol currency.Pair, limit int64, startTim
|
||||
params.Set("start_time", strconv.FormatInt(startTime.Unix(), 10))
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(exchange.RestUSDTMargined, ufuturesLiquidationOrders+params.Encode(), rateLimit, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesLiquidationOrders+params.Encode(), rateLimit, &resp)
|
||||
}
|
||||
|
||||
// UOpenInterest gets open interest data for USDTMarginedFutures
|
||||
func (b *Binance) UOpenInterest(symbol currency.Pair) (UOpenInterestData, error) {
|
||||
func (b *Binance) UOpenInterest(ctx context.Context, symbol currency.Pair) (UOpenInterestData, error) {
|
||||
var resp UOpenInterestData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
@@ -488,11 +489,11 @@ func (b *Binance) UOpenInterest(symbol currency.Pair) (UOpenInterestData, error)
|
||||
return resp, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
return resp, b.SendHTTPRequest(exchange.RestUSDTMargined, ufuturesOpenInterest+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesOpenInterest+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UOpenInterestStats gets open interest stats for USDTMarginedFutures
|
||||
func (b *Binance) UOpenInterestStats(symbol currency.Pair, period string, limit int64, startTime, endTime time.Time) ([]UOpenInterestStats, error) {
|
||||
func (b *Binance) UOpenInterestStats(ctx context.Context, symbol currency.Pair, period string, limit int64, startTime, endTime time.Time) ([]UOpenInterestStats, error) {
|
||||
var resp []UOpenInterestStats
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
@@ -514,11 +515,11 @@ func (b *Binance) UOpenInterestStats(symbol currency.Pair, period string, limit
|
||||
params.Set("start_time", strconv.FormatInt(startTime.Unix(), 10))
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(exchange.RestUSDTMargined, ufuturesOpenInterestStats+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesOpenInterestStats+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UTopAcccountsLongShortRatio gets long/short ratio data for top trader accounts in ufutures
|
||||
func (b *Binance) UTopAcccountsLongShortRatio(symbol currency.Pair, period string, limit int64, startTime, endTime time.Time) ([]ULongShortRatio, error) {
|
||||
func (b *Binance) UTopAcccountsLongShortRatio(ctx context.Context, symbol currency.Pair, period string, limit int64, startTime, endTime time.Time) ([]ULongShortRatio, error) {
|
||||
var resp []ULongShortRatio
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
@@ -540,11 +541,11 @@ func (b *Binance) UTopAcccountsLongShortRatio(symbol currency.Pair, period strin
|
||||
params.Set("start_time", strconv.FormatInt(startTime.Unix(), 10))
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(exchange.RestUSDTMargined, ufuturesTopAccountsRatio+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesTopAccountsRatio+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UTopPostionsLongShortRatio gets long/short ratio data for top positions' in ufutures
|
||||
func (b *Binance) UTopPostionsLongShortRatio(symbol currency.Pair, period string, limit int64, startTime, endTime time.Time) ([]ULongShortRatio, error) {
|
||||
func (b *Binance) UTopPostionsLongShortRatio(ctx context.Context, symbol currency.Pair, period string, limit int64, startTime, endTime time.Time) ([]ULongShortRatio, error) {
|
||||
var resp []ULongShortRatio
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
@@ -566,11 +567,11 @@ func (b *Binance) UTopPostionsLongShortRatio(symbol currency.Pair, period string
|
||||
params.Set("start_time", strconv.FormatInt(startTime.Unix(), 10))
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(exchange.RestUSDTMargined, ufuturesTopPositionsRatio+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesTopPositionsRatio+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UGlobalLongShortRatio gets the global long/short ratio data for USDTMarginedFutures
|
||||
func (b *Binance) UGlobalLongShortRatio(symbol currency.Pair, period string, limit int64, startTime, endTime time.Time) ([]ULongShortRatio, error) {
|
||||
func (b *Binance) UGlobalLongShortRatio(ctx context.Context, symbol currency.Pair, period string, limit int64, startTime, endTime time.Time) ([]ULongShortRatio, error) {
|
||||
var resp []ULongShortRatio
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
@@ -592,11 +593,11 @@ func (b *Binance) UGlobalLongShortRatio(symbol currency.Pair, period string, lim
|
||||
params.Set("start_time", strconv.FormatInt(startTime.Unix(), 10))
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(exchange.RestUSDTMargined, ufuturesLongShortRatio+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesLongShortRatio+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UTakerBuySellVol gets takers' buy/sell ratio for USDTMarginedFutures
|
||||
func (b *Binance) UTakerBuySellVol(symbol currency.Pair, period string, limit int64, startTime, endTime time.Time) ([]UTakerVolumeData, error) {
|
||||
func (b *Binance) UTakerBuySellVol(ctx context.Context, symbol currency.Pair, period string, limit int64, startTime, endTime time.Time) ([]UTakerVolumeData, error) {
|
||||
var resp []UTakerVolumeData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
@@ -618,11 +619,11 @@ func (b *Binance) UTakerBuySellVol(symbol currency.Pair, period string, limit in
|
||||
params.Set("start_time", strconv.FormatInt(startTime.Unix(), 10))
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(exchange.RestUSDTMargined, ufuturesBuySellVolume+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesBuySellVolume+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UCompositeIndexInfo stores composite indexs' info for usdt margined futures
|
||||
func (b *Binance) UCompositeIndexInfo(symbol currency.Pair) ([]UCompositeIndexInfoData, error) {
|
||||
func (b *Binance) UCompositeIndexInfo(ctx context.Context, symbol currency.Pair) ([]UCompositeIndexInfoData, error) {
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
@@ -631,18 +632,18 @@ func (b *Binance) UCompositeIndexInfo(symbol currency.Pair) ([]UCompositeIndexIn
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
var tempResp UCompositeIndexInfoData
|
||||
err = b.SendHTTPRequest(exchange.RestUSDTMargined, ufuturesCompositeIndexInfo+params.Encode(), uFuturesDefaultRate, &tempResp)
|
||||
err = b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesCompositeIndexInfo+params.Encode(), uFuturesDefaultRate, &tempResp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []UCompositeIndexInfoData{tempResp}, err
|
||||
}
|
||||
var resp []UCompositeIndexInfoData
|
||||
return resp, b.SendHTTPRequest(exchange.RestUSDTMargined, ufuturesCompositeIndexInfo+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesCompositeIndexInfo+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UFuturesNewOrder sends a new order for USDTMarginedFutures
|
||||
func (b *Binance) UFuturesNewOrder(symbol currency.Pair, side, positionSide, orderType, timeInForce,
|
||||
func (b *Binance) UFuturesNewOrder(ctx context.Context, symbol currency.Pair, side, positionSide, orderType, timeInForce,
|
||||
newClientOrderID, closePosition, workingType, newOrderRespType string,
|
||||
quantity, price, stopPrice, activationPrice, callbackRate float64, reduceOnly bool) (UOrderData, error) {
|
||||
var resp UOrderData
|
||||
@@ -697,11 +698,11 @@ func (b *Binance) UFuturesNewOrder(symbol currency.Pair, side, positionSide, ord
|
||||
if callbackRate != 0 {
|
||||
params.Set("callbackRate", strconv.FormatFloat(callbackRate, 'f', -1, 64))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestUSDTMargined, http.MethodPost, ufuturesOrder, params, uFuturesOrdersDefaultRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodPost, ufuturesOrder, params, uFuturesOrdersDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UPlaceBatchOrders places batch orders
|
||||
func (b *Binance) UPlaceBatchOrders(data []PlaceBatchOrderData) ([]UOrderData, error) {
|
||||
func (b *Binance) UPlaceBatchOrders(ctx context.Context, data []PlaceBatchOrderData) ([]UOrderData, error) {
|
||||
var resp []UOrderData
|
||||
params := url.Values{}
|
||||
for x := range data {
|
||||
@@ -735,11 +736,11 @@ func (b *Binance) UPlaceBatchOrders(data []PlaceBatchOrderData) ([]UOrderData, e
|
||||
return resp, err
|
||||
}
|
||||
params.Set("batchOrders", string(jsonData))
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestUSDTMargined, http.MethodPost, ufuturesBatchOrder, params, uFuturesBatchOrdersRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodPost, ufuturesBatchOrder, params, uFuturesBatchOrdersRate, &resp)
|
||||
}
|
||||
|
||||
// UGetOrderData gets order data for USDTMarginedFutures
|
||||
func (b *Binance) UGetOrderData(symbol currency.Pair, orderID, cliOrderID string) (UOrderData, error) {
|
||||
func (b *Binance) UGetOrderData(ctx context.Context, symbol currency.Pair, orderID, cliOrderID string) (UOrderData, error) {
|
||||
var resp UOrderData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
@@ -753,11 +754,11 @@ func (b *Binance) UGetOrderData(symbol currency.Pair, orderID, cliOrderID string
|
||||
if cliOrderID != "" {
|
||||
params.Set("origClientOrderId", cliOrderID)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestUSDTMargined, http.MethodGet, ufuturesOrder, params, uFuturesOrdersDefaultRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesOrder, params, uFuturesOrdersDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UCancelOrder cancel an order for USDTMarginedFutures
|
||||
func (b *Binance) UCancelOrder(symbol currency.Pair, orderID, cliOrderID string) (UOrderData, error) {
|
||||
func (b *Binance) UCancelOrder(ctx context.Context, symbol currency.Pair, orderID, cliOrderID string) (UOrderData, error) {
|
||||
var resp UOrderData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
@@ -771,11 +772,11 @@ func (b *Binance) UCancelOrder(symbol currency.Pair, orderID, cliOrderID string)
|
||||
if cliOrderID != "" {
|
||||
params.Set("origClientOrderId", cliOrderID)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestUSDTMargined, http.MethodDelete, ufuturesOrder, params, uFuturesOrdersDefaultRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodDelete, ufuturesOrder, params, uFuturesOrdersDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UCancelAllOpenOrders cancels all open orders for a symbol ufutures
|
||||
func (b *Binance) UCancelAllOpenOrders(symbol currency.Pair) (GenericAuthResponse, error) {
|
||||
func (b *Binance) UCancelAllOpenOrders(ctx context.Context, symbol currency.Pair) (GenericAuthResponse, error) {
|
||||
var resp GenericAuthResponse
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
@@ -783,11 +784,11 @@ func (b *Binance) UCancelAllOpenOrders(symbol currency.Pair) (GenericAuthRespons
|
||||
return resp, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestUSDTMargined, http.MethodDelete, ufuturesCancelAllOrders, params, uFuturesOrdersDefaultRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodDelete, ufuturesCancelAllOrders, params, uFuturesOrdersDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UCancelBatchOrders cancel batch order for USDTMarginedFutures
|
||||
func (b *Binance) UCancelBatchOrders(symbol currency.Pair, orderIDList, origCliOrdIDList []string) ([]UOrderData, error) {
|
||||
func (b *Binance) UCancelBatchOrders(ctx context.Context, symbol currency.Pair, orderIDList, origCliOrdIDList []string) ([]UOrderData, error) {
|
||||
var resp []UOrderData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
@@ -809,11 +810,11 @@ func (b *Binance) UCancelBatchOrders(symbol currency.Pair, orderIDList, origCliO
|
||||
}
|
||||
params.Set("origClientOrderIdList", string(jsonCliOrders))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestUSDTMargined, http.MethodDelete, ufuturesBatchOrder, params, uFuturesOrdersDefaultRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodDelete, ufuturesBatchOrder, params, uFuturesOrdersDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UAutoCancelAllOpenOrders auto cancels all ufutures open orders for a symbol after the set countdown time
|
||||
func (b *Binance) UAutoCancelAllOpenOrders(symbol currency.Pair, countdownTime int64) (AutoCancelAllOrdersData, error) {
|
||||
func (b *Binance) UAutoCancelAllOpenOrders(ctx context.Context, symbol currency.Pair, countdownTime int64) (AutoCancelAllOrdersData, error) {
|
||||
var resp AutoCancelAllOrdersData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
@@ -822,11 +823,11 @@ func (b *Binance) UAutoCancelAllOpenOrders(symbol currency.Pair, countdownTime i
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
params.Set("countdownTime", strconv.FormatInt(countdownTime, 10))
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestUSDTMargined, http.MethodPost, ufuturesCountdownCancel, params, uFuturesCountdownCancelRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodPost, ufuturesCountdownCancel, params, uFuturesCountdownCancelRate, &resp)
|
||||
}
|
||||
|
||||
// UFetchOpenOrder sends a request to fetch open order data for USDTMarginedFutures
|
||||
func (b *Binance) UFetchOpenOrder(symbol currency.Pair, orderID, origClientOrderID string) (UOrderData, error) {
|
||||
func (b *Binance) UFetchOpenOrder(ctx context.Context, symbol currency.Pair, orderID, origClientOrderID string) (UOrderData, error) {
|
||||
var resp UOrderData
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
@@ -842,11 +843,11 @@ func (b *Binance) UFetchOpenOrder(symbol currency.Pair, orderID, origClientOrder
|
||||
if origClientOrderID != "" {
|
||||
params.Set("origClientOrderId", origClientOrderID)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestUSDTMargined, http.MethodGet, ufuturesOpenOrder, params, uFuturesOrdersDefaultRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesOpenOrder, params, uFuturesOrdersDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UAllAccountOpenOrders gets all account's orders for USDTMarginedFutures
|
||||
func (b *Binance) UAllAccountOpenOrders(symbol currency.Pair) ([]UOrderData, error) {
|
||||
func (b *Binance) UAllAccountOpenOrders(ctx context.Context, symbol currency.Pair) ([]UOrderData, error) {
|
||||
var resp []UOrderData
|
||||
params := url.Values{}
|
||||
rateLimit := uFuturesGetAllOpenOrdersRate
|
||||
@@ -861,11 +862,11 @@ func (b *Binance) UAllAccountOpenOrders(symbol currency.Pair) ([]UOrderData, err
|
||||
// extend the receive window when all currencies to prevent "recvwindow" error
|
||||
params.Set("recvWindow", "10000")
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestUSDTMargined, http.MethodGet, ufuturesAllOpenOrders, params, rateLimit, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesAllOpenOrders, params, rateLimit, &resp)
|
||||
}
|
||||
|
||||
// UAllAccountOrders gets all account's orders for USDTMarginedFutures
|
||||
func (b *Binance) UAllAccountOrders(symbol currency.Pair, orderID, limit int64, startTime, endTime time.Time) ([]UFuturesOrderData, error) {
|
||||
func (b *Binance) UAllAccountOrders(ctx context.Context, symbol currency.Pair, orderID, limit int64, startTime, endTime time.Time) ([]UFuturesOrderData, error) {
|
||||
var resp []UFuturesOrderData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
@@ -886,23 +887,23 @@ func (b *Binance) UAllAccountOrders(symbol currency.Pair, orderID, limit int64,
|
||||
params.Set("start_time", strconv.FormatInt(startTime.Unix(), 10))
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestUSDTMargined, http.MethodGet, ufuturesAllOrders, params, uFuturesGetAllOrdersRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesAllOrders, params, uFuturesGetAllOrdersRate, &resp)
|
||||
}
|
||||
|
||||
// UAccountBalanceV2 gets V2 account balance data
|
||||
func (b *Binance) UAccountBalanceV2() ([]UAccountBalanceV2Data, error) {
|
||||
func (b *Binance) UAccountBalanceV2(ctx context.Context) ([]UAccountBalanceV2Data, error) {
|
||||
var resp []UAccountBalanceV2Data
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestUSDTMargined, http.MethodGet, ufuturesAccountBalance, nil, uFuturesOrdersDefaultRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesAccountBalance, nil, uFuturesOrdersDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UAccountInformationV2 gets V2 account balance data
|
||||
func (b *Binance) UAccountInformationV2() (UAccountInformationV2Data, error) {
|
||||
func (b *Binance) UAccountInformationV2(ctx context.Context) (UAccountInformationV2Data, error) {
|
||||
var resp UAccountInformationV2Data
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestUSDTMargined, http.MethodGet, ufuturesAccountInfo, nil, uFuturesAccountInformationRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesAccountInfo, nil, uFuturesAccountInformationRate, &resp)
|
||||
}
|
||||
|
||||
// UChangeInitialLeverageRequest sends a request to change account's initial leverage
|
||||
func (b *Binance) UChangeInitialLeverageRequest(symbol currency.Pair, leverage int64) (UChangeInitialLeverage, error) {
|
||||
func (b *Binance) UChangeInitialLeverageRequest(ctx context.Context, symbol currency.Pair, leverage int64) (UChangeInitialLeverage, error) {
|
||||
var resp UChangeInitialLeverage
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
@@ -914,11 +915,11 @@ func (b *Binance) UChangeInitialLeverageRequest(symbol currency.Pair, leverage i
|
||||
return resp, errors.New("invalid leverage")
|
||||
}
|
||||
params.Set("leverage", strconv.FormatInt(leverage, 10))
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestUSDTMargined, http.MethodPost, ufuturesChangeInitialLeverage, params, uFuturesDefaultRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodPost, ufuturesChangeInitialLeverage, params, uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UChangeInitialMarginType sends a request to change account's initial margin type
|
||||
func (b *Binance) UChangeInitialMarginType(symbol currency.Pair, marginType string) error {
|
||||
func (b *Binance) UChangeInitialMarginType(ctx context.Context, symbol currency.Pair, marginType string) error {
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
@@ -929,11 +930,11 @@ func (b *Binance) UChangeInitialMarginType(symbol currency.Pair, marginType stri
|
||||
return errors.New("invalid marginType")
|
||||
}
|
||||
params.Set("marginType", marginType)
|
||||
return b.SendAuthHTTPRequest(exchange.RestUSDTMargined, http.MethodPost, ufuturesChangeMarginType, params, uFuturesDefaultRate, nil)
|
||||
return b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodPost, ufuturesChangeMarginType, params, uFuturesDefaultRate, nil)
|
||||
}
|
||||
|
||||
// UModifyIsolatedPositionMarginReq sends a request to modify isolated margin for USDTMarginedFutures
|
||||
func (b *Binance) UModifyIsolatedPositionMarginReq(symbol currency.Pair, positionSide, changeType string, amount float64) (UModifyIsolatedPosMargin, error) {
|
||||
func (b *Binance) UModifyIsolatedPositionMarginReq(ctx context.Context, symbol currency.Pair, positionSide, changeType string, amount float64) (UModifyIsolatedPosMargin, error) {
|
||||
var resp UModifyIsolatedPosMargin
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
@@ -952,11 +953,11 @@ func (b *Binance) UModifyIsolatedPositionMarginReq(symbol currency.Pair, positio
|
||||
}
|
||||
params.Set("type", strconv.FormatInt(cType, 10))
|
||||
params.Set("amount", strconv.FormatFloat(amount, 'f', -1, 64))
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestUSDTMargined, http.MethodPost, ufuturesModifyMargin, params, uFuturesDefaultRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodPost, ufuturesModifyMargin, params, uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UPositionMarginChangeHistory gets margin change history for USDTMarginedFutures
|
||||
func (b *Binance) UPositionMarginChangeHistory(symbol currency.Pair, changeType string, limit int64, startTime, endTime time.Time) ([]UPositionMarginChangeHistoryData, error) {
|
||||
func (b *Binance) UPositionMarginChangeHistory(ctx context.Context, symbol currency.Pair, changeType string, limit int64, startTime, endTime time.Time) ([]UPositionMarginChangeHistoryData, error) {
|
||||
var resp []UPositionMarginChangeHistoryData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
@@ -979,11 +980,11 @@ func (b *Binance) UPositionMarginChangeHistory(symbol currency.Pair, changeType
|
||||
params.Set("start_time", strconv.FormatInt(startTime.Unix(), 10))
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestUSDTMargined, http.MethodGet, ufuturesMarginChangeHistory, params, uFuturesDefaultRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesMarginChangeHistory, params, uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UPositionsInfoV2 gets positions' info for USDTMarginedFutures
|
||||
func (b *Binance) UPositionsInfoV2(symbol currency.Pair) ([]UPositionInformationV2, error) {
|
||||
func (b *Binance) UPositionsInfoV2(ctx context.Context, symbol currency.Pair) ([]UPositionInformationV2, error) {
|
||||
var resp []UPositionInformationV2
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
@@ -993,11 +994,11 @@ func (b *Binance) UPositionsInfoV2(symbol currency.Pair) ([]UPositionInformation
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestUSDTMargined, http.MethodGet, ufuturesPositionInfo, params, uFuturesDefaultRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesPositionInfo, params, uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UAccountTradesHistory gets account's trade history data for USDTMarginedFutures
|
||||
func (b *Binance) UAccountTradesHistory(symbol currency.Pair, fromID string, limit int64, startTime, endTime time.Time) ([]UAccountTradeHistory, error) {
|
||||
func (b *Binance) UAccountTradesHistory(ctx context.Context, symbol currency.Pair, fromID string, limit int64, startTime, endTime time.Time) ([]UAccountTradeHistory, error) {
|
||||
var resp []UAccountTradeHistory
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
@@ -1018,11 +1019,11 @@ func (b *Binance) UAccountTradesHistory(symbol currency.Pair, fromID string, lim
|
||||
params.Set("start_time", strconv.FormatInt(startTime.Unix(), 10))
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestUSDTMargined, http.MethodGet, ufuturesAccountTradeList, params, uFuturesAccountInformationRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesAccountTradeList, params, uFuturesAccountInformationRate, &resp)
|
||||
}
|
||||
|
||||
// UAccountIncomeHistory gets account's income history data for USDTMarginedFutures
|
||||
func (b *Binance) UAccountIncomeHistory(symbol currency.Pair, incomeType string, limit int64, startTime, endTime time.Time) ([]UAccountIncomeHistory, error) {
|
||||
func (b *Binance) UAccountIncomeHistory(ctx context.Context, symbol currency.Pair, incomeType string, limit int64, startTime, endTime time.Time) ([]UAccountIncomeHistory, error) {
|
||||
var resp []UAccountIncomeHistory
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
@@ -1046,11 +1047,11 @@ func (b *Binance) UAccountIncomeHistory(symbol currency.Pair, incomeType string,
|
||||
params.Set("start_time", strconv.FormatInt(startTime.Unix(), 10))
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestUSDTMargined, http.MethodGet, ufuturesIncomeHistory, params, uFuturesIncomeHistoryRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesIncomeHistory, params, uFuturesIncomeHistoryRate, &resp)
|
||||
}
|
||||
|
||||
// UGetNotionalAndLeverageBrackets gets account's notional and leverage brackets for USDTMarginedFutures
|
||||
func (b *Binance) UGetNotionalAndLeverageBrackets(symbol currency.Pair) ([]UNotionalLeverageAndBrakcetsData, error) {
|
||||
func (b *Binance) UGetNotionalAndLeverageBrackets(ctx context.Context, symbol currency.Pair) ([]UNotionalLeverageAndBrakcetsData, error) {
|
||||
var resp []UNotionalLeverageAndBrakcetsData
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
@@ -1060,11 +1061,11 @@ func (b *Binance) UGetNotionalAndLeverageBrackets(symbol currency.Pair) ([]UNoti
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestUSDTMargined, http.MethodGet, ufuturesNotionalBracket, params, uFuturesDefaultRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesNotionalBracket, params, uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UPositionsADLEstimate gets estimated ADL data for USDTMarginedFutures positions
|
||||
func (b *Binance) UPositionsADLEstimate(symbol currency.Pair) (UPositionADLEstimationData, error) {
|
||||
func (b *Binance) UPositionsADLEstimate(ctx context.Context, symbol currency.Pair) (UPositionADLEstimationData, error) {
|
||||
var resp UPositionADLEstimationData
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
@@ -1074,11 +1075,11 @@ func (b *Binance) UPositionsADLEstimate(symbol currency.Pair) (UPositionADLEstim
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestUSDTMargined, http.MethodGet, ufuturesADLQuantile, params, uFuturesAccountInformationRate, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesADLQuantile, params, uFuturesAccountInformationRate, &resp)
|
||||
}
|
||||
|
||||
// UAccountForcedOrders gets account's forced (liquidation) orders for USDTMarginedFutures
|
||||
func (b *Binance) UAccountForcedOrders(symbol currency.Pair, autoCloseType string, limit int64, startTime, endTime time.Time) ([]UForceOrdersData, error) {
|
||||
func (b *Binance) UAccountForcedOrders(ctx context.Context, symbol currency.Pair, autoCloseType string, limit int64, startTime, endTime time.Time) ([]UForceOrdersData, error) {
|
||||
var resp []UForceOrdersData
|
||||
params := url.Values{}
|
||||
rateLimit := uFuturesAllForceOrdersRate
|
||||
@@ -1106,17 +1107,17 @@ func (b *Binance) UAccountForcedOrders(symbol currency.Pair, autoCloseType strin
|
||||
params.Set("start_time", strconv.FormatInt(startTime.Unix(), 10))
|
||||
params.Set("end_time", strconv.FormatInt(endTime.Unix(), 10))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(exchange.RestUSDTMargined, http.MethodGet, ufuturesUsersForceOrders, params, rateLimit, &resp)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesUsersForceOrders, params, rateLimit, &resp)
|
||||
}
|
||||
|
||||
// GetPerpMarkets returns exchange information. Check binance_types for more information
|
||||
func (b *Binance) GetPerpMarkets() (PerpsExchangeInfo, error) {
|
||||
func (b *Binance) GetPerpMarkets(ctx context.Context) (PerpsExchangeInfo, error) {
|
||||
var resp PerpsExchangeInfo
|
||||
return resp, b.SendHTTPRequest(exchange.RestUSDTMargined, perpExchangeInfo, uFuturesDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, perpExchangeInfo, uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetFundingRates gets funding rate history for perpetual contracts
|
||||
func (b *Binance) GetFundingRates(symbol currency.Pair, limit string, startTime, endTime time.Time) ([]FundingRateData, error) {
|
||||
func (b *Binance) GetFundingRates(ctx context.Context, symbol currency.Pair, limit string, startTime, endTime time.Time) ([]FundingRateData, error) {
|
||||
var resp []FundingRateData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
@@ -1133,13 +1134,13 @@ func (b *Binance) GetFundingRates(symbol currency.Pair, limit string, startTime,
|
||||
if !endTime.IsZero() {
|
||||
params.Set("endTime", strconv.FormatInt(endTime.UnixNano(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(exchange.RestUSDTMargined, fundingRate+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, fundingRate+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FetchUSDTMarginExchangeLimits fetches USDT margined order execution limits
|
||||
func (b *Binance) FetchUSDTMarginExchangeLimits() ([]order.MinMaxLevel, error) {
|
||||
func (b *Binance) FetchUSDTMarginExchangeLimits(ctx context.Context) ([]order.MinMaxLevel, error) {
|
||||
var limits []order.MinMaxLevel
|
||||
usdtFutures, err := b.UExchangeInfo()
|
||||
usdtFutures, err := b.UExchangeInfo(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package binance
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -51,7 +52,7 @@ func (b *Binance) WsConnect() error {
|
||||
dialer.Proxy = http.ProxyFromEnvironment
|
||||
var err error
|
||||
if b.Websocket.CanUseAuthenticatedEndpoints() {
|
||||
listenKey, err = b.GetWsAuthStreamKey()
|
||||
listenKey, err = b.GetWsAuthStreamKey(context.TODO())
|
||||
if err != nil {
|
||||
b.Websocket.SetCanUseAuthenticatedEndpoints(false)
|
||||
log.Errorf(log.ExchangeSys,
|
||||
@@ -130,7 +131,7 @@ func (b *Binance) KeepAuthKeyAlive() {
|
||||
ticks.Stop()
|
||||
return
|
||||
case <-ticks.C:
|
||||
err := b.MaintainWsAuthStreamKey()
|
||||
err := b.MaintainWsAuthStreamKey(context.TODO())
|
||||
if err != nil {
|
||||
b.Websocket.DataHandler <- err
|
||||
log.Warnf(log.ExchangeSys,
|
||||
@@ -467,11 +468,12 @@ func stringToOrderStatus(status string) (order.Status, error) {
|
||||
}
|
||||
|
||||
// SeedLocalCache seeds depth data
|
||||
func (b *Binance) SeedLocalCache(p currency.Pair) error {
|
||||
ob, err := b.GetOrderBook(OrderBookDataRequestParams{
|
||||
Symbol: p,
|
||||
Limit: 1000,
|
||||
})
|
||||
func (b *Binance) SeedLocalCache(ctx context.Context, p currency.Pair) error {
|
||||
ob, err := b.GetOrderBook(ctx,
|
||||
OrderBookDataRequestParams{
|
||||
Symbol: p,
|
||||
Limit: 1000,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -759,7 +761,7 @@ func (b *Binance) SynchroniseWebsocketOrderbook() {
|
||||
|
||||
// processJob fetches and processes orderbook updates
|
||||
func (b *Binance) processJob(p currency.Pair) error {
|
||||
err := b.SeedLocalCache(p)
|
||||
err := b.SeedLocalCache(context.TODO(), p)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s %s seeding local cache for orderbook error: %v",
|
||||
p, asset.Spot, err)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package binance
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
@@ -41,7 +42,7 @@ func (b *Binance) GetDefaultConfig() (*config.ExchangeConfig, error) {
|
||||
}
|
||||
|
||||
if b.Features.Supports.RESTCapabilities.AutoPairUpdates {
|
||||
err = b.UpdateTradablePairs(true)
|
||||
err = b.UpdateTradablePairs(context.TODO(), true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -317,7 +318,7 @@ func (b *Binance) Run() {
|
||||
|
||||
a := b.GetAssetTypes(true)
|
||||
for x := range a {
|
||||
err = b.UpdateOrderExecutionLimits(a[x])
|
||||
err = b.UpdateOrderExecutionLimits(context.TODO(), a[x])
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s failed to set exchange order execution limits. Err: %v",
|
||||
@@ -329,7 +330,7 @@ func (b *Binance) Run() {
|
||||
if !b.GetEnabledFeatures().AutoPairUpdates && !forceUpdate {
|
||||
return
|
||||
}
|
||||
err = b.UpdateTradablePairs(forceUpdate)
|
||||
err = b.UpdateTradablePairs(context.TODO(), forceUpdate)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s failed to update tradable pairs. Err: %s",
|
||||
@@ -339,7 +340,7 @@ func (b *Binance) Run() {
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (b *Binance) FetchTradablePairs(a asset.Item) ([]string, error) {
|
||||
func (b *Binance) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string, error) {
|
||||
if !b.SupportsAsset(a) {
|
||||
return nil, fmt.Errorf("asset type of %s is not supported by %s", a, b.Name)
|
||||
}
|
||||
@@ -350,7 +351,7 @@ func (b *Binance) FetchTradablePairs(a asset.Item) ([]string, error) {
|
||||
var pairs []string
|
||||
switch a {
|
||||
case asset.Spot, asset.Margin:
|
||||
info, err := b.GetExchangeInfo()
|
||||
info, err := b.GetExchangeInfo(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -368,7 +369,7 @@ func (b *Binance) FetchTradablePairs(a asset.Item) ([]string, error) {
|
||||
}
|
||||
}
|
||||
case asset.CoinMarginedFutures:
|
||||
cInfo, err := b.FuturesExchangeInfo()
|
||||
cInfo, err := b.FuturesExchangeInfo(ctx)
|
||||
if err != nil {
|
||||
return pairs, nil
|
||||
}
|
||||
@@ -382,7 +383,7 @@ func (b *Binance) FetchTradablePairs(a asset.Item) ([]string, error) {
|
||||
}
|
||||
}
|
||||
case asset.USDTMarginedFutures:
|
||||
uInfo, err := b.UExchangeInfo()
|
||||
uInfo, err := b.UExchangeInfo(ctx)
|
||||
if err != nil {
|
||||
return pairs, nil
|
||||
}
|
||||
@@ -401,10 +402,10 @@ func (b *Binance) FetchTradablePairs(a asset.Item) ([]string, error) {
|
||||
|
||||
// UpdateTradablePairs updates the exchanges available pairs and stores
|
||||
// them in the exchanges config
|
||||
func (b *Binance) UpdateTradablePairs(forceUpdate bool) error {
|
||||
func (b *Binance) UpdateTradablePairs(ctx context.Context, forceUpdate bool) error {
|
||||
assetTypes := b.GetAssetTypes(false)
|
||||
for i := range assetTypes {
|
||||
p, err := b.FetchTradablePairs(assetTypes[i])
|
||||
p, err := b.FetchTradablePairs(ctx, assetTypes[i])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -423,10 +424,10 @@ func (b *Binance) UpdateTradablePairs(forceUpdate bool) error {
|
||||
}
|
||||
|
||||
// UpdateTickers updates the ticker for all currency pairs of a given asset type
|
||||
func (b *Binance) UpdateTickers(a asset.Item) error {
|
||||
func (b *Binance) UpdateTickers(ctx context.Context, a asset.Item) error {
|
||||
switch a {
|
||||
case asset.Spot, asset.Margin:
|
||||
tick, err := b.GetTickers()
|
||||
tick, err := b.GetTickers(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -454,7 +455,7 @@ func (b *Binance) UpdateTickers(a asset.Item) error {
|
||||
}
|
||||
}
|
||||
case asset.USDTMarginedFutures:
|
||||
tick, err := b.U24HTickerPriceChangeStats(currency.Pair{})
|
||||
tick, err := b.U24HTickerPriceChangeStats(ctx, currency.Pair{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -481,7 +482,7 @@ func (b *Binance) UpdateTickers(a asset.Item) error {
|
||||
}
|
||||
}
|
||||
case asset.CoinMarginedFutures:
|
||||
tick, err := b.GetFuturesSwapTickerChangeStats(currency.Pair{}, "")
|
||||
tick, err := b.GetFuturesSwapTickerChangeStats(ctx, currency.Pair{}, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -514,10 +515,10 @@ func (b *Binance) UpdateTickers(a asset.Item) error {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (b *Binance) UpdateTicker(p currency.Pair, a asset.Item) (*ticker.Price, error) {
|
||||
func (b *Binance) UpdateTicker(ctx context.Context, p currency.Pair, a asset.Item) (*ticker.Price, error) {
|
||||
switch a {
|
||||
case asset.Spot, asset.Margin:
|
||||
tick, err := b.GetPriceChangeStats(p)
|
||||
tick, err := b.GetPriceChangeStats(ctx, p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -543,7 +544,7 @@ func (b *Binance) UpdateTicker(p currency.Pair, a asset.Item) (*ticker.Price, er
|
||||
return nil, err
|
||||
}
|
||||
case asset.USDTMarginedFutures:
|
||||
tick, err := b.U24HTickerPriceChangeStats(p)
|
||||
tick, err := b.U24HTickerPriceChangeStats(ctx, p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -567,7 +568,7 @@ func (b *Binance) UpdateTicker(p currency.Pair, a asset.Item) (*ticker.Price, er
|
||||
return nil, err
|
||||
}
|
||||
case asset.CoinMarginedFutures:
|
||||
tick, err := b.GetFuturesSwapTickerChangeStats(p, "")
|
||||
tick, err := b.GetFuturesSwapTickerChangeStats(ctx, p, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -598,7 +599,7 @@ func (b *Binance) UpdateTicker(p currency.Pair, a asset.Item) (*ticker.Price, er
|
||||
}
|
||||
|
||||
// FetchTicker returns the ticker for a currency pair
|
||||
func (b *Binance) FetchTicker(p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
|
||||
func (b *Binance) FetchTicker(ctx context.Context, p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
|
||||
fPair, err := b.FormatExchangeCurrency(p, assetType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -606,22 +607,22 @@ func (b *Binance) FetchTicker(p currency.Pair, assetType asset.Item) (*ticker.Pr
|
||||
|
||||
tickerNew, err := ticker.GetTicker(b.Name, fPair, assetType)
|
||||
if err != nil {
|
||||
return b.UpdateTicker(p, assetType)
|
||||
return b.UpdateTicker(ctx, p, assetType)
|
||||
}
|
||||
return tickerNew, nil
|
||||
}
|
||||
|
||||
// FetchOrderbook returns orderbook base on the currency pair
|
||||
func (b *Binance) FetchOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
func (b *Binance) FetchOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
ob, err := orderbook.Get(b.Name, p, assetType)
|
||||
if err != nil {
|
||||
return b.UpdateOrderbook(p, assetType)
|
||||
return b.UpdateOrderbook(ctx, p, assetType)
|
||||
}
|
||||
return ob, nil
|
||||
}
|
||||
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func (b *Binance) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
func (b *Binance) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
book := &orderbook.Base{
|
||||
Exchange: b.Name,
|
||||
Pair: p,
|
||||
@@ -632,13 +633,14 @@ func (b *Binance) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*order
|
||||
var err error
|
||||
switch assetType {
|
||||
case asset.Spot, asset.Margin:
|
||||
orderbookNew, err = b.GetOrderBook(OrderBookDataRequestParams{
|
||||
Symbol: p,
|
||||
Limit: 1000})
|
||||
orderbookNew, err = b.GetOrderBook(ctx,
|
||||
OrderBookDataRequestParams{
|
||||
Symbol: p,
|
||||
Limit: 1000})
|
||||
case asset.USDTMarginedFutures:
|
||||
orderbookNew, err = b.UFuturesOrderbook(p, 1000)
|
||||
orderbookNew, err = b.UFuturesOrderbook(ctx, p, 1000)
|
||||
case asset.CoinMarginedFutures:
|
||||
orderbookNew, err = b.GetFuturesOrderbook(p, 1000)
|
||||
orderbookNew, err = b.GetFuturesOrderbook(ctx, p, 1000)
|
||||
}
|
||||
if err != nil {
|
||||
return book, err
|
||||
@@ -665,13 +667,13 @@ func (b *Binance) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*order
|
||||
|
||||
// UpdateAccountInfo retrieves balances for all enabled currencies for the
|
||||
// Binance exchange
|
||||
func (b *Binance) UpdateAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
func (b *Binance) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (account.Holdings, error) {
|
||||
var info account.Holdings
|
||||
var acc account.SubAccount
|
||||
info.Exchange = b.Name
|
||||
switch assetType {
|
||||
case asset.Spot:
|
||||
raw, err := b.GetAccount()
|
||||
raw, err := b.GetAccount(ctx)
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
@@ -698,7 +700,7 @@ func (b *Binance) UpdateAccountInfo(assetType asset.Item) (account.Holdings, err
|
||||
acc.Currencies = currencyBalance
|
||||
|
||||
case asset.CoinMarginedFutures:
|
||||
accData, err := b.GetFuturesAccountInfo()
|
||||
accData, err := b.GetFuturesAccountInfo(ctx)
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
@@ -714,7 +716,7 @@ func (b *Binance) UpdateAccountInfo(assetType asset.Item) (account.Holdings, err
|
||||
acc.Currencies = currencyDetails
|
||||
|
||||
case asset.USDTMarginedFutures:
|
||||
accData, err := b.UAccountBalanceV2()
|
||||
accData, err := b.UAccountBalanceV2(ctx)
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
@@ -729,7 +731,7 @@ func (b *Binance) UpdateAccountInfo(assetType asset.Item) (account.Holdings, err
|
||||
|
||||
acc.Currencies = currencyDetails
|
||||
case asset.Margin:
|
||||
accData, err := b.GetMarginAccount()
|
||||
accData, err := b.GetMarginAccount(ctx)
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
@@ -757,10 +759,10 @@ func (b *Binance) UpdateAccountInfo(assetType asset.Item) (account.Holdings, err
|
||||
}
|
||||
|
||||
// FetchAccountInfo retrieves balances for all enabled currencies
|
||||
func (b *Binance) FetchAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
func (b *Binance) FetchAccountInfo(ctx context.Context, assetType asset.Item) (account.Holdings, error) {
|
||||
acc, err := account.GetHoldings(b.Name, assetType)
|
||||
if err != nil {
|
||||
return b.UpdateAccountInfo(assetType)
|
||||
return b.UpdateAccountInfo(ctx, assetType)
|
||||
}
|
||||
|
||||
return acc, nil
|
||||
@@ -768,13 +770,13 @@ func (b *Binance) FetchAccountInfo(assetType asset.Item) (account.Holdings, erro
|
||||
|
||||
// GetFundingHistory returns funding history, deposits and
|
||||
// withdrawals
|
||||
func (b *Binance) GetFundingHistory() ([]exchange.FundHistory, error) {
|
||||
func (b *Binance) GetFundingHistory(ctx context.Context) ([]exchange.FundHistory, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetWithdrawalsHistory returns previous withdrawals data
|
||||
func (b *Binance) GetWithdrawalsHistory(c currency.Code) (resp []exchange.WithdrawalHistory, err error) {
|
||||
w, err := b.WithdrawStatus(c, "", 0, 0)
|
||||
func (b *Binance) GetWithdrawalsHistory(ctx context.Context, c currency.Code) (resp []exchange.WithdrawalHistory, err error) {
|
||||
w, err := b.WithdrawStatus(ctx, c, "", 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -796,10 +798,11 @@ func (b *Binance) GetWithdrawalsHistory(c currency.Code) (resp []exchange.Withdr
|
||||
}
|
||||
|
||||
// GetRecentTrades returns the most recent trades for a currency and asset
|
||||
func (b *Binance) GetRecentTrades(p currency.Pair, assetType asset.Item) ([]trade.Data, error) {
|
||||
func (b *Binance) GetRecentTrades(ctx context.Context, p currency.Pair, assetType asset.Item) ([]trade.Data, error) {
|
||||
var resp []trade.Data
|
||||
limit := 1000
|
||||
tradeData, err := b.GetMostRecentTrades(RecentTradeRequestParams{p, limit})
|
||||
tradeData, err := b.GetMostRecentTrades(ctx,
|
||||
RecentTradeRequestParams{p, limit})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -826,13 +829,13 @@ func (b *Binance) GetRecentTrades(p currency.Pair, assetType asset.Item) ([]trad
|
||||
}
|
||||
|
||||
// GetHistoricTrades returns historic trade data within the timeframe provided
|
||||
func (b *Binance) GetHistoricTrades(p currency.Pair, a asset.Item, from, to time.Time) ([]trade.Data, error) {
|
||||
func (b *Binance) GetHistoricTrades(ctx context.Context, p currency.Pair, a asset.Item, from, to time.Time) ([]trade.Data, error) {
|
||||
req := AggregatedTradeRequestParams{
|
||||
Symbol: p,
|
||||
StartTime: from,
|
||||
EndTime: to,
|
||||
}
|
||||
trades, err := b.GetAggregatedTrades(&req)
|
||||
trades, err := b.GetAggregatedTrades(ctx, &req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -859,7 +862,7 @@ func (a *AggregatedTrade) toTradeData(p currency.Pair, exchange string, aType as
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (b *Binance) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
func (b *Binance) SubmitOrder(ctx context.Context, s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
@@ -895,7 +898,7 @@ func (b *Binance) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
TimeInForce: timeInForce,
|
||||
NewClientOrderID: s.ClientOrderID,
|
||||
}
|
||||
response, err := b.NewOrder(&orderRequest)
|
||||
response, err := b.NewOrder(ctx, &orderRequest)
|
||||
if err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
@@ -947,7 +950,8 @@ func (b *Binance) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
default:
|
||||
return submitOrderResponse, errors.New("invalid type, check api docs for updates")
|
||||
}
|
||||
o, err := b.FuturesNewOrder(s.Pair, reqSide,
|
||||
o, err := b.FuturesNewOrder(ctx,
|
||||
s.Pair, reqSide,
|
||||
"", oType, "GTC", "",
|
||||
s.ClientOrderID, "", "",
|
||||
s.Amount, s.Price, 0, 0, 0, s.ReduceOnly)
|
||||
@@ -985,7 +989,8 @@ func (b *Binance) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
default:
|
||||
return submitOrderResponse, errors.New("invalid type, check api docs for updates")
|
||||
}
|
||||
order, err := b.UFuturesNewOrder(s.Pair, reqSide,
|
||||
order, err := b.UFuturesNewOrder(ctx,
|
||||
s.Pair, reqSide,
|
||||
"", oType, "GTC", "",
|
||||
s.ClientOrderID, "", "",
|
||||
s.Amount, s.Price, 0, 0, 0, s.ReduceOnly)
|
||||
@@ -1003,12 +1008,12 @@ func (b *Binance) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (b *Binance) ModifyOrder(action *order.Modify) (order.Modify, error) {
|
||||
func (b *Binance) 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 (b *Binance) CancelOrder(o *order.Cancel) error {
|
||||
func (b *Binance) CancelOrder(ctx context.Context, o *order.Cancel) error {
|
||||
if err := o.Validate(o.StandardCancel()); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1018,19 +1023,20 @@ func (b *Binance) CancelOrder(o *order.Cancel) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = b.CancelExistingOrder(o.Pair,
|
||||
_, err = b.CancelExistingOrder(ctx,
|
||||
o.Pair,
|
||||
orderIDInt,
|
||||
o.AccountID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case asset.CoinMarginedFutures:
|
||||
_, err := b.FuturesCancelOrder(o.Pair, o.ID, "")
|
||||
_, err := b.FuturesCancelOrder(ctx, o.Pair, o.ID, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case asset.USDTMarginedFutures:
|
||||
_, err := b.UCancelOrder(o.Pair, o.ID, "")
|
||||
_, err := b.UCancelOrder(ctx, o.Pair, o.ID, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1039,12 +1045,12 @@ func (b *Binance) CancelOrder(o *order.Cancel) error {
|
||||
}
|
||||
|
||||
// CancelBatchOrders cancels an orders by their corresponding ID numbers
|
||||
func (b *Binance) CancelBatchOrders(o []order.Cancel) (order.CancelBatchResponse, error) {
|
||||
func (b *Binance) 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 (b *Binance) CancelAllOrders(req *order.Cancel) (order.CancelAllResponse, error) {
|
||||
func (b *Binance) CancelAllOrders(ctx context.Context, req *order.Cancel) (order.CancelAllResponse, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return order.CancelAllResponse{}, err
|
||||
}
|
||||
@@ -1052,12 +1058,13 @@ func (b *Binance) CancelAllOrders(req *order.Cancel) (order.CancelAllResponse, e
|
||||
cancelAllOrdersResponse.Status = make(map[string]string)
|
||||
switch req.AssetType {
|
||||
case asset.Spot, asset.Margin:
|
||||
openOrders, err := b.OpenOrders(req.Pair)
|
||||
openOrders, err := b.OpenOrders(ctx, req.Pair)
|
||||
if err != nil {
|
||||
return cancelAllOrdersResponse, err
|
||||
}
|
||||
for i := range openOrders {
|
||||
_, err = b.CancelExistingOrder(req.Pair,
|
||||
_, err = b.CancelExistingOrder(ctx,
|
||||
req.Pair,
|
||||
openOrders[i].OrderID,
|
||||
"")
|
||||
if err != nil {
|
||||
@@ -1071,13 +1078,13 @@ func (b *Binance) CancelAllOrders(req *order.Cancel) (order.CancelAllResponse, e
|
||||
return cancelAllOrdersResponse, err
|
||||
}
|
||||
for i := range enabledPairs {
|
||||
_, err = b.FuturesCancelAllOpenOrders(enabledPairs[i])
|
||||
_, err = b.FuturesCancelAllOpenOrders(ctx, enabledPairs[i])
|
||||
if err != nil {
|
||||
return cancelAllOrdersResponse, err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_, err := b.FuturesCancelAllOpenOrders(req.Pair)
|
||||
_, err := b.FuturesCancelAllOpenOrders(ctx, req.Pair)
|
||||
if err != nil {
|
||||
return cancelAllOrdersResponse, err
|
||||
}
|
||||
@@ -1089,13 +1096,13 @@ func (b *Binance) CancelAllOrders(req *order.Cancel) (order.CancelAllResponse, e
|
||||
return cancelAllOrdersResponse, err
|
||||
}
|
||||
for i := range enabledPairs {
|
||||
_, err = b.UCancelAllOpenOrders(enabledPairs[i])
|
||||
_, err = b.UCancelAllOpenOrders(ctx, enabledPairs[i])
|
||||
if err != nil {
|
||||
return cancelAllOrdersResponse, err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_, err := b.UCancelAllOpenOrders(req.Pair)
|
||||
_, err := b.UCancelAllOpenOrders(ctx, req.Pair)
|
||||
if err != nil {
|
||||
return cancelAllOrdersResponse, err
|
||||
}
|
||||
@@ -1107,7 +1114,7 @@ func (b *Binance) CancelAllOrders(req *order.Cancel) (order.CancelAllResponse, e
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (b *Binance) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
func (b *Binance) GetOrderInfo(ctx context.Context, orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
var respData order.Detail
|
||||
orderIDInt, err := strconv.ParseInt(orderID, 10, 64)
|
||||
if err != nil {
|
||||
@@ -1115,7 +1122,7 @@ func (b *Binance) GetOrderInfo(orderID string, pair currency.Pair, assetType ass
|
||||
}
|
||||
switch assetType {
|
||||
case asset.Spot:
|
||||
resp, err := b.QueryOrder(pair, "", orderIDInt)
|
||||
resp, err := b.QueryOrder(ctx, pair, "", orderIDInt)
|
||||
if err != nil {
|
||||
return respData, err
|
||||
}
|
||||
@@ -1146,7 +1153,7 @@ func (b *Binance) GetOrderInfo(orderID string, pair currency.Pair, assetType ass
|
||||
LastUpdated: resp.UpdateTime,
|
||||
}, nil
|
||||
case asset.CoinMarginedFutures:
|
||||
orderData, err := b.FuturesOpenOrderData(pair, orderID, "")
|
||||
orderData, err := b.FuturesOpenOrderData(ctx, pair, orderID, "")
|
||||
if err != nil {
|
||||
return respData, err
|
||||
}
|
||||
@@ -1154,7 +1161,7 @@ func (b *Binance) GetOrderInfo(orderID string, pair currency.Pair, assetType ass
|
||||
feeBuilder.Amount = orderData.ExecutedQuantity
|
||||
feeBuilder.PurchasePrice = orderData.AveragePrice
|
||||
feeBuilder.Pair = pair
|
||||
fee, err := b.GetFee(&feeBuilder)
|
||||
fee, err := b.GetFee(ctx, &feeBuilder)
|
||||
if err != nil {
|
||||
return respData, err
|
||||
}
|
||||
@@ -1175,7 +1182,7 @@ func (b *Binance) GetOrderInfo(orderID string, pair currency.Pair, assetType ass
|
||||
respData.Date = orderData.Time
|
||||
respData.LastUpdated = orderData.UpdateTime
|
||||
case asset.USDTMarginedFutures:
|
||||
orderData, err := b.UGetOrderData(pair, orderID, "")
|
||||
orderData, err := b.UGetOrderData(ctx, pair, orderID, "")
|
||||
if err != nil {
|
||||
return respData, err
|
||||
}
|
||||
@@ -1183,7 +1190,7 @@ func (b *Binance) GetOrderInfo(orderID string, pair currency.Pair, assetType ass
|
||||
feeBuilder.Amount = orderData.ExecutedQuantity
|
||||
feeBuilder.PurchasePrice = orderData.AveragePrice
|
||||
feeBuilder.Pair = pair
|
||||
fee, err := b.GetFee(&feeBuilder)
|
||||
fee, err := b.GetFee(ctx, &feeBuilder)
|
||||
if err != nil {
|
||||
return respData, err
|
||||
}
|
||||
@@ -1210,18 +1217,19 @@ func (b *Binance) GetOrderInfo(orderID string, pair currency.Pair, assetType ass
|
||||
}
|
||||
|
||||
// GetDepositAddress returns a deposit address for a specified currency
|
||||
func (b *Binance) GetDepositAddress(cryptocurrency currency.Code, _ string) (string, error) {
|
||||
return b.GetDepositAddressForCurrency(cryptocurrency.String())
|
||||
func (b *Binance) GetDepositAddress(ctx context.Context, cryptocurrency currency.Code, _ string) (string, error) {
|
||||
return b.GetDepositAddressForCurrency(ctx, cryptocurrency.String())
|
||||
}
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (b *Binance) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
func (b *Binance) WithdrawCryptocurrencyFunds(ctx context.Context, withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
if err := withdrawRequest.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
amountStr := strconv.FormatFloat(withdrawRequest.Amount, 'f', -1, 64)
|
||||
v, err := b.WithdrawCrypto(withdrawRequest.Currency.String(),
|
||||
v, err := b.WithdrawCrypto(ctx,
|
||||
withdrawRequest.Currency.String(),
|
||||
withdrawRequest.Crypto.Address,
|
||||
withdrawRequest.Crypto.AddressTag,
|
||||
withdrawRequest.Description, amountStr)
|
||||
@@ -1235,27 +1243,27 @@ func (b *Binance) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request)
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (b *Binance) WithdrawFiatFunds(_ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
func (b *Binance) WithdrawFiatFunds(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (b *Binance) WithdrawFiatFundsToInternationalBank(_ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
func (b *Binance) WithdrawFiatFundsToInternationalBank(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetFeeByType returns an estimate of fee based on type of transaction
|
||||
func (b *Binance) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error) {
|
||||
func (b *Binance) GetFeeByType(ctx context.Context, feeBuilder *exchange.FeeBuilder) (float64, error) {
|
||||
if (!b.AllowAuthenticatedRequest() || b.SkipAuthCheck) && // Todo check connection status
|
||||
feeBuilder.FeeType == exchange.CryptocurrencyTradeFee {
|
||||
feeBuilder.FeeType = exchange.OfflineTradeFee
|
||||
}
|
||||
return b.GetFee(feeBuilder)
|
||||
return b.GetFee(ctx, feeBuilder)
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (b *Binance) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
func (b *Binance) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1267,7 +1275,7 @@ func (b *Binance) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail,
|
||||
for i := range req.Pairs {
|
||||
switch req.AssetType {
|
||||
case asset.Spot, asset.Margin:
|
||||
resp, err := b.OpenOrders(req.Pairs[i])
|
||||
resp, err := b.OpenOrders(ctx, req.Pairs[i])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1290,7 +1298,7 @@ func (b *Binance) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail,
|
||||
})
|
||||
}
|
||||
case asset.CoinMarginedFutures:
|
||||
openOrders, err := b.GetFuturesAllOpenOrders(req.Pairs[i], "")
|
||||
openOrders, err := b.GetFuturesAllOpenOrders(ctx, req.Pairs[i], "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1299,7 +1307,7 @@ func (b *Binance) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail,
|
||||
feeBuilder.Amount = openOrders[y].ExecutedQty
|
||||
feeBuilder.PurchasePrice = openOrders[y].AvgPrice
|
||||
feeBuilder.Pair = req.Pairs[i]
|
||||
fee, err := b.GetFee(&feeBuilder)
|
||||
fee, err := b.GetFee(ctx, &feeBuilder)
|
||||
if err != nil {
|
||||
return orders, err
|
||||
}
|
||||
@@ -1323,7 +1331,7 @@ func (b *Binance) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail,
|
||||
})
|
||||
}
|
||||
case asset.USDTMarginedFutures:
|
||||
openOrders, err := b.UAllAccountOpenOrders(req.Pairs[i])
|
||||
openOrders, err := b.UAllAccountOpenOrders(ctx, req.Pairs[i])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1332,7 +1340,7 @@ func (b *Binance) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail,
|
||||
feeBuilder.Amount = openOrders[y].ExecutedQuantity
|
||||
feeBuilder.PurchasePrice = openOrders[y].AveragePrice
|
||||
feeBuilder.Pair = req.Pairs[i]
|
||||
fee, err := b.GetFee(&feeBuilder)
|
||||
fee, err := b.GetFee(ctx, &feeBuilder)
|
||||
if err != nil {
|
||||
return orders, err
|
||||
}
|
||||
@@ -1368,7 +1376,7 @@ func (b *Binance) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail,
|
||||
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
func (b *Binance) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
func (b *Binance) GetOrderHistory(ctx context.Context, req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1379,7 +1387,8 @@ func (b *Binance) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail,
|
||||
switch req.AssetType {
|
||||
case asset.Spot, asset.Margin:
|
||||
for x := range req.Pairs {
|
||||
resp, err := b.AllOrders(req.Pairs[x],
|
||||
resp, err := b.AllOrders(ctx,
|
||||
req.Pairs[x],
|
||||
"",
|
||||
"1000")
|
||||
if err != nil {
|
||||
@@ -1423,7 +1432,8 @@ func (b *Binance) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail,
|
||||
if time.Since(req.StartTime) > time.Hour*24*30 {
|
||||
return nil, fmt.Errorf("can only fetch orders 30 days out")
|
||||
}
|
||||
orderHistory, err = b.GetAllFuturesOrders(req.Pairs[i], "", req.StartTime, req.EndTime, 0, 0)
|
||||
orderHistory, err = b.GetAllFuturesOrders(ctx,
|
||||
req.Pairs[i], "", req.StartTime, req.EndTime, 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1432,7 +1442,8 @@ func (b *Binance) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
orderHistory, err = b.GetAllFuturesOrders(req.Pairs[i], "", time.Time{}, time.Time{}, fromID, 0)
|
||||
orderHistory, err = b.GetAllFuturesOrders(ctx,
|
||||
req.Pairs[i], "", time.Time{}, time.Time{}, fromID, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1444,7 +1455,7 @@ func (b *Binance) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail,
|
||||
feeBuilder.Amount = orderHistory[y].ExecutedQty
|
||||
feeBuilder.PurchasePrice = orderHistory[y].AvgPrice
|
||||
feeBuilder.Pair = req.Pairs[i]
|
||||
fee, err := b.GetFee(&feeBuilder)
|
||||
fee, err := b.GetFee(ctx, &feeBuilder)
|
||||
if err != nil {
|
||||
return orders, err
|
||||
}
|
||||
@@ -1479,7 +1490,8 @@ func (b *Binance) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail,
|
||||
if time.Since(req.StartTime) > time.Hour*24*7 {
|
||||
return nil, fmt.Errorf("can only fetch orders 7 days out")
|
||||
}
|
||||
orderHistory, err = b.UAllAccountOrders(req.Pairs[i], 0, 0, req.StartTime, req.EndTime)
|
||||
orderHistory, err = b.UAllAccountOrders(ctx,
|
||||
req.Pairs[i], 0, 0, req.StartTime, req.EndTime)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1488,7 +1500,8 @@ func (b *Binance) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
orderHistory, err = b.UAllAccountOrders(req.Pairs[i], fromID, 0, time.Time{}, time.Time{})
|
||||
orderHistory, err = b.UAllAccountOrders(ctx,
|
||||
req.Pairs[i], fromID, 0, time.Time{}, time.Time{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1500,7 +1513,7 @@ func (b *Binance) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail,
|
||||
feeBuilder.Amount = orderHistory[y].ExecutedQty
|
||||
feeBuilder.PurchasePrice = orderHistory[y].AvgPrice
|
||||
feeBuilder.Pair = req.Pairs[i]
|
||||
fee, err := b.GetFee(&feeBuilder)
|
||||
fee, err := b.GetFee(ctx, &feeBuilder)
|
||||
if err != nil {
|
||||
return orders, err
|
||||
}
|
||||
@@ -1534,8 +1547,8 @@ func (b *Binance) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail,
|
||||
|
||||
// ValidateCredentials validates current credentials used for wrapper
|
||||
// functionality
|
||||
func (b *Binance) ValidateCredentials(assetType asset.Item) error {
|
||||
_, err := b.UpdateAccountInfo(assetType)
|
||||
func (b *Binance) ValidateCredentials(ctx context.Context, assetType asset.Item) error {
|
||||
_, err := b.UpdateAccountInfo(ctx, assetType)
|
||||
return b.CheckTransientError(err)
|
||||
}
|
||||
|
||||
@@ -1556,7 +1569,7 @@ func (b *Binance) FormatExchangeKlineInterval(interval kline.Interval) string {
|
||||
}
|
||||
|
||||
// GetHistoricCandles returns candles between a time period for a set time interval
|
||||
func (b *Binance) GetHistoricCandles(pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
|
||||
func (b *Binance) GetHistoricCandles(ctx context.Context, pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
|
||||
if err := b.ValidateKline(pair, a, interval); err != nil {
|
||||
return kline.Item{}, err
|
||||
}
|
||||
@@ -1577,7 +1590,7 @@ func (b *Binance) GetHistoricCandles(pair currency.Pair, a asset.Item, start, en
|
||||
Interval: interval,
|
||||
}
|
||||
|
||||
candles, err := b.GetSpotKline(&req)
|
||||
candles, err := b.GetSpotKline(ctx, &req)
|
||||
if err != nil {
|
||||
return kline.Item{}, err
|
||||
}
|
||||
@@ -1596,7 +1609,7 @@ func (b *Binance) GetHistoricCandles(pair currency.Pair, a asset.Item, start, en
|
||||
}
|
||||
|
||||
// GetHistoricCandlesExtended returns candles between a time period for a set time interval
|
||||
func (b *Binance) GetHistoricCandlesExtended(pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
|
||||
func (b *Binance) GetHistoricCandlesExtended(ctx context.Context, pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
|
||||
if err := b.ValidateKline(pair, a, interval); err != nil {
|
||||
return kline.Item{}, err
|
||||
}
|
||||
@@ -1621,7 +1634,7 @@ func (b *Binance) GetHistoricCandlesExtended(pair currency.Pair, a asset.Item, s
|
||||
Limit: int(b.Features.Enabled.Kline.ResultLimit),
|
||||
}
|
||||
|
||||
candles, err = b.GetSpotKline(&req)
|
||||
candles, err = b.GetSpotKline(ctx, &req)
|
||||
if err != nil {
|
||||
return kline.Item{}, err
|
||||
}
|
||||
@@ -1698,19 +1711,19 @@ func compatibleOrderVars(side, status, orderType string) OrderVars {
|
||||
}
|
||||
|
||||
// UpdateOrderExecutionLimits sets exchange executions for a required asset type
|
||||
func (b *Binance) UpdateOrderExecutionLimits(a asset.Item) error {
|
||||
func (b *Binance) UpdateOrderExecutionLimits(ctx context.Context, a asset.Item) error {
|
||||
var limits []order.MinMaxLevel
|
||||
var err error
|
||||
switch a {
|
||||
case asset.Spot:
|
||||
limits, err = b.FetchSpotExchangeLimits()
|
||||
limits, err = b.FetchSpotExchangeLimits(ctx)
|
||||
case asset.USDTMarginedFutures:
|
||||
limits, err = b.FetchUSDTMarginExchangeLimits()
|
||||
limits, err = b.FetchUSDTMarginExchangeLimits(ctx)
|
||||
case asset.CoinMarginedFutures:
|
||||
limits, err = b.FetchCoinMarginExchangeLimits()
|
||||
limits, err = b.FetchCoinMarginExchangeLimits(ctx)
|
||||
case asset.Margin:
|
||||
if err = b.CurrencyPairs.IsAssetEnabled(asset.Spot); err != nil {
|
||||
limits, err = b.FetchSpotExchangeLimits()
|
||||
limits, err = b.FetchSpotExchangeLimits(ctx)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user