github.com/polygon-io/client-go@v1.16.4/rest/models/trades.go (about) 1 package models 2 3 import "time" 4 5 // ListTradesParams is the set of parameters for the ListTrades method. 6 type ListTradesParams struct { 7 // The ticker symbol to get trades for. 8 Ticker string `validate:"required" path:"ticker"` 9 10 // Query by timestamp. To query for a specific day instead of a nanosecond timestamp, 11 // set it via this pattern: params.WithDay(2006, 1, 2) // January 2, 2006. 12 TimestampEQ *Nanos `query:"timestamp"` 13 TimestampLT *Nanos `query:"timestamp.lt"` 14 TimestampLTE *Nanos `query:"timestamp.lte"` 15 TimestampGT *Nanos `query:"timestamp.gt"` 16 TimestampGTE *Nanos `query:"timestamp.gte"` 17 18 // Order results based on the sort field. 19 Order *Order `query:"order"` 20 21 // Limit the number of results returned, default is 10 and max is 50000. 22 Limit *int `query:"limit"` 23 24 // Sort field used for ordering. 25 Sort *Sort `query:"sort"` 26 } 27 28 func (p ListTradesParams) WithTimestamp(c Comparator, q Nanos) *ListTradesParams { 29 switch c { 30 case EQ: 31 p.TimestampEQ = &q 32 case LT: 33 p.TimestampLT = &q 34 case LTE: 35 p.TimestampLTE = &q 36 case GT: 37 p.TimestampGT = &q 38 case GTE: 39 p.TimestampGTE = &q 40 } 41 return &p 42 } 43 44 func (p ListTradesParams) WithDay(year int, month time.Month, day int) *ListTradesParams { 45 d := Nanos(time.Date(year, month, day, 0, 0, 0, 0, time.UTC)) 46 p.TimestampEQ = &d 47 return &p 48 } 49 50 func (p ListTradesParams) WithOrder(q Order) *ListTradesParams { 51 p.Order = &q 52 return &p 53 } 54 55 func (p ListTradesParams) WithLimit(q int) *ListTradesParams { 56 p.Limit = &q 57 return &p 58 } 59 60 func (p ListTradesParams) WithSort(q Sort) *ListTradesParams { 61 p.Sort = &q 62 return &p 63 } 64 65 // ListTradesResponse is the response returned by the ListTrades method. 66 type ListTradesResponse struct { 67 BaseResponse 68 Results []Trade `json:"results,omitempty"` 69 } 70 71 // GetLastTradeParams is the set of parameters for GetLastTrade method. 72 type GetLastTradeParams struct { 73 // The ticker symbol of the stock/equity. 74 Ticker string `validate:"required" path:"ticker"` 75 } 76 77 // GetLastTradeResponse is the response returned by the GetLastTradeResponse method. 78 type GetLastTradeResponse struct { 79 BaseResponse 80 Results LastTrade `json:"results,omitempty"` 81 } 82 83 // GetLastCryptoTradeParams is the set of parameters for the GetLastCryptoTrade method. 84 type GetLastCryptoTradeParams struct { 85 // The "from" symbol of the pair. 86 From string `validate:"required" path:"from"` 87 88 // The "to" symbol of the pair. 89 To string `validate:"required" path:"to"` 90 } 91 92 // GetLastCryptoTradeResponse is the response returned by the GetLastCryptoTrade method. 93 type GetLastCryptoTradeResponse struct { 94 BaseResponse 95 Symbol string `json:"symbol,omitempty"` 96 Last CryptoTrade `json:"last,omitempty"` 97 } 98 99 // Trade contains trade data for a specified ticker symbol. 100 type Trade struct { 101 Conditions []int32 `json:"conditions,omitempty"` 102 Correction int `json:"correction,omitempty"` 103 Exchange int `json:"exchange,omitempty"` 104 ID string `json:"id,omitempty"` 105 ParticipantTimestamp Nanos `json:"participant_timestamp,omitempty"` 106 Price float64 `json:"price,omitempty"` 107 SequenceNumber int64 `json:"sequence_number,omitempty"` 108 SipTimestamp Nanos `json:"sip_timestamp,omitempty"` 109 Size float64 `json:"size,omitempty"` 110 Tape int32 `json:"tape,omitempty"` 111 TrfID int `json:"trf_id,omitempty"` 112 TrfTimestamp Nanos `json:"trf_timestamp,omitempty"` 113 } 114 115 // LastTrade is the most recent trade for a specified ticker. 116 type LastTrade struct { 117 Ticker string `json:"T,omitempty"` 118 TRFTimestamp Nanos `json:"f,omitempty"` 119 SequenceNumber int64 `json:"q,omitempty"` 120 Timestamp Nanos `json:"t,omitempty"` 121 ParticipantTimestamp Nanos `json:"y,omitempty"` 122 Conditions []int32 `json:"c,omitempty"` 123 Correction uint32 `json:"e,omitempty"` 124 ID string `json:"i,omitempty"` 125 Price float64 `json:"p,omitempty"` 126 TRF int32 `json:"r,omitempty"` 127 Size float64 `json:"s,omitempty"` 128 Exchange int32 `json:"x,omitempty"` 129 Tape int32 `json:"z,omitempty"` 130 } 131 132 // CryptoTrade is a trade for a crypto pair. 133 type CryptoTrade struct { 134 Conditions []int `json:"conditions,omitempty"` 135 Exchange int `json:"exchange,omitempty"` 136 Price float64 `json:"price,omitempty"` 137 Size float64 `json:"size,omitempty"` 138 Timestamp Nanos `json:"timestamp,omitempty"` 139 }