Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend the calendar day with session and settlement info #268

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions alpaca/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Comment on lines +181 to +182
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't like to add the session open/close fields here as they were exposed to the API unintentionally and there is no good use for them either as they don't really mean much as far as trading goes.

We can't remove it from the API response as that would be a breaking change, but at least we avoid adding it here to avoid more breaking changes in future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add this comment to the original issue: #266?

SettlementDate string `json:"settlement_date"`
}

//easyjson:json
Expand Down
23 changes: 22 additions & 1 deletion alpaca/entities_easyjson.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 22 additions & 11 deletions alpaca/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading