From 34e5162cf64717fe15938aa97d53c305e3abc123 Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Wed, 25 Jan 2023 10:06:39 -0500 Subject: [PATCH] btcalpha fetchTicker and fetchTickers --- js/btcalpha.js | 112 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 111 insertions(+), 1 deletion(-) diff --git a/js/btcalpha.js b/js/btcalpha.js index a237a24da914..b2add9ec55c2 100644 --- a/js/btcalpha.js +++ b/js/btcalpha.js @@ -61,7 +61,8 @@ module.exports = class btcalpha extends Exchange { 'fetchPositions': false, 'fetchPositionsRisk': false, 'fetchPremiumIndexOHLCV': false, - 'fetchTicker': undefined, + 'fetchTicker': true, + 'fetchTickers': true, 'fetchTrades': true, 'fetchTradingFee': false, 'fetchTradingFees': false, @@ -102,6 +103,7 @@ module.exports = class btcalpha extends Exchange { 'orderbook/{pair_name}', 'exchanges/', 'charts/{pair}/{type}/chart/', + 'ticker/', ], }, 'private': { @@ -228,6 +230,114 @@ module.exports = class btcalpha extends Exchange { return result; } + async fetchTickers (symbols = undefined, params = {}) { + /** + * @method + * @name btcalpha#fetchTickers + * @see https://btc-alpha.github.io/api-docs/#tickers + * @description fetches price tickers for multiple markets, statistical calculations with the information calculated over the past 24 hours each market + * @param {[string]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned + * @param {object} params extra parameters specific to the btcalpha api endpoint + * @returns {object} an array of [ticker structures]{@link https://docs.ccxt.com/en/latest/manual.html#ticker-structure} + */ + await this.loadMarkets (); + const response = await this.publicGetTicker (params); + // + // [ + // { + // timestamp: '1674658.445272', + // pair: 'BTC_USDT', + // last: '22476.85', + // diff: '458.96', + // vol: '6660.847784', + // high: '23106.08', + // low: '22348.29', + // buy: '22508.46', + // sell: '22521.11' + // }, + // ... + // ] + // + return this.parseTickers (response, symbols); + } + + async fetchTicker (symbol, params = {}) { + /** + * @method + * @name btcalpha#fetchTicker + * @see https://btc-alpha.github.io/api-docs/#tickers + * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market + * @param {string} symbol unified symbol of the market to fetch the ticker for + * @param {object} params extra parameters specific to the btcalpha api endpoint + * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/en/latest/manual.html#ticker-structure} + */ + await this.loadMarkets (); + const market = this.market (symbol); + const request = { + 'pair': market['id'], + }; + const response = await this.publicGetTicker (this.extend (request, params)); + // + // { + // timestamp: '1674658.445272', + // pair: 'BTC_USDT', + // last: '22476.85', + // diff: '458.96', + // vol: '6660.847784', + // high: '23106.08', + // low: '22348.29', + // buy: '22508.46', + // sell: '22521.11' + // } + // + return this.parseTickers (response, market); + } + + parseTicker (ticker, market = undefined) { + // + // { + // timestamp: '1674658.445272', + // pair: 'BTC_USDT', + // last: '22476.85', + // diff: '458.96', + // vol: '6660.847784', + // high: '23106.08', + // low: '22348.29', + // buy: '22508.46', + // sell: '22521.11' + // } + // + let timestamp = this.safeFloat (ticker, 'timestamp'); + if (timestamp !== undefined) { + timestamp = timestamp * 1000000; + } + const marketId = this.safeString (ticker, 'pair'); + market = this.safeMarket (marketId, market, '-'); + const last = this.safeString (ticker, 'last'); + return this.safeTicker ({ + 'info': ticker, + 'symbol': this.safeSymbol (marketId, market, '-'), + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'high': this.safeString (ticker, 'high'), + 'low': this.safeString (ticker, 'low'), + 'bid': this.safeString (ticker, 'buy'), + 'bidVolume': undefined, + 'ask': this.safeString (ticker, 'sell'), + 'askVolume': undefined, + 'vwap': undefined, + 'open': undefined, + 'close': last, + 'last': last, + 'previousClose': undefined, + 'change': undefined, + 'percentage': undefined, + 'average': undefined, + 'baseVolume': undefined, + 'quoteVolume': this.safeString (ticker, 'vol'), + }, market); + } + async fetchOrderBook (symbol, limit = undefined, params = {}) { /** * @method