mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-31 07:26:44 +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:
@@ -73,75 +73,75 @@ type Bitflyer struct {
|
||||
|
||||
// GetLatestBlockCA returns the latest block information from bitflyer chain
|
||||
// analysis system
|
||||
func (b *Bitflyer) GetLatestBlockCA() (ChainAnalysisBlock, error) {
|
||||
func (b *Bitflyer) GetLatestBlockCA(ctx context.Context) (ChainAnalysisBlock, error) {
|
||||
var resp ChainAnalysisBlock
|
||||
return resp, b.SendHTTPRequest(exchange.ChainAnalysis, latestBlock, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.ChainAnalysis, latestBlock, &resp)
|
||||
}
|
||||
|
||||
// GetBlockCA returns block information by blockhash from bitflyer chain
|
||||
// analysis system
|
||||
func (b *Bitflyer) GetBlockCA(blockhash string) (ChainAnalysisBlock, error) {
|
||||
func (b *Bitflyer) GetBlockCA(ctx context.Context, blockhash string) (ChainAnalysisBlock, error) {
|
||||
var resp ChainAnalysisBlock
|
||||
return resp, b.SendHTTPRequest(exchange.ChainAnalysis, blockByBlockHash+blockhash, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.ChainAnalysis, blockByBlockHash+blockhash, &resp)
|
||||
}
|
||||
|
||||
// GetBlockbyHeightCA returns the block information by height from bitflyer chain
|
||||
// analysis system
|
||||
func (b *Bitflyer) GetBlockbyHeightCA(height int64) (ChainAnalysisBlock, error) {
|
||||
func (b *Bitflyer) GetBlockbyHeightCA(ctx context.Context, height int64) (ChainAnalysisBlock, error) {
|
||||
var resp ChainAnalysisBlock
|
||||
return resp, b.SendHTTPRequest(exchange.ChainAnalysis, blockByBlockHeight+strconv.FormatInt(height, 10), &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.ChainAnalysis, blockByBlockHeight+strconv.FormatInt(height, 10), &resp)
|
||||
}
|
||||
|
||||
// GetTransactionByHashCA returns transaction information by txHash from
|
||||
// bitflyer chain analysis system
|
||||
func (b *Bitflyer) GetTransactionByHashCA(txHash string) (ChainAnalysisTransaction, error) {
|
||||
func (b *Bitflyer) GetTransactionByHashCA(ctx context.Context, txHash string) (ChainAnalysisTransaction, error) {
|
||||
var resp ChainAnalysisTransaction
|
||||
return resp, b.SendHTTPRequest(exchange.ChainAnalysis, transaction+txHash, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.ChainAnalysis, transaction+txHash, &resp)
|
||||
}
|
||||
|
||||
// GetAddressInfoCA returns balance information for address by addressln string
|
||||
// from bitflyer chain analysis system
|
||||
func (b *Bitflyer) GetAddressInfoCA(addressln string) (ChainAnalysisAddress, error) {
|
||||
func (b *Bitflyer) GetAddressInfoCA(ctx context.Context, addressln string) (ChainAnalysisAddress, error) {
|
||||
var resp ChainAnalysisAddress
|
||||
return resp, b.SendHTTPRequest(exchange.ChainAnalysis, address+addressln, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.ChainAnalysis, address+addressln, &resp)
|
||||
}
|
||||
|
||||
// GetMarkets returns market information
|
||||
func (b *Bitflyer) GetMarkets() ([]MarketInfo, error) {
|
||||
func (b *Bitflyer) GetMarkets(ctx context.Context) ([]MarketInfo, error) {
|
||||
var resp []MarketInfo
|
||||
return resp, b.SendHTTPRequest(exchange.RestSpot, pubGetMarkets, &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestSpot, pubGetMarkets, &resp)
|
||||
}
|
||||
|
||||
// GetOrderBook returns market orderbook depth
|
||||
func (b *Bitflyer) GetOrderBook(symbol string) (Orderbook, error) {
|
||||
func (b *Bitflyer) GetOrderBook(ctx context.Context, symbol string) (Orderbook, error) {
|
||||
var resp Orderbook
|
||||
v := url.Values{}
|
||||
v.Set("product_code", symbol)
|
||||
|
||||
return resp, b.SendHTTPRequest(exchange.RestSpot, pubGetBoard+"?"+v.Encode(), &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestSpot, pubGetBoard+"?"+v.Encode(), &resp)
|
||||
}
|
||||
|
||||
// GetTicker returns ticker information
|
||||
func (b *Bitflyer) GetTicker(symbol string) (Ticker, error) {
|
||||
func (b *Bitflyer) GetTicker(ctx context.Context, symbol string) (Ticker, error) {
|
||||
var resp Ticker
|
||||
v := url.Values{}
|
||||
v.Set("product_code", symbol)
|
||||
return resp, b.SendHTTPRequest(exchange.RestSpot, pubGetTicker+"?"+v.Encode(), &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestSpot, pubGetTicker+"?"+v.Encode(), &resp)
|
||||
}
|
||||
|
||||
// GetExecutionHistory returns past trades that were executed on the market
|
||||
func (b *Bitflyer) GetExecutionHistory(symbol string) ([]ExecutedTrade, error) {
|
||||
func (b *Bitflyer) GetExecutionHistory(ctx context.Context, symbol string) ([]ExecutedTrade, error) {
|
||||
var resp []ExecutedTrade
|
||||
v := url.Values{}
|
||||
v.Set("product_code", symbol)
|
||||
|
||||
return resp, b.SendHTTPRequest(exchange.RestSpot, pubGetExecutionHistory+"?"+v.Encode(), &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestSpot, pubGetExecutionHistory+"?"+v.Encode(), &resp)
|
||||
}
|
||||
|
||||
// GetExchangeStatus returns exchange status information
|
||||
func (b *Bitflyer) GetExchangeStatus() (string, error) {
|
||||
func (b *Bitflyer) GetExchangeStatus(ctx context.Context) (string, error) {
|
||||
resp := make(map[string]string)
|
||||
err := b.SendHTTPRequest(exchange.RestSpot, pubGetHealth, &resp)
|
||||
err := b.SendHTTPRequest(ctx, exchange.RestSpot, pubGetHealth, &resp)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -162,11 +162,11 @@ func (b *Bitflyer) GetExchangeStatus() (string, error) {
|
||||
|
||||
// GetChats returns trollbox chat log
|
||||
// Note: returns vary from instant to infinty
|
||||
func (b *Bitflyer) GetChats(fromDate string) ([]ChatLog, error) {
|
||||
func (b *Bitflyer) GetChats(ctx context.Context, fromDate string) ([]ChatLog, error) {
|
||||
var resp []ChatLog
|
||||
v := url.Values{}
|
||||
v.Set("from_date", fromDate)
|
||||
return resp, b.SendHTTPRequest(exchange.RestSpot, pubGetChats+"?"+v.Encode(), &resp)
|
||||
return resp, b.SendHTTPRequest(ctx, exchange.RestSpot, pubGetChats+"?"+v.Encode(), &resp)
|
||||
}
|
||||
|
||||
// GetPermissions returns current permissions for associated with your API
|
||||
@@ -286,7 +286,7 @@ func (b *Bitflyer) GetTradingCommission() {
|
||||
}
|
||||
|
||||
// SendHTTPRequest sends an unauthenticated request
|
||||
func (b *Bitflyer) SendHTTPRequest(ep exchange.URL, path string, result interface{}) error {
|
||||
func (b *Bitflyer) SendHTTPRequest(ctx context.Context, ep exchange.URL, path string, result interface{}) error {
|
||||
endpoint, err := b.API.Endpoints.GetURL(ep)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -299,7 +299,7 @@ func (b *Bitflyer) SendHTTPRequest(ep exchange.URL, path string, result interfac
|
||||
HTTPDebugging: b.HTTPDebugging,
|
||||
HTTPRecording: b.HTTPRecording,
|
||||
}
|
||||
return b.SendPayload(context.Background(), request.Unset, func() (*request.Item, error) {
|
||||
return b.SendPayload(ctx, request.Unset, func() (*request.Item, error) {
|
||||
return item, nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package bitflyer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
@@ -50,7 +51,7 @@ func TestMain(m *testing.M) {
|
||||
|
||||
func TestGetLatestBlockCA(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetLatestBlockCA()
|
||||
_, err := b.GetLatestBlockCA(context.Background())
|
||||
if err != nil {
|
||||
t.Error("Bitflyer - GetLatestBlockCA() error:", err)
|
||||
}
|
||||
@@ -58,7 +59,7 @@ func TestGetLatestBlockCA(t *testing.T) {
|
||||
|
||||
func TestGetBlockCA(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetBlockCA("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f")
|
||||
_, err := b.GetBlockCA(context.Background(), "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f")
|
||||
if err != nil {
|
||||
t.Error("Bitflyer - GetBlockCA() error:", err)
|
||||
}
|
||||
@@ -66,7 +67,7 @@ func TestGetBlockCA(t *testing.T) {
|
||||
|
||||
func TestGetBlockbyHeightCA(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetBlockbyHeightCA(0)
|
||||
_, err := b.GetBlockbyHeightCA(context.Background(), 0)
|
||||
if err != nil {
|
||||
t.Error("Bitflyer - GetBlockbyHeightCA() error:", err)
|
||||
}
|
||||
@@ -74,7 +75,7 @@ func TestGetBlockbyHeightCA(t *testing.T) {
|
||||
|
||||
func TestGetTransactionByHashCA(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetTransactionByHashCA("0562d1f063cd4127053d838b165630445af5e480ceb24e1fd9ecea52903cb772")
|
||||
_, err := b.GetTransactionByHashCA(context.Background(), "0562d1f063cd4127053d838b165630445af5e480ceb24e1fd9ecea52903cb772")
|
||||
if err != nil {
|
||||
t.Error("Bitflyer - GetTransactionByHashCA() error:", err)
|
||||
}
|
||||
@@ -82,7 +83,7 @@ func TestGetTransactionByHashCA(t *testing.T) {
|
||||
|
||||
func TestGetAddressInfoCA(t *testing.T) {
|
||||
t.Parallel()
|
||||
v, err := b.GetAddressInfoCA(core.BitcoinDonationAddress)
|
||||
v, err := b.GetAddressInfoCA(context.Background(), core.BitcoinDonationAddress)
|
||||
if err != nil {
|
||||
t.Error("Bitflyer - GetAddressInfoCA() error:", err)
|
||||
}
|
||||
@@ -93,7 +94,7 @@ func TestGetAddressInfoCA(t *testing.T) {
|
||||
|
||||
func TestGetMarkets(t *testing.T) {
|
||||
t.Parallel()
|
||||
markets, err := b.GetMarkets()
|
||||
markets, err := b.GetMarkets(context.Background())
|
||||
if err != nil {
|
||||
t.Error("Bitflyer - GetMarkets() error:", err)
|
||||
}
|
||||
@@ -109,7 +110,7 @@ func TestGetMarkets(t *testing.T) {
|
||||
|
||||
func TestGetOrderBook(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetOrderBook("BTC_JPY")
|
||||
_, err := b.GetOrderBook(context.Background(), "BTC_JPY")
|
||||
if err != nil {
|
||||
t.Error("Bitflyer - GetOrderBook() error:", err)
|
||||
}
|
||||
@@ -117,7 +118,7 @@ func TestGetOrderBook(t *testing.T) {
|
||||
|
||||
func TestGetTicker(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetTicker("BTC_JPY")
|
||||
_, err := b.GetTicker(context.Background(), "BTC_JPY")
|
||||
if err != nil {
|
||||
t.Error("Bitflyer - GetTicker() error:", err)
|
||||
}
|
||||
@@ -125,7 +126,7 @@ func TestGetTicker(t *testing.T) {
|
||||
|
||||
func TestGetExecutionHistory(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetExecutionHistory("BTC_JPY")
|
||||
_, err := b.GetExecutionHistory(context.Background(), "BTC_JPY")
|
||||
if err != nil {
|
||||
t.Error("Bitflyer - GetExecutionHistory() error:", err)
|
||||
}
|
||||
@@ -133,7 +134,7 @@ func TestGetExecutionHistory(t *testing.T) {
|
||||
|
||||
func TestGetExchangeStatus(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetExchangeStatus()
|
||||
_, err := b.GetExchangeStatus(context.Background())
|
||||
if err != nil {
|
||||
t.Error("Bitflyer - GetExchangeStatus() error:", err)
|
||||
}
|
||||
@@ -167,7 +168,7 @@ func TestFetchTicker(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
_, err = b.FetchTicker(p, asset.Spot)
|
||||
_, err = b.FetchTicker(context.Background(), p, asset.Spot)
|
||||
if err != nil {
|
||||
t.Error("Bitflyer - FetchTicker() error", err)
|
||||
}
|
||||
@@ -187,7 +188,7 @@ func setFeeBuilder() *exchange.FeeBuilder {
|
||||
// TestGetFeeByTypeOfflineTradeFee logic test
|
||||
func TestGetFeeByTypeOfflineTradeFee(t *testing.T) {
|
||||
var feeBuilder = setFeeBuilder()
|
||||
_, err := b.GetFeeByType(feeBuilder)
|
||||
_, err := b.GetFeeByType(context.Background(), feeBuilder)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -282,7 +283,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 {
|
||||
@@ -297,7 +298,7 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
_, err := b.GetOrderHistory(&getOrdersRequest)
|
||||
_, err := b.GetOrderHistory(context.Background(), &getOrdersRequest)
|
||||
if err != common.ErrNotYetImplemented {
|
||||
t.Errorf("Expected '%v', received '%v'", common.ErrNotYetImplemented, err)
|
||||
}
|
||||
@@ -327,7 +328,7 @@ func TestSubmitOrder(t *testing.T) {
|
||||
ClientID: "meowOrder",
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
_, err := b.SubmitOrder(orderSubmission)
|
||||
_, err := b.SubmitOrder(context.Background(), orderSubmission)
|
||||
if err != common.ErrNotYetImplemented {
|
||||
t.Errorf("Expected 'Not Yet Implemented', received %v", err)
|
||||
}
|
||||
@@ -348,7 +349,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
err := b.CancelOrder(orderCancellation)
|
||||
err := b.CancelOrder(context.Background(), orderCancellation)
|
||||
|
||||
if err != common.ErrNotYetImplemented {
|
||||
t.Errorf("Expected 'Not Yet Implemented', received %v", err)
|
||||
@@ -370,7 +371,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
_, err := b.CancelAllOrders(orderCancellation)
|
||||
_, err := b.CancelAllOrders(context.Background(), orderCancellation)
|
||||
|
||||
if err != common.ErrNotYetImplemented {
|
||||
t.Errorf("Expected 'Not Yet Implemented', received %v", err)
|
||||
@@ -392,7 +393,8 @@ func TestWithdraw(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
_, err := b.WithdrawCryptocurrencyFunds(&withdrawCryptoRequest)
|
||||
_, err := b.WithdrawCryptocurrencyFunds(context.Background(),
|
||||
&withdrawCryptoRequest)
|
||||
if err != common.ErrNotYetImplemented {
|
||||
t.Errorf("Expected 'Not Yet Implemented', received %v", err)
|
||||
}
|
||||
@@ -403,7 +405,8 @@ func TestModifyOrder(t *testing.T) {
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
_, err := b.ModifyOrder(&order.Modify{AssetType: asset.Spot})
|
||||
_, err := b.ModifyOrder(context.Background(),
|
||||
&order.Modify{AssetType: asset.Spot})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
}
|
||||
@@ -417,7 +420,7 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
|
||||
_, err := b.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
_, err := b.WithdrawFiatFunds(context.Background(), &withdrawFiatRequest)
|
||||
if err != common.ErrNotYetImplemented {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrNotYetImplemented, err)
|
||||
}
|
||||
@@ -431,7 +434,8 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
|
||||
_, err := b.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
_, err := b.WithdrawFiatFundsToInternationalBank(context.Background(),
|
||||
&withdrawFiatRequest)
|
||||
if err != common.ErrNotYetImplemented {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrNotYetImplemented, err)
|
||||
}
|
||||
@@ -443,7 +447,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)
|
||||
}
|
||||
@@ -455,7 +459,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.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package bitflyer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -38,7 +39,7 @@ func (b *Bitflyer) 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
|
||||
}
|
||||
@@ -132,15 +133,15 @@ func (b *Bitflyer) 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 *Bitflyer) FetchTradablePairs(a asset.Item) ([]string, error) {
|
||||
pairs, err := b.GetMarkets()
|
||||
func (b *Bitflyer) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string, error) {
|
||||
pairs, err := b.GetMarkets(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -166,10 +167,10 @@ func (b *Bitflyer) FetchTradablePairs(a asset.Item) ([]string, error) {
|
||||
|
||||
// UpdateTradablePairs updates the exchanges available pairs and stores
|
||||
// them in the exchanges config
|
||||
func (b *Bitflyer) UpdateTradablePairs(forceUpdate bool) error {
|
||||
func (b *Bitflyer) UpdateTradablePairs(ctx context.Context, forceUpdate bool) error {
|
||||
assets := b.CurrencyPairs.GetAssetTypes(false)
|
||||
for x := range assets {
|
||||
pairs, err := b.FetchTradablePairs(assets[x])
|
||||
pairs, err := b.FetchTradablePairs(ctx, assets[x])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -188,18 +189,18 @@ func (b *Bitflyer) UpdateTradablePairs(forceUpdate bool) error {
|
||||
}
|
||||
|
||||
// UpdateTickers updates the ticker for all currency pairs of a given asset type
|
||||
func (b *Bitflyer) UpdateTickers(a asset.Item) error {
|
||||
func (b *Bitflyer) UpdateTickers(ctx context.Context, a asset.Item) error {
|
||||
return common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (b *Bitflyer) UpdateTicker(p currency.Pair, a asset.Item) (*ticker.Price, error) {
|
||||
func (b *Bitflyer) UpdateTicker(ctx context.Context, p currency.Pair, a asset.Item) (*ticker.Price, error) {
|
||||
fPair, err := b.FormatExchangeCurrency(p, a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tickerNew, err := b.GetTicker(b.CheckFXString(fPair).String())
|
||||
tickerNew, err := b.GetTicker(ctx, b.CheckFXString(fPair).String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -220,7 +221,7 @@ func (b *Bitflyer) UpdateTicker(p currency.Pair, a asset.Item) (*ticker.Price, e
|
||||
}
|
||||
|
||||
// FetchTicker returns the ticker for a currency pair
|
||||
func (b *Bitflyer) FetchTicker(p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
|
||||
func (b *Bitflyer) FetchTicker(ctx context.Context, p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
|
||||
fPair, err := b.FormatExchangeCurrency(p, assetType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -228,7 +229,7 @@ func (b *Bitflyer) FetchTicker(p currency.Pair, assetType asset.Item) (*ticker.P
|
||||
|
||||
tick, err := ticker.GetTicker(b.Name, fPair, assetType)
|
||||
if err != nil {
|
||||
return b.UpdateTicker(fPair, assetType)
|
||||
return b.UpdateTicker(ctx, fPair, assetType)
|
||||
}
|
||||
return tick, nil
|
||||
}
|
||||
@@ -243,7 +244,7 @@ func (b *Bitflyer) CheckFXString(p currency.Pair) currency.Pair {
|
||||
}
|
||||
|
||||
// FetchOrderbook returns the orderbook for a currency pair
|
||||
func (b *Bitflyer) FetchOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
func (b *Bitflyer) FetchOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
fPair, err := b.FormatExchangeCurrency(p, assetType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -251,13 +252,13 @@ func (b *Bitflyer) FetchOrderbook(p currency.Pair, assetType asset.Item) (*order
|
||||
|
||||
ob, err := orderbook.Get(b.Name, fPair, assetType)
|
||||
if err != nil {
|
||||
return b.UpdateOrderbook(fPair, assetType)
|
||||
return b.UpdateOrderbook(ctx, fPair, assetType)
|
||||
}
|
||||
return ob, nil
|
||||
}
|
||||
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func (b *Bitflyer) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
func (b *Bitflyer) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
book := &orderbook.Base{
|
||||
Exchange: b.Name,
|
||||
Pair: p,
|
||||
@@ -270,7 +271,7 @@ func (b *Bitflyer) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orde
|
||||
return book, err
|
||||
}
|
||||
|
||||
orderbookNew, err := b.GetOrderBook(b.CheckFXString(fPair).String())
|
||||
orderbookNew, err := b.GetOrderBook(ctx, b.CheckFXString(fPair).String())
|
||||
if err != nil {
|
||||
return book, err
|
||||
}
|
||||
@@ -297,15 +298,15 @@ func (b *Bitflyer) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orde
|
||||
|
||||
// UpdateAccountInfo retrieves balances for all enabled currencies on the
|
||||
// Bitflyer exchange
|
||||
func (b *Bitflyer) UpdateAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
func (b *Bitflyer) UpdateAccountInfo(_ context.Context, _ asset.Item) (account.Holdings, error) {
|
||||
return account.Holdings{}, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// FetchAccountInfo retrieves balances for all enabled currencies
|
||||
func (b *Bitflyer) FetchAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
func (b *Bitflyer) 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
|
||||
@@ -313,23 +314,23 @@ func (b *Bitflyer) FetchAccountInfo(assetType asset.Item) (account.Holdings, err
|
||||
|
||||
// GetFundingHistory returns funding history, deposits and
|
||||
// withdrawals
|
||||
func (b *Bitflyer) GetFundingHistory() ([]exchange.FundHistory, error) {
|
||||
func (b *Bitflyer) GetFundingHistory(_ context.Context) ([]exchange.FundHistory, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetWithdrawalsHistory returns previous withdrawals data
|
||||
func (b *Bitflyer) GetWithdrawalsHistory(c currency.Code) (resp []exchange.WithdrawalHistory, err error) {
|
||||
func (b *Bitflyer) GetWithdrawalsHistory(_ context.Context, _ currency.Code) (resp []exchange.WithdrawalHistory, err error) {
|
||||
return nil, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// GetRecentTrades returns recent historic trades
|
||||
func (b *Bitflyer) GetRecentTrades(p currency.Pair, assetType asset.Item) ([]trade.Data, error) {
|
||||
func (b *Bitflyer) 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.GetExecutionHistory(p.String())
|
||||
tradeData, err := b.GetExecutionHistory(ctx, p.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -367,80 +368,80 @@ func (b *Bitflyer) GetRecentTrades(p currency.Pair, assetType asset.Item) ([]tra
|
||||
}
|
||||
|
||||
// GetHistoricTrades returns historic trade data within the timeframe provided
|
||||
func (b *Bitflyer) GetHistoricTrades(_ currency.Pair, _ asset.Item, _, _ time.Time) ([]trade.Data, error) {
|
||||
func (b *Bitflyer) GetHistoricTrades(_ context.Context, _ currency.Pair, _ asset.Item, _, _ time.Time) ([]trade.Data, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (b *Bitflyer) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
func (b *Bitflyer) SubmitOrder(_ context.Context, _ *order.Submit) (order.SubmitResponse, error) {
|
||||
return order.SubmitResponse{}, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (b *Bitflyer) ModifyOrder(action *order.Modify) (order.Modify, error) {
|
||||
func (b *Bitflyer) ModifyOrder(_ context.Context, _ *order.Modify) (order.Modify, error) {
|
||||
return order.Modify{}, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (b *Bitflyer) CancelOrder(_ *order.Cancel) error {
|
||||
func (b *Bitflyer) CancelOrder(_ context.Context, _ *order.Cancel) error {
|
||||
return common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// CancelBatchOrders cancels an orders by their corresponding ID numbers
|
||||
func (b *Bitflyer) CancelBatchOrders(_ []order.Cancel) (order.CancelBatchResponse, error) {
|
||||
func (b *Bitflyer) CancelBatchOrders(_ context.Context, _ []order.Cancel) (order.CancelBatchResponse, error) {
|
||||
return order.CancelBatchResponse{}, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (b *Bitflyer) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
func (b *Bitflyer) CancelAllOrders(_ context.Context, _ *order.Cancel) (order.CancelAllResponse, error) {
|
||||
// TODO, implement BitFlyer API
|
||||
b.CancelAllExistingOrders()
|
||||
return order.CancelAllResponse{}, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (b *Bitflyer) GetOrderInfo(_ string, _ currency.Pair, _ asset.Item) (order.Detail, error) {
|
||||
func (b *Bitflyer) GetOrderInfo(_ context.Context, _ string, _ currency.Pair, _ asset.Item) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
return orderDetail, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// GetDepositAddress returns a deposit address for a specified currency
|
||||
func (b *Bitflyer) GetDepositAddress(_ currency.Code, _ string) (string, error) {
|
||||
func (b *Bitflyer) GetDepositAddress(_ context.Context, _ currency.Code, _ string) (string, error) {
|
||||
return "", common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (b *Bitflyer) WithdrawCryptocurrencyFunds(_ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
func (b *Bitflyer) WithdrawCryptocurrencyFunds(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (b *Bitflyer) WithdrawFiatFunds(_ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
func (b *Bitflyer) WithdrawFiatFunds(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (b *Bitflyer) WithdrawFiatFundsToInternationalBank(_ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
func (b *Bitflyer) WithdrawFiatFundsToInternationalBank(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (b *Bitflyer) GetActiveOrders(_ *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
func (b *Bitflyer) GetActiveOrders(_ context.Context, _ *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
return nil, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
func (b *Bitflyer) GetOrderHistory(_ *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
func (b *Bitflyer) GetOrderHistory(_ context.Context, _ *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
return nil, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// GetFeeByType returns an estimate of fee based on the type of transaction
|
||||
func (b *Bitflyer) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error) {
|
||||
func (b *Bitflyer) GetFeeByType(ctx context.Context, feeBuilder *exchange.FeeBuilder) (float64, error) {
|
||||
if !b.AllowAuthenticatedRequest() && // Todo check connection status
|
||||
feeBuilder.FeeType == exchange.CryptocurrencyTradeFee {
|
||||
feeBuilder.FeeType = exchange.OfflineTradeFee
|
||||
@@ -450,17 +451,17 @@ func (b *Bitflyer) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error
|
||||
|
||||
// ValidateCredentials validates current credentials used for wrapper
|
||||
// functionality
|
||||
func (b *Bitflyer) ValidateCredentials(assetType asset.Item) error {
|
||||
_, err := b.UpdateAccountInfo(assetType)
|
||||
func (b *Bitflyer) ValidateCredentials(ctx context.Context, assetType asset.Item) error {
|
||||
_, err := b.UpdateAccountInfo(ctx, assetType)
|
||||
return b.CheckTransientError(err)
|
||||
}
|
||||
|
||||
// GetHistoricCandles returns candles between a time period for a set time interval
|
||||
func (b *Bitflyer) GetHistoricCandles(pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
|
||||
func (b *Bitflyer) GetHistoricCandles(_ context.Context, _ currency.Pair, _ asset.Item, _, _ time.Time, _ kline.Interval) (kline.Item, error) {
|
||||
return kline.Item{}, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetHistoricCandlesExtended returns candles between a time period for a set time interval
|
||||
func (b *Bitflyer) GetHistoricCandlesExtended(pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
|
||||
func (b *Bitflyer) GetHistoricCandlesExtended(_ context.Context, _ currency.Pair, _ asset.Item, _, _ time.Time, _ kline.Interval) (kline.Item, error) {
|
||||
return kline.Item{}, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user