Skip to content

Commit

Permalink
btcalpha fetchTicker and fetchTickers
Browse files Browse the repository at this point in the history
  • Loading branch information
samgermain committed Jan 25, 2023
1 parent 0089884 commit 34e5162
Showing 1 changed file with 111 additions and 1 deletion.
112 changes: 111 additions & 1 deletion js/btcalpha.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -102,6 +103,7 @@ module.exports = class btcalpha extends Exchange {
'orderbook/{pair_name}',
'exchanges/',
'charts/{pair}/{type}/chart/',
'ticker/',
],
},
'private': {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 34e5162

Please sign in to comment.