mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-06 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:
@@ -47,9 +47,9 @@ type Yobit struct {
|
||||
// GetInfo returns the Yobit info
|
||||
func (y *Yobit) GetInfo() (Info, error) {
|
||||
resp := Info{}
|
||||
path := fmt.Sprintf("%s/%s/%s/", y.API.Endpoints.URL, apiPublicVersion, publicInfo)
|
||||
path := fmt.Sprintf("/%s/%s/", apiPublicVersion, publicInfo)
|
||||
|
||||
return resp, y.SendHTTPRequest(path, &resp)
|
||||
return resp, y.SendHTTPRequest(exchange.RestSpot, path, &resp)
|
||||
}
|
||||
|
||||
// GetTicker returns a ticker for a specific currency
|
||||
@@ -59,9 +59,9 @@ func (y *Yobit) GetTicker(symbol string) (map[string]Ticker, error) {
|
||||
}
|
||||
|
||||
response := Response{}
|
||||
path := fmt.Sprintf("%s/%s/%s/%s", y.API.Endpoints.URL, apiPublicVersion, publicTicker, symbol)
|
||||
path := fmt.Sprintf("/%s/%s/%s", apiPublicVersion, publicTicker, symbol)
|
||||
|
||||
return response.Data, y.SendHTTPRequest(path, &response.Data)
|
||||
return response.Data, y.SendHTTPRequest(exchange.RestSpot, path, &response.Data)
|
||||
}
|
||||
|
||||
// GetDepth returns the depth for a specific currency
|
||||
@@ -71,10 +71,10 @@ func (y *Yobit) GetDepth(symbol string) (Orderbook, error) {
|
||||
}
|
||||
|
||||
response := Response{}
|
||||
path := fmt.Sprintf("%s/%s/%s/%s", y.API.Endpoints.URL, apiPublicVersion, publicDepth, symbol)
|
||||
path := fmt.Sprintf("/%s/%s/%s", apiPublicVersion, publicDepth, symbol)
|
||||
|
||||
return response.Data[symbol],
|
||||
y.SendHTTPRequest(path, &response.Data)
|
||||
y.SendHTTPRequest(exchange.RestSpot, path, &response.Data)
|
||||
}
|
||||
|
||||
// GetTrades returns the trades for a specific currency
|
||||
@@ -84,8 +84,8 @@ func (y *Yobit) GetTrades(symbol string) ([]Trade, error) {
|
||||
}
|
||||
|
||||
var dataHolder respDataHolder
|
||||
path := y.API.Endpoints.URL + "/" + apiPublicVersion + "/" + publicTrades + "/" + symbol
|
||||
err := y.SendHTTPRequest(path, &dataHolder.Data)
|
||||
path := "/" + apiPublicVersion + "/" + publicTrades + "/" + symbol
|
||||
err := y.SendHTTPRequest(exchange.RestSpot, path, &dataHolder.Data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -100,7 +100,7 @@ func (y *Yobit) GetTrades(symbol string) ([]Trade, error) {
|
||||
func (y *Yobit) GetAccountInformation() (AccountInfo, error) {
|
||||
result := AccountInfo{}
|
||||
|
||||
err := y.SendAuthenticatedHTTPRequest(privateAccountInfo, url.Values{}, &result)
|
||||
err := y.SendAuthenticatedHTTPRequest(exchange.RestSpotSupplementary, privateAccountInfo, url.Values{}, &result)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
@@ -120,7 +120,7 @@ func (y *Yobit) Trade(pair, orderType string, amount, price float64) (int64, err
|
||||
|
||||
result := TradeOrderResponse{}
|
||||
|
||||
err := y.SendAuthenticatedHTTPRequest(privateTrade, req, &result)
|
||||
err := y.SendAuthenticatedHTTPRequest(exchange.RestSpotSupplementary, privateTrade, req, &result)
|
||||
if err != nil {
|
||||
return int64(result.OrderID), err
|
||||
}
|
||||
@@ -137,7 +137,7 @@ func (y *Yobit) GetOpenOrders(pair string) (map[string]ActiveOrders, error) {
|
||||
|
||||
result := map[string]ActiveOrders{}
|
||||
|
||||
return result, y.SendAuthenticatedHTTPRequest(privateActiveOrders, req, &result)
|
||||
return result, y.SendAuthenticatedHTTPRequest(exchange.RestSpotSupplementary, privateActiveOrders, req, &result)
|
||||
}
|
||||
|
||||
// GetOrderInformation returns the order info for a specific order ID
|
||||
@@ -147,7 +147,7 @@ func (y *Yobit) GetOrderInformation(orderID int64) (map[string]OrderInfo, error)
|
||||
|
||||
result := map[string]OrderInfo{}
|
||||
|
||||
return result, y.SendAuthenticatedHTTPRequest(privateOrderInfo, req, &result)
|
||||
return result, y.SendAuthenticatedHTTPRequest(exchange.RestSpotSupplementary, privateOrderInfo, req, &result)
|
||||
}
|
||||
|
||||
// CancelExistingOrder cancels an order for a specific order ID
|
||||
@@ -157,7 +157,7 @@ func (y *Yobit) CancelExistingOrder(orderID int64) error {
|
||||
|
||||
result := CancelOrder{}
|
||||
|
||||
err := y.SendAuthenticatedHTTPRequest(privateCancelOrder, req, &result)
|
||||
err := y.SendAuthenticatedHTTPRequest(exchange.RestSpotSupplementary, privateCancelOrder, req, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -181,7 +181,7 @@ func (y *Yobit) GetTradeHistory(tidFrom, count, tidEnd, since, end int64, order,
|
||||
|
||||
result := TradeHistoryResponse{}
|
||||
|
||||
err := y.SendAuthenticatedHTTPRequest(privateTradeHistory, req, &result)
|
||||
err := y.SendAuthenticatedHTTPRequest(exchange.RestSpotSupplementary, privateTradeHistory, req, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -199,7 +199,7 @@ func (y *Yobit) GetCryptoDepositAddress(coin string) (DepositAddress, error) {
|
||||
|
||||
result := DepositAddress{}
|
||||
|
||||
err := y.SendAuthenticatedHTTPRequest(privateGetDepositAddress, req, &result)
|
||||
err := y.SendAuthenticatedHTTPRequest(exchange.RestSpotSupplementary, privateGetDepositAddress, req, &result)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
@@ -218,7 +218,7 @@ func (y *Yobit) WithdrawCoinsToAddress(coin string, amount float64, address stri
|
||||
|
||||
result := WithdrawCoinsToAddress{}
|
||||
|
||||
err := y.SendAuthenticatedHTTPRequest(privateWithdrawCoinsToAddress, req, &result)
|
||||
err := y.SendAuthenticatedHTTPRequest(exchange.RestSpotSupplementary, privateWithdrawCoinsToAddress, req, &result)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
@@ -236,7 +236,7 @@ func (y *Yobit) CreateCoupon(currency string, amount float64) (CreateCoupon, err
|
||||
|
||||
var result CreateCoupon
|
||||
|
||||
err := y.SendAuthenticatedHTTPRequest(privateCreateCoupon, req, &result)
|
||||
err := y.SendAuthenticatedHTTPRequest(exchange.RestSpotSupplementary, privateCreateCoupon, req, &result)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
@@ -253,7 +253,7 @@ func (y *Yobit) RedeemCoupon(coupon string) (RedeemCoupon, error) {
|
||||
|
||||
result := RedeemCoupon{}
|
||||
|
||||
err := y.SendAuthenticatedHTTPRequest(privateRedeemCoupon, req, &result)
|
||||
err := y.SendAuthenticatedHTTPRequest(exchange.RestSpotSupplementary, privateRedeemCoupon, req, &result)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
@@ -264,10 +264,14 @@ func (y *Yobit) RedeemCoupon(coupon string) (RedeemCoupon, error) {
|
||||
}
|
||||
|
||||
// SendHTTPRequest sends an unauthenticated HTTP request
|
||||
func (y *Yobit) SendHTTPRequest(path string, result interface{}) error {
|
||||
func (y *Yobit) SendHTTPRequest(ep exchange.URL, path string, result interface{}) error {
|
||||
endpoint, err := y.API.Endpoints.GetURL(ep)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return y.SendPayload(context.Background(), &request.Item{
|
||||
Method: http.MethodGet,
|
||||
Path: path,
|
||||
Path: endpoint + path,
|
||||
Result: result,
|
||||
Verbose: y.Verbose,
|
||||
HTTPDebugging: y.HTTPDebugging,
|
||||
@@ -276,11 +280,14 @@ func (y *Yobit) SendHTTPRequest(path string, result interface{}) error {
|
||||
}
|
||||
|
||||
// SendAuthenticatedHTTPRequest sends an authenticated HTTP request to Yobit
|
||||
func (y *Yobit) SendAuthenticatedHTTPRequest(path string, params url.Values, result interface{}) (err error) {
|
||||
func (y *Yobit) SendAuthenticatedHTTPRequest(ep exchange.URL, path string, params url.Values, result interface{}) (err error) {
|
||||
if !y.AllowAuthenticatedRequest() {
|
||||
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet, y.Name)
|
||||
}
|
||||
|
||||
endpoint, err := y.API.Endpoints.GetURL(ep)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if params == nil {
|
||||
params = url.Values{}
|
||||
}
|
||||
@@ -295,7 +302,7 @@ func (y *Yobit) SendAuthenticatedHTTPRequest(path string, params url.Values, res
|
||||
|
||||
if y.Verbose {
|
||||
log.Debugf(log.ExchangeSys, "Sending POST request to %s calling path %s with params %s\n",
|
||||
apiPrivateURL,
|
||||
endpoint,
|
||||
path,
|
||||
encoded)
|
||||
}
|
||||
@@ -307,7 +314,7 @@ func (y *Yobit) SendAuthenticatedHTTPRequest(path string, params url.Values, res
|
||||
|
||||
return y.SendPayload(context.Background(), &request.Item{
|
||||
Method: http.MethodPost,
|
||||
Path: apiPrivateURL,
|
||||
Path: endpoint,
|
||||
Headers: headers,
|
||||
Body: strings.NewReader(encoded),
|
||||
Result: result,
|
||||
|
||||
@@ -91,7 +91,7 @@ func TestGetTrades(t *testing.T) {
|
||||
|
||||
func TestGetAccountInfo(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := y.UpdateAccountInfo()
|
||||
_, err := y.UpdateAccountInfo(asset.Spot)
|
||||
if err == nil {
|
||||
t.Error("GetAccountInfo() Expected error")
|
||||
}
|
||||
@@ -330,6 +330,7 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
Type: order.AnyType,
|
||||
Pairs: []currency.Pair{currency.NewPair(currency.LTC,
|
||||
currency.BTC)},
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
_, err := y.GetActiveOrders(&getOrdersRequest)
|
||||
@@ -342,7 +343,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
|
||||
func TestGetOrderHistory(t *testing.T) {
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
Type: order.AnyType,
|
||||
Type: order.AnyType,
|
||||
AssetType: asset.Spot,
|
||||
Pairs: []currency.Pair{currency.NewPair(currency.LTC,
|
||||
currency.BTC)},
|
||||
StartTicks: time.Unix(0, 0),
|
||||
|
||||
@@ -98,11 +98,14 @@ func (y *Yobit) SetDefaults() {
|
||||
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout),
|
||||
// Server responses are cached every 2 seconds.
|
||||
request.WithLimiter(request.NewBasicRateLimit(time.Second, 1)))
|
||||
|
||||
y.API.Endpoints.URLDefault = apiPublicURL
|
||||
y.API.Endpoints.URL = y.API.Endpoints.URLDefault
|
||||
y.API.Endpoints.URLSecondaryDefault = apiPrivateURL
|
||||
y.API.Endpoints.URLSecondary = y.API.Endpoints.URLSecondaryDefault
|
||||
y.API.Endpoints = y.NewEndpoints()
|
||||
err = y.API.Endpoints.SetDefaultEndpoints(map[exchange.URL]string{
|
||||
exchange.RestSpot: apiPublicURL,
|
||||
exchange.RestSpotSupplementary: apiPrivateURL,
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorln(log.ExchangeSys, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Setup sets exchange configuration parameters for Yobit
|
||||
@@ -275,7 +278,7 @@ func (y *Yobit) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orderbo
|
||||
|
||||
// UpdateAccountInfo retrieves balances for all enabled currencies for the
|
||||
// Yobit exchange
|
||||
func (y *Yobit) UpdateAccountInfo() (account.Holdings, error) {
|
||||
func (y *Yobit) UpdateAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
var response account.Holdings
|
||||
response.Exchange = y.Name
|
||||
accountBalance, err := y.GetAccountInformation()
|
||||
@@ -311,10 +314,10 @@ func (y *Yobit) UpdateAccountInfo() (account.Holdings, error) {
|
||||
}
|
||||
|
||||
// FetchAccountInfo retrieves balances for all enabled currencies
|
||||
func (y *Yobit) FetchAccountInfo() (account.Holdings, error) {
|
||||
acc, err := account.GetHoldings(y.Name)
|
||||
func (y *Yobit) FetchAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
acc, err := account.GetHoldings(y.Name, assetType)
|
||||
if err != nil {
|
||||
return y.UpdateAccountInfo()
|
||||
return y.UpdateAccountInfo(assetType)
|
||||
}
|
||||
|
||||
return acc, nil
|
||||
@@ -640,8 +643,8 @@ func (y *Yobit) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, er
|
||||
|
||||
// ValidateCredentials validates current credentials used for wrapper
|
||||
// functionality
|
||||
func (y *Yobit) ValidateCredentials() error {
|
||||
_, err := y.UpdateAccountInfo()
|
||||
func (y *Yobit) ValidateCredentials(assetType asset.Item) error {
|
||||
_, err := y.UpdateAccountInfo(assetType)
|
||||
return y.CheckTransientError(err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user