-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #216 from coinranking/feat/coindcx
feat: coindcx driver
- Loading branch information
Showing
3 changed files
with
18,842 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
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 Coindcx extends Driver { | ||
/** | ||
* @augments Driver.fetchTickers | ||
* @returns {Promise.Array<Ticker>} Returns a promise of an array with tickers. | ||
*/ | ||
async fetchTickers() { | ||
const symbols = await request('https://api.coindcx.com/exchange/v1/markets_details'); | ||
const pairs = []; | ||
|
||
symbols.forEach((el) => { | ||
pairs[el.symbol] = { | ||
quote: el.base_currency_short_name, | ||
base: el.target_currency_short_name, | ||
quoteName: el.base_currency_name, | ||
baseName: el.target_currency_name, | ||
}; | ||
}); | ||
|
||
const tickers = await request('https://api.coindcx.com/exchange/ticker'); | ||
|
||
return tickers.map((ticker) => { | ||
if (!pairs[ticker.market]) { | ||
return undefined; | ||
} | ||
|
||
const { | ||
base, quote, baseName, quoteName, | ||
} = pairs[ticker.market]; | ||
|
||
return new Ticker({ | ||
base, | ||
baseName, | ||
quote, | ||
quoteName, | ||
high: parseToFloat(ticker.high), | ||
low: parseToFloat(ticker.low), | ||
close: parseToFloat(ticker.last_price), | ||
quoteVolume: parseToFloat(ticker.volume), | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = Coindcx; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.