mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-03 07:26:45 +00:00
exchanges: Add UpdateTickers method and reserve UpdateTicker for single ticker symbol update requests (if supported) (#764)
* exchanges: add an UpdateTickers method to the main exchange interface This method will fetch all currency pair tickers of a given asset type and update them internally, does nothing for now. * exchanges: refactor UpdateTicker on all exchanges Keep the exact previous behaviour but implement the UpdateTickers method and refactor UpdateTicker by using it where applicable. * sync_manager: update all tickers when batching is enabled * binance: UpdateTicker to fetch single ticker symbol * ftx: UpdateTicker to fetch single ticker symbol
This commit is contained in:
@@ -1090,3 +1090,18 @@ func TestGetHistoricTrades(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateTicker(t *testing.T) {
|
||||
cp := currency.NewPair(currency.ETH, currency.USD)
|
||||
_, err := b.UpdateTicker(cp, asset.PerpetualContract)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateTickers(t *testing.T) {
|
||||
err := b.UpdateTickers(asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,21 +279,16 @@ func (b *Bitmex) UpdateTradablePairs(forceUpdate bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (b *Bitmex) UpdateTicker(p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
|
||||
fPair, err := b.FormatExchangeCurrency(p, assetType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// UpdateTickers updates the ticker for all currency pairs of a given asset type
|
||||
func (b *Bitmex) UpdateTickers(a asset.Item) error {
|
||||
tick, err := b.GetActiveAndIndexInstruments()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
pairs, err := b.GetEnabledPairs(assetType)
|
||||
pairs, err := b.GetEnabledPairs(a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
for j := range tick {
|
||||
@@ -312,12 +307,27 @@ func (b *Bitmex) UpdateTicker(p currency.Pair, assetType asset.Item) (*ticker.Pr
|
||||
Pair: tick[j].Symbol,
|
||||
LastUpdated: tick[j].Timestamp,
|
||||
ExchangeName: b.Name,
|
||||
AssetType: assetType})
|
||||
AssetType: a})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
}
|
||||
return ticker.GetTicker(b.Name, fPair, assetType)
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (b *Bitmex) UpdateTicker(p currency.Pair, a asset.Item) (*ticker.Price, error) {
|
||||
err := b.UpdateTickers(a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fPair, err := b.FormatExchangeCurrency(p, a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ticker.GetTicker(b.Name, fPair, a)
|
||||
}
|
||||
|
||||
// FetchTicker returns the ticker for a currency pair
|
||||
|
||||
Reference in New Issue
Block a user