mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-24 07:26:47 +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:
@@ -43,18 +43,18 @@ type ItBit struct {
|
||||
// currencyPair - example "XBTUSD" "XBTSGD" "XBTEUR"
|
||||
func (i *ItBit) GetTicker(currencyPair string) (Ticker, error) {
|
||||
var response Ticker
|
||||
path := fmt.Sprintf("%s/%s/%s/%s", i.API.Endpoints.URL, itbitMarkets, currencyPair, itbitTicker)
|
||||
path := fmt.Sprintf("/%s/%s/%s", itbitMarkets, currencyPair, itbitTicker)
|
||||
|
||||
return response, i.SendHTTPRequest(path, &response)
|
||||
return response, i.SendHTTPRequest(exchange.RestSpot, path, &response)
|
||||
}
|
||||
|
||||
// GetOrderbook returns full order book for the specified market.
|
||||
// currencyPair - example "XBTUSD" "XBTSGD" "XBTEUR"
|
||||
func (i *ItBit) GetOrderbook(currencyPair string) (OrderbookResponse, error) {
|
||||
response := OrderbookResponse{}
|
||||
path := fmt.Sprintf("%s/%s/%s/%s", i.API.Endpoints.URL, itbitMarkets, currencyPair, itbitOrderbook)
|
||||
path := fmt.Sprintf("/%s/%s/%s", itbitMarkets, currencyPair, itbitOrderbook)
|
||||
|
||||
return response, i.SendHTTPRequest(path, &response)
|
||||
return response, i.SendHTTPRequest(exchange.RestSpot, path, &response)
|
||||
}
|
||||
|
||||
// GetTradeHistory returns recent trades for a specified market.
|
||||
@@ -68,9 +68,9 @@ func (i *ItBit) GetTradeHistory(currencyPair, tradeID string) (Trades, error) {
|
||||
if tradeID != "" {
|
||||
req += "?since=" + tradeID
|
||||
}
|
||||
path := fmt.Sprintf("%s/%s/%s/%s", i.API.Endpoints.URL, itbitMarkets, currencyPair, req)
|
||||
path := fmt.Sprintf("/%s/%s/%s", itbitMarkets, currencyPair, req)
|
||||
|
||||
return response, i.SendHTTPRequest(path, &response)
|
||||
return response, i.SendHTTPRequest(exchange.RestSpot, path, &response)
|
||||
}
|
||||
|
||||
// GetWallets returns information about all wallets associated with the account.
|
||||
@@ -82,7 +82,7 @@ func (i *ItBit) GetWallets(params url.Values) ([]Wallet, error) {
|
||||
var resp []Wallet
|
||||
params.Set("userId", i.API.Credentials.ClientID)
|
||||
path := fmt.Sprintf("/%s?%s", itbitWallets, params.Encode())
|
||||
return resp, i.SendAuthenticatedHTTPRequest(http.MethodGet, path, nil, &resp)
|
||||
return resp, i.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, path, nil, &resp)
|
||||
}
|
||||
|
||||
// CreateWallet creates a new wallet with a specified name.
|
||||
@@ -92,7 +92,7 @@ func (i *ItBit) CreateWallet(walletName string) (Wallet, error) {
|
||||
params["userId"] = i.API.Credentials.ClientID
|
||||
params["name"] = walletName
|
||||
|
||||
err := i.SendAuthenticatedHTTPRequest(http.MethodPost, "/"+itbitWallets, params, &resp)
|
||||
err := i.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, "/"+itbitWallets, params, &resp)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -107,7 +107,7 @@ func (i *ItBit) GetWallet(walletID string) (Wallet, error) {
|
||||
resp := Wallet{}
|
||||
path := fmt.Sprintf("/%s/%s", itbitWallets, walletID)
|
||||
|
||||
err := i.SendAuthenticatedHTTPRequest(http.MethodGet, path, nil, &resp)
|
||||
err := i.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, path, nil, &resp)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -123,7 +123,7 @@ func (i *ItBit) GetWalletBalance(walletID, currency string) (Balance, error) {
|
||||
resp := Balance{}
|
||||
path := fmt.Sprintf("/%s/%s/%s/%s", itbitWallets, walletID, itbitBalances, currency)
|
||||
|
||||
err := i.SendAuthenticatedHTTPRequest(http.MethodGet, path, nil, &resp)
|
||||
err := i.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, path, nil, &resp)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -153,7 +153,7 @@ func (i *ItBit) GetOrders(walletID, symbol, status string, page, perPage int64)
|
||||
params["perPage"] = strconv.FormatInt(perPage, 10)
|
||||
}
|
||||
|
||||
return resp, i.SendAuthenticatedHTTPRequest(http.MethodGet, itbitOrders, params, &resp)
|
||||
return resp, i.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, itbitOrders, params, &resp)
|
||||
}
|
||||
|
||||
// GetWalletTrades returns all trades for a specified wallet.
|
||||
@@ -162,7 +162,7 @@ func (i *ItBit) GetWalletTrades(walletID string, params url.Values) (Records, er
|
||||
urlPath := fmt.Sprintf("/%s/%s/%s", itbitWallets, walletID, itbitTrades)
|
||||
path := common.EncodeURLValues(urlPath, params)
|
||||
|
||||
err := i.SendAuthenticatedHTTPRequest(http.MethodGet, path, nil, &resp)
|
||||
err := i.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, path, nil, &resp)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -178,7 +178,7 @@ func (i *ItBit) GetFundingHistoryForWallet(walletID string, params url.Values) (
|
||||
urlPath := fmt.Sprintf("/%s/%s/%s", itbitWallets, walletID, itbitFundingHistory)
|
||||
path := common.EncodeURLValues(urlPath, params)
|
||||
|
||||
err := i.SendAuthenticatedHTTPRequest(http.MethodGet, path, nil, &resp)
|
||||
err := i.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, path, nil, &resp)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -205,7 +205,7 @@ func (i *ItBit) PlaceOrder(walletID, side, orderType, currency string, amount, p
|
||||
params["clientOrderIdentifier"] = clientRef
|
||||
}
|
||||
|
||||
err := i.SendAuthenticatedHTTPRequest(http.MethodPost, path, params, &resp)
|
||||
err := i.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, path, params, &resp)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -221,7 +221,7 @@ func (i *ItBit) GetOrder(walletID string, params url.Values) (Order, error) {
|
||||
urlPath := fmt.Sprintf("/%s/%s/%s", itbitWallets, walletID, itbitOrders)
|
||||
path := common.EncodeURLValues(urlPath, params)
|
||||
|
||||
err := i.SendAuthenticatedHTTPRequest(http.MethodGet, path, nil, &resp)
|
||||
err := i.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, path, nil, &resp)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -236,7 +236,7 @@ func (i *ItBit) GetOrder(walletID string, params url.Values) (Order, error) {
|
||||
func (i *ItBit) CancelExistingOrder(walletID, orderID string) error {
|
||||
path := fmt.Sprintf("/%s/%s/%s/%s", itbitWallets, walletID, itbitOrders, orderID)
|
||||
|
||||
return i.SendAuthenticatedHTTPRequest(http.MethodDelete, path, nil, nil)
|
||||
return i.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodDelete, path, nil, nil)
|
||||
}
|
||||
|
||||
// GetCryptoDepositAddress returns a deposit address to send cryptocurrency to.
|
||||
@@ -246,7 +246,7 @@ func (i *ItBit) GetCryptoDepositAddress(walletID, currency string) (CryptoCurren
|
||||
params := make(map[string]interface{})
|
||||
params["currency"] = currency
|
||||
|
||||
err := i.SendAuthenticatedHTTPRequest(http.MethodPost, path, params, &resp)
|
||||
err := i.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, path, params, &resp)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -267,7 +267,7 @@ func (i *ItBit) WalletTransfer(walletID, sourceWallet, destWallet string, amount
|
||||
params["amount"] = strconv.FormatFloat(amount, 'f', -1, 64)
|
||||
params["currencyCode"] = currency
|
||||
|
||||
err := i.SendAuthenticatedHTTPRequest(http.MethodPost, path, params, &resp)
|
||||
err := i.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, path, params, &resp)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
@@ -278,10 +278,14 @@ func (i *ItBit) WalletTransfer(walletID, sourceWallet, destWallet string, amount
|
||||
}
|
||||
|
||||
// SendHTTPRequest sends an unauthenticated HTTP request
|
||||
func (i *ItBit) SendHTTPRequest(path string, result interface{}) error {
|
||||
func (i *ItBit) SendHTTPRequest(ep exchange.URL, path string, result interface{}) error {
|
||||
endpoint, err := i.API.Endpoints.GetURL(ep)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return i.SendPayload(context.Background(), &request.Item{
|
||||
Method: http.MethodGet,
|
||||
Path: path,
|
||||
Path: endpoint + path,
|
||||
Result: result,
|
||||
Verbose: i.Verbose,
|
||||
HTTPDebugging: i.HTTPDebugging,
|
||||
@@ -290,20 +294,22 @@ func (i *ItBit) SendHTTPRequest(path string, result interface{}) error {
|
||||
}
|
||||
|
||||
// SendAuthenticatedHTTPRequest sends an authenticated request to itBit
|
||||
func (i *ItBit) SendAuthenticatedHTTPRequest(method, path string, params map[string]interface{}, result interface{}) error {
|
||||
func (i *ItBit) SendAuthenticatedHTTPRequest(ep exchange.URL, method, path string, params map[string]interface{}, result interface{}) error {
|
||||
if !i.AllowAuthenticatedRequest() {
|
||||
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet, i.Name)
|
||||
}
|
||||
|
||||
endpoint, err := i.API.Endpoints.GetURL(ep)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req := make(map[string]interface{})
|
||||
urlPath := i.API.Endpoints.URL + path
|
||||
urlPath := endpoint + path
|
||||
|
||||
for key, value := range params {
|
||||
req[key] = value
|
||||
}
|
||||
|
||||
PayloadJSON := []byte("")
|
||||
var err error
|
||||
|
||||
if params != nil {
|
||||
PayloadJSON, err = json.Marshal(req)
|
||||
|
||||
@@ -269,7 +269,8 @@ func TestFormatWithdrawPermissions(t *testing.T) {
|
||||
|
||||
func TestGetActiveOrders(t *testing.T) {
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
Type: order.AnyType,
|
||||
Type: order.AnyType,
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
_, err := i.GetActiveOrders(&getOrdersRequest)
|
||||
@@ -282,7 +283,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
|
||||
func TestGetOrderHistory(t *testing.T) {
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
Type: order.AnyType,
|
||||
Type: order.AnyType,
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
_, err := i.GetOrderHistory(&getOrdersRequest)
|
||||
@@ -378,7 +380,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
func TestGetAccountInfo(t *testing.T) {
|
||||
if areTestAPIKeysSet() {
|
||||
_, err := i.UpdateAccountInfo()
|
||||
_, err := i.UpdateAccountInfo(asset.Spot)
|
||||
if err == nil {
|
||||
t.Error("GetAccountInfo() Expected error")
|
||||
}
|
||||
|
||||
@@ -94,9 +94,13 @@ func (i *ItBit) SetDefaults() {
|
||||
|
||||
i.Requester = request.New(i.Name,
|
||||
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout))
|
||||
|
||||
i.API.Endpoints.URLDefault = itbitAPIURL
|
||||
i.API.Endpoints.URL = i.API.Endpoints.URLDefault
|
||||
i.API.Endpoints = i.NewEndpoints()
|
||||
err = i.API.Endpoints.SetDefaultEndpoints(map[exchange.URL]string{
|
||||
exchange.RestSpot: itbitAPIURL,
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorln(log.ExchangeSys, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Setup sets the exchange parameters from exchange config
|
||||
@@ -244,7 +248,7 @@ func (i *ItBit) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orderbo
|
||||
}
|
||||
|
||||
// UpdateAccountInfo retrieves balances for all enabled currencies
|
||||
func (i *ItBit) UpdateAccountInfo() (account.Holdings, error) {
|
||||
func (i *ItBit) UpdateAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
var info account.Holdings
|
||||
info.Exchange = i.Name
|
||||
|
||||
@@ -293,10 +297,10 @@ func (i *ItBit) UpdateAccountInfo() (account.Holdings, error) {
|
||||
}
|
||||
|
||||
// FetchAccountInfo retrieves balances for all enabled currencies
|
||||
func (i *ItBit) FetchAccountInfo() (account.Holdings, error) {
|
||||
acc, err := account.GetHoldings(i.Name)
|
||||
func (i *ItBit) FetchAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
acc, err := account.GetHoldings(i.Name, assetType)
|
||||
if err != nil {
|
||||
return i.UpdateAccountInfo()
|
||||
return i.UpdateAccountInfo(assetType)
|
||||
}
|
||||
|
||||
return acc, nil
|
||||
@@ -625,8 +629,8 @@ func (i *ItBit) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, er
|
||||
|
||||
// ValidateCredentials validates current credentials used for wrapper
|
||||
// functionality
|
||||
func (i *ItBit) ValidateCredentials() error {
|
||||
_, err := i.UpdateAccountInfo()
|
||||
func (i *ItBit) ValidateCredentials(assetType asset.Item) error {
|
||||
_, err := i.UpdateAccountInfo(assetType)
|
||||
return i.CheckTransientError(err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user