From a1c8c03b7e7228cb2a29b97f282c3ce95e24335c Mon Sep 17 00:00:00 2001 From: Tyler Date: Sun, 1 Dec 2019 20:20:39 -0700 Subject: [PATCH] some cleanup --- lib/history.js | 13 +++++++++---- lib/marketMetrics.js | 4 ++-- package.json | 2 +- util/endpoints.js | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/history.js b/lib/history.js index 996704b..8c0f4f8 100644 --- a/lib/history.js +++ b/lib/history.js @@ -38,7 +38,7 @@ const doRequest = (headers, endpoint, start_date, end_date, pageOffset) => { return { items, pagination }; }) .catch(err => { - return err.message; + return {message: err.message, status: err.status}; }); } @@ -47,10 +47,15 @@ module.exports = async (headers, account_id, start_date, end_date) => { const items = []; let currentPage = -1; let keepGoing = true; - while (keepGoing) { // run through pagination + while (keepGoing) { const r = await doRequest(headers, endpoint, start_date, end_date, ++currentPage); - items.push.apply(items, r.items); - keepGoing = currentPage < r.pagination['total-pages'] - 1; + + if(r && !!r.message && r.status !=200){ + keepGoing = false; + } else { + items.push.apply(items, r.items); + keepGoing = currentPage < r.pagination['total-pages'] - 1; + } } return items; } diff --git a/lib/marketMetrics.js b/lib/marketMetrics.js index 357b42a..87d022f 100644 --- a/lib/marketMetrics.js +++ b/lib/marketMetrics.js @@ -11,8 +11,8 @@ const request = require('superagent'); const endpoints = require('../util/endpoints'); -module.exports = (headers, account_id, tickers) => { - const endpoint = endpoints['marketMetrics'](account_id, tickers); +module.exports = (headers, tickers) => { + const endpoint = endpoints['marketMetrics'](tickers); return request .get(`${endpoint}`) .set(headers) diff --git a/package.json b/package.json index 8045037..d81c1ed 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tasty-works-api", - "version": "0.3.0", + "version": "0.4.0", "description": "NodeJS API wrapper for Tastyworks API", "main": "index.js", "scripts": {}, diff --git a/util/endpoints.js b/util/endpoints.js index b723aec..12ba2d2 100644 --- a/util/endpoints.js +++ b/util/endpoints.js @@ -13,6 +13,6 @@ module.exports = { streamer: () => `${baseURL}/quote-streamer-tokens`, optionChain: (ticker) => `${baseURL}/option-chains/${ticker}/nested`, history: (account_id) => `${baseURL}/accounts/${account_id}/transactions`, - marketMetrics: (account_id, tickers) => `${baseURL}/market-metrics?symbols=${tickers}` + marketMetrics: (tickers) => `${baseURL}/market-metrics?symbols=${tickers}` // TODO: '{url}/dry-run' }