Skip to content

Commit

Permalink
some bugs fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
tankakatan committed Mar 15, 2018
1 parent 2f22b7f commit 4a391eb
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 36 deletions.
12 changes: 7 additions & 5 deletions js/acx.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@ module.exports = class acx extends Exchange {
'api': {
'public': {
'get': [
'depth', // Get depth or specified market Both asks and bids are sorted from highest price to lowest.
'k_with_pending_trades', // Get K data with pending trades, which are the trades not included in K data yet, because there's delay between trade generated and processed by K data generator
'k', // Get OHLC(k line) of specific market
'markets', // Get all available markets
'order_book', // Get the order book of specified market
'order_book/{market}',
'tickers', // Get ticker of all markets
'tickers/{market}', // Get ticker of specific market
'trades', // Get recent trades on market, each trade is included only once Trades are sorted in reverse creation order.
'order_book', // Get the order book of specified market
'depth', // Get depth or specified market Both asks and bids are sorted from highest price to lowest.
'k', // Get OHLC(k line) of specific market
'k_with_pending_trades', // Get K data with pending trades, which are the trades not included in K data yet, because there's delay between trade generated and processed by K data generator
'timestamp', // Get server current time, in seconds since Unix epoch
'trades', // Get recent trades on market, each trade is included only once Trades are sorted in reverse creation order.
'trades/{market}',
],
},
'private': {
Expand Down
13 changes: 7 additions & 6 deletions js/base/Exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -718,15 +718,15 @@ module.exports = class Exchange {
implodeParams (string, params) {
for (let property in params)
string = string.replace ('{' + property + '}', params[property])
return string
return string;
}

url (path, params = {}) {
let result = this.implodeParams (path, params);
let query = this.omit (params, this.extractParams (path))
if (Object.keys (query).length)
result += '?' + this.urlencode (query)
return result
return result;
}

async performOrderBookRequest (symbol, limit = undefined, params = {}) {
Expand All @@ -736,7 +736,7 @@ module.exports = class Exchange {
async fetchOrderBook (symbol, limit = undefined, params = {}) {
let orderbook = await this.performOrderBookRequest (symbol, limit, params);
let keys = this.orderBookKeys ();
return this.parseOrderBook (orderbook, keys)
return this.parseOrderBook (orderbook, keys);
}

async fetchL2OrderBook (symbol, limit = undefined, params = {}) {
Expand Down Expand Up @@ -795,14 +795,15 @@ module.exports = class Exchange {
}

parseOrderBook (orderbook, keys) {
let time = this.parseOrderBookTimestamp (orderbook, keys);
let timestamp = this.parseOrderBookTimestamp (orderbook, keys);
let datetime = this.iso8601 (timestamp);
let orders = this.parseOrderBookOrders (orderbook, keys);
let sec = this.parseOrderBookNonce (orderbook, keys);
return {
'bids': sortBy (orders['bids'], 0, true),
'asks': sortBy (orders['asks'], 0),
'timestamp': time,
'datetime': this.iso8601 (time),
'timestamp': timestamp,
'datetime': datetime,
'nonce': sec,
'info': orderbook,
}
Expand Down
9 changes: 9 additions & 0 deletions js/kraken.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,15 @@ module.exports = class kraken extends Exchange {
return orderbook;
}

parseOrderBookOrders (orderbook, keys) {
let bids = (keys['bids'] in orderbook) ? this.parseBidsAsks (orderbook[keys['bids']], keys) : [];
let asks = (keys['asks'] in orderbook) ? this.parseBidsAsks (orderbook[keys['asks']], keys) : [];
return {
'bids': bids,
'asks': asks,
};
}

parseTicker (ticker, market = undefined) {
let timestamp = this.milliseconds ();
let symbol = undefined;
Expand Down
28 changes: 4 additions & 24 deletions js/kuna.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,6 @@ module.exports = class kuna extends acx {
'doc': 'https://kuna.io/documents/api',
'fees': 'https://kuna.io/documents/api',
},
'api': {
'public': {
'get': [
'tickers', // all of them at once
'tickers/{market}',
'order_book',
'order_book/{market}',
'trades',
'trades/{market}',
'timestamp',
],
},
'private': {
'get': [
'members/me',
'orders',
'trades/my',
],
'post': [
'orders',
'order/delete',
],
},
},
'fees': {
'trading': {
'taker': 0.25 / 100,
Expand Down Expand Up @@ -142,6 +118,10 @@ module.exports = class kuna extends acx {
return orderBook;
}

parseOrderBookTimestamp (orderbook, keys) {
return this.safeInteger (orderbook, keys['timestamp'], undefined);
}

orderBookKeyMap () {
return {
'price': 'price',
Expand Down
9 changes: 8 additions & 1 deletion js/test/Exchange/test.fetchOrderBooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@ const log = require ('ololog')

module.exports = async (exchange) => {

const randomSymbols = exchange.symbols.sort (() => 0.5 - Math.random ()).slice (0, 10)
const customExchangeParams = {
'yobit': [randomSymbols],
'tidex': [randomSymbols],
}

const args = (exchange.id in customExchangeParams) ? customExchangeParams[exchange.id] : []
const method = 'fetchOrderBooks'

if (exchange.has[method]) {

// log ('fetching order books...')

let orderbooks = await exchange[method] ()
let orderbooks = await exchange[method] (...args)

// log.green (orderbooks)

Expand Down

0 comments on commit 4a391eb

Please sign in to comment.