alpaca-py-nopandas 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. alpaca/__init__.py +2 -0
  2. alpaca/broker/__init__.py +8 -0
  3. alpaca/broker/client.py +2360 -0
  4. alpaca/broker/enums.py +528 -0
  5. alpaca/broker/models/__init__.py +7 -0
  6. alpaca/broker/models/accounts.py +347 -0
  7. alpaca/broker/models/cip.py +265 -0
  8. alpaca/broker/models/documents.py +159 -0
  9. alpaca/broker/models/funding.py +114 -0
  10. alpaca/broker/models/journals.py +71 -0
  11. alpaca/broker/models/rebalancing.py +80 -0
  12. alpaca/broker/models/trading.py +13 -0
  13. alpaca/broker/requests.py +1135 -0
  14. alpaca/common/__init__.py +6 -0
  15. alpaca/common/constants.py +13 -0
  16. alpaca/common/enums.py +64 -0
  17. alpaca/common/exceptions.py +47 -0
  18. alpaca/common/models.py +21 -0
  19. alpaca/common/requests.py +82 -0
  20. alpaca/common/rest.py +438 -0
  21. alpaca/common/types.py +7 -0
  22. alpaca/common/utils.py +89 -0
  23. alpaca/data/__init__.py +5 -0
  24. alpaca/data/enums.py +184 -0
  25. alpaca/data/historical/__init__.py +13 -0
  26. alpaca/data/historical/corporate_actions.py +76 -0
  27. alpaca/data/historical/crypto.py +299 -0
  28. alpaca/data/historical/news.py +63 -0
  29. alpaca/data/historical/option.py +230 -0
  30. alpaca/data/historical/screener.py +72 -0
  31. alpaca/data/historical/stock.py +226 -0
  32. alpaca/data/historical/utils.py +30 -0
  33. alpaca/data/live/__init__.py +11 -0
  34. alpaca/data/live/crypto.py +168 -0
  35. alpaca/data/live/news.py +62 -0
  36. alpaca/data/live/option.py +88 -0
  37. alpaca/data/live/stock.py +199 -0
  38. alpaca/data/live/websocket.py +390 -0
  39. alpaca/data/mappings.py +84 -0
  40. alpaca/data/models/__init__.py +7 -0
  41. alpaca/data/models/bars.py +83 -0
  42. alpaca/data/models/base.py +45 -0
  43. alpaca/data/models/corporate_actions.py +309 -0
  44. alpaca/data/models/news.py +90 -0
  45. alpaca/data/models/orderbooks.py +59 -0
  46. alpaca/data/models/quotes.py +78 -0
  47. alpaca/data/models/screener.py +68 -0
  48. alpaca/data/models/snapshots.py +132 -0
  49. alpaca/data/models/trades.py +204 -0
  50. alpaca/data/requests.py +580 -0
  51. alpaca/data/timeframe.py +148 -0
  52. alpaca/py.typed +0 -0
  53. alpaca/trading/__init__.py +5 -0
  54. alpaca/trading/client.py +784 -0
  55. alpaca/trading/enums.py +412 -0
  56. alpaca/trading/models.py +697 -0
  57. alpaca/trading/requests.py +604 -0
  58. alpaca/trading/stream.py +225 -0
  59. alpaca_py_nopandas-0.1.0.dist-info/LICENSE +201 -0
  60. alpaca_py_nopandas-0.1.0.dist-info/METADATA +299 -0
  61. alpaca_py_nopandas-0.1.0.dist-info/RECORD +62 -0
  62. alpaca_py_nopandas-0.1.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,132 @@
1
+ from typing import Dict, Optional
2
+
3
+ from alpaca.common.models import ValidateBaseModel as BaseModel
4
+ from alpaca.common.types import RawData
5
+ from alpaca.data.mappings import SNAPSHOT_MAPPING
6
+ from alpaca.data.models import Bar, Quote, Trade
7
+
8
+
9
+ class Snapshot(BaseModel):
10
+ """A Snapshot contains the latest trade, latest quote, minute bar daily bar
11
+ and previous daily bar data for a given ticker symbol.
12
+
13
+ Attributes:
14
+ symbol (str): The identifier for the snapshot security.
15
+ latest_trade (Optional[Trade]): The latest transaction on the price and sales tape
16
+ latest_quote (Optional[Quote]): Level 1 ask/bid pair quote data.
17
+ minute_bar (Optional[Bar]): The latest minute OHLC bar data
18
+ daily_bar (Optional[Bar]): The latest daily OHLC bar data
19
+ previous_daily_bar (Optional[Bar]): The 2nd to latest (2 trading days ago) daily OHLC bar data
20
+ """
21
+
22
+ symbol: str
23
+ latest_trade: Optional[Trade] = None
24
+ latest_quote: Optional[Quote] = None
25
+ minute_bar: Optional[Bar] = None
26
+ daily_bar: Optional[Bar] = None
27
+ previous_daily_bar: Optional[Bar] = None
28
+
29
+ def __init__(self, symbol: str, raw_data: Dict[str, RawData]) -> None:
30
+ """Instantiates a Snapshot.
31
+
32
+ Args:
33
+ symbol (str): The identifier for the snapshot security.
34
+ raw_data (Dict[str, RawData]): The raw API snapshot data keyed by symbol
35
+ """
36
+ mapped_snapshot = {
37
+ SNAPSHOT_MAPPING.get(key): val
38
+ for key, val in raw_data.items()
39
+ if key in SNAPSHOT_MAPPING
40
+ }
41
+
42
+ # Parse each data type
43
+ if mapped_snapshot.get("latest_trade", None) is not None:
44
+ mapped_snapshot["latest_trade"] = Trade(
45
+ symbol, mapped_snapshot["latest_trade"]
46
+ )
47
+ if mapped_snapshot.get("latest_quote", None) is not None:
48
+ mapped_snapshot["latest_quote"] = Quote(
49
+ symbol, mapped_snapshot["latest_quote"]
50
+ )
51
+ if mapped_snapshot.get("minute_bar", None) is not None:
52
+ mapped_snapshot["minute_bar"] = Bar(symbol, mapped_snapshot["minute_bar"])
53
+ if mapped_snapshot.get("daily_bar", None) is not None:
54
+ mapped_snapshot["daily_bar"] = Bar(symbol, mapped_snapshot["daily_bar"])
55
+ if mapped_snapshot.get("previous_daily_bar", None) is not None:
56
+ mapped_snapshot["previous_daily_bar"] = Bar(
57
+ symbol, mapped_snapshot["previous_daily_bar"]
58
+ )
59
+
60
+ super().__init__(symbol=symbol, **mapped_snapshot)
61
+
62
+
63
+ class OptionsGreeks(BaseModel):
64
+ """Options Greeks are a set of risk measures that are used in the options market to evaluate the risk and reward of an option.
65
+
66
+ Attributes:
67
+ delta (float): The rate of change of an option's price relative to a change in the price of the underlying asset.
68
+ gamma (float): The rate of change in an option's delta relative to a change in the price of the underlying asset.
69
+ rho (float): The rate of change in an option's price relative to a change in the risk-free rate of interest.
70
+ theta (float): The rate of change in an option's price relative to a change in time.
71
+ vega (float): The rate of change in an option's price relative to a change in the volatility of the underlying asset.
72
+ """
73
+
74
+ delta: float
75
+ gamma: float
76
+ rho: float
77
+ theta: float
78
+ vega: float
79
+
80
+ def __init__(self, raw_data: RawData) -> None:
81
+ """Instantiates an OptionGreeks object.
82
+
83
+ Args:
84
+ raw_data (RawData): The raw API option greeks data
85
+ """
86
+ super().__init__(**raw_data)
87
+
88
+
89
+ class OptionsSnapshot(BaseModel):
90
+ """An options snapshot contains the latest trade, latest quote, greeks
91
+ and implied volatility data for a given symbol.
92
+
93
+ Attributes:
94
+ symbol (str): The identifier for the snapshot security.
95
+ latest_trade (Optional[Trade]): The latest transaction on the price and sales tape
96
+ latest_quote (Optional[Quote]): Level 1 ask/bid pair quote data.
97
+ implied_volatility (Optional[float]): The implied volatility of the option
98
+ greeks (Optional[OptionGreeks]): The option greeks data
99
+ """
100
+
101
+ symbol: str
102
+ latest_trade: Optional[Trade] = None
103
+ latest_quote: Optional[Quote] = None
104
+ implied_volatility: Optional[float] = None
105
+ greeks: Optional[OptionsGreeks] = None
106
+
107
+ def __init__(self, symbol: str, raw_data: Dict[str, RawData]) -> None:
108
+ """Instantiates a Snapshot.
109
+
110
+ Args:
111
+ symbol (str): The identifier for the snapshot security.
112
+ raw_data (Dict[str, RawData]): The raw API snapshot data keyed by symbol
113
+ """
114
+ mapped_snapshot = {
115
+ SNAPSHOT_MAPPING.get(key): val
116
+ for key, val in raw_data.items()
117
+ if key in SNAPSHOT_MAPPING
118
+ }
119
+
120
+ # Parse each data type
121
+ if mapped_snapshot.get("latest_trade", None) is not None:
122
+ mapped_snapshot["latest_trade"] = Trade(
123
+ symbol, mapped_snapshot["latest_trade"]
124
+ )
125
+ if mapped_snapshot.get("latest_quote", None) is not None:
126
+ mapped_snapshot["latest_quote"] = Quote(
127
+ symbol, mapped_snapshot["latest_quote"]
128
+ )
129
+ if mapped_snapshot.get("greeks", None) is not None:
130
+ mapped_snapshot["greeks"] = OptionsGreeks(mapped_snapshot["greeks"])
131
+
132
+ super().__init__(symbol=symbol, **mapped_snapshot)
@@ -0,0 +1,204 @@
1
+ from datetime import datetime
2
+ from typing import Dict, List, Optional, Union
3
+
4
+ from alpaca.common.models import ValidateBaseModel as BaseModel
5
+ from alpaca.common.types import RawData
6
+ from alpaca.data.enums import Exchange
7
+ from alpaca.data.mappings import (
8
+ TRADE_CANCEL_MAPPING,
9
+ TRADE_CORRECTION_MAPPING,
10
+ TRADE_MAPPING,
11
+ TRADING_STATUS_MAPPING,
12
+ )
13
+ from alpaca.data.models.base import BaseDataSet, TimeSeriesMixin
14
+
15
+
16
+ class Trade(BaseModel):
17
+ """A transaction from the price and sales history of a security.
18
+
19
+ Attributes:
20
+ symbol (str): The ticker identifier for the security whose data forms the trade.
21
+ timestamp (datetime): The time of submission of the trade.
22
+ exchange (Optional[Exchange]): The exchange the trade occurred.
23
+ price (float): The price that the transaction occurred at.
24
+ size (float): The quantity traded
25
+ id (Optional[int]): The trade ID
26
+ conditions (Optional[Union[List[str], str]]): The trade conditions. Defaults to None.
27
+ tape (Optional[str]): The trade tape. Defaults to None.
28
+ """
29
+
30
+ symbol: str
31
+ timestamp: datetime
32
+ exchange: Optional[Union[Exchange, str]] = None
33
+ price: float
34
+ size: float
35
+ id: Optional[int] = None
36
+ conditions: Optional[Union[List[str], str]] = None
37
+ tape: Optional[str] = None
38
+
39
+ def __init__(self, symbol: str, raw_data: RawData) -> None:
40
+ """Instantiates a Trade object
41
+
42
+ Args:
43
+ symbol (str): The security identifier for the trade that occurred.
44
+ raw_data (RawData): The trade data as received by API.
45
+ """
46
+
47
+ mapped_trade = {
48
+ TRADE_MAPPING.get(key): val
49
+ for key, val in raw_data.items()
50
+ if key in TRADE_MAPPING
51
+ }
52
+
53
+ super().__init__(symbol=symbol, **mapped_trade)
54
+
55
+
56
+ class TradeSet(BaseDataSet, TimeSeriesMixin):
57
+ """A collection of Trade objects.
58
+
59
+ Attributes:
60
+ data (Dict[str, List[Trade]]]): The collection of Trades keyed by symbol.
61
+ """
62
+
63
+ data: Dict[str, List[Trade]] = {}
64
+
65
+ def __init__(self, raw_data: RawData) -> None:
66
+ """Instantiates a TradeSet - a collection of Trades.
67
+
68
+ Args:
69
+ raw_data (RawData): The raw trade data received from API keyed by symbol
70
+ """
71
+ parsed_trades = {}
72
+
73
+ if raw_data is not None:
74
+ for symbol, trades in raw_data.items():
75
+ parsed_trades[symbol] = [
76
+ Trade(symbol, trade) for trade in trades if trade is not None
77
+ ]
78
+
79
+ super().__init__(data=parsed_trades)
80
+
81
+
82
+ class TradingStatus(BaseModel):
83
+ """Trading status update of a security, for example if a symbol gets halted.
84
+
85
+ Attributes:
86
+ symbol (str): The ticker identifier.
87
+ timestamp (datetime): The time of trading status.
88
+ status_code (str): The tape-dependent code of the status.
89
+ status_message (str): The status message.
90
+ reason_code (str): The tape-dependent code of the halt reason.
91
+ reason_message (str): The reason message.
92
+ tape (Optional[str]): The tape (A, B or C).
93
+ """
94
+
95
+ symbol: str
96
+ timestamp: datetime
97
+ status_code: str
98
+ status_message: str
99
+ reason_code: str
100
+ reason_message: str
101
+ tape: str
102
+
103
+ def __init__(self, symbol: str, raw_data: RawData) -> None:
104
+ """Instantiates a Trading status object
105
+
106
+ Args:
107
+ symbol (str): The security identifier
108
+ raw_data (RawData): The raw data as received by API.
109
+ """
110
+
111
+ mapped = {
112
+ TRADING_STATUS_MAPPING.get(key): val
113
+ for key, val in raw_data.items()
114
+ if key in TRADING_STATUS_MAPPING
115
+ }
116
+
117
+ super().__init__(symbol=symbol, **mapped)
118
+
119
+
120
+ class TradeCancel(BaseModel):
121
+ """Cancel of a previous trade.
122
+
123
+ Attributes:
124
+ symbol (str): The ticker identifier.
125
+ timestamp (datetime): The timestamp.
126
+ exchange (Exchange): The exchange.
127
+ price (float): The price of the canceled trade.
128
+ size (float): The size of the canceled trade.
129
+ id (Optional[int]): The original ID of the canceled trade.
130
+ action (Optional[str]): The cancel action ("C" for cancel, "E" for error)
131
+ tape (str): The trade tape. Defaults to None.
132
+ """
133
+
134
+ symbol: str
135
+ timestamp: datetime
136
+ exchange: Exchange
137
+ price: float
138
+ size: float
139
+ id: Optional[int] = None
140
+ action: Optional[str] = None
141
+ tape: str
142
+
143
+ def __init__(self, symbol: str, raw_data: RawData) -> None:
144
+ """Instantiates a trade cancel object
145
+
146
+ Args:
147
+ symbol (str): The security identifier
148
+ raw_data (RawData): The raw data as received by API.
149
+ """
150
+
151
+ mapped = {
152
+ TRADE_CANCEL_MAPPING.get(key): val
153
+ for key, val in raw_data.items()
154
+ if key in TRADE_CANCEL_MAPPING
155
+ }
156
+
157
+ super().__init__(symbol=symbol, **mapped)
158
+
159
+
160
+ class TradeCorrection(BaseModel):
161
+ """Correction of a previous trade.
162
+
163
+ Attributes:
164
+ symbol (str): The ticker identifier.
165
+ timestamp (datetime): The timestamp.
166
+ exchange (Exchange): The exchange.
167
+ original_id (Optional[int]): The original ID of the corrected trade.
168
+ original_price (float): The original price of the corrected trade.
169
+ original_size (float): The original size of the corrected trade.
170
+ original_conditions (List[str]): The original conditions of the corrected trade.
171
+ corrected_id (Optional[int]): The corrected ID of the corrected trade.
172
+ corrected_price (float): The corrected price of the corrected trade.
173
+ corrected_size (float): The corrected size of the corrected trade.
174
+ corrected_conditions (List[str]): The corrected conditions of the corrected trade.
175
+ tape (str): The trade tape. Defaults to None.
176
+ """
177
+
178
+ symbol: str
179
+ timestamp: datetime
180
+ exchange: Exchange
181
+ original_id: Optional[int] = None
182
+ original_price: float
183
+ original_size: float
184
+ original_conditions: List[str]
185
+ corrected_id: Optional[int] = None
186
+ corrected_price: float
187
+ corrected_size: float
188
+ corrected_conditions: List[str]
189
+ tape: str
190
+
191
+ def __init__(self, symbol: str, raw_data: RawData) -> None:
192
+ """Instantiates a trade correction object
193
+
194
+ Args:
195
+ symbol (str): The security identifier
196
+ raw_data (RawData): The raw data as received by API.
197
+ """
198
+ mapped = {
199
+ TRADE_CORRECTION_MAPPING.get(key): val
200
+ for key, val in raw_data.items()
201
+ if key in TRADE_CORRECTION_MAPPING
202
+ }
203
+
204
+ super().__init__(symbol=symbol, **mapped)