From 7ee7fc6dfe938ea3c1488deb6269422f3d1752d6 Mon Sep 17 00:00:00 2001 From: George Karagoulis Date: Wed, 16 Feb 2022 23:46:03 -0800 Subject: [PATCH] Aligned the "Minute" members of intraday and historical data points. They appear to both be used the same way, as a string field that tells us the minute of the data point in the time zone of the exchange. I also removed, rather than update, a helper function that attempts to get the time from the historical data point by combining the date and minute fields. The problem is that this results in the wrong time because the time objects are in UTC, so to do this right you'd need to know the time zone which the "minute" value is in. I think we should leave it up to the consumer to write their methods to convert times according to their special circumstances. --- client_test.go | 2 ++ historical.go | 54 +++++++++++++++++++------------------------------- 2 files changed, 22 insertions(+), 34 deletions(-) diff --git a/client_test.go b/client_test.go index e6d3558..027a208 100644 --- a/client_test.go +++ b/client_test.go @@ -498,6 +498,7 @@ func TestHistoricalPrices(t *testing.T) { "key": "AAPL", "subkey": "12345", "date": "2021-12-03", + "minute": "9:30", "uOpen": 164.02, "uClose": 161.84, "uHigh": 164.96, @@ -521,6 +522,7 @@ func TestHistoricalPrices(t *testing.T) { Key: "AAPL", Subkey: "12345", Date: Date(time.Date(2021, 12, 3, 0, 0, 0, 0, time.UTC)), + Minute: HourMinute(9*time.Hour + 30*time.Minute), UOpen: 164.02, UClose: 161.84, UHigh: 164.96, diff --git a/historical.go b/historical.go index 1eee710..8509915 100644 --- a/historical.go +++ b/historical.go @@ -6,7 +6,6 @@ package iex import ( - "fmt" "time" ) @@ -112,39 +111,26 @@ type IntradayHistoricalOptions struct { // HistoricalDataPoint Represents a single historical data point for a stock type HistoricalDataPoint struct { - Close float64 `json:"close"` - High float64 `json:"high"` - Low float64 `json:"low"` - Open float64 `json:"open"` - Symbol string `json:"symbol"` - Volume float64 `json:"volume"` - ID string `json:"id"` - Key string `json:"key"` - Subkey string `json:"subkey"` - Date Date `json:"date"` - Minute string `json:"minute"` - UOpen float64 `json:"uOpen"` - UClose float64 `json:"uClose"` - UHigh float64 `json:"uHigh"` - ULow float64 `json:"uLow"` - UVolume int `json:"uVolume"` - Change float64 `json:"change"` - ChangePercent float64 `json:"changePercent"` - Label string `json:"label"` - ChangeOverTime float64 `json:"changeOverTime"` -} - -// Time merges HistoricalDataPoint's Date and Mintue field and -// get the exact time. Useful for "5dm" and "1mm" time frames -func (p HistoricalDataPoint) Time() time.Time { - if p.Minute == "" { - return time.Time(p.Date) - } - - layout := "2006-01-02 15:04" - dateStr := fmt.Sprintf("%s %s", p.Date.String(), p.Minute) - t, _ := time.Parse(layout, dateStr) - return t + Close float64 `json:"close"` + High float64 `json:"high"` + Low float64 `json:"low"` + Open float64 `json:"open"` + Symbol string `json:"symbol"` + Volume float64 `json:"volume"` + ID string `json:"id"` + Key string `json:"key"` + Subkey string `json:"subkey"` + Date Date `json:"date"` + Minute HourMinute `json:"minute"` + UOpen float64 `json:"uOpen"` + UClose float64 `json:"uClose"` + UHigh float64 `json:"uHigh"` + ULow float64 `json:"uLow"` + UVolume int `json:"uVolume"` + Change float64 `json:"change"` + ChangePercent float64 `json:"changePercent"` + Label string `json:"label"` + ChangeOverTime float64 `json:"changeOverTime"` } // IntradayOptions optional query params to pass to intraday endpoint