Skip to content
Closed
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
21 changes: 11 additions & 10 deletions rest/models/aggs.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,17 @@ func (p GetDailyOpenCloseAggParams) WithAdjusted(q bool) *GetDailyOpenCloseAggPa
// GetDailyOpenCloseAggResponse is the response for the GetDailyOpenCloseAgg method.
type GetDailyOpenCloseAggResponse struct {
BaseResponse
Symbol string `json:"symbol,omitempty"`
From string `json:"from,omitempty"`
Open float64 `json:"open,omitempty"`
High float64 `json:"high,omitempty"`
Low float64 `json:"low,omitempty"`
Close float64 `json:"close,omitempty"`
Volume float64 `json:"volume,omitempty"`
AfterHours float64 `json:"afterHours,omitempty"`
PreMarket float64 `json:"preMarket,omitempty"`
OTC bool `json:"otc,omitempty"`
Symbol string `json:"symbol,omitempty"`
From string `json:"from,omitempty"`
Open float64 `json:"open,omitempty"`
High float64 `json:"high,omitempty"`
Low float64 `json:"low,omitempty"`
Close float64 `json:"close,omitempty"`
Volume float64 `json:"volume,omitempty"`
DecimalVolume DecimalVolume `json:"decimal_volume,omitempty"`
AfterHours float64 `json:"afterHours,omitempty"`
PreMarket float64 `json:"preMarket,omitempty"`
OTC bool `json:"otc,omitempty"`
}

// GetPreviousCloseAggParams is the set of parameters for the GetPreviousCloseAgg method.
Expand Down
15 changes: 15 additions & 0 deletions rest/models/decimal_volume.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package models

import (
"strconv"
)

type DecimalVolume string

func (dv DecimalVolume) Float64() (float64, error) {
return strconv.ParseFloat(string(dv), 64)
}

func (dv DecimalVolume) String() string {
return string(dv)
}
44 changes: 44 additions & 0 deletions rest/models/decimal_volume_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package models

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestDecimalVolume_Float64(t *testing.T) {
tests := []struct {
name string
dv DecimalVolume
want float64
wantErr assert.ErrorAssertionFunc
}{
{"dv 2.5", DecimalVolume("2.5"), 2.5, assert.NoError},
{"dv invalid", DecimalVolume("2.b"), 0, assert.Error},
{"dv high precision", DecimalVolume("2.323233223223223223322"), 2.323233223223223, assert.NoError},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := tt.dv.Float64()
if !tt.wantErr(t, err, "Float64()") {
return
}
assert.Equalf(t, tt.want, got, "Float64()")
})
}
}

func TestDecimalVolume_String(t *testing.T) {
tests := []struct {
name string
dv DecimalVolume
want string
}{
{"dv 2.5", DecimalVolume("2.5"), "2.5"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.dv.String(), "String()")
})
}
}
31 changes: 17 additions & 14 deletions rest/models/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,9 @@ type SnapshotLastMinute struct {
Transactions int64 `json:"transactions,omitempty"`
Open float64 `json:"open,omitempty"`
Volume float64 `json:"volume,omitempty"`
VWAP float64 `json:"vwap,omitempty"`
LastUpdated int64 `json:"last_updated,omitempty"`
//TODO: check if this need a decimal_volume
VWAP float64 `json:"vwap,omitempty"`
LastUpdated int64 `json:"last_updated,omitempty"`
}

// SnapshotLastQuote contains all the information that might come back in the last_quote attribute of a SnapshotResponse.
Expand All @@ -509,15 +510,16 @@ type SnapshotLastQuote struct {

// SnapshotLastTrade contains all the information that might come back in the last_trade attribute of a SnapshotResponse.
type SnapshotLastTrade struct {
Timestamp int64 `json:"sip_timestamp,omitempty"`
ParticipantTimestamp int64 `json:"participant_timestamp,omitempty"`
Conditions []int32 `json:"conditions,omitempty"`
Price float64 `json:"price,omitempty"`
Size uint32 `json:"size,omitempty"`
Exchange int32 `json:"exchange,omitempty"`
Timeframe string `json:"timeframe,omitempty"`
ID string `json:"id,omitempty"`
LastUpdated int64 `json:"last_updated,omitempty"`
Timestamp int64 `json:"sip_timestamp,omitempty"`
ParticipantTimestamp int64 `json:"participant_timestamp,omitempty"`
Conditions []int32 `json:"conditions,omitempty"`
Price float64 `json:"price,omitempty"`
Size uint32 `json:"size,omitempty"`
DecimalSize DecimalVolume `json:"decimal_size,omitempty"`
Exchange int32 `json:"exchange,omitempty"`
Timeframe string `json:"timeframe,omitempty"`
ID string `json:"id,omitempty"`
LastUpdated int64 `json:"last_updated,omitempty"`
}

// Session contains all the information that might come back in the Session attribute of a SnapshotResponseModel or SummaryResult.
Expand All @@ -536,9 +538,10 @@ type Session struct {
Open float64 `json:"open,omitempty"`
PreviousClose float64 `json:"previous_close,omitempty"`
Volume float64 `json:"volume,omitempty"`
Price float64 `json:"price,omitempty"`
LastUpdated int64 `json:"last_updated,omitempty"`
VWAP float64 `json:"vwap,omitempty"`
//TODO: check if this need a decimal volume
Price float64 `json:"price,omitempty"`
LastUpdated int64 `json:"last_updated,omitempty"`
VWAP float64 `json:"vwap,omitempty"`
}

// Details contains all the information that might come back in the details attribute of a SnapshotResponse.
Expand Down
25 changes: 13 additions & 12 deletions rest/models/trades.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,19 @@ type GetLastCryptoTradeResponse struct {

// Trade contains trade data for a specified ticker symbol.
type Trade struct {
Conditions []int32 `json:"conditions,omitempty"`
Correction int `json:"correction,omitempty"`
Exchange int `json:"exchange,omitempty"`
ID string `json:"id,omitempty"`
ParticipantTimestamp Nanos `json:"participant_timestamp,omitempty"`
Price float64 `json:"price,omitempty"`
SequenceNumber int64 `json:"sequence_number,omitempty"`
SipTimestamp Nanos `json:"sip_timestamp,omitempty"`
Size float64 `json:"size,omitempty"`
Tape int32 `json:"tape,omitempty"`
TrfID int `json:"trf_id,omitempty"`
TrfTimestamp Nanos `json:"trf_timestamp,omitempty"`
Conditions []int32 `json:"conditions,omitempty"`
Correction int `json:"correction,omitempty"`
Exchange int `json:"exchange,omitempty"`
ID string `json:"id,omitempty"`
ParticipantTimestamp Nanos `json:"participant_timestamp,omitempty"`
Price float64 `json:"price,omitempty"`
SequenceNumber int64 `json:"sequence_number,omitempty"`
SipTimestamp Nanos `json:"sip_timestamp,omitempty"`
Size float64 `json:"size,omitempty"`
DecimalSize DecimalVolume `json:"decimal_size,omitempty"`
Tape int32 `json:"tape,omitempty"`
TrfID int `json:"trf_id,omitempty"`
TrfTimestamp Nanos `json:"trf_timestamp,omitempty"`
}

// LastTrade is the most recent trade for a specified ticker.
Expand Down
2 changes: 2 additions & 0 deletions rest/trades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestListTrades(t *testing.T) {
"sequence_number": 1063,
"sip_timestamp": 1517562000016036600,
"size": 100,
"decimal_size": "100.0",
"tape": 3
}`

Expand All @@ -45,6 +46,7 @@ func TestListTrades(t *testing.T) {
"sequence_number": 1064,
"sip_timestamp": 1517562000016038100,
"size": 100,
"decimal_size": "100.233456",
"tape": 3
}`

Expand Down
Loading