-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolygon.go
More file actions
809 lines (754 loc) · 27 KB
/
Copy pathpolygon.go
File metadata and controls
809 lines (754 loc) · 27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
// Auto-generated by claw402 codegen — DO NOT EDIT
// Provider: Polygon.io (polygon)
package claw402
import (
"context"
"encoding/json"
)
// PolygonAggs provides methods for Polygon aggs endpoints.
type PolygonAggs struct {
client *Client
}
// PolygonAggsTickerParams are the query parameters for Ticker.
type PolygonAggsTickerParams struct {
StocksTicker string `json:"stocksTicker,omitempty"`
Multiplier string `json:"multiplier,omitempty"`
Timespan string `json:"timespan,omitempty"`
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
Adjusted string `json:"adjusted,omitempty"`
Sort string `json:"sort,omitempty"`
Limit string `json:"limit,omitempty"`
}
// Get aggregate bars (OHLCV) for any stock ticker — $0.001/call
func (r *PolygonAggs) Ticker(ctx context.Context, params *PolygonAggsTickerParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.StocksTicker != "" {
q["stocksTicker"] = params.StocksTicker
}
if params != nil && params.Multiplier != "" {
q["multiplier"] = params.Multiplier
}
if params != nil && params.Timespan != "" {
q["timespan"] = params.Timespan
}
if params != nil && params.From != "" {
q["from"] = params.From
}
if params != nil && params.To != "" {
q["to"] = params.To
}
if params != nil && params.Adjusted != "" {
q["adjusted"] = params.Adjusted
}
if params != nil && params.Sort != "" {
q["sort"] = params.Sort
}
if params != nil && params.Limit != "" {
q["limit"] = params.Limit
}
return r.client.get(ctx, "/api/v1/polygon/aggs/ticker", q)
}
// PolygonAggsGroupedParams are the query parameters for Grouped.
type PolygonAggsGroupedParams struct {
Date string `json:"date,omitempty"`
Adjusted string `json:"adjusted,omitempty"`
IncludeOtc string `json:"include_otc,omitempty"`
}
// Get aggregate bars for entire US market on a specific date — $0.005/call
func (r *PolygonAggs) Grouped(ctx context.Context, params *PolygonAggsGroupedParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Date != "" {
q["date"] = params.Date
}
if params != nil && params.Adjusted != "" {
q["adjusted"] = params.Adjusted
}
if params != nil && params.IncludeOtc != "" {
q["include_otc"] = params.IncludeOtc
}
return r.client.get(ctx, "/api/v1/polygon/aggs/grouped", q)
}
// PolygonSnapshot provides methods for Polygon snapshot endpoints.
type PolygonSnapshot struct {
client *Client
}
// PolygonSnapshotTickerParams are the query parameters for Ticker.
type PolygonSnapshotTickerParams struct {
StocksTicker string `json:"stocksTicker,omitempty"`
}
// Get real-time snapshot for any ticker — $0.001/call
func (r *PolygonSnapshot) Ticker(ctx context.Context, params *PolygonSnapshotTickerParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.StocksTicker != "" {
q["stocksTicker"] = params.StocksTicker
}
return r.client.get(ctx, "/api/v1/polygon/snapshot/ticker", q)
}
// PolygonSnapshotAllParams are the query parameters for All.
type PolygonSnapshotAllParams struct {
Tickers string `json:"tickers,omitempty"`
IncludeOtc string `json:"include_otc,omitempty"`
}
// Get snapshots for all US stock tickers — $0.005/call
func (r *PolygonSnapshot) All(ctx context.Context, params *PolygonSnapshotAllParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Tickers != "" {
q["tickers"] = params.Tickers
}
if params != nil && params.IncludeOtc != "" {
q["include_otc"] = params.IncludeOtc
}
return r.client.get(ctx, "/api/v1/polygon/snapshot/all", q)
}
// PolygonSnapshotGainersParams are the query parameters for Gainers.
type PolygonSnapshotGainersParams struct {
IncludeOtc string `json:"include_otc,omitempty"`
}
// Get top 20 gainers of the day — $0.001/call
func (r *PolygonSnapshot) Gainers(ctx context.Context, params *PolygonSnapshotGainersParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.IncludeOtc != "" {
q["include_otc"] = params.IncludeOtc
}
return r.client.get(ctx, "/api/v1/polygon/snapshot/gainers", q)
}
// PolygonSnapshotLosersParams are the query parameters for Losers.
type PolygonSnapshotLosersParams struct {
IncludeOtc string `json:"include_otc,omitempty"`
}
// Get top 20 losers of the day — $0.001/call
func (r *PolygonSnapshot) Losers(ctx context.Context, params *PolygonSnapshotLosersParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.IncludeOtc != "" {
q["include_otc"] = params.IncludeOtc
}
return r.client.get(ctx, "/api/v1/polygon/snapshot/losers", q)
}
// PolygonOptions provides methods for Polygon options endpoints.
type PolygonOptions struct {
client *Client
}
// PolygonOptionsContractsParams are the query parameters for Contracts.
type PolygonOptionsContractsParams struct {
UnderlyingTicker string `json:"underlying_ticker,omitempty"`
ContractType string `json:"contract_type,omitempty"`
ExpirationDate string `json:"expiration_date,omitempty"`
ExpirationDateGte string `json:"expiration_date.gte,omitempty"`
ExpirationDateGt string `json:"expiration_date.gt,omitempty"`
ExpirationDateLte string `json:"expiration_date.lte,omitempty"`
ExpirationDateLt string `json:"expiration_date.lt,omitempty"`
AsOf string `json:"as_of,omitempty"`
StrikePrice string `json:"strike_price,omitempty"`
StrikePriceGte string `json:"strike_price.gte,omitempty"`
StrikePriceGt string `json:"strike_price.gt,omitempty"`
StrikePriceLte string `json:"strike_price.lte,omitempty"`
StrikePriceLt string `json:"strike_price.lt,omitempty"`
Expired string `json:"expired,omitempty"`
Order string `json:"order,omitempty"`
Limit string `json:"limit,omitempty"`
Sort string `json:"sort,omitempty"`
}
// Query for historical options contracts — $0.002/call
func (r *PolygonOptions) Contracts(ctx context.Context, params *PolygonOptionsContractsParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.UnderlyingTicker != "" {
q["underlying_ticker"] = params.UnderlyingTicker
}
if params != nil && params.ContractType != "" {
q["contract_type"] = params.ContractType
}
if params != nil && params.ExpirationDate != "" {
q["expiration_date"] = params.ExpirationDate
}
if params != nil && params.ExpirationDateGte != "" {
q["expiration_date.gte"] = params.ExpirationDateGte
}
if params != nil && params.ExpirationDateGt != "" {
q["expiration_date.gt"] = params.ExpirationDateGt
}
if params != nil && params.ExpirationDateLte != "" {
q["expiration_date.lte"] = params.ExpirationDateLte
}
if params != nil && params.ExpirationDateLt != "" {
q["expiration_date.lt"] = params.ExpirationDateLt
}
if params != nil && params.AsOf != "" {
q["as_of"] = params.AsOf
}
if params != nil && params.StrikePrice != "" {
q["strike_price"] = params.StrikePrice
}
if params != nil && params.StrikePriceGte != "" {
q["strike_price.gte"] = params.StrikePriceGte
}
if params != nil && params.StrikePriceGt != "" {
q["strike_price.gt"] = params.StrikePriceGt
}
if params != nil && params.StrikePriceLte != "" {
q["strike_price.lte"] = params.StrikePriceLte
}
if params != nil && params.StrikePriceLt != "" {
q["strike_price.lt"] = params.StrikePriceLt
}
if params != nil && params.Expired != "" {
q["expired"] = params.Expired
}
if params != nil && params.Order != "" {
q["order"] = params.Order
}
if params != nil && params.Limit != "" {
q["limit"] = params.Limit
}
if params != nil && params.Sort != "" {
q["sort"] = params.Sort
}
return r.client.get(ctx, "/api/v1/polygon/options/contracts", q)
}
// PolygonOptionsContractDetailsParams are the query parameters for ContractDetails.
type PolygonOptionsContractDetailsParams struct {
OptionsTicker string `json:"options_ticker,omitempty"`
AsOf string `json:"as_of,omitempty"`
}
// Get details for a single options contract — $0.001/call
func (r *PolygonOptions) ContractDetails(ctx context.Context, params *PolygonOptionsContractDetailsParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.OptionsTicker != "" {
q["options_ticker"] = params.OptionsTicker
}
if params != nil && params.AsOf != "" {
q["as_of"] = params.AsOf
}
return r.client.get(ctx, "/api/v1/polygon/options/contract-details", q)
}
// PolygonOptionsSnapshotParams are the query parameters for Snapshot.
type PolygonOptionsSnapshotParams struct {
UnderlyingAsset string `json:"underlyingAsset,omitempty"`
StrikePrice string `json:"strike_price,omitempty"`
StrikePriceGte string `json:"strike_price.gte,omitempty"`
StrikePriceGt string `json:"strike_price.gt,omitempty"`
StrikePriceLte string `json:"strike_price.lte,omitempty"`
StrikePriceLt string `json:"strike_price.lt,omitempty"`
ExpirationDate string `json:"expiration_date,omitempty"`
ExpirationDateGte string `json:"expiration_date.gte,omitempty"`
ExpirationDateGt string `json:"expiration_date.gt,omitempty"`
ExpirationDateLte string `json:"expiration_date.lte,omitempty"`
ExpirationDateLt string `json:"expiration_date.lt,omitempty"`
ContractType string `json:"contract_type,omitempty"`
Order string `json:"order,omitempty"`
Limit string `json:"limit,omitempty"`
}
// Get snapshot of options chain for an underlying asset — $0.002/call
func (r *PolygonOptions) Snapshot(ctx context.Context, params *PolygonOptionsSnapshotParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.UnderlyingAsset != "" {
q["underlyingAsset"] = params.UnderlyingAsset
}
if params != nil && params.StrikePrice != "" {
q["strike_price"] = params.StrikePrice
}
if params != nil && params.StrikePriceGte != "" {
q["strike_price.gte"] = params.StrikePriceGte
}
if params != nil && params.StrikePriceGt != "" {
q["strike_price.gt"] = params.StrikePriceGt
}
if params != nil && params.StrikePriceLte != "" {
q["strike_price.lte"] = params.StrikePriceLte
}
if params != nil && params.StrikePriceLt != "" {
q["strike_price.lt"] = params.StrikePriceLt
}
if params != nil && params.ExpirationDate != "" {
q["expiration_date"] = params.ExpirationDate
}
if params != nil && params.ExpirationDateGte != "" {
q["expiration_date.gte"] = params.ExpirationDateGte
}
if params != nil && params.ExpirationDateGt != "" {
q["expiration_date.gt"] = params.ExpirationDateGt
}
if params != nil && params.ExpirationDateLte != "" {
q["expiration_date.lte"] = params.ExpirationDateLte
}
if params != nil && params.ExpirationDateLt != "" {
q["expiration_date.lt"] = params.ExpirationDateLt
}
if params != nil && params.ContractType != "" {
q["contract_type"] = params.ContractType
}
if params != nil && params.Order != "" {
q["order"] = params.Order
}
if params != nil && params.Limit != "" {
q["limit"] = params.Limit
}
return r.client.get(ctx, "/api/v1/polygon/options/snapshot", q)
}
// PolygonOptionsSnapshotContractParams are the query parameters for SnapshotContract.
type PolygonOptionsSnapshotContractParams struct {
UnderlyingAsset string `json:"underlyingAsset,omitempty"`
OptionContract string `json:"optionContract,omitempty"`
}
// Get snapshot of a single options contract — $0.001/call
func (r *PolygonOptions) SnapshotContract(ctx context.Context, params *PolygonOptionsSnapshotContractParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.UnderlyingAsset != "" {
q["underlyingAsset"] = params.UnderlyingAsset
}
if params != nil && params.OptionContract != "" {
q["optionContract"] = params.OptionContract
}
return r.client.get(ctx, "/api/v1/polygon/options/snapshot/contract", q)
}
// PolygonResource provides access to all Polygon.io API endpoints.
type PolygonResource struct {
client *Client
Aggs *PolygonAggs
Snapshot *PolygonSnapshot
Options *PolygonOptions
}
func newPolygonResource(c *Client) *PolygonResource {
return &PolygonResource{
client: c,
Aggs: &PolygonAggs{client: c},
Snapshot: &PolygonSnapshot{client: c},
Options: &PolygonOptions{client: c},
}
}
// PolygonPrevCloseParams are the query parameters for PrevClose.
type PolygonPrevCloseParams struct {
StocksTicker string `json:"stocksTicker,omitempty"`
Adjusted string `json:"adjusted,omitempty"`
}
// Get previous day close for any ticker — $0.001/call
func (r *PolygonResource) PrevClose(ctx context.Context, params *PolygonPrevCloseParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.StocksTicker != "" {
q["stocksTicker"] = params.StocksTicker
}
if params != nil && params.Adjusted != "" {
q["adjusted"] = params.Adjusted
}
return r.client.get(ctx, "/api/v1/polygon/prev-close", q)
}
// PolygonTradesParams are the query parameters for Trades.
type PolygonTradesParams struct {
StockTicker string `json:"stockTicker,omitempty"`
TimestampGte string `json:"timestamp.gte,omitempty"`
TimestampLte string `json:"timestamp.lte,omitempty"`
TimestampGt string `json:"timestamp.gt,omitempty"`
TimestampLt string `json:"timestamp.lt,omitempty"`
Order string `json:"order,omitempty"`
Limit string `json:"limit,omitempty"`
Sort string `json:"sort,omitempty"`
}
// Get tick-by-tick trade data for any stock — $0.005/call
func (r *PolygonResource) Trades(ctx context.Context, params *PolygonTradesParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.StockTicker != "" {
q["stockTicker"] = params.StockTicker
}
if params != nil && params.TimestampGte != "" {
q["timestamp.gte"] = params.TimestampGte
}
if params != nil && params.TimestampLte != "" {
q["timestamp.lte"] = params.TimestampLte
}
if params != nil && params.TimestampGt != "" {
q["timestamp.gt"] = params.TimestampGt
}
if params != nil && params.TimestampLt != "" {
q["timestamp.lt"] = params.TimestampLt
}
if params != nil && params.Order != "" {
q["order"] = params.Order
}
if params != nil && params.Limit != "" {
q["limit"] = params.Limit
}
if params != nil && params.Sort != "" {
q["sort"] = params.Sort
}
return r.client.get(ctx, "/api/v1/polygon/trades", q)
}
// PolygonLastTradeParams are the query parameters for LastTrade.
type PolygonLastTradeParams struct {
StocksTicker string `json:"stocksTicker,omitempty"`
}
// Get most recent trade for a ticker — $0.001/call
func (r *PolygonResource) LastTrade(ctx context.Context, params *PolygonLastTradeParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.StocksTicker != "" {
q["stocksTicker"] = params.StocksTicker
}
return r.client.get(ctx, "/api/v1/polygon/last-trade", q)
}
// PolygonQuotesParams are the query parameters for Quotes.
type PolygonQuotesParams struct {
StockTicker string `json:"stockTicker,omitempty"`
TimestampGte string `json:"timestamp.gte,omitempty"`
TimestampLte string `json:"timestamp.lte,omitempty"`
TimestampGt string `json:"timestamp.gt,omitempty"`
TimestampLt string `json:"timestamp.lt,omitempty"`
Order string `json:"order,omitempty"`
Limit string `json:"limit,omitempty"`
Sort string `json:"sort,omitempty"`
}
// Get NBBO quotes for any stock — $0.005/call
func (r *PolygonResource) Quotes(ctx context.Context, params *PolygonQuotesParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.StockTicker != "" {
q["stockTicker"] = params.StockTicker
}
if params != nil && params.TimestampGte != "" {
q["timestamp.gte"] = params.TimestampGte
}
if params != nil && params.TimestampLte != "" {
q["timestamp.lte"] = params.TimestampLte
}
if params != nil && params.TimestampGt != "" {
q["timestamp.gt"] = params.TimestampGt
}
if params != nil && params.TimestampLt != "" {
q["timestamp.lt"] = params.TimestampLt
}
if params != nil && params.Order != "" {
q["order"] = params.Order
}
if params != nil && params.Limit != "" {
q["limit"] = params.Limit
}
if params != nil && params.Sort != "" {
q["sort"] = params.Sort
}
return r.client.get(ctx, "/api/v1/polygon/quotes", q)
}
// PolygonLastQuoteParams are the query parameters for LastQuote.
type PolygonLastQuoteParams struct {
StocksTicker string `json:"stocksTicker,omitempty"`
}
// Get most recent NBBO quote for a ticker — $0.001/call
func (r *PolygonResource) LastQuote(ctx context.Context, params *PolygonLastQuoteParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.StocksTicker != "" {
q["stocksTicker"] = params.StocksTicker
}
return r.client.get(ctx, "/api/v1/polygon/last-quote", q)
}
// PolygonTickersParams are the query parameters for Tickers.
type PolygonTickersParams struct {
Ticker string `json:"ticker,omitempty"`
Type string `json:"type,omitempty"`
Market string `json:"market,omitempty"`
Exchange string `json:"exchange,omitempty"`
Cusip string `json:"cusip,omitempty"`
Cik string `json:"cik,omitempty"`
Date string `json:"date,omitempty"`
Search string `json:"search,omitempty"`
Active string `json:"active,omitempty"`
Order string `json:"order,omitempty"`
Limit string `json:"limit,omitempty"`
Sort string `json:"sort,omitempty"`
}
// Query all ticker symbols with optional filters — $0.001/call
func (r *PolygonResource) Tickers(ctx context.Context, params *PolygonTickersParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Ticker != "" {
q["ticker"] = params.Ticker
}
if params != nil && params.Type != "" {
q["type"] = params.Type
}
if params != nil && params.Market != "" {
q["market"] = params.Market
}
if params != nil && params.Exchange != "" {
q["exchange"] = params.Exchange
}
if params != nil && params.Cusip != "" {
q["cusip"] = params.Cusip
}
if params != nil && params.Cik != "" {
q["cik"] = params.Cik
}
if params != nil && params.Date != "" {
q["date"] = params.Date
}
if params != nil && params.Search != "" {
q["search"] = params.Search
}
if params != nil && params.Active != "" {
q["active"] = params.Active
}
if params != nil && params.Order != "" {
q["order"] = params.Order
}
if params != nil && params.Limit != "" {
q["limit"] = params.Limit
}
if params != nil && params.Sort != "" {
q["sort"] = params.Sort
}
return r.client.get(ctx, "/api/v1/polygon/tickers", q)
}
// PolygonTickerDetailsParams are the query parameters for TickerDetails.
type PolygonTickerDetailsParams struct {
Ticker string `json:"ticker,omitempty"`
Date string `json:"date,omitempty"`
}
// Get detailed information about any ticker — $0.001/call
func (r *PolygonResource) TickerDetails(ctx context.Context, params *PolygonTickerDetailsParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Ticker != "" {
q["ticker"] = params.Ticker
}
if params != nil && params.Date != "" {
q["date"] = params.Date
}
return r.client.get(ctx, "/api/v1/polygon/ticker-details", q)
}
// PolygonTickerNewsParams are the query parameters for TickerNews.
type PolygonTickerNewsParams struct {
Ticker string `json:"ticker,omitempty"`
PublishedUtc string `json:"published_utc,omitempty"`
PublishedUtcGte string `json:"published_utc.gte,omitempty"`
PublishedUtcLte string `json:"published_utc.lte,omitempty"`
Order string `json:"order,omitempty"`
Limit string `json:"limit,omitempty"`
Sort string `json:"sort,omitempty"`
}
// Get news articles for tickers — $0.001/call
func (r *PolygonResource) TickerNews(ctx context.Context, params *PolygonTickerNewsParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Ticker != "" {
q["ticker"] = params.Ticker
}
if params != nil && params.PublishedUtc != "" {
q["published_utc"] = params.PublishedUtc
}
if params != nil && params.PublishedUtcGte != "" {
q["published_utc.gte"] = params.PublishedUtcGte
}
if params != nil && params.PublishedUtcLte != "" {
q["published_utc.lte"] = params.PublishedUtcLte
}
if params != nil && params.Order != "" {
q["order"] = params.Order
}
if params != nil && params.Limit != "" {
q["limit"] = params.Limit
}
if params != nil && params.Sort != "" {
q["sort"] = params.Sort
}
return r.client.get(ctx, "/api/v1/polygon/ticker-news", q)
}
// Get upcoming US market holidays and early closes — $0.001/call
func (r *PolygonResource) MarketHolidays(ctx context.Context) (json.RawMessage, error) {
return r.client.get(ctx, "/api/v1/polygon/market-holidays", nil)
}
// Get current US market trading status — $0.001/call
func (r *PolygonResource) MarketStatus(ctx context.Context) (json.RawMessage, error) {
return r.client.get(ctx, "/api/v1/polygon/market-status", nil)
}
// PolygonExchangesParams are the query parameters for Exchanges.
type PolygonExchangesParams struct {
AssetClass string `json:"asset_class,omitempty"`
Locale string `json:"locale,omitempty"`
}
// List all stock exchanges — $0.001/call
func (r *PolygonResource) Exchanges(ctx context.Context, params *PolygonExchangesParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.AssetClass != "" {
q["asset_class"] = params.AssetClass
}
if params != nil && params.Locale != "" {
q["locale"] = params.Locale
}
return r.client.get(ctx, "/api/v1/polygon/exchanges", q)
}
// PolygonSmaParams are the query parameters for Sma.
type PolygonSmaParams struct {
StockTicker string `json:"stockTicker,omitempty"`
Timestamp string `json:"timestamp,omitempty"`
Timespan string `json:"timespan,omitempty"`
Adjusted string `json:"adjusted,omitempty"`
Window string `json:"window,omitempty"`
SeriesType string `json:"series_type,omitempty"`
ExpandUnderlying string `json:"expand_underlying,omitempty"`
Order string `json:"order,omitempty"`
Limit string `json:"limit,omitempty"`
}
// Get Simple Moving Average (SMA) for any stock — $0.001/call
func (r *PolygonResource) Sma(ctx context.Context, params *PolygonSmaParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.StockTicker != "" {
q["stockTicker"] = params.StockTicker
}
if params != nil && params.Timestamp != "" {
q["timestamp"] = params.Timestamp
}
if params != nil && params.Timespan != "" {
q["timespan"] = params.Timespan
}
if params != nil && params.Adjusted != "" {
q["adjusted"] = params.Adjusted
}
if params != nil && params.Window != "" {
q["window"] = params.Window
}
if params != nil && params.SeriesType != "" {
q["series_type"] = params.SeriesType
}
if params != nil && params.ExpandUnderlying != "" {
q["expand_underlying"] = params.ExpandUnderlying
}
if params != nil && params.Order != "" {
q["order"] = params.Order
}
if params != nil && params.Limit != "" {
q["limit"] = params.Limit
}
return r.client.get(ctx, "/api/v1/polygon/sma", q)
}
// PolygonEmaParams are the query parameters for Ema.
type PolygonEmaParams struct {
StockTicker string `json:"stockTicker,omitempty"`
Timestamp string `json:"timestamp,omitempty"`
Timespan string `json:"timespan,omitempty"`
Adjusted string `json:"adjusted,omitempty"`
Window string `json:"window,omitempty"`
SeriesType string `json:"series_type,omitempty"`
ExpandUnderlying string `json:"expand_underlying,omitempty"`
Order string `json:"order,omitempty"`
Limit string `json:"limit,omitempty"`
}
// Get Exponential Moving Average (EMA) for any stock — $0.001/call
func (r *PolygonResource) Ema(ctx context.Context, params *PolygonEmaParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.StockTicker != "" {
q["stockTicker"] = params.StockTicker
}
if params != nil && params.Timestamp != "" {
q["timestamp"] = params.Timestamp
}
if params != nil && params.Timespan != "" {
q["timespan"] = params.Timespan
}
if params != nil && params.Adjusted != "" {
q["adjusted"] = params.Adjusted
}
if params != nil && params.Window != "" {
q["window"] = params.Window
}
if params != nil && params.SeriesType != "" {
q["series_type"] = params.SeriesType
}
if params != nil && params.ExpandUnderlying != "" {
q["expand_underlying"] = params.ExpandUnderlying
}
if params != nil && params.Order != "" {
q["order"] = params.Order
}
if params != nil && params.Limit != "" {
q["limit"] = params.Limit
}
return r.client.get(ctx, "/api/v1/polygon/ema", q)
}
// PolygonMacdParams are the query parameters for Macd.
type PolygonMacdParams struct {
StockTicker string `json:"stockTicker,omitempty"`
Timestamp string `json:"timestamp,omitempty"`
Timespan string `json:"timespan,omitempty"`
Adjusted string `json:"adjusted,omitempty"`
ShortWindow string `json:"short_window,omitempty"`
LongWindow string `json:"long_window,omitempty"`
SignalWindow string `json:"signal_window,omitempty"`
SeriesType string `json:"series_type,omitempty"`
ExpandUnderlying string `json:"expand_underlying,omitempty"`
Order string `json:"order,omitempty"`
Limit string `json:"limit,omitempty"`
}
// Get Moving Average Convergence/Divergence (MACD) — $0.001/call
func (r *PolygonResource) Macd(ctx context.Context, params *PolygonMacdParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.StockTicker != "" {
q["stockTicker"] = params.StockTicker
}
if params != nil && params.Timestamp != "" {
q["timestamp"] = params.Timestamp
}
if params != nil && params.Timespan != "" {
q["timespan"] = params.Timespan
}
if params != nil && params.Adjusted != "" {
q["adjusted"] = params.Adjusted
}
if params != nil && params.ShortWindow != "" {
q["short_window"] = params.ShortWindow
}
if params != nil && params.LongWindow != "" {
q["long_window"] = params.LongWindow
}
if params != nil && params.SignalWindow != "" {
q["signal_window"] = params.SignalWindow
}
if params != nil && params.SeriesType != "" {
q["series_type"] = params.SeriesType
}
if params != nil && params.ExpandUnderlying != "" {
q["expand_underlying"] = params.ExpandUnderlying
}
if params != nil && params.Order != "" {
q["order"] = params.Order
}
if params != nil && params.Limit != "" {
q["limit"] = params.Limit
}
return r.client.get(ctx, "/api/v1/polygon/macd", q)
}
// PolygonRsiParams are the query parameters for Rsi.
type PolygonRsiParams struct {
StockTicker string `json:"stockTicker,omitempty"`
Timestamp string `json:"timestamp,omitempty"`
Timespan string `json:"timespan,omitempty"`
Adjusted string `json:"adjusted,omitempty"`
Window string `json:"window,omitempty"`
SeriesType string `json:"series_type,omitempty"`
ExpandUnderlying string `json:"expand_underlying,omitempty"`
Order string `json:"order,omitempty"`
Limit string `json:"limit,omitempty"`
}
// Get Relative Strength Index (RSI) — $0.001/call
func (r *PolygonResource) Rsi(ctx context.Context, params *PolygonRsiParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.StockTicker != "" {
q["stockTicker"] = params.StockTicker
}
if params != nil && params.Timestamp != "" {
q["timestamp"] = params.Timestamp
}
if params != nil && params.Timespan != "" {
q["timespan"] = params.Timespan
}
if params != nil && params.Adjusted != "" {
q["adjusted"] = params.Adjusted
}
if params != nil && params.Window != "" {
q["window"] = params.Window
}
if params != nil && params.SeriesType != "" {
q["series_type"] = params.SeriesType
}
if params != nil && params.ExpandUnderlying != "" {
q["expand_underlying"] = params.ExpandUnderlying
}
if params != nil && params.Order != "" {
q["order"] = params.Order
}
if params != nil && params.Limit != "" {
q["limit"] = params.Limit
}
return r.client.get(ctx, "/api/v1/polygon/rsi", q)
}