mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-08 07:26:48 +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:
@@ -1,6 +1,7 @@
|
||||
package exmo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
@@ -52,7 +53,7 @@ func TestMain(m *testing.M) {
|
||||
|
||||
func TestGetTrades(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := e.GetTrades("BTC_USD")
|
||||
_, err := e.GetTrades(context.Background(), "BTC_USD")
|
||||
if err != nil {
|
||||
t.Errorf("Err: %s", err)
|
||||
}
|
||||
@@ -60,7 +61,7 @@ func TestGetTrades(t *testing.T) {
|
||||
|
||||
func TestGetOrderbook(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := e.GetOrderbook("BTC_USD")
|
||||
_, err := e.GetOrderbook(context.Background(), "BTC_USD")
|
||||
if err != nil {
|
||||
t.Errorf("Err: %s", err)
|
||||
}
|
||||
@@ -68,7 +69,7 @@ func TestGetOrderbook(t *testing.T) {
|
||||
|
||||
func TestGetTicker(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := e.GetTicker()
|
||||
_, err := e.GetTicker(context.Background())
|
||||
if err != nil {
|
||||
t.Errorf("Err: %s", err)
|
||||
}
|
||||
@@ -76,7 +77,7 @@ func TestGetTicker(t *testing.T) {
|
||||
|
||||
func TestGetPairSettings(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := e.GetPairSettings()
|
||||
_, err := e.GetPairSettings(context.Background())
|
||||
if err != nil {
|
||||
t.Errorf("Err: %s", err)
|
||||
}
|
||||
@@ -84,7 +85,7 @@ func TestGetPairSettings(t *testing.T) {
|
||||
|
||||
func TestGetCurrency(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := e.GetCurrency()
|
||||
_, err := e.GetCurrency(context.Background())
|
||||
if err != nil {
|
||||
t.Errorf("Err: %s", err)
|
||||
}
|
||||
@@ -95,7 +96,7 @@ func TestGetUserInfo(t *testing.T) {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip()
|
||||
}
|
||||
_, err := e.GetUserInfo()
|
||||
_, err := e.GetUserInfo(context.Background())
|
||||
if err != nil {
|
||||
t.Errorf("Err: %s", err)
|
||||
}
|
||||
@@ -106,7 +107,7 @@ func TestGetRequiredAmount(t *testing.T) {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip()
|
||||
}
|
||||
_, err := e.GetRequiredAmount("BTC_USD", 100)
|
||||
_, err := e.GetRequiredAmount(context.Background(), "BTC_USD", 100)
|
||||
if err != nil {
|
||||
t.Errorf("Err: %s", err)
|
||||
}
|
||||
@@ -126,7 +127,7 @@ func setFeeBuilder() *exchange.FeeBuilder {
|
||||
// TestGetFeeByTypeOfflineTradeFee logic test
|
||||
func TestGetFeeByTypeOfflineTradeFee(t *testing.T) {
|
||||
var feeBuilder = setFeeBuilder()
|
||||
_, err := e.GetFeeByType(feeBuilder)
|
||||
_, err := e.GetFeeByType(context.Background(), feeBuilder)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -258,7 +259,7 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
_, err := e.GetActiveOrders(&getOrdersRequest)
|
||||
_, err := e.GetActiveOrders(context.Background(), &getOrdersRequest)
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
t.Errorf("Could not get open orders: %s", err)
|
||||
} else if !areTestAPIKeysSet() && err == nil {
|
||||
@@ -275,7 +276,7 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
currPair.Delimiter = "_"
|
||||
getOrdersRequest.Pairs = []currency.Pair{currPair}
|
||||
|
||||
_, err := e.GetOrderHistory(&getOrdersRequest)
|
||||
_, err := e.GetOrderHistory(context.Background(), &getOrdersRequest)
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
t.Errorf("Could not get order history: %s", err)
|
||||
} else if !areTestAPIKeysSet() && err == nil {
|
||||
@@ -307,7 +308,7 @@ func TestSubmitOrder(t *testing.T) {
|
||||
ClientID: "meowOrder",
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
response, err := e.SubmitOrder(orderSubmission)
|
||||
response, err := e.SubmitOrder(context.Background(), orderSubmission)
|
||||
if areTestAPIKeysSet() && (err != nil || !response.IsOrderPlaced) {
|
||||
t.Errorf("Order failed to be placed: %v", err)
|
||||
} else if !areTestAPIKeysSet() && err == nil {
|
||||
@@ -329,7 +330,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
err := e.CancelOrder(orderCancellation)
|
||||
err := e.CancelOrder(context.Background(), orderCancellation)
|
||||
if !areTestAPIKeysSet() && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
@@ -352,7 +353,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
resp, err := e.CancelAllOrders(orderCancellation)
|
||||
resp, err := e.CancelAllOrders(context.Background(), orderCancellation)
|
||||
|
||||
if !areTestAPIKeysSet() && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
@@ -370,7 +371,7 @@ func TestModifyOrder(t *testing.T) {
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
_, err := e.ModifyOrder(&order.Modify{AssetType: asset.Spot})
|
||||
_, err := e.ModifyOrder(context.Background(), &order.Modify{AssetType: asset.Spot})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
}
|
||||
@@ -390,7 +391,8 @@ func TestWithdraw(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
_, err := e.WithdrawCryptocurrencyFunds(&withdrawCryptoRequest)
|
||||
_, err := e.WithdrawCryptocurrencyFunds(context.Background(),
|
||||
&withdrawCryptoRequest)
|
||||
if !areTestAPIKeysSet() && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
@@ -405,7 +407,7 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := e.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
_, err := e.WithdrawFiatFunds(context.Background(), &withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
}
|
||||
@@ -417,7 +419,8 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := e.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
_, err := e.WithdrawFiatFundsToInternationalBank(context.Background(),
|
||||
&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
}
|
||||
@@ -425,12 +428,12 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
|
||||
func TestGetDepositAddress(t *testing.T) {
|
||||
if areTestAPIKeysSet() {
|
||||
_, err := e.GetDepositAddress(currency.LTC, "")
|
||||
_, err := e.GetDepositAddress(context.Background(), currency.LTC, "")
|
||||
if err != nil {
|
||||
t.Error("GetDepositAddress() error", err)
|
||||
}
|
||||
} else {
|
||||
_, err := e.GetDepositAddress(currency.LTC, "")
|
||||
_, err := e.GetDepositAddress(context.Background(), currency.LTC, "")
|
||||
if err == nil {
|
||||
t.Error("GetDepositAddress() error cannot be nil")
|
||||
}
|
||||
@@ -443,7 +446,7 @@ func TestGetRecentTrades(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = e.GetRecentTrades(currencyPair, asset.Spot)
|
||||
_, err = e.GetRecentTrades(context.Background(), currencyPair, asset.Spot)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -455,7 +458,8 @@ func TestGetHistoricTrades(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = e.GetHistoricTrades(currencyPair, asset.Spot, time.Now().Add(-time.Minute*15), time.Now())
|
||||
_, err = e.GetHistoricTrades(context.Background(),
|
||||
currencyPair, asset.Spot, time.Now().Add(-time.Minute*15), time.Now())
|
||||
if err != nil && err != common.ErrFunctionNotSupported {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -467,14 +471,14 @@ func TestUpdateTicker(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = e.UpdateTicker(cp, asset.Spot)
|
||||
_, err = e.UpdateTicker(context.Background(), cp, asset.Spot)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateTickers(t *testing.T) {
|
||||
err := e.UpdateTickers(asset.Spot)
|
||||
err := e.UpdateTickers(context.Background(), asset.Spot)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user