Skip to content

Commit

Permalink
Merge pull request #220 from coinranking/feat/nash
Browse files Browse the repository at this point in the history
feat: nash driver
  • Loading branch information
nickpater authored Jul 29, 2020
2 parents a35ea43 + 35336c1 commit 5c3146b
Show file tree
Hide file tree
Showing 3 changed files with 1,502 additions and 0 deletions.
1 change: 1 addition & 0 deletions drivers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ exports.Mushino = require('./mushino');
exports.Mxc = require('./mxc');
exports.Nami = require('./nami');
exports.Nanuexchange = require('./nanuexchange');
exports.Nash = require('./nash');
exports.Needyex = require('./needyex');
exports.Neraex = require('./neraex');
exports.Newcapital = require('./newcapital');
Expand Down
75 changes: 75 additions & 0 deletions drivers/nash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* eslint-disable camelcase */
const Driver = require('../models/driver');
const request = require('../lib/request');
const Ticker = require('../models/ticker');
const { parseToFloat } = require('../lib/utils.js');

/**
* @memberof Driver
* @augments Driver
*/
class Nash extends Driver {
/**
* @augments Driver.fetchTickers
* @returns {Promise.Array<Ticker>} Returns a promise of an array with tickers.
*/
async fetchTickers() {
const { data: { listTickers: tickers } } = await request({
method: 'POST',
url: 'https://app.nash.io/api/graphql',
json: {
query: `
query Ticker {
listTickers {
id,
volume_24h {amount}
bestAskPrice {amount},
bestBidPrice {amount},
lastPrice {amount},
highPrice_24h {amount},
lowPrice_24h {amount},
market {
aUnit,
aAsset {name},
bAsset {name},
bUnit
}
}
}
`,
},
});

return tickers.map((ticker) => {
const {
market: {
aUnit: baseName,
aAsset: { name: base },
bUnit: quoteName,
bAsset: { name: quote },
},
bestBidPrice,
bestAskPrice,
lastPrice,
highPrice_24h,
lowPrice_24h,
volume_24h,
} = ticker;

return new Ticker({
base,
baseName,
quote,
quoteName,
bid: parseToFloat(bestBidPrice ? bestBidPrice.amount : null),
ask: parseToFloat(bestAskPrice ? bestAskPrice.amount : null),
close: parseToFloat(lastPrice ? lastPrice.amount : null),
high: parseToFloat(highPrice_24h ? highPrice_24h.amount : null),
low: parseToFloat(lowPrice_24h ? lowPrice_24h.amount : null),
quoteVolume: parseToFloat(volume_24h ? volume_24h.amount : null),
});
});
}
}

module.exports = Nash;
Loading

0 comments on commit 5c3146b

Please sign in to comment.