mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-02 23:16:51 +00:00
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:
@@ -45,7 +45,7 @@ type ZB struct {
|
||||
}
|
||||
|
||||
// SpotNewOrder submits an order to ZB
|
||||
func (z *ZB) SpotNewOrder(arg SpotNewOrderRequestParams) (int64, error) {
|
||||
func (z *ZB) SpotNewOrder(ctx context.Context, arg SpotNewOrderRequestParams) (int64, error) {
|
||||
var result SpotNewOrderResponse
|
||||
|
||||
vals := url.Values{}
|
||||
@@ -56,7 +56,7 @@ func (z *ZB) SpotNewOrder(arg SpotNewOrderRequestParams) (int64, error) {
|
||||
vals.Set("price", strconv.FormatFloat(arg.Price, 'f', -1, 64))
|
||||
vals.Set("tradeType", string(arg.Type))
|
||||
|
||||
err := z.SendAuthenticatedHTTPRequest(exchange.RestSpotSupplementary, http.MethodGet, vals, &result, request.Auth)
|
||||
err := z.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, vals, &result, request.Auth)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -71,7 +71,7 @@ func (z *ZB) SpotNewOrder(arg SpotNewOrderRequestParams) (int64, error) {
|
||||
}
|
||||
|
||||
// CancelExistingOrder cancels an order
|
||||
func (z *ZB) CancelExistingOrder(orderID int64, symbol string) error {
|
||||
func (z *ZB) CancelExistingOrder(ctx context.Context, orderID int64, symbol string) error {
|
||||
type response struct {
|
||||
Code int `json:"code"` // Result code
|
||||
Message string `json:"message"` // Result Message
|
||||
@@ -84,7 +84,7 @@ func (z *ZB) CancelExistingOrder(orderID int64, symbol string) error {
|
||||
vals.Set("currency", symbol)
|
||||
|
||||
var result response
|
||||
err := z.SendAuthenticatedHTTPRequest(exchange.RestSpotSupplementary, http.MethodGet, vals, &result, request.Auth)
|
||||
err := z.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, vals, &result, request.Auth)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -97,18 +97,18 @@ func (z *ZB) CancelExistingOrder(orderID int64, symbol string) error {
|
||||
|
||||
// GetAccountInformation returns account information including coin information
|
||||
// and pricing
|
||||
func (z *ZB) GetAccountInformation() (AccountsResponse, error) {
|
||||
func (z *ZB) GetAccountInformation(ctx context.Context) (AccountsResponse, error) {
|
||||
var result AccountsResponse
|
||||
|
||||
vals := url.Values{}
|
||||
vals.Set("accesskey", z.API.Credentials.Key)
|
||||
vals.Set("method", "getAccountInfo")
|
||||
|
||||
return result, z.SendAuthenticatedHTTPRequest(exchange.RestSpotSupplementary, http.MethodGet, vals, &result, request.Auth)
|
||||
return result, z.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, vals, &result, request.Auth)
|
||||
}
|
||||
|
||||
// GetUnfinishedOrdersIgnoreTradeType returns unfinished orders
|
||||
func (z *ZB) GetUnfinishedOrdersIgnoreTradeType(currency string, pageindex, pagesize int64) ([]Order, error) {
|
||||
func (z *ZB) GetUnfinishedOrdersIgnoreTradeType(ctx context.Context, currency string, pageindex, pagesize int64) ([]Order, error) {
|
||||
var result []Order
|
||||
vals := url.Values{}
|
||||
vals.Set("accesskey", z.API.Credentials.Key)
|
||||
@@ -117,12 +117,12 @@ func (z *ZB) GetUnfinishedOrdersIgnoreTradeType(currency string, pageindex, page
|
||||
vals.Set("pageIndex", strconv.FormatInt(pageindex, 10))
|
||||
vals.Set("pageSize", strconv.FormatInt(pagesize, 10))
|
||||
|
||||
err := z.SendAuthenticatedHTTPRequest(exchange.RestSpotSupplementary, http.MethodGet, vals, &result, request.Auth)
|
||||
err := z.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, vals, &result, request.Auth)
|
||||
return result, err
|
||||
}
|
||||
|
||||
// GetOrders returns finished orders
|
||||
func (z *ZB) GetOrders(currency string, pageindex, side int64) ([]Order, error) {
|
||||
func (z *ZB) GetOrders(ctx context.Context, currency string, pageindex, side int64) ([]Order, error) {
|
||||
var response []Order
|
||||
vals := url.Values{}
|
||||
vals.Set("accesskey", z.API.Credentials.Key)
|
||||
@@ -130,16 +130,16 @@ func (z *ZB) GetOrders(currency string, pageindex, side int64) ([]Order, error)
|
||||
vals.Set("currency", currency)
|
||||
vals.Set("pageIndex", strconv.FormatInt(pageindex, 10))
|
||||
vals.Set("tradeType", strconv.FormatInt(side, 10))
|
||||
return response, z.SendAuthenticatedHTTPRequest(exchange.RestSpotSupplementary, http.MethodGet, vals, &response, request.Auth)
|
||||
return response, z.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, vals, &response, request.Auth)
|
||||
}
|
||||
|
||||
// GetMarkets returns market information including pricing, symbols and
|
||||
// each symbols decimal precision
|
||||
func (z *ZB) GetMarkets() (map[string]MarketResponseItem, error) {
|
||||
func (z *ZB) GetMarkets(ctx context.Context) (map[string]MarketResponseItem, error) {
|
||||
endpoint := fmt.Sprintf("/%s/%s/%s", zbData, zbAPIVersion, zbMarkets)
|
||||
|
||||
var res map[string]MarketResponseItem
|
||||
err := z.SendHTTPRequest(exchange.RestSpot, endpoint, &res, request.UnAuth)
|
||||
err := z.SendHTTPRequest(ctx, exchange.RestSpot, endpoint, &res, request.UnAuth)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -151,9 +151,8 @@ func (z *ZB) GetMarkets() (map[string]MarketResponseItem, error) {
|
||||
//
|
||||
// symbol: string of currency pair
|
||||
// 获取最新价格
|
||||
func (z *ZB) GetLatestSpotPrice(symbol string) (float64, error) {
|
||||
res, err := z.GetTicker(symbol)
|
||||
|
||||
func (z *ZB) GetLatestSpotPrice(ctx context.Context, symbol string) (float64, error) {
|
||||
res, err := z.GetTicker(ctx, symbol)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -162,35 +161,35 @@ func (z *ZB) GetLatestSpotPrice(symbol string) (float64, error) {
|
||||
}
|
||||
|
||||
// GetTicker returns a ticker for a given symbol
|
||||
func (z *ZB) GetTicker(symbol string) (TickerResponse, error) {
|
||||
func (z *ZB) GetTicker(ctx context.Context, symbol string) (TickerResponse, error) {
|
||||
urlPath := fmt.Sprintf("/%s/%s/%s?market=%s", zbData, zbAPIVersion, zbTicker, symbol)
|
||||
var res TickerResponse
|
||||
err := z.SendHTTPRequest(exchange.RestSpot, urlPath, &res, request.UnAuth)
|
||||
err := z.SendHTTPRequest(ctx, exchange.RestSpot, urlPath, &res, request.UnAuth)
|
||||
return res, err
|
||||
}
|
||||
|
||||
// GetTrades returns trades for a given symbol
|
||||
func (z *ZB) GetTrades(symbol string) (TradeHistory, error) {
|
||||
func (z *ZB) GetTrades(ctx context.Context, symbol string) (TradeHistory, error) {
|
||||
urlPath := fmt.Sprintf("/%s/%s/%s?market=%s", zbData, zbAPIVersion, zbTrades, symbol)
|
||||
var res TradeHistory
|
||||
err := z.SendHTTPRequest(exchange.RestSpot, urlPath, &res, request.UnAuth)
|
||||
err := z.SendHTTPRequest(ctx, exchange.RestSpot, urlPath, &res, request.UnAuth)
|
||||
return res, err
|
||||
}
|
||||
|
||||
// GetTickers returns ticker data for all supported symbols
|
||||
func (z *ZB) GetTickers() (map[string]TickerChildResponse, error) {
|
||||
func (z *ZB) GetTickers(ctx context.Context) (map[string]TickerChildResponse, error) {
|
||||
urlPath := fmt.Sprintf("/%s/%s/%s", zbData, zbAPIVersion, zbTickers)
|
||||
resp := make(map[string]TickerChildResponse)
|
||||
err := z.SendHTTPRequest(exchange.RestSpot, urlPath, &resp, request.UnAuth)
|
||||
err := z.SendHTTPRequest(ctx, exchange.RestSpot, urlPath, &resp, request.UnAuth)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// GetOrderbook returns the orderbook for a given symbol
|
||||
func (z *ZB) GetOrderbook(symbol string) (OrderbookResponse, error) {
|
||||
func (z *ZB) GetOrderbook(ctx context.Context, symbol string) (OrderbookResponse, error) {
|
||||
urlPath := fmt.Sprintf("/%s/%s/%s?market=%s", zbData, zbAPIVersion, zbDepth, symbol)
|
||||
var res OrderbookResponse
|
||||
|
||||
err := z.SendHTTPRequest(exchange.RestSpot, urlPath, &res, request.UnAuth)
|
||||
err := z.SendHTTPRequest(ctx, exchange.RestSpot, urlPath, &res, request.UnAuth)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -214,7 +213,7 @@ func (z *ZB) GetOrderbook(symbol string) (OrderbookResponse, error) {
|
||||
}
|
||||
|
||||
// GetSpotKline returns Kline data
|
||||
func (z *ZB) GetSpotKline(arg KlinesRequestParams) (KLineResponse, error) {
|
||||
func (z *ZB) GetSpotKline(ctx context.Context, arg KlinesRequestParams) (KLineResponse, error) {
|
||||
vals := url.Values{}
|
||||
vals.Set("type", arg.Type)
|
||||
vals.Set("market", arg.Symbol)
|
||||
@@ -229,7 +228,7 @@ func (z *ZB) GetSpotKline(arg KlinesRequestParams) (KLineResponse, error) {
|
||||
|
||||
var res KLineResponse
|
||||
var rawKlines map[string]interface{}
|
||||
err := z.SendHTTPRequest(exchange.RestSpot, urlPath, &rawKlines, klineFunc)
|
||||
err := z.SendHTTPRequest(ctx, exchange.RestSpot, urlPath, &rawKlines, klineFunc)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -268,7 +267,7 @@ func (z *ZB) GetSpotKline(arg KlinesRequestParams) (KLineResponse, error) {
|
||||
// NOTE - PLEASE BE AWARE THAT YOU NEED TO GENERATE A DEPOSIT ADDRESS VIA
|
||||
// LOGGING IN AND NOT BY USING THIS ENDPOINT OTHERWISE THIS WILL GIVE YOU A
|
||||
// GENERAL ERROR RESPONSE.
|
||||
func (z *ZB) GetCryptoAddress(currency currency.Code) (UserAddress, error) {
|
||||
func (z *ZB) GetCryptoAddress(ctx context.Context, currency currency.Code) (UserAddress, error) {
|
||||
var resp UserAddress
|
||||
|
||||
vals := url.Values{}
|
||||
@@ -276,11 +275,11 @@ func (z *ZB) GetCryptoAddress(currency currency.Code) (UserAddress, error) {
|
||||
vals.Set("currency", currency.Lower().String())
|
||||
|
||||
return resp,
|
||||
z.SendAuthenticatedHTTPRequest(exchange.RestSpotSupplementary, http.MethodGet, vals, &resp, request.Auth)
|
||||
z.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, vals, &resp, request.Auth)
|
||||
}
|
||||
|
||||
// SendHTTPRequest sends an unauthenticated HTTP request
|
||||
func (z *ZB) SendHTTPRequest(ep exchange.URL, path string, result interface{}, f request.EndpointLimit) error {
|
||||
func (z *ZB) SendHTTPRequest(ctx context.Context, ep exchange.URL, path string, result interface{}, f request.EndpointLimit) error {
|
||||
endpoint, err := z.API.Endpoints.GetURL(ep)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -295,13 +294,13 @@ func (z *ZB) SendHTTPRequest(ep exchange.URL, path string, result interface{}, f
|
||||
HTTPRecording: z.HTTPRecording,
|
||||
}
|
||||
|
||||
return z.SendPayload(context.Background(), f, func() (*request.Item, error) {
|
||||
return z.SendPayload(ctx, f, func() (*request.Item, error) {
|
||||
return item, nil
|
||||
})
|
||||
}
|
||||
|
||||
// SendAuthenticatedHTTPRequest sends authenticated requests to the zb API
|
||||
func (z *ZB) SendAuthenticatedHTTPRequest(ep exchange.URL, httpMethod string, params url.Values, result interface{}, f request.EndpointLimit) error {
|
||||
func (z *ZB) SendAuthenticatedHTTPRequest(ctx context.Context, ep exchange.URL, httpMethod string, params url.Values, result interface{}, f request.EndpointLimit) error {
|
||||
if !z.AllowAuthenticatedRequest() {
|
||||
return fmt.Errorf("%s %w", z.Name, exchange.ErrAuthenticatedRequestWithoutCredentialsSet)
|
||||
}
|
||||
@@ -345,7 +344,7 @@ func (z *ZB) SendAuthenticatedHTTPRequest(ep exchange.URL, httpMethod string, pa
|
||||
}, nil
|
||||
}
|
||||
|
||||
err = z.SendPayload(context.Background(), f, newRequest)
|
||||
err = z.SendPayload(ctx, f, newRequest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -431,7 +430,7 @@ var errorCode = map[int64]string{
|
||||
}
|
||||
|
||||
// Withdraw transfers funds
|
||||
func (z *ZB) Withdraw(currency, address, safepassword string, amount, fees float64, itransfer bool) (string, error) {
|
||||
func (z *ZB) Withdraw(ctx context.Context, currency, address, safepassword string, amount, fees float64, itransfer bool) (string, error) {
|
||||
type response struct {
|
||||
Code int `json:"code"` // Result code
|
||||
Message string `json:"message"` // Result Message
|
||||
@@ -449,7 +448,7 @@ func (z *ZB) Withdraw(currency, address, safepassword string, amount, fees float
|
||||
vals.Set("safePwd", safepassword)
|
||||
|
||||
var resp response
|
||||
err := z.SendAuthenticatedHTTPRequest(exchange.RestSpotSupplementary, http.MethodGet, vals, &resp, request.Auth)
|
||||
err := z.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpotSupplementary, http.MethodGet, vals, &resp, request.Auth)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package zb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -65,7 +66,7 @@ func TestSpotNewOrder(t *testing.T) {
|
||||
Amount: 0.01,
|
||||
Price: 10246.1,
|
||||
}
|
||||
_, err := z.SpotNewOrder(arg)
|
||||
_, err := z.SpotNewOrder(context.Background(), arg)
|
||||
if err != nil {
|
||||
t.Errorf("ZB SpotNewOrder: %s", err)
|
||||
}
|
||||
@@ -78,7 +79,7 @@ func TestCancelExistingOrder(t *testing.T) {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
err := z.CancelExistingOrder(20180629145864850, testCurrency)
|
||||
err := z.CancelExistingOrder(context.Background(), 20180629145864850, testCurrency)
|
||||
if err != nil {
|
||||
t.Errorf("ZB CancelExistingOrder: %s", err)
|
||||
}
|
||||
@@ -86,7 +87,7 @@ func TestCancelExistingOrder(t *testing.T) {
|
||||
|
||||
func TestGetLatestSpotPrice(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := z.GetLatestSpotPrice(testCurrency)
|
||||
_, err := z.GetLatestSpotPrice(context.Background(), testCurrency)
|
||||
if err != nil {
|
||||
t.Errorf("ZB GetLatestSpotPrice: %s", err)
|
||||
}
|
||||
@@ -94,7 +95,7 @@ func TestGetLatestSpotPrice(t *testing.T) {
|
||||
|
||||
func TestGetTicker(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := z.GetTicker(testCurrency)
|
||||
_, err := z.GetTicker(context.Background(), testCurrency)
|
||||
if err != nil {
|
||||
t.Errorf("ZB GetTicker: %s", err)
|
||||
}
|
||||
@@ -102,7 +103,7 @@ func TestGetTicker(t *testing.T) {
|
||||
|
||||
func TestGetTickers(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := z.GetTickers()
|
||||
_, err := z.GetTickers(context.Background())
|
||||
if err != nil {
|
||||
t.Errorf("ZB GetTicker: %s", err)
|
||||
}
|
||||
@@ -110,7 +111,7 @@ func TestGetTickers(t *testing.T) {
|
||||
|
||||
func TestGetOrderbook(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := z.GetOrderbook(testCurrency)
|
||||
_, err := z.GetOrderbook(context.Background(), testCurrency)
|
||||
if err != nil {
|
||||
t.Errorf("ZB GetTicker: %s", err)
|
||||
}
|
||||
@@ -118,7 +119,7 @@ func TestGetOrderbook(t *testing.T) {
|
||||
|
||||
func TestGetMarkets(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := z.GetMarkets()
|
||||
_, err := z.GetMarkets(context.Background())
|
||||
if err != nil {
|
||||
t.Errorf("ZB GetMarkets: %s", err)
|
||||
}
|
||||
@@ -141,7 +142,7 @@ func setFeeBuilder() *exchange.FeeBuilder {
|
||||
func TestGetFeeByTypeOfflineTradeFee(t *testing.T) {
|
||||
t.Parallel()
|
||||
var feeBuilder = setFeeBuilder()
|
||||
_, err := z.GetFeeByType(feeBuilder)
|
||||
_, err := z.GetFeeByType(context.Background(), feeBuilder)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -235,7 +236,7 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
_, err := z.GetActiveOrders(&getOrdersRequest)
|
||||
_, err := z.GetActiveOrders(context.Background(), &getOrdersRequest)
|
||||
if z.ValidateAPICredentials() && err != nil {
|
||||
t.Error(err)
|
||||
} else if !z.ValidateAPICredentials() && err == nil {
|
||||
@@ -255,7 +256,7 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
currency.BTC)},
|
||||
}
|
||||
|
||||
_, err := z.GetOrderHistory(&getOrdersRequest)
|
||||
_, err := z.GetOrderHistory(context.Background(), &getOrdersRequest)
|
||||
if z.ValidateAPICredentials() && err != nil {
|
||||
t.Error(err)
|
||||
} else if !z.ValidateAPICredentials() && err == nil {
|
||||
@@ -288,7 +289,7 @@ func TestSubmitOrder(t *testing.T) {
|
||||
ClientID: "meowOrder",
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
response, err := z.SubmitOrder(orderSubmission)
|
||||
response, err := z.SubmitOrder(context.Background(), orderSubmission)
|
||||
if z.ValidateAPICredentials() && err != nil {
|
||||
t.Error(err)
|
||||
} else if !z.ValidateAPICredentials() && err == nil {
|
||||
@@ -316,7 +317,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
err := z.CancelOrder(orderCancellation)
|
||||
err := z.CancelOrder(context.Background(), orderCancellation)
|
||||
if z.ValidateAPICredentials() && err != nil {
|
||||
t.Error(err)
|
||||
} else if !z.ValidateAPICredentials() && err == nil {
|
||||
@@ -341,7 +342,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
resp, err := z.CancelAllOrders(orderCancellation)
|
||||
resp, err := z.CancelAllOrders(context.Background(), orderCancellation)
|
||||
|
||||
if z.ValidateAPICredentials() && err != nil {
|
||||
t.Error(err)
|
||||
@@ -358,12 +359,12 @@ func TestGetAccountInfo(t *testing.T) {
|
||||
t.Skip("skipping authenticated function for mock testing")
|
||||
}
|
||||
if z.ValidateAPICredentials() {
|
||||
_, err := z.UpdateAccountInfo(asset.Spot)
|
||||
_, err := z.UpdateAccountInfo(context.Background(), asset.Spot)
|
||||
if err != nil {
|
||||
t.Error("GetAccountInfo() error", err)
|
||||
}
|
||||
} else {
|
||||
_, err := z.UpdateAccountInfo(asset.Spot)
|
||||
_, err := z.UpdateAccountInfo(context.Background(), asset.Spot)
|
||||
if err == nil {
|
||||
t.Error("GetAccountInfo() Expected error")
|
||||
}
|
||||
@@ -377,7 +378,8 @@ func TestModifyOrder(t *testing.T) {
|
||||
if z.ValidateAPICredentials() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
_, err := z.ModifyOrder(&order.Modify{AssetType: asset.Spot})
|
||||
_, err := z.ModifyOrder(context.Background(),
|
||||
&order.Modify{AssetType: asset.Spot})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
}
|
||||
@@ -401,7 +403,8 @@ func TestWithdraw(t *testing.T) {
|
||||
Description: "WITHDRAW IT ALL",
|
||||
}
|
||||
|
||||
_, err := z.WithdrawCryptocurrencyFunds(&withdrawCryptoRequest)
|
||||
_, err := z.WithdrawCryptocurrencyFunds(context.Background(),
|
||||
&withdrawCryptoRequest)
|
||||
if z.ValidateAPICredentials() && err != nil {
|
||||
t.Error(err)
|
||||
} else if !z.ValidateAPICredentials() && err == nil {
|
||||
@@ -418,7 +421,7 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := z.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
_, err := z.WithdrawFiatFunds(context.Background(), &withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
}
|
||||
@@ -433,7 +436,8 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := z.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
_, err := z.WithdrawFiatFundsToInternationalBank(context.Background(),
|
||||
&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
}
|
||||
@@ -444,13 +448,13 @@ func TestGetDepositAddress(t *testing.T) {
|
||||
t.Skip("skipping authenticated function for mock testing")
|
||||
}
|
||||
if z.ValidateAPICredentials() {
|
||||
_, err := z.GetDepositAddress(currency.BTC, "")
|
||||
_, err := z.GetDepositAddress(context.Background(), currency.BTC, "")
|
||||
if err != nil {
|
||||
t.Error("GetDepositAddress() error PLEASE MAKE SURE YOU CREATE DEPOSIT ADDRESSES VIA ZB.COM",
|
||||
err)
|
||||
}
|
||||
} else {
|
||||
_, err := z.GetDepositAddress(currency.BTC, "")
|
||||
_, err := z.GetDepositAddress(context.Background(), currency.BTC, "")
|
||||
if err == nil {
|
||||
t.Error("GetDepositAddress() Expected error")
|
||||
}
|
||||
@@ -833,7 +837,7 @@ func TestGetSpotKline(t *testing.T) {
|
||||
arg.Type = "1day"
|
||||
}
|
||||
|
||||
_, err := z.GetSpotKline(arg)
|
||||
_, err := z.GetSpotKline(context.Background(), arg)
|
||||
if err != nil {
|
||||
t.Errorf("ZB GetSpotKline: %s", err)
|
||||
}
|
||||
@@ -852,11 +856,13 @@ func TestGetHistoricCandles(t *testing.T) {
|
||||
endTime = time.Date(2020, 9, 2, 0, 0, 0, 0, time.UTC)
|
||||
}
|
||||
|
||||
_, err = z.GetHistoricCandles(currencyPair, asset.Spot, startTime, endTime, kline.OneDay)
|
||||
_, err = z.GetHistoricCandles(context.Background(),
|
||||
currencyPair, asset.Spot, startTime, endTime, kline.OneDay)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = z.GetHistoricCandles(currencyPair, asset.Spot, startTime, endTime, kline.Interval(time.Hour*7))
|
||||
_, err = z.GetHistoricCandles(context.Background(),
|
||||
currencyPair, asset.Spot, startTime, endTime, kline.Interval(time.Hour*7))
|
||||
if err == nil {
|
||||
t.Fatal("unexpected result")
|
||||
}
|
||||
@@ -873,7 +879,8 @@ func TestGetHistoricCandlesExtended(t *testing.T) {
|
||||
startTime = time.Date(2020, 9, 1, 0, 0, 0, 0, time.UTC)
|
||||
endTime = time.Date(2020, 9, 2, 0, 0, 0, 0, time.UTC)
|
||||
}
|
||||
_, err = z.GetHistoricCandlesExtended(currencyPair, asset.Spot, startTime, endTime, kline.OneDay)
|
||||
_, err = z.GetHistoricCandlesExtended(context.Background(),
|
||||
currencyPair, asset.Spot, startTime, endTime, kline.OneDay)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -970,7 +977,7 @@ func TestValidateCandlesRequest(t *testing.T) {
|
||||
func TestGetTrades(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
trades, err := z.GetTrades("btc_usdt")
|
||||
trades, err := z.GetTrades(context.Background(), "btc_usdt")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -986,7 +993,7 @@ func TestGetRecentTrades(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = z.GetRecentTrades(currencyPair, asset.Spot)
|
||||
_, err = z.GetRecentTrades(context.Background(), currencyPair, asset.Spot)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -998,7 +1005,8 @@ func TestGetHistoricTrades(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = z.GetHistoricTrades(currencyPair, asset.Spot, time.Now().Add(-time.Minute*15), time.Now())
|
||||
_, err = z.GetHistoricTrades(context.Background(),
|
||||
currencyPair, asset.Spot, time.Now().Add(-time.Minute*15), time.Now())
|
||||
if err != nil && err != common.ErrFunctionNotSupported {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -1010,7 +1018,7 @@ func TestUpdateTicker(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = z.UpdateTicker(cp, asset.Spot)
|
||||
_, err = z.UpdateTicker(context.Background(), cp, asset.Spot)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -1018,7 +1026,7 @@ func TestUpdateTicker(t *testing.T) {
|
||||
|
||||
func TestUpdateTickers(t *testing.T) {
|
||||
t.Parallel()
|
||||
err := z.UpdateTickers(asset.Spot)
|
||||
err := z.UpdateTickers(context.Background(), asset.Spot)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package zb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
@@ -42,7 +43,7 @@ func (z *ZB) GetDefaultConfig() (*config.ExchangeConfig, error) {
|
||||
}
|
||||
|
||||
if z.Features.Supports.RESTCapabilities.AutoPairUpdates {
|
||||
err = z.UpdateTradablePairs(true)
|
||||
err = z.UpdateTradablePairs(context.TODO(), true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -208,15 +209,15 @@ func (z *ZB) Run() {
|
||||
return
|
||||
}
|
||||
|
||||
err := z.UpdateTradablePairs(false)
|
||||
err := z.UpdateTradablePairs(context.TODO(), false)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", z.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (z *ZB) FetchTradablePairs(asset asset.Item) ([]string, error) {
|
||||
markets, err := z.GetMarkets()
|
||||
func (z *ZB) FetchTradablePairs(ctx context.Context, asset asset.Item) ([]string, error) {
|
||||
markets, err := z.GetMarkets(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -231,8 +232,8 @@ func (z *ZB) FetchTradablePairs(asset asset.Item) ([]string, error) {
|
||||
|
||||
// UpdateTradablePairs updates the exchanges available pairs and stores
|
||||
// them in the exchanges config
|
||||
func (z *ZB) UpdateTradablePairs(forceUpdate bool) error {
|
||||
pairs, err := z.FetchTradablePairs(asset.Spot)
|
||||
func (z *ZB) UpdateTradablePairs(ctx context.Context, forceUpdate bool) error {
|
||||
pairs, err := z.FetchTradablePairs(ctx, asset.Spot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -244,8 +245,8 @@ func (z *ZB) UpdateTradablePairs(forceUpdate bool) error {
|
||||
}
|
||||
|
||||
// UpdateTickers updates the ticker for all currency pairs of a given asset type
|
||||
func (z *ZB) UpdateTickers(a asset.Item) error {
|
||||
result, err := z.GetTickers()
|
||||
func (z *ZB) UpdateTickers(ctx context.Context, a asset.Item) error {
|
||||
result, err := z.GetTickers(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -281,8 +282,8 @@ func (z *ZB) UpdateTickers(a asset.Item) error {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (z *ZB) UpdateTicker(p currency.Pair, a asset.Item) (*ticker.Price, error) {
|
||||
err := z.UpdateTickers(a)
|
||||
func (z *ZB) UpdateTicker(ctx context.Context, p currency.Pair, a asset.Item) (*ticker.Price, error) {
|
||||
err := z.UpdateTickers(ctx, a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -290,25 +291,25 @@ func (z *ZB) UpdateTicker(p currency.Pair, a asset.Item) (*ticker.Price, error)
|
||||
}
|
||||
|
||||
// FetchTicker returns the ticker for a currency pair
|
||||
func (z *ZB) FetchTicker(p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
|
||||
func (z *ZB) FetchTicker(ctx context.Context, p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
|
||||
tickerNew, err := ticker.GetTicker(z.Name, p, assetType)
|
||||
if err != nil {
|
||||
return z.UpdateTicker(p, assetType)
|
||||
return z.UpdateTicker(ctx, p, assetType)
|
||||
}
|
||||
return tickerNew, nil
|
||||
}
|
||||
|
||||
// FetchOrderbook returns orderbook base on the currency pair
|
||||
func (z *ZB) FetchOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
func (z *ZB) FetchOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
ob, err := orderbook.Get(z.Name, p, assetType)
|
||||
if err != nil {
|
||||
return z.UpdateOrderbook(p, assetType)
|
||||
return z.UpdateOrderbook(ctx, p, assetType)
|
||||
}
|
||||
return ob, nil
|
||||
}
|
||||
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func (z *ZB) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
func (z *ZB) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
book := &orderbook.Base{
|
||||
Exchange: z.Name,
|
||||
Pair: p,
|
||||
@@ -320,7 +321,7 @@ func (z *ZB) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.
|
||||
return book, err
|
||||
}
|
||||
|
||||
orderbookNew, err := z.GetOrderbook(currFormat.String())
|
||||
orderbookNew, err := z.GetOrderbook(ctx, currFormat.String())
|
||||
if err != nil {
|
||||
return book, err
|
||||
}
|
||||
@@ -347,7 +348,7 @@ func (z *ZB) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.
|
||||
|
||||
// UpdateAccountInfo retrieves balances for all enabled currencies for the
|
||||
// ZB exchange
|
||||
func (z *ZB) UpdateAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
func (z *ZB) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (account.Holdings, error) {
|
||||
var info account.Holdings
|
||||
var balances []account.Balance
|
||||
var coins []AccountsResponseCoin
|
||||
@@ -358,7 +359,7 @@ func (z *ZB) UpdateAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
}
|
||||
coins = resp.Data.Coins
|
||||
} else {
|
||||
bal, err := z.GetAccountInformation()
|
||||
bal, err := z.GetAccountInformation(ctx)
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
@@ -397,10 +398,10 @@ func (z *ZB) UpdateAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
}
|
||||
|
||||
// FetchAccountInfo retrieves balances for all enabled currencies
|
||||
func (z *ZB) FetchAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
func (z *ZB) FetchAccountInfo(ctx context.Context, assetType asset.Item) (account.Holdings, error) {
|
||||
acc, err := account.GetHoldings(z.Name, assetType)
|
||||
if err != nil {
|
||||
return z.UpdateAccountInfo(assetType)
|
||||
return z.UpdateAccountInfo(ctx, assetType)
|
||||
}
|
||||
|
||||
return acc, nil
|
||||
@@ -408,24 +409,24 @@ func (z *ZB) FetchAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
|
||||
// GetFundingHistory returns funding history, deposits and
|
||||
// withdrawals
|
||||
func (z *ZB) GetFundingHistory() ([]exchange.FundHistory, error) {
|
||||
func (z *ZB) GetFundingHistory(ctx context.Context) ([]exchange.FundHistory, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetWithdrawalsHistory returns previous withdrawals data
|
||||
func (z *ZB) GetWithdrawalsHistory(c currency.Code) (resp []exchange.WithdrawalHistory, err error) {
|
||||
func (z *ZB) 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 (z *ZB) GetRecentTrades(p currency.Pair, assetType asset.Item) ([]trade.Data, error) {
|
||||
func (z *ZB) GetRecentTrades(ctx context.Context, p currency.Pair, assetType asset.Item) ([]trade.Data, error) {
|
||||
var err error
|
||||
p, err = z.FormatExchangeCurrency(p, assetType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var tradeData TradeHistory
|
||||
tradeData, err = z.GetTrades(p.String())
|
||||
tradeData, err = z.GetTrades(ctx, p.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -459,12 +460,12 @@ func (z *ZB) GetRecentTrades(p currency.Pair, assetType asset.Item) ([]trade.Dat
|
||||
}
|
||||
|
||||
// GetHistoricTrades returns historic trade data within the timeframe provided
|
||||
func (z *ZB) GetHistoricTrades(_ currency.Pair, _ asset.Item, _, _ time.Time) ([]trade.Data, error) {
|
||||
func (z *ZB) GetHistoricTrades(_ context.Context, _ currency.Pair, _ asset.Item, _, _ time.Time) ([]trade.Data, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (z *ZB) SubmitOrder(o *order.Submit) (order.SubmitResponse, error) {
|
||||
func (z *ZB) SubmitOrder(ctx context.Context, o *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
err := o.Validate()
|
||||
if err != nil {
|
||||
@@ -503,7 +504,7 @@ func (z *ZB) SubmitOrder(o *order.Submit) (order.SubmitResponse, error) {
|
||||
Type: oT,
|
||||
}
|
||||
var response int64
|
||||
response, err = z.SpotNewOrder(params)
|
||||
response, err = z.SpotNewOrder(ctx, params)
|
||||
if err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
@@ -520,12 +521,12 @@ func (z *ZB) SubmitOrder(o *order.Submit) (order.SubmitResponse, error) {
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (z *ZB) ModifyOrder(action *order.Modify) (order.Modify, error) {
|
||||
func (z *ZB) 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 (z *ZB) CancelOrder(o *order.Cancel) error {
|
||||
func (z *ZB) CancelOrder(ctx context.Context, o *order.Cancel) error {
|
||||
if err := o.Validate(o.StandardCancel()); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -550,16 +551,16 @@ func (z *ZB) CancelOrder(o *order.Cancel) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return z.CancelExistingOrder(orderIDInt, fpair.String())
|
||||
return z.CancelExistingOrder(ctx, orderIDInt, fpair.String())
|
||||
}
|
||||
|
||||
// CancelBatchOrders cancels an orders by their corresponding ID numbers
|
||||
func (z *ZB) CancelBatchOrders(o []order.Cancel) (order.CancelBatchResponse, error) {
|
||||
func (z *ZB) 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 (z *ZB) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
func (z *ZB) CancelAllOrders(ctx context.Context, _ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
cancelAllOrdersResponse := order.CancelAllResponse{
|
||||
Status: make(map[string]string),
|
||||
}
|
||||
@@ -575,7 +576,8 @@ func (z *ZB) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
return cancelAllOrdersResponse, err
|
||||
}
|
||||
for y := int64(1); ; y++ {
|
||||
openOrders, err := z.GetUnfinishedOrdersIgnoreTradeType(fPair.String(), y, 10)
|
||||
openOrders, err := z.GetUnfinishedOrdersIgnoreTradeType(ctx,
|
||||
fPair.String(), y, 10)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "3001") {
|
||||
break
|
||||
@@ -602,11 +604,12 @@ func (z *ZB) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
err = z.CancelOrder(&order.Cancel{
|
||||
ID: strconv.FormatInt(allOpenOrders[i].ID, 10),
|
||||
Pair: p,
|
||||
AssetType: asset.Spot,
|
||||
})
|
||||
err = z.CancelOrder(ctx,
|
||||
&order.Cancel{
|
||||
ID: strconv.FormatInt(allOpenOrders[i].ID, 10),
|
||||
Pair: p,
|
||||
AssetType: asset.Spot,
|
||||
})
|
||||
if err != nil {
|
||||
cancelAllOrdersResponse.Status[strconv.FormatInt(allOpenOrders[i].ID, 10)] = err.Error()
|
||||
}
|
||||
@@ -616,14 +619,14 @@ func (z *ZB) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
}
|
||||
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (z *ZB) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
func (z *ZB) 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 (z *ZB) GetDepositAddress(cryptocurrency currency.Code, _ string) (string, error) {
|
||||
address, err := z.GetCryptoAddress(cryptocurrency)
|
||||
func (z *ZB) GetDepositAddress(ctx context.Context, cryptocurrency currency.Code, _ string) (string, error) {
|
||||
address, err := z.GetCryptoAddress(ctx, cryptocurrency)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -633,11 +636,12 @@ func (z *ZB) GetDepositAddress(cryptocurrency currency.Code, _ string) (string,
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (z *ZB) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
func (z *ZB) WithdrawCryptocurrencyFunds(ctx context.Context, withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
if err := withdrawRequest.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v, err := z.Withdraw(withdrawRequest.Currency.Lower().String(),
|
||||
v, err := z.Withdraw(ctx,
|
||||
withdrawRequest.Currency.Lower().String(),
|
||||
withdrawRequest.Crypto.Address,
|
||||
withdrawRequest.TradePassword,
|
||||
withdrawRequest.Amount,
|
||||
@@ -653,18 +657,18 @@ func (z *ZB) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*wi
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (z *ZB) WithdrawFiatFunds(_ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
func (z *ZB) WithdrawFiatFunds(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (z *ZB) WithdrawFiatFundsToInternationalBank(_ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
func (z *ZB) WithdrawFiatFundsToInternationalBank(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetFeeByType returns an estimate of fee based on type of transaction
|
||||
func (z *ZB) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error) {
|
||||
func (z *ZB) GetFeeByType(ctx context.Context, feeBuilder *exchange.FeeBuilder) (float64, error) {
|
||||
if (!z.AllowAuthenticatedRequest() || z.SkipAuthCheck) && // Todo check connection status
|
||||
feeBuilder.FeeType == exchange.CryptocurrencyTradeFee {
|
||||
feeBuilder.FeeType = exchange.OfflineTradeFee
|
||||
@@ -674,7 +678,7 @@ func (z *ZB) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error) {
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
// This function is not concurrency safe due to orderSide/orderType maps
|
||||
func (z *ZB) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
func (z *ZB) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -686,7 +690,8 @@ func (z *ZB) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := z.GetUnfinishedOrdersIgnoreTradeType(fPair.String(), i, 10)
|
||||
resp, err := z.GetUnfinishedOrdersIgnoreTradeType(ctx,
|
||||
fPair.String(), i, 10)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "3001") {
|
||||
break
|
||||
@@ -740,7 +745,7 @@ func (z *ZB) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
// This function is not concurrency safe due to orderSide/orderType maps
|
||||
func (z *ZB) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
func (z *ZB) GetOrderHistory(ctx context.Context, req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -775,7 +780,7 @@ func (z *ZB) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := z.GetOrders(fPair.String(), y, side)
|
||||
resp, err := z.GetOrders(ctx, fPair.String(), y, side)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -821,8 +826,8 @@ func (z *ZB) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error
|
||||
|
||||
// ValidateCredentials validates current credentials used for wrapper
|
||||
// functionality
|
||||
func (z *ZB) ValidateCredentials(assetType asset.Item) error {
|
||||
_, err := z.UpdateAccountInfo(assetType)
|
||||
func (z *ZB) ValidateCredentials(ctx context.Context, assetType asset.Item) error {
|
||||
_, err := z.UpdateAccountInfo(ctx, assetType)
|
||||
return z.CheckTransientError(err)
|
||||
}
|
||||
|
||||
@@ -845,7 +850,7 @@ func (z *ZB) FormatExchangeKlineInterval(in kline.Interval) string {
|
||||
}
|
||||
|
||||
// GetHistoricCandles returns candles between a time period for a set time interval
|
||||
func (z *ZB) GetHistoricCandles(p currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
|
||||
func (z *ZB) GetHistoricCandles(ctx context.Context, p currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
|
||||
ret, err := z.validateCandlesRequest(p, a, start, end, interval)
|
||||
if err != nil {
|
||||
return kline.Item{}, err
|
||||
@@ -863,7 +868,7 @@ func (z *ZB) GetHistoricCandles(p currency.Pair, a asset.Item, start, end time.T
|
||||
Size: int64(z.Features.Enabled.Kline.ResultLimit),
|
||||
}
|
||||
var candles KLineResponse
|
||||
candles, err = z.GetSpotKline(klineParams)
|
||||
candles, err = z.GetSpotKline(ctx, klineParams)
|
||||
if err != nil {
|
||||
return kline.Item{}, err
|
||||
}
|
||||
@@ -887,7 +892,7 @@ func (z *ZB) GetHistoricCandles(p currency.Pair, a asset.Item, start, end time.T
|
||||
}
|
||||
|
||||
// GetHistoricCandlesExtended returns candles between a time period for a set time interval
|
||||
func (z *ZB) GetHistoricCandlesExtended(p currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
|
||||
func (z *ZB) GetHistoricCandlesExtended(ctx context.Context, p currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
|
||||
ret, err := z.validateCandlesRequest(p, a, start, end, interval)
|
||||
if err != nil {
|
||||
return kline.Item{}, err
|
||||
@@ -908,7 +913,7 @@ allKlines:
|
||||
Size: int64(z.Features.Enabled.Kline.ResultLimit),
|
||||
}
|
||||
|
||||
candles, err := z.GetSpotKline(klineParams)
|
||||
candles, err := z.GetSpotKline(ctx, klineParams)
|
||||
if err != nil {
|
||||
return kline.Item{}, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user