mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-04 07:26:47 +00:00
Currency: Add additional functionality, refactor and improvements (#881)
* currency: Add method to derive pair * currency: Add method to lower entire charset but used the slice copy and returned that. This will change the original, just gotta see if this is an issue, but the slice usually goes out of scope anyway. * currency/pairs: add filter method * currency: add function to derive select currencies from currency pairs * currency/engine: slight adjustments * currency: fix linter issue also shift burden of proof to caller instead of repair, more performant. * currency: more linter * pairs: optimize; reduce allocs/op and B/op * currency: Add in function 'NewPairsFromString' for testing purposes * currency: don't suppress error * currency: stop panic on empty currency code * currency: Add helper method to match currencies between exchanges * currency: fixed my bad spelling * currency: Implement stable coin checks, refactored base code methods, optimized upper and lower case strings for currency code/pairs * currency: add pairs method to derive stable coins from internal list. * Currency: Cleanup, fix tests. * engine/exchanges/currency: fix whoops * Currency: force govet no copy on Item datatype * Currency: fix naughty linter issues * exchange: revert change * currency/config: fix config upgrade mistake * currency: re-implement currency sub-systems * *RetrieveConfigCurrencyPairs removed *CheckCurrencyConfigValues to only provide warnings, add additional support when, disable when support is lost or not available and set default values. *Drop Cryptocurrencies from configuration as this is not needed. *Drop REST Poll delay field as this was unused. *Update default values for currencyFileUpdateDuration & foreignExchangeUpdateDuration. *Allow Role to be marshalled for file type. *Refactor RunUpdater to verify and check config values and set default running foreign exchange provider. * currency: cleanup * currency: change match -> equal for comparison which is more of a standard and little easier to find * currency: address nits * currency: fix whoops * currency: Add some more pairs methods * currency: linter issues * currency: RM unused field * currency: rm verbose * currency: fix word * currency: gocritic * currency: fix another whoopsie * example_config: default to show log system name * Currency: Force all support packages to use Equal method for comparison as there is a small comparison bug when checking upper and lower casing, this has a more of a pronounced impact between exchanges and client instances of currency generation * currency: fix log name * ordermanager: fix potential panic * currency: small optim. * engine: display correct bool and force shutdown * currency: add function and fix regression * Change ConvertCurrency -> ConvertFiat to be more precise * ADD GetForeignExchangeRate to get specific exchange rate for fiat pair * Fix currency display and formatting regression and tied in with config.Currency fields * engine: fix tests * currency: return the amount when no conversion needs to take place * currency: reduce method name * currency: Address nits glorious nits * currency: fix linter * currency: addr nits * currency: check underlying role in test * gct: change to EMPTYCODE and EMPTYPAIR across codebase * currency: fix nits * currency: this fixes test race but this issue has not been resolved. Please see: https://trello.com/c/54eizOIo/143-currency-package-upgrades * currency: Add temp dir for testing * Update engine/engine.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * documentation: update and regen * currency: Address niterinos * currency: Add test case for config upgrade when falling over to exchange rate host as default from exchangeRates provider * currency: addr nits * currency: fix whoops Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io> Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
This commit is contained in:
@@ -230,7 +230,7 @@ func TestUGetMarkPrice(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = b.UGetMarkPrice(context.Background(), currency.Pair{})
|
||||
_, err = b.UGetMarkPrice(context.Background(), currency.EMPTYPAIR)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -254,7 +254,7 @@ func TestU24HTickerPriceChangeStats(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = b.U24HTickerPriceChangeStats(context.Background(), currency.Pair{})
|
||||
_, err = b.U24HTickerPriceChangeStats(context.Background(), currency.EMPTYPAIR)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -266,7 +266,7 @@ func TestUSymbolPriceTicker(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = b.USymbolPriceTicker(context.Background(), currency.Pair{})
|
||||
_, err = b.USymbolPriceTicker(context.Background(), currency.EMPTYPAIR)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -278,7 +278,7 @@ func TestUSymbolOrderbookTicker(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = b.USymbolOrderbookTicker(context.Background(), currency.Pair{})
|
||||
_, err = b.USymbolOrderbookTicker(context.Background(), currency.EMPTYPAIR)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -370,7 +370,7 @@ func TestUCompositeIndexInfo(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = b.UCompositeIndexInfo(context.Background(), currency.Pair{})
|
||||
_, err = b.UCompositeIndexInfo(context.Background(), currency.EMPTYPAIR)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -489,7 +489,7 @@ func TestUAllAccountOrders(t *testing.T) {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip("skipping test: api keys not set")
|
||||
}
|
||||
_, err := b.UAllAccountOrders(context.Background(), currency.Pair{}, 0, 0, time.Time{}, time.Time{})
|
||||
_, err := b.UAllAccountOrders(context.Background(), currency.EMPTYPAIR, 0, 0, time.Time{}, time.Time{})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -592,7 +592,7 @@ func TestUAccountIncomeHistory(t *testing.T) {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip("skipping test: api keys not set")
|
||||
}
|
||||
_, err := b.UAccountIncomeHistory(context.Background(), currency.Pair{}, "", 5, time.Now().Add(-time.Hour*48), time.Now())
|
||||
_, err := b.UAccountIncomeHistory(context.Background(), currency.EMPTYPAIR, "", 5, time.Now().Add(-time.Hour*48), time.Now())
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -764,7 +764,7 @@ func TestGetFuturesSwapTickerChangeStats(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = b.GetFuturesSwapTickerChangeStats(context.Background(), currency.Pair{}, "")
|
||||
_, err = b.GetFuturesSwapTickerChangeStats(context.Background(), currency.EMPTYPAIR, "")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -810,7 +810,7 @@ func TestGetFuturesSymbolPriceTicker(t *testing.T) {
|
||||
|
||||
func TestGetFuturesOrderbookTicker(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetFuturesOrderbookTicker(context.Background(), currency.Pair{}, "")
|
||||
_, err := b.GetFuturesOrderbookTicker(context.Background(), currency.EMPTYPAIR, "")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -822,7 +822,7 @@ func TestGetFuturesOrderbookTicker(t *testing.T) {
|
||||
|
||||
func TestGetFuturesLiquidationOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetFuturesLiquidationOrders(context.Background(), currency.Pair{}, "", 0, time.Time{}, time.Time{})
|
||||
_, err := b.GetFuturesLiquidationOrders(context.Background(), currency.EMPTYPAIR, "", 0, time.Time{}, time.Time{})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -1124,7 +1124,7 @@ func TestFuturesIncomeHistory(t *testing.T) {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip("skipping test: api keys not set")
|
||||
}
|
||||
_, err := b.FuturesIncomeHistory(context.Background(), currency.Pair{}, "TRANSFER", time.Time{}, time.Time{}, 5)
|
||||
_, err := b.FuturesIncomeHistory(context.Background(), currency.EMPTYPAIR, "TRANSFER", time.Time{}, time.Time{}, 5)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -1135,7 +1135,7 @@ func TestFuturesForceOrders(t *testing.T) {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip("skipping test: api keys not set")
|
||||
}
|
||||
_, err := b.FuturesForceOrders(context.Background(), currency.Pair{}, "ADL", time.Time{}, time.Time{})
|
||||
_, err := b.FuturesForceOrders(context.Background(), currency.EMPTYPAIR, "ADL", time.Time{}, time.Time{})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -1161,7 +1161,7 @@ func TestFuturesPositionsADLEstimate(t *testing.T) {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip("skipping test: api keys not set")
|
||||
}
|
||||
_, err := b.FuturesPositionsADLEstimate(context.Background(), currency.Pair{})
|
||||
_, err := b.FuturesPositionsADLEstimate(context.Background(), currency.EMPTYPAIR)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -1341,7 +1341,7 @@ func TestOpenOrders(t *testing.T) {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip()
|
||||
}
|
||||
_, err := b.OpenOrders(context.Background(), currency.Pair{})
|
||||
_, err := b.OpenOrders(context.Background(), currency.EMPTYPAIR)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -489,7 +489,7 @@ func (b *Binance) UpdateTickers(ctx context.Context, a asset.Item) error {
|
||||
}
|
||||
}
|
||||
case asset.USDTMarginedFutures:
|
||||
tick, err := b.U24HTickerPriceChangeStats(ctx, currency.Pair{})
|
||||
tick, err := b.U24HTickerPriceChangeStats(ctx, currency.EMPTYPAIR)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -516,7 +516,7 @@ func (b *Binance) UpdateTickers(ctx context.Context, a asset.Item) error {
|
||||
}
|
||||
}
|
||||
case asset.CoinMarginedFutures:
|
||||
tick, err := b.GetFuturesSwapTickerChangeStats(ctx, currency.Pair{}, "")
|
||||
tick, err := b.GetFuturesSwapTickerChangeStats(ctx, currency.EMPTYPAIR, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1323,7 +1323,7 @@ func (b *Binance) GetActiveOrders(ctx context.Context, req *order.GetOrdersReque
|
||||
}
|
||||
if len(req.Pairs) == 0 || len(req.Pairs) >= 40 {
|
||||
// sending an empty currency pair retrieves data for all currencies
|
||||
req.Pairs = append(req.Pairs, currency.Pair{})
|
||||
req.Pairs = append(req.Pairs, currency.EMPTYPAIR)
|
||||
}
|
||||
var orders []order.Detail
|
||||
for i := range req.Pairs {
|
||||
@@ -1832,7 +1832,7 @@ func (b *Binance) GetAvailableTransferChains(ctx context.Context, cryptocurrency
|
||||
func (b *Binance) FormatExchangeCurrency(p currency.Pair, a asset.Item) (currency.Pair, error) {
|
||||
pairFmt, err := b.GetPairFormat(a, true)
|
||||
if err != nil {
|
||||
return currency.Pair{}, err
|
||||
return currency.EMPTYPAIR, err
|
||||
}
|
||||
if a == asset.USDTMarginedFutures {
|
||||
return b.formatUSDTMarginedFuturesPair(p, pairFmt), nil
|
||||
|
||||
@@ -1148,7 +1148,8 @@ func TestUpdateTicker(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateTickers(t *testing.T) {
|
||||
err := b.UpdateTickers(context.Background(), asset.Spot)
|
||||
t.Parallel()
|
||||
err := b.UpdateTickers(context.Background(), asset.PerpetualContract)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -43,12 +43,12 @@ func TestGetSnapshot(t *testing.T) {
|
||||
|
||||
func TestCanTradePair(t *testing.T) {
|
||||
t.Parallel()
|
||||
err := (*States)(nil).CanTradePair(currency.Pair{}, "")
|
||||
err := (*States)(nil).CanTradePair(currency.EMPTYPAIR, "")
|
||||
if !errors.Is(err, errNilStates) {
|
||||
t.Fatalf("received: %v, but expected: %v", err, errNilStates)
|
||||
}
|
||||
|
||||
err = (&States{}).CanTradePair(currency.Pair{}, "")
|
||||
err = (&States{}).CanTradePair(currency.EMPTYPAIR, "")
|
||||
if !errors.Is(err, errEmptyCurrency) {
|
||||
t.Fatalf("received: %v, but expected: %v", err, errEmptyCurrency)
|
||||
}
|
||||
@@ -115,11 +115,11 @@ func TestCanTradePair(t *testing.T) {
|
||||
|
||||
func TestStatesCanTrade(t *testing.T) {
|
||||
t.Parallel()
|
||||
err := (*States)(nil).CanTrade(currency.Code{}, "")
|
||||
err := (*States)(nil).CanTrade(currency.EMPTYCODE, "")
|
||||
if !errors.Is(err, errNilStates) {
|
||||
t.Fatalf("received: %v, but expected: %v", err, errNilStates)
|
||||
}
|
||||
err = (&States{}).CanTrade(currency.Code{}, "")
|
||||
err = (&States{}).CanTrade(currency.EMPTYCODE, "")
|
||||
if !errors.Is(err, errEmptyCurrency) {
|
||||
t.Fatalf("received: %v, but expected: %v", err, errEmptyCurrency)
|
||||
}
|
||||
@@ -127,11 +127,11 @@ func TestStatesCanTrade(t *testing.T) {
|
||||
|
||||
func TestStatesCanWithdraw(t *testing.T) {
|
||||
t.Parallel()
|
||||
err := (*States)(nil).CanWithdraw(currency.Code{}, "")
|
||||
err := (*States)(nil).CanWithdraw(currency.EMPTYCODE, "")
|
||||
if !errors.Is(err, errNilStates) {
|
||||
t.Fatalf("received: %v, but expected: %v", err, errNilStates)
|
||||
}
|
||||
err = (&States{}).CanWithdraw(currency.Code{}, "")
|
||||
err = (&States{}).CanWithdraw(currency.EMPTYCODE, "")
|
||||
if !errors.Is(err, errEmptyCurrency) {
|
||||
t.Fatalf("received: %v, but expected: %v", err, errEmptyCurrency)
|
||||
}
|
||||
@@ -161,11 +161,11 @@ func TestStatesCanWithdraw(t *testing.T) {
|
||||
|
||||
func TestStatesCanDeposit(t *testing.T) {
|
||||
t.Parallel()
|
||||
err := (*States)(nil).CanDeposit(currency.Code{}, "")
|
||||
err := (*States)(nil).CanDeposit(currency.EMPTYCODE, "")
|
||||
if !errors.Is(err, errNilStates) {
|
||||
t.Fatalf("received: %v, but expected: %v", err, errNilStates)
|
||||
}
|
||||
err = (&States{}).CanDeposit(currency.Code{}, "")
|
||||
err = (&States{}).CanDeposit(currency.EMPTYCODE, "")
|
||||
if !errors.Is(err, errEmptyCurrency) {
|
||||
t.Fatalf("received: %v, but expected: %v", err, errEmptyCurrency)
|
||||
}
|
||||
@@ -246,12 +246,12 @@ func TestStatesUpdateAll(t *testing.T) {
|
||||
|
||||
func TestStatesUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
err := (*States)(nil).Update(currency.Code{}, "", Options{})
|
||||
err := (*States)(nil).Update(currency.EMPTYCODE, "", Options{})
|
||||
if !errors.Is(err, errNilStates) {
|
||||
t.Fatalf("received: %v, but expected: %v", err, errNilStates)
|
||||
}
|
||||
|
||||
err = (&States{}).Update(currency.Code{}, "", Options{})
|
||||
err = (&States{}).Update(currency.EMPTYCODE, "", Options{})
|
||||
if !errors.Is(err, errEmptyCurrency) {
|
||||
t.Fatalf("received: %v, but expected: %v", err, errEmptyCurrency)
|
||||
}
|
||||
@@ -273,12 +273,12 @@ func TestStatesUpdate(t *testing.T) {
|
||||
|
||||
func TestStatesGet(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := (*States)(nil).Get(currency.Code{}, "")
|
||||
_, err := (*States)(nil).Get(currency.EMPTYCODE, "")
|
||||
if !errors.Is(err, errNilStates) {
|
||||
t.Fatalf("received: %v, but expected: %v", err, errNilStates)
|
||||
}
|
||||
|
||||
_, err = (&States{}).Get(currency.Code{}, "")
|
||||
_, err = (&States{}).Get(currency.EMPTYCODE, "")
|
||||
if !errors.Is(err, errEmptyCurrency) {
|
||||
t.Fatalf("received: %v, but expected: %v", err, errEmptyCurrency)
|
||||
}
|
||||
|
||||
@@ -535,7 +535,7 @@ func (b *Base) FormatExchangeCurrencies(pairs []currency.Pair, assetType asset.I
|
||||
func (b *Base) FormatExchangeCurrency(p currency.Pair, assetType asset.Item) (currency.Pair, error) {
|
||||
pairFmt, err := b.GetPairFormat(assetType, true)
|
||||
if err != nil {
|
||||
return currency.Pair{}, err
|
||||
return currency.EMPTYPAIR, err
|
||||
}
|
||||
return p.Format(pairFmt.Delimiter, pairFmt.Uppercase), nil
|
||||
}
|
||||
|
||||
@@ -694,7 +694,7 @@ func TestLoadConfigPairs(t *testing.T) {
|
||||
}
|
||||
p = pairs[2].Format(pFmt.Delimiter, pFmt.Uppercase).String()
|
||||
if p != "xrp/usd" {
|
||||
t.Error("incorrect value, expected xrp/usd")
|
||||
t.Error("incorrect value, expected xrp/usd", p)
|
||||
}
|
||||
|
||||
avail, err = b.GetAvailablePairs(asset.Spot)
|
||||
@@ -708,7 +708,7 @@ func TestLoadConfigPairs(t *testing.T) {
|
||||
}
|
||||
p = format.String()
|
||||
if p != "xrp~usd" {
|
||||
t.Error("incorrect value, expected xrp~usd")
|
||||
t.Error("incorrect value, expected xrp~usd", p)
|
||||
}
|
||||
ps, err := b.Config.CurrencyPairs.Get(asset.Spot)
|
||||
if err != nil {
|
||||
@@ -1609,7 +1609,7 @@ func TestUpdatePairs(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pairs := currency.Pairs{
|
||||
currency.Pair{},
|
||||
currency.EMPTYPAIR,
|
||||
p,
|
||||
}
|
||||
err = UAC.UpdatePairs(pairs, asset.Spot, true, true)
|
||||
|
||||
@@ -506,7 +506,7 @@ func TestGetOrderInfo(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err := g.GetOrderInfo(context.Background(),
|
||||
"917591554", currency.Pair{}, asset.Spot)
|
||||
"917591554", currency.EMPTYPAIR, asset.Spot)
|
||||
if err != nil {
|
||||
if err.Error() != "no order found with id 917591554" && err.Error() != "failed to get open orders" {
|
||||
t.Fatalf("GetOrderInfo() returned an error skipping test: %v", err)
|
||||
|
||||
@@ -101,7 +101,7 @@ func TestStart(t *testing.T) {
|
||||
|
||||
func TestGetCurrenciesIncludingChains(t *testing.T) {
|
||||
t.Parallel()
|
||||
r, err := h.GetCurrenciesIncludingChains(context.Background(), currency.Code{})
|
||||
r, err := h.GetCurrenciesIncludingChains(context.Background(), currency.EMPTYCODE)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -119,7 +119,7 @@ func TestGetCurrenciesIncludingChains(t *testing.T) {
|
||||
|
||||
func TestFGetContractInfo(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := h.FGetContractInfo(context.Background(), "", "", currency.Pair{})
|
||||
_, err := h.FGetContractInfo(context.Background(), "", "", currency.EMPTYPAIR)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -136,7 +136,7 @@ func TestFIndexPriceInfo(t *testing.T) {
|
||||
func TestFContractPriceLimitations(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := h.FContractPriceLimitations(context.Background(),
|
||||
"BTC", "next_quarter", currency.Pair{})
|
||||
"BTC", "next_quarter", currency.EMPTYPAIR)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -145,7 +145,7 @@ func TestFContractPriceLimitations(t *testing.T) {
|
||||
func TestFContractOpenInterest(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := h.FContractOpenInterest(context.Background(),
|
||||
"BTC", "next_quarter", currency.Pair{})
|
||||
"BTC", "next_quarter", currency.EMPTYPAIR)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -289,7 +289,7 @@ func TestFGetAccountInfo(t *testing.T) {
|
||||
t.Skip("skipping test: api keys not set")
|
||||
}
|
||||
t.Parallel()
|
||||
_, err := h.FGetAccountInfo(context.Background(), currency.Code{})
|
||||
_, err := h.FGetAccountInfo(context.Background(), currency.EMPTYCODE)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -300,7 +300,7 @@ func TestFGetPositionsInfo(t *testing.T) {
|
||||
t.Skip("skipping test: api keys not set")
|
||||
}
|
||||
t.Parallel()
|
||||
_, err := h.FGetPositionsInfo(context.Background(), currency.Code{})
|
||||
_, err := h.FGetPositionsInfo(context.Background(), currency.EMPTYCODE)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -311,7 +311,7 @@ func TestFGetAllSubAccountAssets(t *testing.T) {
|
||||
t.Skip("skipping test: api keys not set")
|
||||
}
|
||||
t.Parallel()
|
||||
_, err := h.FGetAllSubAccountAssets(context.Background(), currency.Code{})
|
||||
_, err := h.FGetAllSubAccountAssets(context.Background(), currency.EMPTYCODE)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -368,7 +368,7 @@ func TestFContractTradingFee(t *testing.T) {
|
||||
t.Skip("skipping test: api keys not set")
|
||||
}
|
||||
t.Parallel()
|
||||
_, err := h.FContractTradingFee(context.Background(), currency.Code{})
|
||||
_, err := h.FContractTradingFee(context.Background(), currency.EMPTYCODE)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -379,7 +379,7 @@ func TestFGetTransferLimits(t *testing.T) {
|
||||
t.Skip("skipping test: api keys not set")
|
||||
}
|
||||
t.Parallel()
|
||||
_, err := h.FGetTransferLimits(context.Background(), currency.Code{})
|
||||
_, err := h.FGetTransferLimits(context.Background(), currency.EMPTYCODE)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -390,7 +390,7 @@ func TestFGetPositionLimits(t *testing.T) {
|
||||
t.Skip("skipping test: api keys not set")
|
||||
}
|
||||
t.Parallel()
|
||||
_, err := h.FGetPositionLimits(context.Background(), currency.Code{})
|
||||
_, err := h.FGetPositionLimits(context.Background(), currency.EMPTYCODE)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -460,7 +460,7 @@ func TestFOrder(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = h.FOrder(context.Background(),
|
||||
currency.Pair{}, cp.Base.Upper().String(),
|
||||
currency.EMPTYPAIR, cp.Base.Upper().String(),
|
||||
"quarter", "123", "BUY", "open", "limit", 1, 1, 1)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
@@ -542,7 +542,7 @@ func TestFFlashCloseOrder(t *testing.T) {
|
||||
}
|
||||
t.Parallel()
|
||||
_, err := h.FFlashCloseOrder(context.Background(),
|
||||
currency.Pair{}, "BTC", "quarter", "BUY", "lightning", "", 1)
|
||||
currency.EMPTYPAIR, "BTC", "quarter", "BUY", "lightning", "", 1)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -600,7 +600,7 @@ func TestFGetOrderHistory(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = h.FGetOrderHistory(context.Background(),
|
||||
currency.Pair{}, cp.Base.Upper().String(),
|
||||
currency.EMPTYPAIR, cp.Base.Upper().String(),
|
||||
"all", "all", "limit",
|
||||
[]order.Status{},
|
||||
5, 0, 0)
|
||||
@@ -615,7 +615,7 @@ func TestFTradeHistory(t *testing.T) {
|
||||
}
|
||||
t.Parallel()
|
||||
_, err := h.FTradeHistory(context.Background(),
|
||||
currency.Pair{}, "BTC", "all", 10, 0, 0)
|
||||
currency.EMPTYPAIR, "BTC", "all", 10, 0, 0)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -627,7 +627,7 @@ func TestFPlaceTriggerOrder(t *testing.T) {
|
||||
}
|
||||
t.Parallel()
|
||||
_, err := h.FPlaceTriggerOrder(context.Background(),
|
||||
currency.Pair{}, "EOS", "quarter", "greaterOrEqual",
|
||||
currency.EMPTYPAIR, "EOS", "quarter", "greaterOrEqual",
|
||||
"limit", "buy", "close", 1.1, 1.05, 5, 2)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
@@ -651,7 +651,7 @@ func TestFCancelAllTriggerOrders(t *testing.T) {
|
||||
}
|
||||
t.Parallel()
|
||||
_, err := h.FCancelAllTriggerOrders(context.Background(),
|
||||
currency.Pair{}, "BTC", "this_week")
|
||||
currency.EMPTYPAIR, "BTC", "this_week")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -663,7 +663,7 @@ func TestFQueryTriggerOpenOrders(t *testing.T) {
|
||||
}
|
||||
t.Parallel()
|
||||
_, err := h.FQueryTriggerOpenOrders(context.Background(),
|
||||
currency.Pair{}, "BTC", 0, 0)
|
||||
currency.EMPTYPAIR, "BTC", 0, 0)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -675,7 +675,7 @@ func TestFQueryTriggerOrderHistory(t *testing.T) {
|
||||
}
|
||||
t.Parallel()
|
||||
_, err := h.FQueryTriggerOrderHistory(context.Background(),
|
||||
currency.Pair{}, "EOS", "all", "all", 10, 0, 0)
|
||||
currency.EMPTYPAIR, "EOS", "all", "all", 10, 0, 0)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -1571,7 +1571,7 @@ func TestGetSwapTriggerOrderHistory(t *testing.T) {
|
||||
|
||||
func TestGetSwapMarkets(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := h.GetSwapMarkets(context.Background(), currency.Pair{})
|
||||
_, err := h.GetSwapMarkets(context.Background(), currency.EMPTYPAIR)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -360,7 +360,7 @@ func (h *HUOBI) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string,
|
||||
}
|
||||
|
||||
case asset.CoinMarginedFutures:
|
||||
symbols, err := h.GetSwapMarkets(ctx, currency.Pair{})
|
||||
symbols, err := h.GetSwapMarkets(ctx, currency.EMPTYPAIR)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -375,7 +375,7 @@ func (h *HUOBI) FetchTradablePairs(ctx context.Context, a asset.Item) ([]string,
|
||||
}
|
||||
}
|
||||
case asset.Futures:
|
||||
symbols, err := h.FGetContractInfo(ctx, "", "", currency.Pair{})
|
||||
symbols, err := h.FGetContractInfo(ctx, "", "", currency.EMPTYPAIR)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -707,7 +707,7 @@ func (h *HUOBI) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (ac
|
||||
|
||||
case asset.CoinMarginedFutures:
|
||||
// fetch swap account info
|
||||
acctInfo, err := h.GetSwapAccountInfo(ctx, currency.Pair{})
|
||||
acctInfo, err := h.GetSwapAccountInfo(ctx, currency.EMPTYPAIR)
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
@@ -727,14 +727,14 @@ func (h *HUOBI) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (ac
|
||||
})
|
||||
|
||||
// fetch subaccounts data
|
||||
subAccsData, err := h.GetSwapAllSubAccAssets(ctx, currency.Pair{})
|
||||
subAccsData, err := h.GetSwapAllSubAccAssets(ctx, currency.EMPTYPAIR)
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
var currencyDetails []account.Balance
|
||||
for x := range subAccsData.Data {
|
||||
a, err := h.SwapSingleSubAccAssets(ctx,
|
||||
currency.Pair{},
|
||||
currency.EMPTYPAIR,
|
||||
subAccsData.Data[x].SubUID)
|
||||
if err != nil {
|
||||
return info, err
|
||||
@@ -750,7 +750,7 @@ func (h *HUOBI) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (ac
|
||||
acc.Currencies = currencyDetails
|
||||
case asset.Futures:
|
||||
// fetch main account data
|
||||
mainAcctData, err := h.FGetAccountInfo(ctx, currency.Code{})
|
||||
mainAcctData, err := h.FGetAccountInfo(ctx, currency.EMPTYCODE)
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
@@ -770,7 +770,7 @@ func (h *HUOBI) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (ac
|
||||
})
|
||||
|
||||
// fetch subaccounts data
|
||||
subAccsData, err := h.FGetAllSubAccountAssets(ctx, currency.Code{})
|
||||
subAccsData, err := h.FGetAllSubAccountAssets(ctx, currency.EMPTYCODE)
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ func TestWrapperGetOrderInfo(t *testing.T) {
|
||||
t.Skip("skipping test: api keys not set")
|
||||
}
|
||||
_, err := k.GetOrderInfo(context.Background(),
|
||||
"123", currency.Pair{}, asset.Futures)
|
||||
"123", currency.EMPTYPAIR, asset.Futures)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -882,7 +882,7 @@ func TestGetOrderInfo(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err := k.GetOrderInfo(context.Background(),
|
||||
"OZPTPJ-HVYHF-EDIGXS", currency.Pair{}, asset.Spot)
|
||||
"OZPTPJ-HVYHF-EDIGXS", currency.EMPTYPAIR, asset.Spot)
|
||||
if !areTestAPIKeysSet() && err == nil {
|
||||
t.Error("Expecting error")
|
||||
}
|
||||
|
||||
@@ -381,7 +381,7 @@ func TestGetOrderInfo(t *testing.T) {
|
||||
t.Skip("API keys required but not set, skipping test")
|
||||
}
|
||||
_, err := l.GetOrderInfo(context.Background(),
|
||||
"9ead39f5-701a-400b-b635-d7349eb0f6b", currency.Pair{}, asset.Spot)
|
||||
"9ead39f5-701a-400b-b635-d7349eb0f6b", currency.EMPTYPAIR, asset.Spot)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -847,7 +847,7 @@ func (o *OKGroup) GenerateDefaultSubscriptions() ([]stream.ChannelSubscription,
|
||||
subscriptions = append(subscriptions,
|
||||
stream.ChannelSubscription{
|
||||
Channel: channels[y],
|
||||
Currency: currency.NewPair(newP.Base, currency.Code{}),
|
||||
Currency: currency.NewPair(newP.Base, currency.EMPTYCODE),
|
||||
Asset: asset.Futures,
|
||||
})
|
||||
futuresAccountCodes = append(futuresAccountCodes, newP.Base)
|
||||
|
||||
@@ -374,7 +374,7 @@ func TestFilterOrdersByCurrencies(t *testing.T) {
|
||||
if len(orders) != 1 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 1, len(orders))
|
||||
}
|
||||
currencies = append(currencies, currency.Pair{})
|
||||
currencies = append(currencies, currency.EMPTYPAIR)
|
||||
FilterOrdersByCurrencies(&orders, currencies)
|
||||
if len(orders) != 1 {
|
||||
t.Errorf("Orders failed to be filtered. Expected %v, received %v", 1, len(orders))
|
||||
@@ -718,7 +718,7 @@ func TestUpdateOrderFromModify(t *testing.T) {
|
||||
AssetType: "",
|
||||
Date: time.Time{},
|
||||
LastUpdated: time.Time{},
|
||||
Pair: currency.Pair{},
|
||||
Pair: currency.EMPTYPAIR,
|
||||
Trades: nil,
|
||||
}
|
||||
updated := time.Now()
|
||||
@@ -910,7 +910,7 @@ func TestUpdateOrderFromDetail(t *testing.T) {
|
||||
AssetType: "",
|
||||
Date: time.Time{},
|
||||
LastUpdated: time.Time{},
|
||||
Pair: currency.Pair{},
|
||||
Pair: currency.EMPTYPAIR,
|
||||
Trades: nil,
|
||||
}
|
||||
updated := time.Now()
|
||||
|
||||
@@ -112,7 +112,9 @@ func (d *Detail) UpdateOrderFromDetail(m *Detail) {
|
||||
d.PostOnly = m.PostOnly
|
||||
updated = true
|
||||
}
|
||||
if !m.Pair.IsEmpty() && m.Pair != d.Pair {
|
||||
if !m.Pair.IsEmpty() && !m.Pair.Equal(d.Pair) {
|
||||
// TODO: Add a check to see if the original pair is empty as well, but
|
||||
// error if it is changing from BTC-USD -> LTC-USD.
|
||||
d.Pair = m.Pair
|
||||
updated = true
|
||||
}
|
||||
@@ -274,7 +276,9 @@ func (d *Detail) UpdateOrderFromModify(m *Modify) {
|
||||
d.PostOnly = m.PostOnly
|
||||
updated = true
|
||||
}
|
||||
if !m.Pair.IsEmpty() && m.Pair != d.Pair {
|
||||
if !m.Pair.IsEmpty() && !m.Pair.Equal(d.Pair) {
|
||||
// TODO: Add a check to see if the original pair is empty as well, but
|
||||
// error if it is changing from BTC-USD -> LTC-USD.
|
||||
d.Pair = m.Pair
|
||||
updated = true
|
||||
}
|
||||
|
||||
@@ -303,7 +303,7 @@ func TestDeployDepth(t *testing.T) {
|
||||
if !errors.Is(err, errExchangeNameUnset) {
|
||||
t.Fatalf("expecting %s error but received %v", errExchangeNameUnset, err)
|
||||
}
|
||||
_, err = DeployDepth("test", currency.Pair{}, asset.Spot)
|
||||
_, err = DeployDepth("test", currency.EMPTYPAIR, asset.Spot)
|
||||
if !errors.Is(err, errPairNotSet) {
|
||||
t.Fatalf("expecting %s error but received %v", errPairNotSet, err)
|
||||
}
|
||||
@@ -370,7 +370,7 @@ func TestProcessOrderbook(t *testing.T) {
|
||||
}
|
||||
|
||||
// test for empty pair
|
||||
base.Pair = currency.Pair{}
|
||||
base.Pair = currency.EMPTYPAIR
|
||||
err = base.Process()
|
||||
if err == nil {
|
||||
t.Error("empty pair should throw an err")
|
||||
|
||||
@@ -101,7 +101,7 @@ func (w *CurrencyDetails) GetPair(id float64) (currency.Pair, error) {
|
||||
w.m.RLock()
|
||||
defer w.m.RUnlock()
|
||||
if w.pairs == nil {
|
||||
return currency.Pair{}, errPairMapIsNil
|
||||
return currency.EMPTYPAIR, errPairMapIsNil
|
||||
}
|
||||
|
||||
p, ok := w.pairs[id]
|
||||
@@ -124,13 +124,13 @@ func (w *CurrencyDetails) GetCode(id float64) (currency.Code, error) {
|
||||
w.m.RLock()
|
||||
defer w.m.RUnlock()
|
||||
if w.codes == nil {
|
||||
return currency.Code{}, errCodeMapIsNil
|
||||
return currency.EMPTYCODE, errCodeMapIsNil
|
||||
}
|
||||
c, ok := w.codes[id]
|
||||
if ok {
|
||||
return c.Currency, nil
|
||||
}
|
||||
return currency.Code{}, errIDNotFoundInCodeMap
|
||||
return currency.EMPTYCODE, errIDNotFoundInCodeMap
|
||||
}
|
||||
|
||||
// GetWithdrawalTXFee returns withdrawal transaction fee for the currency
|
||||
|
||||
@@ -35,32 +35,32 @@ func TestWsCurrencyMap(t *testing.T) {
|
||||
t.Fatalf("expected: %v but received: %v", errCodeMapIsNil, err)
|
||||
}
|
||||
|
||||
_, err = m.GetWithdrawalTXFee(currency.Code{})
|
||||
_, err = m.GetWithdrawalTXFee(currency.EMPTYCODE)
|
||||
if !errors.Is(err, errCodeMapIsNil) {
|
||||
t.Fatalf("expected: %v but received: %v", errCodeMapIsNil, err)
|
||||
}
|
||||
|
||||
_, err = m.GetDepositAddress(currency.Code{})
|
||||
_, err = m.GetDepositAddress(currency.EMPTYCODE)
|
||||
if !errors.Is(err, errCodeMapIsNil) {
|
||||
t.Fatalf("expected: %v but received: %v", errCodeMapIsNil, err)
|
||||
}
|
||||
|
||||
_, err = m.IsWithdrawAndDepositsEnabled(currency.Code{})
|
||||
_, err = m.IsWithdrawAndDepositsEnabled(currency.EMPTYCODE)
|
||||
if !errors.Is(err, errCodeMapIsNil) {
|
||||
t.Fatalf("expected: %v but received: %v", errCodeMapIsNil, err)
|
||||
}
|
||||
|
||||
_, err = m.IsTradingEnabledForCurrency(currency.Code{})
|
||||
_, err = m.IsTradingEnabledForCurrency(currency.EMPTYCODE)
|
||||
if !errors.Is(err, errCodeMapIsNil) {
|
||||
t.Fatalf("expected: %v but received: %v", errCodeMapIsNil, err)
|
||||
}
|
||||
|
||||
_, err = m.IsTradingEnabledForPair(currency.Pair{})
|
||||
_, err = m.IsTradingEnabledForPair(currency.EMPTYPAIR)
|
||||
if !errors.Is(err, errCodeMapIsNil) {
|
||||
t.Fatalf("expected: %v but received: %v", errCodeMapIsNil, err)
|
||||
}
|
||||
|
||||
_, err = m.IsPostOnlyForPair(currency.Pair{})
|
||||
_, err = m.IsPostOnlyForPair(currency.EMPTYPAIR)
|
||||
if !errors.Is(err, errCodeMapIsNil) {
|
||||
t.Fatalf("expected: %v but received: %v", errCodeMapIsNil, err)
|
||||
}
|
||||
@@ -178,32 +178,32 @@ func TestWsCurrencyMap(t *testing.T) {
|
||||
t.Fatal("unexpected results")
|
||||
}
|
||||
|
||||
_, err = m.GetWithdrawalTXFee(currency.Code{})
|
||||
_, err = m.GetWithdrawalTXFee(currency.EMPTYCODE)
|
||||
if !errors.Is(err, errCurrencyNotFoundInMap) {
|
||||
t.Fatalf("expected: %v but received: %v", errCurrencyNotFoundInMap, err)
|
||||
}
|
||||
|
||||
_, err = m.GetDepositAddress(currency.Code{})
|
||||
_, err = m.GetDepositAddress(currency.EMPTYCODE)
|
||||
if !errors.Is(err, errCurrencyNotFoundInMap) {
|
||||
t.Fatalf("expected: %v but received: %v", errCurrencyNotFoundInMap, err)
|
||||
}
|
||||
|
||||
_, err = m.IsWithdrawAndDepositsEnabled(currency.Code{})
|
||||
_, err = m.IsWithdrawAndDepositsEnabled(currency.EMPTYCODE)
|
||||
if !errors.Is(err, errCurrencyNotFoundInMap) {
|
||||
t.Fatalf("expected: %v but received: %v", errCurrencyNotFoundInMap, err)
|
||||
}
|
||||
|
||||
_, err = m.IsTradingEnabledForCurrency(currency.Code{})
|
||||
_, err = m.IsTradingEnabledForCurrency(currency.EMPTYCODE)
|
||||
if !errors.Is(err, errCurrencyNotFoundInMap) {
|
||||
t.Fatalf("expected: %v but received: %v", errCurrencyNotFoundInMap, err)
|
||||
}
|
||||
|
||||
_, err = m.IsTradingEnabledForPair(currency.Pair{})
|
||||
_, err = m.IsTradingEnabledForPair(currency.EMPTYPAIR)
|
||||
if !errors.Is(err, errCurrencyNotFoundInMap) {
|
||||
t.Fatalf("expected: %v but received: %v", errCurrencyNotFoundInMap, err)
|
||||
}
|
||||
|
||||
_, err = m.IsPostOnlyForPair(currency.Pair{})
|
||||
_, err = m.IsPostOnlyForPair(currency.EMPTYPAIR)
|
||||
if !errors.Is(err, errCurrencyNotFoundInMap) {
|
||||
t.Fatalf("expected: %v but received: %v", errCurrencyNotFoundInMap, err)
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ func Add(exchange string, p currency.Pair, a asset.Item, price, volume float64)
|
||||
return errors.New("cannot add or update, invalid params")
|
||||
}
|
||||
|
||||
if p.Base == currency.XBT {
|
||||
if p.Base.Equal(currency.XBT) {
|
||||
newPair, err := currency.NewPairFromStrings(currency.BTC.String(),
|
||||
p.Quote.String())
|
||||
if err != nil {
|
||||
@@ -70,7 +70,7 @@ func Add(exchange string, p currency.Pair, a asset.Item, price, volume float64)
|
||||
Append(exchange, newPair, a, price, volume)
|
||||
}
|
||||
|
||||
if p.Quote == currency.USDT {
|
||||
if p.Quote.Equal(currency.USDT) {
|
||||
newPair, err := currency.NewPairFromStrings(p.Base.String(), currency.USD.String())
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -29,7 +29,7 @@ func TestMain(m *testing.M) {
|
||||
var cpyMux *dispatch.Mux
|
||||
|
||||
func TestSubscribeTicker(t *testing.T) {
|
||||
_, err := SubscribeTicker("", currency.Pair{}, asset.Item(""))
|
||||
_, err := SubscribeTicker("", currency.EMPTYPAIR, asset.Item(""))
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ func TestGetOpenOrders(t *testing.T) {
|
||||
func TestGetOrderInfo(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := y.GetOrderInfo(context.Background(),
|
||||
"6196974", currency.Pair{}, asset.Spot)
|
||||
"6196974", currency.EMPTYPAIR, asset.Spot)
|
||||
if err == nil {
|
||||
t.Error("GetOrderInfo() Expected error")
|
||||
}
|
||||
|
||||
@@ -971,15 +971,15 @@ func Test_FormatExchangeKlineInterval(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateCandlesRequest(t *testing.T) {
|
||||
_, err := z.validateCandlesRequest(currency.Pair{}, "", time.Time{}, time.Time{}, kline.Interval(-1))
|
||||
_, err := z.validateCandlesRequest(currency.EMPTYPAIR, "", time.Time{}, time.Time{}, kline.Interval(-1))
|
||||
if !errors.Is(err, common.ErrDateUnset) {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = z.validateCandlesRequest(currency.Pair{}, "", time.Date(2020, 1, 1, 1, 1, 1, 1, time.UTC), time.Time{}, kline.Interval(-1))
|
||||
_, err = z.validateCandlesRequest(currency.EMPTYPAIR, "", time.Date(2020, 1, 1, 1, 1, 1, 1, time.UTC), time.Time{}, kline.Interval(-1))
|
||||
if !errors.Is(err, common.ErrDateUnset) {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = z.validateCandlesRequest(currency.Pair{}, asset.Spot, time.Date(2020, 1, 1, 1, 1, 1, 1, time.UTC), time.Date(2020, 1, 1, 1, 1, 1, 3, time.UTC), kline.OneHour)
|
||||
_, err = z.validateCandlesRequest(currency.EMPTYPAIR, asset.Spot, time.Date(2020, 1, 1, 1, 1, 1, 1, time.UTC), time.Date(2020, 1, 1, 1, 1, 1, 3, time.UTC), kline.OneHour)
|
||||
if err != nil && err.Error() != "pair not enabled" {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user