exchanges: Initial context propagation (#744)

* gct: phase one context awareness pass

* exchanges: context propagation pass

* common/requester: force context requirement

* gctcli/exchanges: linter fix

* rpcserver: fix test using dummy rpc server

* backtester: fix comments

* grpc: add correct cancel and timeout for commands

* rpcserver_test: add comment on dummy server

* common: deprecated SendHTTPGetRequest

* linter: fix

* linter: turn on no context check

* apichecker: fix context linter issue

* binance: use param context

* common: remove checks as this gets executed before main

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

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

* common: Add comments

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

View File

@@ -1,6 +1,7 @@
package okex
import (
"context"
"encoding/json"
"errors"
"fmt"
@@ -61,28 +62,28 @@ type OKEX struct {
}
// GetSwapMarkets gets perpetual swap markets
func (o *OKEX) GetSwapMarkets() ([]okgroup.SwapInstrumentsData, error) {
func (o *OKEX) GetSwapMarkets(ctx context.Context) ([]okgroup.SwapInstrumentsData, error) {
var resp []okgroup.SwapInstrumentsData
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection,
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupSwapSubsection,
okGroupSwapInstruments,
nil, &resp, false)
}
// GetSwapInstruments gets perpetual swap instruments data
func (o *OKEX) GetSwapInstruments() ([]okgroup.PerpSwapInstrumentData, error) {
func (o *OKEX) GetSwapInstruments(ctx context.Context) ([]okgroup.PerpSwapInstrumentData, error) {
var resp []okgroup.PerpSwapInstrumentData
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection,
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupSwapSubsection,
okGroupInstruments,
nil, &resp, false)
}
// GetAllMarginRates gets interest rates for all margin currencies on OKEX
func (o *OKEX) GetAllMarginRates() ([]okgroup.MarginCurrencyData, error) {
func (o *OKEX) GetAllMarginRates(ctx context.Context) ([]okgroup.MarginCurrencyData, error) {
var resp []okgroup.MarginCurrencyData
var result []map[string]interface{}
var tempResp okgroup.MarginCurrencyData
tempResp.Data = make(map[string]okgroup.MarginData)
err := o.SendHTTPRequest(exchange.RestSpot, http.MethodGet,
err := o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet,
okGroupMarginSubsection,
okGroupMarginPairsData,
nil,
@@ -126,11 +127,11 @@ func (o *OKEX) GetAllMarginRates() ([]okgroup.MarginCurrencyData, error) {
}
// GetMarginRates gets interest rates for margin currencies
func (o *OKEX) GetMarginRates(instrumentID currency.Pair) (okgroup.MarginCurrencyData, error) {
func (o *OKEX) GetMarginRates(ctx context.Context, instrumentID currency.Pair) (okgroup.MarginCurrencyData, error) {
var resp okgroup.MarginCurrencyData
resp.Data = make(map[string]okgroup.MarginData)
var result []map[string]interface{}
err := o.SendHTTPRequest(exchange.RestSpot, http.MethodGet,
err := o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet,
okGroupMarginSubsection,
fmt.Sprintf(okGroupMarginPairData, instrumentID),
nil,
@@ -178,410 +179,410 @@ func (o *OKEX) GetMarginRates(instrumentID currency.Pair) (okgroup.MarginCurrenc
}
// GetSpotMarkets gets perpetual swap markets' data
func (o *OKEX) GetSpotMarkets() ([]okgroup.TradingPairData, error) {
func (o *OKEX) GetSpotMarkets(ctx context.Context) ([]okgroup.TradingPairData, error) {
var resp []okgroup.TradingPairData
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSpotSubsection, okGroupInstruments, nil, &resp, false)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupSpotSubsection, okGroupInstruments, nil, &resp, false)
}
// GetFundingRate gets funding rate of a given currency
func (o *OKEX) GetFundingRate(marketName, limit string) ([]okgroup.PerpSwapFundingRates, error) {
func (o *OKEX) GetFundingRate(ctx context.Context, marketName, limit string) ([]okgroup.PerpSwapFundingRates, error) {
params := url.Values{}
params.Set("limit", limit)
var resp []okgroup.PerpSwapFundingRates
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection,
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupSwapSubsection,
fmt.Sprintf(okGroupPerpSwapRates, marketName)+params.Encode(),
nil, &resp, false)
}
// GetPerpSwapMarkets gets perpetual swap markets' data
func (o *OKEX) GetPerpSwapMarkets() ([]okgroup.TickerData, error) {
func (o *OKEX) GetPerpSwapMarkets(ctx context.Context) ([]okgroup.TickerData, error) {
var resp []okgroup.TickerData
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection,
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupSwapSubsection,
okGroupPerpTickers,
nil, &resp, false)
}
// GetFuturesPostions Get the information of all holding positions in futures trading.
// Due to high energy consumption, you are advised to capture data with the "Futures Account of a Currency" API instead.
func (o *OKEX) GetFuturesPostions() (resp okgroup.GetFuturesPositionsResponse, _ error) {
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, okGroupFuturePosition, nil, &resp, true)
func (o *OKEX) GetFuturesPostions(ctx context.Context) (resp okgroup.GetFuturesPositionsResponse, _ error) {
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, okGroupFuturePosition, nil, &resp, true)
}
// GetFuturesPostionsForCurrency Get the information of holding positions of a contract.
func (o *OKEX) GetFuturesPostionsForCurrency(instrumentID string) (resp okgroup.GetFuturesPositionsForCurrencyResponse, _ error) {
func (o *OKEX) GetFuturesPostionsForCurrency(ctx context.Context, instrumentID string) (resp okgroup.GetFuturesPositionsForCurrencyResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v", instrumentID, okGroupFuturePosition)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, true)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, true)
}
// GetFuturesAccountOfAllCurrencies Get the futures account info of all token.
// Due to high energy consumption, you are advised to capture data with the "Futures Account of a Currency" API instead.
func (o *OKEX) GetFuturesAccountOfAllCurrencies() (resp okgroup.FuturesAccountForAllCurrenciesResponse, _ error) {
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, okgroup.OKGroupAccounts, nil, &resp, true)
func (o *OKEX) GetFuturesAccountOfAllCurrencies(ctx context.Context) (resp okgroup.FuturesAccountForAllCurrenciesResponse, _ error) {
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, okgroup.OKGroupAccounts, nil, &resp, true)
}
// GetFuturesAccountOfACurrency Get the futures account info of a token.
func (o *OKEX) GetFuturesAccountOfACurrency(instrumentID string) (resp okgroup.FuturesCurrencyData, _ error) {
func (o *OKEX) GetFuturesAccountOfACurrency(ctx context.Context, instrumentID string) (resp okgroup.FuturesCurrencyData, _ error) {
requestURL := fmt.Sprintf("%v/%v", okgroup.OKGroupAccounts, instrumentID)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, true)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, true)
}
// GetFuturesLeverage Get the leverage of the futures account
func (o *OKEX) GetFuturesLeverage(instrumentID string) (resp okgroup.GetFuturesLeverageResponse, _ error) {
func (o *OKEX) GetFuturesLeverage(ctx context.Context, instrumentID string) (resp okgroup.GetFuturesLeverageResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupAccounts, instrumentID, okGroupFutureLeverage)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, true)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, true)
}
// SetFuturesLeverage Adjusting the leverage for futures account。
// Cross margin request requirements: {"leverage":"10"}
// Fixed margin request requirements: {"instrument_id":"BTC-USD-180213","direction":"long","leverage":"10"}
func (o *OKEX) SetFuturesLeverage(request okgroup.SetFuturesLeverageRequest) (resp okgroup.SetFuturesLeverageResponse, _ error) {
func (o *OKEX) SetFuturesLeverage(ctx context.Context, request okgroup.SetFuturesLeverageRequest) (resp okgroup.SetFuturesLeverageResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupAccounts, request.Currency, okGroupFutureLeverage)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodPost, okGroupFuturesSubsection, requestURL, request, &resp, true)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, okGroupFuturesSubsection, requestURL, request, &resp, true)
}
// GetFuturesBillDetails Shows the accounts historical coin in flow and out flow.
// All paginated requests return the latest information (newest) as the first page sorted by newest (in chronological time) first.
func (o *OKEX) GetFuturesBillDetails(request okgroup.GetSpotBillDetailsForCurrencyRequest) (resp []okgroup.GetSpotBillDetailsForCurrencyResponse, _ error) {
func (o *OKEX) GetFuturesBillDetails(ctx context.Context, request okgroup.GetSpotBillDetailsForCurrencyRequest) (resp []okgroup.GetSpotBillDetailsForCurrencyResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v%v", okgroup.OKGroupAccounts, request.Currency, okgroup.OKGroupLedger, okgroup.FormatParameters(request))
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, true)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, true)
}
// PlaceFuturesOrder OKEx futures trading only supports limit orders.
// You can place an order only if you have enough funds. Once your order is placed, the amount will be put on hold in the order lifecycle.
// The assets and amount on hold depends on the order's specific type and parameters.
func (o *OKEX) PlaceFuturesOrder(request okgroup.PlaceFuturesOrderRequest) (resp okgroup.PlaceFuturesOrderResponse, _ error) {
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodPost, okGroupFuturesSubsection, okGroupFutureOrder, request, &resp, true)
func (o *OKEX) PlaceFuturesOrder(ctx context.Context, request okgroup.PlaceFuturesOrderRequest) (resp okgroup.PlaceFuturesOrderResponse, _ error) {
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, okGroupFuturesSubsection, okGroupFutureOrder, request, &resp, true)
}
// PlaceFuturesOrderBatch Batch contract placing order operation.
func (o *OKEX) PlaceFuturesOrderBatch(request okgroup.PlaceFuturesOrderBatchRequest) (resp okgroup.PlaceFuturesOrderBatchResponse, _ error) {
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodPost, okGroupFuturesSubsection, okgroup.OKGroupOrders, request, &resp, true)
func (o *OKEX) PlaceFuturesOrderBatch(ctx context.Context, request okgroup.PlaceFuturesOrderBatchRequest) (resp okgroup.PlaceFuturesOrderBatchResponse, _ error) {
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, okGroupFuturesSubsection, okgroup.OKGroupOrders, request, &resp, true)
}
// CancelFuturesOrder Cancelling an unfilled order.
func (o *OKEX) CancelFuturesOrder(request okgroup.CancelFuturesOrderRequest) (resp okgroup.CancelFuturesOrderResponse, _ error) {
func (o *OKEX) CancelFuturesOrder(ctx context.Context, request okgroup.CancelFuturesOrderRequest) (resp okgroup.CancelFuturesOrderResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupCancelOrder, request.InstrumentID, request.OrderID)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodPost, okGroupFuturesSubsection, requestURL, request, &resp, true)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, okGroupFuturesSubsection, requestURL, request, &resp, true)
}
// CancelFuturesOrderBatch With best effort, cancel all open orders.
func (o *OKEX) CancelFuturesOrderBatch(request okgroup.CancelMultipleSpotOrdersRequest) (resp okgroup.CancelMultipleSpotOrdersResponse, _ error) {
func (o *OKEX) CancelFuturesOrderBatch(ctx context.Context, request okgroup.CancelMultipleSpotOrdersRequest) (resp okgroup.CancelMultipleSpotOrdersResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v", okgroup.OKGroupCancelBatchOrders, request.InstrumentID)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodPost, okGroupFuturesSubsection, requestURL, request, &resp, true)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, okGroupFuturesSubsection, requestURL, request, &resp, true)
}
// GetFuturesOrderList List your orders. Cursor pagination is used.
// All paginated requests return the latest information (newest) as the first page sorted by newest (in chronological time) first.
func (o *OKEX) GetFuturesOrderList(request okgroup.GetFuturesOrdersListRequest) (resp okgroup.GetFuturesOrderListResponse, _ error) {
func (o *OKEX) GetFuturesOrderList(ctx context.Context, request okgroup.GetFuturesOrdersListRequest) (resp okgroup.GetFuturesOrderListResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v%v", okgroup.OKGroupOrders, request.InstrumentID, okgroup.FormatParameters(request))
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, true)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, true)
}
// GetFuturesOrderDetails Get order details by order ID.
func (o *OKEX) GetFuturesOrderDetails(request okgroup.GetFuturesOrderDetailsRequest) (resp okgroup.GetFuturesOrderDetailsResponseData, _ error) {
func (o *OKEX) GetFuturesOrderDetails(ctx context.Context, request okgroup.GetFuturesOrderDetailsRequest) (resp okgroup.GetFuturesOrderDetailsResponseData, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupOrders, request.InstrumentID, request.OrderID)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, true)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, true)
}
// GetFuturesTransactionDetails Get details of the recent filled orders. Cursor pagination is used.
// All paginated requests return the latest information (newest) as the first page sorted by newest (in chronological time) first.
func (o *OKEX) GetFuturesTransactionDetails(request okgroup.GetFuturesTransactionDetailsRequest) (resp []okgroup.GetFuturesTransactionDetailsResponse, _ error) {
func (o *OKEX) GetFuturesTransactionDetails(ctx context.Context, request okgroup.GetFuturesTransactionDetailsRequest) (resp []okgroup.GetFuturesTransactionDetailsResponse, _ error) {
requestURL := fmt.Sprintf("%v%v", okgroup.OKGroupGetSpotTransactionDetails, okgroup.FormatParameters(request))
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, true)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, true)
}
// GetFuturesContractInformation Get market data. This endpoint provides the snapshots of market data and can be used without verifications.
func (o *OKEX) GetFuturesContractInformation() (resp []okgroup.GetFuturesContractInformationResponse, _ error) {
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, okgroup.OKGroupInstruments, nil, &resp, false)
func (o *OKEX) GetFuturesContractInformation(ctx context.Context) (resp []okgroup.GetFuturesContractInformationResponse, _ error) {
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, okgroup.OKGroupInstruments, nil, &resp, false)
}
// GetAllFuturesTokenInfo Get the last traded price, best bid/ask price, 24 hour trading volume and more info of all contracts.
func (o *OKEX) GetAllFuturesTokenInfo() (resp []okgroup.GetFuturesTokenInfoResponse, _ error) {
func (o *OKEX) GetAllFuturesTokenInfo(ctx context.Context) (resp []okgroup.GetFuturesTokenInfoResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v", okgroup.OKGroupInstruments, okgroup.OKGroupTicker)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
}
// GetFuturesTokenInfoForCurrency Get the last traded price, best bid/ask price, 24 hour trading volume and more info of a contract.
func (o *OKEX) GetFuturesTokenInfoForCurrency(instrumentID string) (resp okgroup.GetFuturesTokenInfoResponse, _ error) {
func (o *OKEX) GetFuturesTokenInfoForCurrency(ctx context.Context, instrumentID string) (resp okgroup.GetFuturesTokenInfoResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupInstruments, instrumentID, okgroup.OKGroupTicker)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
}
// GetFuturesFilledOrder Get the recent 300 transactions of all contracts. Pagination is not supported here.
// The whole book will be returned for one request. Websocket is recommended here.
func (o *OKEX) GetFuturesFilledOrder(request okgroup.GetFuturesFilledOrderRequest) (resp []okgroup.GetFuturesFilledOrdersResponse, _ error) {
func (o *OKEX) GetFuturesFilledOrder(ctx context.Context, request okgroup.GetFuturesFilledOrderRequest) (resp []okgroup.GetFuturesFilledOrdersResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v%v", okgroup.OKGroupInstruments, request.InstrumentID, okgroup.OKGroupTrades, okgroup.FormatParameters(request))
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
}
// GetFuturesHoldAmount Get the number of futures with hold.
func (o *OKEX) GetFuturesHoldAmount(instrumentID string) (resp okgroup.GetFuturesHoldAmountResponse, _ error) {
func (o *OKEX) GetFuturesHoldAmount(ctx context.Context, instrumentID string) (resp okgroup.GetFuturesHoldAmountResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupAccounts, instrumentID, okGroupFutureHolds)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, true)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, true)
}
// GetFuturesIndices Get Indices of tokens. This is a public endpoint, no identity verification is needed.
func (o *OKEX) GetFuturesIndices(instrumentID string) (resp okgroup.GetFuturesIndicesResponse, _ error) {
func (o *OKEX) GetFuturesIndices(ctx context.Context, instrumentID string) (resp okgroup.GetFuturesIndicesResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupInstruments, instrumentID, okGroupIndices)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
}
// GetFuturesExchangeRates Get the fiat exchange rates. This is a public endpoint, no identity verification is needed.
func (o *OKEX) GetFuturesExchangeRates() (resp okgroup.GetFuturesExchangeRatesResponse, _ error) {
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, okGroupRate, nil, &resp, false)
func (o *OKEX) GetFuturesExchangeRates(ctx context.Context) (resp okgroup.GetFuturesExchangeRatesResponse, _ error) {
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, okGroupRate, nil, &resp, false)
}
// GetFuturesEstimatedDeliveryPrice the estimated delivery price. It is available 3 hours before delivery.
// This is a public endpoint, no identity verification is needed.
func (o *OKEX) GetFuturesEstimatedDeliveryPrice(instrumentID string) (resp okgroup.GetFuturesEstimatedDeliveryPriceResponse, _ error) {
func (o *OKEX) GetFuturesEstimatedDeliveryPrice(ctx context.Context, instrumentID string) (resp okgroup.GetFuturesEstimatedDeliveryPriceResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupInstruments, instrumentID, okGroupEsimtatedPrice)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
}
// GetFuturesOpenInterests Get the open interest of a contract. This is a public endpoint, no identity verification is needed.
func (o *OKEX) GetFuturesOpenInterests(instrumentID string) (resp okgroup.GetFuturesOpenInterestsResponse, _ error) {
func (o *OKEX) GetFuturesOpenInterests(ctx context.Context, instrumentID string) (resp okgroup.GetFuturesOpenInterestsResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupInstruments, instrumentID, okGroupOpenInterest)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
}
// GetFuturesCurrentPriceLimit The maximum buying price and the minimum selling price of the contract.
// This is a public endpoint, no identity verification is needed.
func (o *OKEX) GetFuturesCurrentPriceLimit(instrumentID string) (resp okgroup.GetFuturesCurrentPriceLimitResponse, _ error) {
func (o *OKEX) GetFuturesCurrentPriceLimit(ctx context.Context, instrumentID string) (resp okgroup.GetFuturesCurrentPriceLimitResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupInstruments, instrumentID, okgroup.OKGroupPriceLimit)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
}
// GetFuturesCurrentMarkPrice The maximum buying price and the minimum selling price of the contract.
// This is a public endpoint, no identity verification is needed.
func (o *OKEX) GetFuturesCurrentMarkPrice(instrumentID string) (resp okgroup.GetFuturesCurrentMarkPriceResponse, _ error) {
func (o *OKEX) GetFuturesCurrentMarkPrice(ctx context.Context, instrumentID string) (resp okgroup.GetFuturesCurrentMarkPriceResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupInstruments, instrumentID, okgroup.OKGroupMarkPrice)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
}
// GetFuturesForceLiquidatedOrders Get force liquidated orders. This is a public endpoint, no identity verification is needed.
func (o *OKEX) GetFuturesForceLiquidatedOrders(request okgroup.GetFuturesForceLiquidatedOrdersRequest) (resp []okgroup.GetFuturesForceLiquidatedOrdersResponse, _ error) {
func (o *OKEX) GetFuturesForceLiquidatedOrders(ctx context.Context, request okgroup.GetFuturesForceLiquidatedOrdersRequest) (resp []okgroup.GetFuturesForceLiquidatedOrdersResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v%v", okgroup.OKGroupInstruments, request.InstrumentID, okgroup.OKGroupLiquidation, okgroup.FormatParameters(request))
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
}
// GetFuturesTagPrice Get the tag price. This is a public endpoint, no identity verification is needed.
func (o *OKEX) GetFuturesTagPrice(instrumentID string) (resp okgroup.GetFuturesTagPriceResponse, _ error) {
func (o *OKEX) GetFuturesTagPrice(ctx context.Context, instrumentID string) (resp okgroup.GetFuturesTagPriceResponse, _ error) {
// OKEX documentation is missing for this endpoint. Guessing "tag_price" for the URL results in 404
return okgroup.GetFuturesTagPriceResponse{}, common.ErrNotYetImplemented
}
// GetSwapPostions Get the information of all holding positions in swap trading.
// Due to high energy consumption, you are advised to capture data with the "Swap Account of a Currency" API instead.
func (o *OKEX) GetSwapPostions() (resp []okgroup.GetSwapPostionsResponse, _ error) {
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, okGroupFuturePosition, nil, &resp, true)
func (o *OKEX) GetSwapPostions(ctx context.Context) (resp []okgroup.GetSwapPostionsResponse, _ error) {
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, okGroupFuturePosition, nil, &resp, true)
}
// GetSwapPostionsForContract Get the information of holding positions of a contract.
func (o *OKEX) GetSwapPostionsForContract(instrumentID string) (resp okgroup.GetSwapPostionsResponse, _ error) {
func (o *OKEX) GetSwapPostionsForContract(ctx context.Context, instrumentID string) (resp okgroup.GetSwapPostionsResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v", instrumentID, okGroupFuturePosition)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, true)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, true)
}
// GetSwapAccountOfAllCurrency Get the perpetual swap account info of a token.
// Margin ratio set as 10,000 when users have no open position.
func (o *OKEX) GetSwapAccountOfAllCurrency() (resp okgroup.GetSwapAccountOfAllCurrencyResponse, _ error) {
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, okgroup.OKGroupAccounts, nil, &resp, true)
func (o *OKEX) GetSwapAccountOfAllCurrency(ctx context.Context) (resp okgroup.GetSwapAccountOfAllCurrencyResponse, _ error) {
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, okgroup.OKGroupAccounts, nil, &resp, true)
}
// GetSwapAccountSettingsOfAContract Get leverage level and margin mode of a contract.
func (o *OKEX) GetSwapAccountSettingsOfAContract(instrumentID string) (resp okgroup.GetSwapAccountSettingsOfAContractResponse, _ error) {
func (o *OKEX) GetSwapAccountSettingsOfAContract(ctx context.Context, instrumentID string) (resp okgroup.GetSwapAccountSettingsOfAContractResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupAccounts, instrumentID, okGroupSettings)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, true)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, true)
}
// SetSwapLeverageLevelOfAContract Setting the leverage level of a contract
// TODO this returns invalid parameters, but matches spec. Unsure how to fix
func (o *OKEX) SetSwapLeverageLevelOfAContract(request okgroup.SetSwapLeverageLevelOfAContractRequest) (resp okgroup.SetSwapLeverageLevelOfAContractResponse, _ error) {
func (o *OKEX) SetSwapLeverageLevelOfAContract(ctx context.Context, request okgroup.SetSwapLeverageLevelOfAContractRequest) (resp okgroup.SetSwapLeverageLevelOfAContractResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupAccounts, request.InstrumentID, okGroupFutureLeverage)
request.InstrumentID = ""
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodPost, okGroupSwapSubsection, requestURL, request, &resp, true)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, okGroupSwapSubsection, requestURL, request, &resp, true)
}
// GetSwapBillDetails Shows the accounts historical coin in flow and out flow.
// All paginated requests return the latest information (newest) as the first page sorted by newest (in chronological time) first.
func (o *OKEX) GetSwapBillDetails(request okgroup.GetSpotBillDetailsForCurrencyRequest) (resp []okgroup.GetSwapBillDetailsResponse, _ error) {
func (o *OKEX) GetSwapBillDetails(ctx context.Context, request okgroup.GetSpotBillDetailsForCurrencyRequest) (resp []okgroup.GetSwapBillDetailsResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v%v", okgroup.OKGroupAccounts, request.Currency, okgroup.OKGroupLedger, okgroup.FormatParameters(request))
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, true)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, true)
}
// PlaceSwapOrder OKEx perpetual swap trading only supports limit ordersUSD as quote currency for orders.
// You can place an order only if you have enough funds. Once your order is placed, the amount will be put on hold in the order lifecycle.
// The assets and amount on hold depends on the order's specific type and parameters.
func (o *OKEX) PlaceSwapOrder(request okgroup.PlaceSwapOrderRequest) (resp okgroup.PlaceSwapOrderResponse, _ error) {
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodPost, okGroupSwapSubsection, okGroupFutureOrder, request, &resp, true)
func (o *OKEX) PlaceSwapOrder(ctx context.Context, request okgroup.PlaceSwapOrderRequest) (resp okgroup.PlaceSwapOrderResponse, _ error) {
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, okGroupSwapSubsection, okGroupFutureOrder, request, &resp, true)
}
// PlaceMultipleSwapOrders Batch contract placing order operation.
func (o *OKEX) PlaceMultipleSwapOrders(request okgroup.PlaceMultipleSwapOrdersRequest) (resp okgroup.PlaceMultipleSwapOrdersResponse, _ error) {
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodPost, okGroupSwapSubsection, okgroup.OKGroupOrders, request, &resp, true)
func (o *OKEX) PlaceMultipleSwapOrders(ctx context.Context, request okgroup.PlaceMultipleSwapOrdersRequest) (resp okgroup.PlaceMultipleSwapOrdersResponse, _ error) {
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, okGroupSwapSubsection, okgroup.OKGroupOrders, request, &resp, true)
}
// CancelSwapOrder Cancelling an unfilled order
func (o *OKEX) CancelSwapOrder(request okgroup.CancelSwapOrderRequest) (resp okgroup.CancelSwapOrderResponse, _ error) {
func (o *OKEX) CancelSwapOrder(ctx context.Context, request okgroup.CancelSwapOrderRequest) (resp okgroup.CancelSwapOrderResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupCancelOrder, request.InstrumentID, request.OrderID)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodPost, okGroupSwapSubsection, requestURL, nil, &resp, true)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, okGroupSwapSubsection, requestURL, nil, &resp, true)
}
// CancelMultipleSwapOrders With best effort, cancel all open orders.
func (o *OKEX) CancelMultipleSwapOrders(request okgroup.CancelMultipleSwapOrdersRequest) (resp okgroup.CancelMultipleSwapOrdersResponse, _ error) {
func (o *OKEX) CancelMultipleSwapOrders(ctx context.Context, request okgroup.CancelMultipleSwapOrdersRequest) (resp okgroup.CancelMultipleSwapOrdersResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v", okgroup.OKGroupCancelBatchOrders, request.InstrumentID)
request.InstrumentID = ""
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodPost, okGroupSwapSubsection, requestURL, request, &resp, true)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, okGroupSwapSubsection, requestURL, request, &resp, true)
}
// GetSwapOrderList List your orders. Cursor pagination is used.
// All paginated requests return the latest information (newest) as the first page sorted by newest (in chronological time) first.
func (o *OKEX) GetSwapOrderList(request okgroup.GetSwapOrderListRequest) (resp okgroup.GetSwapOrderListResponse, _ error) {
func (o *OKEX) GetSwapOrderList(ctx context.Context, request okgroup.GetSwapOrderListRequest) (resp okgroup.GetSwapOrderListResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v%v", okgroup.OKGroupOrders, request.InstrumentID, okgroup.FormatParameters(request))
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, true)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, true)
}
// GetSwapOrderDetails Get order details by order ID.
func (o *OKEX) GetSwapOrderDetails(request okgroup.GetSwapOrderDetailsRequest) (resp okgroup.GetSwapOrderListResponseData, _ error) {
func (o *OKEX) GetSwapOrderDetails(ctx context.Context, request okgroup.GetSwapOrderDetailsRequest) (resp okgroup.GetSwapOrderListResponseData, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupOrders, request.InstrumentID, request.OrderID)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, true)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, true)
}
// GetSwapTransactionDetails Get details of the recent filled orders
func (o *OKEX) GetSwapTransactionDetails(request okgroup.GetSwapTransactionDetailsRequest) (resp []okgroup.GetSwapTransactionDetailsResponse, _ error) {
func (o *OKEX) GetSwapTransactionDetails(ctx context.Context, request okgroup.GetSwapTransactionDetailsRequest) (resp []okgroup.GetSwapTransactionDetailsResponse, _ error) {
requestURL := fmt.Sprintf("%v%v", okgroup.OKGroupGetSpotTransactionDetails, okgroup.FormatParameters(request))
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, true)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, true)
}
// GetSwapContractInformation Get market data.
func (o *OKEX) GetSwapContractInformation() (resp []okgroup.GetSwapContractInformationResponse, _ error) {
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, okgroup.OKGroupInstruments, nil, &resp, false)
func (o *OKEX) GetSwapContractInformation(ctx context.Context) (resp []okgroup.GetSwapContractInformationResponse, _ error) {
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, okgroup.OKGroupInstruments, nil, &resp, false)
}
// GetAllSwapTokensInformation Get the last traded price, best bid/ask price, 24 hour trading volume and more info of all contracts.
func (o *OKEX) GetAllSwapTokensInformation() (resp []okgroup.GetAllSwapTokensInformationResponse, _ error) {
func (o *OKEX) GetAllSwapTokensInformation(ctx context.Context) (resp []okgroup.GetAllSwapTokensInformationResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v", okgroup.OKGroupInstruments, okgroup.OKGroupTicker)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
}
// GetSwapTokensInformationForCurrency Get the last traded price, best bid/ask price, 24 hour trading volume and more info of all contracts.
func (o *OKEX) GetSwapTokensInformationForCurrency(instrumentID string) (resp okgroup.GetAllSwapTokensInformationResponse, _ error) {
func (o *OKEX) GetSwapTokensInformationForCurrency(ctx context.Context, instrumentID string) (resp okgroup.GetAllSwapTokensInformationResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupInstruments, instrumentID, okgroup.OKGroupTicker)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
}
// GetSwapFilledOrdersData Get details of the recent filled orders
func (o *OKEX) GetSwapFilledOrdersData(request *okgroup.GetSwapFilledOrdersDataRequest) (resp []okgroup.GetSwapFilledOrdersDataResponse, _ error) {
func (o *OKEX) GetSwapFilledOrdersData(ctx context.Context, request *okgroup.GetSwapFilledOrdersDataRequest) (resp []okgroup.GetSwapFilledOrdersDataResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v%v", okgroup.OKGroupInstruments, request.InstrumentID, okgroup.OKGroupTrades, okgroup.FormatParameters(request))
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
}
// GetSwapIndices Get Indices of tokens.
func (o *OKEX) GetSwapIndices(instrumentID string) (resp okgroup.GetSwapIndecesResponse, _ error) {
func (o *OKEX) GetSwapIndices(ctx context.Context, instrumentID string) (resp okgroup.GetSwapIndecesResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupInstruments, instrumentID, okGroupIndices)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
}
// GetSwapExchangeRates Get the fiat exchange rates.
func (o *OKEX) GetSwapExchangeRates() (resp okgroup.GetSwapExchangeRatesResponse, _ error) {
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, okGroupRate, nil, &resp, false)
func (o *OKEX) GetSwapExchangeRates(ctx context.Context) (resp okgroup.GetSwapExchangeRatesResponse, _ error) {
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, okGroupRate, nil, &resp, false)
}
// GetSwapOpenInterest Get the open interest of a contract.
func (o *OKEX) GetSwapOpenInterest(instrumentID string) (resp okgroup.GetSwapExchangeRatesResponse, _ error) {
func (o *OKEX) GetSwapOpenInterest(ctx context.Context, instrumentID string) (resp okgroup.GetSwapExchangeRatesResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupInstruments, instrumentID, okGroupOpenInterest)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
}
// GetSwapCurrentPriceLimits Get the open interest of a contract.
func (o *OKEX) GetSwapCurrentPriceLimits(instrumentID string) (resp okgroup.GetSwapCurrentPriceLimitsResponse, _ error) {
func (o *OKEX) GetSwapCurrentPriceLimits(ctx context.Context, instrumentID string) (resp okgroup.GetSwapCurrentPriceLimitsResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupInstruments, instrumentID, okgroup.OKGroupPriceLimit)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
}
// GetSwapForceLiquidatedOrders Get force liquidated orders.
func (o *OKEX) GetSwapForceLiquidatedOrders(request okgroup.GetSwapForceLiquidatedOrdersRequest) (resp []okgroup.GetSwapForceLiquidatedOrdersResponse, _ error) {
func (o *OKEX) GetSwapForceLiquidatedOrders(ctx context.Context, request okgroup.GetSwapForceLiquidatedOrdersRequest) (resp []okgroup.GetSwapForceLiquidatedOrdersResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v%v", okgroup.OKGroupInstruments, request.InstrumentID, okgroup.OKGroupLiquidation, okgroup.FormatParameters(request))
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
}
// GetSwapOnHoldAmountForOpenOrders Get On Hold Amount for Open Orders.
func (o *OKEX) GetSwapOnHoldAmountForOpenOrders(instrumentID string) (resp okgroup.GetSwapOnHoldAmountForOpenOrdersResponse, _ error) {
func (o *OKEX) GetSwapOnHoldAmountForOpenOrders(ctx context.Context, instrumentID string) (resp okgroup.GetSwapOnHoldAmountForOpenOrdersResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupAccounts, instrumentID, okGroupFutureHolds)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, true)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, true)
}
// GetSwapNextSettlementTime Get the time of next settlement.
func (o *OKEX) GetSwapNextSettlementTime(instrumentID string) (resp okgroup.GetSwapNextSettlementTimeResponse, _ error) {
func (o *OKEX) GetSwapNextSettlementTime(ctx context.Context, instrumentID string) (resp okgroup.GetSwapNextSettlementTimeResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupInstruments, instrumentID, okGroupFundingTime)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
}
// GetSwapMarkPrice Get the time of next settlement.
func (o *OKEX) GetSwapMarkPrice(instrumentID string) (resp okgroup.GetSwapMarkPriceResponse, _ error) {
func (o *OKEX) GetSwapMarkPrice(ctx context.Context, instrumentID string) (resp okgroup.GetSwapMarkPriceResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupInstruments, instrumentID, okgroup.OKGroupMarkPrice)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
}
// GetSwapFundingRateHistory Get Funding Rate History.
func (o *OKEX) GetSwapFundingRateHistory(request okgroup.GetSwapFundingRateHistoryRequest) (resp []okgroup.GetSwapFundingRateHistoryResponse, _ error) {
func (o *OKEX) GetSwapFundingRateHistory(ctx context.Context, request okgroup.GetSwapFundingRateHistoryRequest) (resp []okgroup.GetSwapFundingRateHistoryResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v%v", okgroup.OKGroupInstruments, request.InstrumentID, okGroupHistoricalFundingRate, okgroup.FormatParameters(request))
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
}
// GetETT List the assets in ETT account. Get information such as balance, amount on hold/ available.
func (o *OKEX) GetETT() (resp []okgroup.GetETTResponse, _ error) {
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupETTSubsection, okgroup.OKGroupAccounts, nil, &resp, true)
func (o *OKEX) GetETT(ctx context.Context) (resp []okgroup.GetETTResponse, _ error) {
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupETTSubsection, okgroup.OKGroupAccounts, nil, &resp, true)
}
// GetETTAccountInformationForCurrency Getting the balance, amount available/on hold of a token in ETT account.
func (o *OKEX) GetETTAccountInformationForCurrency(currency string) (resp okgroup.GetETTResponse, _ error) {
func (o *OKEX) GetETTAccountInformationForCurrency(ctx context.Context, currency string) (resp okgroup.GetETTResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v", okgroup.OKGroupAccounts, currency)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupETTSubsection, requestURL, nil, &resp, true)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupETTSubsection, requestURL, nil, &resp, true)
}
// GetETTBillsDetails Bills details. All paginated requests return the latest information (newest)
// as the first page sorted by newest (in chronological time) first
func (o *OKEX) GetETTBillsDetails(currency string) (resp []okgroup.GetETTBillsDetailsResponse, _ error) {
func (o *OKEX) GetETTBillsDetails(ctx context.Context, currency string) (resp []okgroup.GetETTBillsDetailsResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupAccounts, currency, okgroup.OKGroupLedger)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupETTSubsection, requestURL, nil, &resp, true)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupETTSubsection, requestURL, nil, &resp, true)
}
// PlaceETTOrder You can place subscription or redemption orders under ETT trading.
// You can place an order only if you have enough funds. Once your order is placed,
// the amount will be put on hold in the order lifecycle.
// The assets and amount on hold depends on the order's specific type and parameters.
func (o *OKEX) PlaceETTOrder(request *okgroup.PlaceETTOrderRequest) (resp okgroup.PlaceETTOrderResponse, _ error) {
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodPost, okGroupETTSubsection, okgroup.OKGroupOrders, nil, &resp, true)
func (o *OKEX) PlaceETTOrder(ctx context.Context, request *okgroup.PlaceETTOrderRequest) (resp okgroup.PlaceETTOrderResponse, _ error) {
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, okGroupETTSubsection, okgroup.OKGroupOrders, nil, &resp, true)
}
// CancelETTOrder Cancel an unfilled order.
func (o *OKEX) CancelETTOrder(orderID string) (resp okgroup.PlaceETTOrderResponse, _ error) {
func (o *OKEX) CancelETTOrder(ctx context.Context, orderID string) (resp okgroup.PlaceETTOrderResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v", okgroup.OKGroupOrders, orderID)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodDelete, okGroupETTSubsection, requestURL, nil, &resp, true)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodDelete, okGroupETTSubsection, requestURL, nil, &resp, true)
}
// GetETTOrderList List your orders. Cursor pagination is used. All paginated requests return the latest information
// (newest) as the first page sorted by newest (in chronological time) first.
func (o *OKEX) GetETTOrderList(request okgroup.GetETTOrderListRequest) (resp []okgroup.GetETTOrderListResponse, _ error) {
func (o *OKEX) GetETTOrderList(ctx context.Context, request okgroup.GetETTOrderListRequest) (resp []okgroup.GetETTOrderListResponse, _ error) {
requestURL := fmt.Sprintf("%v%v", okgroup.OKGroupOrders, okgroup.FormatParameters(request))
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupETTSubsection, requestURL, nil, &resp, true)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupETTSubsection, requestURL, nil, &resp, true)
}
// GetETTOrderDetails Get order details by order ID.
func (o *OKEX) GetETTOrderDetails(orderID string) (resp okgroup.GetETTOrderListResponse, _ error) {
func (o *OKEX) GetETTOrderDetails(ctx context.Context, orderID string) (resp okgroup.GetETTOrderListResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v", okgroup.OKGroupOrders, orderID)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupETTSubsection, requestURL, nil, &resp, true)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupETTSubsection, requestURL, nil, &resp, true)
}
// GetETTConstituents Get ETT Constituents.This is a public endpoint, no identity verification is needed.
func (o *OKEX) GetETTConstituents(ett string) (resp okgroup.GetETTConstituentsResponse, _ error) {
func (o *OKEX) GetETTConstituents(ctx context.Context, ett string) (resp okgroup.GetETTConstituentsResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v", okGroupConstituents, ett)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupETTSubsection, requestURL, nil, &resp, false)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupETTSubsection, requestURL, nil, &resp, false)
}
// GetETTSettlementPriceHistory Get ETT settlement price history. This is a public endpoint, no identity verification is needed.
func (o *OKEX) GetETTSettlementPriceHistory(ett string) (resp []okgroup.GetETTSettlementPriceHistoryResponse, _ error) {
func (o *OKEX) GetETTSettlementPriceHistory(ctx context.Context, ett string) (resp []okgroup.GetETTSettlementPriceHistoryResponse, _ error) {
requestURL := fmt.Sprintf("%v/%v", okGroupDefinePrice, ett)
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupETTSubsection, requestURL, nil, &resp, false)
return resp, o.SendHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, okGroupETTSubsection, requestURL, nil, &resp, false)
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,7 @@
package okex
import (
"context"
"errors"
"fmt"
"sort"
@@ -37,7 +38,7 @@ func (o *OKEX) GetDefaultConfig() (*config.ExchangeConfig, error) {
}
if o.Features.Supports.RESTCapabilities.AutoPairUpdates {
err = o.UpdateTradablePairs(true)
err = o.UpdateTradablePairs(context.TODO(), true)
if err != nil {
return nil, err
}
@@ -291,7 +292,7 @@ func (o *OKEX) Run() {
return
}
err = o.UpdateTradablePairs(forceUpdate)
err = o.UpdateTradablePairs(context.TODO(), forceUpdate)
if err != nil {
log.Errorf(log.ExchangeSys,
"%s failed to update tradable pairs. Err: %s",
@@ -301,7 +302,7 @@ func (o *OKEX) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (o *OKEX) FetchTradablePairs(i asset.Item) ([]string, error) {
func (o *OKEX) FetchTradablePairs(ctx context.Context, i asset.Item) ([]string, error) {
var pairs []string
format, err := o.GetPairFormat(i, false)
@@ -311,7 +312,7 @@ func (o *OKEX) FetchTradablePairs(i asset.Item) ([]string, error) {
switch i {
case asset.Spot:
prods, err := o.GetSpotTokenPairDetails()
prods, err := o.GetSpotTokenPairDetails(ctx)
if err != nil {
return nil, err
}
@@ -324,7 +325,7 @@ func (o *OKEX) FetchTradablePairs(i asset.Item) ([]string, error) {
}
return pairs, nil
case asset.Futures:
prods, err := o.GetFuturesContractInformation()
prods, err := o.GetFuturesContractInformation(ctx)
if err != nil {
return nil, err
}
@@ -336,7 +337,7 @@ func (o *OKEX) FetchTradablePairs(i asset.Item) ([]string, error) {
return pairs, nil
case asset.PerpetualSwap:
prods, err := o.GetSwapContractInformation()
prods, err := o.GetSwapContractInformation(ctx)
if err != nil {
return nil, err
}
@@ -360,7 +361,7 @@ func (o *OKEX) FetchTradablePairs(i asset.Item) ([]string, error) {
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (o *OKEX) UpdateTradablePairs(forceUpdate bool) error {
func (o *OKEX) UpdateTradablePairs(ctx context.Context, forceUpdate bool) error {
assets := o.CurrencyPairs.GetAssetTypes(false)
for x := range assets {
if assets[x] == asset.Index {
@@ -368,7 +369,7 @@ func (o *OKEX) UpdateTradablePairs(forceUpdate bool) error {
continue
}
pairs, err := o.FetchTradablePairs(assets[x])
pairs, err := o.FetchTradablePairs(ctx, assets[x])
if err != nil {
return err
}
@@ -425,10 +426,10 @@ func (o *OKEX) UpdateTradablePairs(forceUpdate bool) error {
}
// UpdateTickers updates the ticker for all currency pairs of a given asset type
func (o *OKEX) UpdateTickers(a asset.Item) error {
func (o *OKEX) UpdateTickers(ctx context.Context, a asset.Item) error {
switch a {
case asset.Spot:
resp, err := o.GetSpotAllTokenPairsInformation()
resp, err := o.GetSpotAllTokenPairsInformation(ctx)
if err != nil {
return err
}
@@ -462,7 +463,7 @@ func (o *OKEX) UpdateTickers(a asset.Item) error {
}
case asset.PerpetualSwap:
resp, err := o.GetAllSwapTokensInformation()
resp, err := o.GetAllSwapTokensInformation(ctx)
if err != nil {
return err
}
@@ -498,7 +499,7 @@ func (o *OKEX) UpdateTickers(a asset.Item) error {
}
case asset.Futures:
resp, err := o.GetAllFuturesTokenInfo()
resp, err := o.GetAllFuturesTokenInfo(ctx)
if err != nil {
return err
}
@@ -538,8 +539,8 @@ func (o *OKEX) UpdateTickers(a asset.Item) error {
}
// UpdateTicker updates and returns the ticker for a currency pair
func (o *OKEX) UpdateTicker(p currency.Pair, a asset.Item) (*ticker.Price, error) {
err := o.UpdateTickers(a)
func (o *OKEX) UpdateTicker(ctx context.Context, p currency.Pair, a asset.Item) (*ticker.Price, error) {
err := o.UpdateTickers(ctx, a)
if err != nil {
return nil, err
}
@@ -547,7 +548,7 @@ func (o *OKEX) UpdateTicker(p currency.Pair, a asset.Item) (*ticker.Price, error
}
// FetchTicker returns the ticker for a currency pair
func (o *OKEX) FetchTicker(p currency.Pair, assetType asset.Item) (tickerData *ticker.Price, err error) {
func (o *OKEX) FetchTicker(ctx context.Context, p currency.Pair, assetType asset.Item) (tickerData *ticker.Price, err error) {
if assetType == asset.Index {
return tickerData, errors.New("ticker fetching not supported for index")
}
@@ -558,13 +559,13 @@ func (o *OKEX) FetchTicker(p currency.Pair, assetType asset.Item) (tickerData *t
tickerData, err = ticker.GetTicker(o.Name, fPair, assetType)
if err != nil {
return o.UpdateTicker(fPair, assetType)
return o.UpdateTicker(ctx, fPair, assetType)
}
return
}
// GetRecentTrades returns recent trade data
func (o *OKEX) GetRecentTrades(p currency.Pair, assetType asset.Item) ([]trade.Data, error) {
func (o *OKEX) GetRecentTrades(ctx context.Context, p currency.Pair, assetType asset.Item) ([]trade.Data, error) {
var err error
p, err = o.FormatExchangeCurrency(p, assetType)
if err != nil {
@@ -575,9 +576,10 @@ func (o *OKEX) GetRecentTrades(p currency.Pair, assetType asset.Item) ([]trade.D
switch assetType {
case asset.Spot:
var tradeData []okgroup.GetSpotFilledOrdersInformationResponse
tradeData, err = o.GetSpotFilledOrdersInformation(okgroup.GetSpotFilledOrdersInformationRequest{
InstrumentID: p.String(),
})
tradeData, err = o.GetSpotFilledOrdersInformation(ctx,
okgroup.GetSpotFilledOrdersInformationRequest{
InstrumentID: p.String(),
})
if err != nil {
return nil, err
}
@@ -599,9 +601,10 @@ func (o *OKEX) GetRecentTrades(p currency.Pair, assetType asset.Item) ([]trade.D
}
case asset.Futures:
var tradeData []okgroup.GetFuturesFilledOrdersResponse
tradeData, err = o.GetFuturesFilledOrder(okgroup.GetFuturesFilledOrderRequest{
InstrumentID: p.String(),
})
tradeData, err = o.GetFuturesFilledOrder(ctx,
okgroup.GetFuturesFilledOrderRequest{
InstrumentID: p.String(),
})
if err != nil {
return nil, err
}
@@ -623,9 +626,10 @@ func (o *OKEX) GetRecentTrades(p currency.Pair, assetType asset.Item) ([]trade.D
}
case asset.PerpetualSwap:
var tradeData []okgroup.GetSwapFilledOrdersDataResponse
tradeData, err = o.GetSwapFilledOrdersData(&okgroup.GetSwapFilledOrdersDataRequest{
InstrumentID: p.String(),
})
tradeData, err = o.GetSwapFilledOrdersData(ctx,
&okgroup.GetSwapFilledOrdersDataRequest{
InstrumentID: p.String(),
})
if err != nil {
return nil, err
}
@@ -659,6 +663,6 @@ func (o *OKEX) GetRecentTrades(p currency.Pair, assetType asset.Item) ([]trade.D
}
// CancelBatchOrders cancels an orders by their corresponding ID numbers
func (o *OKEX) CancelBatchOrders(_ []order.Cancel) (order.CancelBatchResponse, error) {
func (o *OKEX) CancelBatchOrders(_ context.Context, _ []order.Cancel) (order.CancelBatchResponse, error) {
return order.CancelBatchResponse{}, common.ErrNotYetImplemented
}