mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-30 15:10:40 +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:
@@ -147,15 +147,8 @@ func (b *Bitstamp) GetTicker(currency string, hourly bool) (*Ticker, error) {
|
||||
if hourly {
|
||||
tickerEndpoint = bitstampAPITickerHourly
|
||||
}
|
||||
|
||||
path := fmt.Sprintf(
|
||||
"%s/v%s/%s/%s/",
|
||||
b.API.Endpoints.URL,
|
||||
bitstampAPIVersion,
|
||||
tickerEndpoint,
|
||||
strings.ToLower(currency),
|
||||
)
|
||||
return &response, b.SendHTTPRequest(path, &response)
|
||||
path := "/v" + bitstampAPIVersion + "/" + tickerEndpoint + "/" + strings.ToLower(currency) + "/"
|
||||
return &response, b.SendHTTPRequest(exchange.RestSpot, path, &response)
|
||||
}
|
||||
|
||||
// GetOrderbook Returns a JSON dictionary with "bids" and "asks". Each is a list
|
||||
@@ -168,16 +161,8 @@ func (b *Bitstamp) GetOrderbook(currency string) (Orderbook, error) {
|
||||
Asks [][]string `json:"asks"`
|
||||
}
|
||||
resp := response{}
|
||||
|
||||
path := fmt.Sprintf(
|
||||
"%s/v%s/%s/%s/",
|
||||
b.API.Endpoints.URL,
|
||||
bitstampAPIVersion,
|
||||
bitstampAPIOrderbook,
|
||||
strings.ToLower(currency),
|
||||
)
|
||||
|
||||
err := b.SendHTTPRequest(path, &resp)
|
||||
path := "/v" + bitstampAPIVersion + "/" + bitstampAPIOrderbook + "/" + strings.ToLower(currency) + "/"
|
||||
err := b.SendHTTPRequest(exchange.RestSpot, path, &resp)
|
||||
if err != nil {
|
||||
return Orderbook{}, err
|
||||
}
|
||||
@@ -220,13 +205,8 @@ func (b *Bitstamp) GetOrderbook(currency string) (Orderbook, error) {
|
||||
// currently supports
|
||||
func (b *Bitstamp) GetTradingPairs() ([]TradingPair, error) {
|
||||
var result []TradingPair
|
||||
|
||||
path := fmt.Sprintf("%s/v%s/%s",
|
||||
b.API.Endpoints.URL,
|
||||
bitstampAPIVersion,
|
||||
bitstampAPITradingPairsInfo)
|
||||
|
||||
return result, b.SendHTTPRequest(path, &result)
|
||||
path := "/v" + bitstampAPIVersion + "/" + bitstampAPITradingPairsInfo
|
||||
return result, b.SendHTTPRequest(exchange.RestSpot, path, &result)
|
||||
}
|
||||
|
||||
// GetTransactions returns transaction information
|
||||
@@ -234,36 +214,27 @@ func (b *Bitstamp) GetTradingPairs() ([]TradingPair, error) {
|
||||
// response into time intervals.
|
||||
func (b *Bitstamp) GetTransactions(currencyPair, timePeriod string) ([]Transactions, error) {
|
||||
var transactions []Transactions
|
||||
requestURL := fmt.Sprintf(
|
||||
"%s/v%s/%s/%s/",
|
||||
b.API.Endpoints.URL,
|
||||
bitstampAPIVersion,
|
||||
bitstampAPITransactions,
|
||||
strings.ToLower(currencyPair),
|
||||
)
|
||||
requestURL := "/v" + bitstampAPIVersion + "/" + bitstampAPITransactions + "/" + strings.ToLower(currencyPair) + "/"
|
||||
if timePeriod != "" {
|
||||
requestURL += "?time=" + url.QueryEscape(timePeriod)
|
||||
}
|
||||
|
||||
return transactions, b.SendHTTPRequest(requestURL, &transactions)
|
||||
return transactions, b.SendHTTPRequest(exchange.RestSpot, requestURL, &transactions)
|
||||
}
|
||||
|
||||
// GetEURUSDConversionRate returns the conversion rate between Euro and USD
|
||||
func (b *Bitstamp) GetEURUSDConversionRate() (EURUSDConversionRate, error) {
|
||||
rate := EURUSDConversionRate{}
|
||||
path := fmt.Sprintf("%s/%s", b.API.Endpoints.URL, bitstampAPIEURUSD)
|
||||
|
||||
return rate, b.SendHTTPRequest(path, &rate)
|
||||
path := "/" + bitstampAPIEURUSD
|
||||
return rate, b.SendHTTPRequest(exchange.RestSpot, path, &rate)
|
||||
}
|
||||
|
||||
// GetBalance returns full balance of currency held on the exchange
|
||||
func (b *Bitstamp) GetBalance() (Balances, error) {
|
||||
var balance map[string]string
|
||||
err := b.SendAuthenticatedHTTPRequest(bitstampAPIBalance, true, nil, &balance)
|
||||
err := b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPIBalance, true, nil, &balance)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
balances := make(map[string]Balance)
|
||||
for k := range balance {
|
||||
curr := k[0:3]
|
||||
@@ -317,14 +288,14 @@ func (b *Bitstamp) GetUserTransactions(currencyPair string) ([]UserTransactions,
|
||||
var response []Response
|
||||
|
||||
if currencyPair == "" {
|
||||
if err := b.SendAuthenticatedHTTPRequest(bitstampAPIUserTransactions,
|
||||
if err := b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPIUserTransactions,
|
||||
true,
|
||||
url.Values{},
|
||||
&response); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
if err := b.SendAuthenticatedHTTPRequest(bitstampAPIUserTransactions+"/"+currencyPair,
|
||||
if err := b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPIUserTransactions+"/"+currencyPair,
|
||||
true,
|
||||
url.Values{},
|
||||
&response); err != nil {
|
||||
@@ -366,11 +337,8 @@ func (b *Bitstamp) GetUserTransactions(currencyPair string) ([]UserTransactions,
|
||||
// GetOpenOrders returns all open orders on the exchange
|
||||
func (b *Bitstamp) GetOpenOrders(currencyPair string) ([]Order, error) {
|
||||
var resp []Order
|
||||
path := fmt.Sprintf(
|
||||
"%s/%s", bitstampAPIOpenOrders, strings.ToLower(currencyPair),
|
||||
)
|
||||
|
||||
return resp, b.SendAuthenticatedHTTPRequest(path, true, nil, &resp)
|
||||
path := bitstampAPIOpenOrders + "/" + strings.ToLower(currencyPair)
|
||||
return resp, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, path, true, nil, &resp)
|
||||
}
|
||||
|
||||
// GetOrderStatus returns an the status of an order by its ID
|
||||
@@ -380,7 +348,7 @@ func (b *Bitstamp) GetOrderStatus(orderID int64) (OrderStatus, error) {
|
||||
req.Add("id", strconv.FormatInt(orderID, 10))
|
||||
|
||||
return resp,
|
||||
b.SendAuthenticatedHTTPRequest(bitstampAPIOrderStatus, false, req, &resp)
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPIOrderStatus, false, req, &resp)
|
||||
}
|
||||
|
||||
// CancelExistingOrder cancels order by ID
|
||||
@@ -389,7 +357,7 @@ func (b *Bitstamp) CancelExistingOrder(orderID int64) (CancelOrder, error) {
|
||||
req.Add("id", strconv.FormatInt(orderID, 10))
|
||||
|
||||
var result CancelOrder
|
||||
err := b.SendAuthenticatedHTTPRequest(bitstampAPICancelOrder, true, req, &result)
|
||||
err := b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPICancelOrder, true, req, &result)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
@@ -402,7 +370,7 @@ func (b *Bitstamp) CancelAllExistingOrders() (bool, error) {
|
||||
result := false
|
||||
|
||||
return result,
|
||||
b.SendAuthenticatedHTTPRequest(bitstampAPICancelAllOrders, false, nil, &result)
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPICancelAllOrders, false, nil, &result)
|
||||
}
|
||||
|
||||
// PlaceOrder places an order on the exchange.
|
||||
@@ -419,13 +387,13 @@ func (b *Bitstamp) PlaceOrder(currencyPair string, price, amount float64, buy, m
|
||||
|
||||
var path string
|
||||
if market {
|
||||
path = fmt.Sprintf("%s/%s/%s", orderType, bitstampAPIMarket, strings.ToLower(currencyPair))
|
||||
path = orderType + "/" + bitstampAPIMarket + strings.ToLower(currencyPair)
|
||||
} else {
|
||||
path = fmt.Sprintf("%s/%s", orderType, strings.ToLower(currencyPair))
|
||||
path = orderType + "/" + orderType + strings.ToLower(currencyPair)
|
||||
}
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(path, true, req, &response)
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, path, true, req, &response)
|
||||
}
|
||||
|
||||
// GetWithdrawalRequests returns withdrawal requests for the account
|
||||
@@ -445,7 +413,7 @@ func (b *Bitstamp) GetWithdrawalRequests(timedelta int64) ([]WithdrawalRequests,
|
||||
}
|
||||
|
||||
return resp,
|
||||
b.SendAuthenticatedHTTPRequest(bitstampAPIWithdrawalRequests, false, value, &resp)
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPIWithdrawalRequests, false, value, &resp)
|
||||
}
|
||||
|
||||
// CryptoWithdrawal withdraws a cryptocurrency into a supplied wallet, returns ID
|
||||
@@ -484,7 +452,7 @@ func (b *Bitstamp) CryptoWithdrawal(amount float64, address, symbol, destTag str
|
||||
return resp, errors.New("incorrect symbol")
|
||||
}
|
||||
|
||||
return resp, b.SendAuthenticatedHTTPRequest(endpoint, false, req, &resp)
|
||||
return resp, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, endpoint, false, req, &resp)
|
||||
}
|
||||
|
||||
// OpenBankWithdrawal Opens a bank withdrawal request (SEPA or international)
|
||||
@@ -505,7 +473,7 @@ func (b *Bitstamp) OpenBankWithdrawal(amount float64, currency,
|
||||
req.Add("comment", comment)
|
||||
|
||||
resp := FIATWithdrawalResponse{}
|
||||
return resp, b.SendAuthenticatedHTTPRequest(bitstampAPIOpenWithdrawal, true, req, &resp)
|
||||
return resp, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPIOpenWithdrawal, true, req, &resp)
|
||||
}
|
||||
|
||||
// OpenInternationalBankWithdrawal Opens a bank withdrawal request (international)
|
||||
@@ -533,7 +501,7 @@ func (b *Bitstamp) OpenInternationalBankWithdrawal(amount float64, currency,
|
||||
req.Add("bank_country", bankCountry)
|
||||
|
||||
resp := FIATWithdrawalResponse{}
|
||||
return resp, b.SendAuthenticatedHTTPRequest(bitstampAPIOpenWithdrawal, true, req, &resp)
|
||||
return resp, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPIOpenWithdrawal, true, req, &resp)
|
||||
}
|
||||
|
||||
// GetCryptoDepositAddress returns a depositing address by crypto
|
||||
@@ -547,23 +515,23 @@ func (b *Bitstamp) GetCryptoDepositAddress(crypto currency.Code) (string, error)
|
||||
switch crypto {
|
||||
case currency.BTC:
|
||||
return resp,
|
||||
b.SendAuthenticatedHTTPRequest(bitstampAPIBitcoinDeposit, false, nil, &resp)
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPIBitcoinDeposit, false, nil, &resp)
|
||||
|
||||
case currency.LTC:
|
||||
return v2Resp.Address,
|
||||
b.SendAuthenticatedHTTPRequest(bitstampAPILitecoinDeposit, true, nil, &v2Resp)
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPILitecoinDeposit, true, nil, &v2Resp)
|
||||
|
||||
case currency.ETH:
|
||||
return v2Resp.Address,
|
||||
b.SendAuthenticatedHTTPRequest(bitstampAPIEthereumDeposit, true, nil, &v2Resp)
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPIEthereumDeposit, true, nil, &v2Resp)
|
||||
|
||||
case currency.XRP:
|
||||
return v2Resp.Address,
|
||||
b.SendAuthenticatedHTTPRequest(bitstampAPIXrpDeposit, true, nil, &v2Resp)
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPIXrpDeposit, true, nil, &v2Resp)
|
||||
|
||||
case currency.BCH:
|
||||
return v2Resp.Address,
|
||||
b.SendAuthenticatedHTTPRequest(bitstampAPIBitcoinCashDeposit, true, nil, &v2Resp)
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPIBitcoinCashDeposit, true, nil, &v2Resp)
|
||||
|
||||
default:
|
||||
return resp, fmt.Errorf("unsupported cryptocurrency string %s", crypto)
|
||||
@@ -575,7 +543,7 @@ func (b *Bitstamp) GetUnconfirmedBitcoinDeposits() ([]UnconfirmedBTCTransactions
|
||||
var response []UnconfirmedBTCTransactions
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(bitstampAPIUnconfirmedBitcoin, false, nil, &response)
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPIUnconfirmedBitcoin, false, nil, &response)
|
||||
}
|
||||
|
||||
// OHLC returns OHLCV data for step (interval)
|
||||
@@ -593,7 +561,7 @@ func (b *Bitstamp) OHLC(currency string, start, end time.Time, step, limit strin
|
||||
if !end.IsZero() {
|
||||
v.Add("end", strconv.FormatInt(end.Unix(), 10))
|
||||
}
|
||||
return resp, b.SendHTTPRequest(common.EncodeURLValues(b.API.Endpoints.URL+"/v"+bitstampAPIVersion+"/"+bitstampOHLC+"/"+currency, v), &resp)
|
||||
return resp, b.SendHTTPRequest(exchange.RestSpot, common.EncodeURLValues("/v"+bitstampAPIVersion+"/"+bitstampOHLC+"/"+currency, v), &resp)
|
||||
}
|
||||
|
||||
// TransferAccountBalance transfers funds from either a main or sub account
|
||||
@@ -621,14 +589,18 @@ func (b *Bitstamp) TransferAccountBalance(amount float64, currency, subAccount s
|
||||
|
||||
var resp interface{}
|
||||
|
||||
return b.SendAuthenticatedHTTPRequest(path, true, req, &resp)
|
||||
return b.SendAuthenticatedHTTPRequest(exchange.RestSpot, path, true, req, &resp)
|
||||
}
|
||||
|
||||
// SendHTTPRequest sends an unauthenticated HTTP request
|
||||
func (b *Bitstamp) SendHTTPRequest(path string, result interface{}) error {
|
||||
func (b *Bitstamp) SendHTTPRequest(ep exchange.URL, path string, result interface{}) error {
|
||||
endpoint, err := b.API.Endpoints.GetURL(ep)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return b.SendPayload(context.Background(), &request.Item{
|
||||
Method: http.MethodGet,
|
||||
Path: path,
|
||||
Path: endpoint + path,
|
||||
Result: result,
|
||||
Verbose: b.Verbose,
|
||||
HTTPDebugging: b.HTTPDebugging,
|
||||
@@ -637,11 +609,14 @@ func (b *Bitstamp) SendHTTPRequest(path string, result interface{}) error {
|
||||
}
|
||||
|
||||
// SendAuthenticatedHTTPRequest sends an authenticated request
|
||||
func (b *Bitstamp) SendAuthenticatedHTTPRequest(path string, v2 bool, values url.Values, result interface{}) error {
|
||||
func (b *Bitstamp) SendAuthenticatedHTTPRequest(ep exchange.URL, path string, v2 bool, values url.Values, result interface{}) error {
|
||||
if !b.AllowAuthenticatedRequest() {
|
||||
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet, b.Name)
|
||||
}
|
||||
|
||||
endpoint, err := b.API.Endpoints.GetURL(ep)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
n := b.Requester.GetNonce(true).String()
|
||||
|
||||
if values == nil {
|
||||
@@ -656,9 +631,9 @@ func (b *Bitstamp) SendAuthenticatedHTTPRequest(path string, v2 bool, values url
|
||||
values.Set("signature", strings.ToUpper(crypto.HexEncodeToString(hmac)))
|
||||
|
||||
if v2 {
|
||||
path = fmt.Sprintf("%s/v%s/%s/", b.API.Endpoints.URL, bitstampAPIVersion, path)
|
||||
path = endpoint + "/v" + bitstampAPIVersion + "/" + path + "/"
|
||||
} else {
|
||||
path = fmt.Sprintf("%s/%s/", b.API.Endpoints.URL, path)
|
||||
path = endpoint + "/" + path + "/"
|
||||
}
|
||||
|
||||
if b.Verbose {
|
||||
@@ -679,7 +654,7 @@ func (b *Bitstamp) SendAuthenticatedHTTPRequest(path string, v2 bool, values url
|
||||
Reason interface{} `json:"reason"`
|
||||
}{}
|
||||
|
||||
err := b.SendPayload(context.Background(), &request.Item{
|
||||
err = b.SendPayload(context.Background(), &request.Item{
|
||||
Method: http.MethodPost,
|
||||
Path: path,
|
||||
Headers: headers,
|
||||
|
||||
@@ -35,6 +35,6 @@ func TestMain(m *testing.M) {
|
||||
if err != nil {
|
||||
log.Fatal("Bitstamp setup error", err)
|
||||
}
|
||||
log.Printf(sharedtestvalues.LiveTesting, b.Name, b.API.Endpoints.URL)
|
||||
log.Printf(sharedtestvalues.LiveTesting, b.Name)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
@@ -46,7 +46,13 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
b.HTTPClient = newClient
|
||||
b.API.Endpoints.URL = serverDetails + "/api"
|
||||
log.Printf(sharedtestvalues.MockTesting, b.Name, b.API.Endpoints.URL)
|
||||
endpointMap := b.API.Endpoints.GetURLMap()
|
||||
for k := range endpointMap {
|
||||
err = b.API.Endpoints.SetRunning(k, serverDetails+"/api")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
log.Printf(sharedtestvalues.MockTesting, b.Name)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
@@ -182,7 +182,6 @@ func TestGetTicker(t *testing.T) {
|
||||
|
||||
func TestGetOrderbook(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := b.GetOrderbook(currency.BTC.String() + currency.USD.String())
|
||||
if err != nil {
|
||||
t.Error("GetOrderbook() error", err)
|
||||
@@ -217,7 +216,6 @@ func TestGetEURUSDConversionRate(t *testing.T) {
|
||||
|
||||
func TestGetBalance(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := b.GetBalance()
|
||||
switch {
|
||||
case areTestAPIKeysSet() && err != nil && !mockTests:
|
||||
@@ -333,7 +331,8 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
Type: order.AnyType,
|
||||
Type: order.AnyType,
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
_, err := b.GetActiveOrders(&getOrdersRequest)
|
||||
@@ -351,7 +350,8 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
Type: order.AnyType,
|
||||
Type: order.AnyType,
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
_, err := b.GetOrderHistory(&getOrdersRequest)
|
||||
|
||||
@@ -33,7 +33,6 @@ func (b *Bitstamp) GetDefaultConfig() (*config.ExchangeConfig, error) {
|
||||
exchCfg.Name = b.Name
|
||||
exchCfg.HTTPTimeout = exchange.DefaultHTTPTimeout
|
||||
exchCfg.BaseCurrencies = b.BaseCurrencies
|
||||
|
||||
err := b.SetupDefaults(exchCfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -57,7 +56,6 @@ func (b *Bitstamp) SetDefaults() {
|
||||
b.API.CredentialsValidator.RequiresKey = true
|
||||
b.API.CredentialsValidator.RequiresSecret = true
|
||||
b.API.CredentialsValidator.RequiresClientID = true
|
||||
|
||||
requestFmt := ¤cy.PairFormat{Uppercase: true}
|
||||
configFmt := ¤cy.PairFormat{Uppercase: true}
|
||||
err := b.SetGlobalPairsManager(requestFmt, configFmt, asset.Spot)
|
||||
@@ -129,10 +127,14 @@ func (b *Bitstamp) SetDefaults() {
|
||||
b.Requester = request.New(b.Name,
|
||||
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout),
|
||||
request.WithLimiter(request.NewBasicRateLimit(bitstampRateInterval, bitstampRequestRate)))
|
||||
|
||||
b.API.Endpoints.URLDefault = bitstampAPIURL
|
||||
b.API.Endpoints.URL = b.API.Endpoints.URLDefault
|
||||
b.API.Endpoints.WebsocketURL = bitstampWSURL
|
||||
b.API.Endpoints = b.NewEndpoints()
|
||||
err = b.API.Endpoints.SetDefaultEndpoints(map[exchange.URL]string{
|
||||
exchange.RestSpot: bitstampAPIURL,
|
||||
exchange.WebsocketSpot: bitstampWSURL,
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorln(log.ExchangeSys, err)
|
||||
}
|
||||
b.Websocket = stream.New()
|
||||
b.WebsocketResponseMaxLimit = exchange.DefaultWebsocketResponseMaxLimit
|
||||
b.WebsocketResponseCheckTimeout = exchange.DefaultWebsocketResponseCheckTimeout
|
||||
@@ -151,6 +153,11 @@ func (b *Bitstamp) Setup(exch *config.ExchangeConfig) error {
|
||||
return err
|
||||
}
|
||||
|
||||
wsURL, err := b.API.Endpoints.GetURL(exchange.WebsocketSpot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = b.Websocket.Setup(&stream.WebsocketSetup{
|
||||
Enabled: exch.Features.Enabled.Websocket,
|
||||
Verbose: exch.Verbose,
|
||||
@@ -158,7 +165,7 @@ func (b *Bitstamp) Setup(exch *config.ExchangeConfig) error {
|
||||
WebsocketTimeout: exch.WebsocketTrafficTimeout,
|
||||
DefaultURL: bitstampWSURL,
|
||||
ExchangeName: exch.Name,
|
||||
RunningURL: exch.API.Endpoints.WebsocketURL,
|
||||
RunningURL: wsURL,
|
||||
Connector: b.WsConnect,
|
||||
Subscriber: b.Subscribe,
|
||||
UnSubscriber: b.Unsubscribe,
|
||||
@@ -354,7 +361,7 @@ func (b *Bitstamp) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orde
|
||||
|
||||
// UpdateAccountInfo retrieves balances for all enabled currencies for the
|
||||
// Bitstamp exchange
|
||||
func (b *Bitstamp) UpdateAccountInfo() (account.Holdings, error) {
|
||||
func (b *Bitstamp) UpdateAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
var response account.Holdings
|
||||
response.Exchange = b.Name
|
||||
accountBalance, err := b.GetBalance()
|
||||
@@ -383,10 +390,10 @@ func (b *Bitstamp) UpdateAccountInfo() (account.Holdings, error) {
|
||||
}
|
||||
|
||||
// FetchAccountInfo retrieves balances for all enabled currencies
|
||||
func (b *Bitstamp) FetchAccountInfo() (account.Holdings, error) {
|
||||
acc, err := account.GetHoldings(b.Name)
|
||||
func (b *Bitstamp) FetchAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
acc, err := account.GetHoldings(b.Name, assetType)
|
||||
if err != nil {
|
||||
return b.UpdateAccountInfo()
|
||||
return b.UpdateAccountInfo(assetType)
|
||||
}
|
||||
|
||||
return acc, nil
|
||||
@@ -775,8 +782,8 @@ func (b *Bitstamp) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail,
|
||||
|
||||
// ValidateCredentials validates current credentials used for wrapper
|
||||
// functionality
|
||||
func (b *Bitstamp) ValidateCredentials() error {
|
||||
_, err := b.UpdateAccountInfo()
|
||||
func (b *Bitstamp) ValidateCredentials(assetType asset.Item) error {
|
||||
_, err := b.UpdateAccountInfo(assetType)
|
||||
return b.CheckTransientError(err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user