From a205ba7f4b6952aff1e3e43362018d7cc257f3fb Mon Sep 17 00:00:00 2001 From: Gergely Novak Date: Wed, 6 Dec 2023 08:12:42 +0100 Subject: [PATCH] Extend the calendar day with session and settlement info --- alpaca/entities.go | 9 ++++++--- alpaca/entities_easyjson.go | 23 ++++++++++++++++++++++- alpaca/rest_test.go | 33 ++++++++++++++++++++++----------- 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/alpaca/entities.go b/alpaca/entities.go index 2a3a60a..f5c6697 100644 --- a/alpaca/entities.go +++ b/alpaca/entities.go @@ -175,9 +175,12 @@ type Fundamental struct { } type CalendarDay struct { - Date string `json:"date"` - Open string `json:"open"` - Close string `json:"close"` + Date string `json:"date"` + Open string `json:"open"` + Close string `json:"close"` + SessionOpen string `json:"session_open"` + SessionClose string `json:"session_close"` + SettlementDate string `json:"settlement_date"` } //easyjson:json diff --git a/alpaca/entities_easyjson.go b/alpaca/entities_easyjson.go index b03ded3..593239b 100644 --- a/alpaca/entities_easyjson.go +++ b/alpaca/entities_easyjson.go @@ -226,7 +226,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca3(in *jlexer in.Delim('[') if *out == nil { if !in.IsDelim(']') { - *out = make(calendarDaySlice, 0, 1) + *out = make(calendarDaySlice, 0, 0) } else { *out = calendarDaySlice{} } @@ -2476,6 +2476,12 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca17(in *jlexe out.Open = string(in.String()) case "close": out.Close = string(in.String()) + case "session_open": + out.SessionOpen = string(in.String()) + case "session_close": + out.SessionClose = string(in.String()) + case "settlement_date": + out.SettlementDate = string(in.String()) default: in.SkipRecursive() } @@ -2505,6 +2511,21 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca17(out *jwri out.RawString(prefix) out.String(string(in.Close)) } + { + const prefix string = ",\"session_open\":" + out.RawString(prefix) + out.String(string(in.SessionOpen)) + } + { + const prefix string = ",\"session_close\":" + out.RawString(prefix) + out.String(string(in.SessionClose)) + } + { + const prefix string = ",\"settlement_date\":" + out.RawString(prefix) + out.String(string(in.SettlementDate)) + } out.RawByte('}') } diff --git a/alpaca/rest_test.go b/alpaca/rest_test.go index c38facb..0aae352 100644 --- a/alpaca/rest_test.go +++ b/alpaca/rest_test.go @@ -235,26 +235,37 @@ func TestGetCalendar(t *testing.T) { c := DefaultClient // successful c.do = func(c *Client, req *http.Request) (*http.Response, error) { - assert.Equal(t, "2018-01-01", req.URL.Query().Get("start")) - assert.Equal(t, "2018-01-02", req.URL.Query().Get("end")) - calendar := []CalendarDay{ + assert.Equal(t, "2023-01-01", req.URL.Query().Get("start")) + assert.Equal(t, "2023-01-03", req.URL.Query().Get("end")) + jsonResp := `[ { - Date: "2018-01-01", - Open: time.Now().Format(time.RFC3339), - Close: time.Now().Format(time.RFC3339), - }, - } + "date": "2023-01-03", + "open": "09:30", + "close": "16:00", + "session_open": "0400", + "session_close": "2000", + "settlement_date": "2023-01-05" + } + ]` return &http.Response{ - Body: genBody(calendar), + Body: nopCloser{strings.NewReader(jsonResp)}, }, nil } calendar, err := c.GetCalendar(GetCalendarRequest{ - Start: time.Date(2018, 1, 1, 0, 0, 0, 0, time.UTC), - End: time.Date(2018, 1, 2, 0, 0, 0, 0, time.UTC), + Start: time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC), + End: time.Date(2023, 1, 3, 0, 0, 0, 0, time.UTC), }) require.NoError(t, err) assert.Len(t, calendar, 1) + assert.Equal(t, CalendarDay{ + Date: "2023-01-03", + Open: "09:30", + Close: "16:00", + SessionOpen: "0400", + SessionClose: "2000", + SettlementDate: "2023-01-05", + }, calendar[0]) // api failure c.do = func(c *Client, req *http.Request) (*http.Response, error) {