exchanges: Initial context propagation (#744)

* gct: phase one context awareness pass

* exchanges: context propagation pass

* common/requester: force context requirement

* gctcli/exchanges: linter fix

* rpcserver: fix test using dummy rpc server

* backtester: fix comments

* grpc: add correct cancel and timeout for commands

* rpcserver_test: add comment on dummy server

* common: deprecated SendHTTPGetRequest

* linter: fix

* linter: turn on no context check

* apichecker: fix context linter issue

* binance: use param context

* common: remove checks as this gets executed before main

* common: change mutex to RW as clients can be used by multiple go routines.

* common: remove init and JIT default client. Unexport global variables and add protection.

* common: Add comments

* bithumb: after dinner mints fix
This commit is contained in:
Ryan O'Hara-Reid
2021-09-11 13:52:07 +10:00
committed by GitHub
parent 72516f7268
commit d636049fb2
168 changed files with 8085 additions and 6996 deletions

View File

@@ -66,12 +66,12 @@ type Bitstamp struct {
}
// GetFee returns an estimate of fee based on type of transaction
func (b *Bitstamp) GetFee(feeBuilder *exchange.FeeBuilder) (float64, error) {
func (b *Bitstamp) GetFee(ctx context.Context, feeBuilder *exchange.FeeBuilder) (float64, error) {
var fee float64
switch feeBuilder.FeeType {
case exchange.CryptocurrencyTradeFee:
balance, err := b.GetBalance()
balance, err := b.GetBalance(ctx)
if err != nil {
return 0, err
}
@@ -140,7 +140,7 @@ func (b *Bitstamp) CalculateTradingFee(base, quote currency.Code, purchasePrice,
}
// GetTicker returns ticker information
func (b *Bitstamp) GetTicker(currency string, hourly bool) (*Ticker, error) {
func (b *Bitstamp) GetTicker(ctx context.Context, currency string, hourly bool) (*Ticker, error) {
response := Ticker{}
tickerEndpoint := bitstampAPITicker
@@ -148,13 +148,13 @@ func (b *Bitstamp) GetTicker(currency string, hourly bool) (*Ticker, error) {
tickerEndpoint = bitstampAPITickerHourly
}
path := "/v" + bitstampAPIVersion + "/" + tickerEndpoint + "/" + strings.ToLower(currency) + "/"
return &response, b.SendHTTPRequest(exchange.RestSpot, path, &response)
return &response, b.SendHTTPRequest(ctx, exchange.RestSpot, path, &response)
}
// GetOrderbook Returns a JSON dictionary with "bids" and "asks". Each is a list
// of open orders and each order is represented as a list holding the price and
// the amount.
func (b *Bitstamp) GetOrderbook(currency string) (Orderbook, error) {
func (b *Bitstamp) GetOrderbook(ctx context.Context, currency string) (Orderbook, error) {
type response struct {
Timestamp int64 `json:"timestamp,string"`
Bids [][]string `json:"bids"`
@@ -162,7 +162,7 @@ func (b *Bitstamp) GetOrderbook(currency string) (Orderbook, error) {
}
resp := response{}
path := "/v" + bitstampAPIVersion + "/" + bitstampAPIOrderbook + "/" + strings.ToLower(currency) + "/"
err := b.SendHTTPRequest(exchange.RestSpot, path, &resp)
err := b.SendHTTPRequest(ctx, exchange.RestSpot, path, &resp)
if err != nil {
return Orderbook{}, err
}
@@ -203,35 +203,35 @@ func (b *Bitstamp) GetOrderbook(currency string) (Orderbook, error) {
// GetTradingPairs returns a list of trading pairs which Bitstamp
// currently supports
func (b *Bitstamp) GetTradingPairs() ([]TradingPair, error) {
func (b *Bitstamp) GetTradingPairs(ctx context.Context) ([]TradingPair, error) {
var result []TradingPair
path := "/v" + bitstampAPIVersion + "/" + bitstampAPITradingPairsInfo
return result, b.SendHTTPRequest(exchange.RestSpot, path, &result)
return result, b.SendHTTPRequest(ctx, exchange.RestSpot, path, &result)
}
// GetTransactions returns transaction information
// value paramater ["time"] = "minute", "hour", "day" will collate your
// response into time intervals.
func (b *Bitstamp) GetTransactions(currencyPair, timePeriod string) ([]Transactions, error) {
func (b *Bitstamp) GetTransactions(ctx context.Context, currencyPair, timePeriod string) ([]Transactions, error) {
var transactions []Transactions
requestURL := "/v" + bitstampAPIVersion + "/" + bitstampAPITransactions + "/" + strings.ToLower(currencyPair) + "/"
if timePeriod != "" {
requestURL += "?time=" + url.QueryEscape(timePeriod)
}
return transactions, b.SendHTTPRequest(exchange.RestSpot, requestURL, &transactions)
return transactions, b.SendHTTPRequest(ctx, exchange.RestSpot, requestURL, &transactions)
}
// GetEURUSDConversionRate returns the conversion rate between Euro and USD
func (b *Bitstamp) GetEURUSDConversionRate() (EURUSDConversionRate, error) {
func (b *Bitstamp) GetEURUSDConversionRate(ctx context.Context) (EURUSDConversionRate, error) {
rate := EURUSDConversionRate{}
path := "/" + bitstampAPIEURUSD
return rate, b.SendHTTPRequest(exchange.RestSpot, path, &rate)
return rate, b.SendHTTPRequest(ctx, exchange.RestSpot, path, &rate)
}
// GetBalance returns full balance of currency held on the exchange
func (b *Bitstamp) GetBalance() (Balances, error) {
func (b *Bitstamp) GetBalance(ctx context.Context) (Balances, error) {
var balance map[string]string
err := b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPIBalance, true, nil, &balance)
err := b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, bitstampAPIBalance, true, nil, &balance)
if err != nil {
return nil, err
}
@@ -272,7 +272,7 @@ func (b *Bitstamp) GetBalance() (Balances, error) {
}
// GetUserTransactions returns an array of transactions
func (b *Bitstamp) GetUserTransactions(currencyPair string) ([]UserTransactions, error) {
func (b *Bitstamp) GetUserTransactions(ctx context.Context, currencyPair string) ([]UserTransactions, error) {
type Response struct {
Date string `json:"datetime"`
TransactionID int64 `json:"id"`
@@ -288,14 +288,14 @@ func (b *Bitstamp) GetUserTransactions(currencyPair string) ([]UserTransactions,
var response []Response
if currencyPair == "" {
if err := b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPIUserTransactions,
if err := b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, bitstampAPIUserTransactions,
true,
url.Values{},
&response); err != nil {
return nil, err
}
} else {
if err := b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPIUserTransactions+"/"+currencyPair,
if err := b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, bitstampAPIUserTransactions+"/"+currencyPair,
true,
url.Values{},
&response); err != nil {
@@ -335,29 +335,29 @@ func (b *Bitstamp) GetUserTransactions(currencyPair string) ([]UserTransactions,
}
// GetOpenOrders returns all open orders on the exchange
func (b *Bitstamp) GetOpenOrders(currencyPair string) ([]Order, error) {
func (b *Bitstamp) GetOpenOrders(ctx context.Context, currencyPair string) ([]Order, error) {
var resp []Order
path := bitstampAPIOpenOrders + "/" + strings.ToLower(currencyPair)
return resp, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, path, true, nil, &resp)
return resp, b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, path, true, nil, &resp)
}
// GetOrderStatus returns an the status of an order by its ID
func (b *Bitstamp) GetOrderStatus(orderID int64) (OrderStatus, error) {
func (b *Bitstamp) GetOrderStatus(ctx context.Context, orderID int64) (OrderStatus, error) {
resp := OrderStatus{}
req := url.Values{}
req.Add("id", strconv.FormatInt(orderID, 10))
return resp,
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPIOrderStatus, false, req, &resp)
b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, bitstampAPIOrderStatus, false, req, &resp)
}
// CancelExistingOrder cancels order by ID
func (b *Bitstamp) CancelExistingOrder(orderID int64) (CancelOrder, error) {
func (b *Bitstamp) CancelExistingOrder(ctx context.Context, orderID int64) (CancelOrder, error) {
var req = url.Values{}
req.Add("id", strconv.FormatInt(orderID, 10))
var result CancelOrder
err := b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPICancelOrder, true, req, &result)
err := b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, bitstampAPICancelOrder, true, req, &result)
if err != nil {
return result, err
}
@@ -366,15 +366,15 @@ func (b *Bitstamp) CancelExistingOrder(orderID int64) (CancelOrder, error) {
}
// CancelAllExistingOrders cancels all open orders on the exchange
func (b *Bitstamp) CancelAllExistingOrders() (bool, error) {
func (b *Bitstamp) CancelAllExistingOrders(ctx context.Context) (bool, error) {
result := false
return result,
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPICancelAllOrders, false, nil, &result)
b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, bitstampAPICancelAllOrders, false, nil, &result)
}
// PlaceOrder places an order on the exchange.
func (b *Bitstamp) PlaceOrder(currencyPair string, price, amount float64, buy, market bool) (Order, error) {
func (b *Bitstamp) PlaceOrder(ctx context.Context, currencyPair string, price, amount float64, buy, market bool) (Order, error) {
var req = url.Values{}
req.Add("amount", strconv.FormatFloat(amount, 'f', -1, 64))
req.Add("price", strconv.FormatFloat(price, 'f', -1, 64))
@@ -393,13 +393,13 @@ func (b *Bitstamp) PlaceOrder(currencyPair string, price, amount float64, buy, m
}
return response,
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, path, true, req, &response)
b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, path, true, req, &response)
}
// GetWithdrawalRequests returns withdrawal requests for the account
// timedelta - positive integer with max value 50000000 which returns requests
// from number of seconds ago to now.
func (b *Bitstamp) GetWithdrawalRequests(timedelta int64) ([]WithdrawalRequests, error) {
func (b *Bitstamp) GetWithdrawalRequests(ctx context.Context, timedelta int64) ([]WithdrawalRequests, error) {
var resp []WithdrawalRequests
if timedelta > 50000000 || timedelta < 0 {
return resp, errors.New("time delta exceeded, max: 50000000 min: 0")
@@ -413,7 +413,7 @@ func (b *Bitstamp) GetWithdrawalRequests(timedelta int64) ([]WithdrawalRequests,
}
return resp,
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPIWithdrawalRequests, false, value, &resp)
b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, bitstampAPIWithdrawalRequests, false, value, &resp)
}
// CryptoWithdrawal withdraws a cryptocurrency into a supplied wallet, returns ID
@@ -422,7 +422,7 @@ func (b *Bitstamp) GetWithdrawalRequests(timedelta int64) ([]WithdrawalRequests,
// symbol - the type of crypto ie "ltc", "btc", "eth"
// destTag - only for XRP default to ""
// instant - only for bitcoins
func (b *Bitstamp) CryptoWithdrawal(amount float64, address, symbol, destTag string, instant bool) (CryptoWithdrawalResponse, error) {
func (b *Bitstamp) CryptoWithdrawal(ctx context.Context, amount float64, address, symbol, destTag string, instant bool) (CryptoWithdrawalResponse, error) {
var req = url.Values{}
req.Add("amount", strconv.FormatFloat(amount, 'f', -1, 64))
req.Add("address", address)
@@ -452,11 +452,11 @@ func (b *Bitstamp) CryptoWithdrawal(amount float64, address, symbol, destTag str
return resp, errors.New("incorrect symbol")
}
return resp, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, endpoint, false, req, &resp)
return resp, b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, endpoint, false, req, &resp)
}
// OpenBankWithdrawal Opens a bank withdrawal request (SEPA or international)
func (b *Bitstamp) OpenBankWithdrawal(amount float64, currency,
func (b *Bitstamp) OpenBankWithdrawal(ctx context.Context, amount float64, currency,
name, iban, bic, address, postalCode, city, country,
comment, withdrawalType string) (FIATWithdrawalResponse, error) {
var req = url.Values{}
@@ -473,11 +473,11 @@ func (b *Bitstamp) OpenBankWithdrawal(amount float64, currency,
req.Add("comment", comment)
resp := FIATWithdrawalResponse{}
return resp, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPIOpenWithdrawal, true, req, &resp)
return resp, b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, bitstampAPIOpenWithdrawal, true, req, &resp)
}
// OpenInternationalBankWithdrawal Opens a bank withdrawal request (international)
func (b *Bitstamp) OpenInternationalBankWithdrawal(amount float64, currency,
func (b *Bitstamp) OpenInternationalBankWithdrawal(ctx context.Context, amount float64, currency,
name, iban, bic, address, postalCode, city, country,
bankName, bankAddress, bankPostCode, bankCity, bankCountry, internationalCurrency,
comment, withdrawalType string) (FIATWithdrawalResponse, error) {
@@ -501,12 +501,12 @@ func (b *Bitstamp) OpenInternationalBankWithdrawal(amount float64, currency,
req.Add("bank_country", bankCountry)
resp := FIATWithdrawalResponse{}
return resp, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPIOpenWithdrawal, true, req, &resp)
return resp, b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, bitstampAPIOpenWithdrawal, true, req, &resp)
}
// GetCryptoDepositAddress returns a depositing address by crypto
// crypto - example "btc", "ltc", "eth", "xrp" or "bch"
func (b *Bitstamp) GetCryptoDepositAddress(crypto currency.Code) (string, error) {
func (b *Bitstamp) GetCryptoDepositAddress(ctx context.Context, crypto currency.Code) (string, error) {
var resp string
v2Resp := struct {
Address string `json:"address"`
@@ -515,23 +515,23 @@ func (b *Bitstamp) GetCryptoDepositAddress(crypto currency.Code) (string, error)
switch crypto {
case currency.BTC:
return resp,
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPIBitcoinDeposit, false, nil, &resp)
b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, bitstampAPIBitcoinDeposit, false, nil, &resp)
case currency.LTC:
return v2Resp.Address,
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPILitecoinDeposit, true, nil, &v2Resp)
b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, bitstampAPILitecoinDeposit, true, nil, &v2Resp)
case currency.ETH:
return v2Resp.Address,
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPIEthereumDeposit, true, nil, &v2Resp)
b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, bitstampAPIEthereumDeposit, true, nil, &v2Resp)
case currency.XRP:
return v2Resp.Address,
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPIXrpDeposit, true, nil, &v2Resp)
b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, bitstampAPIXrpDeposit, true, nil, &v2Resp)
case currency.BCH:
return v2Resp.Address,
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPIBitcoinCashDeposit, true, nil, &v2Resp)
b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, bitstampAPIBitcoinCashDeposit, true, nil, &v2Resp)
default:
return resp, fmt.Errorf("unsupported cryptocurrency string %s", crypto)
@@ -539,15 +539,15 @@ func (b *Bitstamp) GetCryptoDepositAddress(crypto currency.Code) (string, error)
}
// GetUnconfirmedBitcoinDeposits returns unconfirmed transactions
func (b *Bitstamp) GetUnconfirmedBitcoinDeposits() ([]UnconfirmedBTCTransactions, error) {
func (b *Bitstamp) GetUnconfirmedBitcoinDeposits(ctx context.Context) ([]UnconfirmedBTCTransactions, error) {
var response []UnconfirmedBTCTransactions
return response,
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, bitstampAPIUnconfirmedBitcoin, false, nil, &response)
b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, bitstampAPIUnconfirmedBitcoin, false, nil, &response)
}
// OHLC returns OHLCV data for step (interval)
func (b *Bitstamp) OHLC(currency string, start, end time.Time, step, limit string) (resp OHLCResponse, err error) {
func (b *Bitstamp) OHLC(ctx context.Context, currency string, start, end time.Time, step, limit string) (resp OHLCResponse, err error) {
var v = url.Values{}
v.Add("limit", limit)
v.Add("step", step)
@@ -561,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(exchange.RestSpot, common.EncodeURLValues("/v"+bitstampAPIVersion+"/"+bitstampOHLC+"/"+currency, v), &resp)
return resp, b.SendHTTPRequest(ctx, exchange.RestSpot, common.EncodeURLValues("/v"+bitstampAPIVersion+"/"+bitstampOHLC+"/"+currency, v), &resp)
}
// TransferAccountBalance transfers funds from either a main or sub account
@@ -569,7 +569,7 @@ func (b *Bitstamp) OHLC(currency string, start, end time.Time, step, limit strin
// currency - which currency to transfer
// subaccount - name of account
// toMain - bool either to or from account
func (b *Bitstamp) TransferAccountBalance(amount float64, currency, subAccount string, toMain bool) error {
func (b *Bitstamp) TransferAccountBalance(ctx context.Context, amount float64, currency, subAccount string, toMain bool) error {
var req = url.Values{}
req.Add("amount", strconv.FormatFloat(amount, 'f', -1, 64))
req.Add("currency", currency)
@@ -589,11 +589,11 @@ func (b *Bitstamp) TransferAccountBalance(amount float64, currency, subAccount s
var resp interface{}
return b.SendAuthenticatedHTTPRequest(exchange.RestSpot, path, true, req, &resp)
return b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, path, true, req, &resp)
}
// SendHTTPRequest sends an unauthenticated HTTP request
func (b *Bitstamp) SendHTTPRequest(ep exchange.URL, path string, result interface{}) error {
func (b *Bitstamp) SendHTTPRequest(ctx context.Context, ep exchange.URL, path string, result interface{}) error {
endpoint, err := b.API.Endpoints.GetURL(ep)
if err != nil {
return err
@@ -606,13 +606,13 @@ func (b *Bitstamp) SendHTTPRequest(ep exchange.URL, path string, result interfac
HTTPDebugging: b.HTTPDebugging,
HTTPRecording: b.HTTPRecording,
}
return b.SendPayload(context.Background(), request.Unset, func() (*request.Item, error) {
return b.SendPayload(ctx, request.Unset, func() (*request.Item, error) {
return item, nil
})
}
// SendAuthenticatedHTTPRequest sends an authenticated request
func (b *Bitstamp) SendAuthenticatedHTTPRequest(ep exchange.URL, path string, v2 bool, values url.Values, result interface{}) error {
func (b *Bitstamp) SendAuthenticatedHTTPRequest(ctx context.Context, ep exchange.URL, path string, v2 bool, values url.Values, result interface{}) error {
if !b.AllowAuthenticatedRequest() {
return fmt.Errorf("%s %w", b.Name, exchange.ErrAuthenticatedRequestWithoutCredentialsSet)
}
@@ -626,7 +626,7 @@ func (b *Bitstamp) SendAuthenticatedHTTPRequest(ep exchange.URL, path string, v2
}
interim := json.RawMessage{}
err = b.SendPayload(context.Background(), request.Unset, func() (*request.Item, error) {
err = b.SendPayload(ctx, request.Unset, func() (*request.Item, error) {
n := b.Requester.GetNonce(true).String()
values.Set("key", b.API.Credentials.Key)

View File

@@ -1,6 +1,7 @@
package bitstamp
import (
"context"
"errors"
"testing"
"time"
@@ -44,7 +45,7 @@ func TestGetFeeByTypeOfflineTradeFee(t *testing.T) {
t.Parallel()
var feeBuilder = setFeeBuilder()
_, err := b.GetFeeByType(feeBuilder)
_, err := b.GetFeeByType(context.Background(), feeBuilder)
if err != nil {
t.Fatal(err)
}
@@ -69,7 +70,7 @@ func TestGetFee(t *testing.T) {
var feeBuilder = setFeeBuilder()
// CryptocurrencyTradeFee Basic
if _, err := b.GetFee(feeBuilder); err != nil {
if _, err := b.GetFee(context.Background(), feeBuilder); err != nil {
t.Error(err)
}
@@ -77,35 +78,35 @@ func TestGetFee(t *testing.T) {
feeBuilder = setFeeBuilder()
feeBuilder.Amount = 1000
feeBuilder.PurchasePrice = 1000
if _, err := b.GetFee(feeBuilder); err != nil {
if _, err := b.GetFee(context.Background(), feeBuilder); err != nil {
t.Error(err)
}
// CryptocurrencyTradeFee IsMaker
feeBuilder = setFeeBuilder()
feeBuilder.IsMaker = true
if _, err := b.GetFee(feeBuilder); err != nil {
if _, err := b.GetFee(context.Background(), feeBuilder); err != nil {
t.Error(err)
}
// CryptocurrencyTradeFee Negative purchase price
feeBuilder = setFeeBuilder()
feeBuilder.PurchasePrice = -1000
if _, err := b.GetFee(feeBuilder); err != nil {
if _, err := b.GetFee(context.Background(), feeBuilder); err != nil {
t.Error(err)
}
// CryptocurrencyWithdrawalFee Basic
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.CryptocurrencyWithdrawalFee
if _, err := b.GetFee(feeBuilder); err != nil {
if _, err := b.GetFee(context.Background(), feeBuilder); err != nil {
t.Error(err)
}
// CryptocurrencyDepositFee Basic
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.CryptocurrencyDepositFee
if _, err := b.GetFee(feeBuilder); err != nil {
if _, err := b.GetFee(context.Background(), feeBuilder); err != nil {
t.Error(err)
}
@@ -113,7 +114,7 @@ func TestGetFee(t *testing.T) {
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.InternationalBankDepositFee
feeBuilder.FiatCurrency = currency.HKD
if _, err := b.GetFee(feeBuilder); err != nil {
if _, err := b.GetFee(context.Background(), feeBuilder); err != nil {
t.Error(err)
}
@@ -121,7 +122,7 @@ func TestGetFee(t *testing.T) {
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.InternationalBankWithdrawalFee
feeBuilder.FiatCurrency = currency.HKD
if _, err := b.GetFee(feeBuilder); err != nil {
if _, err := b.GetFee(context.Background(), feeBuilder); err != nil {
t.Error(err)
}
}
@@ -154,7 +155,8 @@ func TestCalculateTradingFee(t *testing.T) {
func TestGetTicker(t *testing.T) {
t.Parallel()
_, err := b.GetTicker(currency.BTC.String()+currency.USD.String(), false)
_, err := b.GetTicker(context.Background(),
currency.BTC.String()+currency.USD.String(), false)
if err != nil {
t.Error("GetTicker() error", err)
}
@@ -162,7 +164,8 @@ func TestGetTicker(t *testing.T) {
func TestGetOrderbook(t *testing.T) {
t.Parallel()
_, err := b.GetOrderbook(currency.BTC.String() + currency.USD.String())
_, err := b.GetOrderbook(context.Background(),
currency.BTC.String()+currency.USD.String())
if err != nil {
t.Error("GetOrderbook() error", err)
}
@@ -171,7 +174,7 @@ func TestGetOrderbook(t *testing.T) {
func TestGetTradingPairs(t *testing.T) {
t.Parallel()
_, err := b.GetTradingPairs()
_, err := b.GetTradingPairs(context.Background())
if err != nil {
t.Error("GetTradingPairs() error", err)
}
@@ -179,7 +182,7 @@ func TestGetTradingPairs(t *testing.T) {
func TestFetchTradablePairs(t *testing.T) {
t.Parallel()
r, err := b.FetchTradablePairs(asset.Spot)
r, err := b.FetchTradablePairs(context.Background(), asset.Spot)
if err != nil {
t.Fatal(err)
}
@@ -200,7 +203,8 @@ func TestFetchTradablePairs(t *testing.T) {
func TestGetTransactions(t *testing.T) {
t.Parallel()
_, err := b.GetTransactions(currency.BTC.String()+currency.USD.String(), "hour")
_, err := b.GetTransactions(context.Background(),
currency.BTC.String()+currency.USD.String(), "hour")
if err != nil {
t.Error("GetTransactions() error", err)
}
@@ -209,7 +213,7 @@ func TestGetTransactions(t *testing.T) {
func TestGetEURUSDConversionRate(t *testing.T) {
t.Parallel()
_, err := b.GetEURUSDConversionRate()
_, err := b.GetEURUSDConversionRate(context.Background())
if err != nil {
t.Error("GetEURUSDConversionRate() error", err)
}
@@ -217,7 +221,7 @@ func TestGetEURUSDConversionRate(t *testing.T) {
func TestGetBalance(t *testing.T) {
t.Parallel()
_, err := b.GetBalance()
_, err := b.GetBalance(context.Background())
switch {
case areTestAPIKeysSet() && err != nil && !mockTests:
t.Error("GetBalance() error", err)
@@ -231,7 +235,7 @@ func TestGetBalance(t *testing.T) {
func TestGetUserTransactions(t *testing.T) {
t.Parallel()
_, err := b.GetUserTransactions("btcusd")
_, err := b.GetUserTransactions(context.Background(), "btcusd")
switch {
case areTestAPIKeysSet() && err != nil && !mockTests:
t.Error("GetUserTransactions() error", err)
@@ -245,7 +249,7 @@ func TestGetUserTransactions(t *testing.T) {
func TestGetOpenOrders(t *testing.T) {
t.Parallel()
_, err := b.GetOpenOrders("btcusd")
_, err := b.GetOpenOrders(context.Background(), "btcusd")
switch {
case areTestAPIKeysSet() && err != nil && !mockTests:
t.Error("GetOpenOrders() error", err)
@@ -259,7 +263,7 @@ func TestGetOpenOrders(t *testing.T) {
func TestGetOrderStatus(t *testing.T) {
t.Parallel()
_, err := b.GetOrderStatus(1337)
_, err := b.GetOrderStatus(context.Background(), 1337)
switch {
case areTestAPIKeysSet() && err != nil && !mockTests:
t.Error("GetOrderStatus() error", err)
@@ -273,7 +277,7 @@ func TestGetOrderStatus(t *testing.T) {
func TestGetWithdrawalRequests(t *testing.T) {
t.Parallel()
_, err := b.GetWithdrawalRequests(0)
_, err := b.GetWithdrawalRequests(context.Background(), 0)
switch {
case areTestAPIKeysSet() && err != nil && !mockTests:
t.Error("GetWithdrawalRequests() error", err)
@@ -287,7 +291,7 @@ func TestGetWithdrawalRequests(t *testing.T) {
func TestGetUnconfirmedBitcoinDeposits(t *testing.T) {
t.Parallel()
_, err := b.GetUnconfirmedBitcoinDeposits()
_, err := b.GetUnconfirmedBitcoinDeposits(context.Background())
switch {
case areTestAPIKeysSet() && err != nil && !mockTests:
t.Error("GetUnconfirmedBitcoinDeposits() error", err)
@@ -305,7 +309,8 @@ func TestTransferAccountBalance(t *testing.T) {
t.Skip()
}
err := b.TransferAccountBalance(0.01, "btc", "testAccount", true)
err := b.TransferAccountBalance(context.Background(),
0.01, "btc", "testAccount", true)
if !mockTests && err != nil {
t.Error("TransferAccountBalance() error", err)
}
@@ -336,7 +341,7 @@ func TestGetActiveOrders(t *testing.T) {
AssetType: asset.Spot,
}
_, err := b.GetActiveOrders(&getOrdersRequest)
_, err := b.GetActiveOrders(context.Background(), &getOrdersRequest)
switch {
case areTestAPIKeysSet() && err != nil && !mockTests:
t.Errorf("Could not get open orders: %s", err)
@@ -355,7 +360,7 @@ func TestGetOrderHistory(t *testing.T) {
AssetType: asset.Spot,
}
_, err := b.GetOrderHistory(&getOrdersRequest)
_, err := b.GetOrderHistory(context.Background(), &getOrdersRequest)
switch {
case areTestAPIKeysSet() && err != nil && !mockTests:
t.Errorf("Could not get order history: %s", err)
@@ -388,7 +393,7 @@ func TestSubmitOrder(t *testing.T) {
ClientID: "meowOrder",
AssetType: asset.Spot,
}
response, err := b.SubmitOrder(orderSubmission)
response, err := b.SubmitOrder(context.Background(), orderSubmission)
switch {
case areTestAPIKeysSet() && (err != nil || !response.IsOrderPlaced) && !mockTests:
t.Errorf("Order failed to be placed: %v", err)
@@ -410,7 +415,7 @@ func TestCancelExchangeOrder(t *testing.T) {
ID: "1234",
AssetType: asset.Spot,
}
err := b.CancelOrder(orderCancellation)
err := b.CancelOrder(context.Background(), orderCancellation)
switch {
case !areTestAPIKeysSet() && err == nil && !mockTests:
t.Error("Expecting an error when no keys are set")
@@ -428,7 +433,8 @@ func TestCancelAllExchangeOrders(t *testing.T) {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}
resp, err := b.CancelAllOrders(&order.Cancel{AssetType: asset.Spot})
resp, err := b.CancelAllOrders(context.Background(),
&order.Cancel{AssetType: asset.Spot})
switch {
case !areTestAPIKeysSet() && err == nil && !mockTests:
t.Error("Expecting an error when no keys are set")
@@ -446,7 +452,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
func TestModifyOrder(t *testing.T) {
t.Parallel()
_, err := b.ModifyOrder(&order.Modify{AssetType: asset.Spot})
_, err := b.ModifyOrder(context.Background(), &order.Modify{AssetType: asset.Spot})
if err == nil {
t.Error("ModifyOrder() Expected error")
}
@@ -468,7 +474,7 @@ func TestWithdraw(t *testing.T) {
},
}
_, err := b.WithdrawCryptocurrencyFunds(&withdrawCryptoRequest)
_, err := b.WithdrawCryptocurrencyFunds(context.Background(), &withdrawCryptoRequest)
switch {
case !areTestAPIKeysSet() && err == nil && !mockTests:
t.Error("Expecting an error when no keys are set")
@@ -508,7 +514,7 @@ func TestWithdrawFiat(t *testing.T) {
Description: "WITHDRAW IT ALL",
}
_, err := b.WithdrawFiatFunds(&withdrawFiatRequest)
_, err := b.WithdrawFiatFunds(context.Background(), &withdrawFiatRequest)
switch {
case !areTestAPIKeysSet() && err == nil && !mockTests:
t.Error("Expecting an error when no keys are set")
@@ -554,7 +560,8 @@ func TestWithdrawInternationalBank(t *testing.T) {
Description: "WITHDRAW IT ALL",
}
_, err := b.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
_, err := b.WithdrawFiatFundsToInternationalBank(context.Background(),
&withdrawFiatRequest)
switch {
case !areTestAPIKeysSet() && err == nil && !mockTests:
t.Error("Expecting an error when no keys are set")
@@ -568,7 +575,7 @@ func TestWithdrawInternationalBank(t *testing.T) {
func TestGetDepositAddress(t *testing.T) {
t.Parallel()
_, err := b.GetDepositAddress(currency.BTC, "")
_, err := b.GetDepositAddress(context.Background(), currency.BTC, "")
switch {
case areTestAPIKeysSet() && customerID != "" && err != nil && !mockTests:
t.Error("GetDepositAddress error", err)
@@ -674,7 +681,7 @@ func TestWsRequestReconnect(t *testing.T) {
func TestBitstamp_OHLC(t *testing.T) {
start := time.Unix(1546300800, 0)
end := time.Unix(1577836799, 0)
_, err := b.OHLC("btcusd", start, end, "60", "10")
_, err := b.OHLC(context.Background(), "btcusd", start, end, "60", "10")
if err != nil {
t.Fatal(err)
}
@@ -688,7 +695,8 @@ func TestBitstamp_GetHistoricCandles(t *testing.T) {
start := time.Unix(1546300800, 0)
end := time.Unix(1577836799, 0)
_, err = b.GetHistoricCandles(currencyPair, asset.Spot, start, end, kline.OneDay)
_, err = b.GetHistoricCandles(context.Background(),
currencyPair, asset.Spot, start, end, kline.OneDay)
if err != nil {
t.Fatal(err)
}
@@ -701,7 +709,8 @@ func TestBitstamp_GetHistoricCandlesExtended(t *testing.T) {
}
start := time.Unix(1546300800, 0)
end := time.Unix(1577836799, 0)
_, err = b.GetHistoricCandlesExtended(currencyPair, asset.Spot, start, end, kline.OneDay)
_, err = b.GetHistoricCandlesExtended(context.Background(),
currencyPair, asset.Spot, start, end, kline.OneDay)
if err != nil {
t.Fatal(err)
}
@@ -713,7 +722,7 @@ func TestGetRecentTrades(t *testing.T) {
if err != nil {
t.Fatal(err)
}
_, err = b.GetRecentTrades(currencyPair, asset.Spot)
_, err = b.GetRecentTrades(context.Background(), currencyPair, asset.Spot)
if err != nil {
t.Error(err)
}
@@ -725,7 +734,8 @@ func TestGetHistoricTrades(t *testing.T) {
if err != nil {
t.Fatal(err)
}
_, err = b.GetHistoricTrades(currencyPair, asset.Spot, time.Now().Add(-time.Minute*15), time.Now())
_, err = b.GetHistoricTrades(context.Background(),
currencyPair, asset.Spot, time.Now().Add(-time.Minute*15), time.Now())
if err != nil && err != common.ErrFunctionNotSupported {
t.Error(err)
}

View File

@@ -1,6 +1,7 @@
package bitstamp
import (
"context"
"encoding/json"
"errors"
"net/http"
@@ -36,7 +37,7 @@ func (b *Bitstamp) WsConnect() error {
if b.Verbose {
log.Debugf(log.ExchangeSys, "%s Connected to Websocket.\n", b.Name)
}
err = b.seedOrderBook()
err = b.seedOrderBook(context.TODO())
if err != nil {
b.Websocket.DataHandler <- err
}
@@ -293,7 +294,7 @@ func (b *Bitstamp) wsUpdateOrderbook(update websocketOrderBook, p currency.Pair,
})
}
func (b *Bitstamp) seedOrderBook() error {
func (b *Bitstamp) seedOrderBook(ctx context.Context) error {
p, err := b.GetEnabledPairs(asset.Spot)
if err != nil {
return err
@@ -304,7 +305,7 @@ func (b *Bitstamp) seedOrderBook() error {
if err != nil {
return err
}
orderbookSeed, err := b.GetOrderbook(pairFmt.String())
orderbookSeed, err := b.GetOrderbook(ctx, pairFmt.String())
if err != nil {
return err
}

View File

@@ -1,6 +1,7 @@
package bitstamp
import (
"context"
"errors"
"sort"
"strconv"
@@ -39,7 +40,7 @@ func (b *Bitstamp) GetDefaultConfig() (*config.ExchangeConfig, error) {
}
if b.Features.Supports.RESTCapabilities.AutoPairUpdates {
err = b.UpdateTradablePairs(true)
err = b.UpdateTradablePairs(context.TODO(), true)
if err != nil {
return nil, err
}
@@ -261,7 +262,7 @@ func (b *Bitstamp) Run() {
return
}
err = b.UpdateTradablePairs(forceUpdate)
err = b.UpdateTradablePairs(context.TODO(), forceUpdate)
if err != nil {
log.Errorf(log.ExchangeSys,
"%s failed to update tradable pairs. Err: %s",
@@ -271,8 +272,8 @@ func (b *Bitstamp) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (b *Bitstamp) FetchTradablePairs(asset asset.Item) ([]string, error) {
pairs, err := b.GetTradingPairs()
func (b *Bitstamp) FetchTradablePairs(ctx context.Context, asset asset.Item) ([]string, error) {
pairs, err := b.GetTradingPairs(ctx)
if err != nil {
return nil, err
}
@@ -290,8 +291,8 @@ func (b *Bitstamp) FetchTradablePairs(asset asset.Item) ([]string, error) {
// UpdateTradablePairs updates the exchanges available pairs and stores
// them in the exchanges config
func (b *Bitstamp) UpdateTradablePairs(forceUpdate bool) error {
pairs, err := b.FetchTradablePairs(asset.Spot)
func (b *Bitstamp) UpdateTradablePairs(ctx context.Context, forceUpdate bool) error {
pairs, err := b.FetchTradablePairs(ctx, asset.Spot)
if err != nil {
return err
}
@@ -305,18 +306,18 @@ func (b *Bitstamp) UpdateTradablePairs(forceUpdate bool) error {
}
// UpdateTickers updates the ticker for all currency pairs of a given asset type
func (b *Bitstamp) UpdateTickers(a asset.Item) error {
func (b *Bitstamp) UpdateTickers(ctx context.Context, a asset.Item) error {
return common.ErrFunctionNotSupported
}
// UpdateTicker updates and returns the ticker for a currency pair
func (b *Bitstamp) UpdateTicker(p currency.Pair, a asset.Item) (*ticker.Price, error) {
func (b *Bitstamp) UpdateTicker(ctx context.Context, p currency.Pair, a asset.Item) (*ticker.Price, error) {
fPair, err := b.FormatExchangeCurrency(p, a)
if err != nil {
return nil, err
}
tick, err := b.GetTicker(fPair.String(), false)
tick, err := b.GetTicker(ctx, fPair.String(), false)
if err != nil {
return nil, err
}
@@ -341,7 +342,7 @@ func (b *Bitstamp) UpdateTicker(p currency.Pair, a asset.Item) (*ticker.Price, e
}
// FetchTicker returns the ticker for a currency pair
func (b *Bitstamp) FetchTicker(p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
func (b *Bitstamp) FetchTicker(ctx context.Context, p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
fPair, err := b.FormatExchangeCurrency(p, assetType)
if err != nil {
return nil, err
@@ -349,22 +350,22 @@ func (b *Bitstamp) FetchTicker(p currency.Pair, assetType asset.Item) (*ticker.P
tick, err := ticker.GetTicker(b.Name, fPair, assetType)
if err != nil {
return b.UpdateTicker(fPair, assetType)
return b.UpdateTicker(ctx, fPair, assetType)
}
return tick, nil
}
// GetFeeByType returns an estimate of fee based on type of transaction
func (b *Bitstamp) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error) {
func (b *Bitstamp) GetFeeByType(ctx context.Context, feeBuilder *exchange.FeeBuilder) (float64, error) {
if (!b.AllowAuthenticatedRequest() || b.SkipAuthCheck) && // Todo check connection status
feeBuilder.FeeType == exchange.CryptocurrencyTradeFee {
feeBuilder.FeeType = exchange.OfflineTradeFee
}
return b.GetFee(feeBuilder)
return b.GetFee(ctx, feeBuilder)
}
// FetchOrderbook returns the orderbook for a currency pair
func (b *Bitstamp) FetchOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
func (b *Bitstamp) FetchOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
fPair, err := b.FormatExchangeCurrency(p, assetType)
if err != nil {
return nil, err
@@ -372,13 +373,13 @@ func (b *Bitstamp) FetchOrderbook(p currency.Pair, assetType asset.Item) (*order
ob, err := orderbook.Get(b.Name, fPair, assetType)
if err != nil {
return b.UpdateOrderbook(fPair, assetType)
return b.UpdateOrderbook(ctx, fPair, assetType)
}
return ob, nil
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (b *Bitstamp) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
func (b *Bitstamp) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
book := &orderbook.Base{
Exchange: b.Name,
Pair: p,
@@ -390,7 +391,7 @@ func (b *Bitstamp) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orde
return book, err
}
orderbookNew, err := b.GetOrderbook(fPair.String())
orderbookNew, err := b.GetOrderbook(ctx, fPair.String())
if err != nil {
return book, err
}
@@ -417,10 +418,10 @@ 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(assetType asset.Item) (account.Holdings, error) {
func (b *Bitstamp) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (account.Holdings, error) {
var response account.Holdings
response.Exchange = b.Name
accountBalance, err := b.GetBalance()
accountBalance, err := b.GetBalance(ctx)
if err != nil {
return response, err
}
@@ -446,10 +447,10 @@ func (b *Bitstamp) UpdateAccountInfo(assetType asset.Item) (account.Holdings, er
}
// FetchAccountInfo retrieves balances for all enabled currencies
func (b *Bitstamp) FetchAccountInfo(assetType asset.Item) (account.Holdings, error) {
func (b *Bitstamp) FetchAccountInfo(ctx context.Context, assetType asset.Item) (account.Holdings, error) {
acc, err := account.GetHoldings(b.Name, assetType)
if err != nil {
return b.UpdateAccountInfo(assetType)
return b.UpdateAccountInfo(ctx, assetType)
}
return acc, nil
@@ -457,24 +458,24 @@ func (b *Bitstamp) FetchAccountInfo(assetType asset.Item) (account.Holdings, err
// GetFundingHistory returns funding history, deposits and
// withdrawals
func (b *Bitstamp) GetFundingHistory() ([]exchange.FundHistory, error) {
func (b *Bitstamp) GetFundingHistory(ctx context.Context) ([]exchange.FundHistory, error) {
return nil, common.ErrFunctionNotSupported
}
// GetWithdrawalsHistory returns previous withdrawals data
func (b *Bitstamp) GetWithdrawalsHistory(c currency.Code) (resp []exchange.WithdrawalHistory, err error) {
func (b *Bitstamp) GetWithdrawalsHistory(ctx context.Context, c currency.Code) (resp []exchange.WithdrawalHistory, err error) {
return nil, common.ErrNotYetImplemented
}
// GetRecentTrades returns the most recent trades for a currency and asset
func (b *Bitstamp) GetRecentTrades(p currency.Pair, assetType asset.Item) ([]trade.Data, error) {
func (b *Bitstamp) GetRecentTrades(ctx context.Context, p currency.Pair, assetType asset.Item) ([]trade.Data, error) {
var err error
p, err = b.FormatExchangeCurrency(p, assetType)
if err != nil {
return nil, err
}
var tradeData []Transactions
tradeData, err = b.GetTransactions(p.String(), "")
tradeData, err = b.GetTransactions(ctx, p.String(), "")
if err != nil {
return nil, err
}
@@ -506,12 +507,12 @@ func (b *Bitstamp) GetRecentTrades(p currency.Pair, assetType asset.Item) ([]tra
}
// GetHistoricTrades returns historic trade data within the timeframe provided
func (b *Bitstamp) GetHistoricTrades(_ currency.Pair, _ asset.Item, _, _ time.Time) ([]trade.Data, error) {
func (b *Bitstamp) GetHistoricTrades(_ context.Context, _ currency.Pair, _ asset.Item, _, _ time.Time) ([]trade.Data, error) {
return nil, common.ErrFunctionNotSupported
}
// SubmitOrder submits a new order
func (b *Bitstamp) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
func (b *Bitstamp) SubmitOrder(ctx context.Context, s *order.Submit) (order.SubmitResponse, error) {
var submitOrderResponse order.SubmitResponse
if err := s.Validate(); err != nil {
return submitOrderResponse, err
@@ -524,7 +525,8 @@ func (b *Bitstamp) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
buy := s.Side == order.Buy
market := s.Type == order.Market
response, err := b.PlaceOrder(fPair.String(),
response, err := b.PlaceOrder(ctx,
fPair.String(),
s.Price,
s.Amount,
buy,
@@ -545,12 +547,12 @@ func (b *Bitstamp) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
// ModifyOrder will allow of changing orderbook placement and limit to
// market conversion
func (b *Bitstamp) ModifyOrder(action *order.Modify) (order.Modify, error) {
func (b *Bitstamp) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) {
return order.Modify{}, common.ErrFunctionNotSupported
}
// CancelOrder cancels an order by its corresponding ID number
func (b *Bitstamp) CancelOrder(o *order.Cancel) error {
func (b *Bitstamp) CancelOrder(ctx context.Context, o *order.Cancel) error {
if err := o.Validate(o.StandardCancel()); err != nil {
return err
}
@@ -559,18 +561,18 @@ func (b *Bitstamp) CancelOrder(o *order.Cancel) error {
if err != nil {
return err
}
_, err = b.CancelExistingOrder(orderIDInt)
_, err = b.CancelExistingOrder(ctx, orderIDInt)
return err
}
// CancelBatchOrders cancels an orders by their corresponding ID numbers
func (b *Bitstamp) CancelBatchOrders(o []order.Cancel) (order.CancelBatchResponse, error) {
func (b *Bitstamp) CancelBatchOrders(ctx context.Context, o []order.Cancel) (order.CancelBatchResponse, error) {
return order.CancelBatchResponse{}, common.ErrNotYetImplemented
}
// CancelAllOrders cancels all orders associated with a currency pair
func (b *Bitstamp) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
success, err := b.CancelAllExistingOrders()
func (b *Bitstamp) CancelAllOrders(ctx context.Context, _ *order.Cancel) (order.CancelAllResponse, error) {
success, err := b.CancelAllExistingOrders(ctx)
if err != nil {
return order.CancelAllResponse{}, err
}
@@ -582,23 +584,24 @@ func (b *Bitstamp) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, er
}
// GetOrderInfo returns order information based on order ID
func (b *Bitstamp) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
func (b *Bitstamp) GetOrderInfo(ctx context.Context, orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
var orderDetail order.Detail
return orderDetail, common.ErrNotYetImplemented
}
// GetDepositAddress returns a deposit address for a specified currency
func (b *Bitstamp) GetDepositAddress(cryptocurrency currency.Code, _ string) (string, error) {
return b.GetCryptoDepositAddress(cryptocurrency)
func (b *Bitstamp) GetDepositAddress(ctx context.Context, cryptocurrency currency.Code, _ string) (string, error) {
return b.GetCryptoDepositAddress(ctx, cryptocurrency)
}
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
// submitted
func (b *Bitstamp) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
func (b *Bitstamp) WithdrawCryptocurrencyFunds(ctx context.Context, withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
if err := withdrawRequest.Validate(); err != nil {
return nil, err
}
resp, err := b.CryptoWithdrawal(withdrawRequest.Amount,
resp, err := b.CryptoWithdrawal(ctx,
withdrawRequest.Amount,
withdrawRequest.Crypto.Address,
withdrawRequest.Currency.String(),
withdrawRequest.Crypto.AddressTag,
@@ -621,11 +624,12 @@ func (b *Bitstamp) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request
// WithdrawFiatFunds returns a withdrawal ID when a
// withdrawal is submitted
func (b *Bitstamp) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
func (b *Bitstamp) WithdrawFiatFunds(ctx context.Context, withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
if err := withdrawRequest.Validate(); err != nil {
return nil, err
}
resp, err := b.OpenBankWithdrawal(withdrawRequest.Amount,
resp, err := b.OpenBankWithdrawal(ctx,
withdrawRequest.Amount,
withdrawRequest.Currency.String(),
withdrawRequest.Fiat.Bank.AccountName,
withdrawRequest.Fiat.Bank.IBAN,
@@ -655,11 +659,12 @@ func (b *Bitstamp) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdr
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
// withdrawal is submitted
func (b *Bitstamp) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
func (b *Bitstamp) WithdrawFiatFundsToInternationalBank(ctx context.Context, withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
if err := withdrawRequest.Validate(); err != nil {
return nil, err
}
resp, err := b.OpenInternationalBankWithdrawal(withdrawRequest.Amount,
resp, err := b.OpenInternationalBankWithdrawal(ctx,
withdrawRequest.Amount,
withdrawRequest.Currency.String(),
withdrawRequest.Fiat.Bank.AccountName,
withdrawRequest.Fiat.Bank.IBAN,
@@ -694,7 +699,7 @@ func (b *Bitstamp) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdra
}
// GetActiveOrders retrieves any orders that are active/open
func (b *Bitstamp) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
func (b *Bitstamp) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequest) ([]order.Detail, error) {
if err := req.Validate(); err != nil {
return nil, err
}
@@ -710,7 +715,7 @@ func (b *Bitstamp) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail,
currPair = fPair.String()
}
resp, err := b.GetOpenOrders(currPair)
resp, err := b.GetOpenOrders(ctx, currPair)
if err != nil {
return nil, err
}
@@ -759,7 +764,7 @@ func (b *Bitstamp) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail,
// GetOrderHistory retrieves account order information
// Can Limit response to specific order status
func (b *Bitstamp) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
func (b *Bitstamp) GetOrderHistory(ctx context.Context, req *order.GetOrdersRequest) ([]order.Detail, error) {
if err := req.Validate(); err != nil {
return nil, err
}
@@ -778,7 +783,7 @@ func (b *Bitstamp) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail,
return nil, err
}
resp, err := b.GetUserTransactions(currPair)
resp, err := b.GetUserTransactions(ctx, currPair)
if err != nil {
return nil, err
}
@@ -842,13 +847,13 @@ func (b *Bitstamp) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail,
// ValidateCredentials validates current credentials used for wrapper
// functionality
func (b *Bitstamp) ValidateCredentials(assetType asset.Item) error {
_, err := b.UpdateAccountInfo(assetType)
func (b *Bitstamp) ValidateCredentials(ctx context.Context, assetType asset.Item) error {
_, err := b.UpdateAccountInfo(ctx, assetType)
return b.CheckTransientError(err)
}
// GetHistoricCandles returns candles between a time period for a set time interval
func (b *Bitstamp) GetHistoricCandles(pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
func (b *Bitstamp) GetHistoricCandles(ctx context.Context, pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
if err := b.ValidateKline(pair, a, interval); err != nil {
return kline.Item{}, err
}
@@ -865,7 +870,7 @@ func (b *Bitstamp) GetHistoricCandles(pair currency.Pair, a asset.Item, start, e
return kline.Item{}, err
}
candles, err := b.OHLC(
candles, err := b.OHLC(ctx,
formattedPair.Lower().String(),
start,
end,
@@ -897,7 +902,7 @@ func (b *Bitstamp) GetHistoricCandles(pair currency.Pair, a asset.Item, start, e
}
// GetHistoricCandlesExtended returns candles between a time period for a set time interval
func (b *Bitstamp) GetHistoricCandlesExtended(pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
func (b *Bitstamp) GetHistoricCandlesExtended(ctx context.Context, pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
if err := b.ValidateKline(pair, a, interval); err != nil {
return kline.Item{}, err
}
@@ -920,7 +925,7 @@ func (b *Bitstamp) GetHistoricCandlesExtended(pair currency.Pair, a asset.Item,
for x := range dates.Ranges {
var candles OHLCResponse
candles, err = b.OHLC(
candles, err = b.OHLC(ctx,
formattedPair.Lower().String(),
dates.Ranges[x].Start.Time,
dates.Ranges[x].End.Time,