mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-14 07:26:47 +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:
@@ -78,6 +78,7 @@ var (
|
||||
errGRPCShutdownSignalIsNil = errors.New("cannot shutdown, gRPC shutdown channel is nil")
|
||||
errInvalidStrategy = errors.New("invalid strategy")
|
||||
errSpecificPairNotEnabled = errors.New("specified pair is not enabled")
|
||||
errPairNotEnabled = errors.New("pair is not enabled")
|
||||
)
|
||||
|
||||
// RPCServer struct
|
||||
@@ -4686,13 +4687,18 @@ func (s *RPCServer) GetFundingRates(ctx context.Context, r *gctrpc.GetFundingRat
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cp, err := exch.MatchSymbolWithAvailablePairs(r.Pair.Base+r.Pair.Quote, a, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pairs, err := exch.GetEnabledPairs(a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cp, err := pairs.DeriveFrom(r.Pair.Base + r.Pair.Quote)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
if !pairs.Contains(cp, true) {
|
||||
return nil, fmt.Errorf("%w %v", errPairNotEnabled, cp)
|
||||
}
|
||||
|
||||
funding, err := exch.GetFundingRates(ctx, &fundingrate.RatesRequest{
|
||||
@@ -4779,14 +4785,20 @@ func (s *RPCServer) GetLatestFundingRate(ctx context.Context, r *gctrpc.GetLates
|
||||
return nil, fmt.Errorf("%s %w", a, futures.ErrNotFuturesAsset)
|
||||
}
|
||||
|
||||
cp, err := exch.MatchSymbolWithAvailablePairs(r.Pair.Base+r.Pair.Quote, a, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pairs, err := exch.GetEnabledPairs(a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cp, err := pairs.DeriveFrom(r.Pair.Base + r.Pair.Quote)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
if !pairs.Contains(cp, true) {
|
||||
return nil, fmt.Errorf("%w %v", errPairNotEnabled, cp)
|
||||
}
|
||||
|
||||
funding, err := exch.GetLatestFundingRate(ctx, &fundingrate.LatestRateRequest{
|
||||
Asset: a,
|
||||
Pair: cp,
|
||||
|
||||
@@ -2927,19 +2927,26 @@ func TestGetFundingRates(t *testing.T) {
|
||||
}
|
||||
|
||||
b.CurrencyPairs.Pairs = make(map[asset.Item]*currency.PairStore)
|
||||
b.CurrencyPairs.Pairs[asset.Futures] = ¤cy.PairStore{
|
||||
err = b.CurrencyPairs.Store(asset.Futures, ¤cy.PairStore{
|
||||
AssetEnabled: convert.BoolPtr(true),
|
||||
RequestFormat: ¤cy.PairFormat{Delimiter: "-"},
|
||||
ConfigFormat: ¤cy.PairFormat{Delimiter: "-"},
|
||||
Available: currency.Pairs{cp},
|
||||
Enabled: currency.Pairs{cp},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b.CurrencyPairs.Pairs[asset.Spot] = ¤cy.PairStore{
|
||||
|
||||
err = b.CurrencyPairs.Store(asset.Spot, ¤cy.PairStore{
|
||||
AssetEnabled: convert.BoolPtr(true),
|
||||
ConfigFormat: ¤cy.PairFormat{Delimiter: "/"},
|
||||
RequestFormat: ¤cy.PairFormat{Delimiter: "/"},
|
||||
Available: currency.Pairs{cp},
|
||||
Enabled: currency.Pairs{cp},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b.Features.Supports.FuturesCapabilities.FundingRates = true
|
||||
fakeExchange := fExchange{
|
||||
@@ -3028,19 +3035,25 @@ func TestGetLatestFundingRate(t *testing.T) {
|
||||
}
|
||||
|
||||
b.CurrencyPairs.Pairs = make(map[asset.Item]*currency.PairStore)
|
||||
b.CurrencyPairs.Pairs[asset.Futures] = ¤cy.PairStore{
|
||||
err = b.CurrencyPairs.Store(asset.Futures, ¤cy.PairStore{
|
||||
AssetEnabled: convert.BoolPtr(true),
|
||||
RequestFormat: ¤cy.PairFormat{Delimiter: "-"},
|
||||
ConfigFormat: ¤cy.PairFormat{Delimiter: "-"},
|
||||
Available: currency.Pairs{cp},
|
||||
Enabled: currency.Pairs{cp},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b.CurrencyPairs.Pairs[asset.Spot] = ¤cy.PairStore{
|
||||
err = b.CurrencyPairs.Store(asset.Spot, ¤cy.PairStore{
|
||||
AssetEnabled: convert.BoolPtr(true),
|
||||
ConfigFormat: ¤cy.PairFormat{Delimiter: "/"},
|
||||
RequestFormat: ¤cy.PairFormat{Delimiter: "/"},
|
||||
Available: currency.Pairs{cp},
|
||||
Enabled: currency.Pairs{cp},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fakeExchange := fExchange{
|
||||
IBotExchange: exch,
|
||||
|
||||
Reference in New Issue
Block a user