Skip to content

Commit

Permalink
Add delayed sip feed (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnvk authored Jan 28, 2025
1 parent dbaa6de commit 31c0f29
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
12 changes: 9 additions & 3 deletions marketdata/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const (
IEX Feed = "iex"
// OTC includes Over-the-Counter exchanges
OTC Feed = "otc"
// DelayedSIP is 15-minute delayed SIP. It can only be used in the latest
// endpoints and on the stream. For historical endpoints you can simply
// use sip and set the end parameter to 15 minutes ago, or leave it empty.
DelayedSIP Feed = "delayed_sip"
)

// CryptoFeed defines the source feed of crypto data.
Expand Down Expand Up @@ -209,9 +213,11 @@ type CryptoSnapshot struct {
PrevDailyBar *CryptoBar `json:"prevDailyBar"`
}

type CryptoPerpTrade CryptoTrade
type CryptoPerpQuote CryptoQuote
type CryptoPerpBar CryptoBar
type (
CryptoPerpTrade CryptoTrade
CryptoPerpQuote CryptoQuote
CryptoPerpBar CryptoBar
)

type CryptoPerpPricing struct {
IndexPrice float64 `json:"ip"`
Expand Down
13 changes: 5 additions & 8 deletions marketdata/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func mockErrResp() func(_ *Client, _ *http.Request) (*http.Response, error) {

func TestGetTrades_Gzip(t *testing.T) {
c := NewClient(ClientOpts{
Feed: "sip",
Feed: SIP,
})

f, err := os.Open("testdata/trades.json.gz")
Expand Down Expand Up @@ -172,11 +172,11 @@ func TestGetTrades(t *testing.T) {

func TestGetTrades_Currency(t *testing.T) {
c := NewClient(ClientOpts{
Feed: "sip",
Feed: DelayedSIP,
Currency: "JPY",
})
c.do = func(_ *Client, req *http.Request) (*http.Response, error) {
assert.Equal(t, "sip", req.URL.Query().Get("feed"))
assert.Equal(t, "delayed_sip", req.URL.Query().Get("feed"))
assert.Equal(t, "JPY", req.URL.Query().Get("currency"))
resp := `{"trades":{"AAPL":[{"t":"2021-10-13T08:00:00.08960768Z","x":"P","p":15922.93,"s":595,"c":["@","T"],"i":1,"z":"C"}]},"currency":"JPY","next_page_token":"QUFQTHwyMDIxLTEwLTEzVDA4OjAwOjAwLjA4OTYwNzY4MFp8UHwwOTIyMzM3MjAzNjg1NDc3NTgwOQ=="}`
return &http.Response{
Expand All @@ -195,7 +195,6 @@ func TestGetTrades_Currency(t *testing.T) {

c.do = func(_ *Client, req *http.Request) (*http.Response, error) {
resp := `{"trades":{},"currency":"MXN","next_page_token":null}`
assert.Equal(t, "sip", req.URL.Query().Get("feed"))
assert.Equal(t, "MXN", req.URL.Query().Get("currency"))
return &http.Response{
Body: io.NopCloser(strings.NewReader(resp)),
Expand Down Expand Up @@ -455,7 +454,7 @@ func TestGetBars(t *testing.T) {
Adjustment: Split,
Start: time.Date(2021, 10, 15, 16, 0, 0, 0, time.UTC),
End: time.Date(2021, 10, 15, 17, 0, 0, 0, time.UTC),
Feed: "sip",
Feed: SIP,
})
require.NoError(t, err)
require.Len(t, got, 5)
Expand Down Expand Up @@ -571,9 +570,7 @@ func TestLatestBar_Feed(t *testing.T) {
)),
}, nil
}
_, err = c.GetLatestBar("AAPL", GetLatestBarRequest{
Feed: "sip",
})
_, err = c.GetLatestBar("AAPL", GetLatestBarRequest{Feed: SIP})
require.NoError(t, err)
}

Expand Down

0 comments on commit 31c0f29

Please sign in to comment.