Two problems - Without specifying an interval for getHistory it defaults to monthly.
What this ends up doing is getting the open/close/high/low for a whole month of data, and presenting that as if it were the day we ask for.
Setting that to Daily fixes the issue, but also:
The first object in the collection is not reliably for the startDate we ask for, and the collection may not contain any entry for that date.
So, to that end, we filter for a match on the date, and only if there's nothing there do we use the first item in the collection.
Two problems - Without specifying an interval for
getHistory
it defaults to monthly. What this ends up doing is getting the open/close/high/low for a whole month of data, and presenting that as if it were the day we ask for. Setting that to Daily fixes the issue, but also: The first object in the collection is not reliably for thestartDate
we ask for, and the collection may not contain any entry for that date. So, to that end, we filter for a match on the date, and only if there's nothing there do we use the first item in the collection.