mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-07 15:11:03 +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:
@@ -1000,3 +1000,23 @@ func TestGetHistoricTrades(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateTicker(t *testing.T) {
|
||||
t.Parallel()
|
||||
cp, err := currency.NewPairFromString("ETH_USDT")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = z.UpdateTicker(cp, asset.Spot)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateTickers(t *testing.T) {
|
||||
t.Parallel()
|
||||
err := z.UpdateTickers(asset.Spot)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,16 +243,16 @@ func (z *ZB) UpdateTradablePairs(forceUpdate bool) error {
|
||||
return z.UpdatePairs(p, asset.Spot, false, forceUpdate)
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (z *ZB) UpdateTicker(p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
|
||||
// UpdateTickers updates the ticker for all currency pairs of a given asset type
|
||||
func (z *ZB) UpdateTickers(a asset.Item) error {
|
||||
result, err := z.GetTickers()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
enabledPairs, err := z.GetEnabledPairs(assetType)
|
||||
enabledPairs, err := z.GetEnabledPairs(a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
for x := range enabledPairs {
|
||||
// We can't use either pair format here, so format it to lower-
|
||||
@@ -271,13 +271,22 @@ func (z *ZB) UpdateTicker(p currency.Pair, assetType asset.Item) (*ticker.Price,
|
||||
Low: result[curr].Low,
|
||||
Volume: result[curr].Volume,
|
||||
ExchangeName: z.Name,
|
||||
AssetType: assetType})
|
||||
AssetType: a})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return ticker.GetTicker(z.Name, p, assetType)
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (z *ZB) UpdateTicker(p currency.Pair, a asset.Item) (*ticker.Price, error) {
|
||||
err := z.UpdateTickers(a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ticker.GetTicker(z.Name, p, a)
|
||||
}
|
||||
|
||||
// FetchTicker returns the ticker for a currency pair
|
||||
|
||||
Reference in New Issue
Block a user