Skip to content

Commit

Permalink
Config: Move assetEnabled upgrade to Version management
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed Nov 22, 2024
1 parent fff95a1 commit b7fbff6
Show file tree
Hide file tree
Showing 26 changed files with 283 additions and 510 deletions.
5 changes: 2 additions & 3 deletions backtester/data/kline/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"time"

"github.com/thrasher-corp/gocryptotrader/backtester/common"
"github.com/thrasher-corp/gocryptotrader/common/convert"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/engine"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
Expand All @@ -30,7 +29,7 @@ func TestLoadCandles(t *testing.T) {
b.CurrencyPairs.Pairs[asset.Spot] = &currency.PairStore{
Available: currency.Pairs{cp},
Enabled: currency.Pairs{cp},
AssetEnabled: convert.BoolPtr(true),
AssetEnabled: true,
ConfigFormat: &currency.PairFormat{Uppercase: true},
RequestFormat: &currency.PairFormat{Uppercase: true}}
tt1 := time.Now().Add(-time.Minute).Round(gctkline.OneMin.Duration())
Expand Down Expand Up @@ -68,7 +67,7 @@ func TestLoadTrades(t *testing.T) {
b.CurrencyPairs.Pairs[asset.Spot] = &currency.PairStore{
Available: currency.Pairs{cp},
Enabled: currency.Pairs{cp},
AssetEnabled: convert.BoolPtr(true),
AssetEnabled: true,
ConfigFormat: &currency.PairFormat{Uppercase: true},
RequestFormat: &currency.PairFormat{Uppercase: true}}
interval := gctkline.OneMin
Expand Down
5 changes: 2 additions & 3 deletions backtester/data/kline/live/live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"time"

"github.com/thrasher-corp/gocryptotrader/backtester/common"
"github.com/thrasher-corp/gocryptotrader/common/convert"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/engine"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
Expand All @@ -33,7 +32,7 @@ func TestLoadCandles(t *testing.T) {
b.CurrencyPairs.Pairs[asset.Spot] = &currency.PairStore{
Available: currency.Pairs{cp},
Enabled: currency.Pairs{cp},
AssetEnabled: convert.BoolPtr(true),
AssetEnabled: true,
RequestFormat: pFormat,
ConfigFormat: pFormat,
}
Expand Down Expand Up @@ -68,7 +67,7 @@ func TestLoadTrades(t *testing.T) {
b.CurrencyPairs.Pairs[asset.Spot] = &currency.PairStore{
Available: currency.Pairs{cp},
Enabled: currency.Pairs{cp},
AssetEnabled: convert.BoolPtr(true),
AssetEnabled: true,
RequestFormat: pFormat,
ConfigFormat: pFormat,
}
Expand Down
9 changes: 4 additions & 5 deletions backtester/engine/backtest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/thrasher-corp/gocryptotrader/backtester/funding"
"github.com/thrasher-corp/gocryptotrader/backtester/report"
gctcommon "github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/convert"
"github.com/thrasher-corp/gocryptotrader/common/key"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/database"
Expand Down Expand Up @@ -182,7 +181,7 @@ func TestLoadDataAPI(t *testing.T) {
b.CurrencyPairs.Pairs[asset.Spot] = &currency.PairStore{
Available: currency.Pairs{cp},
Enabled: currency.Pairs{cp},
AssetEnabled: convert.BoolPtr(true),
AssetEnabled: true,
ConfigFormat: &currency.PairFormat{Uppercase: true},
RequestFormat: &currency.PairFormat{Uppercase: true}}

Expand Down Expand Up @@ -236,7 +235,7 @@ func TestLoadDataCSV(t *testing.T) {
b.CurrencyPairs.Pairs[asset.Spot] = &currency.PairStore{
Available: currency.Pairs{cp},
Enabled: currency.Pairs{cp},
AssetEnabled: convert.BoolPtr(true),
AssetEnabled: true,
ConfigFormat: &currency.PairFormat{Uppercase: true},
RequestFormat: &currency.PairFormat{Uppercase: true}}
_, err = bt.loadData(cfg, exch, cp, asset.Spot, false)
Expand Down Expand Up @@ -301,7 +300,7 @@ func TestLoadDataDatabase(t *testing.T) {
b.CurrencyPairs.Pairs[asset.Spot] = &currency.PairStore{
Available: currency.Pairs{cp},
Enabled: currency.Pairs{cp},
AssetEnabled: convert.BoolPtr(true),
AssetEnabled: true,
ConfigFormat: &currency.PairFormat{Uppercase: true},
RequestFormat: &currency.PairFormat{Uppercase: true}}
bt.databaseManager, err = engine.SetupDatabaseConnectionManager(&cfg.DataSettings.DatabaseData.Config)
Expand Down Expand Up @@ -384,7 +383,7 @@ func TestLoadDataLive(t *testing.T) {
b.CurrencyPairs.Pairs[asset.Spot] = &currency.PairStore{
Available: currency.Pairs{cp},
Enabled: currency.Pairs{cp},
AssetEnabled: convert.BoolPtr(true),
AssetEnabled: true,
ConfigFormat: &currency.PairFormat{Uppercase: true},
RequestFormat: &currency.PairFormat{Uppercase: true}}
_, err = bt.loadData(cfg, exch, cp, asset.Spot, false)
Expand Down
3 changes: 1 addition & 2 deletions backtester/engine/live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/thrasher-corp/gocryptotrader/backtester/funding"
"github.com/thrasher-corp/gocryptotrader/backtester/report"
gctcommon "github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/convert"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/engine"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
Expand Down Expand Up @@ -402,7 +401,7 @@ func TestLoadCandleData(t *testing.T) {
eba := exch.CurrencyPairs.Pairs[asset.Spot]
eba.Available = eba.Available.Add(cp)
eba.Enabled = eba.Enabled.Add(cp)
eba.AssetEnabled = convert.BoolPtr(true)
eba.AssetEnabled = true
l.exchange = exch
l.dataType = common.DataCandle
l.asset = asset.Spot
Expand Down
2 changes: 1 addition & 1 deletion backtester/engine/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (bt *BackTest) SetupFromConfig(cfg *config.Config, templatePath, output str
if !ok {
return fmt.Errorf("%v %v %w", cfg.CurrencySettings[i].ExchangeName, cfg.CurrencySettings[i].Asset, asset.ErrNotSupported)
}
exchangeAsset.AssetEnabled = convert.BoolPtr(true)
exchangeAsset.AssetEnabled = true
cp := currency.NewPair(cfg.CurrencySettings[i].Base, cfg.CurrencySettings[i].Quote).Format(*exchangeAsset.RequestFormat)
exchangeAsset.Available = exchangeAsset.Available.Add(cp)
exchangeAsset.Enabled = exchangeAsset.Enabled.Add(cp)
Expand Down
3 changes: 1 addition & 2 deletions backtester/eventhandlers/exchange/exchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/thrasher-corp/gocryptotrader/backtester/eventtypes/order"
"github.com/thrasher-corp/gocryptotrader/backtester/funding"
gctcommon "github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/convert"
gctconfig "github.com/thrasher-corp/gocryptotrader/config"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/engine"
Expand Down Expand Up @@ -381,7 +380,7 @@ func TestExecuteOrderBuySellSizeLimit(t *testing.T) {
},
Pairs: map[asset.Item]*currency.PairStore{
asset.Spot: {
AssetEnabled: convert.BoolPtr(true),
AssetEnabled: true,
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"testing"

"github.com/thrasher-corp/gocryptotrader/common/convert"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/engine"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
Expand Down Expand Up @@ -55,7 +54,7 @@ func TestCreateUSDTrackingPairs(t *testing.T) {
eba := exchB.CurrencyPairs.Pairs[a]
eba.Available = eba.Available.Add(cp, cp2, cp3)
eba.Enabled = eba.Enabled.Add(cp, cp2, cp3)
eba.AssetEnabled = convert.BoolPtr(true)
eba.AssetEnabled = true

err = em.Add(exch)
if !errors.Is(err, nil) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"testing"
"time"

"github.com/stretchr/testify/require"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/key"
"github.com/thrasher-corp/gocryptotrader/config"
Expand Down Expand Up @@ -100,14 +101,9 @@ func setupExchange(ctx context.Context, t *testing.T, name string, cfg *config.C
b := exch.GetBase()

assets := b.CurrencyPairs.GetAssetTypes(false)
if len(assets) == 0 {
t.Fatalf("Cannot setup %v, exchange has no assets", name)
}
for j := range assets {
err = b.CurrencyPairs.SetAssetEnabled(assets[j], true)
if err != nil && !errors.Is(err, currency.ErrAssetAlreadyEnabled) {
t.Fatalf("Cannot setup %v SetAssetEnabled %v", name, err)
}
require.NotEmpty(t, assets, "exchange %s must have assets", name)
for _, a := range assets {
require.NoErrorf(t, b.CurrencyPairs.SetAssetEnabled(a, true), "exchange %s SetAssetEnabled must not error for %s", name, a)
}

// Add +1 to len to verify that exchanges can handle requests with unset pairs and assets
Expand Down
10 changes: 0 additions & 10 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -904,16 +904,6 @@ func (c *Config) CheckExchangeConfigValues() error {
continue
}

for _, a := range assets {
if err := e.CurrencyPairs.IsAssetEnabled(a); errors.Is(err, currency.ErrAssetIsNil) {
// Checks if we have an old config without the ability to enable disable the entire asset
log.Warnf(log.ConfigMgr, "Exchange %s: upgrading config for asset type %s and setting enabled.\n", e.Name, a)
if err := e.CurrencyPairs.SetAssetEnabled(a, true); err != nil {
return err
}
}
}

if enabled := e.CurrencyPairs.GetAssetTypes(true); len(enabled) == 0 {
// turn on an asset if all disabled
log.Warnf(log.ConfigMgr, "%s assets disabled, turning on asset %s", e.Name, assets[0])
Expand Down
Loading

0 comments on commit b7fbff6

Please sign in to comment.