UNPKG

fme-poloniex

Version:

API for fetching data from the Poloniex API

61 lines (60 loc) 2.95 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const fme_logger_1 = require("fme-logger"); var L = new fme_logger_1.Log("poloniex"); const _m = require("moment-timezone"); const fme_quotes_models_1 = require("fme-quotes-models"); const Poloniex = require("poloniex-api-node"); class PoloniexQuotes { constructor() { this.version = "1.0.0"; this.getQuotes = (symbol, minutes = 5, startTime = _m().startOf("day").toDate(), endTime = _m().toDate()) => __awaiter(this, void 0, void 0, function* () { var seconds = minutes * 60; var start = _m(startTime).unix(); var end = _m(endTime).unix(); var pQuotes = []; L.debug("Calling poloniex for chartdate with data", symbol, seconds, start, end); try { pQuotes = (yield this.poloniex.returnChartData(symbol, seconds, start, end)); } catch (err) { L.error("GetQuotes returend error", err, symbol, minutes, startTime, endTime); } L.debug("returnChartDate returned", pQuotes.length); var fQuotes = []; for (var i in pQuotes) { fQuotes.push(this.convert(symbol, minutes, pQuotes[i])); } return fQuotes; }); this.convert = (symbol, minutes, pQuote) => { var fQuote = new fme_quotes_models_1.FmeQuote(); fQuote.YYYYMMDD = _m.unix(pQuote.date).format("YYYYMMDD"); fQuote.timeHHMM = _m.unix(pQuote.date).format("HHmm"); fQuote.time = _m.unix(pQuote.date).hours() * 60 + _m(pQuote.date).minutes(); fQuote.timestamp = _m.unix(pQuote.date).toDate(); fQuote.symbol = symbol; fQuote.open = pQuote.open; fQuote.high = pQuote.high; fQuote.low = pQuote.low; fQuote.close = pQuote.close; fQuote.avg = pQuote.weightedAverage; fQuote.volume = pQuote.volume; fQuote.source = "Poloniex"; fQuote.decimalPoints = 2; fQuote.interval = minutes; fQuote.type = "minutes"; return fQuote; }; this.poloniex = new Poloniex(); } } exports.PoloniexQuotes = PoloniexQuotes;