diff --git a/rest/models/aggs.go b/rest/models/aggs.go index 4780c058..fd227bc5 100644 --- a/rest/models/aggs.go +++ b/rest/models/aggs.go @@ -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. diff --git a/rest/models/decimal_volume.go b/rest/models/decimal_volume.go new file mode 100644 index 00000000..eeefc17d --- /dev/null +++ b/rest/models/decimal_volume.go @@ -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) +} diff --git a/rest/models/decimal_volume_test.go b/rest/models/decimal_volume_test.go new file mode 100644 index 00000000..d23bee39 --- /dev/null +++ b/rest/models/decimal_volume_test.go @@ -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()") + }) + } +} diff --git a/rest/models/snapshot.go b/rest/models/snapshot.go index 12ee4d22..b23cf780 100644 --- a/rest/models/snapshot.go +++ b/rest/models/snapshot.go @@ -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. @@ -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. @@ -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. diff --git a/rest/models/trades.go b/rest/models/trades.go index 84d6267c..9bb61f0f 100644 --- a/rest/models/trades.go +++ b/rest/models/trades.go @@ -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. diff --git a/rest/trades_test.go b/rest/trades_test.go index 45737e0f..e6299f1e 100644 --- a/rest/trades_test.go +++ b/rest/trades_test.go @@ -30,6 +30,7 @@ func TestListTrades(t *testing.T) { "sequence_number": 1063, "sip_timestamp": 1517562000016036600, "size": 100, + "decimal_size": "100.0", "tape": 3 }` @@ -45,6 +46,7 @@ func TestListTrades(t *testing.T) { "sequence_number": 1064, "sip_timestamp": 1517562000016038100, "size": 100, + "decimal_size": "100.233456", "tape": 3 }`