-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
equity_price.py
627 lines (596 loc) · 28.1 KB
/
equity_price.py
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
### THIS FILE IS AUTO-GENERATED. DO NOT EDIT. ###
import datetime
from typing import List, Literal, Optional, Union
from openbb_core.app.model.field import OpenBBField
from openbb_core.app.model.obbject import OBBject
from openbb_core.app.static.container import Container
from openbb_core.app.static.utils.decorators import exception_handler, validate
from openbb_core.app.static.utils.filters import filter_inputs
from typing_extensions import Annotated
class ROUTER_equity_price(Container):
"""/equity/price
historical
nbbo
performance
quote
"""
def __repr__(self) -> str:
return self.__doc__ or ""
@exception_handler
@validate
def historical(
self,
symbol: Annotated[
Union[str, List[str]],
OpenBBField(
description="Symbol to get data for. Multiple comma separated items allowed for provider(s): fmp, polygon, tiingo, yfinance."
),
],
start_date: Annotated[
Union[datetime.date, None, str],
OpenBBField(description="Start date of the data, in YYYY-MM-DD format."),
] = None,
end_date: Annotated[
Union[datetime.date, None, str],
OpenBBField(description="End date of the data, in YYYY-MM-DD format."),
] = None,
provider: Annotated[
Optional[Literal["fmp", "intrinio", "polygon", "tiingo", "yfinance"]],
OpenBBField(
description="The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: fmp, intrinio, polygon, tiingo, yfinance."
),
] = None,
**kwargs
) -> OBBject:
"""Get historical price data for a given stock. This includes open, high, low, close, and volume.
Parameters
----------
symbol : Union[str, List[str]]
Symbol to get data for. Multiple comma separated items allowed for provider(s): fmp, polygon, tiingo, yfinance.
start_date : Union[date, None, str]
Start date of the data, in YYYY-MM-DD format.
end_date : Union[date, None, str]
End date of the data, in YYYY-MM-DD format.
provider : Optional[Literal['fmp', 'intrinio', 'polygon', 'tiingo', 'yfinance']]
The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: fmp, intrinio, polygon, tiingo, yfinance.
interval : Union[Literal['1m', '5m', '15m', '30m', '1h', '4h', '1d'], Literal['1m', '5m', '10m', '15m', '30m', '60m', '1h', '1d', '1W', '1M', '1Q', '1Y'], str, Literal['1m', '5m', '15m', '30m', '90m', '1h', '2h', '4h', '1d', '1W', '1M', '1Y'], Literal['1m', '2m', '5m', '15m', '30m', '60m', '90m', '1h', '1d', '5d', '1W', '1M', '1Q']]
Time interval of the data to return. (provider: fmp, intrinio, polygon, tiingo, yfinance)
start_time : Optional[datetime.time]
Return intervals starting at the specified time on the `start_date` formatted as 'HH:MM:SS'. (provider: intrinio)
end_time : Optional[datetime.time]
Return intervals stopping at the specified time on the `end_date` formatted as 'HH:MM:SS'. (provider: intrinio)
timezone : Optional[str]
Timezone of the data, in the IANA format (Continent/City). (provider: intrinio)
source : Literal['realtime', 'delayed', 'nasdaq_basic']
The source of the data. (provider: intrinio)
adjustment : Union[Literal['splits_only', 'unadjusted'], Literal['splits_only', 'splits_and_dividends']]
The adjustment factor to apply. Default is splits only. (provider: polygon, yfinance)
extended_hours : bool
Include Pre and Post market data. (provider: polygon, yfinance)
sort : Literal['asc', 'desc']
Sort order of the data. This impacts the results in combination with the 'limit' parameter. The results are always returned in ascending order by date. (provider: polygon)
limit : int
The number of data entries to return. (provider: polygon)
include_actions : bool
Include dividends and stock splits in results. (provider: yfinance)
Returns
-------
OBBject
results : List[EquityHistorical]
Serializable results.
provider : Optional[Literal['fmp', 'intrinio', 'polygon', 'tiingo', 'yfinance']]
Provider name.
warnings : Optional[List[Warning_]]
List of warnings.
chart : Optional[Chart]
Chart object.
extra : Dict[str, Any]
Extra info.
EquityHistorical
----------------
date : Union[date, datetime]
The date of the data.
open : float
The open price.
high : float
The high price.
low : float
The low price.
close : float
The close price.
volume : Optional[Union[int, float]]
The trading volume.
vwap : Optional[float]
Volume Weighted Average Price over the period.
adj_close : Optional[float]
The adjusted close price. (provider: fmp, intrinio, tiingo)
unadjusted_volume : Optional[float]
Unadjusted volume of the symbol. (provider: fmp)
change : Optional[float]
Change in the price from the previous close. (provider: fmp);
Change in the price of the symbol from the previous day. (provider: intrinio)
change_percent : Optional[float]
Change in the price from the previous close, as a normalized percent. (provider: fmp);
Percent change in the price of the symbol from the previous day. (provider: intrinio)
average : Optional[float]
Average trade price of an individual equity during the interval. (provider: intrinio)
adj_open : Optional[float]
The adjusted open price. (provider: intrinio, tiingo)
adj_high : Optional[float]
The adjusted high price. (provider: intrinio, tiingo)
adj_low : Optional[float]
The adjusted low price. (provider: intrinio, tiingo)
adj_volume : Optional[float]
The adjusted volume. (provider: intrinio, tiingo)
fifty_two_week_high : Optional[float]
52 week high price for the symbol. (provider: intrinio)
fifty_two_week_low : Optional[float]
52 week low price for the symbol. (provider: intrinio)
factor : Optional[float]
factor by which to multiply equity prices before this date, in order to calculate historically-adjusted equity prices. (provider: intrinio)
split_ratio : Optional[float]
Ratio of the equity split, if a split occurred. (provider: intrinio, tiingo, yfinance)
dividend : Optional[float]
Dividend amount, if a dividend was paid. (provider: intrinio, tiingo, yfinance)
close_time : Optional[datetime]
The timestamp that represents the end of the interval span. (provider: intrinio)
interval : Optional[str]
The data time frequency. (provider: intrinio)
intra_period : Optional[bool]
If true, the equity price represents an unfinished period (be it day, week, quarter, month, or year), meaning that the close price is the latest price available, not the official close price for the period (provider: intrinio)
transactions : Optional[Annotated[int, Gt(gt=0)]]
Number of transactions for the symbol in the time period. (provider: polygon)
Examples
--------
>>> from openbb import obb
>>> obb.equity.price.historical(symbol='AAPL', provider='fmp')
>>> obb.equity.price.historical(symbol='AAPL', interval='1d', provider='intrinio')
""" # noqa: E501
return self._run(
"/equity/price/historical",
**filter_inputs(
provider_choices={
"provider": self._get_provider(
provider,
"equity.price.historical",
("fmp", "intrinio", "polygon", "tiingo", "yfinance"),
)
},
standard_params={
"symbol": symbol,
"start_date": start_date,
"end_date": end_date,
},
extra_params=kwargs,
info={
"symbol": {
"fmp": {"multiple_items_allowed": True, "choices": None},
"polygon": {"multiple_items_allowed": True, "choices": None},
"tiingo": {"multiple_items_allowed": True, "choices": None},
"yfinance": {"multiple_items_allowed": True, "choices": None},
},
"interval": {
"fmp": {
"multiple_items_allowed": False,
"choices": ["1m", "5m", "15m", "30m", "1h", "4h", "1d"],
},
"intrinio": {
"multiple_items_allowed": False,
"choices": [
"1m",
"5m",
"10m",
"15m",
"30m",
"60m",
"1h",
"1d",
"1W",
"1M",
"1Q",
"1Y",
],
},
"tiingo": {
"multiple_items_allowed": False,
"choices": [
"1m",
"5m",
"15m",
"30m",
"90m",
"1h",
"2h",
"4h",
"1d",
"1W",
"1M",
"1Y",
],
},
"yfinance": {
"multiple_items_allowed": False,
"choices": [
"1m",
"2m",
"5m",
"15m",
"30m",
"60m",
"90m",
"1h",
"1d",
"5d",
"1W",
"1M",
"1Q",
],
},
},
},
)
)
@exception_handler
@validate
def nbbo(
self,
symbol: Annotated[str, OpenBBField(description="Symbol to get data for.")],
provider: Annotated[
Optional[Literal["polygon"]],
OpenBBField(
description="The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: polygon."
),
] = None,
**kwargs
) -> OBBject:
"""Get the National Best Bid and Offer for a given stock.
Parameters
----------
symbol : str
Symbol to get data for.
provider : Optional[Literal['polygon']]
The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: polygon.
limit : int
The number of data entries to return. Up to ten million records will be returned. Pagination occurs in groups of 50,000. Remaining limit values will always return 50,000 more records unless it is the last page. High volume tickers will require multiple max requests for a single day's NBBO records. Expect stocks, like SPY, to approach 1GB in size, per day, as a raw CSV. Splitting large requests into chunks is recommended for full-day requests of high-volume symbols. (provider: polygon)
date : Optional[datetime.date]
A specific date to get data for. Use bracketed the timestamp parameters to specify exact time ranges. (provider: polygon)
timestamp_lt : Optional[Union[datetime.datetime, str]]
Query by datetime, less than. Either a date with the format 'YYYY-MM-DD' or a TZ-aware timestamp string, 'YYYY-MM-DDTH:M:S.000000000-04:00'. Include all nanoseconds and the 'T' between the day and hour. (provider: polygon)
timestamp_gt : Optional[Union[datetime.datetime, str]]
Query by datetime, greater than. Either a date with the format 'YYYY-MM-DD' or a TZ-aware timestamp string, 'YYYY-MM-DDTH:M:S.000000000-04:00'. Include all nanoseconds and the 'T' between the day and hour. (provider: polygon)
timestamp_lte : Optional[Union[datetime.datetime, str]]
Query by datetime, less than or equal to. Either a date with the format 'YYYY-MM-DD' or a TZ-aware timestamp string, 'YYYY-MM-DDTH:M:S.000000000-04:00'. Include all nanoseconds and the 'T' between the day and hour. (provider: polygon)
timestamp_gte : Optional[Union[datetime.datetime, str]]
Query by datetime, greater than or equal to. Either a date with the format 'YYYY-MM-DD' or a TZ-aware timestamp string, 'YYYY-MM-DDTH:M:S.000000000-04:00'. Include all nanoseconds and the 'T' between the day and hour. (provider: polygon)
Returns
-------
OBBject
results : List[EquityNBBO]
Serializable results.
provider : Optional[Literal['polygon']]
Provider name.
warnings : Optional[List[Warning_]]
List of warnings.
chart : Optional[Chart]
Chart object.
extra : Dict[str, Any]
Extra info.
EquityNBBO
----------
ask_exchange : str
The exchange ID for the ask.
ask : float
The last ask price.
ask_size : int
The ask size. This represents the number of round lot orders at the given ask price.
The normal round lot size is 100 shares.
An ask size of 2 means there are 200 shares available to purchase at the given ask price.
bid_size : int
The bid size in round lots.
bid : float
The last bid price.
bid_exchange : str
The exchange ID for the bid.
tape : Optional[str]
The exchange tape. (provider: polygon)
conditions : Optional[Union[str, List[int], List[str]]]
A list of condition codes. (provider: polygon)
indicators : Optional[List[int]]
A list of indicator codes. (provider: polygon)
sequence_num : Optional[int]
The sequence number represents the sequence in which message events happened. These are increasing and unique per ticker symbol, but will not always be sequential (e.g., 1, 2, 6, 9, 10, 11) (provider: polygon)
participant_timestamp : Optional[datetime]
The nanosecond accuracy Participant/Exchange Unix Timestamp. This is the timestamp of when the quote was actually generated at the exchange. (provider: polygon)
sip_timestamp : Optional[datetime]
The nanosecond accuracy SIP Unix Timestamp. This is the timestamp of when the SIP received this quote from the exchange which produced it. (provider: polygon)
trf_timestamp : Optional[datetime]
The nanosecond accuracy TRF (Trade Reporting Facility) Unix Timestamp. This is the timestamp of when the trade reporting facility received this quote. (provider: polygon)
Examples
--------
>>> from openbb import obb
>>> obb.equity.price.nbbo(symbol='AAPL', provider='polygon')
""" # noqa: E501
return self._run(
"/equity/price/nbbo",
**filter_inputs(
provider_choices={
"provider": self._get_provider(
provider,
"equity.price.nbbo",
("polygon",),
)
},
standard_params={
"symbol": symbol,
},
extra_params=kwargs,
)
)
@exception_handler
@validate
def performance(
self,
symbol: Annotated[
Union[str, List[str]],
OpenBBField(
description="Symbol to get data for. Multiple comma separated items allowed for provider(s): fmp."
),
],
provider: Annotated[
Optional[Literal["fmp"]],
OpenBBField(
description="The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: fmp."
),
] = None,
**kwargs
) -> OBBject:
"""Get price performance data for a given stock. This includes price changes for different time periods.
Parameters
----------
symbol : Union[str, List[str]]
Symbol to get data for. Multiple comma separated items allowed for provider(s): fmp.
provider : Optional[Literal['fmp']]
The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: fmp.
Returns
-------
OBBject
results : List[PricePerformance]
Serializable results.
provider : Optional[Literal['fmp']]
Provider name.
warnings : Optional[List[Warning_]]
List of warnings.
chart : Optional[Chart]
Chart object.
extra : Dict[str, Any]
Extra info.
PricePerformance
----------------
symbol : Optional[str]
Symbol representing the entity requested in the data.
one_day : Optional[float]
One-day return.
wtd : Optional[float]
Week to date return.
one_week : Optional[float]
One-week return.
mtd : Optional[float]
Month to date return.
one_month : Optional[float]
One-month return.
qtd : Optional[float]
Quarter to date return.
three_month : Optional[float]
Three-month return.
six_month : Optional[float]
Six-month return.
ytd : Optional[float]
Year to date return.
one_year : Optional[float]
One-year return.
two_year : Optional[float]
Two-year return.
three_year : Optional[float]
Three-year return.
four_year : Optional[float]
Four-year
five_year : Optional[float]
Five-year return.
ten_year : Optional[float]
Ten-year return.
max : Optional[float]
Return from the beginning of the time series.
Examples
--------
>>> from openbb import obb
>>> obb.equity.price.performance(symbol='AAPL', provider='fmp')
""" # noqa: E501
return self._run(
"/equity/price/performance",
**filter_inputs(
provider_choices={
"provider": self._get_provider(
provider,
"equity.price.performance",
("fmp",),
)
},
standard_params={
"symbol": symbol,
},
extra_params=kwargs,
info={
"symbol": {"fmp": {"multiple_items_allowed": True, "choices": None}}
},
)
)
@exception_handler
@validate
def quote(
self,
symbol: Annotated[
Union[str, List[str]],
OpenBBField(
description="Symbol to get data for. Multiple comma separated items allowed for provider(s): fmp, intrinio, yfinance."
),
],
provider: Annotated[
Optional[Literal["fmp", "intrinio", "yfinance"]],
OpenBBField(
description="The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: fmp, intrinio, yfinance."
),
] = None,
**kwargs
) -> OBBject:
"""Get the latest quote for a given stock. Quote includes price, volume, and other data.
Parameters
----------
symbol : Union[str, List[str]]
Symbol to get data for. Multiple comma separated items allowed for provider(s): fmp, intrinio, yfinance.
provider : Optional[Literal['fmp', 'intrinio', 'yfinance']]
The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: fmp, intrinio, yfinance.
source : Literal['iex', 'bats', 'bats_delayed', 'utp_delayed', 'cta_a_delayed', 'cta_b_delayed', 'intrinio_mx', 'intrinio_mx_plus', 'delayed_sip']
Source of the data. (provider: intrinio)
Returns
-------
OBBject
results : List[EquityQuote]
Serializable results.
provider : Optional[Literal['fmp', 'intrinio', 'yfinance']]
Provider name.
warnings : Optional[List[Warning_]]
List of warnings.
chart : Optional[Chart]
Chart object.
extra : Dict[str, Any]
Extra info.
EquityQuote
-----------
symbol : str
Symbol representing the entity requested in the data.
asset_type : Optional[str]
Type of asset - i.e, stock, ETF, etc.
name : Optional[str]
Name of the company or asset.
exchange : Optional[str]
The name or symbol of the venue where the data is from.
bid : Optional[float]
Price of the top bid order.
bid_size : Optional[int]
This represents the number of round lot orders at the given price. The normal round lot size is 100 shares. A size of 2 means there are 200 shares available at the given price.
bid_exchange : Optional[str]
The specific trading venue where the purchase order was placed.
ask : Optional[float]
Price of the top ask order.
ask_size : Optional[int]
This represents the number of round lot orders at the given price. The normal round lot size is 100 shares. A size of 2 means there are 200 shares available at the given price.
ask_exchange : Optional[str]
The specific trading venue where the sale order was placed.
quote_conditions : Optional[Union[str, int, List[str], List[int]]]
Conditions or condition codes applicable to the quote.
quote_indicators : Optional[Union[str, int, List[str], List[int]]]
Indicators or indicator codes applicable to the participant quote related to the price bands for the issue, or the affect the quote has on the NBBO.
sales_conditions : Optional[Union[str, int, List[str], List[int]]]
Conditions or condition codes applicable to the sale.
sequence_number : Optional[int]
The sequence number represents the sequence in which message events happened. These are increasing and unique per ticker symbol, but will not always be sequential (e.g., 1, 2, 6, 9, 10, 11).
market_center : Optional[str]
The ID of the UTP participant that originated the message.
participant_timestamp : Optional[datetime]
Timestamp for when the quote was generated by the exchange.
trf_timestamp : Optional[datetime]
Timestamp for when the TRF (Trade Reporting Facility) received the message.
sip_timestamp : Optional[datetime]
Timestamp for when the SIP (Security Information Processor) received the message from the exchange.
last_price : Optional[float]
Price of the last trade.
last_tick : Optional[str]
Whether the last sale was an up or down tick.
last_size : Optional[int]
Size of the last trade.
last_timestamp : Optional[datetime]
Date and Time when the last price was recorded.
open : Optional[float]
The open price.
high : Optional[float]
The high price.
low : Optional[float]
The low price.
close : Optional[float]
The close price.
volume : Optional[Union[int, float]]
The trading volume.
exchange_volume : Optional[Union[int, float]]
Volume of shares exchanged during the trading day on the specific exchange.
prev_close : Optional[float]
The previous close price.
change : Optional[float]
Change in price from previous close.
change_percent : Optional[float]
Change in price as a normalized percentage.
year_high : Optional[float]
The one year high (52W High).
year_low : Optional[float]
The one year low (52W Low).
price_avg50 : Optional[float]
50 day moving average price. (provider: fmp)
price_avg200 : Optional[float]
200 day moving average price. (provider: fmp)
avg_volume : Optional[int]
Average volume over the last 10 trading days. (provider: fmp)
market_cap : Optional[float]
Market cap of the company. (provider: fmp)
shares_outstanding : Optional[int]
Number of shares outstanding. (provider: fmp)
eps : Optional[float]
Earnings per share. (provider: fmp)
pe : Optional[float]
Price earnings ratio. (provider: fmp)
earnings_announcement : Optional[datetime]
Upcoming earnings announcement date. (provider: fmp)
is_darkpool : Optional[bool]
Whether or not the current trade is from a darkpool. (provider: intrinio)
source : Optional[str]
Source of the Intrinio data. (provider: intrinio)
updated_on : Optional[datetime]
Date and Time when the data was last updated. (provider: intrinio)
security : Optional[IntrinioSecurity]
Security details related to the quote. (provider: intrinio)
ma_50d : Optional[float]
50-day moving average price. (provider: yfinance)
ma_200d : Optional[float]
200-day moving average price. (provider: yfinance)
volume_average : Optional[float]
Average daily trading volume. (provider: yfinance)
volume_average_10d : Optional[float]
Average daily trading volume in the last 10 days. (provider: yfinance)
currency : Optional[str]
Currency of the price. (provider: yfinance)
Examples
--------
>>> from openbb import obb
>>> obb.equity.price.quote(symbol='AAPL', provider='fmp')
""" # noqa: E501
return self._run(
"/equity/price/quote",
**filter_inputs(
provider_choices={
"provider": self._get_provider(
provider,
"equity.price.quote",
("fmp", "intrinio", "yfinance"),
)
},
standard_params={
"symbol": symbol,
},
extra_params=kwargs,
info={
"symbol": {
"fmp": {"multiple_items_allowed": True, "choices": None},
"intrinio": {"multiple_items_allowed": True, "choices": None},
"yfinance": {"multiple_items_allowed": True, "choices": None},
}
},
)
)