exmo: refactor UpdateTickers function (#1180)

* exmo: filter pairs that are not currently enabled by last update time

* stop filtering, add tests to qualify all deployable can be retrieved

* glorious: nits

---------

Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
This commit is contained in:
Ryan O'Hara-Reid
2023-05-09 10:17:15 +10:00
committed by GitHub
parent 2d2d115ac9
commit 616b45ae14
2 changed files with 65 additions and 26 deletions

View File

@@ -177,16 +177,14 @@ func (e *EXMO) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.P
return nil, err
}
pairs := make([]currency.Pair, len(symbols))
var target int
pairs := make([]currency.Pair, 0, len(symbols))
for key := range symbols {
var pair currency.Pair
pair, err = currency.NewPairFromString(key)
if err != nil {
return nil, err
}
pairs[target] = pair
target++
pairs = append(pairs, pair)
}
return pairs, nil
}
@@ -203,35 +201,46 @@ func (e *EXMO) UpdateTradablePairs(ctx context.Context, forceUpdate bool) error
// UpdateTickers updates the ticker for all currency pairs of a given asset type
func (e *EXMO) UpdateTickers(ctx context.Context, a asset.Item) error {
avail, err := e.GetAvailablePairs(a)
if err != nil {
return err
}
enabled, err := e.GetEnabledPairs(a)
if err != nil {
return err
}
result, err := e.GetTicker(ctx)
if err != nil {
return err
}
pairs, err := e.GetEnabledPairs(a)
if err != nil {
return err
}
for i := range pairs {
for j := range result {
if !strings.EqualFold(pairs[i].String(), j) {
continue
}
err = ticker.ProcessTicker(&ticker.Price{
Pair: pairs[i],
Last: result[j].Last,
Ask: result[j].Sell,
High: result[j].High,
Bid: result[j].Buy,
Low: result[j].Low,
Volume: result[j].Volume,
ExchangeName: e.Name,
AssetType: a})
if err != nil {
return err
}
for symbol, tick := range result {
var pair currency.Pair
pair, err = avail.DeriveFrom(strings.Replace(symbol, "_", "", 1))
if err != nil {
return err
}
if !enabled.Contains(pair, true) {
continue
}
err = ticker.ProcessTicker(&ticker.Price{
Pair: pair,
Last: tick.Last,
Ask: tick.Sell,
High: tick.High,
Bid: tick.Buy,
Low: tick.Low,
Volume: tick.Volume,
LastUpdated: time.Unix(tick.Updated, 0),
ExchangeName: e.Name,
AssetType: a})
if err != nil {
return err
}
}
return nil
}