Skip to content

Commit

Permalink
Fixed Market.js to account for non-trading days
Browse files Browse the repository at this point in the history
  • Loading branch information
torreyleonard committed Mar 21, 2019
1 parent 24617d0 commit 7f3f89e
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions objects/broker/robinhood/Market.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class Market extends Robinhood {
this.parseHours = function(object) {
return {
isOpen: Boolean(object.is_open),
close: new Date(object.closes_at),
open: new Date(object.opens_at),
extendedOpen: new Date(object.extended_opens_at),
extendedClose: new Date(object.extended_closes_at),
close: object.closes_at === null ? null : new Date(object.closes_at),
open: object.opens_at === null ? null : new Date(object.opens_at),
extendedOpen: object.extended_opens_at === null ? null : new Date(object.extended_opens_at),
extendedClose: object.extended_closes_at === null ? null : new Date(object.extended_closes_at),
date: new Date(object.date),
nextTradingDay: String(object.next_open_hours),
previousTradingDay: String(object.previous_open_hours)
Expand Down Expand Up @@ -171,19 +171,17 @@ class Market extends Robinhood {
const _this = this;
return new Promise((resolve, reject) => {
let next = null;
let days = _this.isOpenToday() ? 1 : 0;
let days = moment().isAfter(_this.getOpen()) ? 1 : 0;
async.whilst(
() => { return next === null; },
callback => {
let newDate = moment().add(days, 'days');
_this.getHoursOn(newDate.toDate()).then(hours => {
if (hours.isOpen) next = hours.open;
callback();
})
},
error => {
if (error) reject(error);
else resolve(next);
}).catch(error => reject(new LibraryError(error)));
}, () => {
resolve(next);
})
})
}
Expand Down

0 comments on commit 7f3f89e

Please sign in to comment.