Skip to content

Commit

Permalink
fetchTickers support
Browse files Browse the repository at this point in the history
Added support for fetching tickers. Tested with my okex account and works OK :)
  • Loading branch information
michnovka authored Jan 20, 2018
1 parent cd0c54e commit 08ae603
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions js/okcoinusd.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = class okcoinusd extends Exchange {
'hasFetchOHLCV': true,
'hasFetchOrder': true,
'hasFetchOrders': false,
'hasFetchTickets': true,
'hasFetchOpenOrders': true,
'hasFetchClosedOrders': true,
'hasWithdraw': true,
Expand All @@ -31,6 +32,7 @@ module.exports = class okcoinusd extends Exchange {
'fetchOrders': false,
'fetchOpenOrders': true,
'fetchClosedOrders': true,
'fetchTickers' : true,
'withdraw': true,
},
'extension': '.do', // appended to endpoint URL
Expand Down Expand Up @@ -72,6 +74,7 @@ module.exports = class okcoinusd extends Exchange {
'kline',
'otcs',
'ticker',
'tickers',
'trades',
],
},
Expand Down Expand Up @@ -272,6 +275,39 @@ module.exports = class okcoinusd extends Exchange {
let ticker = this.extend (response['ticker'], { 'timestamp': timestamp });
return this.parseTicker (ticker, market);
}


async fetchTickers (params = {}) {
await this.loadMarkets ();
let method = 'publicGetTickers';
let request = { };
let response = await this[method] (this.extend (request, params));
let timestamp = parseInt (response['date']) * 1000;
return this.parseTickers (response['tickers'], timestamp);
}


parseTickers (tickers, timestamp) {

if(!tickers || tickers.length < 1)
return [];

let tickers_result = {};

for(let i = 0; i < tickers.length; i++){

let market = undefined;

if ('symbol' in tickers[i] && tickers[i]['symbol'] in this.markets_by_id)
market = this.markets_by_id[tickers[i]['symbol']];

let ticker = this.extend (tickers[i], { 'timestamp': timestamp });
tickers_result[market['symbol']] = this.parseTicker(ticker, market);
}

return tickers_result;

}

parseTrade (trade, market = undefined) {
let symbol = undefined;
Expand Down

0 comments on commit 08ae603

Please sign in to comment.