diff --git a/README.md b/README.md index 1bfc48e..99299ba 100644 --- a/README.md +++ b/README.md @@ -871,19 +871,19 @@ It will print similar to the following: ### Exchanges - Services/Methods -| ExchangeRatesService | MetadataService | OHLCVService | TradesService | -| -------------------- | ------------------ | -------------- | ------------------------------------------ | -| getSpecificRate | listAllExchanges | listAllPeriods | getLatestData | -| getAllCurrentRates | getExchangeDetails | latestData | getLatestDataBySymbol | -| | listAllAssets | historicalData | getLatestDataByExchange | -| | listAllSymbols | | getLatestDataByAsset | -| | getSymbolDetails | | getLatestDataByAssetsPair | -| | | | getLatestDataByExchangeAssetsPair | -| | | | tradesGetHistoricalData | -| | | | tradesGetHistoricalDataByExchange | -| | | | tradesGetHistoricalDataByAsset | -| | | | tradesGetHistoricalDataByAssetPair | -| | | | tradesGetHistoricalDataByExchangeAssetPair | +| Base | ExchangeRatesService | MetadataService | OHLCVService | TradesService | +| ------------------ | -------------------- | ---------------- | -------------- | ------------------------------------------ | +| listAllExchanges | getSpecificRate | listAllExchanges | listAllPeriods | getLatestData | +| getExchangeDetails | getAllCurrentRates | listAllAssets | latestData | getLatestDataBySymbol | +| listAllAssets | | listAllSymbols | historicalData | getLatestDataByExchange | +| getAssetDetails | | | | getLatestDataByAsset | +| getSymbolDetails | | | | getLatestDataByAssetsPair | +| | | | | getLatestDataByExchangeAssetsPair | +| | | | | tradesGetHistoricalData | +| | | | | tradesGetHistoricalDataByExchange | +| | | | | tradesGetHistoricalDataByAsset | +| | | | | tradesGetHistoricalDataByAssetPair | +| | | | | tradesGetHistoricalDataByExchangeAssetPair | ### Ethereum - Services/Methods diff --git a/src/rest-apis/crypto-market-data/base.js b/src/rest-apis/crypto-market-data/base.js new file mode 100644 index 0000000..ed64a9f --- /dev/null +++ b/src/rest-apis/crypto-market-data/base.js @@ -0,0 +1,79 @@ +const BaseAuth = require('../../common/base-auth'); + +class Base extends BaseAuth { + + /** + * List All Exchanges + * + * @async + * @desc Get a detailed list of all supported exchanges provided by our system. + * + * @param {number} [skip=0] - The offset of items to start from. Useful for paginations. (e.g. skip=100 would show results from 101 item to 150). + * @param {number} [limit=50] - Amount of items to return (optional, default value is 50). + * + * @returns {*} + */ + listAllExchanges(skip = 0, limit = 50) { + return this.request.get('/exchanges?skip=' + skip + '&limit=' + limit); + } + + /** + * Get Exchange details + * + * @async + * @desc Get a detailed information for a single supported exchange provided by our system by ID. + * + * @param {string} exchangeId - Our identifier (UID) of the exchange. (_id attribute from exchanges endpoint). + * + * @returns {*} + */ + getExchangeDetails(exchangeId) { + return this.request.get('/exchanges/' + exchangeId); + } + + /** + * List All Assets + * + * @async + * @desc Get detailed list of all associated assets. + * + * @param {number} [skip=0] - The offset of items to start from. Useful for paginations. (e.g. skip=100 would show results from 101 item to 150). + * @param {number} [limit=50] - Amount of items to return (optional, default value is 50). + * + * @returns {*} + */ + listAllAssets(skip = 0, limit = 50) { + return this.request.get('/assets?skip=' + skip + '&limit=' + limit); + } + + /** + * Get Asset details + * + * @async + * @desc Get detailed information for a specific asset. + * + * @param {string} assetId - Our identifier (UID) of the asset. (_id attribute from assets endpoint). + * + * @returns {*} + */ + getAssetDetails(assetId) { + return this.request.get('/assets/' + assetId); + } + + /** + * Get symbol details + * + * @async + * @desc Get a detailed information for a specific symbol mapping. + * + * @param {string} symbolId - Symbol identifier used to filter response. (_id attribute from symbols endpoint). + * + * @returns {*} + */ + getSymbolDetails(symbolId) { + return this.request.get('/mappings/' + symbolId); + } + +} + +module.exports = Base; diff --git a/src/rest-apis/crypto-market-data/index.js b/src/rest-apis/crypto-market-data/index.js index 36085ab..8277373 100644 --- a/src/rest-apis/crypto-market-data/index.js +++ b/src/rest-apis/crypto-market-data/index.js @@ -1,3 +1,4 @@ +var Base = require('./base'); var ExchangeRates = require('./exchange-rates'); var Meta = require('./meta'); var OHLCV = require('./ohlcv'); @@ -6,6 +7,7 @@ var Trades = require('./trades'); class CryptoMarketData { constructor(...props) { + this.base = new Base(...props); this.exchangeRates = new ExchangeRates(...props); this.meta = new Meta(...props); this.OHLCV = new OHLCV(...props); diff --git a/src/rest-apis/crypto-market-data/meta.js b/src/rest-apis/crypto-market-data/meta.js index 6aa54b1..d3e80c7 100644 --- a/src/rest-apis/crypto-market-data/meta.js +++ b/src/rest-apis/crypto-market-data/meta.js @@ -14,21 +14,7 @@ class Meta extends BaseAuth { * @returns {*} */ listAllExchanges(skip = 0, limit = 50) { - return this.request.get('/exchanges?skip=' + skip + '&limit=' + limit); - } - - /** - * Get Exchange details - * - * @async - * @desc Get a detailed information for a single supported exchange provided by our system by ID. - * - * @param {string} exchangeId - Our identifier (UID) of the exchange. (_id attribute from exchanges endpoint). - * - * @returns {*} - */ - getExchangeDetails(exchangeId) { - return this.request.get('/exchanges/' + exchangeId); + return this.request.get('/exchanges/meta?skip=' + skip + '&limit=' + limit); } /** @@ -43,21 +29,7 @@ class Meta extends BaseAuth { * @returns {*} */ listAllAssets(skip = 0, limit = 50) { - return this.request.get('/assets?skip=' + skip + '&limit=' + limit); - } - - /** - * Get Asset details - * - * @async - * @desc Get detailed information for a specific asset. - * - * @param {string} assetId - Our identifier (UID) of the asset. (_id attribute from assets endpoint). - * - * @returns {*} - */ - getAssetDetails(assetId) { - return this.request.get('/assets/' + assetId); + return this.request.get('/assets/meta?skip=' + skip + '&limit=' + limit); } /** @@ -75,20 +47,6 @@ class Meta extends BaseAuth { return this.request.get('/mappings?skip=' + skip + '&limit=' + limit); } - /** - * Get symbol details - * - * @async - * @desc Get a detailed information for a specific symbol mapping. - * - * @param {string} symbolId - Symbol identifier used to filter response. (_id attribute from symbols endpoint). - * - * @returns {*} - */ - getSymbolDetails(symbolId) { - return this.request.get('/mappings/' + symbolId); - } - } module.exports = Meta; diff --git a/tests/rest-apis/crypto-market-data/base.test.js b/tests/rest-apis/crypto-market-data/base.test.js new file mode 100644 index 0000000..feba4b0 --- /dev/null +++ b/tests/rest-apis/crypto-market-data/base.test.js @@ -0,0 +1,23 @@ +async function Base(caClient) { + console.log('\n::CMD Base'); + + const exchanges = await caClient.CMD.base.listAllExchanges().then(response => response.payload); + if (exchanges && exchanges.length) { + const exchangeId = exchanges[0]._id; + await caClient.CMD.base.getExchangeDetails(exchangeId); + } + + const assets = await caClient.CMD.base.listAllAssets().then(response => response.payload); + if (assets && assets.length) { + const assetsId = assets[0]._id; + await caClient.CMD.base.getAssetDetails(assetsId); + } + + const symbols = await caClient.CMD.meta.listAllSymbols().then(response => response.payload); // Duplicated in meta but needed for scenario + if (symbols && symbols.length) { + const symbolId = symbols[0]._id; + await caClient.CMD.base.getSymbolDetails(symbolId); + } +} + +module.exports = Base; diff --git a/tests/rest-apis/crypto-market-data/index.js b/tests/rest-apis/crypto-market-data/index.js index 239feae..1f67f72 100644 --- a/tests/rest-apis/crypto-market-data/index.js +++ b/tests/rest-apis/crypto-market-data/index.js @@ -1,3 +1,4 @@ +const Base = require('./base.test'); const Meta = require('./meta.test'); const OHLCV = require('./ohlcv.test'); const Trades = require('./trades.test'); @@ -5,6 +6,7 @@ const Trades = require('./trades.test'); async function CMD(caClient) { console.log('\n::Crypto market data'); + await Base(caClient); await Meta(caClient); await OHLCV(caClient); await Trades(caClient); diff --git a/tests/rest-apis/crypto-market-data/meta.test.js b/tests/rest-apis/crypto-market-data/meta.test.js index 8b520a1..6735da1 100644 --- a/tests/rest-apis/crypto-market-data/meta.test.js +++ b/tests/rest-apis/crypto-market-data/meta.test.js @@ -1,17 +1,9 @@ async function Meta(caClient) { console.log('\n::CMD Meta'); - const exchanges = await caClient.CMD.meta.listAllExchanges().then(response => response.payload); - const exchangeId = exchanges[0]._id; - await caClient.CMD.meta.getExchangeDetails(exchangeId); - - const assets = await caClient.CMD.meta.listAllAssets().then(response => response.payload); - const assetsId = assets[0]._id; - await caClient.CMD.meta.getAssetDetails(assetsId); - - const symbols = await caClient.CMD.meta.listAllSymbols().then(response => response.payload); - const symbolId = symbols[0]._id; - await caClient.CMD.meta.getSymbolDetails(symbolId); + await caClient.CMD.meta.listAllExchanges().then(response => response.payload); + await caClient.CMD.meta.listAllAssets().then(response => response.payload); + await caClient.CMD.meta.listAllSymbols().then(response => response.payload); } module.exports = Meta;