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:
Luis Rascão
2021-08-27 03:31:34 +01:00
committed by GitHub
parent 4851e94eba
commit c9ab0b1164
52 changed files with 931 additions and 267 deletions

View File

@@ -139,23 +139,23 @@ func (b *Bitflyer) Run() {
}
// FetchTradablePairs returns a list of the exchanges tradable pairs
func (b *Bitflyer) FetchTradablePairs(assetType asset.Item) ([]string, error) {
func (b *Bitflyer) FetchTradablePairs(a asset.Item) ([]string, error) {
pairs, err := b.GetMarkets()
if err != nil {
return nil, err
}
format, err := b.GetPairFormat(assetType, false)
format, err := b.GetPairFormat(a, false)
if err != nil {
return nil, err
}
var products []string
for i := range pairs {
if pairs[i].Alias != "" && assetType == asset.Futures {
if pairs[i].Alias != "" && a == asset.Futures {
products = append(products, pairs[i].Alias)
} else if pairs[i].Alias == "" &&
assetType == asset.Spot &&
a == asset.Spot &&
strings.Contains(pairs[i].ProductCode,
format.Delimiter) {
products = append(products, pairs[i].ProductCode)
@@ -187,9 +187,14 @@ func (b *Bitflyer) UpdateTradablePairs(forceUpdate bool) error {
return nil
}
// UpdateTickers updates the ticker for all currency pairs of a given asset type
func (b *Bitflyer) UpdateTickers(a asset.Item) error {
return common.ErrFunctionNotSupported
}
// UpdateTicker updates and returns the ticker for a currency pair
func (b *Bitflyer) UpdateTicker(p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
fPair, err := b.FormatExchangeCurrency(p, assetType)
func (b *Bitflyer) UpdateTicker(p currency.Pair, a asset.Item) (*ticker.Price, error) {
fPair, err := b.FormatExchangeCurrency(p, a)
if err != nil {
return nil, err
}
@@ -206,12 +211,12 @@ func (b *Bitflyer) UpdateTicker(p currency.Pair, assetType asset.Item) (*ticker.
Last: tickerNew.Last,
Volume: tickerNew.Volume,
ExchangeName: b.Name,
AssetType: assetType})
AssetType: a})
if err != nil {
return nil, err
}
return ticker.GetTicker(b.Name, fPair, assetType)
return ticker.GetTicker(b.Name, fPair, a)
}
// FetchTicker returns the ticker for a currency pair