github.com/polygon-io/client-go@v1.16.4/rest/models/snapshot.go (about) 1 package models 2 3 import ( 4 "strings" 5 ) 6 7 // GetAllTickersSnapshotParams is the set of parameters for the GetAllTickersSnapshot method. 8 type GetAllTickersSnapshotParams struct { 9 // The locale of the market. 10 Locale MarketLocale `validate:"required" path:"locale"` 11 12 // The type of market to query. 13 MarketType MarketType `validate:"required" path:"marketType"` 14 15 // A comma separated list of tickers to get snapshots for. 16 Tickers *string `query:"tickers"` 17 18 // Include OTC securities in the response. Default is false (don't include OTC securities). 19 IncludeOTC *bool `query:"include_otc"` 20 } 21 22 func (p GetAllTickersSnapshotParams) WithTickers(q string) *GetAllTickersSnapshotParams { 23 p.Tickers = &q 24 return &p 25 } 26 27 func (p GetAllTickersSnapshotParams) WithIncludeOTC(q bool) *GetAllTickersSnapshotParams { 28 p.IncludeOTC = &q 29 return &p 30 } 31 32 // GetAllTickersSnapshotResponse is the response returned by the GetAllTickersSnapshot method. 33 type GetAllTickersSnapshotResponse struct { 34 BaseResponse 35 Tickers []TickerSnapshot `json:"tickers,omitempty"` 36 } 37 38 // GetTickerSnapshotParams is the set of parameters for the GetTickerSnapshot method. 39 type GetTickerSnapshotParams struct { 40 // The locale of the market. 41 Locale MarketLocale `validate:"required" path:"locale"` 42 43 // The type of market to query. 44 MarketType MarketType `validate:"required" path:"marketType"` 45 46 // The ticker symbol of the stock/equity. 47 Ticker string `validate:"required" path:"ticker"` 48 } 49 50 // GetTickerSnapshotResponse is the response returned by the GetTickerSnapshot method. 51 type GetTickerSnapshotResponse struct { 52 BaseResponse 53 Snapshot TickerSnapshot `json:"ticker,omitempty"` 54 } 55 56 // GetGainersLosersSnapshotParams is the set of parameters for the GetGainersLosersSnapshot method. 57 type GetGainersLosersSnapshotParams struct { 58 // The locale of the market. 59 Locale MarketLocale `validate:"required" path:"locale"` 60 61 // The type of market to query. 62 MarketType MarketType `validate:"required" path:"marketType"` 63 64 // The direction of the snapshot results to return. 65 Direction Direction `validate:"required" path:"direction"` 66 67 // Include OTC securities in the response. Default is false (don't include OTC securities). 68 IncludeOTC *bool `query:"include_otc"` 69 } 70 71 func (p GetGainersLosersSnapshotParams) WithIncludeOTC(q bool) *GetGainersLosersSnapshotParams { 72 p.IncludeOTC = &q 73 return &p 74 } 75 76 // ListOptionsChainParams is a set of parameters for the ListOptionsChainSnapshot method. 77 type ListOptionsChainParams struct { 78 // The underlying ticker symbol of the option contract. 79 UnderlyingAsset string `validate:"required" path:"underlyingAsset"` 80 81 // The strike price of the option contract. 82 StrikePrice *float64 `query:"strike_price"` 83 84 // The type of contract. Can be ContractCall, ContractPut, or in some rare cases, ContractOther. 85 ContractType *ContractType `query:"contract_type"` 86 87 // The contract's expiration date in YYYY-MM-DD format. 88 ExpirationDateEQ *Date `query:"expiration_date"` 89 ExpirationDateLT *Date `query:"expiration_date.lt"` 90 ExpirationDateLTE *Date `query:"expiration_date.lte"` 91 ExpirationDateGT *Date `query:"expiration_date.gt"` 92 ExpirationDateGTE *Date `query:"expiration_date.gte"` 93 94 // Limit the number of results returned, default is 10 and max is 1000. 95 Limit *int `query:"limit"` 96 97 // Sort field used for ordering. 98 Sort *Sort `query:"sort"` 99 100 // Order results based on the sort field. 101 Order *Order `query:"order"` 102 } 103 104 // WithStrikePrice sets strike price to params. Strike Price is the price at which a put or call option can be exercised. 105 func (o ListOptionsChainParams) WithStrikePrice(strikePrice float64) *ListOptionsChainParams { 106 o.StrikePrice = &strikePrice 107 return &o 108 } 109 110 // WithContractType sets contract type to params. 111 // contractType options include ContractCall and ContractPut. 112 func (o ListOptionsChainParams) WithContractType(contractType ContractType) *ListOptionsChainParams { 113 o.ContractType = &contractType 114 return &o 115 } 116 117 // WithLimit sets number of results returned. Limit default is 10. Limit must fall in range of 0-1000. 118 func (o ListOptionsChainParams) WithLimit(limit int) *ListOptionsChainParams { 119 o.Limit = &limit 120 return &o 121 } 122 123 // WithExpirationDate sets expiration_date query parameter. 124 // comparator options include EQ, LT, LTE, GT, and GTE. 125 // expirationDate should be in YYYY-MM-DD format 126 func (o ListOptionsChainParams) WithExpirationDate(comparator Comparator, expirationDate Date) *ListOptionsChainParams { 127 switch comparator { 128 case EQ: 129 o.ExpirationDateEQ = &expirationDate 130 case LT: 131 o.ExpirationDateLT = &expirationDate 132 case LTE: 133 o.ExpirationDateLTE = &expirationDate 134 case GT: 135 o.ExpirationDateGT = &expirationDate 136 case GTE: 137 o.ExpirationDateGTE = &expirationDate 138 default: 139 o.ExpirationDateEQ = &expirationDate 140 } 141 return &o 142 } 143 144 // WithOrder sets order of results based on the Sort field. 145 func (o ListOptionsChainParams) WithOrder(order Order) *ListOptionsChainParams { 146 o.Order = &order 147 return &o 148 } 149 150 // WithSort sets sort field. Sort expects to receive TickerSymbol, ExpirationDate, or StrikePrice as an argument. 151 func (o ListOptionsChainParams) WithSort(sort Sort) *ListOptionsChainParams { 152 switch sort { 153 case TickerSymbol: 154 o.Sort = &sort 155 case ExpirationDate: 156 o.Sort = &sort 157 case StrikePrice: 158 o.Sort = &sort 159 } 160 return &o 161 } 162 163 type ListOptionsChainSnapshotResponse struct { 164 BaseResponse 165 Results []OptionContractSnapshot `json:"results,omitempty"` 166 } 167 168 // GetGainersLosersSnapshotResponse is the response returned by the GetGainersLosersSnapshot method. 169 type GetGainersLosersSnapshotResponse struct { 170 BaseResponse 171 Tickers []TickerSnapshot `json:"tickers,omitempty"` 172 } 173 174 // GetOptionContractSnapshotParams is the set of parameters for the GetOptionContractSnapshot method. 175 type GetOptionContractSnapshotParams struct { 176 UnderlyingAsset string `validate:"required" path:"underlyingAsset"` 177 OptionContract string `validate:"required" path:"optionContract"` 178 } 179 180 // GetOptionContractSnapshotResponse is the response returned by the GetOptionContractSnapshot method. 181 type GetOptionContractSnapshotResponse struct { 182 BaseResponse 183 Results OptionContractSnapshot `json:"results,omitempty"` 184 } 185 186 // GetCryptoFullBookSnapshotParams is the set of parameters for the GetCryptoFullBookSnapshot method. 187 type GetCryptoFullBookSnapshotParams struct { 188 Ticker string `validate:"required" path:"ticker"` 189 } 190 191 // GetCryptoFullBookSnapshotResponse is the response returned by the GetCryptoFullBookSnapshot method. 192 type GetCryptoFullBookSnapshotResponse struct { 193 BaseResponse 194 Data FullBookSnapshot `json:"data,omitempty"` 195 } 196 197 // GetIndicesSnapshotParams is the set of parameters for the GetIndicesSnapshot method. 198 type GetIndicesSnapshotParams struct { 199 // The ticker list to get summaries for 200 TickerAnyOf *string `query:"ticker.any_of"` 201 } 202 203 func (p GetIndicesSnapshotParams) WithTickerAnyOf(tickers ...string) *GetIndicesSnapshotParams { 204 q := strings.Join(tickers, ",") 205 p.TickerAnyOf = &q 206 return &p 207 } 208 209 // GetIndicesSnapshotResponse is the response returned by the GetIndicesSnapshot method. 210 type GetIndicesSnapshotResponse struct { 211 BaseResponse 212 Results []IndexSnapshot `json:"results,omitempty"` 213 } 214 215 // TickerSnapshot is a collection of data for a ticker including the current minute, day, and previous day's aggregate, 216 // as well as the last trade and quote. 217 type TickerSnapshot struct { 218 Day DaySnapshot `json:"day,omitempty"` 219 LastQuote LastQuoteSnapshot `json:"lastQuote,omitempty"` 220 LastTrade LastTradeSnapshot `json:"lastTrade,omitempty"` 221 Minute MinuteSnapshot `json:"min,omitempty"` 222 PrevDay DaySnapshot `json:"prevDay,omitempty"` 223 Ticker string `json:"ticker,omitempty"` 224 TodaysChange float64 `json:"todaysChange,omitempty"` 225 TodaysChangePerc float64 `json:"todaysChangePerc,omitempty"` 226 Updated Nanos `json:"updated,omitempty"` 227 FairMarketValue float64 `json:"fmv,omitempty"` 228 } 229 230 // DaySnapshot is the most recent day agg for a ticker. 231 type DaySnapshot struct { 232 Close float64 `json:"c,omitempty"` 233 High float64 `json:"h,omitempty"` 234 Low float64 `json:"l,omitempty"` 235 Open float64 `json:"o,omitempty"` 236 Volume float64 `json:"v,omitempty"` 237 VolumeWeightedAverage float64 `json:"vw,omitempty"` 238 OTC bool `json:"otc,omitempty"` 239 } 240 241 // LastQuoteSnapshot is the most recent quote for a ticker. 242 type LastQuoteSnapshot struct { 243 AskPrice float64 `json:"P,omitempty"` 244 BidPrice float64 `json:"p,omitempty"` 245 AskSize float64 `json:"S,omitempty"` 246 BidSize float64 `json:"s,omitempty"` 247 Timestamp Nanos `json:"t,omitempty"` 248 } 249 250 // LastTradeSnapshot is the most recent trade for a ticker. 251 type LastTradeSnapshot struct { 252 Conditions []int `json:"c,omitempty"` 253 TradeID string `json:"i,omitempty"` 254 Price float64 `json:"p,omitempty"` 255 Size float64 `json:"s,omitempty"` 256 Timestamp Nanos `json:"t,omitempty"` 257 ExchangeID int `json:"x,omitempty"` 258 } 259 260 // MinuteSnapshot is the most recent minute agg for a ticker. 261 type MinuteSnapshot struct { 262 AccumulatedVolume float64 `json:"av,omitempty"` 263 Close float64 `json:"c,omitempty"` 264 High float64 `json:"h,omitempty"` 265 Low float64 `json:"l,omitempty"` 266 Open float64 `json:"o,omitempty"` 267 Volume float64 `json:"v,omitempty"` 268 VolumeWeightedAverage float64 `json:"vw,omitempty"` 269 NumberOfTransactions float64 `json:"n,omitempty"` 270 Timestamp Millis `json:"t,omitempty"` 271 OTC bool `json:"otc,omitempty"` 272 } 273 274 // OptionContractSnapshot is a collection of data for an option contract ticker including the current day aggregate and 275 // the most recent quote. 276 type OptionContractSnapshot struct { 277 BreakEvenPrice float64 `json:"break_even_price,omitempty"` 278 Day DayOptionContractSnapshot `json:"day,omitempty"` 279 Details OptionDetails `json:"details,omitempty"` 280 Greeks Greeks `json:"greeks,omitempty"` 281 ImpliedVolatility float64 `json:"implied_volatility,omitempty"` 282 LastQuote LastQuoteOptionContractSnapshot `json:"last_quote,omitempty"` 283 LastTrade LastTradeOptionContractSnapshot `json:"last_trade,omitempty"` 284 OpenInterest float64 `json:"open_interest,omitempty"` 285 UnderlyingAsset UnderlyingAsset `json:"underlying_asset,omitempty"` 286 FairMarketValue float64 `json:"fmv,omitempty"` 287 } 288 289 // IndexSnapshot is a collection of data for an index ticker including the current session information and the most recent value. 290 type IndexSnapshot struct { 291 Value float64 `json:"value,omitempty"` 292 Ticker string `json:"ticker,omitempty"` 293 Name string `json:"name,omitempty"` 294 Type string `json:"type,omitempty"` 295 MarketStatus string `json:"market_status,omitempty"` 296 Session IndexSession `json:"session,omitempty"` 297 } 298 299 type IndexSession struct { 300 Change float64 `json:"change,omitempty"` 301 ChangePercent float64 `json:"change_percent,omitempty"` 302 Close float64 `json:"close,omitempty"` 303 High float64 `json:"high,omitempty"` 304 Low float64 `json:"low,omitempty"` 305 Open float64 `json:"open,omitempty"` 306 PreviousClose float64 `json:"previous_close,omitempty"` 307 } 308 309 // DayOptionContractSnapshot contains the most recent day agg for an option contract. 310 type DayOptionContractSnapshot struct { 311 Change float64 `json:"change,omitempty"` 312 ChangePercent float64 `json:"change_percent,omitempty"` 313 Close float64 `json:"close,omitempty"` 314 High float64 `json:"high,omitempty"` 315 LastUpdated Nanos `json:"last_updated,omitempty"` 316 Low float64 `json:"low,omitempty"` 317 Open float64 `json:"open,omitempty"` 318 PreviousClose float64 `json:"previous_close,omitempty"` 319 Volume float64 `json:"volume,omitempty"` 320 VWAP float64 `json:"vwap,omitempty"` 321 } 322 323 // OptionDetails contains more detailed information about an option contract. 324 type OptionDetails struct { 325 ContractType string `json:"contract_type,omitempty"` 326 ExerciseStyle string `json:"exercise_style,omitempty"` 327 ExpirationDate Date `json:"expiration_date,omitempty"` 328 SharesPerContract float64 `json:"shares_per_contract,omitempty"` 329 StrikePrice float64 `json:"strike_price,omitempty"` 330 Ticker string `json:"ticker,omitempty"` 331 } 332 333 // Greeks contains the delta, gamma, vega, and theta of an option contract. 334 type Greeks struct { 335 Delta float64 `json:"delta,omitempty"` 336 Gamma float64 `json:"gamma,omitempty"` 337 Theta float64 `json:"theta,omitempty"` 338 Vega float64 `json:"vega,omitempty"` 339 } 340 341 // LastQuoteOptionContractSnapshot contains the most recent quote of an option contract. 342 type LastQuoteOptionContractSnapshot struct { 343 Ask float64 `json:"ask,omitempty"` 344 AskSize float64 `json:"ask_size,omitempty"` 345 Bid float64 `json:"bid,omitempty"` 346 BidSize float64 `json:"bid_size,omitempty"` 347 LastUpdated Nanos `json:"last_updated,omitempty"` 348 Midpoint float64 `json:"midpoint,omitempty"` 349 Timeframe string `json:"timeframe,omitempty"` 350 } 351 352 type LastTradeOptionContractSnapshot struct { 353 Timestamp Nanos `json:"sip_timestamp,omitempty"` 354 Conditions []int32 `json:"conditions,omitempty"` 355 Price float64 `json:"price,omitempty"` 356 Size float64 `json:"size,omitempty"` 357 Exchange int32 `json:"exchange,omitempty"` 358 Timeframe string `json:"timeframe,omitempty"` 359 } 360 361 // UnderlyingAsset contains information on the underlying stock for this options contract. 362 type UnderlyingAsset struct { 363 ChangeToBreakEven float64 `json:"change_to_break_even,omitempty"` 364 LastUpdated int64 `json:"last_updated,omitempty"` 365 Price float64 `json:"price,omitempty"` 366 Value float64 `json:"value,omitempty"` 367 Ticker string `json:"ticker,omitempty"` 368 Timeframe string `json:"timeframe,omitempty"` 369 } 370 371 // FullBookSnapshot is the level 2 book of a single crypto ticker. 372 type FullBookSnapshot struct { 373 AskCount float64 `json:"askCount,omitempty"` 374 Asks []OrderBookQuote `json:"asks,omitempty"` 375 BidCount float64 `json:"bidCount,omitempty"` 376 Bids []OrderBookQuote `json:"bids,omitempty"` 377 Spread float64 `json:"spread,omitempty"` 378 Ticker string `json:"ticker,omitempty"` 379 Updated Nanos `json:"updated,omitempty"` 380 } 381 382 // OrderBookQuote contains quote information for a crypto ticker. 383 type OrderBookQuote struct { 384 Price float64 `json:"p,omitempty"` 385 ExchangeToShares map[string]float64 `json:"x,omitempty"` 386 } 387 388 // ListUniversalSnapshotsParams is a set of parameters for the ListUniversalSnapshots method. 389 type ListUniversalSnapshotsParams struct { 390 TickerAnyOf *string `query:"ticker.any_of"` 391 Ticker *string `query:"ticker"` 392 393 TickerLT *string `query:"ticker.lt"` 394 TickerLTE *string `query:"ticker.lte"` 395 TickerGT *string `query:"ticker.gt"` 396 TickerGTE *string `query:"ticker.gte"` 397 398 Type *string `query:"type"` 399 } 400 401 // WithTickerAnyOf sets the ticker.any_of query param. 402 func (p ListUniversalSnapshotsParams) WithTickerAnyOf(q string) *ListUniversalSnapshotsParams { 403 p.TickerAnyOf = &q 404 return &p 405 } 406 407 // WithTicker sets the ticker equality query param. 408 func (p ListUniversalSnapshotsParams) WithTicker(q string) *ListUniversalSnapshotsParams { 409 p.Ticker = &q 410 return &p 411 } 412 413 // WithType sets the type query param. 414 func (p ListUniversalSnapshotsParams) WithType(q string) *ListUniversalSnapshotsParams { 415 p.Type = &q 416 return &p 417 } 418 419 // WithTickersByComparison sets the ticker inequality query params. 420 // Comparator options include EQ, LT, LTE, GT, and GTE. 421 func (p ListUniversalSnapshotsParams) WithTickersByComparison(c Comparator, q string) *ListUniversalSnapshotsParams { 422 switch c { 423 case LT: 424 p.TickerLT = &q 425 case LTE: 426 p.TickerLTE = &q 427 case GT: 428 p.TickerGT = &q 429 case GTE: 430 p.TickerGTE = &q 431 } 432 return &p 433 } 434 435 // ListUniversalSnapshotsResponse is the response returned by the ListUniversalSnapshots method. 436 type ListUniversalSnapshotsResponse struct { 437 BaseResponse 438 Results []SnapshotResponseModel `json:"results,omitempty"` 439 } 440 441 // SnapshotResponseModel contains all the information that might come back in a SnapshotResponse. 442 type SnapshotResponseModel struct { 443 Name string `json:"name,omitempty"` 444 MarketStatus string `json:"market_status,omitempty"` 445 Ticker string `json:"ticker,omitempty"` 446 Type string `json:"type,omitempty"` 447 LastQuote SnapshotLastQuote `json:"last_quote,omitempty"` 448 LastTrade SnapshotLastTrade `json:"last_trade,omitempty"` 449 Session Session `json:"session,omitempty"` 450 BreakEvenPrice float64 `json:"break_even_price,omitempty"` 451 Details Details `json:"details,omitempty"` 452 Greeks Greeks `json:"greeks,omitempty"` 453 ImpliedVolatility float64 `json:"implied_volatility,omitempty"` 454 OpenInterest float64 `json:"open_interest,omitempty"` 455 UnderlyingAsset UnderlyingAsset `json:"underlying_asset,omitempty"` 456 Value float64 `json:"value,omitempty"` 457 LastUpdated int64 `json:"last_updated,omitempty"` 458 Timeframe string `json:"timeframe,omitempty"` 459 FairMarketValue float64 `json:"fmv,omitempty"` 460 Error string `json:"error"` 461 Message string `json:"message"` 462 } 463 464 // SnapshotLastQuote contains all the information that might come back in the last_quote attribute of a SnapshotResponse. 465 type SnapshotLastQuote struct { 466 Ask float64 `json:"ask,omitempty"` 467 AskSize float64 `json:"ask_size,omitempty"` 468 Bid float64 `json:"bid,omitempty"` 469 BidSize float64 `json:"bid_size,omitempty"` 470 LastUpdated int64 `json:"last_updated,omitempty"` 471 Midpoint float64 `json:"midpoint,omitempty"` 472 Timeframe string `json:"timeframe,omitempty"` 473 Exchange int64 `json:"exchange,omitempty"` 474 } 475 476 // SnapshotLastTrade contains all the information that might come back in the last_trade attribute of a SnapshotResponse. 477 type SnapshotLastTrade struct { 478 Timestamp int64 `json:"sip_timestamp,omitempty"` 479 ParticipantTimestamp int64 `json:"participant_timestamp,omitempty"` 480 Conditions []int32 `json:"conditions,omitempty"` 481 Price float64 `json:"price,omitempty"` 482 Size uint32 `json:"size,omitempty"` 483 Exchange int32 `json:"exchange,omitempty"` 484 Timeframe string `json:"timeframe,omitempty"` 485 ID string `json:"id,omitempty"` 486 LastUpdated int64 `json:"last_updated,omitempty"` 487 } 488 489 // Details contains all the information that might come back in the details attribute of a SnapshotResponse. 490 type Details struct { 491 ContractType string `json:"contract_type,omitempty"` 492 ExerciseStyle string `json:"exercise_style,omitempty"` 493 ExpirationDate string `json:"expiration_date,omitempty"` 494 SharesPerContract float64 `json:"shares_per_contract,omitempty"` 495 StrikePrice float64 `json:"strike_price,omitempty"` 496 }