-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalphavantage.go
More file actions
410 lines (366 loc) · 13.4 KB
/
Copy pathalphavantage.go
File metadata and controls
410 lines (366 loc) · 13.4 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
// Auto-generated by claw402 codegen — DO NOT EDIT
// Provider: Alpha Vantage (alphavantage)
package claw402
import (
"context"
"encoding/json"
)
// AlphavantageUs provides methods for Alphavantage us endpoints.
type AlphavantageUs struct {
client *Client
}
// AlphavantageUsQuoteParams are the query parameters for Quote.
type AlphavantageUsQuoteParams struct {
Symbol string `json:"symbol,omitempty"`
}
// Real-time US stock quote (price, change, volume) — $0.001/call
func (r *AlphavantageUs) Quote(ctx context.Context, params *AlphavantageUsQuoteParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Symbol != "" {
q["symbol"] = params.Symbol
}
return r.client.get(ctx, "/api/v1/stocks/us/quote", q)
}
// AlphavantageUsSearchParams are the query parameters for Search.
type AlphavantageUsSearchParams struct {
Keywords string `json:"keywords,omitempty"`
}
// Stock symbol search by keyword — $0.001/call
func (r *AlphavantageUs) Search(ctx context.Context, params *AlphavantageUsSearchParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Keywords != "" {
q["keywords"] = params.Keywords
}
return r.client.get(ctx, "/api/v1/stocks/us/search", q)
}
// AlphavantageUsDailyParams are the query parameters for Daily.
type AlphavantageUsDailyParams struct {
Symbol string `json:"symbol,omitempty"`
Outputsize string `json:"outputsize,omitempty"`
Datatype string `json:"datatype,omitempty"`
}
// Daily OHLCV data (compact=100 days or full history) — $0.001/call
func (r *AlphavantageUs) Daily(ctx context.Context, params *AlphavantageUsDailyParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Symbol != "" {
q["symbol"] = params.Symbol
}
if params != nil && params.Outputsize != "" {
q["outputsize"] = params.Outputsize
}
if params != nil && params.Datatype != "" {
q["datatype"] = params.Datatype
}
return r.client.get(ctx, "/api/v1/stocks/us/daily", q)
}
// AlphavantageUsDailyAdjustedParams are the query parameters for DailyAdjusted.
type AlphavantageUsDailyAdjustedParams struct {
Symbol string `json:"symbol,omitempty"`
Outputsize string `json:"outputsize,omitempty"`
Datatype string `json:"datatype,omitempty"`
}
// Daily adjusted OHLCV (dividend & split adjusted) — $0.001/call
func (r *AlphavantageUs) DailyAdjusted(ctx context.Context, params *AlphavantageUsDailyAdjustedParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Symbol != "" {
q["symbol"] = params.Symbol
}
if params != nil && params.Outputsize != "" {
q["outputsize"] = params.Outputsize
}
if params != nil && params.Datatype != "" {
q["datatype"] = params.Datatype
}
return r.client.get(ctx, "/api/v1/stocks/us/daily-adjusted", q)
}
// AlphavantageUsIntradayParams are the query parameters for Intraday.
type AlphavantageUsIntradayParams struct {
Symbol string `json:"symbol,omitempty"`
Interval string `json:"interval,omitempty"`
Outputsize string `json:"outputsize,omitempty"`
Month string `json:"month,omitempty"`
}
// Intraday OHLCV bars (1/5/15/30/60min intervals) — $0.001/call
func (r *AlphavantageUs) Intraday(ctx context.Context, params *AlphavantageUsIntradayParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Symbol != "" {
q["symbol"] = params.Symbol
}
if params != nil && params.Interval != "" {
q["interval"] = params.Interval
}
if params != nil && params.Outputsize != "" {
q["outputsize"] = params.Outputsize
}
if params != nil && params.Month != "" {
q["month"] = params.Month
}
return r.client.get(ctx, "/api/v1/stocks/us/intraday", q)
}
// AlphavantageUsWeeklyParams are the query parameters for Weekly.
type AlphavantageUsWeeklyParams struct {
Symbol string `json:"symbol,omitempty"`
}
// Weekly OHLCV time series — $0.001/call
func (r *AlphavantageUs) Weekly(ctx context.Context, params *AlphavantageUsWeeklyParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Symbol != "" {
q["symbol"] = params.Symbol
}
return r.client.get(ctx, "/api/v1/stocks/us/weekly", q)
}
// AlphavantageUsMonthlyParams are the query parameters for Monthly.
type AlphavantageUsMonthlyParams struct {
Symbol string `json:"symbol,omitempty"`
}
// Monthly OHLCV time series — $0.001/call
func (r *AlphavantageUs) Monthly(ctx context.Context, params *AlphavantageUsMonthlyParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Symbol != "" {
q["symbol"] = params.Symbol
}
return r.client.get(ctx, "/api/v1/stocks/us/monthly", q)
}
// AlphavantageUsOverviewParams are the query parameters for Overview.
type AlphavantageUsOverviewParams struct {
Symbol string `json:"symbol,omitempty"`
}
// Company overview: market cap, PE, PB, revenue, EPS, dividends — $0.001/call
func (r *AlphavantageUs) Overview(ctx context.Context, params *AlphavantageUsOverviewParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Symbol != "" {
q["symbol"] = params.Symbol
}
return r.client.get(ctx, "/api/v1/stocks/us/overview", q)
}
// AlphavantageUsEarningsParams are the query parameters for Earnings.
type AlphavantageUsEarningsParams struct {
Symbol string `json:"symbol,omitempty"`
}
// Quarterly & annual EPS vs. analyst estimates — $0.001/call
func (r *AlphavantageUs) Earnings(ctx context.Context, params *AlphavantageUsEarningsParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Symbol != "" {
q["symbol"] = params.Symbol
}
return r.client.get(ctx, "/api/v1/stocks/us/earnings", q)
}
// AlphavantageUsIncomeParams are the query parameters for Income.
type AlphavantageUsIncomeParams struct {
Symbol string `json:"symbol,omitempty"`
}
// Income statement (quarterly & annual) — $0.001/call
func (r *AlphavantageUs) Income(ctx context.Context, params *AlphavantageUsIncomeParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Symbol != "" {
q["symbol"] = params.Symbol
}
return r.client.get(ctx, "/api/v1/stocks/us/income", q)
}
// AlphavantageUsBalanceSheetParams are the query parameters for BalanceSheet.
type AlphavantageUsBalanceSheetParams struct {
Symbol string `json:"symbol,omitempty"`
}
// Balance sheet (quarterly & annual) — $0.001/call
func (r *AlphavantageUs) BalanceSheet(ctx context.Context, params *AlphavantageUsBalanceSheetParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Symbol != "" {
q["symbol"] = params.Symbol
}
return r.client.get(ctx, "/api/v1/stocks/us/balance-sheet", q)
}
// AlphavantageUsCashFlowParams are the query parameters for CashFlow.
type AlphavantageUsCashFlowParams struct {
Symbol string `json:"symbol,omitempty"`
}
// Cash flow statement (quarterly & annual) — $0.001/call
func (r *AlphavantageUs) CashFlow(ctx context.Context, params *AlphavantageUsCashFlowParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Symbol != "" {
q["symbol"] = params.Symbol
}
return r.client.get(ctx, "/api/v1/stocks/us/cash-flow", q)
}
// Top gainers, losers, and most active stocks today — $0.001/call
func (r *AlphavantageUs) Movers(ctx context.Context) (json.RawMessage, error) {
return r.client.get(ctx, "/api/v1/stocks/us/movers", nil)
}
// AlphavantageUsNewsParams are the query parameters for News.
type AlphavantageUsNewsParams struct {
Tickers string `json:"tickers,omitempty"`
Topics string `json:"topics,omitempty"`
TimeFrom string `json:"time_from,omitempty"`
TimeTo string `json:"time_to,omitempty"`
Sort string `json:"sort,omitempty"`
Limit string `json:"limit,omitempty"`
}
// News articles with AI sentiment scores (bullish/bearish) — $0.001/call
func (r *AlphavantageUs) News(ctx context.Context, params *AlphavantageUsNewsParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Tickers != "" {
q["tickers"] = params.Tickers
}
if params != nil && params.Topics != "" {
q["topics"] = params.Topics
}
if params != nil && params.TimeFrom != "" {
q["time_from"] = params.TimeFrom
}
if params != nil && params.TimeTo != "" {
q["time_to"] = params.TimeTo
}
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/stocks/us/news", q)
}
// AlphavantageUsRsiParams are the query parameters for Rsi.
type AlphavantageUsRsiParams struct {
Symbol string `json:"symbol,omitempty"`
Interval string `json:"interval,omitempty"`
TimePeriod string `json:"time_period,omitempty"`
SeriesType string `json:"series_type,omitempty"`
}
// Relative Strength Index (RSI) — $0.001/call
func (r *AlphavantageUs) Rsi(ctx context.Context, params *AlphavantageUsRsiParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Symbol != "" {
q["symbol"] = params.Symbol
}
if params != nil && params.Interval != "" {
q["interval"] = params.Interval
}
if params != nil && params.TimePeriod != "" {
q["time_period"] = params.TimePeriod
}
if params != nil && params.SeriesType != "" {
q["series_type"] = params.SeriesType
}
return r.client.get(ctx, "/api/v1/stocks/us/rsi", q)
}
// AlphavantageUsMacdParams are the query parameters for Macd.
type AlphavantageUsMacdParams struct {
Symbol string `json:"symbol,omitempty"`
Interval string `json:"interval,omitempty"`
SeriesType string `json:"series_type,omitempty"`
Fastperiod string `json:"fastperiod,omitempty"`
Slowperiod string `json:"slowperiod,omitempty"`
Signalperiod string `json:"signalperiod,omitempty"`
}
// MACD (signal, histogram, fast/slow lines) — $0.001/call
func (r *AlphavantageUs) Macd(ctx context.Context, params *AlphavantageUsMacdParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Symbol != "" {
q["symbol"] = params.Symbol
}
if params != nil && params.Interval != "" {
q["interval"] = params.Interval
}
if params != nil && params.SeriesType != "" {
q["series_type"] = params.SeriesType
}
if params != nil && params.Fastperiod != "" {
q["fastperiod"] = params.Fastperiod
}
if params != nil && params.Slowperiod != "" {
q["slowperiod"] = params.Slowperiod
}
if params != nil && params.Signalperiod != "" {
q["signalperiod"] = params.Signalperiod
}
return r.client.get(ctx, "/api/v1/stocks/us/macd", q)
}
// AlphavantageUsBbandsParams are the query parameters for Bbands.
type AlphavantageUsBbandsParams struct {
Symbol string `json:"symbol,omitempty"`
Interval string `json:"interval,omitempty"`
TimePeriod string `json:"time_period,omitempty"`
SeriesType string `json:"series_type,omitempty"`
Nbdevup string `json:"nbdevup,omitempty"`
Nbdevdn string `json:"nbdevdn,omitempty"`
}
// Bollinger Bands (upper, middle, lower) — $0.001/call
func (r *AlphavantageUs) Bbands(ctx context.Context, params *AlphavantageUsBbandsParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Symbol != "" {
q["symbol"] = params.Symbol
}
if params != nil && params.Interval != "" {
q["interval"] = params.Interval
}
if params != nil && params.TimePeriod != "" {
q["time_period"] = params.TimePeriod
}
if params != nil && params.SeriesType != "" {
q["series_type"] = params.SeriesType
}
if params != nil && params.Nbdevup != "" {
q["nbdevup"] = params.Nbdevup
}
if params != nil && params.Nbdevdn != "" {
q["nbdevdn"] = params.Nbdevdn
}
return r.client.get(ctx, "/api/v1/stocks/us/bbands", q)
}
// AlphavantageUsSmaParams are the query parameters for Sma.
type AlphavantageUsSmaParams struct {
Symbol string `json:"symbol,omitempty"`
Interval string `json:"interval,omitempty"`
TimePeriod string `json:"time_period,omitempty"`
SeriesType string `json:"series_type,omitempty"`
}
// Simple Moving Average (SMA) — $0.001/call
func (r *AlphavantageUs) Sma(ctx context.Context, params *AlphavantageUsSmaParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Symbol != "" {
q["symbol"] = params.Symbol
}
if params != nil && params.Interval != "" {
q["interval"] = params.Interval
}
if params != nil && params.TimePeriod != "" {
q["time_period"] = params.TimePeriod
}
if params != nil && params.SeriesType != "" {
q["series_type"] = params.SeriesType
}
return r.client.get(ctx, "/api/v1/stocks/us/sma", q)
}
// AlphavantageUsEmaParams are the query parameters for Ema.
type AlphavantageUsEmaParams struct {
Symbol string `json:"symbol,omitempty"`
Interval string `json:"interval,omitempty"`
TimePeriod string `json:"time_period,omitempty"`
SeriesType string `json:"series_type,omitempty"`
}
// Exponential Moving Average (EMA) — $0.001/call
func (r *AlphavantageUs) Ema(ctx context.Context, params *AlphavantageUsEmaParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Symbol != "" {
q["symbol"] = params.Symbol
}
if params != nil && params.Interval != "" {
q["interval"] = params.Interval
}
if params != nil && params.TimePeriod != "" {
q["time_period"] = params.TimePeriod
}
if params != nil && params.SeriesType != "" {
q["series_type"] = params.SeriesType
}
return r.client.get(ctx, "/api/v1/stocks/us/ema", q)
}
// AlphavantageResource provides access to all Alpha Vantage API endpoints.
type AlphavantageResource struct {
client *Client
Us *AlphavantageUs
}
func newAlphavantageResource(c *Client) *AlphavantageResource {
return &AlphavantageResource{
client: c,
Us: &AlphavantageUs{client: c},
}
}