diff --git a/drivers/ankerswap.js b/drivers/ankerswap.js new file mode 100644 index 00000000..e9552642 --- /dev/null +++ b/drivers/ankerswap.js @@ -0,0 +1,31 @@ +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 Ankerswap extends Driver { + /** + * @augments Driver.fetchTickers + * @returns {Promise.Array} Returns a promise of an array with tickers. + */ + async fetchTickers() { + // get base and quote data for tickers + const { data: tickers } = await request('https://api.ankerswap.com/api/v1/tickers'); + + return tickers.map((ticker) => new Ticker({ + base: ticker.base_currency, + quote: ticker.target_currency, + high: parseToFloat(ticker.high), + low: parseToFloat(ticker.low), + close: parseToFloat(ticker.last_price), + baseVolume: parseToFloat(ticker.base_volume), + quoteVolume: parseToFloat(ticker.target_volume), + })); + } +} + +module.exports = Ankerswap; diff --git a/drivers/index.js b/drivers/index.js index 37cbbfc7..7fe222d7 100644 --- a/drivers/index.js +++ b/drivers/index.js @@ -8,6 +8,7 @@ exports.Allcoin = require('./allcoin'); exports.Altcointrader = require('./altcointrader'); exports.Altilly = require('./altilly'); exports.Altmarkets = require('./altmarkets'); +exports.Ankerswap = require('./ankerswap'); exports.Atomars = require('./atomars'); exports.Bamboo = require('./bamboo'); exports.Bancor = require('./bancor'); diff --git a/tests/fixtures/ankerswap.json b/tests/fixtures/ankerswap.json new file mode 100644 index 00000000..9997021b --- /dev/null +++ b/tests/fixtures/ankerswap.json @@ -0,0 +1,568 @@ +[ + { + "scope": "https://api.ankerswap.com:443", + "method": "GET", + "path": "/api/v1/tickers", + "body": "", + "status": 200, + "response": { + "time": 1597086847, + "data": [ + { + "ticker_id": "PAX_LTC", + "base_currency": "PAX", + "target_currency": "LTC", + "ask": "0.016791", + "last_price": "0.016791", + "base_volume": 0, + "target_volume": 0, + "high": "0.016791", + "low": "0.016791" + }, + { + "ticker_id": "PAX_NANO", + "base_currency": "PAX", + "target_currency": "NANO", + "ask": "0.831269", + "last_price": "0.831269", + "base_volume": 0, + "target_volume": 0, + "high": "0.831269", + "low": "0.831269" + }, + { + "ticker_id": "PAX_DOGE", + "base_currency": "PAX", + "target_currency": "DOGE", + "ask": "269.375455", + "last_price": "269.375455", + "base_volume": 0, + "target_volume": 0, + "high": "269.375455", + "low": "269.375455" + }, + { + "ticker_id": "PAX_DASH", + "base_currency": "PAX", + "target_currency": "DASH", + "ask": "0.010202", + "last_price": "0.010202", + "base_volume": 0, + "target_volume": 0, + "high": "0.010202", + "low": "0.010202" + }, + { + "ticker_id": "PAX_MATIC", + "base_currency": "PAX", + "target_currency": "MATIC", + "ask": "39.614038", + "last_price": "39.614038", + "base_volume": 0, + "target_volume": 0, + "high": "39.614038", + "low": "39.614038" + }, + { + "ticker_id": "PAX_BTC", + "base_currency": "PAX", + "target_currency": "BTC", + "ask": "0.000082", + "last_price": "0.000082", + "base_volume": 0, + "target_volume": 0, + "high": "0.000082", + "low": "0.000082" + }, + { + "ticker_id": "PAX_ETH", + "base_currency": "PAX", + "target_currency": "ETH", + "ask": "0.002423", + "last_price": "0.002423", + "base_volume": 0, + "target_volume": 0, + "high": "0.002423", + "low": "0.002423" + }, + { + "ticker_id": "LTC_PAX", + "base_currency": "LTC", + "target_currency": "PAX", + "ask": "57.168659", + "last_price": "57.168659", + "base_volume": 0, + "target_volume": 0, + "high": "57.168659", + "low": "57.168659" + }, + { + "ticker_id": "LTC_NANO", + "base_currency": "LTC", + "target_currency": "NANO", + "ask": "48.506048", + "last_price": "48.506048", + "base_volume": 0, + "target_volume": 0, + "high": "48.506048", + "low": "48.506048" + }, + { + "ticker_id": "LTC_DOGE", + "base_currency": "LTC", + "target_currency": "DOGE", + "ask": "16039.333333", + "last_price": "16039.333333", + "base_volume": 0, + "target_volume": 0, + "high": "16039.333333", + "low": "16039.333333" + }, + { + "ticker_id": "LTC_DASH", + "base_currency": "LTC", + "target_currency": "DASH", + "ask": "0.595299", + "last_price": "0.595299", + "base_volume": 0, + "target_volume": 0, + "high": "0.595299", + "low": "0.595299" + }, + { + "ticker_id": "LTC_MATIC", + "base_currency": "LTC", + "target_currency": "MATIC", + "ask": "2358.725490", + "last_price": "2557.483871", + "base_volume": 4.199999999999999, + "target_volume": 10741.432258064515, + "high": "2557.483871", + "low": "2557.483871" + }, + { + "ticker_id": "LTC_BTC", + "base_currency": "LTC", + "target_currency": "BTC", + "ask": "0.004812", + "last_price": "0.004772", + "base_volume": 4.199999999999999, + "target_volume": 0.020040803999999995, + "high": "0.004772", + "low": "0.004772" + }, + { + "ticker_id": "LTC_ETH", + "base_currency": "LTC", + "target_currency": "ETH", + "ask": "0.144265", + "last_price": "0.144265", + "base_volume": 0, + "target_volume": 0, + "high": "0.144265", + "low": "0.144265" + }, + { + "ticker_id": "NANO_PAX", + "base_currency": "NANO", + "target_currency": "PAX", + "ask": "1.152688", + "last_price": "1.152688", + "base_volume": 0, + "target_volume": 0, + "high": "1.152688", + "low": "1.152688" + }, + { + "ticker_id": "NANO_LTC", + "base_currency": "NANO", + "target_currency": "LTC", + "ask": "0.019756", + "last_price": "0.018614", + "base_volume": 140, + "target_volume": 2.6059228706949886, + "high": "0.018614", + "low": "0.018614" + }, + { + "ticker_id": "NANO_DOGE", + "base_currency": "NANO", + "target_currency": "DOGE", + "ask": "323.400000", + "last_price": "299.553333", + "base_volume": 805, + "target_volume": 239505.46666666667, + "high": "299.553333", + "low": "295.306667" + }, + { + "ticker_id": "NANO_DASH", + "base_currency": "NANO", + "target_currency": "DASH", + "ask": "0.012003", + "last_price": "0.012003", + "base_volume": 0, + "target_volume": 0, + "high": "0.012003", + "low": "0.012003" + }, + { + "ticker_id": "NANO_MATIC", + "base_currency": "NANO", + "target_currency": "MATIC", + "ask": "47.558824", + "last_price": "47.558824", + "base_volume": 0, + "target_volume": 0, + "high": "47.558824", + "low": "47.558824" + }, + { + "ticker_id": "NANO_BTC", + "base_currency": "NANO", + "target_currency": "BTC", + "ask": "0.000097", + "last_price": "0.000092", + "base_volume": 315, + "target_volume": 0.028777699999999996, + "high": "0.000092", + "low": "0.000091" + }, + { + "ticker_id": "NANO_ETH", + "base_currency": "NANO", + "target_currency": "ETH", + "ask": "0.002909", + "last_price": "0.002909", + "base_volume": 0, + "target_volume": 0, + "high": "0.002909", + "low": "0.002909" + }, + { + "ticker_id": "DASH_PAX", + "base_currency": "DASH", + "target_currency": "PAX", + "ask": "94.077956", + "last_price": "94.077956", + "base_volume": 0, + "target_volume": 0, + "high": "94.077956", + "low": "94.077956" + }, + { + "ticker_id": "DASH_LTC", + "base_currency": "DASH", + "target_currency": "LTC", + "ask": "1.612380", + "last_price": "1.611724", + "base_volume": 4, + "target_volume": 6.565067627016841, + "high": "1.670810", + "low": "1.611724" + }, + { + "ticker_id": "DASH_NANO", + "base_currency": "DASH", + "target_currency": "NANO", + "ask": "79.822581", + "last_price": "86.660455", + "base_volume": 2, + "target_volume": 173.32091007583966, + "high": "86.660455", + "low": "86.660455" + }, + { + "ticker_id": "DASH_DOGE", + "base_currency": "DASH", + "target_currency": "DOGE", + "ask": "26394.666667", + "last_price": "26394.666667", + "base_volume": 0, + "target_volume": 0, + "high": "26394.666667", + "low": "26394.666667" + }, + { + "ticker_id": "DASH_MATIC", + "base_currency": "DASH", + "target_currency": "MATIC", + "ask": "3881.568627", + "last_price": "3881.568627", + "base_volume": 0, + "target_volume": 0, + "high": "3881.568627", + "low": "3881.568627" + }, + { + "ticker_id": "DASH_BTC", + "base_currency": "DASH", + "target_currency": "BTC", + "ask": "0.007918", + "last_price": "0.008008", + "base_volume": 2.8000000000000003, + "target_volume": 0.022421224000000003, + "high": "0.008008", + "low": "0.008008" + }, + { + "ticker_id": "DASH_ETH", + "base_currency": "DASH", + "target_currency": "ETH", + "ask": "0.237405", + "last_price": "0.240260", + "base_volume": 2.6, + "target_volume": 0.6246754473612499, + "high": "0.240260", + "low": "0.240260" + }, + { + "ticker_id": "MATIC_PAX", + "base_currency": "MATIC", + "target_currency": "PAX", + "ask": "0.023163", + "last_price": "0.023163", + "base_volume": 0, + "target_volume": 0, + "high": "0.023163", + "low": "0.023163" + }, + { + "ticker_id": "MATIC_LTC", + "base_currency": "MATIC", + "target_currency": "LTC", + "ask": "0.000405", + "last_price": "0.000405", + "base_volume": 0, + "target_volume": 0, + "high": "0.000405", + "low": "0.000405" + }, + { + "ticker_id": "MATIC_NANO", + "base_currency": "MATIC", + "target_currency": "NANO", + "ask": "0.020054", + "last_price": "0.020054", + "base_volume": 0, + "target_volume": 0, + "high": "0.020054", + "low": "0.020054" + }, + { + "ticker_id": "MATIC_DOGE", + "base_currency": "MATIC", + "target_currency": "DOGE", + "ask": "6.498707", + "last_price": "5.954480", + "base_volume": 14000, + "target_volume": 83362.72, + "high": "5.954480", + "low": "5.954480" + }, + { + "ticker_id": "MATIC_DASH", + "base_currency": "MATIC", + "target_currency": "DASH", + "ask": "0.000246", + "last_price": "0.000246", + "base_volume": 0, + "target_volume": 0, + "high": "0.000246", + "low": "0.000246" + }, + { + "ticker_id": "MATIC_BTC", + "base_currency": "MATIC", + "target_currency": "BTC", + "ask": "0.000002", + "last_price": "0.000002", + "base_volume": 0, + "target_volume": 0, + "high": "0.000002", + "low": "0.000002" + }, + { + "ticker_id": "MATIC_ETH", + "base_currency": "MATIC", + "target_currency": "ETH", + "ask": "0.000058", + "last_price": "0.000058", + "base_volume": 0, + "target_volume": 0, + "high": "0.000058", + "low": "0.000058" + }, + { + "ticker_id": "BTC_PAX", + "base_currency": "BTC", + "target_currency": "PAX", + "ask": "11643.311400", + "last_price": "11653.336800", + "base_volume": 0.096, + "target_volume": 1124.4880248000002, + "high": "11758.049800", + "low": "11558.688400" + }, + { + "ticker_id": "BTC_LTC", + "base_currency": "BTC", + "target_currency": "LTC", + "ask": "199.552026", + "last_price": "199.470792", + "base_volume": 0.049999999999999996, + "target_volume": 10.041110075893476, + "high": "201.936946", + "low": "199.470792" + }, + { + "ticker_id": "BTC_NANO", + "base_currency": "BTC", + "target_currency": "NANO", + "ask": "9879.032258", + "last_price": "10283.315845", + "base_volume": 0.09, + "target_volume": 949.6156045838741, + "high": "10925.306577", + "low": "10283.315845" + }, + { + "ticker_id": "BTC_DOGE", + "base_currency": "BTC", + "target_currency": "DOGE", + "ask": "3266666.666667", + "last_price": "3266666.666667", + "base_volume": 0.129, + "target_volume": 421399.99999999994, + "high": "3266666.666667", + "low": "3266666.666667" + }, + { + "ticker_id": "BTC_DASH", + "base_currency": "BTC", + "target_currency": "DASH", + "ask": "121.242113", + "last_price": "121.227115", + "base_volume": 0.147, + "target_volume": 17.754603628743524, + "high": "121.332178", + "low": "119.745846" + }, + { + "ticker_id": "BTC_MATIC", + "base_currency": "BTC", + "target_currency": "MATIC", + "ask": "480392.156863", + "last_price": "485148.514851", + "base_volume": 0.084, + "target_volume": 42501.3674478468, + "high": "521276.595745", + "low": "485148.514851" + }, + { + "ticker_id": "BTC_ETH", + "base_currency": "BTC", + "target_currency": "ETH", + "ask": "29.381783", + "last_price": "29.525187", + "base_volume": 0.039, + "target_volume": 1.156263707219138, + "high": "29.744742", + "low": "29.525187" + }, + { + "ticker_id": "ETH_PAX", + "base_currency": "ETH", + "target_currency": "PAX", + "ask": "380.572578", + "last_price": "381.368499", + "base_volume": 4.700000000000001, + "target_volume": 1785.0596757000003, + "high": "384.020781", + "low": "376.310627" + }, + { + "ticker_id": "ETH_LTC", + "base_currency": "ETH", + "target_currency": "LTC", + "ask": "6.655659", + "last_price": "6.681671", + "base_volume": 0.2, + "target_volume": 1.3363342273571281, + "high": "6.681671", + "low": "6.681671" + }, + { + "ticker_id": "ETH_NANO", + "base_currency": "ETH", + "target_currency": "NANO", + "ask": "329.495363", + "last_price": "351.395440", + "base_volume": 2.9000000000000004, + "target_volume": 1027.9150784655158, + "high": "355.618441", + "low": "351.395440" + }, + { + "ticker_id": "ETH_DOGE", + "base_currency": "ETH", + "target_currency": "DOGE", + "ask": "106774.070667", + "last_price": "106281.065333", + "base_volume": 2.3000000000000003, + "target_volume": 244446.45026590003, + "high": "106281.065333", + "low": "106281.065333" + }, + { + "ticker_id": "ETH_DASH", + "base_currency": "ETH", + "target_currency": "DASH", + "ask": "4.043788", + "last_price": "4.020556", + "base_volume": 6.4, + "target_volume": 25.586695948455578, + "high": "4.020556", + "low": "3.874532" + }, + { + "ticker_id": "ETH_MATIC", + "base_currency": "ETH", + "target_currency": "MATIC", + "ask": "15702.069216", + "last_price": "15877.028515", + "base_volume": 4.300000000000001, + "target_volume": 71711.4679768, + "high": "17133.536000", + "low": "15877.028515" + }, + { + "ticker_id": "ETH_BTC", + "base_currency": "ETH", + "target_currency": "BTC", + "ask": "0.032686", + "last_price": "0.032726", + "base_volume": 2.3000000000000003, + "target_volume": 0.07525449399999999, + "high": "0.032726", + "low": "0.032570" + } + ] + }, + "rawHeaders": [ + "Server", + "nginx/1.14.0 (Ubuntu)", + "Date", + "Mon, 10 Aug 2020 19:14:35 GMT", + "Content-Type", + "application/json; charset=UTF-8", + "Content-Length", + "10690", + "Connection", + "keep-alive", + "Etag", + "\"5b5e306220fb073e0e82b29d9976d1eedcba56f1\"" + ], + "responseIsBinary": false + } +] \ No newline at end of file