mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-07 23:16:53 +00:00
cmd/exchange_template, exchanges: Update templates and propogate to exchanges (#1777)
* Added TimeInForce type and updated related files * Linter issue fix and minor coinbasepro type update * Bitrex consts update * added unit test and minor changes in bittrex * Unit tests update * Fix minor linter issues * Update TestStringToTimeInForce unit test * Exchange test template change * A different approach * fix conflict with gateio timeInForce * minor exchange template update * Minor fix to test_files template * Update order tests * Complete updating the order unit tests * Updating exchange wrapper and test template files * update kucoin and deribit wrapper to match the time in force change * minor comment update * fix time-in-force related test errors * linter issue fix * ADD_NEW_EXCHANGE documentation update * time in force constants, functions and unit tests update * shift tif policies to TimeInForce * Update time-in-force, related functions, and unit tests * fix linter issue and time-in-force processing * added a good till crossing tif value * order type fix and fix related tim-in-force entries * update time-in-force unmarshaling and unit test * consistency guideline added * fix time-in-force error in gateio * linter issue fix * update based on review comments * add unit test and fix missing issues * minor fix and added benchmark unit test * change GTT to GTC for limit * fix linter issue * added time-in-force value to place order param * fix minor issues based on review comment and move tif code to separate files * update on exchanges linked to time-in-force * resolve missing review comments * minor linter issues fix * added time-in-force handler and update timeInForce parametered endpoint * minor fixes based on review * nits fix * update based on review * linter fix * rm getTimeInForce func and minor change to time-in-force * minor change * update based on review comments * wrappers and time-in-force calling approach * minor change * update gateio string to timeInForce conversion and unit test * update exchange template * update wrapper template file * policy comments, and template files update * rename all exchange types name to Exchange * update on template files and template generation * templates and generation code and other updates * linter issue fix * added subscriptions and websocket templates * update ADD_NEW_EXCHANGE.md with recent binance functions and implementations * rename template files and update unit tests * minor template and unit test fix * rename templates and fix on unit tests * update on template files and documentation * removed unnecessary tag fix and update templates * fix Add_NEW_EXCHANGE.md doc file * formatting, comments, and error checks update on template files * rename exchange receivers to e and ex for consistency * rename unit test exchange receiver and minor updates * linter issues fix * fix deribit issue and minor style update * fix test issues caused by receiver change * raname local variables exchange declaration variables * update templates comments * update templates and related comments * renamed ex to e * update template comments * toggle WS to false to improve coverage * template comments update * added test coverage to Ws enabled and minor changes --------- Co-authored-by: Samuel Reid <43227667+cranktakular@users.noreply.github.com>
This commit is contained in:
@@ -23,8 +23,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
)
|
||||
|
||||
// Binance is the overarching type across the Binance package
|
||||
type Binance struct {
|
||||
// Exchange implements exchange.IBotExchange and contains additional specific api methods for interacting with Binance
|
||||
type Exchange struct {
|
||||
exchange.Base
|
||||
obm *orderbookManager
|
||||
}
|
||||
@@ -110,9 +110,9 @@ var (
|
||||
|
||||
// GetExchangeInfo returns exchange information. Check binance_types for more
|
||||
// information
|
||||
func (b *Binance) GetExchangeInfo(ctx context.Context) (ExchangeInfo, error) {
|
||||
func (e *Exchange) GetExchangeInfo(ctx context.Context) (ExchangeInfo, error) {
|
||||
var resp ExchangeInfo
|
||||
return resp, b.SendHTTPRequest(ctx,
|
||||
return resp, e.SendHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary, exchangeInfo, spotExchangeInfo, &resp)
|
||||
}
|
||||
|
||||
@@ -121,9 +121,9 @@ func (b *Binance) GetExchangeInfo(ctx context.Context) (ExchangeInfo, error) {
|
||||
// OrderBookDataRequestParams contains the following members
|
||||
// symbol: string of currency pair
|
||||
// limit: returned limit amount
|
||||
func (b *Binance) GetOrderBook(ctx context.Context, obd OrderBookDataRequestParams) (*OrderBook, error) {
|
||||
func (e *Exchange) GetOrderBook(ctx context.Context, obd OrderBookDataRequestParams) (*OrderBook, error) {
|
||||
params := url.Values{}
|
||||
symbol, err := b.FormatSymbol(obd.Symbol, asset.Spot)
|
||||
symbol, err := e.FormatSymbol(obd.Symbol, asset.Spot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -131,7 +131,7 @@ func (b *Binance) GetOrderBook(ctx context.Context, obd OrderBookDataRequestPara
|
||||
params.Set("limit", strconv.Itoa(obd.Limit))
|
||||
|
||||
var resp *OrderBookData
|
||||
if err := b.SendHTTPRequest(ctx, exchange.RestSpotSupplementary, common.EncodeURLValues(orderBookDepth, params), orderbookLimit(obd.Limit), &resp); err != nil {
|
||||
if err := e.SendHTTPRequest(ctx, exchange.RestSpotSupplementary, common.EncodeURLValues(orderBookDepth, params), orderbookLimit(obd.Limit), &resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -155,9 +155,9 @@ func (b *Binance) GetOrderBook(ctx context.Context, obd OrderBookDataRequestPara
|
||||
|
||||
// GetMostRecentTrades returns recent trade activity
|
||||
// limit: Up to 500 results returned
|
||||
func (b *Binance) GetMostRecentTrades(ctx context.Context, rtr RecentTradeRequestParams) ([]RecentTrade, error) {
|
||||
func (e *Exchange) GetMostRecentTrades(ctx context.Context, rtr RecentTradeRequestParams) ([]RecentTrade, error) {
|
||||
params := url.Values{}
|
||||
symbol, err := b.FormatSymbol(rtr.Symbol, asset.Spot)
|
||||
symbol, err := e.FormatSymbol(rtr.Symbol, asset.Spot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -167,7 +167,7 @@ func (b *Binance) GetMostRecentTrades(ctx context.Context, rtr RecentTradeReques
|
||||
path := recentTrades + "?" + params.Encode()
|
||||
|
||||
var resp []RecentTrade
|
||||
return resp, b.SendHTTPRequest(ctx,
|
||||
return resp, e.SendHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary, path, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ func (b *Binance) GetMostRecentTrades(ctx context.Context, rtr RecentTradeReques
|
||||
// symbol: string of currency pair
|
||||
// limit: Optional. Default 500; max 1000.
|
||||
// fromID:
|
||||
func (b *Binance) GetHistoricalTrades(ctx context.Context, symbol string, limit int, fromID int64) ([]HistoricalTrade, error) {
|
||||
func (e *Exchange) GetHistoricalTrades(ctx context.Context, symbol string, limit int, fromID int64) ([]HistoricalTrade, error) {
|
||||
var resp []HistoricalTrade
|
||||
params := url.Values{}
|
||||
|
||||
@@ -189,18 +189,18 @@ func (b *Binance) GetHistoricalTrades(ctx context.Context, symbol string, limit
|
||||
|
||||
path := historicalTrades + "?" + params.Encode()
|
||||
return resp,
|
||||
b.SendAPIKeyHTTPRequest(ctx, exchange.RestSpotSupplementary, path, spotDefaultRate, &resp)
|
||||
e.SendAPIKeyHTTPRequest(ctx, exchange.RestSpotSupplementary, path, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetUserMarginInterestHistory returns margin interest history for the user
|
||||
func (b *Binance) GetUserMarginInterestHistory(ctx context.Context, assetCurrency currency.Code, isolatedSymbol currency.Pair, startTime, endTime time.Time, currentPage, size int64, archived bool) (*UserMarginInterestHistoryResponse, error) {
|
||||
func (e *Exchange) GetUserMarginInterestHistory(ctx context.Context, assetCurrency currency.Code, isolatedSymbol currency.Pair, startTime, endTime time.Time, currentPage, size int64, archived bool) (*UserMarginInterestHistoryResponse, error) {
|
||||
params := url.Values{}
|
||||
|
||||
if !assetCurrency.IsEmpty() {
|
||||
params.Set("asset", assetCurrency.String())
|
||||
}
|
||||
if !isolatedSymbol.IsEmpty() {
|
||||
fPair, err := b.FormatSymbol(isolatedSymbol, asset.Margin)
|
||||
fPair, err := e.FormatSymbol(isolatedSymbol, asset.Margin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -224,14 +224,14 @@ func (b *Binance) GetUserMarginInterestHistory(ctx context.Context, assetCurrenc
|
||||
|
||||
path := marginInterestHistory + "?" + params.Encode()
|
||||
var resp UserMarginInterestHistoryResponse
|
||||
return &resp, b.SendAPIKeyHTTPRequest(ctx, exchange.RestSpotSupplementary, path, spotDefaultRate, &resp)
|
||||
return &resp, e.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(ctx context.Context, arg *AggregatedTradeRequestParams) ([]AggregatedTrade, error) {
|
||||
func (e *Exchange) GetAggregatedTrades(ctx context.Context, arg *AggregatedTradeRequestParams) ([]AggregatedTrade, error) {
|
||||
params := url.Values{}
|
||||
params.Set("symbol", arg.Symbol.String())
|
||||
// If the user request is directly not supported by the exchange, we might be able to fulfill it
|
||||
@@ -259,7 +259,7 @@ func (b *Binance) GetAggregatedTrades(ctx context.Context, arg *AggregatedTradeR
|
||||
canBatch := arg.FromID == 0 != arg.StartTime.IsZero()
|
||||
if canBatch {
|
||||
// Split the request into multiple
|
||||
return b.batchAggregateTrades(ctx, arg, params)
|
||||
return e.batchAggregateTrades(ctx, arg, params)
|
||||
}
|
||||
|
||||
// Can't handle this request locally or remotely
|
||||
@@ -268,14 +268,14 @@ func (b *Binance) GetAggregatedTrades(ctx context.Context, arg *AggregatedTradeR
|
||||
}
|
||||
var resp []AggregatedTrade
|
||||
path := aggregatedTrades + "?" + params.Encode()
|
||||
return resp, b.SendHTTPRequest(ctx,
|
||||
return resp, e.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(ctx context.Context, arg *AggregatedTradeRequestParams, params url.Values) ([]AggregatedTrade, error) {
|
||||
func (e *Exchange) 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 {
|
||||
@@ -298,7 +298,7 @@ func (b *Binance) batchAggregateTrades(ctx context.Context, arg *AggregatedTrade
|
||||
params.Set("startTime", strconv.FormatInt(start.UnixMilli(), 10))
|
||||
params.Set("endTime", strconv.FormatInt(start.Add(increment).UnixMilli(), 10))
|
||||
path := aggregatedTrades + "?" + params.Encode()
|
||||
err := b.SendHTTPRequest(ctx,
|
||||
err := e.SendHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary, path, spotDefaultRate, &resp)
|
||||
if err != nil {
|
||||
return resp, fmt.Errorf("%w %v", err, arg.Symbol)
|
||||
@@ -316,7 +316,7 @@ func (b *Binance) batchAggregateTrades(ctx context.Context, arg *AggregatedTrade
|
||||
params.Set("fromId", strconv.FormatInt(fromID, 10))
|
||||
path := aggregatedTrades + "?" + params.Encode()
|
||||
var additionalTrades []AggregatedTrade
|
||||
err := b.SendHTTPRequest(ctx,
|
||||
err := e.SendHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary,
|
||||
path,
|
||||
spotDefaultRate,
|
||||
@@ -354,8 +354,8 @@ func (b *Binance) batchAggregateTrades(ctx context.Context, arg *AggregatedTrade
|
||||
// interval: the interval time for the data
|
||||
// startTime: startTime filter for kline data
|
||||
// endTime: endTime filter for the kline data
|
||||
func (b *Binance) GetSpotKline(ctx context.Context, arg *KlinesRequestParams) ([]CandleStick, error) {
|
||||
symbol, err := b.FormatSymbol(arg.Symbol, asset.Spot)
|
||||
func (e *Exchange) GetSpotKline(ctx context.Context, arg *KlinesRequestParams) ([]CandleStick, error) {
|
||||
symbol, err := e.FormatSymbol(arg.Symbol, asset.Spot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -373,16 +373,16 @@ func (b *Binance) GetSpotKline(ctx context.Context, arg *KlinesRequestParams) ([
|
||||
params.Set("endTime", strconv.FormatInt(arg.EndTime.UnixMilli(), 10))
|
||||
}
|
||||
var resp []CandleStick
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestSpotSupplementary, common.EncodeURLValues(candleStick, params), spotDefaultRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestSpotSupplementary, common.EncodeURLValues(candleStick, params), spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetAveragePrice returns current average price for a symbol.
|
||||
//
|
||||
// symbol: string of currency pair
|
||||
func (b *Binance) GetAveragePrice(ctx context.Context, symbol currency.Pair) (AveragePrice, error) {
|
||||
func (e *Exchange) GetAveragePrice(ctx context.Context, symbol currency.Pair) (AveragePrice, error) {
|
||||
resp := AveragePrice{}
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.Spot)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.Spot)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -390,20 +390,20 @@ func (b *Binance) GetAveragePrice(ctx context.Context, symbol currency.Pair) (Av
|
||||
|
||||
path := averagePrice + "?" + params.Encode()
|
||||
|
||||
return resp, b.SendHTTPRequest(ctx,
|
||||
return resp, e.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(ctx context.Context, symbol currency.Pair) (*PriceChangeStats, error) {
|
||||
func (e *Exchange) GetPriceChangeStats(ctx context.Context, symbol currency.Pair) (*PriceChangeStats, error) {
|
||||
resp := PriceChangeStats{}
|
||||
params := url.Values{}
|
||||
rateLimit := spotTickerAllRate
|
||||
if !symbol.IsEmpty() {
|
||||
rateLimit = spotTicker1Rate
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.Spot)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.Spot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -411,11 +411,11 @@ func (b *Binance) GetPriceChangeStats(ctx context.Context, symbol currency.Pair)
|
||||
}
|
||||
path := priceChange + "?" + params.Encode()
|
||||
|
||||
return &resp, b.SendHTTPRequest(ctx, exchange.RestSpotSupplementary, path, rateLimit, &resp)
|
||||
return &resp, e.SendHTTPRequest(ctx, exchange.RestSpotSupplementary, path, rateLimit, &resp)
|
||||
}
|
||||
|
||||
// GetTickers returns the ticker data for the last 24 hrs
|
||||
func (b *Binance) GetTickers(ctx context.Context, symbols ...currency.Pair) ([]PriceChangeStats, error) {
|
||||
func (e *Exchange) GetTickers(ctx context.Context, symbols ...currency.Pair) ([]PriceChangeStats, error) {
|
||||
var resp []PriceChangeStats
|
||||
symbolLength := len(symbols)
|
||||
params := url.Values{}
|
||||
@@ -434,7 +434,7 @@ func (b *Binance) GetTickers(ctx context.Context, symbols ...currency.Pair) ([]P
|
||||
if symbolLength > 0 {
|
||||
symbolValues := make([]string, symbolLength)
|
||||
for i := range symbols {
|
||||
symbolValue, err := b.FormatSymbol(symbols[i], asset.Spot)
|
||||
symbolValue, err := e.FormatSymbol(symbols[i], asset.Spot)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -443,19 +443,19 @@ func (b *Binance) GetTickers(ctx context.Context, symbols ...currency.Pair) ([]P
|
||||
params.Set("symbols", "["+strings.Join(symbolValues, ",")+"]")
|
||||
path += "?" + params.Encode()
|
||||
}
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestSpotSupplementary, path, rl, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestSpotSupplementary, path, rl, &resp)
|
||||
}
|
||||
|
||||
// GetLatestSpotPrice returns latest spot price of symbol
|
||||
//
|
||||
// symbol: string of currency pair
|
||||
func (b *Binance) GetLatestSpotPrice(ctx context.Context, symbol currency.Pair) (SymbolPrice, error) {
|
||||
func (e *Exchange) GetLatestSpotPrice(ctx context.Context, symbol currency.Pair) (SymbolPrice, error) {
|
||||
resp := SymbolPrice{}
|
||||
params := url.Values{}
|
||||
rateLimit := spotTickerAllRate
|
||||
if !symbol.IsEmpty() {
|
||||
rateLimit = spotDefaultRate
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.Spot)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.Spot)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -464,19 +464,19 @@ func (b *Binance) GetLatestSpotPrice(ctx context.Context, symbol currency.Pair)
|
||||
path := symbolPrice + "?" + params.Encode()
|
||||
|
||||
return resp,
|
||||
b.SendHTTPRequest(ctx, exchange.RestSpotSupplementary, path, rateLimit, &resp)
|
||||
e.SendHTTPRequest(ctx, exchange.RestSpotSupplementary, path, rateLimit, &resp)
|
||||
}
|
||||
|
||||
// GetBestPrice returns the latest best price for symbol
|
||||
//
|
||||
// symbol: string of currency pair
|
||||
func (b *Binance) GetBestPrice(ctx context.Context, symbol currency.Pair) (BestPrice, error) {
|
||||
func (e *Exchange) GetBestPrice(ctx context.Context, symbol currency.Pair) (BestPrice, error) {
|
||||
resp := BestPrice{}
|
||||
params := url.Values{}
|
||||
rateLimit := spotOrderbookTickerAllRate
|
||||
if !symbol.IsEmpty() {
|
||||
rateLimit = spotDefaultRate
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.Spot)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.Spot)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -485,13 +485,13 @@ func (b *Binance) GetBestPrice(ctx context.Context, symbol currency.Pair) (BestP
|
||||
path := bestPrice + "?" + params.Encode()
|
||||
|
||||
return resp,
|
||||
b.SendHTTPRequest(ctx, exchange.RestSpotSupplementary, path, rateLimit, &resp)
|
||||
e.SendHTTPRequest(ctx, exchange.RestSpotSupplementary, path, rateLimit, &resp)
|
||||
}
|
||||
|
||||
// NewOrder sends a new order to Binance
|
||||
func (b *Binance) NewOrder(ctx context.Context, o *NewOrderRequest) (NewOrderResponse, error) {
|
||||
func (e *Exchange) NewOrder(ctx context.Context, o *NewOrderRequest) (NewOrderResponse, error) {
|
||||
var resp NewOrderResponse
|
||||
if err := b.newOrder(ctx, orderEndpoint, o, &resp); err != nil {
|
||||
if err := e.newOrder(ctx, orderEndpoint, o, &resp); err != nil {
|
||||
return resp, err
|
||||
}
|
||||
|
||||
@@ -503,14 +503,14 @@ func (b *Binance) NewOrder(ctx context.Context, o *NewOrderRequest) (NewOrderRes
|
||||
}
|
||||
|
||||
// NewOrderTest sends a new test order to Binance
|
||||
func (b *Binance) NewOrderTest(ctx context.Context, o *NewOrderRequest) error {
|
||||
func (e *Exchange) NewOrderTest(ctx context.Context, o *NewOrderRequest) error {
|
||||
var resp NewOrderResponse
|
||||
return b.newOrder(ctx, newOrderTest, o, &resp)
|
||||
return e.newOrder(ctx, newOrderTest, o, &resp)
|
||||
}
|
||||
|
||||
func (b *Binance) newOrder(ctx context.Context, api string, o *NewOrderRequest, resp *NewOrderResponse) error {
|
||||
func (e *Exchange) newOrder(ctx context.Context, api string, o *NewOrderRequest, resp *NewOrderResponse) error {
|
||||
params := url.Values{}
|
||||
symbol, err := b.FormatSymbol(o.Symbol, asset.Spot)
|
||||
symbol, err := e.FormatSymbol(o.Symbol, asset.Spot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -544,14 +544,14 @@ func (b *Binance) newOrder(ctx context.Context, api string, o *NewOrderRequest,
|
||||
if o.NewOrderRespType != "" {
|
||||
params.Set("newOrderRespType", o.NewOrderRespType)
|
||||
}
|
||||
return b.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodPost, api, params, spotOrderRate, resp)
|
||||
return e.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodPost, api, params, spotOrderRate, resp)
|
||||
}
|
||||
|
||||
// CancelExistingOrder sends a cancel order to Binance
|
||||
func (b *Binance) CancelExistingOrder(ctx context.Context, symbol currency.Pair, orderID int64, origClientOrderID string) (CancelOrderResponse, error) {
|
||||
func (e *Exchange) CancelExistingOrder(ctx context.Context, symbol currency.Pair, orderID int64, origClientOrderID string) (CancelOrderResponse, error) {
|
||||
var resp CancelOrderResponse
|
||||
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.Spot)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.Spot)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -565,19 +565,19 @@ func (b *Binance) CancelExistingOrder(ctx context.Context, symbol currency.Pair,
|
||||
if origClientOrderID != "" {
|
||||
params.Set("origClientOrderId", origClientOrderID)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodDelete, orderEndpoint, params, spotOrderRate, &resp)
|
||||
return resp, e.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(ctx context.Context, pair currency.Pair) ([]QueryOrderData, error) {
|
||||
func (e *Exchange) OpenOrders(ctx context.Context, pair currency.Pair) ([]QueryOrderData, error) {
|
||||
var resp []QueryOrderData
|
||||
params := url.Values{}
|
||||
var p string
|
||||
var err error
|
||||
if !pair.IsEmpty() {
|
||||
p, err = b.FormatSymbol(pair, asset.Spot)
|
||||
p, err = e.FormatSymbol(pair, asset.Spot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -587,7 +587,7 @@ func (b *Binance) OpenOrders(ctx context.Context, pair currency.Pair) ([]QueryOr
|
||||
// error
|
||||
params.Set("recvWindow", "10000")
|
||||
}
|
||||
if err := b.SendAuthHTTPRequest(ctx,
|
||||
if err := e.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary,
|
||||
http.MethodGet,
|
||||
openOrders,
|
||||
@@ -603,11 +603,11 @@ func (b *Binance) OpenOrders(ctx context.Context, pair currency.Pair) ([]QueryOr
|
||||
// AllOrders Get all account orders; active, canceled, or filled.
|
||||
// orderId optional param
|
||||
// limit optional param, default 500; max 500
|
||||
func (b *Binance) AllOrders(ctx context.Context, symbol currency.Pair, orderID, limit string) ([]QueryOrderData, error) {
|
||||
func (e *Exchange) AllOrders(ctx context.Context, symbol currency.Pair, orderID, limit string) ([]QueryOrderData, error) {
|
||||
var resp []QueryOrderData
|
||||
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.Spot)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.Spot)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -618,7 +618,7 @@ func (b *Binance) AllOrders(ctx context.Context, symbol currency.Pair, orderID,
|
||||
if limit != "" {
|
||||
params.Set("limit", limit)
|
||||
}
|
||||
if err := b.SendAuthHTTPRequest(ctx,
|
||||
if err := e.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary,
|
||||
http.MethodGet,
|
||||
allOrders,
|
||||
@@ -631,11 +631,11 @@ func (b *Binance) AllOrders(ctx context.Context, symbol currency.Pair, orderID,
|
||||
}
|
||||
|
||||
// QueryOrder returns information on a past order
|
||||
func (b *Binance) QueryOrder(ctx context.Context, symbol currency.Pair, origClientOrderID string, orderID int64) (QueryOrderData, error) {
|
||||
func (e *Exchange) QueryOrder(ctx context.Context, symbol currency.Pair, origClientOrderID string, orderID int64) (QueryOrderData, error) {
|
||||
var resp QueryOrderData
|
||||
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.Spot)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.Spot)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -647,7 +647,7 @@ func (b *Binance) QueryOrder(ctx context.Context, symbol currency.Pair, origClie
|
||||
params.Set("orderId", strconv.FormatInt(orderID, 10))
|
||||
}
|
||||
|
||||
if err := b.SendAuthHTTPRequest(ctx,
|
||||
if err := e.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary,
|
||||
http.MethodGet, orderEndpoint,
|
||||
params, spotOrderQueryRate,
|
||||
@@ -662,7 +662,7 @@ func (b *Binance) QueryOrder(ctx context.Context, symbol currency.Pair, origClie
|
||||
}
|
||||
|
||||
// GetAccount returns binance user accounts
|
||||
func (b *Binance) GetAccount(ctx context.Context) (*Account, error) {
|
||||
func (e *Exchange) GetAccount(ctx context.Context) (*Account, error) {
|
||||
type response struct {
|
||||
Response
|
||||
Account
|
||||
@@ -671,7 +671,7 @@ func (b *Binance) GetAccount(ctx context.Context) (*Account, error) {
|
||||
var resp response
|
||||
params := url.Values{}
|
||||
|
||||
if err := b.SendAuthHTTPRequest(ctx,
|
||||
if err := e.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary,
|
||||
http.MethodGet, accountInfo,
|
||||
params, spotAccountInformationRate,
|
||||
@@ -687,11 +687,11 @@ func (b *Binance) GetAccount(ctx context.Context) (*Account, error) {
|
||||
}
|
||||
|
||||
// GetMarginAccount returns account information for margin accounts
|
||||
func (b *Binance) GetMarginAccount(ctx context.Context) (*MarginAccount, error) {
|
||||
func (e *Exchange) GetMarginAccount(ctx context.Context) (*MarginAccount, error) {
|
||||
var resp MarginAccount
|
||||
params := url.Values{}
|
||||
|
||||
if err := b.SendAuthHTTPRequest(ctx,
|
||||
if err := e.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary,
|
||||
http.MethodGet, marginAccountInfo,
|
||||
params, spotAccountInformationRate,
|
||||
@@ -703,8 +703,8 @@ func (b *Binance) GetMarginAccount(ctx context.Context) (*MarginAccount, error)
|
||||
}
|
||||
|
||||
// SendHTTPRequest sends an unauthenticated request
|
||||
func (b *Binance) SendHTTPRequest(ctx context.Context, ePath exchange.URL, path string, f request.EndpointLimit, result any) error {
|
||||
endpointPath, err := b.API.Endpoints.GetURL(ePath)
|
||||
func (e *Exchange) SendHTTPRequest(ctx context.Context, ePath exchange.URL, path string, f request.EndpointLimit, result any) error {
|
||||
endpointPath, err := e.API.Endpoints.GetURL(ePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -712,25 +712,25 @@ func (b *Binance) SendHTTPRequest(ctx context.Context, ePath exchange.URL, path
|
||||
Method: http.MethodGet,
|
||||
Path: endpointPath + path,
|
||||
Result: result,
|
||||
Verbose: b.Verbose,
|
||||
HTTPDebugging: b.HTTPDebugging,
|
||||
HTTPRecording: b.HTTPRecording,
|
||||
Verbose: e.Verbose,
|
||||
HTTPDebugging: e.HTTPDebugging,
|
||||
HTTPRecording: e.HTTPRecording,
|
||||
}
|
||||
|
||||
return b.SendPayload(ctx, f, func() (*request.Item, error) {
|
||||
return e.SendPayload(ctx, f, func() (*request.Item, error) {
|
||||
return item, nil
|
||||
}, request.UnauthenticatedRequest)
|
||||
}
|
||||
|
||||
// SendAPIKeyHTTPRequest is a special API request where the api key is
|
||||
// appended to the headers without a secret
|
||||
func (b *Binance) SendAPIKeyHTTPRequest(ctx context.Context, ePath exchange.URL, path string, f request.EndpointLimit, result any) error {
|
||||
endpointPath, err := b.API.Endpoints.GetURL(ePath)
|
||||
func (e *Exchange) SendAPIKeyHTTPRequest(ctx context.Context, ePath exchange.URL, path string, f request.EndpointLimit, result any) error {
|
||||
endpointPath, err := e.API.Endpoints.GetURL(ePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
creds, err := b.GetCredentials(ctx)
|
||||
creds, err := e.GetCredentials(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -742,24 +742,24 @@ func (b *Binance) SendAPIKeyHTTPRequest(ctx context.Context, ePath exchange.URL,
|
||||
Path: endpointPath + path,
|
||||
Headers: headers,
|
||||
Result: result,
|
||||
Verbose: b.Verbose,
|
||||
HTTPDebugging: b.HTTPDebugging,
|
||||
HTTPRecording: b.HTTPRecording,
|
||||
Verbose: e.Verbose,
|
||||
HTTPDebugging: e.HTTPDebugging,
|
||||
HTTPRecording: e.HTTPRecording,
|
||||
}
|
||||
|
||||
return b.SendPayload(ctx, f, func() (*request.Item, error) {
|
||||
return e.SendPayload(ctx, f, func() (*request.Item, error) {
|
||||
return item, nil
|
||||
}, request.AuthenticatedRequest)
|
||||
}
|
||||
|
||||
// SendAuthHTTPRequest sends an authenticated HTTP request
|
||||
func (b *Binance) SendAuthHTTPRequest(ctx context.Context, ePath exchange.URL, method, path string, params url.Values, f request.EndpointLimit, result any) error {
|
||||
creds, err := b.GetCredentials(ctx)
|
||||
func (e *Exchange) SendAuthHTTPRequest(ctx context.Context, ePath exchange.URL, method, path string, params url.Values, f request.EndpointLimit, result any) error {
|
||||
creds, err := e.GetCredentials(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
endpointPath, err := b.API.Endpoints.GetURL(ePath)
|
||||
endpointPath, err := e.API.Endpoints.GetURL(ePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -773,7 +773,7 @@ func (b *Binance) SendAuthHTTPRequest(ctx context.Context, ePath exchange.URL, m
|
||||
}
|
||||
|
||||
interim := json.RawMessage{}
|
||||
err = b.SendPayload(ctx, f, func() (*request.Item, error) {
|
||||
err = e.SendPayload(ctx, f, func() (*request.Item, error) {
|
||||
params.Set("timestamp", strconv.FormatInt(time.Now().UnixMilli(), 10))
|
||||
hmacSigned, err := crypto.GetHMAC(crypto.HashSHA256, []byte(params.Encode()), []byte(creds.Secret))
|
||||
if err != nil {
|
||||
@@ -787,9 +787,9 @@ func (b *Binance) SendAuthHTTPRequest(ctx context.Context, ePath exchange.URL, m
|
||||
Path: fullPath,
|
||||
Headers: headers,
|
||||
Result: &interim,
|
||||
Verbose: b.Verbose,
|
||||
HTTPDebugging: b.HTTPDebugging,
|
||||
HTTPRecording: b.HTTPRecording,
|
||||
Verbose: e.Verbose,
|
||||
HTTPDebugging: e.HTTPDebugging,
|
||||
HTTPRecording: e.HTTPRecording,
|
||||
}, nil
|
||||
}, request.AuthenticatedRequest)
|
||||
if err != nil {
|
||||
@@ -813,12 +813,12 @@ func (b *Binance) SendAuthHTTPRequest(ctx context.Context, ePath exchange.URL, m
|
||||
}
|
||||
|
||||
// GetFee returns an estimate of fee based on type of transaction
|
||||
func (b *Binance) GetFee(ctx context.Context, feeBuilder *exchange.FeeBuilder) (float64, error) {
|
||||
func (e *Exchange) GetFee(ctx context.Context, feeBuilder *exchange.FeeBuilder) (float64, error) {
|
||||
var fee float64
|
||||
|
||||
switch feeBuilder.FeeType {
|
||||
case exchange.CryptocurrencyTradeFee:
|
||||
multiplier, err := b.getMultiplier(ctx, feeBuilder.IsMaker)
|
||||
multiplier, err := e.getMultiplier(ctx, feeBuilder.IsMaker)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -840,9 +840,9 @@ func getOfflineTradeFee(price, amount float64) float64 {
|
||||
}
|
||||
|
||||
// getMultiplier retrieves account based taker/maker fees
|
||||
func (b *Binance) getMultiplier(ctx context.Context, isMaker bool) (float64, error) {
|
||||
func (e *Exchange) getMultiplier(ctx context.Context, isMaker bool) (float64, error) {
|
||||
var multiplier float64
|
||||
account, err := b.GetAccount(ctx)
|
||||
account, err := e.GetAccount(ctx)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -865,9 +865,9 @@ func getCryptocurrencyWithdrawalFee(c currency.Code) float64 {
|
||||
}
|
||||
|
||||
// GetAllCoinsInfo returns details about all supported coins
|
||||
func (b *Binance) GetAllCoinsInfo(ctx context.Context) ([]CoinInfo, error) {
|
||||
func (e *Exchange) GetAllCoinsInfo(ctx context.Context) ([]CoinInfo, error) {
|
||||
var resp []CoinInfo
|
||||
if err := b.SendAuthHTTPRequest(ctx,
|
||||
if err := e.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary,
|
||||
http.MethodGet,
|
||||
allCoinsInfo,
|
||||
@@ -880,7 +880,7 @@ func (b *Binance) GetAllCoinsInfo(ctx context.Context) ([]CoinInfo, error) {
|
||||
}
|
||||
|
||||
// WithdrawCrypto sends cryptocurrency to the address of your choosing
|
||||
func (b *Binance) WithdrawCrypto(ctx context.Context, cryptoAsset, withdrawOrderID, network, address, addressTag, name, amount string, transactionFeeFlag bool) (string, error) {
|
||||
func (e *Exchange) WithdrawCrypto(ctx context.Context, cryptoAsset, withdrawOrderID, network, address, addressTag, name, amount string, transactionFeeFlag bool) (string, error) {
|
||||
if cryptoAsset == "" || address == "" || amount == "" {
|
||||
return "", errors.New("asset, address and amount must not be empty")
|
||||
}
|
||||
@@ -908,7 +908,7 @@ func (b *Binance) WithdrawCrypto(ctx context.Context, cryptoAsset, withdrawOrder
|
||||
}
|
||||
|
||||
var resp WithdrawResponse
|
||||
if err := b.SendAuthHTTPRequest(ctx,
|
||||
if err := e.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary,
|
||||
http.MethodPost,
|
||||
withdrawEndpoint,
|
||||
@@ -927,7 +927,7 @@ func (b *Binance) WithdrawCrypto(ctx context.Context, cryptoAsset, withdrawOrder
|
||||
|
||||
// DepositHistory returns the deposit history based on the supplied params
|
||||
// status `param` used as string to prevent default value 0 (for int) interpreting as EmailSent status
|
||||
func (b *Binance) DepositHistory(ctx context.Context, c currency.Code, status string, startTime, endTime time.Time, offset, limit int) ([]DepositHistory, error) {
|
||||
func (e *Exchange) DepositHistory(ctx context.Context, c currency.Code, status string, startTime, endTime time.Time, offset, limit int) ([]DepositHistory, error) {
|
||||
var response []DepositHistory
|
||||
|
||||
params := url.Values{}
|
||||
@@ -966,7 +966,7 @@ func (b *Binance) DepositHistory(ctx context.Context, c currency.Code, status st
|
||||
params.Set("limit", strconv.Itoa(limit))
|
||||
}
|
||||
|
||||
if err := b.SendAuthHTTPRequest(ctx,
|
||||
if err := e.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary,
|
||||
http.MethodGet,
|
||||
depositHistory,
|
||||
@@ -981,7 +981,7 @@ func (b *Binance) DepositHistory(ctx context.Context, c currency.Code, status st
|
||||
|
||||
// WithdrawHistory 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) WithdrawHistory(ctx context.Context, c currency.Code, status string, startTime, endTime time.Time, offset, limit int) ([]WithdrawStatusResponse, error) {
|
||||
func (e *Exchange) WithdrawHistory(ctx context.Context, c currency.Code, status string, startTime, endTime time.Time, offset, limit int) ([]WithdrawStatusResponse, error) {
|
||||
params := url.Values{}
|
||||
if !c.IsEmpty() {
|
||||
params.Set("coin", c.String())
|
||||
@@ -1019,7 +1019,7 @@ func (b *Binance) WithdrawHistory(ctx context.Context, c currency.Code, status s
|
||||
}
|
||||
|
||||
var withdrawStatus []WithdrawStatusResponse
|
||||
if err := b.SendAuthHTTPRequest(ctx,
|
||||
if err := e.SendAuthHTTPRequest(ctx,
|
||||
exchange.RestSpotSupplementary,
|
||||
http.MethodGet,
|
||||
withdrawHistory,
|
||||
@@ -1033,7 +1033,7 @@ func (b *Binance) WithdrawHistory(ctx context.Context, c currency.Code, status s
|
||||
}
|
||||
|
||||
// GetDepositAddressForCurrency retrieves the wallet address for a given currency
|
||||
func (b *Binance) GetDepositAddressForCurrency(ctx context.Context, currency, chain string) (*DepositAddress, error) {
|
||||
func (e *Exchange) GetDepositAddressForCurrency(ctx context.Context, currency, chain string) (*DepositAddress, error) {
|
||||
params := url.Values{}
|
||||
params.Set("coin", currency)
|
||||
if chain != "" {
|
||||
@@ -1042,17 +1042,17 @@ func (b *Binance) GetDepositAddressForCurrency(ctx context.Context, currency, ch
|
||||
params.Set("recvWindow", "10000")
|
||||
var d DepositAddress
|
||||
return &d,
|
||||
b.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, depositAddress, params, spotDefaultRate, &d)
|
||||
e.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, depositAddress, params, spotDefaultRate, &d)
|
||||
}
|
||||
|
||||
// GetWsAuthStreamKey will retrieve a key to use for authorised WS streaming
|
||||
func (b *Binance) GetWsAuthStreamKey(ctx context.Context) (string, error) {
|
||||
endpointPath, err := b.API.Endpoints.GetURL(exchange.RestSpotSupplementary)
|
||||
func (e *Exchange) GetWsAuthStreamKey(ctx context.Context) (string, error) {
|
||||
endpointPath, err := e.API.Endpoints.GetURL(exchange.RestSpotSupplementary)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
creds, err := b.GetCredentials(ctx)
|
||||
creds, err := e.GetCredentials(ctx)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -1065,12 +1065,12 @@ func (b *Binance) GetWsAuthStreamKey(ctx context.Context) (string, error) {
|
||||
Path: endpointPath + userAccountStream,
|
||||
Headers: headers,
|
||||
Result: &resp,
|
||||
Verbose: b.Verbose,
|
||||
HTTPDebugging: b.HTTPDebugging,
|
||||
HTTPRecording: b.HTTPRecording,
|
||||
Verbose: e.Verbose,
|
||||
HTTPDebugging: e.HTTPDebugging,
|
||||
HTTPRecording: e.HTTPRecording,
|
||||
}
|
||||
|
||||
err = b.SendPayload(ctx, request.Unset, func() (*request.Item, error) {
|
||||
err = e.SendPayload(ctx, request.Unset, func() (*request.Item, error) {
|
||||
return item, nil
|
||||
}, request.AuthenticatedRequest)
|
||||
if err != nil {
|
||||
@@ -1080,17 +1080,17 @@ func (b *Binance) GetWsAuthStreamKey(ctx context.Context) (string, error) {
|
||||
}
|
||||
|
||||
// MaintainWsAuthStreamKey will keep the key alive
|
||||
func (b *Binance) MaintainWsAuthStreamKey(ctx context.Context) error {
|
||||
endpointPath, err := b.API.Endpoints.GetURL(exchange.RestSpotSupplementary)
|
||||
func (e *Exchange) MaintainWsAuthStreamKey(ctx context.Context) error {
|
||||
endpointPath, err := e.API.Endpoints.GetURL(exchange.RestSpotSupplementary)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if listenKey == "" {
|
||||
listenKey, err = b.GetWsAuthStreamKey(ctx)
|
||||
listenKey, err = e.GetWsAuthStreamKey(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
creds, err := b.GetCredentials(ctx)
|
||||
creds, err := e.GetCredentials(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1105,23 +1105,23 @@ func (b *Binance) MaintainWsAuthStreamKey(ctx context.Context) error {
|
||||
Method: http.MethodPut,
|
||||
Path: path,
|
||||
Headers: headers,
|
||||
Verbose: b.Verbose,
|
||||
HTTPDebugging: b.HTTPDebugging,
|
||||
HTTPRecording: b.HTTPRecording,
|
||||
Verbose: e.Verbose,
|
||||
HTTPDebugging: e.HTTPDebugging,
|
||||
HTTPRecording: e.HTTPRecording,
|
||||
}
|
||||
|
||||
return b.SendPayload(ctx, request.Unset, func() (*request.Item, error) {
|
||||
return e.SendPayload(ctx, request.Unset, func() (*request.Item, error) {
|
||||
return item, nil
|
||||
}, request.AuthenticatedRequest)
|
||||
}
|
||||
|
||||
// FetchExchangeLimits fetches order execution limits filtered by asset
|
||||
func (b *Binance) FetchExchangeLimits(ctx context.Context, a asset.Item) ([]order.MinMaxLevel, error) {
|
||||
func (e *Exchange) FetchExchangeLimits(ctx context.Context, a asset.Item) ([]order.MinMaxLevel, error) {
|
||||
if a != asset.Spot && a != asset.Margin {
|
||||
return nil, fmt.Errorf("%w %v", asset.ErrNotSupported, a)
|
||||
}
|
||||
|
||||
resp, err := b.GetExchangeInfo(ctx)
|
||||
resp, err := e.GetExchangeInfo(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1181,7 +1181,7 @@ func (b *Binance) FetchExchangeLimits(ctx context.Context, a asset.Item) ([]orde
|
||||
}
|
||||
|
||||
// CryptoLoanIncomeHistory returns crypto loan income history
|
||||
func (b *Binance) CryptoLoanIncomeHistory(ctx context.Context, curr currency.Code, loanType string, startTime, endTime time.Time, limit int64) ([]CryptoLoansIncomeHistory, error) {
|
||||
func (e *Exchange) CryptoLoanIncomeHistory(ctx context.Context, curr currency.Code, loanType string, startTime, endTime time.Time, limit int64) ([]CryptoLoansIncomeHistory, error) {
|
||||
params := url.Values{}
|
||||
if !curr.IsEmpty() {
|
||||
params.Set("asset", curr.String())
|
||||
@@ -1200,11 +1200,11 @@ func (b *Binance) CryptoLoanIncomeHistory(ctx context.Context, curr currency.Cod
|
||||
}
|
||||
|
||||
var resp []CryptoLoansIncomeHistory
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, loanIncomeHistory, params, spotDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, loanIncomeHistory, params, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// CryptoLoanBorrow borrows crypto
|
||||
func (b *Binance) CryptoLoanBorrow(ctx context.Context, loanCoin currency.Code, loanAmount float64, collateralCoin currency.Code, collateralAmount float64, loanTerm int64) ([]CryptoLoanBorrow, error) {
|
||||
func (e *Exchange) CryptoLoanBorrow(ctx context.Context, loanCoin currency.Code, loanAmount float64, collateralCoin currency.Code, collateralAmount float64, loanTerm int64) ([]CryptoLoanBorrow, error) {
|
||||
if loanCoin.IsEmpty() {
|
||||
return nil, errLoanCoinMustBeSet
|
||||
}
|
||||
@@ -1230,11 +1230,11 @@ func (b *Binance) CryptoLoanBorrow(ctx context.Context, loanCoin currency.Code,
|
||||
params.Set("loanTerm", strconv.FormatInt(loanTerm, 10))
|
||||
|
||||
var resp []CryptoLoanBorrow
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodPost, loanBorrow, params, spotDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodPost, loanBorrow, params, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// CryptoLoanBorrowHistory gets loan borrow history
|
||||
func (b *Binance) CryptoLoanBorrowHistory(ctx context.Context, orderID int64, loanCoin, collateralCoin currency.Code, startTime, endTime time.Time, current, limit int64) (*LoanBorrowHistory, error) {
|
||||
func (e *Exchange) CryptoLoanBorrowHistory(ctx context.Context, orderID int64, loanCoin, collateralCoin currency.Code, startTime, endTime time.Time, current, limit int64) (*LoanBorrowHistory, error) {
|
||||
params := url.Values{}
|
||||
if orderID != 0 {
|
||||
params.Set("orderId", strconv.FormatInt(orderID, 10))
|
||||
@@ -1259,11 +1259,11 @@ func (b *Binance) CryptoLoanBorrowHistory(ctx context.Context, orderID int64, lo
|
||||
}
|
||||
|
||||
var resp LoanBorrowHistory
|
||||
return &resp, b.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, loanBorrowHistory, params, spotDefaultRate, &resp)
|
||||
return &resp, e.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, loanBorrowHistory, params, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// CryptoLoanOngoingOrders obtains ongoing loan orders
|
||||
func (b *Binance) CryptoLoanOngoingOrders(ctx context.Context, orderID int64, loanCoin, collateralCoin currency.Code, current, limit int64) (*CryptoLoanOngoingOrder, error) {
|
||||
func (e *Exchange) CryptoLoanOngoingOrders(ctx context.Context, orderID int64, loanCoin, collateralCoin currency.Code, current, limit int64) (*CryptoLoanOngoingOrder, error) {
|
||||
params := url.Values{}
|
||||
if orderID != 0 {
|
||||
params.Set("orderId", strconv.FormatInt(orderID, 10))
|
||||
@@ -1282,11 +1282,11 @@ func (b *Binance) CryptoLoanOngoingOrders(ctx context.Context, orderID int64, lo
|
||||
}
|
||||
|
||||
var resp CryptoLoanOngoingOrder
|
||||
return &resp, b.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, loanOngoingOrders, params, spotDefaultRate, &resp)
|
||||
return &resp, e.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, loanOngoingOrders, params, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// CryptoLoanRepay repays a crypto loan
|
||||
func (b *Binance) CryptoLoanRepay(ctx context.Context, orderID int64, amount float64, repayType int64, collateralReturn bool) ([]CryptoLoanRepay, error) {
|
||||
func (e *Exchange) CryptoLoanRepay(ctx context.Context, orderID int64, amount float64, repayType int64, collateralReturn bool) ([]CryptoLoanRepay, error) {
|
||||
if orderID <= 0 {
|
||||
return nil, errOrderIDMustBeSet
|
||||
}
|
||||
@@ -1303,11 +1303,11 @@ func (b *Binance) CryptoLoanRepay(ctx context.Context, orderID int64, amount flo
|
||||
params.Set("collateralReturn", strconv.FormatBool(collateralReturn))
|
||||
|
||||
var resp []CryptoLoanRepay
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodPost, loanRepay, params, spotDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodPost, loanRepay, params, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// CryptoLoanRepaymentHistory gets the crypto loan repayment history
|
||||
func (b *Binance) CryptoLoanRepaymentHistory(ctx context.Context, orderID int64, loanCoin, collateralCoin currency.Code, startTime, endTime time.Time, current, limit int64) (*CryptoLoanRepayHistory, error) {
|
||||
func (e *Exchange) CryptoLoanRepaymentHistory(ctx context.Context, orderID int64, loanCoin, collateralCoin currency.Code, startTime, endTime time.Time, current, limit int64) (*CryptoLoanRepayHistory, error) {
|
||||
params := url.Values{}
|
||||
if orderID != 0 {
|
||||
params.Set("orderId", strconv.FormatInt(orderID, 10))
|
||||
@@ -1332,11 +1332,11 @@ func (b *Binance) CryptoLoanRepaymentHistory(ctx context.Context, orderID int64,
|
||||
}
|
||||
|
||||
var resp CryptoLoanRepayHistory
|
||||
return &resp, b.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, loanRepaymentHistory, params, spotDefaultRate, &resp)
|
||||
return &resp, e.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, loanRepaymentHistory, params, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// CryptoLoanAdjustLTV adjusts the LTV of a crypto loan
|
||||
func (b *Binance) CryptoLoanAdjustLTV(ctx context.Context, orderID int64, reduce bool, amount float64) (*CryptoLoanAdjustLTV, error) {
|
||||
func (e *Exchange) CryptoLoanAdjustLTV(ctx context.Context, orderID int64, reduce bool, amount float64) (*CryptoLoanAdjustLTV, error) {
|
||||
if orderID <= 0 {
|
||||
return nil, errOrderIDMustBeSet
|
||||
}
|
||||
@@ -1354,11 +1354,11 @@ func (b *Binance) CryptoLoanAdjustLTV(ctx context.Context, orderID int64, reduce
|
||||
params.Set("direction", direction)
|
||||
|
||||
var resp CryptoLoanAdjustLTV
|
||||
return &resp, b.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodPost, loanAdjustLTV, params, spotDefaultRate, &resp)
|
||||
return &resp, e.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodPost, loanAdjustLTV, params, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// CryptoLoanLTVAdjustmentHistory gets the crypto loan LTV adjustment history
|
||||
func (b *Binance) CryptoLoanLTVAdjustmentHistory(ctx context.Context, orderID int64, loanCoin, collateralCoin currency.Code, startTime, endTime time.Time, current, limit int64) (*CryptoLoanLTVAdjustmentHistory, error) {
|
||||
func (e *Exchange) CryptoLoanLTVAdjustmentHistory(ctx context.Context, orderID int64, loanCoin, collateralCoin currency.Code, startTime, endTime time.Time, current, limit int64) (*CryptoLoanLTVAdjustmentHistory, error) {
|
||||
params := url.Values{}
|
||||
if orderID != 0 {
|
||||
params.Set("orderId", strconv.FormatInt(orderID, 10))
|
||||
@@ -1383,11 +1383,11 @@ func (b *Binance) CryptoLoanLTVAdjustmentHistory(ctx context.Context, orderID in
|
||||
}
|
||||
|
||||
var resp CryptoLoanLTVAdjustmentHistory
|
||||
return &resp, b.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, loanLTVAdjustmentHistory, params, spotDefaultRate, &resp)
|
||||
return &resp, e.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, loanLTVAdjustmentHistory, params, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// CryptoLoanAssetsData gets the loanable assets data
|
||||
func (b *Binance) CryptoLoanAssetsData(ctx context.Context, loanCoin currency.Code, vipLevel int64) (*LoanableAssetsData, error) {
|
||||
func (e *Exchange) CryptoLoanAssetsData(ctx context.Context, loanCoin currency.Code, vipLevel int64) (*LoanableAssetsData, error) {
|
||||
params := url.Values{}
|
||||
if !loanCoin.IsEmpty() {
|
||||
params.Set("loanCoin", loanCoin.String())
|
||||
@@ -1397,11 +1397,11 @@ func (b *Binance) CryptoLoanAssetsData(ctx context.Context, loanCoin currency.Co
|
||||
}
|
||||
|
||||
var resp LoanableAssetsData
|
||||
return &resp, b.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, loanableAssetsData, params, spotDefaultRate, &resp)
|
||||
return &resp, e.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, loanableAssetsData, params, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// CryptoLoanCollateralAssetsData gets the collateral assets data
|
||||
func (b *Binance) CryptoLoanCollateralAssetsData(ctx context.Context, collateralCoin currency.Code, vipLevel int64) (*CollateralAssetData, error) {
|
||||
func (e *Exchange) CryptoLoanCollateralAssetsData(ctx context.Context, collateralCoin currency.Code, vipLevel int64) (*CollateralAssetData, error) {
|
||||
params := url.Values{}
|
||||
if !collateralCoin.IsEmpty() {
|
||||
params.Set("collateralCoin", collateralCoin.String())
|
||||
@@ -1411,11 +1411,11 @@ func (b *Binance) CryptoLoanCollateralAssetsData(ctx context.Context, collateral
|
||||
}
|
||||
|
||||
var resp CollateralAssetData
|
||||
return &resp, b.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, loanCollateralAssetsData, params, spotDefaultRate, &resp)
|
||||
return &resp, e.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, loanCollateralAssetsData, params, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// CryptoLoanCheckCollateralRepayRate checks the collateral repay rate
|
||||
func (b *Binance) CryptoLoanCheckCollateralRepayRate(ctx context.Context, loanCoin, collateralCoin currency.Code, amount float64) (*CollateralRepayRate, error) {
|
||||
func (e *Exchange) CryptoLoanCheckCollateralRepayRate(ctx context.Context, loanCoin, collateralCoin currency.Code, amount float64) (*CollateralRepayRate, error) {
|
||||
if loanCoin.IsEmpty() {
|
||||
return nil, errLoanCoinMustBeSet
|
||||
}
|
||||
@@ -1432,11 +1432,11 @@ func (b *Binance) CryptoLoanCheckCollateralRepayRate(ctx context.Context, loanCo
|
||||
params.Set("repayAmount", strconv.FormatFloat(amount, 'f', -1, 64))
|
||||
|
||||
var resp CollateralRepayRate
|
||||
return &resp, b.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, loanCheckCollateralRepayRate, params, spotDefaultRate, &resp)
|
||||
return &resp, e.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, loanCheckCollateralRepayRate, params, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// CryptoLoanCustomiseMarginCall customises a loan's margin call
|
||||
func (b *Binance) CryptoLoanCustomiseMarginCall(ctx context.Context, orderID int64, collateralCoin currency.Code, marginCallValue float64) (*CustomiseMarginCall, error) {
|
||||
func (e *Exchange) CryptoLoanCustomiseMarginCall(ctx context.Context, orderID int64, collateralCoin currency.Code, marginCallValue float64) (*CustomiseMarginCall, error) {
|
||||
if marginCallValue <= 0 {
|
||||
return nil, errors.New("marginCallValue must not be <= 0")
|
||||
}
|
||||
@@ -1451,11 +1451,11 @@ func (b *Binance) CryptoLoanCustomiseMarginCall(ctx context.Context, orderID int
|
||||
params.Set("marginCall", strconv.FormatFloat(marginCallValue, 'f', -1, 64))
|
||||
|
||||
var resp CustomiseMarginCall
|
||||
return &resp, b.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodPost, loanCustomiseMarginCall, params, spotDefaultRate, &resp)
|
||||
return &resp, e.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodPost, loanCustomiseMarginCall, params, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FlexibleLoanBorrow creates a flexible loan
|
||||
func (b *Binance) FlexibleLoanBorrow(ctx context.Context, loanCoin, collateralCoin currency.Code, loanAmount, collateralAmount float64) (*FlexibleLoanBorrow, error) {
|
||||
func (e *Exchange) FlexibleLoanBorrow(ctx context.Context, loanCoin, collateralCoin currency.Code, loanAmount, collateralAmount float64) (*FlexibleLoanBorrow, error) {
|
||||
if loanCoin.IsEmpty() {
|
||||
return nil, errLoanCoinMustBeSet
|
||||
}
|
||||
@@ -1477,11 +1477,11 @@ func (b *Binance) FlexibleLoanBorrow(ctx context.Context, loanCoin, collateralCo
|
||||
}
|
||||
|
||||
var resp FlexibleLoanBorrow
|
||||
return &resp, b.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodPost, flexibleLoanBorrow, params, spotDefaultRate, &resp)
|
||||
return &resp, e.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodPost, flexibleLoanBorrow, params, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FlexibleLoanOngoingOrders gets the flexible loan ongoing orders
|
||||
func (b *Binance) FlexibleLoanOngoingOrders(ctx context.Context, loanCoin, collateralCoin currency.Code, current, limit int64) (*FlexibleLoanOngoingOrder, error) {
|
||||
func (e *Exchange) FlexibleLoanOngoingOrders(ctx context.Context, loanCoin, collateralCoin currency.Code, current, limit int64) (*FlexibleLoanOngoingOrder, error) {
|
||||
params := url.Values{}
|
||||
if !loanCoin.IsEmpty() {
|
||||
params.Set("loanCoin", loanCoin.String())
|
||||
@@ -1497,11 +1497,11 @@ func (b *Binance) FlexibleLoanOngoingOrders(ctx context.Context, loanCoin, colla
|
||||
}
|
||||
|
||||
var resp FlexibleLoanOngoingOrder
|
||||
return &resp, b.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, flexibleLoanOngoingOrders, params, spotDefaultRate, &resp)
|
||||
return &resp, e.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, flexibleLoanOngoingOrders, params, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FlexibleLoanBorrowHistory gets the flexible loan borrow history
|
||||
func (b *Binance) FlexibleLoanBorrowHistory(ctx context.Context, loanCoin, collateralCoin currency.Code, startTime, endTime time.Time, current, limit int64) (*FlexibleLoanBorrowHistory, error) {
|
||||
func (e *Exchange) FlexibleLoanBorrowHistory(ctx context.Context, loanCoin, collateralCoin currency.Code, startTime, endTime time.Time, current, limit int64) (*FlexibleLoanBorrowHistory, error) {
|
||||
params := url.Values{}
|
||||
if !loanCoin.IsEmpty() {
|
||||
params.Set("loanCoin", loanCoin.String())
|
||||
@@ -1523,11 +1523,11 @@ func (b *Binance) FlexibleLoanBorrowHistory(ctx context.Context, loanCoin, colla
|
||||
}
|
||||
|
||||
var resp FlexibleLoanBorrowHistory
|
||||
return &resp, b.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, flexibleLoanBorrowHistory, params, spotDefaultRate, &resp)
|
||||
return &resp, e.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, flexibleLoanBorrowHistory, params, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FlexibleLoanRepay repays a flexible loan
|
||||
func (b *Binance) FlexibleLoanRepay(ctx context.Context, loanCoin, collateralCoin currency.Code, amount float64, collateralReturn, fullRepayment bool) (*FlexibleLoanRepay, error) {
|
||||
func (e *Exchange) FlexibleLoanRepay(ctx context.Context, loanCoin, collateralCoin currency.Code, amount float64, collateralReturn, fullRepayment bool) (*FlexibleLoanRepay, error) {
|
||||
if loanCoin.IsEmpty() {
|
||||
return nil, errLoanCoinMustBeSet
|
||||
}
|
||||
@@ -1548,11 +1548,11 @@ func (b *Binance) FlexibleLoanRepay(ctx context.Context, loanCoin, collateralCoi
|
||||
}
|
||||
|
||||
var resp FlexibleLoanRepay
|
||||
return &resp, b.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodPost, flexibleLoanRepay, params, spotDefaultRate, &resp)
|
||||
return &resp, e.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodPost, flexibleLoanRepay, params, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FlexibleLoanRepayHistory gets the flexible loan repayment history
|
||||
func (b *Binance) FlexibleLoanRepayHistory(ctx context.Context, loanCoin, collateralCoin currency.Code, startTime, endTime time.Time, current, limit int64) (*FlexibleLoanRepayHistory, error) {
|
||||
func (e *Exchange) FlexibleLoanRepayHistory(ctx context.Context, loanCoin, collateralCoin currency.Code, startTime, endTime time.Time, current, limit int64) (*FlexibleLoanRepayHistory, error) {
|
||||
params := url.Values{}
|
||||
if !loanCoin.IsEmpty() {
|
||||
params.Set("loanCoin", loanCoin.String())
|
||||
@@ -1574,11 +1574,11 @@ func (b *Binance) FlexibleLoanRepayHistory(ctx context.Context, loanCoin, collat
|
||||
}
|
||||
|
||||
var resp FlexibleLoanRepayHistory
|
||||
return &resp, b.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, flexibleLoanRepayHistory, params, spotDefaultRate, &resp)
|
||||
return &resp, e.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, flexibleLoanRepayHistory, params, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FlexibleLoanAdjustLTV adjusts the LTV of a flexible loan
|
||||
func (b *Binance) FlexibleLoanAdjustLTV(ctx context.Context, loanCoin, collateralCoin currency.Code, amount float64, reduce bool) (*FlexibleLoanAdjustLTV, error) {
|
||||
func (e *Exchange) FlexibleLoanAdjustLTV(ctx context.Context, loanCoin, collateralCoin currency.Code, amount float64, reduce bool) (*FlexibleLoanAdjustLTV, error) {
|
||||
if loanCoin.IsEmpty() {
|
||||
return nil, errLoanCoinMustBeSet
|
||||
}
|
||||
@@ -1601,11 +1601,11 @@ func (b *Binance) FlexibleLoanAdjustLTV(ctx context.Context, loanCoin, collatera
|
||||
params.Set("direction", direction)
|
||||
|
||||
var resp FlexibleLoanAdjustLTV
|
||||
return &resp, b.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodPost, flexibleLoanAdjustLTV, params, spotDefaultRate, &resp)
|
||||
return &resp, e.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodPost, flexibleLoanAdjustLTV, params, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FlexibleLoanLTVAdjustmentHistory gets the flexible loan LTV adjustment history
|
||||
func (b *Binance) FlexibleLoanLTVAdjustmentHistory(ctx context.Context, loanCoin, collateralCoin currency.Code, startTime, endTime time.Time, current, limit int64) (*FlexibleLoanLTVAdjustmentHistory, error) {
|
||||
func (e *Exchange) FlexibleLoanLTVAdjustmentHistory(ctx context.Context, loanCoin, collateralCoin currency.Code, startTime, endTime time.Time, current, limit int64) (*FlexibleLoanLTVAdjustmentHistory, error) {
|
||||
params := url.Values{}
|
||||
if !loanCoin.IsEmpty() {
|
||||
params.Set("loanCoin", loanCoin.String())
|
||||
@@ -1627,27 +1627,27 @@ func (b *Binance) FlexibleLoanLTVAdjustmentHistory(ctx context.Context, loanCoin
|
||||
}
|
||||
|
||||
var resp FlexibleLoanLTVAdjustmentHistory
|
||||
return &resp, b.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, flexibleLoanLTVHistory, params, spotDefaultRate, &resp)
|
||||
return &resp, e.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, flexibleLoanLTVHistory, params, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FlexibleLoanAssetsData gets the flexible loan assets data
|
||||
func (b *Binance) FlexibleLoanAssetsData(ctx context.Context, loanCoin currency.Code) (*FlexibleLoanAssetsData, error) {
|
||||
func (e *Exchange) FlexibleLoanAssetsData(ctx context.Context, loanCoin currency.Code) (*FlexibleLoanAssetsData, error) {
|
||||
params := url.Values{}
|
||||
if !loanCoin.IsEmpty() {
|
||||
params.Set("loanCoin", loanCoin.String())
|
||||
}
|
||||
|
||||
var resp FlexibleLoanAssetsData
|
||||
return &resp, b.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, flexibleLoanAssetsData, params, spotDefaultRate, &resp)
|
||||
return &resp, e.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, flexibleLoanAssetsData, params, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FlexibleCollateralAssetsData gets the flexible loan collateral assets data
|
||||
func (b *Binance) FlexibleCollateralAssetsData(ctx context.Context, collateralCoin currency.Code) (*FlexibleCollateralAssetsData, error) {
|
||||
func (e *Exchange) FlexibleCollateralAssetsData(ctx context.Context, collateralCoin currency.Code) (*FlexibleCollateralAssetsData, error) {
|
||||
params := url.Values{}
|
||||
if !collateralCoin.IsEmpty() {
|
||||
params.Set("collateralCoin", collateralCoin.String())
|
||||
}
|
||||
|
||||
var resp FlexibleCollateralAssetsData
|
||||
return &resp, b.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, flexibleLoanCollateralAssetsData, params, spotDefaultRate, &resp)
|
||||
return &resp, e.SendAuthHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, flexibleLoanCollateralAssetsData, params, spotDefaultRate, &resp)
|
||||
}
|
||||
|
||||
@@ -77,14 +77,14 @@ const (
|
||||
)
|
||||
|
||||
// FuturesExchangeInfo stores CoinMarginedFutures, data
|
||||
func (b *Binance) FuturesExchangeInfo(ctx context.Context) (CExchangeInfo, error) {
|
||||
func (e *Exchange) FuturesExchangeInfo(ctx context.Context) (CExchangeInfo, error) {
|
||||
var resp CExchangeInfo
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesExchangeInfo, cFuturesDefaultRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesExchangeInfo, cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetFuturesOrderbook gets orderbook data for CoinMarginedFutures,
|
||||
func (b *Binance) GetFuturesOrderbook(ctx context.Context, symbol currency.Pair, limit int64) (*OrderBook, error) {
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
func (e *Exchange) GetFuturesOrderbook(ctx context.Context, symbol currency.Pair, limit int64) (*OrderBook, error) {
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -106,7 +106,7 @@ func (b *Binance) GetFuturesOrderbook(ctx context.Context, symbol currency.Pair,
|
||||
}
|
||||
|
||||
var data *OrderbookData
|
||||
if err := b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesOrderbook+params.Encode(), rateBudget, &data); err != nil {
|
||||
if err := e.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesOrderbook+params.Encode(), rateBudget, &data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -129,10 +129,10 @@ func (b *Binance) GetFuturesOrderbook(ctx context.Context, symbol currency.Pair,
|
||||
}
|
||||
|
||||
// GetFuturesPublicTrades gets recent public trades for CoinMarginedFutures,
|
||||
func (b *Binance) GetFuturesPublicTrades(ctx context.Context, symbol currency.Pair, limit int64) ([]FuturesPublicTradesData, error) {
|
||||
func (e *Exchange) GetFuturesPublicTrades(ctx context.Context, symbol currency.Pair, limit int64) ([]FuturesPublicTradesData, error) {
|
||||
var resp []FuturesPublicTradesData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -140,14 +140,14 @@ func (b *Binance) GetFuturesPublicTrades(ctx context.Context, symbol currency.Pa
|
||||
if limit > 0 {
|
||||
params.Set("limit", strconv.FormatInt(limit, 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesRecentTrades+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesRecentTrades+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetFuturesHistoricalTrades gets historical public trades for CoinMarginedFutures,
|
||||
func (b *Binance) GetFuturesHistoricalTrades(ctx context.Context, symbol currency.Pair, fromID string, limit int64) ([]UPublicTradesData, error) {
|
||||
func (e *Exchange) 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)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -158,14 +158,14 @@ func (b *Binance) GetFuturesHistoricalTrades(ctx context.Context, symbol currenc
|
||||
if limit > 0 {
|
||||
params.Set("limit", strconv.FormatInt(limit, 10))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesHistoricalTrades, params, cFuturesHistoricalTradesRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesHistoricalTrades, params, cFuturesHistoricalTradesRate, &resp)
|
||||
}
|
||||
|
||||
// GetPastPublicTrades gets past public trades for CoinMarginedFutures,
|
||||
func (b *Binance) GetPastPublicTrades(ctx context.Context, symbol currency.Pair, limit, fromID int64) ([]FuturesPublicTradesData, error) {
|
||||
func (e *Exchange) 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)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -176,14 +176,14 @@ func (b *Binance) GetPastPublicTrades(ctx context.Context, symbol currency.Pair,
|
||||
if fromID != 0 {
|
||||
params.Set("fromID", strconv.FormatInt(fromID, 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesRecentTrades+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesRecentTrades+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetFuturesAggregatedTradesList gets aggregated trades list for CoinMarginedFutures,
|
||||
func (b *Binance) GetFuturesAggregatedTradesList(ctx context.Context, symbol currency.Pair, fromID, limit int64, startTime, endTime time.Time) ([]AggregatedTrade, error) {
|
||||
func (e *Exchange) 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)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -201,11 +201,11 @@ func (b *Binance) GetFuturesAggregatedTradesList(ctx context.Context, symbol cur
|
||||
params.Set("startTime", strconv.FormatInt(startTime.UnixMilli(), 10))
|
||||
params.Set("endTime", strconv.FormatInt(endTime.UnixMilli(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesCompressedTrades+params.Encode(), cFuturesHistoricalTradesRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesCompressedTrades+params.Encode(), cFuturesHistoricalTradesRate, &resp)
|
||||
}
|
||||
|
||||
// GetIndexAndMarkPrice gets index and mark prices for CoinMarginedFutures,
|
||||
func (b *Binance) GetIndexAndMarkPrice(ctx context.Context, symbol, pair string) ([]IndexMarkPrice, error) {
|
||||
func (e *Exchange) GetIndexAndMarkPrice(ctx context.Context, symbol, pair string) ([]IndexMarkPrice, error) {
|
||||
var resp []IndexMarkPrice
|
||||
params := url.Values{}
|
||||
if symbol != "" {
|
||||
@@ -214,21 +214,21 @@ func (b *Binance) GetIndexAndMarkPrice(ctx context.Context, symbol, pair string)
|
||||
if pair != "" {
|
||||
params.Set("pair", pair)
|
||||
}
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesMarkPrice+params.Encode(), cFuturesIndexMarkPriceRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesMarkPrice+params.Encode(), cFuturesIndexMarkPriceRate, &resp)
|
||||
}
|
||||
|
||||
// GetFundingRateInfo returns extra details about funding rates
|
||||
func (b *Binance) GetFundingRateInfo(ctx context.Context) ([]FundingRateInfoResponse, error) {
|
||||
func (e *Exchange) GetFundingRateInfo(ctx context.Context) ([]FundingRateInfoResponse, error) {
|
||||
params := url.Values{}
|
||||
var resp []FundingRateInfoResponse
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesFundingRateInfo+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesFundingRateInfo+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetFuturesKlineData gets futures kline data for CoinMarginedFutures,
|
||||
func (b *Binance) GetFuturesKlineData(ctx context.Context, symbol currency.Pair, interval string, limit uint64, startTime, endTime time.Time) ([]FuturesCandleStick, error) {
|
||||
func (e *Exchange) GetFuturesKlineData(ctx context.Context, symbol currency.Pair, interval string, limit uint64, startTime, endTime time.Time) ([]FuturesCandleStick, error) {
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -251,14 +251,14 @@ func (b *Binance) GetFuturesKlineData(ctx context.Context, symbol currency.Pair,
|
||||
|
||||
var resp []FuturesCandleStick
|
||||
rateBudget := getKlineRateBudget(limit)
|
||||
if err := b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesKlineData+params.Encode(), rateBudget, &resp); err != nil {
|
||||
if err := e.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesKlineData+params.Encode(), rateBudget, &resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetContinuousKlineData gets continuous kline data
|
||||
func (b *Binance) GetContinuousKlineData(ctx context.Context, pair, contractType, interval string, limit uint64, startTime, endTime time.Time) ([]FuturesCandleStick, error) {
|
||||
func (e *Exchange) GetContinuousKlineData(ctx context.Context, pair, contractType, interval string, limit uint64, startTime, endTime time.Time) ([]FuturesCandleStick, error) {
|
||||
params := url.Values{}
|
||||
params.Set("pair", pair)
|
||||
if !slices.Contains(validContractType, contractType) {
|
||||
@@ -282,7 +282,7 @@ func (b *Binance) GetContinuousKlineData(ctx context.Context, pair, contractType
|
||||
|
||||
rateBudget := getKlineRateBudget(limit)
|
||||
var resp []FuturesCandleStick
|
||||
if err := b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesContinuousKline+params.Encode(), rateBudget, &resp); err != nil {
|
||||
if err := e.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesContinuousKline+params.Encode(), rateBudget, &resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -290,7 +290,7 @@ func (b *Binance) GetContinuousKlineData(ctx context.Context, pair, contractType
|
||||
}
|
||||
|
||||
// GetIndexPriceKlines gets continuous kline data
|
||||
func (b *Binance) GetIndexPriceKlines(ctx context.Context, pair, interval string, limit uint64, startTime, endTime time.Time) ([]FuturesCandleStick, error) {
|
||||
func (e *Exchange) GetIndexPriceKlines(ctx context.Context, pair, interval string, limit uint64, startTime, endTime time.Time) ([]FuturesCandleStick, error) {
|
||||
params := url.Values{}
|
||||
params.Set("pair", pair)
|
||||
if limit > 0 {
|
||||
@@ -310,7 +310,7 @@ func (b *Binance) GetIndexPriceKlines(ctx context.Context, pair, interval string
|
||||
|
||||
rateBudget := getKlineRateBudget(limit)
|
||||
var candles []FuturesCandleStick
|
||||
err := b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesIndexKline+params.Encode(), rateBudget, &candles)
|
||||
err := e.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesIndexKline+params.Encode(), rateBudget, &candles)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -318,8 +318,8 @@ func (b *Binance) GetIndexPriceKlines(ctx context.Context, pair, interval string
|
||||
}
|
||||
|
||||
// GetMarkPriceKline gets mark price kline data
|
||||
func (b *Binance) GetMarkPriceKline(ctx context.Context, symbol currency.Pair, interval string, limit uint64, startTime, endTime time.Time) ([]FuturesCandleStick, error) {
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
func (e *Exchange) GetMarkPriceKline(ctx context.Context, symbol currency.Pair, interval string, limit uint64, startTime, endTime time.Time) ([]FuturesCandleStick, error) {
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -342,7 +342,7 @@ func (b *Binance) GetMarkPriceKline(ctx context.Context, symbol currency.Pair, i
|
||||
|
||||
var candles []FuturesCandleStick
|
||||
rateBudget := getKlineRateBudget(limit)
|
||||
err = b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesMarkPriceKline+params.Encode(), rateBudget, &candles)
|
||||
err = e.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesMarkPriceKline+params.Encode(), rateBudget, &candles)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -366,13 +366,13 @@ func getKlineRateBudget(limit uint64) request.EndpointLimit {
|
||||
}
|
||||
|
||||
// GetFuturesSwapTickerChangeStats gets 24hr ticker change stats for CoinMarginedFutures,
|
||||
func (b *Binance) GetFuturesSwapTickerChangeStats(ctx context.Context, symbol currency.Pair, pair string) ([]PriceChangeStats, error) {
|
||||
func (e *Exchange) GetFuturesSwapTickerChangeStats(ctx context.Context, symbol currency.Pair, pair string) ([]PriceChangeStats, error) {
|
||||
var resp []PriceChangeStats
|
||||
params := url.Values{}
|
||||
rateLimit := cFuturesTickerPriceHistoryRate
|
||||
if !symbol.IsEmpty() {
|
||||
rateLimit = cFuturesDefaultRate
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -381,15 +381,15 @@ func (b *Binance) GetFuturesSwapTickerChangeStats(ctx context.Context, symbol cu
|
||||
if pair != "" {
|
||||
params.Set("pair", pair)
|
||||
}
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesTickerPriceStats+params.Encode(), rateLimit, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesTickerPriceStats+params.Encode(), rateLimit, &resp)
|
||||
}
|
||||
|
||||
// FuturesGetFundingHistory gets funding history for CoinMarginedFutures,
|
||||
func (b *Binance) FuturesGetFundingHistory(ctx context.Context, symbol currency.Pair, limit int64, startTime, endTime time.Time) ([]FundingRateHistory, error) {
|
||||
func (e *Exchange) FuturesGetFundingHistory(ctx context.Context, symbol currency.Pair, limit int64, startTime, endTime time.Time) ([]FundingRateHistory, error) {
|
||||
var resp []FundingRateHistory
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -405,17 +405,17 @@ func (b *Binance) FuturesGetFundingHistory(ctx context.Context, symbol currency.
|
||||
params.Set("startTime", strconv.FormatInt(startTime.UnixMilli(), 10))
|
||||
params.Set("endTime", strconv.FormatInt(endTime.UnixMilli(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesFundingRateHistory+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesFundingRateHistory+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetFuturesSymbolPriceTicker gets price ticker for symbol
|
||||
func (b *Binance) GetFuturesSymbolPriceTicker(ctx context.Context, symbol currency.Pair, pair string) ([]SymbolPriceTicker, error) {
|
||||
func (e *Exchange) GetFuturesSymbolPriceTicker(ctx context.Context, symbol currency.Pair, pair string) ([]SymbolPriceTicker, error) {
|
||||
var resp []SymbolPriceTicker
|
||||
params := url.Values{}
|
||||
rateLimit := cFuturesOrderbookTickerAllRate
|
||||
if !symbol.IsEmpty() {
|
||||
rateLimit = cFuturesDefaultRate
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -424,17 +424,17 @@ func (b *Binance) GetFuturesSymbolPriceTicker(ctx context.Context, symbol curren
|
||||
if pair != "" {
|
||||
params.Set("pair", pair)
|
||||
}
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesSymbolPriceTicker+params.Encode(), rateLimit, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesSymbolPriceTicker+params.Encode(), rateLimit, &resp)
|
||||
}
|
||||
|
||||
// GetFuturesOrderbookTicker gets orderbook ticker for symbol
|
||||
func (b *Binance) GetFuturesOrderbookTicker(ctx context.Context, symbol currency.Pair, pair string) ([]SymbolOrderBookTicker, error) {
|
||||
func (e *Exchange) GetFuturesOrderbookTicker(ctx context.Context, symbol currency.Pair, pair string) ([]SymbolOrderBookTicker, error) {
|
||||
var resp []SymbolOrderBookTicker
|
||||
params := url.Values{}
|
||||
rateLimit := cFuturesOrderbookTickerAllRate
|
||||
if !symbol.IsEmpty() {
|
||||
rateLimit = cFuturesDefaultRate
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -443,23 +443,23 @@ func (b *Binance) GetFuturesOrderbookTicker(ctx context.Context, symbol currency
|
||||
if pair != "" {
|
||||
params.Set("pair", pair)
|
||||
}
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesSymbolOrderbook+params.Encode(), rateLimit, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesSymbolOrderbook+params.Encode(), rateLimit, &resp)
|
||||
}
|
||||
|
||||
// OpenInterest gets open interest data for a symbol
|
||||
func (b *Binance) OpenInterest(ctx context.Context, symbol currency.Pair) (OpenInterestData, error) {
|
||||
func (e *Exchange) OpenInterest(ctx context.Context, symbol currency.Pair) (OpenInterestData, error) {
|
||||
var resp OpenInterestData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesOpenInterest+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesOpenInterest+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetOpenInterestStats gets open interest stats for a symbol
|
||||
func (b *Binance) GetOpenInterestStats(ctx context.Context, pair, contractType, period string, limit int64, startTime, endTime time.Time) ([]OpenInterestStats, error) {
|
||||
func (e *Exchange) GetOpenInterestStats(ctx context.Context, pair, contractType, period string, limit int64, startTime, endTime time.Time) ([]OpenInterestStats, error) {
|
||||
var resp []OpenInterestStats
|
||||
params := url.Values{}
|
||||
if pair != "" {
|
||||
@@ -483,11 +483,11 @@ func (b *Binance) GetOpenInterestStats(ctx context.Context, pair, contractType,
|
||||
params.Set("startTime", strconv.FormatInt(startTime.UnixMilli(), 10))
|
||||
params.Set("endTime", strconv.FormatInt(endTime.UnixMilli(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesOpenInterestStats+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesOpenInterestStats+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetTraderFuturesAccountRatio gets a traders futures account long/short ratio
|
||||
func (b *Binance) GetTraderFuturesAccountRatio(ctx context.Context, pair, period string, limit int64, startTime, endTime time.Time) ([]TopTraderAccountRatio, error) {
|
||||
func (e *Exchange) 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)
|
||||
@@ -505,11 +505,11 @@ func (b *Binance) GetTraderFuturesAccountRatio(ctx context.Context, pair, period
|
||||
params.Set("startTime", strconv.FormatInt(startTime.UnixMilli(), 10))
|
||||
params.Set("endTime", strconv.FormatInt(endTime.UnixMilli(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesTopAccountsRatio+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesTopAccountsRatio+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetTraderFuturesPositionsRatio gets a traders futures positions' long/short ratio
|
||||
func (b *Binance) GetTraderFuturesPositionsRatio(ctx context.Context, pair, period string, limit int64, startTime, endTime time.Time) ([]TopTraderPositionRatio, error) {
|
||||
func (e *Exchange) 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)
|
||||
@@ -527,11 +527,11 @@ func (b *Binance) GetTraderFuturesPositionsRatio(ctx context.Context, pair, peri
|
||||
params.Set("startTime", strconv.FormatInt(startTime.UnixMilli(), 10))
|
||||
params.Set("endTime", strconv.FormatInt(endTime.UnixMilli(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesTopPositionsRatio+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesTopPositionsRatio+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetMarketRatio gets global long/short ratio
|
||||
func (b *Binance) GetMarketRatio(ctx context.Context, pair, period string, limit int64, startTime, endTime time.Time) ([]TopTraderPositionRatio, error) {
|
||||
func (e *Exchange) 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)
|
||||
@@ -549,11 +549,11 @@ func (b *Binance) GetMarketRatio(ctx context.Context, pair, period string, limit
|
||||
params.Set("startTime", strconv.FormatInt(startTime.UnixMilli(), 10))
|
||||
params.Set("endTime", strconv.FormatInt(endTime.UnixMilli(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesLongShortRatio+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesLongShortRatio+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetFuturesTakerVolume gets futures taker buy/sell volumes
|
||||
func (b *Binance) GetFuturesTakerVolume(ctx context.Context, pair, contractType, period string, limit int64, startTime, endTime time.Time) ([]TakerBuySellVolume, error) {
|
||||
func (e *Exchange) 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)
|
||||
@@ -575,11 +575,11 @@ func (b *Binance) GetFuturesTakerVolume(ctx context.Context, pair, contractType,
|
||||
params.Set("startTime", strconv.FormatInt(startTime.UnixMilli(), 10))
|
||||
params.Set("endTime", strconv.FormatInt(endTime.UnixMilli(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesBuySellVolume+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesBuySellVolume+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetFuturesBasisData gets futures basis data
|
||||
func (b *Binance) GetFuturesBasisData(ctx context.Context, pair, contractType, period string, limit int64, startTime, endTime time.Time) ([]FuturesBasisData, error) {
|
||||
func (e *Exchange) 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)
|
||||
@@ -601,17 +601,17 @@ func (b *Binance) GetFuturesBasisData(ctx context.Context, pair, contractType, p
|
||||
params.Set("startTime", strconv.FormatInt(startTime.UnixMilli(), 10))
|
||||
params.Set("endTime", strconv.FormatInt(endTime.UnixMilli(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesBasis+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestCoinMargined, cfuturesBasis+params.Encode(), cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesNewOrder sends a new futures order to the exchange
|
||||
func (b *Binance) FuturesNewOrder(ctx context.Context, x *FuturesNewOrderRequest) (
|
||||
func (e *Exchange) FuturesNewOrder(ctx context.Context, x *FuturesNewOrderRequest) (
|
||||
FuturesOrderPlaceData,
|
||||
error,
|
||||
) {
|
||||
var resp FuturesOrderPlaceData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(x.Symbol, asset.CoinMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(x.Symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -666,11 +666,11 @@ func (b *Binance) FuturesNewOrder(ctx context.Context, x *FuturesNewOrderRequest
|
||||
if x.PriceProtect {
|
||||
params.Set("priceProtect", "TRUE")
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodPost, cfuturesOrder, params, cFuturesOrdersDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodPost, cfuturesOrder, params, cFuturesOrdersDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesBatchOrder sends a batch order request
|
||||
func (b *Binance) FuturesBatchOrder(ctx context.Context, data []PlaceBatchOrderData) ([]FuturesOrderPlaceData, error) {
|
||||
func (e *Exchange) FuturesBatchOrder(ctx context.Context, data []PlaceBatchOrderData) ([]FuturesOrderPlaceData, error) {
|
||||
var resp []FuturesOrderPlaceData
|
||||
params := url.Values{}
|
||||
for x := range data {
|
||||
@@ -678,7 +678,7 @@ func (b *Binance) FuturesBatchOrder(ctx context.Context, data []PlaceBatchOrderD
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
formattedPair, err := b.FormatExchangeCurrency(unformattedPair, asset.CoinMarginedFutures)
|
||||
formattedPair, err := e.FormatExchangeCurrency(unformattedPair, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -704,14 +704,14 @@ func (b *Binance) FuturesBatchOrder(ctx context.Context, data []PlaceBatchOrderD
|
||||
return resp, err
|
||||
}
|
||||
params.Set("batchOrders", string(jsonData))
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodPost, cfuturesBatchOrder, params, cFuturesBatchOrdersRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodPost, cfuturesBatchOrder, params, cFuturesBatchOrdersRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesBatchCancelOrders sends a batch request to cancel orders
|
||||
func (b *Binance) FuturesBatchCancelOrders(ctx context.Context, symbol currency.Pair, orderList, origClientOrderIDList []string) ([]BatchCancelOrderData, error) {
|
||||
func (e *Exchange) 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)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -730,14 +730,14 @@ func (b *Binance) FuturesBatchCancelOrders(ctx context.Context, symbol currency.
|
||||
}
|
||||
params.Set("origClientOrderIdList", string(jsonCliOrdIDList))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodDelete, cfuturesBatchOrder, params, cFuturesOrdersDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodDelete, cfuturesBatchOrder, params, cFuturesOrdersDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesGetOrderData gets futures order data
|
||||
func (b *Binance) FuturesGetOrderData(ctx context.Context, symbol currency.Pair, orderID, origClientOrderID string) (FuturesOrderGetData, error) {
|
||||
func (e *Exchange) 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)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -748,14 +748,14 @@ func (b *Binance) FuturesGetOrderData(ctx context.Context, symbol currency.Pair,
|
||||
if origClientOrderID != "" {
|
||||
params.Set("origClientOrderId", origClientOrderID)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesOrder, params, cFuturesOrdersDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesOrder, params, cFuturesOrdersDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesCancelOrder cancels a futures order
|
||||
func (b *Binance) FuturesCancelOrder(ctx context.Context, symbol currency.Pair, orderID, origClientOrderID string) (FuturesOrderGetData, error) {
|
||||
func (e *Exchange) 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)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -766,40 +766,40 @@ func (b *Binance) FuturesCancelOrder(ctx context.Context, symbol currency.Pair,
|
||||
if origClientOrderID != "" {
|
||||
params.Set("origClientOrderId", origClientOrderID)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodDelete, cfuturesOrder, params, cFuturesOrdersDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodDelete, cfuturesOrder, params, cFuturesOrdersDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesCancelAllOpenOrders cancels a futures order
|
||||
func (b *Binance) FuturesCancelAllOpenOrders(ctx context.Context, symbol currency.Pair) (GenericAuthResponse, error) {
|
||||
func (e *Exchange) FuturesCancelAllOpenOrders(ctx context.Context, symbol currency.Pair) (GenericAuthResponse, error) {
|
||||
var resp GenericAuthResponse
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodDelete, cfuturesCancelAllOrders, params, cFuturesOrdersDefaultRate, &resp)
|
||||
return resp, e.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(ctx context.Context, symbol currency.Pair, countdownTime int64) (AutoCancelAllOrdersData, error) {
|
||||
func (e *Exchange) AutoCancelAllOpenOrders(ctx context.Context, symbol currency.Pair, countdownTime int64) (AutoCancelAllOrdersData, error) {
|
||||
var resp AutoCancelAllOrdersData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
params.Set("countdownTime", strconv.FormatInt(countdownTime, 10))
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodPost, cfuturesCountdownCancel, params, cFuturesCancelAllOrdersRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodPost, cfuturesCountdownCancel, params, cFuturesCancelAllOrdersRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesOpenOrderData gets open order data for CoinMarginedFutures,
|
||||
func (b *Binance) FuturesOpenOrderData(ctx context.Context, symbol currency.Pair, orderID, origClientOrderID string) (FuturesOrderGetData, error) {
|
||||
func (e *Exchange) 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)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -810,11 +810,11 @@ func (b *Binance) FuturesOpenOrderData(ctx context.Context, symbol currency.Pair
|
||||
if origClientOrderID != "" {
|
||||
params.Set("origClientOrderId", origClientOrderID)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesOpenOrder, params, cFuturesOrdersDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesOpenOrder, params, cFuturesOrdersDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetFuturesAllOpenOrders gets all open orders data for CoinMarginedFutures,
|
||||
func (b *Binance) GetFuturesAllOpenOrders(ctx context.Context, symbol currency.Pair, pair string) ([]FuturesOrderData, error) {
|
||||
func (e *Exchange) GetFuturesAllOpenOrders(ctx context.Context, symbol currency.Pair, pair string) ([]FuturesOrderData, error) {
|
||||
var resp []FuturesOrderData
|
||||
params := url.Values{}
|
||||
var p string
|
||||
@@ -822,7 +822,7 @@ func (b *Binance) GetFuturesAllOpenOrders(ctx context.Context, symbol currency.P
|
||||
rateLimit := cFuturesGetAllOpenOrdersRate
|
||||
if !symbol.IsEmpty() {
|
||||
rateLimit = cFuturesOrdersDefaultRate
|
||||
p, err = b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
p, err = e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -834,17 +834,17 @@ func (b *Binance) GetFuturesAllOpenOrders(ctx context.Context, symbol currency.P
|
||||
if pair != "" {
|
||||
params.Set("pair", pair)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesAllOpenOrders, params, rateLimit, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesAllOpenOrders, params, rateLimit, &resp)
|
||||
}
|
||||
|
||||
// GetAllFuturesOrders gets all orders active cancelled or filled
|
||||
func (b *Binance) GetAllFuturesOrders(ctx context.Context, symbol, pair currency.Pair, startTime, endTime time.Time, orderID, limit int64) ([]FuturesOrderData, error) {
|
||||
func (e *Exchange) GetAllFuturesOrders(ctx context.Context, symbol, pair currency.Pair, startTime, endTime time.Time, orderID, limit int64) ([]FuturesOrderData, error) {
|
||||
var resp []FuturesOrderData
|
||||
params := url.Values{}
|
||||
rateLimit := cFuturesPairOrdersRate
|
||||
if !symbol.IsEmpty() {
|
||||
rateLimit = cFuturesSymbolOrdersRate
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -866,26 +866,26 @@ func (b *Binance) GetAllFuturesOrders(ctx context.Context, symbol, pair currency
|
||||
params.Set("startTime", strconv.FormatInt(startTime.UnixMilli(), 10))
|
||||
params.Set("endTime", strconv.FormatInt(endTime.UnixMilli(), 10))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesAllOrders, params, rateLimit, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesAllOrders, params, rateLimit, &resp)
|
||||
}
|
||||
|
||||
// GetFuturesAccountBalance gets account balance data for CoinMarginedFutures, account
|
||||
func (b *Binance) GetFuturesAccountBalance(ctx context.Context) ([]FuturesAccountBalanceData, error) {
|
||||
func (e *Exchange) GetFuturesAccountBalance(ctx context.Context) ([]FuturesAccountBalanceData, error) {
|
||||
var resp []FuturesAccountBalanceData
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesAccountBalance, nil, cFuturesDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesAccountBalance, nil, cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// GetFuturesAccountInfo gets account info data for CoinMarginedFutures, account
|
||||
func (b *Binance) GetFuturesAccountInfo(ctx context.Context) (FuturesAccountInformation, error) {
|
||||
func (e *Exchange) GetFuturesAccountInfo(ctx context.Context) (FuturesAccountInformation, error) {
|
||||
var resp FuturesAccountInformation
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesAccountInfo, nil, cFuturesAccountInformationRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesAccountInfo, nil, cFuturesAccountInformationRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesChangeInitialLeverage changes initial leverage for the account
|
||||
func (b *Binance) FuturesChangeInitialLeverage(ctx context.Context, symbol currency.Pair, leverage float64) (FuturesLeverageData, error) {
|
||||
func (e *Exchange) FuturesChangeInitialLeverage(ctx context.Context, symbol currency.Pair, leverage float64) (FuturesLeverageData, error) {
|
||||
var resp FuturesLeverageData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -894,14 +894,14 @@ func (b *Binance) FuturesChangeInitialLeverage(ctx context.Context, symbol curre
|
||||
return resp, errors.New("invalid leverage")
|
||||
}
|
||||
params.Set("leverage", strconv.FormatFloat(leverage, 'f', -1, 64))
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodPost, cfuturesChangeInitialLeverage, params, cFuturesDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodPost, cfuturesChangeInitialLeverage, params, cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesChangeMarginType changes margin type
|
||||
func (b *Binance) FuturesChangeMarginType(ctx context.Context, symbol currency.Pair, marginType string) (GenericAuthResponse, error) {
|
||||
func (e *Exchange) FuturesChangeMarginType(ctx context.Context, symbol currency.Pair, marginType string) (GenericAuthResponse, error) {
|
||||
var resp GenericAuthResponse
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -910,14 +910,14 @@ func (b *Binance) FuturesChangeMarginType(ctx context.Context, symbol currency.P
|
||||
return resp, errors.New("invalid marginType")
|
||||
}
|
||||
params.Set("marginType", marginType)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodPost, cfuturesChangeMarginType, params, cFuturesDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodPost, cfuturesChangeMarginType, params, cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// ModifyIsolatedPositionMargin changes margin for an isolated position
|
||||
func (b *Binance) ModifyIsolatedPositionMargin(ctx context.Context, symbol currency.Pair, positionSide, changeType string, amount float64) (FuturesMarginUpdatedResponse, error) {
|
||||
func (e *Exchange) ModifyIsolatedPositionMargin(ctx context.Context, symbol currency.Pair, positionSide, changeType string, amount float64) (FuturesMarginUpdatedResponse, error) {
|
||||
var resp FuturesMarginUpdatedResponse
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -934,14 +934,14 @@ func (b *Binance) ModifyIsolatedPositionMargin(ctx context.Context, symbol curre
|
||||
}
|
||||
params.Set("type", strconv.FormatInt(cType, 10))
|
||||
params.Set("amount", strconv.FormatFloat(amount, 'f', -1, 64))
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodPost, cfuturesModifyMargin, params, cFuturesDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodPost, cfuturesModifyMargin, params, cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesMarginChangeHistory gets past margin changes for positions
|
||||
func (b *Binance) FuturesMarginChangeHistory(ctx context.Context, symbol currency.Pair, changeType string, startTime, endTime time.Time, limit int64) ([]GetPositionMarginChangeHistoryData, error) {
|
||||
func (e *Exchange) 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)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -961,13 +961,13 @@ func (b *Binance) FuturesMarginChangeHistory(ctx context.Context, symbol currenc
|
||||
if limit != 0 {
|
||||
params.Set("limit", strconv.FormatInt(limit, 10))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesMarginChangeHistory, params, cFuturesDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesMarginChangeHistory, params, cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesPositionsInfo gets futures positions info
|
||||
// "pair" for coinmarginedfutures in GCT terms is the pair base
|
||||
// eg ADAUSD_PERP the "pair" parameter is ADAUSD
|
||||
func (b *Binance) FuturesPositionsInfo(ctx context.Context, marginAsset, pair string) ([]FuturesPositionInformation, error) {
|
||||
func (e *Exchange) FuturesPositionsInfo(ctx context.Context, marginAsset, pair string) ([]FuturesPositionInformation, error) {
|
||||
var resp []FuturesPositionInformation
|
||||
params := url.Values{}
|
||||
if marginAsset != "" {
|
||||
@@ -978,17 +978,17 @@ func (b *Binance) FuturesPositionsInfo(ctx context.Context, marginAsset, pair st
|
||||
params.Set("pair", pair)
|
||||
}
|
||||
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesPositionInfo, params, cFuturesDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesPositionInfo, params, cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesTradeHistory gets trade history for CoinMarginedFutures, account
|
||||
func (b *Binance) FuturesTradeHistory(ctx context.Context, symbol currency.Pair, pair string, startTime, endTime time.Time, limit, fromID int64) ([]FuturesAccountTradeList, error) {
|
||||
func (e *Exchange) 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
|
||||
if !symbol.IsEmpty() {
|
||||
rateLimit = cFuturesSymbolOrdersRate
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -1010,15 +1010,15 @@ func (b *Binance) FuturesTradeHistory(ctx context.Context, symbol currency.Pair,
|
||||
if fromID != 0 {
|
||||
params.Set("fromId", strconv.FormatInt(fromID, 10))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesAccountTradeList, params, rateLimit, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesAccountTradeList, params, rateLimit, &resp)
|
||||
}
|
||||
|
||||
// FuturesIncomeHistory gets income history for CoinMarginedFutures,
|
||||
func (b *Binance) FuturesIncomeHistory(ctx context.Context, symbol currency.Pair, incomeType string, startTime, endTime time.Time, limit int64) ([]FuturesIncomeHistoryData, error) {
|
||||
func (e *Exchange) 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() {
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -1040,25 +1040,25 @@ func (b *Binance) FuturesIncomeHistory(ctx context.Context, symbol currency.Pair
|
||||
if limit != 0 {
|
||||
params.Set("limit", strconv.FormatInt(limit, 10))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesIncomeHistory, params, cFuturesIncomeHistoryRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesIncomeHistory, params, cFuturesIncomeHistoryRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesNotionalBracket gets futures notional bracket
|
||||
func (b *Binance) FuturesNotionalBracket(ctx context.Context, pair string) ([]NotionalBracketData, error) {
|
||||
func (e *Exchange) FuturesNotionalBracket(ctx context.Context, pair string) ([]NotionalBracketData, error) {
|
||||
var resp []NotionalBracketData
|
||||
params := url.Values{}
|
||||
if pair != "" {
|
||||
params.Set("pair", pair)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesNotionalBracket, params, cFuturesDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesNotionalBracket, params, cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesForceOrders gets futures forced orders
|
||||
func (b *Binance) FuturesForceOrders(ctx context.Context, symbol currency.Pair, autoCloseType string, startTime, endTime time.Time) ([]ForcedOrdersData, error) {
|
||||
func (e *Exchange) FuturesForceOrders(ctx context.Context, symbol currency.Pair, autoCloseType string, startTime, endTime time.Time) ([]ForcedOrdersData, error) {
|
||||
var resp []ForcedOrdersData
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -1077,26 +1077,26 @@ func (b *Binance) FuturesForceOrders(ctx context.Context, symbol currency.Pair,
|
||||
params.Set("startTime", strconv.FormatInt(startTime.UnixMilli(), 10))
|
||||
params.Set("endTime", strconv.FormatInt(endTime.UnixMilli(), 10))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesUsersForceOrders, params, cFuturesDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesUsersForceOrders, params, cFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FuturesPositionsADLEstimate estimates ADL on positions
|
||||
func (b *Binance) FuturesPositionsADLEstimate(ctx context.Context, symbol currency.Pair) ([]ADLEstimateData, error) {
|
||||
func (e *Exchange) FuturesPositionsADLEstimate(ctx context.Context, symbol currency.Pair) ([]ADLEstimateData, error) {
|
||||
var resp []ADLEstimateData
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.CoinMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesADLQuantile, params, cFuturesAccountInformationRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestCoinMargined, http.MethodGet, cfuturesADLQuantile, params, cFuturesAccountInformationRate, &resp)
|
||||
}
|
||||
|
||||
// FetchCoinMarginExchangeLimits fetches coin margined order execution limits
|
||||
func (b *Binance) FetchCoinMarginExchangeLimits(ctx context.Context) ([]order.MinMaxLevel, error) {
|
||||
coinFutures, err := b.FuturesExchangeInfo(ctx)
|
||||
func (e *Exchange) FetchCoinMarginExchangeLimits(ctx context.Context) ([]order.MinMaxLevel, error) {
|
||||
coinFutures, err := e.FuturesExchangeInfo(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -18,15 +18,15 @@ import (
|
||||
var mockTests = false
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
b = new(Binance)
|
||||
if err := testexch.Setup(b); err != nil {
|
||||
e = new(Exchange)
|
||||
if err := testexch.Setup(e); err != nil {
|
||||
log.Fatalf("Binance Setup error: %s", err)
|
||||
}
|
||||
|
||||
if apiKey != "" && apiSecret != "" {
|
||||
b.API.AuthenticatedSupport = true
|
||||
b.API.CredentialsValidator.RequiresBase64DecodeSecret = false
|
||||
b.SetCredentials(apiKey, apiSecret, "", "", "", "")
|
||||
e.API.AuthenticatedSupport = true
|
||||
e.API.CredentialsValidator.RequiresBase64DecodeSecret = false
|
||||
e.SetCredentials(apiKey, apiSecret, "", "", "", "")
|
||||
}
|
||||
|
||||
if useTestNet {
|
||||
@@ -35,15 +35,15 @@ func TestMain(m *testing.M) {
|
||||
exchange.RestCoinMargined: testnetFutures,
|
||||
exchange.RestSpot: testnetSpotURL,
|
||||
} {
|
||||
if err := b.API.Endpoints.SetRunningURL(k.String(), v); err != nil {
|
||||
if err := e.API.Endpoints.SetRunningURL(k.String(), v); err != nil {
|
||||
log.Fatalf("Binance SetRunningURL error: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
b.Websocket.DataHandler = sharedtestvalues.GetWebsocketInterfaceChannelOverride()
|
||||
log.Printf(sharedtestvalues.LiveTesting, b.Name)
|
||||
if err := b.UpdateTradablePairs(context.Background(), true); err != nil {
|
||||
e.Websocket.DataHandler = sharedtestvalues.GetWebsocketInterfaceChannelOverride()
|
||||
log.Printf(sharedtestvalues.LiveTesting, e.Name)
|
||||
if err := e.UpdateTradablePairs(context.Background(), true); err != nil {
|
||||
log.Fatalf("Binance UpdateTradablePairs error: %s", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -20,16 +20,16 @@ func TestMain(m *testing.M) {
|
||||
log.Fatal("cannot use testnet with mock tests")
|
||||
}
|
||||
|
||||
b = new(Binance)
|
||||
if err := testexch.Setup(b); err != nil {
|
||||
e = new(Exchange)
|
||||
if err := testexch.Setup(e); err != nil {
|
||||
log.Fatalf("Binance Setup error: %s", err)
|
||||
}
|
||||
|
||||
if err := testexch.MockHTTPInstance(b); err != nil {
|
||||
if err := testexch.MockHTTPInstance(e); err != nil {
|
||||
log.Fatalf("Binance MockHTTPInstance error: %s", err)
|
||||
}
|
||||
|
||||
if err := b.UpdateTradablePairs(context.Background(), true); err != nil {
|
||||
if err := e.UpdateTradablePairs(context.Background(), true); err != nil {
|
||||
log.Fatalf("Binance UpdateTradablePairs error: %s", err)
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -69,11 +69,11 @@ const (
|
||||
)
|
||||
|
||||
// UServerTime gets the server time
|
||||
func (b *Binance) UServerTime(ctx context.Context) (time.Time, error) {
|
||||
func (e *Exchange) UServerTime(ctx context.Context) (time.Time, error) {
|
||||
var data struct {
|
||||
ServerTime types.Time `json:"serverTime"`
|
||||
}
|
||||
err := b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesServerTime, uFuturesDefaultRate, &data)
|
||||
err := e.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesServerTime, uFuturesDefaultRate, &data)
|
||||
if err != nil {
|
||||
return time.Time{}, err
|
||||
}
|
||||
@@ -81,14 +81,14 @@ func (b *Binance) UServerTime(ctx context.Context) (time.Time, error) {
|
||||
}
|
||||
|
||||
// UExchangeInfo stores usdt margined futures data
|
||||
func (b *Binance) UExchangeInfo(ctx context.Context) (UFuturesExchangeInfo, error) {
|
||||
func (e *Exchange) UExchangeInfo(ctx context.Context) (UFuturesExchangeInfo, error) {
|
||||
var resp UFuturesExchangeInfo
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesExchangeInfo, uFuturesDefaultRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesExchangeInfo, uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UFuturesOrderbook gets orderbook data for usdt margined futures
|
||||
func (b *Binance) UFuturesOrderbook(ctx context.Context, symbol currency.Pair, limit int64) (*OrderBook, error) {
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
func (e *Exchange) UFuturesOrderbook(ctx context.Context, symbol currency.Pair, limit int64) (*OrderBook, error) {
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -114,7 +114,7 @@ func (b *Binance) UFuturesOrderbook(ctx context.Context, symbol currency.Pair, l
|
||||
}
|
||||
|
||||
var data *OrderbookData
|
||||
if err := b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesOrderbook+params.Encode(), rateBudget, &data); err != nil {
|
||||
if err := e.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesOrderbook+params.Encode(), rateBudget, &data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -137,10 +137,10 @@ func (b *Binance) UFuturesOrderbook(ctx context.Context, symbol currency.Pair, l
|
||||
}
|
||||
|
||||
// URecentTrades gets recent trades for usdt margined futures
|
||||
func (b *Binance) URecentTrades(ctx context.Context, symbol currency.Pair, fromID string, limit int64) ([]UPublicTradesData, error) {
|
||||
func (e *Exchange) 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)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -151,14 +151,14 @@ func (b *Binance) URecentTrades(ctx context.Context, symbol currency.Pair, fromI
|
||||
if limit > 0 {
|
||||
params.Set("limit", strconv.FormatInt(limit, 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesRecentTrades+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesRecentTrades+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UFuturesHistoricalTrades gets historical public trades for USDTMarginedFutures
|
||||
func (b *Binance) UFuturesHistoricalTrades(ctx context.Context, symbol currency.Pair, fromID string, limit int64) ([]any, error) {
|
||||
func (e *Exchange) UFuturesHistoricalTrades(ctx context.Context, symbol currency.Pair, fromID string, limit int64) ([]any, error) {
|
||||
var resp []any
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -169,14 +169,14 @@ func (b *Binance) UFuturesHistoricalTrades(ctx context.Context, symbol currency.
|
||||
if limit > 0 {
|
||||
params.Set("limit", strconv.FormatInt(limit, 10))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesHistoricalTrades, params, uFuturesHistoricalTradesRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesHistoricalTrades, params, uFuturesHistoricalTradesRate, &resp)
|
||||
}
|
||||
|
||||
// UCompressedTrades gets compressed public trades for usdt margined futures
|
||||
func (b *Binance) UCompressedTrades(ctx context.Context, symbol currency.Pair, fromID string, limit int64, startTime, endTime time.Time) ([]UCompressedTradeData, error) {
|
||||
func (e *Exchange) 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)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -194,13 +194,13 @@ func (b *Binance) UCompressedTrades(ctx context.Context, symbol currency.Pair, f
|
||||
params.Set("startTime", strconv.FormatInt(startTime.UnixMilli(), 10))
|
||||
params.Set("endTime", strconv.FormatInt(endTime.UnixMilli(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesCompressedTrades+params.Encode(), uFuturesHistoricalTradesRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesCompressedTrades+params.Encode(), uFuturesHistoricalTradesRate, &resp)
|
||||
}
|
||||
|
||||
// UKlineData gets kline data for usdt margined futures
|
||||
func (b *Binance) UKlineData(ctx context.Context, symbol currency.Pair, interval string, limit uint64, startTime, endTime time.Time) ([]FuturesCandleStick, error) {
|
||||
func (e *Exchange) UKlineData(ctx context.Context, symbol currency.Pair, interval string, limit uint64, startTime, endTime time.Time) ([]FuturesCandleStick, error) {
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -232,7 +232,7 @@ func (b *Binance) UKlineData(ctx context.Context, symbol currency.Pair, interval
|
||||
}
|
||||
|
||||
var resp []FuturesCandleStick
|
||||
if err := b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesKlineData+params.Encode(), rateBudget, &resp); err != nil {
|
||||
if err := e.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesKlineData+params.Encode(), rateBudget, &resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -240,23 +240,23 @@ func (b *Binance) UKlineData(ctx context.Context, symbol currency.Pair, interval
|
||||
}
|
||||
|
||||
// UGetMarkPrice gets mark price data for USDTMarginedFutures
|
||||
func (b *Binance) UGetMarkPrice(ctx context.Context, symbol currency.Pair) ([]UMarkPrice, error) {
|
||||
func (e *Exchange) UGetMarkPrice(ctx context.Context, symbol currency.Pair) ([]UMarkPrice, error) {
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
var tempResp UMarkPrice
|
||||
err = b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesMarkPrice+params.Encode(), uFuturesDefaultRate, &tempResp)
|
||||
err = e.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(ctx, exchange.RestUSDTMargined, ufuturesMarkPrice+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
err := e.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesMarkPrice+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -264,17 +264,17 @@ func (b *Binance) UGetMarkPrice(ctx context.Context, symbol currency.Pair) ([]UM
|
||||
}
|
||||
|
||||
// UGetFundingRateInfo returns extra details about funding rates
|
||||
func (b *Binance) UGetFundingRateInfo(ctx context.Context) ([]FundingRateInfoResponse, error) {
|
||||
func (e *Exchange) UGetFundingRateInfo(ctx context.Context) ([]FundingRateInfoResponse, error) {
|
||||
var resp []FundingRateInfoResponse
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesFundingRateInfo, uFuturesDefaultRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesFundingRateInfo, uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UGetFundingHistory gets funding history for USDTMarginedFutures
|
||||
func (b *Binance) UGetFundingHistory(ctx context.Context, symbol currency.Pair, limit int64, startTime, endTime time.Time) ([]FundingRateHistory, error) {
|
||||
func (e *Exchange) UGetFundingHistory(ctx context.Context, symbol currency.Pair, limit int64, startTime, endTime time.Time) ([]FundingRateHistory, error) {
|
||||
var resp []FundingRateHistory
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -290,89 +290,89 @@ func (b *Binance) UGetFundingHistory(ctx context.Context, symbol currency.Pair,
|
||||
params.Set("startTime", strconv.FormatInt(startTime.UnixMilli(), 10))
|
||||
params.Set("endTime", strconv.FormatInt(endTime.UnixMilli(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesFundingRateHistory+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesFundingRateHistory+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// U24HTickerPriceChangeStats gets 24hr ticker price change stats for USDTMarginedFutures
|
||||
func (b *Binance) U24HTickerPriceChangeStats(ctx context.Context, symbol currency.Pair) ([]U24HrPriceChangeStats, error) {
|
||||
func (e *Exchange) U24HTickerPriceChangeStats(ctx context.Context, symbol currency.Pair) ([]U24HrPriceChangeStats, error) {
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
var tempResp U24HrPriceChangeStats
|
||||
err = b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesTickerPriceStats+params.Encode(), uFuturesDefaultRate, &tempResp)
|
||||
err = e.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(ctx, exchange.RestUSDTMargined, ufuturesTickerPriceStats+params.Encode(), uFuturesTickerPriceHistoryRate, &resp)
|
||||
err := e.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesTickerPriceStats+params.Encode(), uFuturesTickerPriceHistoryRate, &resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// USymbolPriceTicker gets symbol price ticker for USDTMarginedFutures
|
||||
func (b *Binance) USymbolPriceTicker(ctx context.Context, symbol currency.Pair) ([]USymbolPriceTicker, error) {
|
||||
func (e *Exchange) USymbolPriceTicker(ctx context.Context, symbol currency.Pair) ([]USymbolPriceTicker, error) {
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
var tempResp USymbolPriceTicker
|
||||
err = b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesSymbolPriceTicker+params.Encode(), uFuturesDefaultRate, &tempResp)
|
||||
err = e.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(ctx, exchange.RestUSDTMargined, ufuturesSymbolPriceTicker+params.Encode(), uFuturesOrderbookTickerAllRate, &resp)
|
||||
err := e.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesSymbolPriceTicker+params.Encode(), uFuturesOrderbookTickerAllRate, &resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// USymbolOrderbookTicker gets symbol orderbook ticker
|
||||
func (b *Binance) USymbolOrderbookTicker(ctx context.Context, symbol currency.Pair) ([]USymbolOrderbookTicker, error) {
|
||||
func (e *Exchange) USymbolOrderbookTicker(ctx context.Context, symbol currency.Pair) ([]USymbolOrderbookTicker, error) {
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
var tempResp USymbolOrderbookTicker
|
||||
err = b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesSymbolOrderbook+params.Encode(), uFuturesDefaultRate, &tempResp)
|
||||
err = e.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(ctx, exchange.RestUSDTMargined, ufuturesTickerPriceStats+params.Encode(), uFuturesOrderbookTickerAllRate, &resp)
|
||||
err := e.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesTickerPriceStats+params.Encode(), uFuturesOrderbookTickerAllRate, &resp)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// UOpenInterest gets open interest data for USDTMarginedFutures
|
||||
func (b *Binance) UOpenInterest(ctx context.Context, symbol currency.Pair) (UOpenInterestData, error) {
|
||||
func (e *Exchange) UOpenInterest(ctx context.Context, symbol currency.Pair) (UOpenInterestData, error) {
|
||||
var resp UOpenInterestData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesOpenInterest+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesOpenInterest+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UOpenInterestStats gets open interest stats for USDTMarginedFutures
|
||||
func (b *Binance) UOpenInterestStats(ctx context.Context, symbol currency.Pair, period string, limit int64, startTime, endTime time.Time) ([]UOpenInterestStats, error) {
|
||||
func (e *Exchange) 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)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -391,14 +391,14 @@ func (b *Binance) UOpenInterestStats(ctx context.Context, symbol currency.Pair,
|
||||
params.Set("startTime", strconv.FormatInt(startTime.UnixMilli(), 10))
|
||||
params.Set("endTime", strconv.FormatInt(endTime.UnixMilli(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesOpenInterestStats+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
return resp, e.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(ctx context.Context, symbol currency.Pair, period string, limit int64, startTime, endTime time.Time) ([]ULongShortRatio, error) {
|
||||
func (e *Exchange) 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)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -417,14 +417,14 @@ func (b *Binance) UTopAcccountsLongShortRatio(ctx context.Context, symbol curren
|
||||
params.Set("startTime", strconv.FormatInt(startTime.UnixMilli(), 10))
|
||||
params.Set("endTime", strconv.FormatInt(endTime.UnixMilli(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesTopAccountsRatio+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesTopAccountsRatio+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UTopPostionsLongShortRatio gets long/short ratio data for top positions' in ufutures
|
||||
func (b *Binance) UTopPostionsLongShortRatio(ctx context.Context, symbol currency.Pair, period string, limit int64, startTime, endTime time.Time) ([]ULongShortRatio, error) {
|
||||
func (e *Exchange) 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)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -443,14 +443,14 @@ func (b *Binance) UTopPostionsLongShortRatio(ctx context.Context, symbol currenc
|
||||
params.Set("startTime", strconv.FormatInt(startTime.UnixMilli(), 10))
|
||||
params.Set("endTime", strconv.FormatInt(endTime.UnixMilli(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesTopPositionsRatio+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesTopPositionsRatio+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UGlobalLongShortRatio gets the global long/short ratio data for USDTMarginedFutures
|
||||
func (b *Binance) UGlobalLongShortRatio(ctx context.Context, symbol currency.Pair, period string, limit int64, startTime, endTime time.Time) ([]ULongShortRatio, error) {
|
||||
func (e *Exchange) 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)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -469,14 +469,14 @@ func (b *Binance) UGlobalLongShortRatio(ctx context.Context, symbol currency.Pai
|
||||
params.Set("startTime", strconv.FormatInt(startTime.UnixMilli(), 10))
|
||||
params.Set("endTime", strconv.FormatInt(endTime.UnixMilli(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesLongShortRatio+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesLongShortRatio+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UTakerBuySellVol gets takers' buy/sell ratio for USDTMarginedFutures
|
||||
func (b *Binance) UTakerBuySellVol(ctx context.Context, symbol currency.Pair, period string, limit int64, startTime, endTime time.Time) ([]UTakerVolumeData, error) {
|
||||
func (e *Exchange) 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)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -495,34 +495,34 @@ func (b *Binance) UTakerBuySellVol(ctx context.Context, symbol currency.Pair, pe
|
||||
params.Set("startTime", strconv.FormatInt(startTime.UnixMilli(), 10))
|
||||
params.Set("endTime", strconv.FormatInt(endTime.UnixMilli(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesBuySellVolume+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesBuySellVolume+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UCompositeIndexInfo stores composite indexs' info for usdt margined futures
|
||||
func (b *Binance) UCompositeIndexInfo(ctx context.Context, symbol currency.Pair) ([]UCompositeIndexInfoData, error) {
|
||||
func (e *Exchange) UCompositeIndexInfo(ctx context.Context, symbol currency.Pair) ([]UCompositeIndexInfoData, error) {
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
var tempResp UCompositeIndexInfoData
|
||||
err = b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesCompositeIndexInfo+params.Encode(), uFuturesDefaultRate, &tempResp)
|
||||
err = e.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(ctx, exchange.RestUSDTMargined, ufuturesCompositeIndexInfo+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestUSDTMargined, ufuturesCompositeIndexInfo+params.Encode(), uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UFuturesNewOrder sends a new order for USDTMarginedFutures
|
||||
func (b *Binance) UFuturesNewOrder(ctx context.Context, data *UFuturesNewOrderRequest) (UOrderData, error) {
|
||||
func (e *Exchange) UFuturesNewOrder(ctx context.Context, data *UFuturesNewOrderRequest) (UOrderData, error) {
|
||||
var resp UOrderData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(data.Symbol, asset.USDTMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(data.Symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -572,11 +572,11 @@ func (b *Binance) UFuturesNewOrder(ctx context.Context, data *UFuturesNewOrderRe
|
||||
if data.CallbackRate != 0 {
|
||||
params.Set("callbackRate", strconv.FormatFloat(data.CallbackRate, 'f', -1, 64))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodPost, ufuturesOrder, params, uFuturesOrdersDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodPost, ufuturesOrder, params, uFuturesOrdersDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UPlaceBatchOrders places batch orders
|
||||
func (b *Binance) UPlaceBatchOrders(ctx context.Context, data []PlaceBatchOrderData) ([]UOrderData, error) {
|
||||
func (e *Exchange) UPlaceBatchOrders(ctx context.Context, data []PlaceBatchOrderData) ([]UOrderData, error) {
|
||||
var resp []UOrderData
|
||||
params := url.Values{}
|
||||
for x := range data {
|
||||
@@ -584,7 +584,7 @@ func (b *Binance) UPlaceBatchOrders(ctx context.Context, data []PlaceBatchOrderD
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
formattedPair, err := b.FormatExchangeCurrency(unformattedPair, asset.USDTMarginedFutures)
|
||||
formattedPair, err := e.FormatExchangeCurrency(unformattedPair, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -610,14 +610,14 @@ func (b *Binance) UPlaceBatchOrders(ctx context.Context, data []PlaceBatchOrderD
|
||||
return resp, err
|
||||
}
|
||||
params.Set("batchOrders", string(jsonData))
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodPost, ufuturesBatchOrder, params, uFuturesBatchOrdersRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodPost, ufuturesBatchOrder, params, uFuturesBatchOrdersRate, &resp)
|
||||
}
|
||||
|
||||
// UGetOrderData gets order data for USDTMarginedFutures
|
||||
func (b *Binance) UGetOrderData(ctx context.Context, symbol currency.Pair, orderID, cliOrderID string) (UOrderData, error) {
|
||||
func (e *Exchange) 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)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -628,14 +628,14 @@ func (b *Binance) UGetOrderData(ctx context.Context, symbol currency.Pair, order
|
||||
if cliOrderID != "" {
|
||||
params.Set("origClientOrderId", cliOrderID)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesOrder, params, uFuturesOrdersDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesOrder, params, uFuturesOrdersDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UCancelOrder cancel an order for USDTMarginedFutures
|
||||
func (b *Binance) UCancelOrder(ctx context.Context, symbol currency.Pair, orderID, cliOrderID string) (UOrderData, error) {
|
||||
func (e *Exchange) 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)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -646,26 +646,26 @@ func (b *Binance) UCancelOrder(ctx context.Context, symbol currency.Pair, orderI
|
||||
if cliOrderID != "" {
|
||||
params.Set("origClientOrderId", cliOrderID)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodDelete, ufuturesOrder, params, uFuturesOrdersDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodDelete, ufuturesOrder, params, uFuturesOrdersDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UCancelAllOpenOrders cancels all open orders for a symbol ufutures
|
||||
func (b *Binance) UCancelAllOpenOrders(ctx context.Context, symbol currency.Pair) (GenericAuthResponse, error) {
|
||||
func (e *Exchange) UCancelAllOpenOrders(ctx context.Context, symbol currency.Pair) (GenericAuthResponse, error) {
|
||||
var resp GenericAuthResponse
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodDelete, ufuturesCancelAllOrders, params, uFuturesOrdersDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodDelete, ufuturesCancelAllOrders, params, uFuturesOrdersDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UCancelBatchOrders cancel batch order for USDTMarginedFutures
|
||||
func (b *Binance) UCancelBatchOrders(ctx context.Context, symbol currency.Pair, orderIDList, origCliOrdIDList []string) ([]UOrderData, error) {
|
||||
func (e *Exchange) 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)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -684,28 +684,28 @@ func (b *Binance) UCancelBatchOrders(ctx context.Context, symbol currency.Pair,
|
||||
}
|
||||
params.Set("origClientOrderIdList", string(jsonCliOrders))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodDelete, ufuturesBatchOrder, params, uFuturesOrdersDefaultRate, &resp)
|
||||
return resp, e.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(ctx context.Context, symbol currency.Pair, countdownTime int64) (AutoCancelAllOrdersData, error) {
|
||||
func (e *Exchange) UAutoCancelAllOpenOrders(ctx context.Context, symbol currency.Pair, countdownTime int64) (AutoCancelAllOrdersData, error) {
|
||||
var resp AutoCancelAllOrdersData
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
params.Set("countdownTime", strconv.FormatInt(countdownTime, 10))
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodPost, ufuturesCountdownCancel, params, uFuturesCountdownCancelRate, &resp)
|
||||
return resp, e.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(ctx context.Context, symbol currency.Pair, orderID, origClientOrderID string) (UOrderData, error) {
|
||||
func (e *Exchange) UFetchOpenOrder(ctx context.Context, symbol currency.Pair, orderID, origClientOrderID string) (UOrderData, error) {
|
||||
var resp UOrderData
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -717,17 +717,17 @@ func (b *Binance) UFetchOpenOrder(ctx context.Context, symbol currency.Pair, ord
|
||||
if origClientOrderID != "" {
|
||||
params.Set("origClientOrderId", origClientOrderID)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesOpenOrder, params, uFuturesOrdersDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesOpenOrder, params, uFuturesOrdersDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UAllAccountOpenOrders gets all account's orders for USDTMarginedFutures
|
||||
func (b *Binance) UAllAccountOpenOrders(ctx context.Context, symbol currency.Pair) ([]UOrderData, error) {
|
||||
func (e *Exchange) UAllAccountOpenOrders(ctx context.Context, symbol currency.Pair) ([]UOrderData, error) {
|
||||
var resp []UOrderData
|
||||
params := url.Values{}
|
||||
rateLimit := uFuturesGetAllOpenOrdersRate
|
||||
if !symbol.IsEmpty() {
|
||||
rateLimit = uFuturesOrdersDefaultRate
|
||||
p, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
p, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -736,14 +736,14 @@ func (b *Binance) UAllAccountOpenOrders(ctx context.Context, symbol currency.Pai
|
||||
// extend the receive window when all currencies to prevent "recvwindow" error
|
||||
params.Set("recvWindow", "10000")
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesAllOpenOrders, params, rateLimit, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesAllOpenOrders, params, rateLimit, &resp)
|
||||
}
|
||||
|
||||
// UAllAccountOrders gets all account's orders for USDTMarginedFutures
|
||||
func (b *Binance) UAllAccountOrders(ctx context.Context, symbol currency.Pair, orderID, limit int64, startTime, endTime time.Time) ([]UFuturesOrderData, error) {
|
||||
func (e *Exchange) 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)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -760,26 +760,26 @@ func (b *Binance) UAllAccountOrders(ctx context.Context, symbol currency.Pair, o
|
||||
if !endTime.IsZero() {
|
||||
params.Set("endTime", strconv.FormatInt(endTime.UnixMilli(), 10))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesAllOrders, params, uFuturesGetAllOrdersRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesAllOrders, params, uFuturesGetAllOrdersRate, &resp)
|
||||
}
|
||||
|
||||
// UAccountBalanceV2 gets V2 account balance data
|
||||
func (b *Binance) UAccountBalanceV2(ctx context.Context) ([]UAccountBalanceV2Data, error) {
|
||||
func (e *Exchange) UAccountBalanceV2(ctx context.Context) ([]UAccountBalanceV2Data, error) {
|
||||
var resp []UAccountBalanceV2Data
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesAccountBalance, nil, uFuturesOrdersDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesAccountBalance, nil, uFuturesOrdersDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UAccountInformationV2 gets V2 account balance data
|
||||
func (b *Binance) UAccountInformationV2(ctx context.Context) (UAccountInformationV2Data, error) {
|
||||
func (e *Exchange) UAccountInformationV2(ctx context.Context) (UAccountInformationV2Data, error) {
|
||||
var resp UAccountInformationV2Data
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesAccountInfo, nil, uFuturesAccountInformationRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesAccountInfo, nil, uFuturesAccountInformationRate, &resp)
|
||||
}
|
||||
|
||||
// UChangeInitialLeverageRequest sends a request to change account's initial leverage
|
||||
func (b *Binance) UChangeInitialLeverageRequest(ctx context.Context, symbol currency.Pair, leverage float64) (UChangeInitialLeverage, error) {
|
||||
func (e *Exchange) UChangeInitialLeverageRequest(ctx context.Context, symbol currency.Pair, leverage float64) (UChangeInitialLeverage, error) {
|
||||
var resp UChangeInitialLeverage
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -788,13 +788,13 @@ func (b *Binance) UChangeInitialLeverageRequest(ctx context.Context, symbol curr
|
||||
return resp, errors.New("invalid leverage")
|
||||
}
|
||||
params.Set("leverage", strconv.FormatFloat(leverage, 'f', -1, 64))
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodPost, ufuturesChangeInitialLeverage, params, uFuturesDefaultRate, &resp)
|
||||
return resp, e.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(ctx context.Context, symbol currency.Pair, marginType string) error {
|
||||
func (e *Exchange) UChangeInitialMarginType(ctx context.Context, symbol currency.Pair, marginType string) error {
|
||||
params := url.Values{}
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -803,14 +803,14 @@ func (b *Binance) UChangeInitialMarginType(ctx context.Context, symbol currency.
|
||||
return errors.New("invalid marginType")
|
||||
}
|
||||
params.Set("marginType", marginType)
|
||||
return b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodPost, ufuturesChangeMarginType, params, uFuturesDefaultRate, nil)
|
||||
return e.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodPost, ufuturesChangeMarginType, params, uFuturesDefaultRate, nil)
|
||||
}
|
||||
|
||||
// UModifyIsolatedPositionMarginReq sends a request to modify isolated margin for USDTMarginedFutures
|
||||
func (b *Binance) UModifyIsolatedPositionMarginReq(ctx context.Context, symbol currency.Pair, positionSide, changeType string, amount float64) (UModifyIsolatedPosMargin, error) {
|
||||
func (e *Exchange) 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)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -824,14 +824,14 @@ func (b *Binance) UModifyIsolatedPositionMarginReq(ctx context.Context, symbol c
|
||||
params.Set("positionSide", positionSide)
|
||||
}
|
||||
params.Set("amount", strconv.FormatFloat(amount, 'f', -1, 64))
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodPost, ufuturesModifyMargin, params, uFuturesDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodPost, ufuturesModifyMargin, params, uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UPositionMarginChangeHistory gets margin change history for USDTMarginedFutures
|
||||
func (b *Binance) UPositionMarginChangeHistory(ctx context.Context, symbol currency.Pair, changeType string, limit int64, startTime, endTime time.Time) ([]UPositionMarginChangeHistoryData, error) {
|
||||
func (e *Exchange) 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)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -851,42 +851,42 @@ func (b *Binance) UPositionMarginChangeHistory(ctx context.Context, symbol curre
|
||||
params.Set("startTime", strconv.FormatInt(startTime.UnixMilli(), 10))
|
||||
params.Set("endTime", strconv.FormatInt(endTime.UnixMilli(), 10))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesMarginChangeHistory, params, uFuturesDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesMarginChangeHistory, params, uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UPositionsInfoV2 gets positions' info for USDTMarginedFutures
|
||||
func (b *Binance) UPositionsInfoV2(ctx context.Context, symbol currency.Pair) ([]UPositionInformationV2, error) {
|
||||
func (e *Exchange) UPositionsInfoV2(ctx context.Context, symbol currency.Pair) ([]UPositionInformationV2, error) {
|
||||
var resp []UPositionInformationV2
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesPositionInfo, params, uFuturesDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesPositionInfo, params, uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UGetCommissionRates returns the commission rates for USDTMarginedFutures
|
||||
func (b *Binance) UGetCommissionRates(ctx context.Context, symbol currency.Pair) ([]UPositionInformationV2, error) {
|
||||
func (e *Exchange) UGetCommissionRates(ctx context.Context, symbol currency.Pair) ([]UPositionInformationV2, error) {
|
||||
var resp []UPositionInformationV2
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesCommissionRate, params, uFuturesDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesCommissionRate, params, uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UAccountTradesHistory gets account's trade history data for USDTMarginedFutures
|
||||
func (b *Binance) UAccountTradesHistory(ctx context.Context, symbol currency.Pair, fromID string, limit int64, startTime, endTime time.Time) ([]UAccountTradeHistory, error) {
|
||||
func (e *Exchange) 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)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -904,14 +904,14 @@ func (b *Binance) UAccountTradesHistory(ctx context.Context, symbol currency.Pai
|
||||
params.Set("startTime", strconv.FormatInt(startTime.UnixMilli(), 10))
|
||||
params.Set("endTime", strconv.FormatInt(endTime.UnixMilli(), 10))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesAccountTradeList, params, uFuturesAccountInformationRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesAccountTradeList, params, uFuturesAccountInformationRate, &resp)
|
||||
}
|
||||
|
||||
// UAccountIncomeHistory gets account's income history data for USDTMarginedFutures
|
||||
func (b *Binance) UAccountIncomeHistory(ctx context.Context, symbol currency.Pair, incomeType string, limit int64, startTime, endTime time.Time) ([]UAccountIncomeHistory, error) {
|
||||
func (e *Exchange) 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)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -932,45 +932,45 @@ func (b *Binance) UAccountIncomeHistory(ctx context.Context, symbol currency.Pai
|
||||
params.Set("startTime", strconv.FormatInt(startTime.UnixMilli(), 10))
|
||||
params.Set("endTime", strconv.FormatInt(endTime.UnixMilli(), 10))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesIncomeHistory, params, uFuturesIncomeHistoryRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesIncomeHistory, params, uFuturesIncomeHistoryRate, &resp)
|
||||
}
|
||||
|
||||
// UGetNotionalAndLeverageBrackets gets account's notional and leverage brackets for USDTMarginedFutures
|
||||
func (b *Binance) UGetNotionalAndLeverageBrackets(ctx context.Context, symbol currency.Pair) ([]UNotionalLeverageAndBrakcetsData, error) {
|
||||
func (e *Exchange) UGetNotionalAndLeverageBrackets(ctx context.Context, symbol currency.Pair) ([]UNotionalLeverageAndBrakcetsData, error) {
|
||||
var resp []UNotionalLeverageAndBrakcetsData
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesNotionalBracket, params, uFuturesDefaultRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesNotionalBracket, params, uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// UPositionsADLEstimate gets estimated ADL data for USDTMarginedFutures positions
|
||||
func (b *Binance) UPositionsADLEstimate(ctx context.Context, symbol currency.Pair) (UPositionADLEstimationData, error) {
|
||||
func (e *Exchange) UPositionsADLEstimate(ctx context.Context, symbol currency.Pair) (UPositionADLEstimationData, error) {
|
||||
var resp UPositionADLEstimationData
|
||||
params := url.Values{}
|
||||
if !symbol.IsEmpty() {
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
params.Set("symbol", symbolValue)
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesADLQuantile, params, uFuturesAccountInformationRate, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesADLQuantile, params, uFuturesAccountInformationRate, &resp)
|
||||
}
|
||||
|
||||
// UAccountForcedOrders gets account's forced (liquidation) orders for USDTMarginedFutures
|
||||
func (b *Binance) UAccountForcedOrders(ctx context.Context, symbol currency.Pair, autoCloseType string, limit int64, startTime, endTime time.Time) ([]UForceOrdersData, error) {
|
||||
func (e *Exchange) 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
|
||||
if !symbol.IsEmpty() {
|
||||
rateLimit = uFuturesCurrencyForceOrdersRate
|
||||
symbolValue, err := b.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
symbolValue, err := e.FormatSymbol(symbol, asset.USDTMarginedFutures)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -992,18 +992,18 @@ func (b *Binance) UAccountForcedOrders(ctx context.Context, symbol currency.Pair
|
||||
params.Set("startTime", strconv.FormatInt(startTime.UnixMilli(), 10))
|
||||
params.Set("endTime", strconv.FormatInt(endTime.UnixMilli(), 10))
|
||||
}
|
||||
return resp, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesUsersForceOrders, params, rateLimit, &resp)
|
||||
return resp, e.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, ufuturesUsersForceOrders, params, rateLimit, &resp)
|
||||
}
|
||||
|
||||
// GetPerpMarkets returns exchange information. Check binance_types for more information
|
||||
func (b *Binance) GetPerpMarkets(ctx context.Context) (PerpsExchangeInfo, error) {
|
||||
func (e *Exchange) GetPerpMarkets(ctx context.Context) (PerpsExchangeInfo, error) {
|
||||
var resp PerpsExchangeInfo
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestUSDTMargined, perpExchangeInfo, uFuturesDefaultRate, &resp)
|
||||
return resp, e.SendHTTPRequest(ctx, exchange.RestUSDTMargined, perpExchangeInfo, uFuturesDefaultRate, &resp)
|
||||
}
|
||||
|
||||
// FetchUSDTMarginExchangeLimits fetches USDT margined order execution limits
|
||||
func (b *Binance) FetchUSDTMarginExchangeLimits(ctx context.Context) ([]order.MinMaxLevel, error) {
|
||||
usdtFutures, err := b.UExchangeInfo(ctx)
|
||||
func (e *Exchange) FetchUSDTMarginExchangeLimits(ctx context.Context) ([]order.MinMaxLevel, error) {
|
||||
usdtFutures, err := e.UExchangeInfo(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1045,17 +1045,17 @@ func (b *Binance) FetchUSDTMarginExchangeLimits(ctx context.Context) ([]order.Mi
|
||||
}
|
||||
|
||||
// SetAssetsMode sets the current asset margin type, true for multi, false for single
|
||||
func (b *Binance) SetAssetsMode(ctx context.Context, multiMargin bool) error {
|
||||
func (e *Exchange) SetAssetsMode(ctx context.Context, multiMargin bool) error {
|
||||
params := url.Values{
|
||||
"multiAssetsMargin": {strconv.FormatBool(multiMargin)},
|
||||
}
|
||||
return b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodPost, uFuturesMultiAssetsMargin, params, uFuturesDefaultRate, nil)
|
||||
return e.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodPost, uFuturesMultiAssetsMargin, params, uFuturesDefaultRate, nil)
|
||||
}
|
||||
|
||||
// GetAssetsMode returns the current asset margin type, true for multi, false for single
|
||||
func (b *Binance) GetAssetsMode(ctx context.Context) (bool, error) {
|
||||
func (e *Exchange) GetAssetsMode(ctx context.Context) (bool, error) {
|
||||
var result struct {
|
||||
MultiAssetsMargin bool `json:"multiAssetsMargin"`
|
||||
}
|
||||
return result.MultiAssetsMargin, b.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, uFuturesMultiAssetsMargin, nil, uFuturesDefaultRate, &result)
|
||||
return result.MultiAssetsMargin, e.SendAuthHTTPRequest(ctx, exchange.RestUSDTMargined, http.MethodGet, uFuturesMultiAssetsMargin, nil, uFuturesDefaultRate, &result)
|
||||
}
|
||||
|
||||
@@ -50,68 +50,68 @@ var (
|
||||
)
|
||||
|
||||
// WsConnect initiates a websocket connection
|
||||
func (b *Binance) WsConnect() error {
|
||||
func (e *Exchange) WsConnect() error {
|
||||
ctx := context.TODO()
|
||||
if !b.Websocket.IsEnabled() || !b.IsEnabled() {
|
||||
if !e.Websocket.IsEnabled() || !e.IsEnabled() {
|
||||
return websocket.ErrWebsocketNotEnabled
|
||||
}
|
||||
|
||||
var dialer gws.Dialer
|
||||
dialer.HandshakeTimeout = b.Config.HTTPTimeout
|
||||
dialer.HandshakeTimeout = e.Config.HTTPTimeout
|
||||
dialer.Proxy = http.ProxyFromEnvironment
|
||||
var err error
|
||||
if b.Websocket.CanUseAuthenticatedEndpoints() {
|
||||
listenKey, err = b.GetWsAuthStreamKey(ctx)
|
||||
if e.Websocket.CanUseAuthenticatedEndpoints() {
|
||||
listenKey, err = e.GetWsAuthStreamKey(ctx)
|
||||
if err != nil {
|
||||
b.Websocket.SetCanUseAuthenticatedEndpoints(false)
|
||||
e.Websocket.SetCanUseAuthenticatedEndpoints(false)
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%v unable to connect to authenticated Websocket. Error: %s",
|
||||
b.Name,
|
||||
e.Name,
|
||||
err)
|
||||
} else {
|
||||
// cleans on failed connection
|
||||
clean := strings.Split(b.Websocket.GetWebsocketURL(), "?streams=")
|
||||
clean := strings.Split(e.Websocket.GetWebsocketURL(), "?streams=")
|
||||
authPayload := clean[0] + "?streams=" + listenKey
|
||||
err = b.Websocket.SetWebsocketURL(authPayload, false, false)
|
||||
err = e.Websocket.SetWebsocketURL(authPayload, false, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err = b.Websocket.Conn.Dial(ctx, &dialer, http.Header{})
|
||||
err = e.Websocket.Conn.Dial(ctx, &dialer, http.Header{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v - Unable to connect to Websocket. Error: %s",
|
||||
b.Name,
|
||||
e.Name,
|
||||
err)
|
||||
}
|
||||
|
||||
if b.Websocket.CanUseAuthenticatedEndpoints() {
|
||||
go b.KeepAuthKeyAlive(ctx)
|
||||
if e.Websocket.CanUseAuthenticatedEndpoints() {
|
||||
go e.KeepAuthKeyAlive(ctx)
|
||||
}
|
||||
|
||||
b.Websocket.Conn.SetupPingHandler(request.Unset, websocket.PingHandler{
|
||||
e.Websocket.Conn.SetupPingHandler(request.Unset, websocket.PingHandler{
|
||||
UseGorillaHandler: true,
|
||||
MessageType: gws.PongMessage,
|
||||
Delay: pingDelay,
|
||||
})
|
||||
|
||||
b.Websocket.Wg.Add(1)
|
||||
go b.wsReadData()
|
||||
e.Websocket.Wg.Add(1)
|
||||
go e.wsReadData()
|
||||
|
||||
b.setupOrderbookManager(ctx)
|
||||
e.setupOrderbookManager(ctx)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *Binance) setupOrderbookManager(ctx context.Context) {
|
||||
if b.obm == nil {
|
||||
b.obm = &orderbookManager{
|
||||
func (e *Exchange) setupOrderbookManager(ctx context.Context) {
|
||||
if e.obm == nil {
|
||||
e.obm = &orderbookManager{
|
||||
state: make(map[currency.Code]map[currency.Code]map[asset.Item]*update),
|
||||
jobs: make(chan job, maxWSOrderbookJobs),
|
||||
}
|
||||
} else {
|
||||
// Change state on reconnect for initial sync.
|
||||
for _, m1 := range b.obm.state {
|
||||
for _, m1 := range e.obm.state {
|
||||
for _, m2 := range m1 {
|
||||
for _, update := range m2 {
|
||||
update.initialSync = true
|
||||
@@ -124,50 +124,50 @@ func (b *Binance) setupOrderbookManager(ctx context.Context) {
|
||||
|
||||
for range maxWSOrderbookWorkers {
|
||||
// 10 workers for synchronising book
|
||||
b.SynchroniseWebsocketOrderbook(ctx)
|
||||
e.SynchroniseWebsocketOrderbook(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
// KeepAuthKeyAlive will continuously send messages to
|
||||
// keep the WS auth key active
|
||||
func (b *Binance) KeepAuthKeyAlive(ctx context.Context) {
|
||||
b.Websocket.Wg.Add(1)
|
||||
defer b.Websocket.Wg.Done()
|
||||
func (e *Exchange) KeepAuthKeyAlive(ctx context.Context) {
|
||||
e.Websocket.Wg.Add(1)
|
||||
defer e.Websocket.Wg.Done()
|
||||
ticks := time.NewTicker(time.Minute * 30)
|
||||
for {
|
||||
select {
|
||||
case <-b.Websocket.ShutdownC:
|
||||
case <-e.Websocket.ShutdownC:
|
||||
ticks.Stop()
|
||||
return
|
||||
case <-ticks.C:
|
||||
err := b.MaintainWsAuthStreamKey(ctx)
|
||||
err := e.MaintainWsAuthStreamKey(ctx)
|
||||
if err != nil {
|
||||
b.Websocket.DataHandler <- err
|
||||
log.Warnf(log.ExchangeSys, "%s - Unable to renew auth websocket token, may experience shutdown", b.Name)
|
||||
e.Websocket.DataHandler <- err
|
||||
log.Warnf(log.ExchangeSys, "%s - Unable to renew auth websocket token, may experience shutdown", e.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// wsReadData receives and passes on websocket messages for processing
|
||||
func (b *Binance) wsReadData() {
|
||||
defer b.Websocket.Wg.Done()
|
||||
func (e *Exchange) wsReadData() {
|
||||
defer e.Websocket.Wg.Done()
|
||||
|
||||
for {
|
||||
resp := b.Websocket.Conn.ReadMessage()
|
||||
resp := e.Websocket.Conn.ReadMessage()
|
||||
if resp.Raw == nil {
|
||||
return
|
||||
}
|
||||
err := b.wsHandleData(resp.Raw)
|
||||
err := e.wsHandleData(resp.Raw)
|
||||
if err != nil {
|
||||
b.Websocket.DataHandler <- err
|
||||
e.Websocket.DataHandler <- err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Binance) wsHandleData(respRaw []byte) error {
|
||||
func (e *Exchange) wsHandleData(respRaw []byte) error {
|
||||
if id, err := jsonparser.GetInt(respRaw, "id"); err == nil {
|
||||
if b.Websocket.Match.IncomingWithData(id, respRaw) {
|
||||
if e.Websocket.Match.IncomingWithData(id, respRaw) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -179,7 +179,7 @@ func (b *Binance) wsHandleData(respRaw []byte) error {
|
||||
}
|
||||
jsonData, _, _, err := jsonparser.Get(respRaw, "data")
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s %s %s", b.Name, websocket.UnhandledMessage, string(respRaw))
|
||||
return fmt.Errorf("%s %s %s", e.Name, websocket.UnhandledMessage, string(respRaw))
|
||||
}
|
||||
var event string
|
||||
event, err = jsonparser.GetUnsafeString(jsonData, "e")
|
||||
@@ -190,27 +190,27 @@ func (b *Binance) wsHandleData(respRaw []byte) error {
|
||||
err = json.Unmarshal(jsonData, &data)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v - Could not convert to outboundAccountPosition structure %s",
|
||||
b.Name,
|
||||
e.Name,
|
||||
err)
|
||||
}
|
||||
b.Websocket.DataHandler <- data
|
||||
e.Websocket.DataHandler <- data
|
||||
return nil
|
||||
case "balanceUpdate":
|
||||
var data WsBalanceUpdateData
|
||||
err = json.Unmarshal(jsonData, &data)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v - Could not convert to balanceUpdate structure %s",
|
||||
b.Name,
|
||||
e.Name,
|
||||
err)
|
||||
}
|
||||
b.Websocket.DataHandler <- data
|
||||
e.Websocket.DataHandler <- data
|
||||
return nil
|
||||
case "executionReport":
|
||||
var data WsOrderUpdateData
|
||||
err = json.Unmarshal(jsonData, &data)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v - Could not convert to executionReport structure %s",
|
||||
b.Name,
|
||||
e.Name,
|
||||
err)
|
||||
}
|
||||
avgPrice := 0.0
|
||||
@@ -220,7 +220,7 @@ func (b *Binance) wsHandleData(respRaw []byte) error {
|
||||
remainingAmount := data.Quantity - data.CumulativeFilledQuantity
|
||||
var pair currency.Pair
|
||||
var assetType asset.Item
|
||||
pair, assetType, err = b.GetRequestFormattedPairAndAssetType(data.Symbol)
|
||||
pair, assetType, err = e.GetRequestFormattedPairAndAssetType(data.Symbol)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -232,8 +232,8 @@ func (b *Binance) wsHandleData(respRaw []byte) error {
|
||||
var orderStatus order.Status
|
||||
orderStatus, err = stringToOrderStatus(data.OrderStatus)
|
||||
if err != nil {
|
||||
b.Websocket.DataHandler <- order.ClassificationError{
|
||||
Exchange: b.Name,
|
||||
e.Websocket.DataHandler <- order.ClassificationError{
|
||||
Exchange: e.Name,
|
||||
OrderID: orderID,
|
||||
Err: err,
|
||||
}
|
||||
@@ -245,8 +245,8 @@ func (b *Binance) wsHandleData(respRaw []byte) error {
|
||||
var orderType order.Type
|
||||
orderType, err = order.StringToOrderType(data.OrderType)
|
||||
if err != nil {
|
||||
b.Websocket.DataHandler <- order.ClassificationError{
|
||||
Exchange: b.Name,
|
||||
e.Websocket.DataHandler <- order.ClassificationError{
|
||||
Exchange: e.Name,
|
||||
OrderID: orderID,
|
||||
Err: err,
|
||||
}
|
||||
@@ -254,13 +254,13 @@ func (b *Binance) wsHandleData(respRaw []byte) error {
|
||||
var orderSide order.Side
|
||||
orderSide, err = order.StringToOrderSide(data.Side)
|
||||
if err != nil {
|
||||
b.Websocket.DataHandler <- order.ClassificationError{
|
||||
Exchange: b.Name,
|
||||
e.Websocket.DataHandler <- order.ClassificationError{
|
||||
Exchange: e.Name,
|
||||
OrderID: orderID,
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
b.Websocket.DataHandler <- &order.Detail{
|
||||
e.Websocket.DataHandler <- &order.Detail{
|
||||
Price: data.Price,
|
||||
Amount: data.Quantity,
|
||||
AverageExecutedPrice: avgPrice,
|
||||
@@ -270,7 +270,7 @@ func (b *Binance) wsHandleData(respRaw []byte) error {
|
||||
CostAsset: pair.Quote,
|
||||
Fee: data.Commission,
|
||||
FeeAsset: feeAsset,
|
||||
Exchange: b.Name,
|
||||
Exchange: e.Name,
|
||||
OrderID: orderID,
|
||||
ClientOrderID: clientOrderID,
|
||||
Type: orderType,
|
||||
@@ -287,10 +287,10 @@ func (b *Binance) wsHandleData(respRaw []byte) error {
|
||||
err = json.Unmarshal(jsonData, &data)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v - Could not convert to listStatus structure %s",
|
||||
b.Name,
|
||||
e.Name,
|
||||
err)
|
||||
}
|
||||
b.Websocket.DataHandler <- data
|
||||
e.Websocket.DataHandler <- data
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -298,13 +298,13 @@ func (b *Binance) wsHandleData(respRaw []byte) error {
|
||||
streamStr, err := jsonparser.GetUnsafeString(respRaw, "stream")
|
||||
if err != nil {
|
||||
if errors.Is(err, jsonparser.KeyPathNotFoundError) {
|
||||
return fmt.Errorf("%s %s %s", b.Name, websocket.UnhandledMessage, string(respRaw))
|
||||
return fmt.Errorf("%s %s %s", e.Name, websocket.UnhandledMessage, string(respRaw))
|
||||
}
|
||||
return err
|
||||
}
|
||||
streamType := strings.Split(streamStr, "@")
|
||||
if len(streamType) <= 1 {
|
||||
return fmt.Errorf("%s %s %s", b.Name, websocket.UnhandledMessage, string(respRaw))
|
||||
return fmt.Errorf("%s %s %s", e.Name, websocket.UnhandledMessage, string(respRaw))
|
||||
}
|
||||
var (
|
||||
pair currency.Pair
|
||||
@@ -316,7 +316,7 @@ func (b *Binance) wsHandleData(respRaw []byte) error {
|
||||
// there should be a symbol returned for all data types below
|
||||
return err
|
||||
}
|
||||
pair, isEnabled, err = b.MatchSymbolCheckEnabled(symbol, asset.Spot, false)
|
||||
pair, isEnabled, err = e.MatchSymbolCheckEnabled(symbol, asset.Spot, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -325,9 +325,9 @@ func (b *Binance) wsHandleData(respRaw []byte) error {
|
||||
}
|
||||
switch streamType[1] {
|
||||
case "trade":
|
||||
saveTradeData := b.IsSaveTradeDataEnabled()
|
||||
saveTradeData := e.IsSaveTradeDataEnabled()
|
||||
if !saveTradeData &&
|
||||
!b.IsTradeFeedEnabled() {
|
||||
!e.IsTradeFeedEnabled() {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -335,7 +335,7 @@ func (b *Binance) wsHandleData(respRaw []byte) error {
|
||||
err := json.Unmarshal(jsonData, &t)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v - Could not unmarshal trade data: %s",
|
||||
b.Name,
|
||||
e.Name,
|
||||
err)
|
||||
}
|
||||
td := trade.Data{
|
||||
@@ -343,7 +343,7 @@ func (b *Binance) wsHandleData(respRaw []byte) error {
|
||||
Timestamp: t.TimeStamp.Time(),
|
||||
Price: t.Price.Float64(),
|
||||
Amount: t.Quantity.Float64(),
|
||||
Exchange: b.Name,
|
||||
Exchange: e.Name,
|
||||
AssetType: asset.Spot,
|
||||
TID: strconv.FormatInt(t.TradeID, 10),
|
||||
}
|
||||
@@ -353,17 +353,17 @@ func (b *Binance) wsHandleData(respRaw []byte) error {
|
||||
} else { // Buyer is Taker
|
||||
td.Side = order.Buy
|
||||
}
|
||||
return b.Websocket.Trade.Update(saveTradeData, td)
|
||||
return e.Websocket.Trade.Update(saveTradeData, td)
|
||||
case "ticker":
|
||||
var t TickerStream
|
||||
err = json.Unmarshal(jsonData, &t)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v - Could not convert to a TickerStream structure %s",
|
||||
b.Name,
|
||||
e.Name,
|
||||
err.Error())
|
||||
}
|
||||
b.Websocket.DataHandler <- &ticker.Price{
|
||||
ExchangeName: b.Name,
|
||||
e.Websocket.DataHandler <- &ticker.Price{
|
||||
ExchangeName: e.Name,
|
||||
Open: t.OpenPrice.Float64(),
|
||||
Close: t.ClosePrice.Float64(),
|
||||
Volume: t.TotalTradedVolume.Float64(),
|
||||
@@ -384,14 +384,14 @@ func (b *Binance) wsHandleData(respRaw []byte) error {
|
||||
err = json.Unmarshal(jsonData, &kline)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v - Could not convert to a KlineStream structure %s",
|
||||
b.Name,
|
||||
e.Name,
|
||||
err)
|
||||
}
|
||||
b.Websocket.DataHandler <- websocket.KlineData{
|
||||
e.Websocket.DataHandler <- websocket.KlineData{
|
||||
Timestamp: kline.EventTime.Time(),
|
||||
Pair: pair,
|
||||
AssetType: asset.Spot,
|
||||
Exchange: b.Name,
|
||||
Exchange: e.Name,
|
||||
StartTime: kline.Kline.StartTime.Time(),
|
||||
CloseTime: kline.Kline.CloseTime.Time(),
|
||||
Interval: kline.Kline.Interval,
|
||||
@@ -407,22 +407,22 @@ func (b *Binance) wsHandleData(respRaw []byte) error {
|
||||
err = json.Unmarshal(jsonData, &depth)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v - Could not convert to depthStream structure %s",
|
||||
b.Name,
|
||||
e.Name,
|
||||
err)
|
||||
}
|
||||
var init bool
|
||||
init, err = b.UpdateLocalBuffer(&depth)
|
||||
init, err = e.UpdateLocalBuffer(&depth)
|
||||
if err != nil {
|
||||
if init {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("%v - UpdateLocalCache error: %s",
|
||||
b.Name,
|
||||
e.Name,
|
||||
err)
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("%s %s %s", b.Name, websocket.UnhandledMessage, string(respRaw))
|
||||
return fmt.Errorf("%s %s %s", e.Name, websocket.UnhandledMessage, string(respRaw))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -448,8 +448,8 @@ func stringToOrderStatus(status string) (order.Status, error) {
|
||||
}
|
||||
|
||||
// SeedLocalCache seeds depth data
|
||||
func (b *Binance) SeedLocalCache(ctx context.Context, p currency.Pair) error {
|
||||
ob, err := b.GetOrderBook(ctx,
|
||||
func (e *Exchange) SeedLocalCache(ctx context.Context, p currency.Pair) error {
|
||||
ob, err := e.GetOrderBook(ctx,
|
||||
OrderBookDataRequestParams{
|
||||
Symbol: p,
|
||||
Limit: 1000,
|
||||
@@ -457,17 +457,17 @@ func (b *Binance) SeedLocalCache(ctx context.Context, p currency.Pair) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return b.SeedLocalCacheWithBook(p, ob)
|
||||
return e.SeedLocalCacheWithBook(p, ob)
|
||||
}
|
||||
|
||||
// SeedLocalCacheWithBook seeds the local orderbook cache
|
||||
func (b *Binance) SeedLocalCacheWithBook(p currency.Pair, orderbookNew *OrderBook) error {
|
||||
func (e *Exchange) SeedLocalCacheWithBook(p currency.Pair, orderbookNew *OrderBook) error {
|
||||
newOrderBook := orderbook.Book{
|
||||
Pair: p,
|
||||
Asset: asset.Spot,
|
||||
Exchange: b.Name,
|
||||
Exchange: e.Name,
|
||||
LastUpdateID: orderbookNew.LastUpdateID,
|
||||
ValidateOrderbook: b.ValidateOrderbook,
|
||||
ValidateOrderbook: e.ValidateOrderbook,
|
||||
Bids: make(orderbook.Levels, len(orderbookNew.Bids)),
|
||||
Asks: make(orderbook.Levels, len(orderbookNew.Asks)),
|
||||
LastUpdated: time.Now(), // Time not provided in REST book.
|
||||
@@ -484,46 +484,46 @@ func (b *Binance) SeedLocalCacheWithBook(p currency.Pair, orderbookNew *OrderBoo
|
||||
Price: orderbookNew.Asks[i].Price,
|
||||
}
|
||||
}
|
||||
return b.Websocket.Orderbook.LoadSnapshot(&newOrderBook)
|
||||
return e.Websocket.Orderbook.LoadSnapshot(&newOrderBook)
|
||||
}
|
||||
|
||||
// UpdateLocalBuffer updates and returns the most recent iteration of the orderbook
|
||||
func (b *Binance) UpdateLocalBuffer(wsdp *WebsocketDepthStream) (bool, error) {
|
||||
pair, err := b.MatchSymbolWithAvailablePairs(wsdp.Pair, asset.Spot, false)
|
||||
func (e *Exchange) UpdateLocalBuffer(wsdp *WebsocketDepthStream) (bool, error) {
|
||||
pair, err := e.MatchSymbolWithAvailablePairs(wsdp.Pair, asset.Spot, false)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
err = b.obm.stageWsUpdate(wsdp, pair, asset.Spot)
|
||||
err = e.obm.stageWsUpdate(wsdp, pair, asset.Spot)
|
||||
if err != nil {
|
||||
init, err2 := b.obm.checkIsInitialSync(pair)
|
||||
init, err2 := e.obm.checkIsInitialSync(pair)
|
||||
if err2 != nil {
|
||||
return false, err2
|
||||
}
|
||||
return init, err
|
||||
}
|
||||
|
||||
err = b.applyBufferUpdate(pair)
|
||||
err = e.applyBufferUpdate(pair)
|
||||
if err != nil {
|
||||
b.invalidateAndCleanupOrderbook(pair)
|
||||
e.invalidateAndCleanupOrderbook(pair)
|
||||
}
|
||||
|
||||
return false, err
|
||||
}
|
||||
|
||||
func (b *Binance) generateSubscriptions() (subscription.List, error) {
|
||||
for _, s := range b.Features.Subscriptions {
|
||||
func (e *Exchange) generateSubscriptions() (subscription.List, error) {
|
||||
for _, s := range e.Features.Subscriptions {
|
||||
if s.Asset == asset.Empty {
|
||||
// Handle backwards compatibility with config without assets, all binance subs are spot
|
||||
s.Asset = asset.Spot
|
||||
}
|
||||
}
|
||||
return b.Features.Subscriptions.ExpandTemplates(b)
|
||||
return e.Features.Subscriptions.ExpandTemplates(e)
|
||||
}
|
||||
|
||||
var subTemplate *template.Template
|
||||
|
||||
// GetSubscriptionTemplate returns a subscription channel template
|
||||
func (b *Binance) GetSubscriptionTemplate(_ *subscription.Subscription) (*template.Template, error) {
|
||||
func (e *Exchange) GetSubscriptionTemplate(_ *subscription.Subscription) (*template.Template, error) {
|
||||
var err error
|
||||
if subTemplate == nil {
|
||||
subTemplate, err = template.New("subscriptions.tmpl").
|
||||
@@ -558,21 +558,21 @@ func formatChannelInterval(s *subscription.Subscription) string {
|
||||
}
|
||||
|
||||
// Subscribe subscribes to a set of channels
|
||||
func (b *Binance) Subscribe(channels subscription.List) error {
|
||||
func (e *Exchange) Subscribe(channels subscription.List) error {
|
||||
ctx := context.TODO()
|
||||
return b.ParallelChanOp(ctx, channels, func(ctx context.Context, l subscription.List) error { return b.manageSubs(ctx, wsSubscribeMethod, l) }, 50)
|
||||
return e.ParallelChanOp(ctx, channels, func(ctx context.Context, l subscription.List) error { return e.manageSubs(ctx, wsSubscribeMethod, l) }, 50)
|
||||
}
|
||||
|
||||
// Unsubscribe unsubscribes from a set of channels
|
||||
func (b *Binance) Unsubscribe(channels subscription.List) error {
|
||||
func (e *Exchange) Unsubscribe(channels subscription.List) error {
|
||||
ctx := context.TODO()
|
||||
return b.ParallelChanOp(ctx, channels, func(ctx context.Context, l subscription.List) error { return b.manageSubs(ctx, wsUnsubscribeMethod, l) }, 50)
|
||||
return e.ParallelChanOp(ctx, channels, func(ctx context.Context, l subscription.List) error { return e.manageSubs(ctx, wsUnsubscribeMethod, l) }, 50)
|
||||
}
|
||||
|
||||
// manageSubs subscribes or unsubscribes from a list of subscriptions
|
||||
func (b *Binance) manageSubs(ctx context.Context, op string, subs subscription.List) error {
|
||||
func (e *Exchange) manageSubs(ctx context.Context, op string, subs subscription.List) error {
|
||||
if op == wsSubscribeMethod {
|
||||
if err := b.Websocket.AddSubscriptions(b.Websocket.Conn, subs...); err != nil { // Note: AddSubscription will set state to subscribing
|
||||
if err := e.Websocket.AddSubscriptions(e.Websocket.Conn, subs...); err != nil { // Note: AddSubscription will set state to subscribing
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
@@ -582,12 +582,12 @@ func (b *Binance) manageSubs(ctx context.Context, op string, subs subscription.L
|
||||
}
|
||||
|
||||
req := WsPayload{
|
||||
ID: b.Websocket.Conn.GenerateMessageID(false),
|
||||
ID: e.Websocket.Conn.GenerateMessageID(false),
|
||||
Method: op,
|
||||
Params: subs.QualifiedChannels(),
|
||||
}
|
||||
|
||||
respRaw, err := b.Websocket.Conn.SendMessageReturnResponse(ctx, request.Unset, req.ID, req)
|
||||
respRaw, err := e.Websocket.Conn.SendMessageReturnResponse(ctx, request.Unset, req.ID, req)
|
||||
if err == nil {
|
||||
if v, d, _, rErr := jsonparser.Get(respRaw, "result"); rErr != nil {
|
||||
err = rErr
|
||||
@@ -598,10 +598,10 @@ func (b *Binance) manageSubs(ctx context.Context, op string, subs subscription.L
|
||||
|
||||
if err != nil {
|
||||
err = fmt.Errorf("%w; Channels: %s", err, strings.Join(subs.QualifiedChannels(), ", "))
|
||||
b.Websocket.DataHandler <- err
|
||||
e.Websocket.DataHandler <- err
|
||||
|
||||
if op == wsSubscribeMethod {
|
||||
if err2 := b.Websocket.RemoveSubscriptions(b.Websocket.Conn, subs...); err2 != nil {
|
||||
if err2 := e.Websocket.RemoveSubscriptions(e.Websocket.Conn, subs...); err2 != nil {
|
||||
err = common.AppendError(err, err2)
|
||||
}
|
||||
}
|
||||
@@ -609,7 +609,7 @@ func (b *Binance) manageSubs(ctx context.Context, op string, subs subscription.L
|
||||
if op == wsSubscribeMethod {
|
||||
err = common.AppendError(err, subs.SetStates(subscription.SubscribedState))
|
||||
} else {
|
||||
err = b.Websocket.RemoveSubscriptions(b.Websocket.Conn, subs...)
|
||||
err = e.Websocket.RemoveSubscriptions(e.Websocket.Conn, subs...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -617,7 +617,7 @@ func (b *Binance) manageSubs(ctx context.Context, op string, subs subscription.L
|
||||
}
|
||||
|
||||
// ProcessOrderbookUpdate processes the websocket orderbook update
|
||||
func (b *Binance) ProcessOrderbookUpdate(cp currency.Pair, a asset.Item, ws *WebsocketDepthStream) error {
|
||||
func (e *Exchange) ProcessOrderbookUpdate(cp currency.Pair, a asset.Item, ws *WebsocketDepthStream) error {
|
||||
updateBid := make([]orderbook.Level, len(ws.UpdateBids))
|
||||
for i := range ws.UpdateBids {
|
||||
updateBid[i] = orderbook.Level{
|
||||
@@ -632,7 +632,7 @@ func (b *Binance) ProcessOrderbookUpdate(cp currency.Pair, a asset.Item, ws *Web
|
||||
Amount: ws.UpdateAsks[i][1].Float64(),
|
||||
}
|
||||
}
|
||||
return b.Websocket.Orderbook.Update(&orderbook.Update{
|
||||
return e.Websocket.Orderbook.Update(&orderbook.Update{
|
||||
Bids: updateBid,
|
||||
Asks: updateAsk,
|
||||
Pair: cp,
|
||||
@@ -644,8 +644,8 @@ func (b *Binance) ProcessOrderbookUpdate(cp currency.Pair, a asset.Item, ws *Web
|
||||
|
||||
// applyBufferUpdate applies the buffer to the orderbook or initiates a new
|
||||
// orderbook sync by the REST protocol which is off handed to go routine.
|
||||
func (b *Binance) applyBufferUpdate(pair currency.Pair) error {
|
||||
fetching, needsFetching, err := b.obm.handleFetchingBook(pair)
|
||||
func (e *Exchange) applyBufferUpdate(pair currency.Pair) error {
|
||||
fetching, needsFetching, err := e.obm.handleFetchingBook(pair)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -653,30 +653,30 @@ func (b *Binance) applyBufferUpdate(pair currency.Pair) error {
|
||||
return nil
|
||||
}
|
||||
if needsFetching {
|
||||
if b.Verbose {
|
||||
log.Debugf(log.WebsocketMgr, "%s Orderbook: Fetching via REST\n", b.Name)
|
||||
if e.Verbose {
|
||||
log.Debugf(log.WebsocketMgr, "%s Orderbook: Fetching via REST\n", e.Name)
|
||||
}
|
||||
return b.obm.fetchBookViaREST(pair)
|
||||
return e.obm.fetchBookViaREST(pair)
|
||||
}
|
||||
|
||||
recent, err := b.Websocket.Orderbook.GetOrderbook(pair, asset.Spot)
|
||||
recent, err := e.Websocket.Orderbook.GetOrderbook(pair, asset.Spot)
|
||||
if err != nil {
|
||||
log.Errorf(
|
||||
log.WebsocketMgr,
|
||||
"%s error fetching recent orderbook when applying updates: %s\n",
|
||||
b.Name,
|
||||
e.Name,
|
||||
err)
|
||||
}
|
||||
|
||||
if recent != nil {
|
||||
err = b.obm.checkAndProcessOrderbookUpdate(b.ProcessOrderbookUpdate, pair, recent)
|
||||
err = e.obm.checkAndProcessOrderbookUpdate(e.ProcessOrderbookUpdate, pair, recent)
|
||||
if err != nil {
|
||||
log.Errorf(
|
||||
log.WebsocketMgr,
|
||||
"%s error processing update - initiating new orderbook sync via REST: %s\n",
|
||||
b.Name,
|
||||
e.Name,
|
||||
err)
|
||||
err = b.obm.setNeedsFetchingBook(pair)
|
||||
err = e.obm.setNeedsFetchingBook(pair)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -702,26 +702,26 @@ func (o *orderbookManager) setNeedsFetchingBook(pair currency.Pair) error {
|
||||
|
||||
// SynchroniseWebsocketOrderbook synchronises full orderbook for currency pair
|
||||
// asset
|
||||
func (b *Binance) SynchroniseWebsocketOrderbook(ctx context.Context) {
|
||||
b.Websocket.Wg.Add(1)
|
||||
func (e *Exchange) SynchroniseWebsocketOrderbook(ctx context.Context) {
|
||||
e.Websocket.Wg.Add(1)
|
||||
go func() {
|
||||
defer b.Websocket.Wg.Done()
|
||||
defer e.Websocket.Wg.Done()
|
||||
for {
|
||||
select {
|
||||
case <-b.Websocket.ShutdownC:
|
||||
case <-e.Websocket.ShutdownC:
|
||||
for {
|
||||
select {
|
||||
case <-b.obm.jobs:
|
||||
case <-e.obm.jobs:
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
case j := <-b.obm.jobs:
|
||||
err := b.processJob(ctx, j.Pair)
|
||||
case j := <-e.obm.jobs:
|
||||
err := e.processJob(ctx, j.Pair)
|
||||
if err != nil {
|
||||
log.Errorf(log.WebsocketMgr,
|
||||
"%s processing websocket orderbook error %v",
|
||||
b.Name, err)
|
||||
e.Name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -729,35 +729,35 @@ func (b *Binance) SynchroniseWebsocketOrderbook(ctx context.Context) {
|
||||
}
|
||||
|
||||
// processJob fetches and processes orderbook updates
|
||||
func (b *Binance) processJob(ctx context.Context, p currency.Pair) error {
|
||||
err := b.SeedLocalCache(ctx, p)
|
||||
func (e *Exchange) processJob(ctx context.Context, p currency.Pair) error {
|
||||
err := e.SeedLocalCache(ctx, p)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s %s seeding local cache for orderbook error: %v",
|
||||
p, asset.Spot, err)
|
||||
}
|
||||
|
||||
err = b.obm.stopFetchingBook(p)
|
||||
err = e.obm.stopFetchingBook(p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Immediately apply the buffer updates so we don't wait for a
|
||||
// new update to initiate this.
|
||||
err = b.applyBufferUpdate(p)
|
||||
err = e.applyBufferUpdate(p)
|
||||
if err != nil {
|
||||
b.invalidateAndCleanupOrderbook(p)
|
||||
e.invalidateAndCleanupOrderbook(p)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// invalidateAndCleanupOrderbook invalidaates orderbook and cleans local cache
|
||||
func (b *Binance) invalidateAndCleanupOrderbook(p currency.Pair) {
|
||||
if err := b.Websocket.Orderbook.InvalidateOrderbook(p, asset.Spot); err != nil {
|
||||
log.Errorf(log.WebsocketMgr, "%s error invalidating websocket orderbook: %v", b.Name, err)
|
||||
func (e *Exchange) invalidateAndCleanupOrderbook(p currency.Pair) {
|
||||
if err := e.Websocket.Orderbook.InvalidateOrderbook(p, asset.Spot); err != nil {
|
||||
log.Errorf(log.WebsocketMgr, "%s error invalidating websocket orderbook: %v", e.Name, err)
|
||||
}
|
||||
if err := b.obm.cleanup(p); err != nil {
|
||||
log.Errorf(log.WebsocketMgr, "%s error during websocket orderbook cleanup: %v", b.Name, err)
|
||||
if err := e.obm.cleanup(p); err != nil {
|
||||
log.Errorf(log.WebsocketMgr, "%s error during websocket orderbook cleanup: %v", e.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user