mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-02 23:16:51 +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:
@@ -104,7 +104,7 @@ type OKGroup struct {
|
||||
|
||||
// GetAccountCurrencies returns a list of tradable spot instruments and their properties
|
||||
func (o *OKGroup) GetAccountCurrencies() (resp []GetAccountCurrenciesResponse, _ error) {
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupAccountSubsection, okGroupGetAccountCurrencies, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupAccountSubsection, okGroupGetAccountCurrencies, nil, &resp, true)
|
||||
}
|
||||
|
||||
// GetAccountWalletInformation returns a list of wallets and their properties
|
||||
@@ -116,17 +116,17 @@ func (o *OKGroup) GetAccountWalletInformation(currency string) (resp []WalletInf
|
||||
requestURL = okGroupGetAccountWalletInformation
|
||||
}
|
||||
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupAccountSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupAccountSubsection, requestURL, nil, &resp, true)
|
||||
}
|
||||
|
||||
// TransferAccountFunds the transfer of funds between wallet, trading accounts, main account and sub accounts.
|
||||
func (o *OKGroup) TransferAccountFunds(request TransferAccountFundsRequest) (resp TransferAccountFundsResponse, _ error) {
|
||||
return resp, o.SendHTTPRequest(http.MethodPost, okGroupAccountSubsection, okGroupFundsTransfer, request, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodPost, okGroupAccountSubsection, okGroupFundsTransfer, request, &resp, true)
|
||||
}
|
||||
|
||||
// AccountWithdraw withdrawal of tokens to OKCoin International, other OKEx accounts or other addresses.
|
||||
func (o *OKGroup) AccountWithdraw(request AccountWithdrawRequest) (resp AccountWithdrawResponse, _ error) {
|
||||
return resp, o.SendHTTPRequest(http.MethodPost, okGroupAccountSubsection, okGroupWithdraw, request, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodPost, okGroupAccountSubsection, okGroupWithdraw, request, &resp, true)
|
||||
}
|
||||
|
||||
// GetAccountWithdrawalFee retrieves the information about the recommended network transaction fee for withdrawals to digital asset addresses. The higher the fees are, the sooner the confirmations you will get.
|
||||
@@ -138,7 +138,7 @@ func (o *OKGroup) GetAccountWithdrawalFee(currency string) (resp []GetAccountWit
|
||||
requestURL = okGroupGetAccountWalletInformation
|
||||
}
|
||||
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupAccountSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupAccountSubsection, requestURL, nil, &resp, true)
|
||||
}
|
||||
|
||||
// GetAccountWithdrawalHistory retrieves all recent withdrawal records.
|
||||
@@ -149,7 +149,7 @@ func (o *OKGroup) GetAccountWithdrawalHistory(currency string) (resp []Withdrawa
|
||||
} else {
|
||||
requestURL = okGroupGetWithdrawalHistory
|
||||
}
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupAccountSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupAccountSubsection, requestURL, nil, &resp, true)
|
||||
}
|
||||
|
||||
// GetAccountBillDetails retrieves the bill details of the wallet. All the information will be paged and sorted in reverse chronological order,
|
||||
@@ -157,7 +157,7 @@ func (o *OKGroup) GetAccountWithdrawalHistory(currency string) (resp []Withdrawa
|
||||
// 3 months recent records will be returned at maximum
|
||||
func (o *OKGroup) GetAccountBillDetails(request GetAccountBillDetailsRequest) (resp []GetAccountBillDetailsResponse, _ error) {
|
||||
requestURL := fmt.Sprintf("%v%v", OKGroupLedger, FormatParameters(request))
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupAccountSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupAccountSubsection, requestURL, nil, &resp, true)
|
||||
}
|
||||
|
||||
// GetAccountDepositAddressForCurrency retrieves the deposit addresses of different tokens, including previously used addresses.
|
||||
@@ -165,7 +165,7 @@ func (o *OKGroup) GetAccountDepositAddressForCurrency(currency string) (resp []G
|
||||
urlValues := url.Values{}
|
||||
urlValues.Set("currency", currency)
|
||||
requestURL := fmt.Sprintf("%v?%v", okGroupGetDepositAddress, urlValues.Encode())
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupAccountSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupAccountSubsection, requestURL, nil, &resp, true)
|
||||
}
|
||||
|
||||
// GetAccountDepositHistory retrieves the deposit history of all tokens.100 recent records will be returned at maximum
|
||||
@@ -176,24 +176,24 @@ func (o *OKGroup) GetAccountDepositHistory(currency string) (resp []GetAccountDe
|
||||
} else {
|
||||
requestURL = OKGroupGetAccountDepositHistory
|
||||
}
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupAccountSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupAccountSubsection, requestURL, nil, &resp, true)
|
||||
}
|
||||
|
||||
// GetSpotTradingAccounts retrieves the list of assets(only show pairs with balance larger than 0), the balances, amount available/on hold in spot accounts.
|
||||
func (o *OKGroup) GetSpotTradingAccounts() (resp []GetSpotTradingAccountResponse, _ error) {
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupTokenSubsection, OKGroupAccounts, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupTokenSubsection, OKGroupAccounts, nil, &resp, true)
|
||||
}
|
||||
|
||||
// GetSpotTradingAccountForCurrency This endpoint supports getting the balance, amount available/on hold of a token in spot account.
|
||||
func (o *OKGroup) GetSpotTradingAccountForCurrency(currency string) (resp GetSpotTradingAccountResponse, _ error) {
|
||||
requestURL := fmt.Sprintf("%v/%v", OKGroupAccounts, currency)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupTokenSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupTokenSubsection, requestURL, nil, &resp, true)
|
||||
}
|
||||
|
||||
// GetSpotBillDetailsForCurrency This endpoint supports getting the balance, amount available/on hold of a token in spot account.
|
||||
func (o *OKGroup) GetSpotBillDetailsForCurrency(request GetSpotBillDetailsForCurrencyRequest) (resp []GetSpotBillDetailsForCurrencyResponse, _ error) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v%v", OKGroupAccounts, request.Currency, OKGroupLedger, FormatParameters(request))
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupTokenSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupTokenSubsection, requestURL, nil, &resp, true)
|
||||
}
|
||||
|
||||
// PlaceSpotOrder token trading only supports limit and market orders (more order types will become available in the future).
|
||||
@@ -203,7 +203,7 @@ func (o *OKGroup) PlaceSpotOrder(request *PlaceOrderRequest) (resp PlaceOrderRes
|
||||
if request.OrderType == "" {
|
||||
request.OrderType = strconv.Itoa(NormalOrder)
|
||||
}
|
||||
return resp, o.SendHTTPRequest(http.MethodPost, okGroupTokenSubsection, OKGroupOrders, request, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodPost, okGroupTokenSubsection, OKGroupOrders, request, &resp, true)
|
||||
}
|
||||
|
||||
// PlaceMultipleSpotOrders supports placing multiple orders for specific trading pairs
|
||||
@@ -228,7 +228,7 @@ func (o *OKGroup) PlaceMultipleSpotOrders(request []PlaceOrderRequest) (map[stri
|
||||
}
|
||||
}
|
||||
|
||||
err := o.SendHTTPRequest(http.MethodPost, okGroupTokenSubsection, OKGroupBatchOrders, request, &resp, true)
|
||||
err := o.SendHTTPRequest(exchange.RestSpot, http.MethodPost, okGroupTokenSubsection, OKGroupBatchOrders, request, &resp, true)
|
||||
if err != nil {
|
||||
return resp, []error{err}
|
||||
}
|
||||
@@ -248,7 +248,7 @@ func (o *OKGroup) PlaceMultipleSpotOrders(request []PlaceOrderRequest) (map[stri
|
||||
// CancelSpotOrder Cancelling an unfilled order.
|
||||
func (o *OKGroup) CancelSpotOrder(request CancelSpotOrderRequest) (resp CancelSpotOrderResponse, _ error) {
|
||||
requestURL := fmt.Sprintf("%v/%v", OKGroupCancelOrders, request.OrderID)
|
||||
return resp, o.SendHTTPRequest(http.MethodPost, okGroupTokenSubsection, requestURL, request, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodPost, okGroupTokenSubsection, requestURL, request, &resp, true)
|
||||
}
|
||||
|
||||
// CancelMultipleSpotOrders Cancelling multiple unfilled orders.
|
||||
@@ -258,7 +258,7 @@ func (o *OKGroup) CancelMultipleSpotOrders(request CancelMultipleSpotOrdersReque
|
||||
return resp, errors.New("maximum 4 order cancellations for each pair")
|
||||
}
|
||||
|
||||
err = o.SendHTTPRequest(http.MethodPost, okGroupTokenSubsection, OKGroupCancelBatchOrders, []CancelMultipleSpotOrdersRequest{request}, &resp, true)
|
||||
err = o.SendHTTPRequest(exchange.RestSpot, http.MethodPost, okGroupTokenSubsection, OKGroupCancelBatchOrders, []CancelMultipleSpotOrdersRequest{request}, &resp, true)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -286,33 +286,33 @@ func (o *OKGroup) CancelMultipleSpotOrders(request CancelMultipleSpotOrdersReque
|
||||
// All paginated requests return the latest information (newest) as the first page sorted by newest (in chronological time) first.
|
||||
func (o *OKGroup) GetSpotOrders(request GetSpotOrdersRequest) (resp []GetSpotOrderResponse, _ error) {
|
||||
requestURL := fmt.Sprintf("%v%v", OKGroupOrders, FormatParameters(request))
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupTokenSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupTokenSubsection, requestURL, nil, &resp, true)
|
||||
}
|
||||
|
||||
// GetSpotOpenOrders List all your current open 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 *OKGroup) GetSpotOpenOrders(request GetSpotOpenOrdersRequest) (resp []GetSpotOrderResponse, _ error) {
|
||||
requestURL := fmt.Sprintf("%v%v", OKGroupPendingOrders, FormatParameters(request))
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupTokenSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupTokenSubsection, requestURL, nil, &resp, true)
|
||||
}
|
||||
|
||||
// GetSpotOrder Get order details by order ID.
|
||||
func (o *OKGroup) GetSpotOrder(request GetSpotOrderRequest) (resp GetSpotOrderResponse, _ error) {
|
||||
requestURL := fmt.Sprintf("%v/%v%v", OKGroupOrders, request.OrderID, FormatParameters(request))
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupTokenSubsection, requestURL, request, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupTokenSubsection, requestURL, request, &resp, true)
|
||||
}
|
||||
|
||||
// GetSpotTransactionDetails 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 *OKGroup) GetSpotTransactionDetails(request GetSpotTransactionDetailsRequest) (resp []GetSpotTransactionDetailsResponse, _ error) {
|
||||
requestURL := fmt.Sprintf("%v%v", OKGroupGetSpotTransactionDetails, FormatParameters(request))
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupTokenSubsection, requestURL, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupTokenSubsection, requestURL, nil, &resp, false)
|
||||
}
|
||||
|
||||
// GetSpotTokenPairDetails Get market data. This endpoint provides the snapshots of market data and can be used without verifications.
|
||||
// List trading pairs and get the trading limit, price, and more information of different trading pairs.
|
||||
func (o *OKGroup) GetSpotTokenPairDetails() (resp []GetSpotTokenPairDetailsResponse, _ error) {
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupTokenSubsection, OKGroupInstruments, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupTokenSubsection, OKGroupInstruments, nil, &resp, false)
|
||||
}
|
||||
|
||||
// GetOrderBook Getting the order book of a trading pair. Pagination is not
|
||||
@@ -333,12 +333,12 @@ func (o *OKGroup) GetOrderBook(request GetOrderBookRequest, a asset.Item) (resp
|
||||
default:
|
||||
return resp, errors.New("unhandled asset type")
|
||||
}
|
||||
requestURL := fmt.Sprintf("%v/%v/%v/%v",
|
||||
requestURL := fmt.Sprintf("%v/%v/%v%v",
|
||||
OKGroupInstruments,
|
||||
request.InstrumentID,
|
||||
endpoint,
|
||||
FormatParameters(request))
|
||||
return resp, o.SendHTTPRequest(http.MethodGet,
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
requestType,
|
||||
requestURL,
|
||||
nil,
|
||||
@@ -349,20 +349,20 @@ func (o *OKGroup) GetOrderBook(request GetOrderBookRequest, a asset.Item) (resp
|
||||
// GetSpotAllTokenPairsInformation Get the last traded price, best bid/ask price, 24 hour trading volume and more info of all trading pairs.
|
||||
func (o *OKGroup) GetSpotAllTokenPairsInformation() (resp []GetSpotTokenPairsInformationResponse, _ error) {
|
||||
requestURL := fmt.Sprintf("%v/%v", OKGroupInstruments, OKGroupTicker)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupTokenSubsection, requestURL, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupTokenSubsection, requestURL, nil, &resp, false)
|
||||
}
|
||||
|
||||
// GetSpotAllTokenPairsInformationForCurrency Get the last traded price, best bid/ask price, 24 hour trading volume and more info of a currency
|
||||
func (o *OKGroup) GetSpotAllTokenPairsInformationForCurrency(currency string) (resp GetSpotTokenPairsInformationResponse, _ error) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v", OKGroupInstruments, currency, OKGroupTicker)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupTokenSubsection, requestURL, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupTokenSubsection, requestURL, nil, &resp, false)
|
||||
}
|
||||
|
||||
// GetSpotFilledOrdersInformation Get the recent 60 transactions of all trading pairs.
|
||||
// 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 *OKGroup) GetSpotFilledOrdersInformation(request GetSpotFilledOrdersInformationRequest) (resp []GetSpotFilledOrdersInformationResponse, _ error) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v%v", OKGroupInstruments, request.InstrumentID, OKGroupTrades, FormatParameters(request))
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupTokenSubsection, requestURL, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupTokenSubsection, requestURL, nil, &resp, false)
|
||||
}
|
||||
|
||||
// GetMarketData Get the charts of the trading pairs. Charts are returned in grouped buckets based on requested granularity.
|
||||
@@ -379,18 +379,18 @@ func (o *OKGroup) GetMarketData(request *GetMarketDataRequest) (resp GetMarketDa
|
||||
default:
|
||||
return nil, errors.New("asset not supported")
|
||||
}
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, requestType, requestURL, nil, &resp, false)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, requestType, requestURL, nil, &resp, false)
|
||||
}
|
||||
|
||||
// GetMarginTradingAccounts List all assets under token margin trading account, including information such as balance, amount on hold and more.
|
||||
func (o *OKGroup) GetMarginTradingAccounts() (resp []GetMarginAccountsResponse, _ error) {
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupMarginTradingSubsection, OKGroupAccounts, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupMarginTradingSubsection, OKGroupAccounts, nil, &resp, true)
|
||||
}
|
||||
|
||||
// GetMarginTradingAccountsForCurrency Get the balance, amount on hold and more useful information.
|
||||
func (o *OKGroup) GetMarginTradingAccountsForCurrency(currency string) (resp GetMarginAccountsResponse, _ error) {
|
||||
requestURL := fmt.Sprintf("%v/%v", OKGroupAccounts, currency)
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupMarginTradingSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupMarginTradingSubsection, requestURL, nil, &resp, true)
|
||||
}
|
||||
|
||||
// GetMarginBillDetails List all bill details. Pagination is used here.
|
||||
@@ -398,7 +398,7 @@ func (o *OKGroup) GetMarginTradingAccountsForCurrency(currency string) (resp Get
|
||||
// Most paginated requests return the latest information (newest) as the first page sorted by newest (in chronological time) first.
|
||||
func (o *OKGroup) GetMarginBillDetails(request GetMarginBillDetailsRequest) (resp []GetSpotBillDetailsForCurrencyResponse, _ error) {
|
||||
requestURL := fmt.Sprintf("%v/%v/%v%v", OKGroupAccounts, request.InstrumentID, OKGroupLedger, FormatParameters(request))
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupMarginTradingSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupMarginTradingSubsection, requestURL, nil, &resp, true)
|
||||
}
|
||||
|
||||
// GetMarginAccountSettings Get all information of the margin trading account,
|
||||
@@ -410,7 +410,7 @@ func (o *OKGroup) GetMarginAccountSettings(currency string) (resp []GetMarginAcc
|
||||
} else {
|
||||
requestURL = fmt.Sprintf("%v/%v", OKGroupAccounts, okGroupGetMarketAvailability)
|
||||
}
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupMarginTradingSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupMarginTradingSubsection, requestURL, nil, &resp, true)
|
||||
}
|
||||
|
||||
// GetMarginLoanHistory Get loan history of the margin trading account.
|
||||
@@ -423,25 +423,25 @@ func (o *OKGroup) GetMarginLoanHistory(request GetMarginLoanHistoryRequest) (res
|
||||
} else {
|
||||
requestURL = fmt.Sprintf("%v/%v", OKGroupAccounts, okGroupGetLoan)
|
||||
}
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupMarginTradingSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupMarginTradingSubsection, requestURL, nil, &resp, true)
|
||||
}
|
||||
|
||||
// OpenMarginLoan Borrowing tokens in a margin trading account.
|
||||
func (o *OKGroup) OpenMarginLoan(request OpenMarginLoanRequest) (resp OpenMarginLoanResponse, _ error) {
|
||||
requestURL := fmt.Sprintf("%v/%v", OKGroupAccounts, okGroupGetLoan)
|
||||
return resp, o.SendHTTPRequest(http.MethodPost, okGroupMarginTradingSubsection, requestURL, request, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodPost, okGroupMarginTradingSubsection, requestURL, request, &resp, true)
|
||||
}
|
||||
|
||||
// RepayMarginLoan Repaying tokens in a margin trading account.
|
||||
func (o *OKGroup) RepayMarginLoan(request RepayMarginLoanRequest) (resp RepayMarginLoanResponse, _ error) {
|
||||
requestURL := fmt.Sprintf("%v/%v", OKGroupAccounts, okGroupGetRepayment)
|
||||
return resp, o.SendHTTPRequest(http.MethodPost, okGroupMarginTradingSubsection, requestURL, request, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodPost, okGroupMarginTradingSubsection, requestURL, request, &resp, true)
|
||||
}
|
||||
|
||||
// PlaceMarginOrder OKEx API only supports limit and market orders (more orders will become available in the future).
|
||||
// You can place an order only if you have enough funds. Once your order is placed, the amount will be put on hold.
|
||||
func (o *OKGroup) PlaceMarginOrder(request *PlaceOrderRequest) (resp PlaceOrderResponse, _ error) {
|
||||
return resp, o.SendHTTPRequest(http.MethodPost, okGroupMarginTradingSubsection, OKGroupOrders, request, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodPost, okGroupMarginTradingSubsection, OKGroupOrders, request, &resp, true)
|
||||
}
|
||||
|
||||
// PlaceMultipleMarginOrders Place multiple orders for specific trading pairs (up to 4 trading pairs, maximum 4 orders each)
|
||||
@@ -460,7 +460,7 @@ func (o *OKGroup) PlaceMultipleMarginOrders(request []PlaceOrderRequest) (map[st
|
||||
}
|
||||
}
|
||||
|
||||
err := o.SendHTTPRequest(http.MethodPost, okGroupMarginTradingSubsection, OKGroupBatchOrders, request, &resp, true)
|
||||
err := o.SendHTTPRequest(exchange.RestSpot, http.MethodPost, okGroupMarginTradingSubsection, OKGroupBatchOrders, request, &resp, true)
|
||||
if err != nil {
|
||||
return resp, []error{err}
|
||||
}
|
||||
@@ -480,7 +480,7 @@ func (o *OKGroup) PlaceMultipleMarginOrders(request []PlaceOrderRequest) (map[st
|
||||
// CancelMarginOrder Cancelling an unfilled order.
|
||||
func (o *OKGroup) CancelMarginOrder(request CancelSpotOrderRequest) (resp CancelSpotOrderResponse, _ error) {
|
||||
requestURL := fmt.Sprintf("%v/%v", OKGroupCancelOrders, request.OrderID)
|
||||
return resp, o.SendHTTPRequest(http.MethodPost, okGroupMarginTradingSubsection, requestURL, request, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodPost, okGroupMarginTradingSubsection, requestURL, request, &resp, true)
|
||||
}
|
||||
|
||||
// CancelMultipleMarginOrders Cancelling multiple unfilled orders.
|
||||
@@ -490,7 +490,7 @@ func (o *OKGroup) CancelMultipleMarginOrders(request CancelMultipleSpotOrdersReq
|
||||
return resp, []error{errors.New("maximum 4 order cancellations for each pair")}
|
||||
}
|
||||
|
||||
err := o.SendHTTPRequest(http.MethodPost, okGroupMarginTradingSubsection, OKGroupCancelBatchOrders, []CancelMultipleSpotOrdersRequest{request}, &resp, true)
|
||||
err := o.SendHTTPRequest(exchange.RestSpot, http.MethodPost, okGroupMarginTradingSubsection, OKGroupCancelBatchOrders, []CancelMultipleSpotOrdersRequest{request}, &resp, true)
|
||||
if err != nil {
|
||||
return resp, []error{err}
|
||||
}
|
||||
@@ -510,26 +510,26 @@ func (o *OKGroup) CancelMultipleMarginOrders(request CancelMultipleSpotOrdersReq
|
||||
// GetMarginOrders 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 *OKGroup) GetMarginOrders(request GetSpotOrdersRequest) (resp []GetSpotOrderResponse, _ error) {
|
||||
requestURL := fmt.Sprintf("%v%v", OKGroupOrders, FormatParameters(request))
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupMarginTradingSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupMarginTradingSubsection, requestURL, nil, &resp, true)
|
||||
}
|
||||
|
||||
// GetMarginOpenOrders List all your current open 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 *OKGroup) GetMarginOpenOrders(request GetSpotOpenOrdersRequest) (resp []GetSpotOrderResponse, _ error) {
|
||||
requestURL := fmt.Sprintf("%v%v", OKGroupPendingOrders, FormatParameters(request))
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupMarginTradingSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupMarginTradingSubsection, requestURL, nil, &resp, true)
|
||||
}
|
||||
|
||||
// GetMarginOrder Get order details by order ID.
|
||||
func (o *OKGroup) GetMarginOrder(request GetSpotOrderRequest) (resp GetSpotOrderResponse, _ error) {
|
||||
requestURL := fmt.Sprintf("%v/%v%v", OKGroupOrders, request.OrderID, FormatParameters(request))
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupMarginTradingSubsection, requestURL, request, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupMarginTradingSubsection, requestURL, request, &resp, true)
|
||||
}
|
||||
|
||||
// GetMarginTransactionDetails 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 *OKGroup) GetMarginTransactionDetails(request GetSpotTransactionDetailsRequest) (resp []GetSpotTransactionDetailsResponse, _ error) {
|
||||
requestURL := fmt.Sprintf("%v%v", OKGroupGetSpotTransactionDetails, FormatParameters(request))
|
||||
return resp, o.SendHTTPRequest(http.MethodGet, okGroupMarginTradingSubsection, requestURL, nil, &resp, true)
|
||||
return resp, o.SendHTTPRequest(exchange.RestSpot, http.MethodGet, okGroupMarginTradingSubsection, requestURL, nil, &resp, true)
|
||||
}
|
||||
|
||||
// FormatParameters Formats URL parameters, useful for optional parameters due to OKEX signature check
|
||||
@@ -568,12 +568,15 @@ func (o *OKGroup) GetErrorCode(code interface{}) error {
|
||||
// SendHTTPRequest sends an authenticated http request to a desired
|
||||
// path with a JSON payload (of present)
|
||||
// URL arguments must be in the request path and not as url.URL values
|
||||
func (o *OKGroup) SendHTTPRequest(httpMethod, requestType, requestPath string, data, result interface{}, authenticated bool) (err error) {
|
||||
func (o *OKGroup) SendHTTPRequest(ep exchange.URL, httpMethod, requestType, requestPath string, data, result interface{}, authenticated bool) (err error) {
|
||||
if authenticated && !o.AllowAuthenticatedRequest() {
|
||||
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet,
|
||||
o.Name)
|
||||
}
|
||||
|
||||
endpoint, err := o.API.Endpoints.GetURL(ep)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
now := time.Now()
|
||||
utcTime := now.UTC().Format(time.RFC3339)
|
||||
payload := []byte("")
|
||||
@@ -589,7 +592,7 @@ func (o *OKGroup) SendHTTPRequest(httpMethod, requestType, requestPath string, d
|
||||
}
|
||||
}
|
||||
|
||||
path := o.API.Endpoints.URL + requestType + o.APIVersion + requestPath
|
||||
path := endpoint + requestType + o.APIVersion + requestPath
|
||||
if o.Verbose {
|
||||
log.Debugf(log.ExchangeSys, "Sending %v request to %s \n", requestType, path)
|
||||
}
|
||||
|
||||
@@ -15,6 +15,74 @@ const (
|
||||
ImmediateOrCancelOrder
|
||||
)
|
||||
|
||||
// TradingPairData stores data about a trading pair
|
||||
type TradingPairData struct {
|
||||
BaseCurrency string `json:"base_currency"`
|
||||
InstrumentID string `json:"instrument_id"`
|
||||
MinSize float64 `json:"min_size,string"`
|
||||
QuoteCurrency string `json:"quote_currency"`
|
||||
SizeIncrement string `json:"size_increment"`
|
||||
TickSize float64 `json:"tick_size,string"`
|
||||
}
|
||||
|
||||
// SwapInstrumentsData stores instruments data for perpetual swap contracts
|
||||
type SwapInstrumentsData struct {
|
||||
InstrumentID string `json:"instrument_id"`
|
||||
UnderlyingIndex string `json:"underlying_index"`
|
||||
QuoteCurrency string `json:"quote_currency"`
|
||||
Coin string `json:"coin"`
|
||||
ContractValue float64 `json:"contract_val,string"`
|
||||
Listing string `json:"listing"`
|
||||
Delivery string `json:"delivery"`
|
||||
SizeIncrement float64 `json:"size_increment,string"`
|
||||
TickSize float64 `json:"tick_size,string"`
|
||||
BaseCurrency string `json:"base_currency"`
|
||||
Underlying string `json:"underlying"`
|
||||
SettlementCurrency string `json:"settlement_currency"`
|
||||
IsInverse bool `json:"is_inverse,string"`
|
||||
Category int64 `json:"category,string"`
|
||||
ContractValueCurrency string `json:"contract_val_currency"`
|
||||
}
|
||||
|
||||
// MarginData stores margin trading data for a currency
|
||||
type MarginData struct {
|
||||
Available float64 `json:"available,string"`
|
||||
Leverage float64 `json:"leverage,string"`
|
||||
LeverageRatio float64 `json:"leverage_ratio,string"`
|
||||
Rate float64 `json:"rate,string"`
|
||||
}
|
||||
|
||||
// MarginCurrencyData stores currency data for margin trading
|
||||
type MarginCurrencyData struct {
|
||||
Data map[string]MarginData
|
||||
InstrumentID string `json:"instrument_id"`
|
||||
ProductID string `json:"product_id"`
|
||||
}
|
||||
|
||||
// TickerData stores ticker data
|
||||
type TickerData struct {
|
||||
InstrumentID string `json:"instrument_id"`
|
||||
BestAsk float64 `json:"best_ask,string"`
|
||||
BestBid float64 `json:"best_bid,string"`
|
||||
Last float64 `json:"last,string"`
|
||||
High24H float64 `json:"high_24h,string"`
|
||||
Low24H float64 `json:"low_24h,string"`
|
||||
Volume24H float64 `json:"volume_24h,string"`
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
LastQty float64 `json:"last_qty,string"`
|
||||
BestAskSize float64 `json:"best_ask_size,string"`
|
||||
BestBidSize float64 `json:"best_bid_size,string"`
|
||||
}
|
||||
|
||||
// PerpSwapFundingRates stores funding rates data
|
||||
type PerpSwapFundingRates struct {
|
||||
InstrumentID string `json:"instrument_id"`
|
||||
FundingRate float64 `json:"funding_rate,string"`
|
||||
RealizedRate float64 `json:"realized_rate,string"`
|
||||
InterestRate float64 `json:"interest_rate,string"`
|
||||
FundingTime time.Time `json:"funding_time"`
|
||||
}
|
||||
|
||||
// GetAccountCurrenciesResponse response data for GetAccountCurrencies
|
||||
type GetAccountCurrenciesResponse struct {
|
||||
Name string `json:"name"`
|
||||
|
||||
@@ -36,14 +36,18 @@ func (o *OKGroup) Setup(exch *config.ExchangeConfig) error {
|
||||
return err
|
||||
}
|
||||
|
||||
wsEndpoint, err := o.API.Endpoints.GetURL(exchange.WebsocketSpot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = o.Websocket.Setup(&stream.WebsocketSetup{
|
||||
Enabled: exch.Features.Enabled.Websocket,
|
||||
Verbose: exch.Verbose,
|
||||
AuthenticatedWebsocketAPISupport: exch.API.AuthenticatedWebsocketSupport,
|
||||
WebsocketTimeout: exch.WebsocketTrafficTimeout,
|
||||
DefaultURL: o.API.Endpoints.WebsocketURL,
|
||||
DefaultURL: wsEndpoint,
|
||||
ExchangeName: exch.Name,
|
||||
RunningURL: exch.API.Endpoints.WebsocketURL,
|
||||
RunningURL: wsEndpoint,
|
||||
Connector: o.WsConnect,
|
||||
Subscriber: o.Subscribe,
|
||||
UnSubscriber: o.Unsubscribe,
|
||||
@@ -96,6 +100,7 @@ func (o *OKGroup) UpdateOrderbook(p currency.Pair, a asset.Item) (*orderbook.Bas
|
||||
|
||||
orderbookNew, err := o.GetOrderBook(GetOrderBookRequest{
|
||||
InstrumentID: fPair.String(),
|
||||
Size: 200,
|
||||
}, a)
|
||||
if err != nil {
|
||||
return book, err
|
||||
@@ -174,7 +179,7 @@ func (o *OKGroup) UpdateOrderbook(p currency.Pair, a asset.Item) (*orderbook.Bas
|
||||
}
|
||||
|
||||
// UpdateAccountInfo retrieves balances for all enabled currencies
|
||||
func (o *OKGroup) UpdateAccountInfo() (account.Holdings, error) {
|
||||
func (o *OKGroup) UpdateAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
currencies, err := o.GetSpotTradingAccounts()
|
||||
if err != nil {
|
||||
return account.Holdings{}, err
|
||||
@@ -212,10 +217,10 @@ func (o *OKGroup) UpdateAccountInfo() (account.Holdings, error) {
|
||||
}
|
||||
|
||||
// FetchAccountInfo retrieves balances for all enabled currencies
|
||||
func (o *OKGroup) FetchAccountInfo() (account.Holdings, error) {
|
||||
acc, err := account.GetHoldings(o.Name)
|
||||
func (o *OKGroup) FetchAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
acc, err := account.GetHoldings(o.Name, assetType)
|
||||
if err != nil {
|
||||
return o.UpdateAccountInfo()
|
||||
return o.UpdateAccountInfo(assetType)
|
||||
}
|
||||
|
||||
return acc, nil
|
||||
@@ -569,8 +574,8 @@ func (o *OKGroup) AuthenticateWebsocket() error {
|
||||
|
||||
// ValidateCredentials validates current credentials used for wrapper
|
||||
// functionality
|
||||
func (o *OKGroup) ValidateCredentials() error {
|
||||
_, err := o.UpdateAccountInfo()
|
||||
func (o *OKGroup) ValidateCredentials(assetType asset.Item) error {
|
||||
_, err := o.UpdateAccountInfo(assetType)
|
||||
return o.CheckTransientError(err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user