UNPKG

tardis-dev

Version:

Convenient access to tick-level historical and real-time cryptocurrency market data via Node.js

49 lines 1.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getInstrumentInfo = getInstrumentInfo; const options_1 = require("./options"); const handy_1 = require("./handy"); async function getInstrumentInfo(exchange, filterOrSymbol) { if (Array.isArray(exchange)) { const exchanges = exchange; const results = await Promise.all(exchanges.map((e) => getInstrumentInfoForExchange(e, filterOrSymbol))); return results.flat(); } else { return getInstrumentInfoForExchange(exchange, filterOrSymbol); } } async function getInstrumentInfoForExchange(exchange, filterOrSymbol) { const options = (0, options_1.getOptions)(); let url = `${options.endpoint}/instruments/${exchange}`; if (typeof filterOrSymbol === 'string') { url += `/${filterOrSymbol}`; } else if (typeof filterOrSymbol === 'object') { url += `?filter=${encodeURIComponent(JSON.stringify(filterOrSymbol))}`; } try { return await handy_1.httpClient .get(url, { headers: { Authorization: `Bearer ${options.apiKey}` } }) .json(); } catch (e) { // expose 400 error message from server if (e.response?.statusCode === 400) { let err; try { err = JSON.parse(e.response.body); } catch { throw e; } throw err ? new Error(`${err.message} (${err.code})`) : e; } else { throw e; } } } //# sourceMappingURL=instrumentinfo.js.map