mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-05 15:10:59 +00:00
Feature: Implement funding rates, futures and coin margin (exchange API coverage) (#530)
* ALMOST THERE * more api wips * more api thingz * testing n more api wipz * more apiz * more wips * what is goin on * more wips * whip n testing * testing * testing no keys * remove log * kraken is broken ugh * still broken * fixing auth funcs + usdtm api docs * wip * api stuffs * whip * more wips * whip * more wip * api wip n testing * wip * wip * unsaved * wip n testing * wip * wip * wip * wip * wip * wip * wip * wip * wip * whip * wrapper authenticated functions * adding asset type and fixing dependencies * wip * binance auth wrapper start * wrapper functionality * wip * wip * wip * wrapper cancel functions * order submission for wrappers * wip * more error fixing and nits * websocket beginning n error fix * wip * WOW * glorious n shazzy nits * useless nits * wip * fixing things * merge stuffs * crapveyor * crapveyor rebuild * probably broke more things than he fixed * rm lns n other thangs * hope * please * stop it * done * ofcourse * rm vb * fix lbank * appveyor please * float lev * DONT ASK RYAN FOR HELP EVER * wip * wip * endpoint upgrades continued * path upgrade * NeeeNeeeNeeeNeeeNING * fix stuffs * fixing time issue * fixing broken funcs * glorious nits * shaz changes * fixing errors for fundmon * more error fixing for fundmon * test running past 30s * basic changes * THX AGAIN SHAZBERT * path system upgrade * config upgrade * unsaved stuffs * broken wip config upgrade * path system upgrade contd. * path system upgrade contd * path upgrade ready for review * testing verbose removed * linter stuffs * appveyor stuffs * appveyor stuff * fixed? * bugfix * wip * broken stuff * fix test * wierd hack fix * appveyor pls stop * error found * more useless nits * bitmex err * broken wip * broken wip path upgrade change to uint32 * changed url lookups to uint * WOW * ready4review * config fixed HOPEFULLY * config fix and glorious changes * efficient way of getting orders and open orders * binance wrapper logic fixing * testing, adding tests and fixing lot of errrrrs * merge master * appveyor stuffs * appveyor stuffs * fmt * test * octalLiteral issue fix? * octalLiteral fix? * rm vb * prnt ln to restart * adding testz * test fixzzz * READY FOR REVIEW * Actually ready now * FORMATTING * addressing shazzy n glorious nits * crapveyor * rm vb * small change * fixing err * shazbert nits * review changes * requested changes * more requested changes * noo * last nit fixes * restart appveyor * improving test cov * Update .golangci.yml * shazbert changes * moving pair formatting * format pair update wip * path upgrade complete * error fix * appveyor linters * more linters * remove testexch * more formatting changes * changes * shazbert changes * checking older requested changes to ensure completion * wip * fixing broken code * error fix * all fixed * additional changes * more changes * remove commented code * ftx margin api * appveyor fixes * more appveyor issues + test addition * more appveyor issues + test addition * remove unnecessary * testing * testing, fixing okex api, error fix * git merge fix * go sum * glorious changes and error fix * rm vb * more glorious changes and go mod tidy * fixed now * okex testing upgrade * old config migration and batch fetching fix * added test * glorious requested changes WIP * tested and fixed * go fmted * go fmt and test fix * additional funcs and tests for fundingRates * OKEX tested and fixed * appveyor fixes * ineff assign * 1 glorious change * error fix * typo * shazbert changes * glorious code changes and path fixing huobi WIP * adding assetType to accountinfo functions * fixing panic * panic fix and updating account info wrappers WIP * updateaccountinfo updated * testing WIP binance USDT n Coin Margined and Kraken Futures * auth functions tested and fixed * added test * config reverted * shazbert and glorious changes * shazbert and glorious changes * latest changes and portfolio update * go fmt change: * remove commented codes * improved error checking * index out of range fix * rm ln * critical nit * glorious latest changes * appveyor changes * shazbert change * easier readability * latest glorious changes * shadow dec * assetstore updated * last change * another last change * merge changes * go mod tidy * thrasher requested changes wip * improving struct layouts * appveyor go fmt * remove unnecessary code * shazbert changes * small change * oopsie * tidy * configtest reverted * error fix * oopsie * for what * test patch fix * insecurities * fixing tests * fix config
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
package okex
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/okgroup"
|
||||
)
|
||||
|
||||
@@ -19,9 +25,11 @@ const (
|
||||
// OkExWebsocketURL WebsocketURL
|
||||
OkExWebsocketURL = "wss://real.okex.com:8443/ws/v3"
|
||||
// API subsections
|
||||
okGroupSpotSubsection = "spot"
|
||||
okGroupFuturesSubsection = "futures"
|
||||
okGroupSwapSubsection = "swap"
|
||||
okGroupETTSubsection = "ett"
|
||||
okGroupMarginSubsection = "margin"
|
||||
// Futures based endpoints
|
||||
okGroupFuturePosition = "position"
|
||||
okGroupFutureLeverage = "leverage"
|
||||
@@ -36,9 +44,15 @@ const (
|
||||
okGroupDepth = "depth"
|
||||
okGroupFundingTime = "funding_time"
|
||||
okGroupHistoricalFundingRate = "historical_funding_rate"
|
||||
okGroupSwapInstruments = "instruments"
|
||||
// ETT endpoints
|
||||
okGroupConstituents = "constituents"
|
||||
okGroupDefinePrice = "define-price"
|
||||
okGroupConstituents = "constituents"
|
||||
okGroupDefinePrice = "define-price"
|
||||
okGroupPerpSwapRates = "instruments/%s/historical_funding_rate?"
|
||||
okGroupPerpTickers = "instruments/ticker"
|
||||
okGroupMarginPairData = "accounts/%s/availability"
|
||||
okGroupMarginPairsData = "accounts/availability"
|
||||
okGroupSpotPairs = "instruments"
|
||||
)
|
||||
|
||||
// OKEX bases all account, spot and margin methods off okgroup implementation
|
||||
@@ -46,34 +60,167 @@ type OKEX struct {
|
||||
okgroup.OKGroup
|
||||
}
|
||||
|
||||
// GetSwapMarkets gets perpetual swap markets
|
||||
func (o *OKEX) GetSwapMarkets() ([]okgroup.SwapInstrumentsData, error) {
|
||||
var resp []okgroup.SwapInstrumentsData
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection,
|
||||
okGroupSwapInstruments,
|
||||
nil, &resp, false)
|
||||
}
|
||||
|
||||
// GetAllMarginRates gets interest rates for all margin currencies on OKEX
|
||||
func (o *OKEX) GetAllMarginRates() ([]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,
|
||||
okGroupMarginSubsection,
|
||||
okGroupMarginPairsData,
|
||||
nil,
|
||||
&result,
|
||||
true)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
for i := range result {
|
||||
for k, v := range result[i] {
|
||||
if strings.Contains(k, "currency:") {
|
||||
var byteData []byte
|
||||
var marginData okgroup.MarginData
|
||||
currencyString := strings.Replace(k, "currency:", "", 1)
|
||||
byteData, err = json.Marshal(v)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
err = json.Unmarshal(byteData, &marginData)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
tempResp.Data[currencyString] = marginData
|
||||
}
|
||||
var strData string
|
||||
var ok bool
|
||||
strData, ok = result[i]["instrument_id"].(string)
|
||||
if !ok {
|
||||
return resp, errors.New("type conversion failed for instrument_id")
|
||||
}
|
||||
tempResp.InstrumentID = strData
|
||||
strData, ok = result[i]["product_id"].(string)
|
||||
if !ok {
|
||||
return resp, errors.New("type conversion failed for product_id")
|
||||
}
|
||||
tempResp.ProductID = strData
|
||||
resp = append(resp, tempResp)
|
||||
}
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetMarginRates gets interest rates for margin currencies
|
||||
func (o *OKEX) GetMarginRates(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,
|
||||
okGroupMarginSubsection,
|
||||
fmt.Sprintf(okGroupMarginPairData, instrumentID),
|
||||
nil,
|
||||
&result,
|
||||
true)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
for i := range result {
|
||||
for k, v := range result[i] {
|
||||
var byteData []byte
|
||||
var marginData okgroup.MarginData
|
||||
byteData, err = json.Marshal(v)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
if strings.Contains(k, instrumentID.Base.String()) {
|
||||
err = json.Unmarshal(byteData, &marginData)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
resp.Data[instrumentID.Base.String()] = marginData
|
||||
} else if strings.Contains(k, instrumentID.Quote.String()) {
|
||||
err = json.Unmarshal(byteData, &marginData)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
resp.Data[instrumentID.Quote.String()] = marginData
|
||||
}
|
||||
}
|
||||
var strData string
|
||||
var ok bool
|
||||
strData, ok = result[i]["instrument_id"].(string)
|
||||
if !ok {
|
||||
return resp, errors.New("type conversion failed for instrument_id")
|
||||
}
|
||||
resp.InstrumentID = strData
|
||||
strData, ok = result[i]["product_id"].(string)
|
||||
if !ok {
|
||||
return resp, errors.New("type conversion failed for product_id")
|
||||
}
|
||||
resp.ProductID = strData
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetSpotMarkets gets perpetual swap markets' data
|
||||
func (o *OKEX) GetSpotMarkets() ([]okgroup.TradingPairData, error) {
|
||||
var resp []okgroup.TradingPairData
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSpotSubsection, okGroupSpotPairs, nil, &resp, false)
|
||||
}
|
||||
|
||||
// GetFundingRate gets funding rate of a given currency
|
||||
func (o *OKEX) GetFundingRate(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,
|
||||
fmt.Sprintf(okGroupPerpSwapRates, marketName)+params.Encode(),
|
||||
nil, &resp, false)
|
||||
}
|
||||
|
||||
// GetPerpSwapMarkets gets perpetual swap markets' data
|
||||
func (o *OKEX) GetPerpSwapMarkets() ([]okgroup.TickerData, error) {
|
||||
var resp []okgroup.TickerData
|
||||
return resp, o.SendHTTPRequest(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(http.MethodGet, okGroupFuturesSubsection, okGroupFuturePosition, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v", instrumentID, okGroupFuturePosition)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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(http.MethodGet, okGroupFuturesSubsection, okgroup.OKGroupAccounts, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v", okgroup.OKGroupAccounts, instrumentID)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupAccounts, instrumentID, okGroupFutureLeverage)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, true)
|
||||
}
|
||||
|
||||
// SetFuturesLeverage Adjusting the leverage for futures account。
|
||||
@@ -81,132 +228,132 @@ func (o *OKEX) GetFuturesLeverage(instrumentID string) (resp okgroup.GetFuturesL
|
||||
// Fixed margin request requirements: {"instrument_id":"BTC-USD-180213","direction":"long","leverage":"10"}
|
||||
func (o *OKEX) SetFuturesLeverage(request okgroup.SetFuturesLeverageRequest) (resp okgroup.SetFuturesLeverageResponse, _ error) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupAccounts, request.Currency, okGroupFutureLeverage)
|
||||
return resp, o.SendHTTPRequest(http.MethodPost, okGroupFuturesSubsection, requestURL, request, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodPost, okGroupFuturesSubsection, requestURL, request, &resp, true)
|
||||
}
|
||||
|
||||
// GetFuturesBillDetails Shows the account’s 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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v%v", okgroup.OKGroupAccounts, request.Currency, okgroup.OKGroupLedger, okgroup.FormatParameters(request))
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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(http.MethodPost, okGroupFuturesSubsection, okGroupFutureOrder, request, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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(http.MethodPost, okGroupFuturesSubsection, okgroup.OKGroupOrders, request, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupCancelOrder, request.InstrumentID, request.OrderID)
|
||||
return resp, o.SendHTTPRequest(http.MethodPost, okGroupFuturesSubsection, requestURL, request, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v", okgroup.OKGroupCancelBatchOrders, request.InstrumentID)
|
||||
return resp, o.SendHTTPRequest(http.MethodPost, okGroupFuturesSubsection, requestURL, request, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v%v", okgroup.OKGroupOrders, request.InstrumentID, okgroup.FormatParameters(request))
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupOrders, request.InstrumentID, request.OrderID)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v%v", okgroup.OKGroupGetSpotTransactionDetails, okgroup.FormatParameters(request))
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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(http.MethodGet, okGroupFuturesSubsection, okgroup.OKGroupInstruments, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v", okgroup.OKGroupInstruments, okgroup.OKGroupTicker)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupInstruments, instrumentID, okgroup.OKGroupTicker)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v%v", okgroup.OKGroupInstruments, request.InstrumentID, okgroup.OKGroupTrades, okgroup.FormatParameters(request))
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupAccounts, instrumentID, okGroupFutureHolds)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupInstruments, instrumentID, okGroupIndices)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(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(http.MethodGet, okGroupFuturesSubsection, okGroupRate, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupInstruments, instrumentID, okGroupEsimtatedPrice)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupInstruments, instrumentID, okGroupOpenInterest)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupInstruments, instrumentID, okgroup.OKGroupPriceLimit)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupInstruments, instrumentID, okgroup.OKGroupMarkPrice)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v%v", okgroup.OKGroupInstruments, request.InstrumentID, okgroup.OKGroupLiquidation, okgroup.FormatParameters(request))
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupFuturesSubsection, requestURL, nil, &resp, false)
|
||||
}
|
||||
|
||||
// GetFuturesTagPrice Get the tag price. This is a public endpoint, no identity verification is needed.
|
||||
@@ -218,25 +365,25 @@ func (o *OKEX) GetFuturesTagPrice(instrumentID string) (resp okgroup.GetFuturesT
|
||||
// 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(http.MethodGet, okGroupSwapSubsection, okGroupFuturePosition, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v", instrumentID, okGroupFuturePosition)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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(http.MethodGet, okGroupSwapSubsection, okgroup.OKGroupAccounts, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupAccounts, instrumentID, okGroupSettings)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, true)
|
||||
}
|
||||
|
||||
// SetSwapLeverageLevelOfAContract Setting the leverage level of a contract
|
||||
@@ -244,152 +391,152 @@ func (o *OKEX) GetSwapAccountSettingsOfAContract(instrumentID string) (resp okgr
|
||||
func (o *OKEX) SetSwapLeverageLevelOfAContract(request okgroup.SetSwapLeverageLevelOfAContractRequest) (resp okgroup.SetSwapLeverageLevelOfAContractResponse, _ error) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupAccounts, request.InstrumentID, okGroupFutureLeverage)
|
||||
request.InstrumentID = ""
|
||||
return resp, o.SendHTTPRequest(http.MethodPost, okGroupSwapSubsection, requestURL, request, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodPost, okGroupSwapSubsection, requestURL, request, &resp, true)
|
||||
}
|
||||
|
||||
// GetSwapBillDetails Shows the account’s 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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v%v", okgroup.OKGroupAccounts, request.Currency, okgroup.OKGroupLedger, okgroup.FormatParameters(request))
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, true)
|
||||
}
|
||||
|
||||
// PlaceSwapOrder OKEx perpetual swap trading only supports limit orders,USD 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(http.MethodPost, okGroupSwapSubsection, okGroupFutureOrder, request, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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(http.MethodPost, okGroupSwapSubsection, okgroup.OKGroupOrders, request, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupCancelOrder, request.InstrumentID, request.OrderID)
|
||||
return resp, o.SendHTTPRequest(http.MethodPost, okGroupSwapSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v", okgroup.OKGroupCancelBatchOrders, request.InstrumentID)
|
||||
request.InstrumentID = ""
|
||||
return resp, o.SendHTTPRequest(http.MethodPost, okGroupSwapSubsection, requestURL, request, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v%v", okgroup.OKGroupOrders, request.InstrumentID, okgroup.FormatParameters(request))
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupOrders, request.InstrumentID, request.OrderID)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v%v", okgroup.OKGroupGetSpotTransactionDetails, okgroup.FormatParameters(request))
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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(http.MethodGet, okGroupSwapSubsection, okgroup.OKGroupInstruments, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v", okgroup.OKGroupInstruments, okgroup.OKGroupTicker)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupInstruments, instrumentID, okgroup.OKGroupTicker)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v%v", okgroup.OKGroupInstruments, request.InstrumentID, okgroup.OKGroupTrades, okgroup.FormatParameters(request))
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
|
||||
}
|
||||
|
||||
// GetSwapIndices Get Indices of tokens.
|
||||
func (o *OKEX) GetSwapIndices(instrumentID string) (resp okgroup.GetSwapIndecesResponse, _ error) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupInstruments, instrumentID, okGroupIndices)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(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(http.MethodGet, okGroupSwapSubsection, okGroupRate, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupInstruments, instrumentID, okGroupOpenInterest)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupInstruments, instrumentID, okgroup.OKGroupPriceLimit)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v%v", okgroup.OKGroupInstruments, request.InstrumentID, okgroup.OKGroupLiquidation, okgroup.FormatParameters(request))
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupAccounts, instrumentID, okGroupFutureHolds)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupInstruments, instrumentID, okGroupFundingTime)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupInstruments, instrumentID, okgroup.OKGroupMarkPrice)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v%v", okgroup.OKGroupInstruments, request.InstrumentID, okGroupHistoricalFundingRate, okgroup.FormatParameters(request))
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupSwapSubsection, requestURL, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(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(http.MethodGet, okGroupETTSubsection, okgroup.OKGroupAccounts, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v", okgroup.OKGroupAccounts, currency)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupETTSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v", okgroup.OKGroupAccounts, currency, okgroup.OKGroupLedger)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupETTSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupETTSubsection, requestURL, nil, &resp, true)
|
||||
}
|
||||
|
||||
// PlaceETTOrder You can place subscription or redemption orders under ETT trading.
|
||||
@@ -397,36 +544,36 @@ func (o *OKEX) GetETTBillsDetails(currency string) (resp []okgroup.GetETTBillsDe
|
||||
// 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(http.MethodPost, okGroupETTSubsection, okgroup.OKGroupOrders, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v", okgroup.OKGroupOrders, orderID)
|
||||
return resp, o.SendHTTPRequest(http.MethodDelete, okGroupETTSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v%v", okgroup.OKGroupOrders, okgroup.FormatParameters(request))
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupETTSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v", okgroup.OKGroupOrders, orderID)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupETTSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v", okGroupConstituents, ett)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupETTSubsection, requestURL, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(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) {
|
||||
requestURL := fmt.Sprintf("%v/%v", okGroupDefinePrice, ett)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupETTSubsection, requestURL, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupETTSubsection, requestURL, nil, &resp, false)
|
||||
}
|
||||
|
||||
@@ -68,7 +68,6 @@ func TestMain(m *testing.M) {
|
||||
okexConfig.API.Credentials.Key = apiKey
|
||||
okexConfig.API.Credentials.Secret = apiSecret
|
||||
okexConfig.API.Credentials.ClientID = passphrase
|
||||
okexConfig.API.Endpoints.WebsocketURL = o.API.Endpoints.WebsocketURL
|
||||
o.Websocket = sharedtestvalues.NewTestWebsocket()
|
||||
err = o.Setup(okexConfig)
|
||||
if err != nil {
|
||||
@@ -81,6 +80,103 @@ func areTestAPIKeysSet() bool {
|
||||
return o.ValidateAPICredentials()
|
||||
}
|
||||
|
||||
func TestUpdateOrderbook(t *testing.T) {
|
||||
tradablePairs, err := o.FetchTradablePairs(asset.Futures)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if len(tradablePairs) == 0 {
|
||||
t.Fatal("no tradable pairs")
|
||||
}
|
||||
cp, err := currency.NewPairFromString(tradablePairs[0])
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
reqPair, err := o.FormatExchangeCurrency(cp, asset.Futures)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
cp, err = currency.NewPairFromString(reqPair.String())
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = o.UpdateOrderbook(cp, asset.Futures)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
cp, err = currency.NewPairFromString("BTC-USD-SWAP")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = o.UpdateOrderbook(cp, asset.PerpetualSwap)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
cp, err = currency.NewPairFromString("BTC-USDT")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = o.UpdateOrderbook(cp, asset.Spot)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetAllMarginRates(t *testing.T) {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip("skipping test: api keys not set")
|
||||
}
|
||||
_, err := o.GetAllMarginRates()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetMarginRates(t *testing.T) {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip("skipping test: api keys not set")
|
||||
}
|
||||
cp, err := currency.NewPairFromString("XRP-USDT")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = o.GetMarginRates(cp)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetSpotMarkets(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := o.GetSpotMarkets()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetSwapMarkets(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := o.GetSwapMarkets()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetFundingRate(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := o.GetFundingRate("BTC-USD-SWAP", "1")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetPerpSwapMarkets(t *testing.T) {
|
||||
_, err := o.GetPerpSwapMarkets()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testStandardErrorHandling(t *testing.T, err error) {
|
||||
if !areTestAPIKeysSet() && err == nil {
|
||||
t.Errorf("Expecting an error when no keys are set")
|
||||
@@ -564,13 +660,14 @@ func TestGetHistoricCandlesExtended(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
startTime := time.Unix(1588636800, 0)
|
||||
_, err = o.GetHistoricCandlesExtended(currencyPair, asset.Spot, startTime, time.Now(), kline.OneMin)
|
||||
startTime := time.Unix(1607494054, 0)
|
||||
endTime := time.Unix(1607512054, 0)
|
||||
_, err = o.GetHistoricCandlesExtended(currencyPair, asset.Spot, startTime, endTime, kline.OneHour)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = o.GetHistoricCandles(currencyPair, asset.Spot, startTime, time.Now(), kline.Interval(time.Hour*7))
|
||||
_, err = o.GetHistoricCandles(currencyPair, asset.Spot, startTime, endTime, kline.Interval(time.Hour*15))
|
||||
if err == nil {
|
||||
t.Fatal("unexpected result")
|
||||
}
|
||||
@@ -1742,7 +1839,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
// TestGetAccountInfo Wrapper test
|
||||
func TestGetAccountInfo(t *testing.T) {
|
||||
_, err := o.UpdateAccountInfo()
|
||||
_, err := o.UpdateAccountInfo(asset.Spot)
|
||||
testStandardErrorHandling(t, err)
|
||||
}
|
||||
|
||||
|
||||
@@ -197,10 +197,14 @@ func (o *OKEX) SetDefaults() {
|
||||
// TODO: Specify each individual endpoint rate limits as per docs
|
||||
request.WithLimiter(request.NewBasicRateLimit(okExRateInterval, okExRequestRate)),
|
||||
)
|
||||
|
||||
o.API.Endpoints.URLDefault = okExAPIURL
|
||||
o.API.Endpoints.URL = okExAPIURL
|
||||
o.API.Endpoints.WebsocketURL = OkExWebsocketURL
|
||||
o.API.Endpoints = o.NewEndpoints()
|
||||
err = o.API.Endpoints.SetDefaultEndpoints(map[exchange.URL]string{
|
||||
exchange.RestSpot: okExAPIURL,
|
||||
exchange.WebsocketSpot: OkExWebsocketURL,
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorln(log.ExchangeSys, err)
|
||||
}
|
||||
o.Websocket = stream.New()
|
||||
o.APIVersion = okExAPIVersion
|
||||
o.WebsocketResponseMaxLimit = exchange.DefaultWebsocketResponseMaxLimit
|
||||
@@ -220,11 +224,15 @@ func (o *OKEX) Start(wg *sync.WaitGroup) {
|
||||
// Run implements the OKEX wrapper
|
||||
func (o *OKEX) Run() {
|
||||
if o.Verbose {
|
||||
wsEndpoint, err := o.API.Endpoints.GetURL(exchange.WebsocketSpot)
|
||||
if err != nil {
|
||||
log.Error(log.ExchangeSys, err)
|
||||
}
|
||||
log.Debugf(log.ExchangeSys,
|
||||
"%s Websocket: %s. (url: %s).\n",
|
||||
o.Name,
|
||||
common.IsEnabled(o.Websocket.IsEnabled()),
|
||||
o.API.Endpoints.WebsocketURL)
|
||||
wsEndpoint)
|
||||
}
|
||||
|
||||
format, err := o.GetPairFormat(asset.Spot, false)
|
||||
|
||||
Reference in New Issue
Block a user