mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
currency: Adds matching lookup table built from available pairs (#1312)
* currency: Add pair matching update (cherry-pick) * exchange/currency: Add tests and update func * linter fix, also if using json unmarshal functionality stop usage of string conversion without delimiter * gemini: fix test * currency/manager: potential optimisation * exchanges: purge derive from wrapper cases and add warning comment * glorious: nits * glorious: nits * linter: fix * glorious: nits * whoops * whoops * glorious: nits continued * glorious: diff THANKS! * hitbtc: fix update tradable pairs strings splitting. continue if not enabled tickers update pair. * glorious: nits * linter: fix * Update exchanges/exmo/exmo_wrapper.go Co-authored-by: Scott <gloriousCode@users.noreply.github.com> * bitstamp: fix test when 32 biterinos architecturinos * capture more strings for speed * swapsies because whos running 32bit \0/? --------- Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io> Co-authored-by: Scott <gloriousCode@users.noreply.github.com>
This commit is contained in:
@@ -3089,3 +3089,139 @@ func TestGetStandardConfig(t *testing.T) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", cfg.WebsocketTrafficTimeout, config.DefaultWebsocketTrafficTimeout)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMatchSymbolWithAvailablePairs(t *testing.T) {
|
||||
t.Parallel()
|
||||
b := Base{Name: "test"}
|
||||
whatIWant := currency.NewPair(currency.BTC, currency.USDT)
|
||||
err := b.CurrencyPairs.Store(asset.Spot, ¤cy.PairStore{
|
||||
AssetEnabled: convert.BoolPtr(true),
|
||||
Available: []currency.Pair{whatIWant}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = b.MatchSymbolWithAvailablePairs("sillBillies", asset.Futures, false)
|
||||
if !errors.Is(err, currency.ErrPairNotFound) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", err, currency.ErrPairNotFound)
|
||||
}
|
||||
|
||||
whatIGot, err := b.MatchSymbolWithAvailablePairs("btcusdT", asset.Spot, false)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
|
||||
}
|
||||
|
||||
if !whatIGot.Equal(whatIWant) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", whatIGot, whatIWant)
|
||||
}
|
||||
|
||||
whatIGot, err = b.MatchSymbolWithAvailablePairs("btc-usdT", asset.Spot, true)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
|
||||
}
|
||||
|
||||
if !whatIGot.Equal(whatIWant) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", whatIGot, whatIWant)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMatchSymbolCheckEnabled(t *testing.T) {
|
||||
t.Parallel()
|
||||
b := Base{Name: "test"}
|
||||
whatIWant := currency.NewPair(currency.BTC, currency.USDT)
|
||||
availButNoEnabled := currency.NewPair(currency.BTC, currency.AUD)
|
||||
err := b.CurrencyPairs.Store(asset.Spot, ¤cy.PairStore{
|
||||
AssetEnabled: convert.BoolPtr(true),
|
||||
Available: []currency.Pair{whatIWant, availButNoEnabled},
|
||||
Enabled: []currency.Pair{whatIWant},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, _, err = b.MatchSymbolCheckEnabled("sillBillies", asset.Futures, false)
|
||||
if !errors.Is(err, currency.ErrPairNotFound) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", err, currency.ErrPairNotFound)
|
||||
}
|
||||
|
||||
whatIGot, enabled, err := b.MatchSymbolCheckEnabled("btcusdT", asset.Spot, false)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
|
||||
}
|
||||
|
||||
if !enabled {
|
||||
t.Fatal("expected true")
|
||||
}
|
||||
|
||||
if !whatIGot.Equal(whatIWant) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", whatIGot, whatIWant)
|
||||
}
|
||||
|
||||
whatIGot, enabled, err = b.MatchSymbolCheckEnabled("btc-usdT", asset.Spot, true)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
|
||||
}
|
||||
|
||||
if !whatIGot.Equal(whatIWant) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", whatIGot, whatIWant)
|
||||
}
|
||||
|
||||
if !enabled {
|
||||
t.Fatal("expected true")
|
||||
}
|
||||
|
||||
whatIGot, enabled, err = b.MatchSymbolCheckEnabled("btc-AUD", asset.Spot, true)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
|
||||
}
|
||||
|
||||
if !whatIGot.Equal(availButNoEnabled) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", whatIGot, whatIWant)
|
||||
}
|
||||
|
||||
if enabled {
|
||||
t.Fatal("expected false")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsPairEnabled(t *testing.T) {
|
||||
t.Parallel()
|
||||
b := Base{Name: "test"}
|
||||
whatIWant := currency.NewPair(currency.BTC, currency.USDT)
|
||||
availButNoEnabled := currency.NewPair(currency.BTC, currency.AUD)
|
||||
err := b.CurrencyPairs.Store(asset.Spot, ¤cy.PairStore{
|
||||
AssetEnabled: convert.BoolPtr(true),
|
||||
Available: []currency.Pair{whatIWant, availButNoEnabled},
|
||||
Enabled: []currency.Pair{whatIWant},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
enabled, err := b.IsPairEnabled(currency.NewPair(currency.AAA, currency.CYC), asset.Spot)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
|
||||
}
|
||||
|
||||
if enabled {
|
||||
t.Fatal("expected false")
|
||||
}
|
||||
|
||||
enabled, err = b.IsPairEnabled(availButNoEnabled, asset.Spot)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
|
||||
}
|
||||
|
||||
if enabled {
|
||||
t.Fatal("expected false")
|
||||
}
|
||||
|
||||
enabled, err = b.IsPairEnabled(whatIWant, asset.Spot)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
|
||||
}
|
||||
|
||||
if !enabled {
|
||||
t.Fatal("expected true")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user