-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwelvedata.go
More file actions
415 lines (372 loc) · 13.8 KB
/
Copy pathtwelvedata.go
File metadata and controls
415 lines (372 loc) · 13.8 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
// Auto-generated by claw402 codegen — DO NOT EDIT
// Provider: Twelve Data (twelvedata)
package claw402
import (
"context"
"encoding/json"
)
// TwelvedataTimeSeries provides methods for Twelvedata timeSeries endpoints.
type TwelvedataTimeSeries struct {
client *Client
}
// Complex query: multiple symbols + indicators in one request — $0.005/call
func (r *TwelvedataTimeSeries) Complex(ctx context.Context, body map[string]interface{}) (json.RawMessage, error) {
return r.client.post(ctx, "/api/v1/twelvedata/time-series/complex", body)
}
// TwelvedataIndicator provides methods for Twelvedata indicator endpoints.
type TwelvedataIndicator struct {
client *Client
}
// TwelvedataIndicatorSmaParams are the query parameters for Sma.
type TwelvedataIndicatorSmaParams struct {
Symbol string `json:"symbol,omitempty"`
Interval string `json:"interval,omitempty"`
TimePeriod string `json:"time_period,omitempty"`
Outputsize string `json:"outputsize,omitempty"`
}
// Simple Moving Average (SMA) — $0.002/call
func (r *TwelvedataIndicator) Sma(ctx context.Context, params *TwelvedataIndicatorSmaParams) (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.Outputsize != "" {
q["outputsize"] = params.Outputsize
}
return r.client.get(ctx, "/api/v1/twelvedata/indicator/sma", q)
}
// TwelvedataIndicatorEmaParams are the query parameters for Ema.
type TwelvedataIndicatorEmaParams struct {
Symbol string `json:"symbol,omitempty"`
Interval string `json:"interval,omitempty"`
TimePeriod string `json:"time_period,omitempty"`
Outputsize string `json:"outputsize,omitempty"`
}
// Exponential Moving Average (EMA) — $0.002/call
func (r *TwelvedataIndicator) Ema(ctx context.Context, params *TwelvedataIndicatorEmaParams) (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.Outputsize != "" {
q["outputsize"] = params.Outputsize
}
return r.client.get(ctx, "/api/v1/twelvedata/indicator/ema", q)
}
// TwelvedataIndicatorRsiParams are the query parameters for Rsi.
type TwelvedataIndicatorRsiParams struct {
Symbol string `json:"symbol,omitempty"`
Interval string `json:"interval,omitempty"`
TimePeriod string `json:"time_period,omitempty"`
Outputsize string `json:"outputsize,omitempty"`
}
// Relative Strength Index (RSI) — $0.002/call
func (r *TwelvedataIndicator) Rsi(ctx context.Context, params *TwelvedataIndicatorRsiParams) (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.Outputsize != "" {
q["outputsize"] = params.Outputsize
}
return r.client.get(ctx, "/api/v1/twelvedata/indicator/rsi", q)
}
// TwelvedataIndicatorMacdParams are the query parameters for Macd.
type TwelvedataIndicatorMacdParams struct {
Symbol string `json:"symbol,omitempty"`
Interval string `json:"interval,omitempty"`
Outputsize string `json:"outputsize,omitempty"`
}
// Moving Average Convergence Divergence (MACD) — $0.002/call
func (r *TwelvedataIndicator) Macd(ctx context.Context, params *TwelvedataIndicatorMacdParams) (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
}
return r.client.get(ctx, "/api/v1/twelvedata/indicator/macd", q)
}
// TwelvedataIndicatorBbandsParams are the query parameters for Bbands.
type TwelvedataIndicatorBbandsParams struct {
Symbol string `json:"symbol,omitempty"`
Interval string `json:"interval,omitempty"`
TimePeriod string `json:"time_period,omitempty"`
Outputsize string `json:"outputsize,omitempty"`
}
// Bollinger Bands — $0.002/call
func (r *TwelvedataIndicator) Bbands(ctx context.Context, params *TwelvedataIndicatorBbandsParams) (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.Outputsize != "" {
q["outputsize"] = params.Outputsize
}
return r.client.get(ctx, "/api/v1/twelvedata/indicator/bbands", q)
}
// TwelvedataIndicatorAtrParams are the query parameters for Atr.
type TwelvedataIndicatorAtrParams struct {
Symbol string `json:"symbol,omitempty"`
Interval string `json:"interval,omitempty"`
TimePeriod string `json:"time_period,omitempty"`
Outputsize string `json:"outputsize,omitempty"`
}
// Average True Range (ATR) — $0.002/call
func (r *TwelvedataIndicator) Atr(ctx context.Context, params *TwelvedataIndicatorAtrParams) (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.Outputsize != "" {
q["outputsize"] = params.Outputsize
}
return r.client.get(ctx, "/api/v1/twelvedata/indicator/atr", q)
}
// TwelvedataMetals provides methods for Twelvedata metals endpoints.
type TwelvedataMetals struct {
client *Client
}
// TwelvedataMetalsPriceParams are the query parameters for Price.
type TwelvedataMetalsPriceParams struct {
Symbol string `json:"symbol,omitempty"`
}
// Precious metals real-time price (XAU/USD, XAG/USD, etc.) — $0.001/call
func (r *TwelvedataMetals) Price(ctx context.Context, params *TwelvedataMetalsPriceParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Symbol != "" {
q["symbol"] = params.Symbol
}
return r.client.get(ctx, "/api/v1/twelvedata/metals/price", q)
}
// TwelvedataMetalsTimeSeriesParams are the query parameters for TimeSeries.
type TwelvedataMetalsTimeSeriesParams struct {
Symbol string `json:"symbol,omitempty"`
Interval string `json:"interval,omitempty"`
Outputsize string `json:"outputsize,omitempty"`
StartDate string `json:"start_date,omitempty"`
EndDate string `json:"end_date,omitempty"`
}
// Precious metals historical bars — $0.002/call
func (r *TwelvedataMetals) TimeSeries(ctx context.Context, params *TwelvedataMetalsTimeSeriesParams) (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.StartDate != "" {
q["start_date"] = params.StartDate
}
if params != nil && params.EndDate != "" {
q["end_date"] = params.EndDate
}
return r.client.get(ctx, "/api/v1/twelvedata/metals/time-series", q)
}
// TwelvedataIndices provides methods for Twelvedata indices endpoints.
type TwelvedataIndices struct {
client *Client
}
// TwelvedataIndicesListParams are the query parameters for List.
type TwelvedataIndicesListParams struct {
Country string `json:"country,omitempty"`
}
// List of global indices — $0.001/call
func (r *TwelvedataIndices) List(ctx context.Context, params *TwelvedataIndicesListParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Country != "" {
q["country"] = params.Country
}
return r.client.get(ctx, "/api/v1/twelvedata/indices/list", q)
}
// TwelvedataIndicesQuoteParams are the query parameters for Quote.
type TwelvedataIndicesQuoteParams struct {
Symbol string `json:"symbol,omitempty"`
Interval string `json:"interval,omitempty"`
}
// Index detailed quote (S&P 500, Hang Seng, Nikkei, etc.) — $0.002/call
func (r *TwelvedataIndices) Quote(ctx context.Context, params *TwelvedataIndicesQuoteParams) (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
}
return r.client.get(ctx, "/api/v1/twelvedata/indices/quote", q)
}
// TwelvedataResource provides access to all Twelve Data API endpoints.
type TwelvedataResource struct {
client *Client
TimeSeries *TwelvedataTimeSeries
Indicator *TwelvedataIndicator
Metals *TwelvedataMetals
Indices *TwelvedataIndices
}
func newTwelvedataResource(c *Client) *TwelvedataResource {
return &TwelvedataResource{
client: c,
TimeSeries: &TwelvedataTimeSeries{client: c},
Indicator: &TwelvedataIndicator{client: c},
Metals: &TwelvedataMetals{client: c},
Indices: &TwelvedataIndices{client: c},
}
}
// TwelvedataPriceParams are the query parameters for Price.
type TwelvedataPriceParams struct {
Symbol string `json:"symbol,omitempty"`
}
// Real-time price for forex, metals, indices, or crypto — $0.001/call
func (r *TwelvedataResource) Price(ctx context.Context, params *TwelvedataPriceParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Symbol != "" {
q["symbol"] = params.Symbol
}
return r.client.get(ctx, "/api/v1/twelvedata/price", q)
}
// TwelvedataQuoteParams are the query parameters for Quote.
type TwelvedataQuoteParams struct {
Symbol string `json:"symbol,omitempty"`
Interval string `json:"interval,omitempty"`
}
// Detailed quote with OHLC, volume, 52-week high/low, etc. — $0.002/call
func (r *TwelvedataResource) Quote(ctx context.Context, params *TwelvedataQuoteParams) (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
}
return r.client.get(ctx, "/api/v1/twelvedata/quote", q)
}
// TwelvedataEodParams are the query parameters for Eod.
type TwelvedataEodParams struct {
Symbol string `json:"symbol,omitempty"`
}
// End-of-day closing price — $0.001/call
func (r *TwelvedataResource) Eod(ctx context.Context, params *TwelvedataEodParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Symbol != "" {
q["symbol"] = params.Symbol
}
return r.client.get(ctx, "/api/v1/twelvedata/eod", q)
}
// TwelvedataExchangeRateParams are the query parameters for ExchangeRate.
type TwelvedataExchangeRateParams struct {
Symbol string `json:"symbol,omitempty"`
}
// Currency exchange rate (e.g. USD/CNY, EUR/JPY) — $0.001/call
func (r *TwelvedataResource) ExchangeRate(ctx context.Context, params *TwelvedataExchangeRateParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Symbol != "" {
q["symbol"] = params.Symbol
}
return r.client.get(ctx, "/api/v1/twelvedata/exchange-rate", q)
}
// TwelvedataForexPairsParams are the query parameters for ForexPairs.
type TwelvedataForexPairsParams struct {
CurrencyBase string `json:"currency_base,omitempty"`
CurrencyQuote string `json:"currency_quote,omitempty"`
}
// List of available forex pairs — $0.001/call
func (r *TwelvedataResource) ForexPairs(ctx context.Context, params *TwelvedataForexPairsParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.CurrencyBase != "" {
q["currency_base"] = params.CurrencyBase
}
if params != nil && params.CurrencyQuote != "" {
q["currency_quote"] = params.CurrencyQuote
}
return r.client.get(ctx, "/api/v1/twelvedata/forex-pairs", q)
}
// TwelvedataGetTimeSeriesParams are the query parameters for GetTimeSeries.
type TwelvedataGetTimeSeriesParams struct {
Symbol string `json:"symbol,omitempty"`
Interval string `json:"interval,omitempty"`
Outputsize string `json:"outputsize,omitempty"`
StartDate string `json:"start_date,omitempty"`
EndDate string `json:"end_date,omitempty"`
}
// Historical OHLCV bars (1min to 1month intervals) — $0.002/call
func (r *TwelvedataResource) GetTimeSeries(ctx context.Context, params *TwelvedataGetTimeSeriesParams) (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.StartDate != "" {
q["start_date"] = params.StartDate
}
if params != nil && params.EndDate != "" {
q["end_date"] = params.EndDate
}
return r.client.get(ctx, "/api/v1/twelvedata/time-series", q)
}
// TwelvedataEconomicCalendarParams are the query parameters for EconomicCalendar.
type TwelvedataEconomicCalendarParams struct {
Country string `json:"country,omitempty"`
StartDate string `json:"start_date,omitempty"`
EndDate string `json:"end_date,omitempty"`
Importance string `json:"importance,omitempty"`
}
// Global economic calendar (NFP, CPI, rate decisions, etc.) — $0.003/call
func (r *TwelvedataResource) EconomicCalendar(ctx context.Context, params *TwelvedataEconomicCalendarParams) (json.RawMessage, error) {
q := map[string]string{}
if params != nil && params.Country != "" {
q["country"] = params.Country
}
if params != nil && params.StartDate != "" {
q["start_date"] = params.StartDate
}
if params != nil && params.EndDate != "" {
q["end_date"] = params.EndDate
}
if params != nil && params.Importance != "" {
q["importance"] = params.Importance
}
return r.client.get(ctx, "/api/v1/twelvedata/economic-calendar", q)
}