mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-27 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:
@@ -58,8 +58,8 @@ type Bithumb struct {
|
||||
}
|
||||
|
||||
// GetTradablePairs returns a list of tradable currencies
|
||||
func (b *Bithumb) GetTradablePairs() ([]string, error) {
|
||||
result, err := b.GetAllTickers()
|
||||
func (b *Bithumb) GetTradablePairs(ctx context.Context) ([]string, error) {
|
||||
result, err := b.GetAllTickers(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -74,9 +74,9 @@ func (b *Bithumb) GetTradablePairs() ([]string, error) {
|
||||
// GetTicker returns ticker information
|
||||
//
|
||||
// symbol e.g. "btc"
|
||||
func (b *Bithumb) GetTicker(symbol string) (Ticker, error) {
|
||||
func (b *Bithumb) GetTicker(ctx context.Context, symbol string) (Ticker, error) {
|
||||
var response TickerResponse
|
||||
err := b.SendHTTPRequest(exchange.RestSpot, publicTicker+strings.ToUpper(symbol), &response)
|
||||
err := b.SendHTTPRequest(ctx, exchange.RestSpot, publicTicker+strings.ToUpper(symbol), &response)
|
||||
if err != nil {
|
||||
return response.Data, err
|
||||
}
|
||||
@@ -89,9 +89,9 @@ func (b *Bithumb) GetTicker(symbol string) (Ticker, error) {
|
||||
}
|
||||
|
||||
// GetAllTickers returns all ticker information
|
||||
func (b *Bithumb) GetAllTickers() (map[string]Ticker, error) {
|
||||
func (b *Bithumb) GetAllTickers(ctx context.Context) (map[string]Ticker, error) {
|
||||
var response TickersResponse
|
||||
err := b.SendHTTPRequest(exchange.RestSpot, publicTicker+"all", &response)
|
||||
err := b.SendHTTPRequest(ctx, exchange.RestSpot, publicTicker+"all", &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -118,9 +118,9 @@ func (b *Bithumb) GetAllTickers() (map[string]Ticker, error) {
|
||||
// GetOrderBook returns current orderbook
|
||||
//
|
||||
// symbol e.g. "btc"
|
||||
func (b *Bithumb) GetOrderBook(symbol string) (*Orderbook, error) {
|
||||
func (b *Bithumb) GetOrderBook(ctx context.Context, symbol string) (*Orderbook, error) {
|
||||
response := Orderbook{}
|
||||
err := b.SendHTTPRequest(exchange.RestSpot, publicOrderBook+strings.ToUpper(symbol), &response)
|
||||
err := b.SendHTTPRequest(ctx, exchange.RestSpot, publicOrderBook+strings.ToUpper(symbol), &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -133,12 +133,12 @@ func (b *Bithumb) GetOrderBook(symbol string) (*Orderbook, error) {
|
||||
}
|
||||
|
||||
// GetAssetStatus returns the withdrawal and deposit status for the symbol
|
||||
func (b *Bithumb) GetAssetStatus(symbol string) (*Status, error) {
|
||||
func (b *Bithumb) GetAssetStatus(ctx context.Context, symbol string) (*Status, error) {
|
||||
if symbol == "" {
|
||||
return nil, errSymbolIsEmpty
|
||||
}
|
||||
var response Status
|
||||
err := b.SendHTTPRequest(exchange.RestSpot, publicAssetStatus+strings.ToUpper(symbol), &response)
|
||||
err := b.SendHTTPRequest(ctx, exchange.RestSpot, publicAssetStatus+strings.ToUpper(symbol), &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -153,12 +153,12 @@ func (b *Bithumb) GetAssetStatus(symbol string) (*Status, error) {
|
||||
// GetTransactionHistory returns recent transactions
|
||||
//
|
||||
// symbol e.g. "btc"
|
||||
func (b *Bithumb) GetTransactionHistory(symbol string) (TransactionHistory, error) {
|
||||
func (b *Bithumb) GetTransactionHistory(ctx context.Context, symbol string) (TransactionHistory, error) {
|
||||
response := TransactionHistory{}
|
||||
path := publicTransactionHistory +
|
||||
strings.ToUpper(symbol)
|
||||
|
||||
err := b.SendHTTPRequest(exchange.RestSpot, path, &response)
|
||||
err := b.SendHTTPRequest(ctx, exchange.RestSpot, path, &response)
|
||||
if err != nil {
|
||||
return response, err
|
||||
}
|
||||
@@ -172,7 +172,7 @@ func (b *Bithumb) GetTransactionHistory(symbol string) (TransactionHistory, erro
|
||||
|
||||
// GetAccountInformation returns account information based on the desired
|
||||
// order/payment currencies
|
||||
func (b *Bithumb) GetAccountInformation(orderCurrency, paymentCurrency string) (Account, error) {
|
||||
func (b *Bithumb) GetAccountInformation(ctx context.Context, orderCurrency, paymentCurrency string) (Account, error) {
|
||||
var response Account
|
||||
if orderCurrency == "" {
|
||||
return response, errSymbolIsEmpty
|
||||
@@ -185,11 +185,11 @@ func (b *Bithumb) GetAccountInformation(orderCurrency, paymentCurrency string) (
|
||||
}
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateAccInfo, val, &response)
|
||||
b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, privateAccInfo, val, &response)
|
||||
}
|
||||
|
||||
// GetAccountBalance returns customer wallet information
|
||||
func (b *Bithumb) GetAccountBalance(c string) (FullBalance, error) {
|
||||
func (b *Bithumb) GetAccountBalance(ctx context.Context, c string) (FullBalance, error) {
|
||||
var response Balance
|
||||
var fullBalance = FullBalance{
|
||||
make(map[string]float64),
|
||||
@@ -204,7 +204,7 @@ func (b *Bithumb) GetAccountBalance(c string) (FullBalance, error) {
|
||||
vals.Set("currency", c)
|
||||
}
|
||||
|
||||
err := b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateAccBalance, vals, &response)
|
||||
err := b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, privateAccBalance, vals, &response)
|
||||
if err != nil {
|
||||
return fullBalance, err
|
||||
}
|
||||
@@ -252,12 +252,12 @@ func (b *Bithumb) GetAccountBalance(c string) (FullBalance, error) {
|
||||
// GetWalletAddress returns customer wallet address
|
||||
//
|
||||
// currency e.g. btc, ltc or "", will default to btc without currency specified
|
||||
func (b *Bithumb) GetWalletAddress(currency string) (WalletAddressRes, error) {
|
||||
func (b *Bithumb) GetWalletAddress(ctx context.Context, currency string) (WalletAddressRes, error) {
|
||||
response := WalletAddressRes{}
|
||||
params := url.Values{}
|
||||
params.Set("currency", strings.ToUpper(currency))
|
||||
|
||||
err := b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateWalletAdd, params, &response)
|
||||
err := b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, privateWalletAdd, params, &response)
|
||||
if err != nil {
|
||||
return response, err
|
||||
}
|
||||
@@ -272,11 +272,11 @@ func (b *Bithumb) GetWalletAddress(currency string) (WalletAddressRes, error) {
|
||||
}
|
||||
|
||||
// GetLastTransaction returns customer last transaction
|
||||
func (b *Bithumb) GetLastTransaction() (LastTransactionTicker, error) {
|
||||
func (b *Bithumb) GetLastTransaction(ctx context.Context) (LastTransactionTicker, error) {
|
||||
response := LastTransactionTicker{}
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateTicker, nil, &response)
|
||||
b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, privateTicker, nil, &response)
|
||||
}
|
||||
|
||||
// GetOrders returns order list
|
||||
@@ -286,7 +286,7 @@ func (b *Bithumb) GetLastTransaction() (LastTransactionTicker, error) {
|
||||
// count: Value : 1 ~1000 (default : 100)
|
||||
// after: YYYY-MM-DD hh:mm:ss's UNIX Timestamp
|
||||
// (2014-11-28 16:40:01 = 1417160401000)
|
||||
func (b *Bithumb) GetOrders(orderID, transactionType, count, after, currency string) (Orders, error) {
|
||||
func (b *Bithumb) GetOrders(ctx context.Context, orderID, transactionType, count, after, currency string) (Orders, error) {
|
||||
response := Orders{}
|
||||
params := url.Values{}
|
||||
|
||||
@@ -313,15 +313,15 @@ func (b *Bithumb) GetOrders(orderID, transactionType, count, after, currency str
|
||||
}
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateOrders, params, &response)
|
||||
b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, privateOrders, params, &response)
|
||||
}
|
||||
|
||||
// GetUserTransactions returns customer transactions
|
||||
func (b *Bithumb) GetUserTransactions() (UserTransactions, error) {
|
||||
func (b *Bithumb) GetUserTransactions(ctx context.Context) (UserTransactions, error) {
|
||||
response := UserTransactions{}
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateUserTrans, nil, &response)
|
||||
b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, privateUserTrans, nil, &response)
|
||||
}
|
||||
|
||||
// PlaceTrade executes a trade order
|
||||
@@ -331,7 +331,7 @@ func (b *Bithumb) GetUserTransactions() (UserTransactions, error) {
|
||||
// transactionType: Transaction type(bid : purchase, ask : sales)
|
||||
// units: Order quantity
|
||||
// price: Transaction amount per currency
|
||||
func (b *Bithumb) PlaceTrade(orderCurrency, transactionType string, units float64, price int64) (OrderPlace, error) {
|
||||
func (b *Bithumb) PlaceTrade(ctx context.Context, orderCurrency, transactionType string, units float64, price int64) (OrderPlace, error) {
|
||||
response := OrderPlace{}
|
||||
|
||||
params := url.Values{}
|
||||
@@ -342,11 +342,11 @@ func (b *Bithumb) PlaceTrade(orderCurrency, transactionType string, units float6
|
||||
params.Set("price", strconv.FormatInt(price, 10))
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privatePlaceTrade, params, &response)
|
||||
b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, privatePlaceTrade, params, &response)
|
||||
}
|
||||
|
||||
// ModifyTrade modifies an order already on the exchange books
|
||||
func (b *Bithumb) ModifyTrade(orderID, orderCurrency, transactionType string, units float64, price int64) (OrderPlace, error) {
|
||||
func (b *Bithumb) ModifyTrade(ctx context.Context, orderID, orderCurrency, transactionType string, units float64, price int64) (OrderPlace, error) {
|
||||
response := OrderPlace{}
|
||||
|
||||
params := url.Values{}
|
||||
@@ -358,7 +358,7 @@ func (b *Bithumb) ModifyTrade(orderID, orderCurrency, transactionType string, un
|
||||
params.Set("order_id", orderID)
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privatePlaceTrade, params, &response)
|
||||
b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, privatePlaceTrade, params, &response)
|
||||
}
|
||||
|
||||
// GetOrderDetails returns specific order details
|
||||
@@ -367,7 +367,7 @@ func (b *Bithumb) ModifyTrade(orderID, orderCurrency, transactionType string, un
|
||||
// transactionType: Transaction type(bid : purchase, ask : sales)
|
||||
// currency: BTC, ETH, DASH, LTC, ETC, XRP, BCH, XMR, ZEC, QTUM, BTG, EOS
|
||||
// (default value: BTC)
|
||||
func (b *Bithumb) GetOrderDetails(orderID, transactionType, currency string) (OrderDetails, error) {
|
||||
func (b *Bithumb) GetOrderDetails(ctx context.Context, orderID, transactionType, currency string) (OrderDetails, error) {
|
||||
response := OrderDetails{}
|
||||
|
||||
params := url.Values{}
|
||||
@@ -376,7 +376,7 @@ func (b *Bithumb) GetOrderDetails(orderID, transactionType, currency string) (Or
|
||||
params.Set("currency", strings.ToUpper(currency))
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateOrderDetail, params, &response)
|
||||
b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, privateOrderDetail, params, &response)
|
||||
}
|
||||
|
||||
// CancelTrade cancels a customer purchase/sales transaction
|
||||
@@ -384,7 +384,7 @@ func (b *Bithumb) GetOrderDetails(orderID, transactionType, currency string) (Or
|
||||
// orderID: Order number registered for purchase/sales
|
||||
// currency: BTC, ETH, DASH, LTC, ETC, XRP, BCH, XMR, ZEC, QTUM, BTG, EOS
|
||||
// (default value: BTC)
|
||||
func (b *Bithumb) CancelTrade(transactionType, orderID, currency string) (ActionStatus, error) {
|
||||
func (b *Bithumb) CancelTrade(ctx context.Context, transactionType, orderID, currency string) (ActionStatus, error) {
|
||||
response := ActionStatus{}
|
||||
|
||||
params := url.Values{}
|
||||
@@ -393,7 +393,7 @@ func (b *Bithumb) CancelTrade(transactionType, orderID, currency string) (Action
|
||||
params.Set("currency", strings.ToUpper(currency))
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateCancelTrade, nil, &response)
|
||||
b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, privateCancelTrade, nil, &response)
|
||||
}
|
||||
|
||||
// WithdrawCrypto withdraws a customer currency to an address
|
||||
@@ -404,7 +404,7 @@ func (b *Bithumb) CancelTrade(transactionType, orderID, currency string) (Action
|
||||
// currency: BTC, ETH, DASH, LTC, ETC, XRP, BCH, XMR, ZEC, QTUM
|
||||
// (default value: BTC)
|
||||
// units: Quantity to withdraw currency
|
||||
func (b *Bithumb) WithdrawCrypto(address, destination, currency string, units float64) (ActionStatus, error) {
|
||||
func (b *Bithumb) WithdrawCrypto(ctx context.Context, address, destination, currency string, units float64) (ActionStatus, error) {
|
||||
response := ActionStatus{}
|
||||
|
||||
params := url.Values{}
|
||||
@@ -416,16 +416,16 @@ func (b *Bithumb) WithdrawCrypto(address, destination, currency string, units fl
|
||||
params.Set("units", strconv.FormatFloat(units, 'f', -1, 64))
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateBTCWithdraw, params, &response)
|
||||
b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, privateBTCWithdraw, params, &response)
|
||||
}
|
||||
|
||||
// RequestKRWDepositDetails returns Bithumb banking details for deposit
|
||||
// information
|
||||
func (b *Bithumb) RequestKRWDepositDetails() (KRWDeposit, error) {
|
||||
func (b *Bithumb) RequestKRWDepositDetails(ctx context.Context) (KRWDeposit, error) {
|
||||
response := KRWDeposit{}
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateKRWDeposit, nil, &response)
|
||||
b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, privateKRWDeposit, nil, &response)
|
||||
}
|
||||
|
||||
// RequestKRWWithdraw allows a customer KRW withdrawal request
|
||||
@@ -433,7 +433,7 @@ func (b *Bithumb) RequestKRWDepositDetails() (KRWDeposit, error) {
|
||||
// bank: Bankcode with bank name e.g. (bankcode)_(bankname)
|
||||
// account: Withdrawing bank account number
|
||||
// price: Withdrawing amount
|
||||
func (b *Bithumb) RequestKRWWithdraw(bank, account string, price int64) (ActionStatus, error) {
|
||||
func (b *Bithumb) RequestKRWWithdraw(ctx context.Context, bank, account string, price int64) (ActionStatus, error) {
|
||||
response := ActionStatus{}
|
||||
|
||||
params := url.Values{}
|
||||
@@ -442,7 +442,7 @@ func (b *Bithumb) RequestKRWWithdraw(bank, account string, price int64) (ActionS
|
||||
params.Set("price", strconv.FormatInt(price, 10))
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateKRWWithdraw, params, &response)
|
||||
b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, privateKRWWithdraw, params, &response)
|
||||
}
|
||||
|
||||
// MarketBuyOrder initiates a buy order through available order books
|
||||
@@ -450,7 +450,7 @@ func (b *Bithumb) RequestKRWWithdraw(bank, account string, price int64) (ActionS
|
||||
// currency: BTC, ETH, DASH, LTC, ETC, XRP, BCH, XMR, ZEC, QTUM, BTG, EOS
|
||||
// (default value: BTC)
|
||||
// units: Order quantity
|
||||
func (b *Bithumb) MarketBuyOrder(pair currency.Pair, units float64) (MarketBuy, error) {
|
||||
func (b *Bithumb) MarketBuyOrder(ctx context.Context, pair currency.Pair, units float64) (MarketBuy, error) {
|
||||
response := MarketBuy{}
|
||||
|
||||
params := url.Values{}
|
||||
@@ -459,7 +459,7 @@ func (b *Bithumb) MarketBuyOrder(pair currency.Pair, units float64) (MarketBuy,
|
||||
params.Set("units", strconv.FormatFloat(units, 'f', -1, 64))
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateMarketBuy, params, &response)
|
||||
b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, privateMarketBuy, params, &response)
|
||||
}
|
||||
|
||||
// MarketSellOrder initiates a sell order through available order books
|
||||
@@ -467,7 +467,7 @@ func (b *Bithumb) MarketBuyOrder(pair currency.Pair, units float64) (MarketBuy,
|
||||
// currency: BTC, ETH, DASH, LTC, ETC, XRP, BCH, XMR, ZEC, QTUM, BTG, EOS
|
||||
// (default value: BTC)
|
||||
// units: Order quantity
|
||||
func (b *Bithumb) MarketSellOrder(pair currency.Pair, units float64) (MarketSell, error) {
|
||||
func (b *Bithumb) MarketSellOrder(ctx context.Context, pair currency.Pair, units float64) (MarketSell, error) {
|
||||
response := MarketSell{}
|
||||
|
||||
params := url.Values{}
|
||||
@@ -476,11 +476,11 @@ func (b *Bithumb) MarketSellOrder(pair currency.Pair, units float64) (MarketSell
|
||||
params.Set("units", strconv.FormatFloat(units, 'f', -1, 64))
|
||||
|
||||
return response,
|
||||
b.SendAuthenticatedHTTPRequest(exchange.RestSpot, privateMarketSell, params, &response)
|
||||
b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, privateMarketSell, params, &response)
|
||||
}
|
||||
|
||||
// SendHTTPRequest sends an unauthenticated HTTP request
|
||||
func (b *Bithumb) SendHTTPRequest(ep exchange.URL, path string, result interface{}) error {
|
||||
func (b *Bithumb) SendHTTPRequest(ctx context.Context, ep exchange.URL, path string, result interface{}) error {
|
||||
endpoint, err := b.API.Endpoints.GetURL(ep)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -493,13 +493,13 @@ func (b *Bithumb) SendHTTPRequest(ep exchange.URL, path string, result interface
|
||||
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 HTTP request to bithumb
|
||||
func (b *Bithumb) SendAuthenticatedHTTPRequest(ep exchange.URL, path string, params url.Values, result interface{}) error {
|
||||
func (b *Bithumb) SendAuthenticatedHTTPRequest(ctx context.Context, ep exchange.URL, path string, params url.Values, result interface{}) error {
|
||||
if !b.AllowAuthenticatedRequest() {
|
||||
return fmt.Errorf("%s %w", b.Name, exchange.ErrAuthenticatedRequestWithoutCredentialsSet)
|
||||
}
|
||||
@@ -512,7 +512,7 @@ func (b *Bithumb) SendAuthenticatedHTTPRequest(ep exchange.URL, path string, par
|
||||
}
|
||||
|
||||
var intermediary json.RawMessage
|
||||
err = b.SendPayload(context.Background(), request.Auth, func() (*request.Item, error) {
|
||||
err = b.SendPayload(ctx, request.Auth, func() (*request.Item, error) {
|
||||
// This is time window sensitive
|
||||
tnMS := time.Now().UnixNano() / int64(time.Millisecond)
|
||||
n := strconv.FormatInt(tnMS, 10)
|
||||
@@ -647,15 +647,15 @@ var errCode = map[string]string{
|
||||
}
|
||||
|
||||
// GetCandleStick returns candle stick data for requested pair
|
||||
func (b *Bithumb) GetCandleStick(symbol, interval string) (resp OHLCVResponse, err error) {
|
||||
func (b *Bithumb) GetCandleStick(ctx context.Context, symbol, interval string) (resp OHLCVResponse, err error) {
|
||||
path := publicCandleStick + symbol + "/" + interval
|
||||
err = b.SendHTTPRequest(exchange.RestSpot, path, &resp)
|
||||
err = b.SendHTTPRequest(ctx, exchange.RestSpot, path, &resp)
|
||||
return
|
||||
}
|
||||
|
||||
// FetchExchangeLimits fetches spot order execution limits
|
||||
func (b *Bithumb) FetchExchangeLimits() ([]order.MinMaxLevel, error) {
|
||||
ticks, err := b.GetAllTickers()
|
||||
func (b *Bithumb) FetchExchangeLimits(ctx context.Context) ([]order.MinMaxLevel, error) {
|
||||
ticks, err := b.GetAllTickers(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package bithumb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
@@ -54,7 +55,7 @@ func TestMain(m *testing.M) {
|
||||
|
||||
func TestGetTradablePairs(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetTradablePairs()
|
||||
_, err := b.GetTradablePairs(context.Background())
|
||||
if err != nil {
|
||||
t.Error("Bithumb GetTradablePairs() error", err)
|
||||
}
|
||||
@@ -62,7 +63,7 @@ func TestGetTradablePairs(t *testing.T) {
|
||||
|
||||
func TestGetTicker(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetTicker(testCurrency)
|
||||
_, err := b.GetTicker(context.Background(), testCurrency)
|
||||
if err != nil {
|
||||
t.Error("Bithumb GetTicker() error", err)
|
||||
}
|
||||
@@ -70,7 +71,7 @@ func TestGetTicker(t *testing.T) {
|
||||
|
||||
func TestGetAllTickers(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetAllTickers()
|
||||
_, err := b.GetAllTickers(context.Background())
|
||||
if err != nil {
|
||||
t.Error("Bithumb GetAllTickers() error", err)
|
||||
}
|
||||
@@ -78,7 +79,7 @@ func TestGetAllTickers(t *testing.T) {
|
||||
|
||||
func TestGetOrderBook(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetOrderBook(testCurrency)
|
||||
_, err := b.GetOrderBook(context.Background(), testCurrency)
|
||||
if err != nil {
|
||||
t.Error("Bithumb GetOrderBook() error", err)
|
||||
}
|
||||
@@ -86,7 +87,7 @@ func TestGetOrderBook(t *testing.T) {
|
||||
|
||||
func TestGetTransactionHistory(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetTransactionHistory(testCurrency)
|
||||
_, err := b.GetTransactionHistory(context.Background(), testCurrency)
|
||||
if err != nil {
|
||||
t.Error("Bithumb GetTransactionHistory() error", err)
|
||||
}
|
||||
@@ -96,7 +97,7 @@ func TestGetAccountInformation(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Offline test
|
||||
_, err := b.GetAccountInformation("", "")
|
||||
_, err := b.GetAccountInformation(context.Background(), "", "")
|
||||
if err == nil {
|
||||
t.Error("expected error when no order currency is specified")
|
||||
}
|
||||
@@ -105,7 +106,9 @@ func TestGetAccountInformation(t *testing.T) {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
_, err = b.GetAccountInformation(testCurrency, currency.KRW.String())
|
||||
_, err = b.GetAccountInformation(context.Background(),
|
||||
testCurrency,
|
||||
currency.KRW.String())
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -117,7 +120,7 @@ func TestGetAccountBalance(t *testing.T) {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
_, err := b.GetAccountBalance(testCurrency)
|
||||
_, err := b.GetAccountBalance(context.Background(), testCurrency)
|
||||
if err == nil {
|
||||
t.Error("Bithumb GetAccountBalance() Expected error")
|
||||
}
|
||||
@@ -129,7 +132,7 @@ func TestGetWalletAddress(t *testing.T) {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
_, err := b.GetWalletAddress("")
|
||||
_, err := b.GetWalletAddress(context.Background(), "")
|
||||
if err == nil {
|
||||
t.Error("Bithumb GetWalletAddress() Expected error")
|
||||
}
|
||||
@@ -137,7 +140,7 @@ func TestGetWalletAddress(t *testing.T) {
|
||||
|
||||
func TestGetLastTransaction(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetLastTransaction()
|
||||
_, err := b.GetLastTransaction(context.Background())
|
||||
if err == nil {
|
||||
t.Error("Bithumb GetLastTransaction() Expected error")
|
||||
}
|
||||
@@ -145,7 +148,8 @@ func TestGetLastTransaction(t *testing.T) {
|
||||
|
||||
func TestGetOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetOrders("1337", order.Bid.Lower(), "100", "", testCurrency)
|
||||
_, err := b.GetOrders(context.Background(),
|
||||
"1337", order.Bid.Lower(), "100", "", testCurrency)
|
||||
if err == nil {
|
||||
t.Error("Bithumb GetOrders() Expected error")
|
||||
}
|
||||
@@ -153,7 +157,7 @@ func TestGetOrders(t *testing.T) {
|
||||
|
||||
func TestGetUserTransactions(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetUserTransactions()
|
||||
_, err := b.GetUserTransactions(context.Background())
|
||||
if err == nil {
|
||||
t.Error("Bithumb GetUserTransactions() Expected error")
|
||||
}
|
||||
@@ -161,7 +165,8 @@ func TestGetUserTransactions(t *testing.T) {
|
||||
|
||||
func TestPlaceTrade(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.PlaceTrade(testCurrency, order.Bid.Lower(), 0, 0)
|
||||
_, err := b.PlaceTrade(context.Background(),
|
||||
testCurrency, order.Bid.Lower(), 0, 0)
|
||||
if err == nil {
|
||||
t.Error("Bithumb PlaceTrade() Expected error")
|
||||
}
|
||||
@@ -169,7 +174,8 @@ func TestPlaceTrade(t *testing.T) {
|
||||
|
||||
func TestGetOrderDetails(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetOrderDetails("1337", order.Bid.Lower(), testCurrency)
|
||||
_, err := b.GetOrderDetails(context.Background(),
|
||||
"1337", order.Bid.Lower(), testCurrency)
|
||||
if err == nil {
|
||||
t.Error("Bithumb GetOrderDetails() Expected error")
|
||||
}
|
||||
@@ -177,7 +183,7 @@ func TestGetOrderDetails(t *testing.T) {
|
||||
|
||||
func TestCancelTrade(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.CancelTrade("", "", "")
|
||||
_, err := b.CancelTrade(context.Background(), "", "", "")
|
||||
if err == nil {
|
||||
t.Error("Bithumb CancelTrade() Expected error")
|
||||
}
|
||||
@@ -185,7 +191,8 @@ func TestCancelTrade(t *testing.T) {
|
||||
|
||||
func TestWithdrawCrypto(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.WithdrawCrypto("LQxiDhKU7idKiWQhx4ALKYkBx8xKEQVxJR", "", "ltc", 0)
|
||||
_, err := b.WithdrawCrypto(context.Background(),
|
||||
"LQxiDhKU7idKiWQhx4ALKYkBx8xKEQVxJR", "", "ltc", 0)
|
||||
if err == nil {
|
||||
t.Error("Bithumb WithdrawCrypto() Expected error")
|
||||
}
|
||||
@@ -196,7 +203,7 @@ func TestRequestKRWDepositDetails(t *testing.T) {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip()
|
||||
}
|
||||
_, err := b.RequestKRWDepositDetails()
|
||||
_, err := b.RequestKRWDepositDetails(context.Background())
|
||||
if err == nil {
|
||||
t.Error("Bithumb RequestKRWDepositDetails() Expected error")
|
||||
}
|
||||
@@ -204,7 +211,8 @@ func TestRequestKRWDepositDetails(t *testing.T) {
|
||||
|
||||
func TestRequestKRWWithdraw(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.RequestKRWWithdraw("102_bank", "1337", 1000)
|
||||
_, err := b.RequestKRWWithdraw(context.Background(),
|
||||
"102_bank", "1337", 1000)
|
||||
if err == nil {
|
||||
t.Error("Bithumb RequestKRWWithdraw() Expected error")
|
||||
}
|
||||
@@ -213,7 +221,7 @@ func TestRequestKRWWithdraw(t *testing.T) {
|
||||
func TestMarketBuyOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
p := currency.NewPair(currency.BTC, currency.KRW)
|
||||
_, err := b.MarketBuyOrder(p, 0)
|
||||
_, err := b.MarketBuyOrder(context.Background(), p, 0)
|
||||
if err == nil {
|
||||
t.Error("Bithumb MarketBuyOrder() Expected error")
|
||||
}
|
||||
@@ -222,7 +230,7 @@ func TestMarketBuyOrder(t *testing.T) {
|
||||
func TestMarketSellOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
p := currency.NewPair(currency.BTC, currency.KRW)
|
||||
_, err := b.MarketSellOrder(p, 0)
|
||||
_, err := b.MarketSellOrder(context.Background(), p, 0)
|
||||
if err == nil {
|
||||
t.Error("Bithumb MarketSellOrder() Expected error")
|
||||
}
|
||||
@@ -231,13 +239,13 @@ func TestMarketSellOrder(t *testing.T) {
|
||||
func TestUpdateTicker(t *testing.T) {
|
||||
t.Parallel()
|
||||
cp := currency.NewPair(currency.QTUM, currency.KRW)
|
||||
_, err := b.UpdateTicker(cp, asset.Spot)
|
||||
_, err := b.UpdateTicker(context.Background(), cp, asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cp = currency.NewPair(currency.BTC, currency.KRW)
|
||||
_, err = b.UpdateTicker(cp, asset.Spot)
|
||||
_, err = b.UpdateTicker(context.Background(), cp, asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -245,7 +253,7 @@ func TestUpdateTicker(t *testing.T) {
|
||||
|
||||
func TestUpdateTickers(t *testing.T) {
|
||||
t.Parallel()
|
||||
err := b.UpdateTickers(asset.Spot)
|
||||
err := b.UpdateTickers(context.Background(), asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -264,7 +272,7 @@ func setFeeBuilder() *exchange.FeeBuilder {
|
||||
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)
|
||||
}
|
||||
@@ -357,7 +365,7 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
_, err := b.GetActiveOrders(&getOrdersRequest)
|
||||
_, err := b.GetActiveOrders(context.Background(), &getOrdersRequest)
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
t.Errorf("Could not get open orders: %s", err)
|
||||
} else if !areTestAPIKeysSet() && err == nil {
|
||||
@@ -372,7 +380,7 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
_, err := b.GetOrderHistory(&getOrdersRequest)
|
||||
_, err := b.GetOrderHistory(context.Background(), &getOrdersRequest)
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
t.Errorf("Could not get order history: %s", err)
|
||||
} else if !areTestAPIKeysSet() && err == nil {
|
||||
@@ -404,7 +412,7 @@ func TestSubmitOrder(t *testing.T) {
|
||||
ClientID: "meowOrder",
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
response, err := b.SubmitOrder(orderSubmission)
|
||||
response, err := b.SubmitOrder(context.Background(), orderSubmission)
|
||||
if areTestAPIKeysSet() && (err != nil || !response.IsOrderPlaced) {
|
||||
t.Errorf("Order failed to be placed: %v", err)
|
||||
} else if !areTestAPIKeysSet() && err == nil {
|
||||
@@ -427,7 +435,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
err := b.CancelOrder(orderCancellation)
|
||||
err := b.CancelOrder(context.Background(), orderCancellation)
|
||||
if !areTestAPIKeysSet() && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
@@ -451,7 +459,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
resp, err := b.CancelAllOrders(orderCancellation)
|
||||
resp, err := b.CancelAllOrders(context.Background(), orderCancellation)
|
||||
|
||||
if !areTestAPIKeysSet() && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
@@ -468,12 +476,12 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
func TestGetAccountInfo(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() {
|
||||
_, err := b.UpdateAccountInfo(asset.Spot)
|
||||
_, err := b.UpdateAccountInfo(context.Background(), asset.Spot)
|
||||
if err != nil {
|
||||
t.Error("Bithumb GetAccountInfo() error", err)
|
||||
}
|
||||
} else {
|
||||
_, err := b.UpdateAccountInfo(asset.Spot)
|
||||
_, err := b.UpdateAccountInfo(context.Background(), asset.Spot)
|
||||
if err == nil {
|
||||
t.Error("Bithumb GetAccountInfo() Expected error")
|
||||
}
|
||||
@@ -486,7 +494,7 @@ func TestModifyOrder(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = b.ModifyOrder(&order.Modify{
|
||||
_, err = b.ModifyOrder(context.Background(), &order.Modify{
|
||||
ID: "1337",
|
||||
Price: 100,
|
||||
Amount: 1000,
|
||||
@@ -514,7 +522,8 @@ func TestWithdraw(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
_, err := b.WithdrawCryptocurrencyFunds(&withdrawCryptoRequest)
|
||||
_, err := b.WithdrawCryptocurrencyFunds(context.Background(),
|
||||
&withdrawCryptoRequest)
|
||||
if !areTestAPIKeysSet() && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
@@ -540,7 +549,7 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
Description: "WITHDRAW IT ALL",
|
||||
}
|
||||
|
||||
_, err := b.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
_, err := b.WithdrawFiatFunds(context.Background(), &withdrawFiatRequest)
|
||||
if !areTestAPIKeysSet() && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
@@ -556,7 +565,8 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := b.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
_, err := b.WithdrawFiatFundsToInternationalBank(context.Background(),
|
||||
&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
}
|
||||
@@ -565,12 +575,12 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
func TestGetDepositAddress(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() {
|
||||
_, err := b.GetDepositAddress(currency.BTC, "")
|
||||
_, err := b.GetDepositAddress(context.Background(), currency.BTC, "")
|
||||
if err != nil {
|
||||
t.Error("GetDepositAddress() error", err)
|
||||
}
|
||||
} else {
|
||||
_, err := b.GetDepositAddress(currency.BTC, "")
|
||||
_, err := b.GetDepositAddress(context.Background(), currency.BTC, "")
|
||||
if err == nil {
|
||||
t.Error("GetDepositAddress() error cannot be nil")
|
||||
}
|
||||
@@ -579,7 +589,7 @@ func TestGetDepositAddress(t *testing.T) {
|
||||
|
||||
func TestGetCandleStick(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetCandleStick("BTC_KRW", "1m")
|
||||
_, err := b.GetCandleStick(context.Background(), "BTC_KRW", "1m")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -592,7 +602,8 @@ func TestGetHistoricCandles(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
startTime := time.Now().Add(-time.Hour * 24)
|
||||
_, err = b.GetHistoricCandles(currencyPair, asset.Spot, startTime, time.Now(), kline.OneDay)
|
||||
_, err = b.GetHistoricCandles(context.Background(),
|
||||
currencyPair, asset.Spot, startTime, time.Now(), kline.OneDay)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -605,7 +616,8 @@ func TestGetHistoricCandlesExtended(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
startTime := time.Now().Add(-time.Hour * 24)
|
||||
_, err = b.GetHistoricCandlesExtended(currencyPair, asset.Spot, startTime, time.Now(), kline.OneDay)
|
||||
_, err = b.GetHistoricCandlesExtended(context.Background(),
|
||||
currencyPair, asset.Spot, startTime, time.Now(), kline.OneDay)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -617,7 +629,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)
|
||||
}
|
||||
@@ -629,7 +641,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)
|
||||
}
|
||||
@@ -637,7 +650,7 @@ func TestGetHistoricTrades(t *testing.T) {
|
||||
|
||||
func TestUpdateOrderExecutionLimits(t *testing.T) {
|
||||
t.Parallel()
|
||||
err := b.UpdateOrderExecutionLimits("")
|
||||
err := b.UpdateOrderExecutionLimits(context.Background(), "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -718,12 +731,12 @@ func TestGetAmountMinimum(t *testing.T) {
|
||||
|
||||
func TestGetAssetStatus(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetAssetStatus("")
|
||||
_, err := b.GetAssetStatus(context.Background(), "")
|
||||
if !errors.Is(err, errSymbolIsEmpty) {
|
||||
t.Fatalf("received: %v but expected: %v", err, errSymbolIsEmpty)
|
||||
}
|
||||
|
||||
_, err = b.GetAssetStatus("sol")
|
||||
_, err = b.GetAssetStatus(context.Background(), "sol")
|
||||
if !errors.Is(err, nil) {
|
||||
t.Fatalf("received: %v but expected: %v", err, nil)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package bithumb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
@@ -45,7 +46,7 @@ func (b *Bithumb) 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
|
||||
}
|
||||
@@ -203,7 +204,7 @@ func (b *Bithumb) Run() {
|
||||
b.PrintEnabledPairs()
|
||||
}
|
||||
|
||||
err := b.UpdateOrderExecutionLimits("")
|
||||
err := b.UpdateOrderExecutionLimits(context.TODO(), "")
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"%s failed to set exchange order execution limits. Err: %v",
|
||||
@@ -215,15 +216,15 @@ func (b *Bithumb) Run() {
|
||||
return
|
||||
}
|
||||
|
||||
err = b.UpdateTradablePairs(false)
|
||||
err = b.UpdateTradablePairs(context.TODO(), false)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s failed to update tradable pairs. Err: %s", b.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (b *Bithumb) FetchTradablePairs(asset asset.Item) ([]string, error) {
|
||||
currencies, err := b.GetTradablePairs()
|
||||
func (b *Bithumb) FetchTradablePairs(ctx context.Context, asset asset.Item) ([]string, error) {
|
||||
currencies, err := b.GetTradablePairs(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -237,8 +238,8 @@ func (b *Bithumb) FetchTradablePairs(asset asset.Item) ([]string, error) {
|
||||
|
||||
// UpdateTradablePairs updates the exchanges available pairs and stores
|
||||
// them in the exchanges config
|
||||
func (b *Bithumb) UpdateTradablePairs(forceUpdate bool) error {
|
||||
pairs, err := b.FetchTradablePairs(asset.Spot)
|
||||
func (b *Bithumb) UpdateTradablePairs(ctx context.Context, forceUpdate bool) error {
|
||||
pairs, err := b.FetchTradablePairs(ctx, asset.Spot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -252,8 +253,8 @@ func (b *Bithumb) UpdateTradablePairs(forceUpdate bool) error {
|
||||
}
|
||||
|
||||
// UpdateTickers updates the ticker for all currency pairs of a given asset type
|
||||
func (b *Bithumb) UpdateTickers(a asset.Item) error {
|
||||
tickers, err := b.GetAllTickers()
|
||||
func (b *Bithumb) UpdateTickers(ctx context.Context, a asset.Item) error {
|
||||
tickers, err := b.GetAllTickers(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -287,8 +288,8 @@ func (b *Bithumb) UpdateTickers(a asset.Item) error {
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (b *Bithumb) UpdateTicker(p currency.Pair, a asset.Item) (*ticker.Price, error) {
|
||||
err := b.UpdateTickers(a)
|
||||
func (b *Bithumb) UpdateTicker(ctx context.Context, p currency.Pair, a asset.Item) (*ticker.Price, error) {
|
||||
err := b.UpdateTickers(ctx, a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -296,25 +297,25 @@ func (b *Bithumb) UpdateTicker(p currency.Pair, a asset.Item) (*ticker.Price, er
|
||||
}
|
||||
|
||||
// FetchTicker returns the ticker for a currency pair
|
||||
func (b *Bithumb) FetchTicker(p currency.Pair, a asset.Item) (*ticker.Price, error) {
|
||||
func (b *Bithumb) FetchTicker(ctx context.Context, p currency.Pair, a asset.Item) (*ticker.Price, error) {
|
||||
tickerNew, err := ticker.GetTicker(b.Name, p, a)
|
||||
if err != nil {
|
||||
return b.UpdateTicker(p, a)
|
||||
return b.UpdateTicker(ctx, p, a)
|
||||
}
|
||||
return tickerNew, nil
|
||||
}
|
||||
|
||||
// FetchOrderbook returns orderbook base on the currency pair
|
||||
func (b *Bithumb) FetchOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
func (b *Bithumb) FetchOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
ob, err := orderbook.Get(b.Name, p, assetType)
|
||||
if err != nil {
|
||||
return b.UpdateOrderbook(p, assetType)
|
||||
return b.UpdateOrderbook(ctx, p, assetType)
|
||||
}
|
||||
return ob, nil
|
||||
}
|
||||
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func (b *Bithumb) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
func (b *Bithumb) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
book := &orderbook.Base{
|
||||
Exchange: b.Name,
|
||||
Pair: p,
|
||||
@@ -323,7 +324,7 @@ func (b *Bithumb) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*order
|
||||
}
|
||||
curr := p.Base.String()
|
||||
|
||||
orderbookNew, err := b.GetOrderBook(curr)
|
||||
orderbookNew, err := b.GetOrderBook(ctx, curr)
|
||||
if err != nil {
|
||||
return book, err
|
||||
}
|
||||
@@ -353,9 +354,9 @@ func (b *Bithumb) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*order
|
||||
|
||||
// UpdateAccountInfo retrieves balances for all enabled currencies for the
|
||||
// Bithumb exchange
|
||||
func (b *Bithumb) UpdateAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
func (b *Bithumb) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (account.Holdings, error) {
|
||||
var info account.Holdings
|
||||
bal, err := b.GetAccountBalance("ALL")
|
||||
bal, err := b.GetAccountBalance(ctx, "ALL")
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
@@ -390,10 +391,10 @@ func (b *Bithumb) UpdateAccountInfo(assetType asset.Item) (account.Holdings, err
|
||||
}
|
||||
|
||||
// FetchAccountInfo retrieves balances for all enabled currencies
|
||||
func (b *Bithumb) FetchAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
func (b *Bithumb) 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
|
||||
@@ -401,23 +402,23 @@ func (b *Bithumb) FetchAccountInfo(assetType asset.Item) (account.Holdings, erro
|
||||
|
||||
// GetFundingHistory returns funding history, deposits and
|
||||
// withdrawals
|
||||
func (b *Bithumb) GetFundingHistory() ([]exchange.FundHistory, error) {
|
||||
func (b *Bithumb) GetFundingHistory(ctx context.Context) ([]exchange.FundHistory, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetWithdrawalsHistory returns previous withdrawals data
|
||||
func (b *Bithumb) GetWithdrawalsHistory(c currency.Code) (resp []exchange.WithdrawalHistory, err error) {
|
||||
func (b *Bithumb) 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 *Bithumb) GetRecentTrades(p currency.Pair, assetType asset.Item) ([]trade.Data, error) {
|
||||
func (b *Bithumb) 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
|
||||
}
|
||||
tradeData, err := b.GetTransactionHistory(p.String())
|
||||
tradeData, err := b.GetTransactionHistory(ctx, p.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -454,13 +455,13 @@ func (b *Bithumb) GetRecentTrades(p currency.Pair, assetType asset.Item) ([]trad
|
||||
}
|
||||
|
||||
// GetHistoricTrades returns historic trade data within the timeframe provided
|
||||
func (b *Bithumb) GetHistoricTrades(_ currency.Pair, _ asset.Item, _, _ time.Time) ([]trade.Data, error) {
|
||||
func (b *Bithumb) GetHistoricTrades(_ context.Context, _ currency.Pair, _ asset.Item, _, _ time.Time) ([]trade.Data, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
// TODO: Fill this out to support limit orders
|
||||
func (b *Bithumb) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
func (b *Bithumb) SubmitOrder(ctx context.Context, s *order.Submit) (order.SubmitResponse, error) {
|
||||
var submitOrderResponse order.SubmitResponse
|
||||
if err := s.Validate(); err != nil {
|
||||
return submitOrderResponse, err
|
||||
@@ -474,14 +475,14 @@ func (b *Bithumb) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
var orderID string
|
||||
if s.Side == order.Buy {
|
||||
var result MarketBuy
|
||||
result, err = b.MarketBuyOrder(fPair, s.Amount)
|
||||
result, err = b.MarketBuyOrder(ctx, fPair, s.Amount)
|
||||
if err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
orderID = result.OrderID
|
||||
} else if s.Side == order.Sell {
|
||||
var result MarketSell
|
||||
result, err = b.MarketSellOrder(fPair, s.Amount)
|
||||
result, err = b.MarketSellOrder(ctx, fPair, s.Amount)
|
||||
if err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
@@ -498,12 +499,13 @@ func (b *Bithumb) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (b *Bithumb) ModifyOrder(action *order.Modify) (order.Modify, error) {
|
||||
func (b *Bithumb) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error) {
|
||||
if err := action.Validate(); err != nil {
|
||||
return order.Modify{}, err
|
||||
}
|
||||
|
||||
o, err := b.ModifyTrade(action.ID,
|
||||
o, err := b.ModifyTrade(ctx,
|
||||
action.ID,
|
||||
action.Pair.Base.String(),
|
||||
action.Side.Lower(),
|
||||
action.Amount,
|
||||
@@ -526,24 +528,24 @@ func (b *Bithumb) ModifyOrder(action *order.Modify) (order.Modify, error) {
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (b *Bithumb) CancelOrder(o *order.Cancel) error {
|
||||
func (b *Bithumb) CancelOrder(ctx context.Context, o *order.Cancel) error {
|
||||
if err := o.Validate(o.StandardCancel()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err := b.CancelTrade(o.Side.String(),
|
||||
_, err := b.CancelTrade(ctx, o.Side.String(),
|
||||
o.ID,
|
||||
o.Pair.Base.String())
|
||||
return err
|
||||
}
|
||||
|
||||
// CancelBatchOrders cancels an orders by their corresponding ID numbers
|
||||
func (b *Bithumb) CancelBatchOrders(o []order.Cancel) (order.CancelBatchResponse, error) {
|
||||
func (b *Bithumb) 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 *Bithumb) CancelAllOrders(orderCancellation *order.Cancel) (order.CancelAllResponse, error) {
|
||||
func (b *Bithumb) CancelAllOrders(ctx context.Context, orderCancellation *order.Cancel) (order.CancelAllResponse, error) {
|
||||
if err := orderCancellation.Validate(); err != nil {
|
||||
return order.CancelAllResponse{}, err
|
||||
}
|
||||
@@ -559,7 +561,8 @@ func (b *Bithumb) CancelAllOrders(orderCancellation *order.Cancel) (order.Cancel
|
||||
}
|
||||
|
||||
for i := range currs {
|
||||
orders, err := b.GetOrders("",
|
||||
orders, err := b.GetOrders(ctx,
|
||||
"",
|
||||
orderCancellation.Side.String(),
|
||||
"100",
|
||||
"",
|
||||
@@ -571,7 +574,8 @@ func (b *Bithumb) CancelAllOrders(orderCancellation *order.Cancel) (order.Cancel
|
||||
}
|
||||
|
||||
for i := range allOrders {
|
||||
_, err := b.CancelTrade(orderCancellation.Side.String(),
|
||||
_, err := b.CancelTrade(ctx,
|
||||
orderCancellation.Side.String(),
|
||||
allOrders[i].OrderID,
|
||||
orderCancellation.Pair.Base.String())
|
||||
if err != nil {
|
||||
@@ -583,14 +587,14 @@ func (b *Bithumb) CancelAllOrders(orderCancellation *order.Cancel) (order.Cancel
|
||||
}
|
||||
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (b *Bithumb) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
||||
func (b *Bithumb) 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 *Bithumb) GetDepositAddress(cryptocurrency currency.Code, _ string) (string, error) {
|
||||
addr, err := b.GetWalletAddress(cryptocurrency.String())
|
||||
func (b *Bithumb) GetDepositAddress(ctx context.Context, cryptocurrency currency.Code, _ string) (string, error) {
|
||||
addr, err := b.GetWalletAddress(ctx, cryptocurrency.String())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -600,11 +604,12 @@ func (b *Bithumb) GetDepositAddress(cryptocurrency currency.Code, _ string) (str
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (b *Bithumb) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
func (b *Bithumb) WithdrawCryptocurrencyFunds(ctx context.Context, withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
if err := withdrawRequest.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v, err := b.WithdrawCrypto(withdrawRequest.Crypto.Address,
|
||||
v, err := b.WithdrawCrypto(ctx,
|
||||
withdrawRequest.Crypto.Address,
|
||||
withdrawRequest.Crypto.AddressTag,
|
||||
withdrawRequest.Currency.String(),
|
||||
withdrawRequest.Amount)
|
||||
@@ -619,7 +624,7 @@ func (b *Bithumb) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request)
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (b *Bithumb) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
func (b *Bithumb) WithdrawFiatFunds(ctx context.Context, withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
if err := withdrawRequest.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -631,7 +636,10 @@ func (b *Bithumb) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdra
|
||||
}
|
||||
bankDetails := strconv.FormatFloat(withdrawRequest.Fiat.Bank.BankCode, 'f', -1, 64) +
|
||||
"_" + withdrawRequest.Fiat.Bank.BankName
|
||||
resp, err := b.RequestKRWWithdraw(bankDetails, withdrawRequest.Fiat.Bank.AccountNumber, int64(withdrawRequest.Amount))
|
||||
resp, err := b.RequestKRWWithdraw(ctx,
|
||||
bankDetails,
|
||||
withdrawRequest.Fiat.Bank.AccountNumber,
|
||||
int64(withdrawRequest.Amount))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -645,12 +653,12 @@ func (b *Bithumb) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdra
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank is not supported as Bithumb only withdraws KRW to South Korean banks
|
||||
func (b *Bithumb) WithdrawFiatFundsToInternationalBank(_ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
func (b *Bithumb) WithdrawFiatFundsToInternationalBank(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetFeeByType returns an estimate of fee based on type of transaction
|
||||
func (b *Bithumb) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error) {
|
||||
func (b *Bithumb) GetFeeByType(ctx context.Context, feeBuilder *exchange.FeeBuilder) (float64, error) {
|
||||
if !b.AllowAuthenticatedRequest() && // Todo check connection status
|
||||
feeBuilder.FeeType == exchange.CryptocurrencyTradeFee {
|
||||
feeBuilder.FeeType = exchange.OfflineTradeFee
|
||||
@@ -659,7 +667,7 @@ func (b *Bithumb) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error)
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (b *Bithumb) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
func (b *Bithumb) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -675,7 +683,7 @@ func (b *Bithumb) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail,
|
||||
|
||||
var orders []order.Detail
|
||||
for x := range req.Pairs {
|
||||
resp, err := b.GetOrders("", "", "1000", "", req.Pairs[x].Base.String())
|
||||
resp, err := b.GetOrders(ctx, "", "", "1000", "", req.Pairs[x].Base.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -717,7 +725,7 @@ func (b *Bithumb) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail,
|
||||
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
func (b *Bithumb) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
func (b *Bithumb) GetOrderHistory(ctx context.Context, req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -733,7 +741,7 @@ func (b *Bithumb) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail,
|
||||
|
||||
var orders []order.Detail
|
||||
for x := range req.Pairs {
|
||||
resp, err := b.GetOrders("", "", "1000", "", req.Pairs[x].Base.String())
|
||||
resp, err := b.GetOrders(ctx, "", "", "1000", "", req.Pairs[x].Base.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -774,8 +782,8 @@ func (b *Bithumb) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail,
|
||||
|
||||
// ValidateCredentials validates current credentials used for wrapper
|
||||
// functionality
|
||||
func (b *Bithumb) ValidateCredentials(assetType asset.Item) error {
|
||||
_, err := b.UpdateAccountInfo(assetType)
|
||||
func (b *Bithumb) ValidateCredentials(ctx context.Context, assetType asset.Item) error {
|
||||
_, err := b.UpdateAccountInfo(ctx, assetType)
|
||||
return b.CheckTransientError(err)
|
||||
}
|
||||
|
||||
@@ -785,7 +793,7 @@ func (b *Bithumb) FormatExchangeKlineInterval(in kline.Interval) string {
|
||||
}
|
||||
|
||||
// GetHistoricCandles returns candles between a time period for a set time interval
|
||||
func (b *Bithumb) GetHistoricCandles(pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
|
||||
func (b *Bithumb) 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
|
||||
}
|
||||
@@ -795,7 +803,7 @@ func (b *Bithumb) GetHistoricCandles(pair currency.Pair, a asset.Item, start, en
|
||||
return kline.Item{}, err
|
||||
}
|
||||
|
||||
candle, err := b.GetCandleStick(formattedPair.String(),
|
||||
candle, err := b.GetCandleStick(ctx, formattedPair.String(),
|
||||
b.FormatExchangeKlineInterval(interval))
|
||||
if err != nil {
|
||||
return kline.Item{}, err
|
||||
@@ -871,13 +879,13 @@ func (b *Bithumb) GetHistoricCandles(pair currency.Pair, a asset.Item, start, en
|
||||
}
|
||||
|
||||
// GetHistoricCandlesExtended returns candles between a time period for a set time interval
|
||||
func (b *Bithumb) GetHistoricCandlesExtended(pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
|
||||
return b.GetHistoricCandles(pair, a, start, end, interval)
|
||||
func (b *Bithumb) GetHistoricCandlesExtended(ctx context.Context, pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
|
||||
return b.GetHistoricCandles(ctx, pair, a, start, end, interval)
|
||||
}
|
||||
|
||||
// UpdateOrderExecutionLimits sets exchange executions for a required asset type
|
||||
func (b *Bithumb) UpdateOrderExecutionLimits(_ asset.Item) error {
|
||||
limits, err := b.FetchExchangeLimits()
|
||||
func (b *Bithumb) UpdateOrderExecutionLimits(ctx context.Context, _ asset.Item) error {
|
||||
limits, err := b.FetchExchangeLimits(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot update exchange execution limits: %w", err)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package bithumb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
@@ -139,7 +140,7 @@ func (b *Bithumb) SynchroniseWebsocketOrderbook() {
|
||||
|
||||
// processJob fetches and processes orderbook updates
|
||||
func (b *Bithumb) processJob(p currency.Pair) error {
|
||||
err := b.SeedLocalCache(p)
|
||||
err := b.SeedLocalCache(context.TODO(), p)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s %s seeding local cache for orderbook error: %v",
|
||||
p, asset.Spot, err)
|
||||
@@ -414,8 +415,8 @@ bufferEmpty:
|
||||
}
|
||||
|
||||
// SeedLocalCache seeds depth data
|
||||
func (b *Bithumb) SeedLocalCache(p currency.Pair) error {
|
||||
ob, err := b.GetOrderBook(p.String())
|
||||
func (b *Bithumb) SeedLocalCache(ctx context.Context, p currency.Pair) error {
|
||||
ob, err := b.GetOrderBook(ctx, p.String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user