mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Expand RetrieveConfigCurrencyPairs to support different asset types
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/bitfinex"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio"
|
||||
)
|
||||
@@ -95,7 +96,7 @@ func main() {
|
||||
Subtotal float64
|
||||
}
|
||||
|
||||
cfg.RetrieveConfigCurrencyPairs(true)
|
||||
cfg.RetrieveConfigCurrencyPairs(true, asset.Spot)
|
||||
portfolioMap := make(map[currency.Code]PortfolioTemp)
|
||||
total := float64(0)
|
||||
|
||||
|
||||
@@ -1214,7 +1214,7 @@ func (c *Config) CheckCurrencyConfigValues() error {
|
||||
|
||||
// RetrieveConfigCurrencyPairs splits, assigns and verifies enabled currency
|
||||
// pairs either cryptoCurrencies or fiatCurrencies
|
||||
func (c *Config) RetrieveConfigCurrencyPairs(enabledOnly bool) error {
|
||||
func (c *Config) RetrieveConfigCurrencyPairs(enabledOnly bool, assetType asset.Item) error {
|
||||
cryptoCurrencies := c.Currency.Cryptocurrencies
|
||||
fiatCurrencies := currency.GetFiatCurrencies()
|
||||
|
||||
@@ -1223,6 +1223,11 @@ func (c *Config) RetrieveConfigCurrencyPairs(enabledOnly bool) error {
|
||||
continue
|
||||
}
|
||||
|
||||
supports, _ := c.SupportsExchangeAssetType(c.Exchanges[x].Name, assetType)
|
||||
if !supports {
|
||||
continue
|
||||
}
|
||||
|
||||
baseCurrencies := c.Exchanges[x].BaseCurrencies
|
||||
for y := range baseCurrencies {
|
||||
if !fiatCurrencies.Contains(baseCurrencies[y]) {
|
||||
@@ -1232,12 +1237,17 @@ func (c *Config) RetrieveConfigCurrencyPairs(enabledOnly bool) error {
|
||||
}
|
||||
|
||||
for x := range c.Exchanges {
|
||||
supports, _ := c.SupportsExchangeAssetType(c.Exchanges[x].Name, assetType)
|
||||
if !supports {
|
||||
continue
|
||||
}
|
||||
|
||||
var pairs []currency.Pair
|
||||
var err error
|
||||
if !c.Exchanges[x].Enabled && enabledOnly {
|
||||
pairs, err = c.GetEnabledPairs(c.Exchanges[x].Name, asset.Spot)
|
||||
pairs, err = c.GetEnabledPairs(c.Exchanges[x].Name, assetType)
|
||||
} else {
|
||||
pairs, err = c.GetAvailablePairs(c.Exchanges[x].Name, asset.Spot)
|
||||
pairs, err = c.GetAvailablePairs(c.Exchanges[x].Name, assetType)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -735,7 +735,7 @@ func TestRetrieveConfigCurrencyPairs(t *testing.T) {
|
||||
"Test failed. TestRetrieveConfigCurrencyPairs.LoadConfig: %s", err.Error(),
|
||||
)
|
||||
}
|
||||
err = cfg.RetrieveConfigCurrencyPairs(true)
|
||||
err = cfg.RetrieveConfigCurrencyPairs(true, asset.Spot)
|
||||
if err != nil {
|
||||
t.Errorf(
|
||||
"Test failed. TestRetrieveConfigCurrencyPairs.RetrieveConfigCurrencyPairs: %s",
|
||||
@@ -743,7 +743,7 @@ func TestRetrieveConfigCurrencyPairs(t *testing.T) {
|
||||
)
|
||||
}
|
||||
|
||||
err = cfg.RetrieveConfigCurrencyPairs(false)
|
||||
err = cfg.RetrieveConfigCurrencyPairs(false, asset.Spot)
|
||||
if err != nil {
|
||||
t.Errorf(
|
||||
"Test failed. TestRetrieveConfigCurrencyPairs.RetrieveConfigCurrencyPairs: %s",
|
||||
|
||||
@@ -35,7 +35,7 @@ func SetupTestHelpers(t *testing.T) {
|
||||
}
|
||||
testSetup = true
|
||||
}
|
||||
err := Bot.Config.RetrieveConfigCurrencyPairs(true)
|
||||
err := Bot.Config.RetrieveConfigCurrencyPairs(true, asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to retrieve config currency pairs. %s", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user