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:
@@ -63,20 +63,20 @@ type CoinbasePro struct {
|
||||
func (c *CoinbasePro) GetProducts() ([]Product, error) {
|
||||
var products []Product
|
||||
|
||||
return products, c.SendHTTPRequest(c.API.Endpoints.URL+coinbaseproProducts, &products)
|
||||
return products, c.SendHTTPRequest(exchange.RestSpot, coinbaseproProducts, &products)
|
||||
}
|
||||
|
||||
// GetOrderbook returns orderbook by currency pair and level
|
||||
func (c *CoinbasePro) GetOrderbook(symbol string, level int) (interface{}, error) {
|
||||
orderbook := OrderbookResponse{}
|
||||
|
||||
path := fmt.Sprintf("%s/%s/%s", c.API.Endpoints.URL+coinbaseproProducts, symbol, coinbaseproOrderbook)
|
||||
path := fmt.Sprintf("%s/%s/%s", coinbaseproProducts, symbol, coinbaseproOrderbook)
|
||||
if level > 0 {
|
||||
levelStr := strconv.Itoa(level)
|
||||
path = fmt.Sprintf("%s/%s/%s?level=%s", c.API.Endpoints.URL+coinbaseproProducts, symbol, coinbaseproOrderbook, levelStr)
|
||||
path = fmt.Sprintf("%s/%s/%s?level=%s", coinbaseproProducts, symbol, coinbaseproOrderbook, levelStr)
|
||||
}
|
||||
|
||||
if err := c.SendHTTPRequest(path, &orderbook); err != nil {
|
||||
if err := c.SendHTTPRequest(exchange.RestSpot, path, &orderbook); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -143,8 +143,8 @@ func (c *CoinbasePro) GetOrderbook(symbol string, level int) (interface{}, error
|
||||
func (c *CoinbasePro) GetTicker(currencyPair string) (Ticker, error) {
|
||||
tick := Ticker{}
|
||||
path := fmt.Sprintf(
|
||||
"%s/%s/%s", c.API.Endpoints.URL+coinbaseproProducts, currencyPair, coinbaseproTicker)
|
||||
return tick, c.SendHTTPRequest(path, &tick)
|
||||
"%s/%s/%s", coinbaseproProducts, currencyPair, coinbaseproTicker)
|
||||
return tick, c.SendHTTPRequest(exchange.RestSpot, path, &tick)
|
||||
}
|
||||
|
||||
// GetTrades listd the latest trades for a product
|
||||
@@ -152,8 +152,8 @@ func (c *CoinbasePro) GetTicker(currencyPair string) (Ticker, error) {
|
||||
func (c *CoinbasePro) GetTrades(currencyPair string) ([]Trade, error) {
|
||||
var trades []Trade
|
||||
path := fmt.Sprintf(
|
||||
"%s/%s/%s", c.API.Endpoints.URL+coinbaseproProducts, currencyPair, coinbaseproTrades)
|
||||
return trades, c.SendHTTPRequest(path, &trades)
|
||||
"%s/%s/%s", coinbaseproProducts, currencyPair, coinbaseproTrades)
|
||||
return trades, c.SendHTTPRequest(exchange.RestSpot, path, &trades)
|
||||
}
|
||||
|
||||
// GetHistoricRates returns historic rates for a product. Rates are returned in
|
||||
@@ -185,10 +185,10 @@ func (c *CoinbasePro) GetHistoricRates(currencyPair, start, end string, granular
|
||||
}
|
||||
|
||||
path := common.EncodeURLValues(
|
||||
fmt.Sprintf("%s/%s/%s", c.API.Endpoints.URL+coinbaseproProducts, currencyPair, coinbaseproHistory),
|
||||
fmt.Sprintf("%s/%s/%s", coinbaseproProducts, currencyPair, coinbaseproHistory),
|
||||
values)
|
||||
|
||||
if err := c.SendHTTPRequest(path, &resp); err != nil {
|
||||
if err := c.SendHTTPRequest(exchange.RestSpot, path, &resp); err != nil {
|
||||
return history, err
|
||||
}
|
||||
|
||||
@@ -217,9 +217,9 @@ func (c *CoinbasePro) GetHistoricRates(currencyPair, start, end string, granular
|
||||
func (c *CoinbasePro) GetStats(currencyPair string) (Stats, error) {
|
||||
stats := Stats{}
|
||||
path := fmt.Sprintf(
|
||||
"%s/%s/%s", c.API.Endpoints.URL+coinbaseproProducts, currencyPair, coinbaseproStats)
|
||||
"%s/%s/%s", coinbaseproProducts, currencyPair, coinbaseproStats)
|
||||
|
||||
return stats, c.SendHTTPRequest(path, &stats)
|
||||
return stats, c.SendHTTPRequest(exchange.RestSpot, path, &stats)
|
||||
}
|
||||
|
||||
// GetCurrencies returns a list of supported currency on the exchange
|
||||
@@ -227,14 +227,14 @@ func (c *CoinbasePro) GetStats(currencyPair string) (Stats, error) {
|
||||
func (c *CoinbasePro) GetCurrencies() ([]Currency, error) {
|
||||
var currencies []Currency
|
||||
|
||||
return currencies, c.SendHTTPRequest(c.API.Endpoints.URL+coinbaseproCurrencies, ¤cies)
|
||||
return currencies, c.SendHTTPRequest(exchange.RestSpot, coinbaseproCurrencies, ¤cies)
|
||||
}
|
||||
|
||||
// GetServerTime returns the API server time
|
||||
func (c *CoinbasePro) GetServerTime() (ServerTime, error) {
|
||||
serverTime := ServerTime{}
|
||||
|
||||
return serverTime, c.SendHTTPRequest(c.API.Endpoints.URL+coinbaseproTime, &serverTime)
|
||||
return serverTime, c.SendHTTPRequest(exchange.RestSpot, coinbaseproTime, &serverTime)
|
||||
}
|
||||
|
||||
// GetAccounts returns a list of trading accounts associated with the APIKEYS
|
||||
@@ -242,7 +242,7 @@ func (c *CoinbasePro) GetAccounts() ([]AccountResponse, error) {
|
||||
var resp []AccountResponse
|
||||
|
||||
return resp,
|
||||
c.SendAuthenticatedHTTPRequest(http.MethodGet, coinbaseproAccounts, nil, &resp)
|
||||
c.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, coinbaseproAccounts, nil, &resp)
|
||||
}
|
||||
|
||||
// GetAccount returns information for a single account. Use this endpoint when
|
||||
@@ -251,7 +251,7 @@ func (c *CoinbasePro) GetAccount(accountID string) (AccountResponse, error) {
|
||||
resp := AccountResponse{}
|
||||
path := fmt.Sprintf("%s/%s", coinbaseproAccounts, accountID)
|
||||
|
||||
return resp, c.SendAuthenticatedHTTPRequest(http.MethodGet, path, nil, &resp)
|
||||
return resp, c.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, path, nil, &resp)
|
||||
}
|
||||
|
||||
// GetAccountHistory returns a list of account activity. Account activity either
|
||||
@@ -261,7 +261,7 @@ func (c *CoinbasePro) GetAccountHistory(accountID string) ([]AccountLedgerRespon
|
||||
var resp []AccountLedgerResponse
|
||||
path := fmt.Sprintf("%s/%s/%s", coinbaseproAccounts, accountID, coinbaseproLedger)
|
||||
|
||||
return resp, c.SendAuthenticatedHTTPRequest(http.MethodGet, path, nil, &resp)
|
||||
return resp, c.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, path, nil, &resp)
|
||||
}
|
||||
|
||||
// GetHolds returns the holds that are placed on an account for any active
|
||||
@@ -272,7 +272,7 @@ func (c *CoinbasePro) GetHolds(accountID string) ([]AccountHolds, error) {
|
||||
var resp []AccountHolds
|
||||
path := fmt.Sprintf("%s/%s/%s", coinbaseproAccounts, accountID, coinbaseproHolds)
|
||||
|
||||
return resp, c.SendAuthenticatedHTTPRequest(http.MethodGet, path, nil, &resp)
|
||||
return resp, c.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, path, nil, &resp)
|
||||
}
|
||||
|
||||
// PlaceLimitOrder places a new limit order. Orders can only be placed if the
|
||||
@@ -317,7 +317,7 @@ func (c *CoinbasePro) PlaceLimitOrder(clientRef string, price, amount float64, s
|
||||
req["post_only"] = postOnly
|
||||
}
|
||||
|
||||
err := c.SendAuthenticatedHTTPRequest(http.MethodPost, coinbaseproOrders, req, &resp)
|
||||
err := c.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, coinbaseproOrders, req, &resp)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -361,7 +361,7 @@ func (c *CoinbasePro) PlaceMarketOrder(clientRef string, size, funds float64, si
|
||||
req["stp"] = stp
|
||||
}
|
||||
|
||||
err := c.SendAuthenticatedHTTPRequest(http.MethodPost, coinbaseproOrders, req, &resp)
|
||||
err := c.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, coinbaseproOrders, req, &resp)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -404,7 +404,7 @@ func (c *CoinbasePro) PlaceMarginOrder(clientRef string, size, funds float64, si
|
||||
req["stp"] = stp
|
||||
}
|
||||
|
||||
err := c.SendAuthenticatedHTTPRequest(http.MethodPost, coinbaseproOrders, req, &resp)
|
||||
err := c.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, coinbaseproOrders, req, &resp)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -416,7 +416,7 @@ func (c *CoinbasePro) PlaceMarginOrder(clientRef string, size, funds float64, si
|
||||
func (c *CoinbasePro) CancelExistingOrder(orderID string) error {
|
||||
path := fmt.Sprintf("%s/%s", coinbaseproOrders, orderID)
|
||||
|
||||
return c.SendAuthenticatedHTTPRequest(http.MethodDelete, path, nil, nil)
|
||||
return c.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodDelete, path, nil, nil)
|
||||
}
|
||||
|
||||
// CancelAllExistingOrders cancels all open orders on the exchange and returns
|
||||
@@ -430,7 +430,7 @@ func (c *CoinbasePro) CancelAllExistingOrders(currencyPair string) ([]string, er
|
||||
if len(currencyPair) > 0 {
|
||||
req["product_id"] = currencyPair
|
||||
}
|
||||
return resp, c.SendAuthenticatedHTTPRequest(http.MethodDelete, coinbaseproOrders, req, &resp)
|
||||
return resp, c.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodDelete, coinbaseproOrders, req, &resp)
|
||||
}
|
||||
|
||||
// GetOrders lists current open orders. Only open or un-settled orders are
|
||||
@@ -449,11 +449,11 @@ func (c *CoinbasePro) GetOrders(status []string, currencyPair string) ([]General
|
||||
params.Set("product_id", currencyPair)
|
||||
}
|
||||
|
||||
path := common.EncodeURLValues(c.API.Endpoints.URL+coinbaseproOrders, params)
|
||||
path := common.EncodeURLValues(coinbaseproOrders, params)
|
||||
path = common.GetURIPath(path)
|
||||
|
||||
return resp,
|
||||
c.SendAuthenticatedHTTPRequest(http.MethodGet, path[1:], nil, &resp)
|
||||
c.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, path[1:], nil, &resp)
|
||||
}
|
||||
|
||||
// GetOrder returns a single order by order id.
|
||||
@@ -461,7 +461,7 @@ func (c *CoinbasePro) GetOrder(orderID string) (GeneralizedOrderResponse, error)
|
||||
resp := GeneralizedOrderResponse{}
|
||||
path := fmt.Sprintf("%s/%s", coinbaseproOrders, orderID)
|
||||
|
||||
return resp, c.SendAuthenticatedHTTPRequest(http.MethodGet, path, nil, &resp)
|
||||
return resp, c.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, path, nil, &resp)
|
||||
}
|
||||
|
||||
// GetFills returns a list of recent fills
|
||||
@@ -479,11 +479,11 @@ func (c *CoinbasePro) GetFills(orderID, currencyPair string) ([]FillResponse, er
|
||||
return resp, errors.New("no parameters set")
|
||||
}
|
||||
|
||||
path := common.EncodeURLValues(c.API.Endpoints.URL+coinbaseproFills, params)
|
||||
path := common.EncodeURLValues(coinbaseproFills, params)
|
||||
uri := common.GetURIPath(path)
|
||||
|
||||
return resp,
|
||||
c.SendAuthenticatedHTTPRequest(http.MethodGet, uri[1:], nil, &resp)
|
||||
c.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, uri[1:], nil, &resp)
|
||||
}
|
||||
|
||||
// MarginTransfer sends funds between a standard/default profile and a margin
|
||||
@@ -506,7 +506,7 @@ func (c *CoinbasePro) MarginTransfer(amount float64, transferType, profileID, cu
|
||||
req["margin_profile_id"] = profileID
|
||||
|
||||
return resp,
|
||||
c.SendAuthenticatedHTTPRequest(http.MethodPost, coinbaseproMarginTransfer, req, &resp)
|
||||
c.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, coinbaseproMarginTransfer, req, &resp)
|
||||
}
|
||||
|
||||
// GetPosition returns an overview of account profile.
|
||||
@@ -514,7 +514,7 @@ func (c *CoinbasePro) GetPosition() (AccountOverview, error) {
|
||||
resp := AccountOverview{}
|
||||
|
||||
return resp,
|
||||
c.SendAuthenticatedHTTPRequest(http.MethodGet, coinbaseproPosition, nil, &resp)
|
||||
c.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, coinbaseproPosition, nil, &resp)
|
||||
}
|
||||
|
||||
// ClosePosition closes a position and allowing you to repay position as well
|
||||
@@ -525,7 +525,7 @@ func (c *CoinbasePro) ClosePosition(repayOnly bool) (AccountOverview, error) {
|
||||
req["repay_only"] = repayOnly
|
||||
|
||||
return resp,
|
||||
c.SendAuthenticatedHTTPRequest(http.MethodPost, coinbaseproPositionClose, req, &resp)
|
||||
c.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, coinbaseproPositionClose, req, &resp)
|
||||
}
|
||||
|
||||
// GetPayMethods returns a full list of payment methods
|
||||
@@ -533,7 +533,7 @@ func (c *CoinbasePro) GetPayMethods() ([]PaymentMethod, error) {
|
||||
var resp []PaymentMethod
|
||||
|
||||
return resp,
|
||||
c.SendAuthenticatedHTTPRequest(http.MethodGet, coinbaseproPaymentMethod, nil, &resp)
|
||||
c.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, coinbaseproPaymentMethod, nil, &resp)
|
||||
}
|
||||
|
||||
// DepositViaPaymentMethod deposits funds from a payment method. See the Payment
|
||||
@@ -550,7 +550,7 @@ func (c *CoinbasePro) DepositViaPaymentMethod(amount float64, currency, paymentI
|
||||
req["payment_method_id"] = paymentID
|
||||
|
||||
return resp,
|
||||
c.SendAuthenticatedHTTPRequest(http.MethodPost, coinbaseproPaymentMethodDeposit, req, &resp)
|
||||
c.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, coinbaseproPaymentMethodDeposit, req, &resp)
|
||||
}
|
||||
|
||||
// DepositViaCoinbase deposits funds from a coinbase account. Move funds between
|
||||
@@ -569,7 +569,7 @@ func (c *CoinbasePro) DepositViaCoinbase(amount float64, currency, accountID str
|
||||
req["coinbase_account_id"] = accountID
|
||||
|
||||
return resp,
|
||||
c.SendAuthenticatedHTTPRequest(http.MethodPost, coinbaseproDepositCoinbase, req, &resp)
|
||||
c.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, coinbaseproDepositCoinbase, req, &resp)
|
||||
}
|
||||
|
||||
// WithdrawViaPaymentMethod withdraws funds to a payment method
|
||||
@@ -585,7 +585,7 @@ func (c *CoinbasePro) WithdrawViaPaymentMethod(amount float64, currency, payment
|
||||
req["payment_method_id"] = paymentID
|
||||
|
||||
return resp,
|
||||
c.SendAuthenticatedHTTPRequest(http.MethodPost, coinbaseproWithdrawalPaymentMethod, req, &resp)
|
||||
c.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, coinbaseproWithdrawalPaymentMethod, req, &resp)
|
||||
}
|
||||
|
||||
// /////////////////////// NO ROUTE FOUND ERROR ////////////////////////////////
|
||||
@@ -618,7 +618,7 @@ func (c *CoinbasePro) WithdrawCrypto(amount float64, currency, cryptoAddress str
|
||||
req["crypto_address"] = cryptoAddress
|
||||
|
||||
return resp,
|
||||
c.SendAuthenticatedHTTPRequest(http.MethodPost, coinbaseproWithdrawalCrypto, req, &resp)
|
||||
c.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, coinbaseproWithdrawalCrypto, req, &resp)
|
||||
}
|
||||
|
||||
// GetCoinbaseAccounts returns a list of coinbase accounts
|
||||
@@ -626,7 +626,7 @@ func (c *CoinbasePro) GetCoinbaseAccounts() ([]CoinbaseAccounts, error) {
|
||||
var resp []CoinbaseAccounts
|
||||
|
||||
return resp,
|
||||
c.SendAuthenticatedHTTPRequest(http.MethodGet, coinbaseproCoinbaseAccounts, nil, &resp)
|
||||
c.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, coinbaseproCoinbaseAccounts, nil, &resp)
|
||||
}
|
||||
|
||||
// GetReport returns batches of historic information about your account in
|
||||
@@ -663,7 +663,7 @@ func (c *CoinbasePro) GetReport(reportType, startDate, endDate, currencyPair, ac
|
||||
}
|
||||
|
||||
return resp,
|
||||
c.SendAuthenticatedHTTPRequest(http.MethodPost, coinbaseproReports, req, &resp)
|
||||
c.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, coinbaseproReports, req, &resp)
|
||||
}
|
||||
|
||||
// GetReportStatus once a report request has been accepted for processing, the
|
||||
@@ -672,7 +672,7 @@ func (c *CoinbasePro) GetReportStatus(reportID string) (Report, error) {
|
||||
resp := Report{}
|
||||
path := fmt.Sprintf("%s/%s", coinbaseproReports, reportID)
|
||||
|
||||
return resp, c.SendAuthenticatedHTTPRequest(http.MethodGet, path, nil, &resp)
|
||||
return resp, c.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, path, nil, &resp)
|
||||
}
|
||||
|
||||
// GetTrailingVolume this request will return your 30-day trailing volume for
|
||||
@@ -681,14 +681,18 @@ func (c *CoinbasePro) GetTrailingVolume() ([]Volume, error) {
|
||||
var resp []Volume
|
||||
|
||||
return resp,
|
||||
c.SendAuthenticatedHTTPRequest(http.MethodGet, coinbaseproTrailingVolume, nil, &resp)
|
||||
c.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, coinbaseproTrailingVolume, nil, &resp)
|
||||
}
|
||||
|
||||
// SendHTTPRequest sends an unauthenticated HTTP request
|
||||
func (c *CoinbasePro) SendHTTPRequest(path string, result interface{}) error {
|
||||
func (c *CoinbasePro) SendHTTPRequest(ep exchange.URL, path string, result interface{}) error {
|
||||
endpoint, err := c.API.Endpoints.GetURL(ep)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return c.SendPayload(context.Background(), &request.Item{
|
||||
Method: http.MethodGet,
|
||||
Path: path,
|
||||
Path: endpoint + path,
|
||||
Result: result,
|
||||
Verbose: c.Verbose,
|
||||
HTTPDebugging: c.HTTPDebugging,
|
||||
@@ -697,12 +701,15 @@ func (c *CoinbasePro) SendHTTPRequest(path string, result interface{}) error {
|
||||
}
|
||||
|
||||
// SendAuthenticatedHTTPRequest sends an authenticated HTTP request
|
||||
func (c *CoinbasePro) SendAuthenticatedHTTPRequest(method, path string, params map[string]interface{}, result interface{}) (err error) {
|
||||
func (c *CoinbasePro) SendAuthenticatedHTTPRequest(ep exchange.URL, method, path string, params map[string]interface{}, result interface{}) (err error) {
|
||||
if !c.AllowAuthenticatedRequest() {
|
||||
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet,
|
||||
c.Name)
|
||||
}
|
||||
|
||||
endpoint, err := c.API.Endpoints.GetURL(ep)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
payload := []byte("")
|
||||
|
||||
if params != nil {
|
||||
@@ -732,7 +739,7 @@ func (c *CoinbasePro) SendAuthenticatedHTTPRequest(method, path string, params m
|
||||
defer cancel()
|
||||
return c.SendPayload(ctx, &request.Item{
|
||||
Method: method,
|
||||
Path: c.API.Endpoints.URL + path,
|
||||
Path: endpoint + path,
|
||||
Headers: headers,
|
||||
Body: bytes.NewBuffer(payload),
|
||||
Result: result,
|
||||
|
||||
@@ -394,7 +394,8 @@ func TestFormatWithdrawPermissions(t *testing.T) {
|
||||
|
||||
func TestGetActiveOrders(t *testing.T) {
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
Type: order.AnyType,
|
||||
Type: order.AnyType,
|
||||
AssetType: asset.Spot,
|
||||
Pairs: []currency.Pair{currency.NewPair(currency.BTC,
|
||||
currency.LTC)},
|
||||
}
|
||||
@@ -409,7 +410,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.BTC,
|
||||
currency.LTC)},
|
||||
}
|
||||
|
||||
@@ -131,10 +131,15 @@ func (c *CoinbasePro) SetDefaults() {
|
||||
c.Requester = request.New(c.Name,
|
||||
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout),
|
||||
request.WithLimiter(SetRateLimit()))
|
||||
|
||||
c.API.Endpoints.URLDefault = coinbaseproAPIURL
|
||||
c.API.Endpoints.URL = c.API.Endpoints.URLDefault
|
||||
c.API.Endpoints.WebsocketURL = coinbaseproWebsocketURL
|
||||
c.API.Endpoints = c.NewEndpoints()
|
||||
err = c.API.Endpoints.SetDefaultEndpoints(map[exchange.URL]string{
|
||||
exchange.RestSpot: coinbaseproAPIURL,
|
||||
exchange.RestSandbox: coinbaseproSandboxAPIURL,
|
||||
exchange.WebsocketSpot: coinbaseproWebsocketURL,
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorln(log.ExchangeSys, err)
|
||||
}
|
||||
c.Websocket = stream.New()
|
||||
c.WebsocketResponseMaxLimit = exchange.DefaultWebsocketResponseMaxLimit
|
||||
c.WebsocketResponseCheckTimeout = exchange.DefaultWebsocketResponseCheckTimeout
|
||||
@@ -153,6 +158,11 @@ func (c *CoinbasePro) Setup(exch *config.ExchangeConfig) error {
|
||||
return err
|
||||
}
|
||||
|
||||
wsRunningURL, err := c.API.Endpoints.GetURL(exchange.WebsocketSpot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.Websocket.Setup(&stream.WebsocketSetup{
|
||||
Enabled: exch.Features.Enabled.Websocket,
|
||||
Verbose: exch.Verbose,
|
||||
@@ -160,7 +170,7 @@ func (c *CoinbasePro) Setup(exch *config.ExchangeConfig) error {
|
||||
WebsocketTimeout: exch.WebsocketTrafficTimeout,
|
||||
DefaultURL: coinbaseproWebsocketURL,
|
||||
ExchangeName: exch.Name,
|
||||
RunningURL: exch.API.Endpoints.WebsocketURL,
|
||||
RunningURL: wsRunningURL,
|
||||
Connector: c.WsConnect,
|
||||
Subscriber: c.Subscribe,
|
||||
UnSubscriber: c.Unsubscribe,
|
||||
@@ -303,7 +313,7 @@ func (c *CoinbasePro) UpdateTradablePairs(forceUpdate bool) error {
|
||||
|
||||
// UpdateAccountInfo retrieves balances for all enabled currencies for the
|
||||
// coinbasepro exchange
|
||||
func (c *CoinbasePro) UpdateAccountInfo() (account.Holdings, error) {
|
||||
func (c *CoinbasePro) UpdateAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
var response account.Holdings
|
||||
response.Exchange = c.Name
|
||||
accountBalance, err := c.GetAccounts()
|
||||
@@ -334,10 +344,10 @@ func (c *CoinbasePro) UpdateAccountInfo() (account.Holdings, error) {
|
||||
}
|
||||
|
||||
// FetchAccountInfo retrieves balances for all enabled currencies
|
||||
func (c *CoinbasePro) FetchAccountInfo() (account.Holdings, error) {
|
||||
acc, err := account.GetHoldings(c.Name)
|
||||
func (c *CoinbasePro) FetchAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
acc, err := account.GetHoldings(c.Name, assetType)
|
||||
if err != nil {
|
||||
return c.UpdateAccountInfo()
|
||||
return c.UpdateAccountInfo(assetType)
|
||||
}
|
||||
|
||||
return acc, nil
|
||||
@@ -934,7 +944,7 @@ func (c *CoinbasePro) GetHistoricCandlesExtended(p currency.Pair, a asset.Item,
|
||||
|
||||
// ValidateCredentials validates current credentials used for wrapper
|
||||
// functionality
|
||||
func (c *CoinbasePro) ValidateCredentials() error {
|
||||
_, err := c.UpdateAccountInfo()
|
||||
func (c *CoinbasePro) ValidateCredentials(assetType asset.Item) error {
|
||||
_, err := c.UpdateAccountInfo(assetType)
|
||||
return c.CheckTransientError(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user