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