Skip to content

Commit

Permalink
some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerfloyd committed Dec 2, 2019
1 parent a644ef6 commit a1c8c03
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
13 changes: 9 additions & 4 deletions lib/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -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};
});
}

Expand All @@ -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;
}
4 changes: 2 additions & 2 deletions lib/marketMetrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {},
Expand Down
2 changes: 1 addition & 1 deletion util/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

0 comments on commit a1c8c03

Please sign in to comment.