alpaca-py-nopandas 0.1.0__tar.gz → 0.1.2__tar.gz

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 (64) hide show
  1. alpaca_py_nopandas-0.1.2/PKG-INFO +40 -0
  2. alpaca_py_nopandas-0.1.2/README.md +13 -0
  3. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/pyproject.toml +3 -1
  4. alpaca_py_nopandas-0.1.0/PKG-INFO +0 -299
  5. alpaca_py_nopandas-0.1.0/README.md +0 -274
  6. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/LICENSE +0 -0
  7. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/__init__.py +0 -0
  8. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/broker/__init__.py +0 -0
  9. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/broker/client.py +0 -0
  10. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/broker/enums.py +0 -0
  11. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/broker/models/__init__.py +0 -0
  12. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/broker/models/accounts.py +0 -0
  13. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/broker/models/cip.py +0 -0
  14. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/broker/models/documents.py +0 -0
  15. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/broker/models/funding.py +0 -0
  16. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/broker/models/journals.py +0 -0
  17. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/broker/models/rebalancing.py +0 -0
  18. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/broker/models/trading.py +0 -0
  19. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/broker/requests.py +0 -0
  20. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/common/__init__.py +0 -0
  21. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/common/constants.py +0 -0
  22. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/common/enums.py +0 -0
  23. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/common/exceptions.py +0 -0
  24. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/common/models.py +0 -0
  25. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/common/requests.py +0 -0
  26. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/common/rest.py +0 -0
  27. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/common/types.py +0 -0
  28. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/common/utils.py +0 -0
  29. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/__init__.py +0 -0
  30. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/enums.py +0 -0
  31. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/historical/__init__.py +0 -0
  32. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/historical/corporate_actions.py +0 -0
  33. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/historical/crypto.py +0 -0
  34. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/historical/news.py +0 -0
  35. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/historical/option.py +0 -0
  36. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/historical/screener.py +0 -0
  37. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/historical/stock.py +0 -0
  38. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/historical/utils.py +0 -0
  39. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/live/__init__.py +0 -0
  40. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/live/crypto.py +0 -0
  41. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/live/news.py +0 -0
  42. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/live/option.py +0 -0
  43. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/live/stock.py +0 -0
  44. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/live/websocket.py +0 -0
  45. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/mappings.py +0 -0
  46. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/models/__init__.py +0 -0
  47. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/models/bars.py +0 -0
  48. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/models/base.py +0 -0
  49. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/models/corporate_actions.py +0 -0
  50. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/models/news.py +0 -0
  51. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/models/orderbooks.py +0 -0
  52. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/models/quotes.py +0 -0
  53. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/models/screener.py +0 -0
  54. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/models/snapshots.py +0 -0
  55. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/models/trades.py +0 -0
  56. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/requests.py +0 -0
  57. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/data/timeframe.py +0 -0
  58. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/py.typed +0 -0
  59. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/trading/__init__.py +0 -0
  60. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/trading/client.py +0 -0
  61. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/trading/enums.py +0 -0
  62. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/trading/models.py +0 -0
  63. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/trading/requests.py +0 -0
  64. {alpaca_py_nopandas-0.1.0 → alpaca_py_nopandas-0.1.2}/alpaca/trading/stream.py +0 -0
@@ -0,0 +1,40 @@
1
+ Metadata-Version: 2.3
2
+ Name: alpaca-py-nopandas
3
+ Version: 0.1.2
4
+ Summary: A forked Python SDK for Alpaca APIs (with Pandas removed)
5
+ License: Apache-2.0
6
+ Author: Will Tesler
7
+ Author-email: willtesler@gmail.com
8
+ Requires-Python: >=3.8.0,<4.0.0
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.8
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Requires-Dist: msgpack (>=1.0.3,<2.0.0)
18
+ Requires-Dist: pydantic (>=2.0.3,<3.0.0)
19
+ Requires-Dist: python-dateutil (>=2.9.0,<3.0.0)
20
+ Requires-Dist: pytz (>=2025.2,<2026.0)
21
+ Requires-Dist: requests (>=2.30.0,<3.0.0)
22
+ Requires-Dist: sseclient-py (>=1.7.2,<2.0.0)
23
+ Requires-Dist: websockets (>=10.4)
24
+ Project-URL: Documentation, https://alpaca.markets/docs/python-sdk/
25
+ Project-URL: Repository, https://github.com/wtesler/alpaca-py-nopandas
26
+ Description-Content-Type: text/markdown
27
+
28
+ [![Python Versions](https://img.shields.io/pypi/pyversions/alpaca-py.svg?logo=python&logoColor=white)](https://pypi.org/project/alpaca-py-nopandas)
29
+ [![GitHub](https://img.shields.io/github/license/alpacahq/alpaca-py?color=blue)](https://github.com/alpacahq/alpaca-py/blob/master/LICENSE.md)
30
+ [![PyPI](https://img.shields.io/pypi/v/alpaca-py?color=blue)](https://pypi.org/project/alpaca-py-nopandas/)
31
+
32
+ Forked version of alpaca-py project with Pandas dependency removed.
33
+
34
+ See https://github.com/alpacahq/alpaca-py
35
+
36
+ # Build and Deploy
37
+
38
+ `poetry build`
39
+
40
+ `uvx twine upload dist/*`
@@ -0,0 +1,13 @@
1
+ [![Python Versions](https://img.shields.io/pypi/pyversions/alpaca-py.svg?logo=python&logoColor=white)](https://pypi.org/project/alpaca-py-nopandas)
2
+ [![GitHub](https://img.shields.io/github/license/alpacahq/alpaca-py?color=blue)](https://github.com/alpacahq/alpaca-py/blob/master/LICENSE.md)
3
+ [![PyPI](https://img.shields.io/pypi/v/alpaca-py?color=blue)](https://pypi.org/project/alpaca-py-nopandas/)
4
+
5
+ Forked version of alpaca-py project with Pandas dependency removed.
6
+
7
+ See https://github.com/alpacahq/alpaca-py
8
+
9
+ # Build and Deploy
10
+
11
+ `poetry build`
12
+
13
+ `uvx twine upload dist/*`
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "alpaca-py-nopandas"
3
- version = "0.1.0"
3
+ version = "0.1.2"
4
4
  description = "A forked Python SDK for Alpaca APIs (with Pandas removed)"
5
5
  authors = [
6
6
  "Will Tesler <willtesler@gmail.com>",
@@ -16,8 +16,10 @@ include = [ "alpaca/py.typed" ]
16
16
 
17
17
  [tool.poetry.dependencies]
18
18
  python = "^3.8.0"
19
+ python-dateutil = "^2.9.0"
19
20
  requests = "^2.30.0"
20
21
  pydantic = "^2.0.3"
22
+ pytz = "^2025.2"
21
23
  msgpack = "^1.0.3"
22
24
  websockets = ">=10.4"
23
25
  sseclient-py = "^1.7.2"
@@ -1,299 +0,0 @@
1
- Metadata-Version: 2.3
2
- Name: alpaca-py-nopandas
3
- Version: 0.1.0
4
- Summary: A forked Python SDK for Alpaca APIs (with Pandas removed)
5
- License: Apache-2.0
6
- Author: Will Tesler
7
- Author-email: willtesler@gmail.com
8
- Requires-Python: >=3.8.0,<4.0.0
9
- Classifier: License :: OSI Approved :: Apache Software License
10
- Classifier: Programming Language :: Python :: 3
11
- Classifier: Programming Language :: Python :: 3.8
12
- Classifier: Programming Language :: Python :: 3.9
13
- Classifier: Programming Language :: Python :: 3.10
14
- Classifier: Programming Language :: Python :: 3.11
15
- Classifier: Programming Language :: Python :: 3.12
16
- Classifier: Programming Language :: Python :: 3.13
17
- Requires-Dist: msgpack (>=1.0.3,<2.0.0)
18
- Requires-Dist: pydantic (>=2.0.3,<3.0.0)
19
- Requires-Dist: requests (>=2.30.0,<3.0.0)
20
- Requires-Dist: sseclient-py (>=1.7.2,<2.0.0)
21
- Requires-Dist: websockets (>=10.4)
22
- Project-URL: Documentation, https://alpaca.markets/docs/python-sdk/
23
- Project-URL: Repository, https://github.com/wtesler/alpaca-py-nopandas
24
- Description-Content-Type: text/markdown
25
-
26
- [![Alpaca-py](https://github.com/alpacahq/alpaca-py/blob/master/docs/images/alpaca-py-banner.png?raw=true)](https://alpaca.markets/docs/python-sdk)
27
-
28
- [![Downloads](https://pepy.tech/badge/alpaca-py/month)](https://pepy.tech/project/alpaca-py)
29
- [![Python Versions](https://img.shields.io/pypi/pyversions/alpaca-py.svg?logo=python&logoColor=white)](https://pypi.org/project/alpaca-py)
30
- [![GitHub](https://img.shields.io/github/license/alpacahq/alpaca-py?color=blue)](https://github.com/alpacahq/alpaca-py/blob/master/LICENSE.md)
31
- [![PyPI](https://img.shields.io/pypi/v/alpaca-py?color=blue)](https://pypi.org/project/alpaca-py/)
32
-
33
- ## Table of Contents
34
-
35
- - [About](#about)
36
- - [Documentation](#documentation)
37
- - [Installation](#installation)
38
- - [Update](#update)
39
- - [What's New?](#whats-new)
40
- 1. [Broker API](#broker-api-new)
41
- 2. [OOP Design](#oop-design)
42
- 3. [Data Validation](#data-validation)
43
- 4. [Many Clients](#many-clients)
44
- - [API Keys](#api-keys)
45
- 1. [Trading and Market Data API Keys](#trading-api-keys)
46
- 2. [Broker API Keys](#trading-api-keys)
47
- - [Usage](#usage)
48
- 1. [Broker API Example](#broker-api-example)
49
- 2. [Trading API Example](#trading-api-example)
50
- 3. [Market Data API Example](#data-api-example)
51
- - [Contributing](https://github.com/alpacahq/alpaca-py/blob/master/CONTRIBUTING.md)
52
- - [License](https://github.com/alpacahq/alpaca-py/blob/master/LICENSE)
53
-
54
- ## About <a name="about"></a>
55
-
56
- Alpaca-py provides an interface for interacting with the API products Alpaca offers. These API products are provided as various REST, WebSocket and SSE endpoints that allow you to do everything from streaming market data to creating your own investment apps.
57
-
58
- Learn more about the API products Alpaca offers at https://alpaca.markets.
59
-
60
- ## Documentation <a name="documentation"></a>
61
-
62
- Alpaca-py has a supplementary documentation site which contains references for all clients, methods and models found in this codebase. The documentation
63
- also contains examples to get started with alpaca-py.
64
-
65
- You can find the documentation site here: https://alpaca.markets/sdks/python/getting_started.html
66
-
67
- You can also find the API Reference of Alpaca APIs: https://docs.alpaca.markets/reference
68
-
69
- ## Installation <a name="installation"></a>
70
-
71
- Alpaca-py is supported on Python 3.8+. You can install Alpaca-py using pip.
72
-
73
- Run the following command in your terminal.
74
-
75
- ```shell
76
- pip install alpaca-py
77
- ```
78
-
79
- ## Update <a name="update"></a>
80
-
81
- If you already have Alpaca-py installed, and would like to use the latest version available...
82
-
83
- Run the following command in your terminal:
84
-
85
- ```shell
86
- pip install alpaca-py --upgrade
87
- ```
88
-
89
- ## What’s New? <a name="whats-new"></a>
90
-
91
- If you’ve used the previous python SDK alpaca-trade-api, there are a few key differences to be aware of.
92
-
93
- ### Broker API <a name="broker-api-new"></a>
94
-
95
- Alpaca-py lets you use Broker API to start building your investment apps! Learn more at the [Broker](https://docs.alpaca.markets/docs/about-broker-api) page.
96
-
97
- ### OOP Design <a name="oop-design"></a>
98
-
99
- Alpaca-py uses a more OOP approach to submitting requests compared to the previous SDK. To submit a request, you will most likely need to create a request object containing the desired request data. Generally, there is a unique request model for each method.
100
-
101
- Some examples of request models corresponding to methods:
102
-
103
- - `GetOrdersRequest` for `TradingClient.get_orders()`
104
- - `CryptoLatestOrderbookRequest` for `CryptoHistoricalDataClient.get_crypto_latest_orderbook()`
105
-
106
- **Request Models Usage Example**
107
-
108
- To get historical bar data for crypto, you will need to provide a `CryptoBarsRequest` object.
109
-
110
- ```python
111
- from alpaca.data.historical import CryptoHistoricalDataClient
112
- from alpaca.data.requests import CryptoBarsRequest
113
- from alpaca.data.timeframe import TimeFrame
114
- from datetime import datetime
115
-
116
- # no keys required for crypto data
117
- client = CryptoHistoricalDataClient()
118
-
119
- request_params = CryptoBarsRequest(
120
- symbol_or_symbols=["BTC/USD", "ETH/USD"],
121
- timeframe=TimeFrame.Day,
122
- start=datetime(2022, 7, 1)
123
- )
124
-
125
- bars = client.get_crypto_bars(request_params)
126
- ```
127
-
128
- ### Data Validation <a name="data-validation"></a>
129
-
130
- Alpaca-py uses _pydantic_ to validate data models at run-time. This means if you are receiving request data via JSON from a client. You can handle parsing and validation through Alpaca’s request models. All request models can be instantiated by passing in data in dictionary format.
131
-
132
- Here is a rough example of what is possible.
133
-
134
- ```python
135
-
136
- @app.route('/post_json', methods=['POST'])
137
- def do_trade():
138
- # ...
139
-
140
- order_data_json = request.get_json()
141
-
142
- # validate data
143
- MarketOrderRequest(**order_data_json)
144
-
145
- # ...
146
- ```
147
-
148
- ### Many Clients <a name="many-clients"></a>
149
-
150
- Alpaca-py has a lot of client classes. There is a client for each API and even asset class specific clients (`StockHistoricalDataClient`, `CryptoDataStream`, `OptionHistoricalDataClient`). This requires you to pick and choose clients based on your needs.
151
-
152
- **Broker API:** `BrokerClient`
153
-
154
- **Trading API:** `TradingClient`
155
-
156
- **Market Data API:** `StockHistoricalDataClient`, `CryptoHistoricalDataClient`, `NewsClient`, `OptionHistoricalDataClient`, `CryptoDataStream`, `StockDataStream`, `NewsDataStream`, `OptionDataStream`
157
-
158
- ## API Keys <a name="api-keys"></a>
159
-
160
- ### Trading and Market Data API <a name="trading-api-keys"></a>
161
-
162
- In order to use Alpaca’s services you’ll need to sign up for an Alpaca account and retrieve your API keys. Signing up is completely free and takes only a few minutes. Sandbox environments are available to test out the API. To use the sandbox environment, you will need to provide sandbox/paper keys. API keys are passed into Alpaca-py through either `TradingClient`, `StockHistoricalDataClient`, `CryptoHistoricalDataClient`, `NewsClient`, `OptionHistoricalDataClient`, `StockDataStream`, `CryptoDataStream`,`NewsDataStream`, or `OptionDataStream`.
163
-
164
- ### Broker API <a name="broker-api-keys"></a>
165
-
166
- To use the Broker API, you will need to sign up for a broker account and retrieve your Broker API keys. The API keys can be found on the dashboard once you’ve logged in. Alpaca also provides a sandbox environment to test out Broker API. To use the sandbox mode, provide your sandbox keys. Once you have your keys, you can pass them into `BrokerClient` to get started.
167
-
168
- ## Usage <a name="usage"></a>
169
-
170
- Alpaca’s APIs allow you to do everything from building algorithmic trading strategies to building a full brokerage experience for your own end users. Here are some things you can do with Alpaca-py.
171
-
172
- To view full descriptions and examples view the [documentation page](https://alpaca.markets/sdks/python/).
173
-
174
- **Market Data API**: Access live and historical market data for 5000+ stocks, 20+ crypto, and options.
175
-
176
- **Trading API**: Trade stock and crypto with lightning fast execution speeds.
177
-
178
- **Broker API & Connect**: Build investment apps - from robo-advisors to brokerages.
179
-
180
- ### Broker API Example <a name="broker-api-example"></a>
181
-
182
- **Listing All Accounts**
183
-
184
- The `BrokerClient.list_accounts` method allows you to list all the brokerage accounts under your management. The method takes an optional parameter `search_parameters` which requires a `ListAccountsRequest` object. This parameter allows you to filter the list of accounts returned.
185
-
186
- ```python
187
- from alpaca.broker.client import BrokerClient
188
- from alpaca.broker.requests import ListAccountsRequest
189
- from alpaca.broker.enums import AccountEntities
190
-
191
- broker_client = BrokerClient('api-key', 'secret-key')
192
-
193
- # search for accounts created after January 30th 2022.
194
- # Response should contain Contact and Identity fields for each account.
195
- filter = ListAccountsRequest(
196
- created_after=datetime.datetime.strptime("2022-01-30", "%Y-%m-%d"),
197
- entities=[AccountEntities.CONTACT, AccountEntities.IDENTITY]
198
- )
199
-
200
- accounts = broker_client.list_accounts(search_parameters=filter)
201
- ```
202
-
203
- ### Trading API Example <a name="trading-api-example"></a>
204
-
205
- **Submitting an Order**
206
-
207
- To create an order on Alpaca-py you must use an `OrderRequest` object. There are different `OrderRequest` objects based on the type of order you want to make. For market orders, there is `MarketOrderRequest`, limit orders have `LimitOrderRequest`, stop orders `StopOrderRequest`, and trailing stop orders have `TrailingStopOrderRequest`. Each order type have their own required parameters for a successful order.
208
-
209
- ```python
210
- from alpaca.trading.client import TradingClient
211
- from alpaca.trading.requests import MarketOrderRequest
212
- from alpaca.trading.enums import OrderSide, TimeInForce
213
-
214
- trading_client = TradingClient('api-key', 'secret-key')
215
-
216
-
217
- # preparing order data
218
- market_order_data = MarketOrderRequest(
219
- symbol="BTC/USD",
220
- qty=0.0001,
221
- side=OrderSide.BUY,
222
- time_in_force=TimeInForce.DAY
223
- )
224
-
225
- # Market order
226
- market_order = trading_client.submit_order(
227
- order_data=market_order_data
228
- )
229
- ```
230
-
231
- ### Market Data API Example <a name="data-api-example"></a>
232
-
233
- **Querying Historical Bar Data**
234
-
235
- You can request bar data via the HistoricalDataClients. In this example, we query daily bar data for “BTC/USD” and “ETH/USD” since July 1st 2022. You can convert the response to a multi-index pandas dataframe using the `.df` property. There are `StockHistoricalDataClient` and `OptionHistoricalDataClient` that you also could use to fetch equity/options historical data.
236
-
237
- ```python
238
- from alpaca.data.historical import CryptoHistoricalDataClient
239
- from alpaca.data.requests import CryptoBarsRequest
240
- from alpaca.data.timeframe import TimeFrame
241
- from datetime import datetime
242
-
243
- # no keys required for crypto data
244
- client = CryptoHistoricalDataClient()
245
-
246
- request_params = CryptoBarsRequest(
247
- symbol_or_symbols=["BTC/USD", "ETH/USD"],
248
- timeframe=TimeFrame.Day,
249
- start=datetime.strptime("2022-07-01", '%Y-%m-%d')
250
- )
251
-
252
- bars = client.get_crypto_bars(request_params)
253
-
254
- # convert to dataframe
255
- bars.df
256
-
257
- ```
258
-
259
- **Querying News Data** <a name="news-client-example"></a>
260
-
261
- You can query news data via the NewsClient. In this example, we query news data for “TSLA” since July 1st 2022. You can convert the response to a pandas dataframe using the `.df` property.
262
-
263
- ```python
264
- from alpaca.data.historical.news import NewsClient
265
- from alpaca.data.requests import NewsRequest
266
- from datetime import datetime
267
-
268
- # no keys required for news data
269
- client = NewsClient()
270
-
271
- request_params = NewsRequest(
272
- symbols="TSLA",
273
- start=datetime.strptime("2022-07-01", '%Y-%m-%d')
274
- )
275
-
276
- news = client.get_news(request_params)
277
-
278
- # convert to dataframe
279
- news.df
280
-
281
- ```
282
-
283
- ### Options Trading <a name="options-trading"></a>
284
-
285
- We're excited to support options trading! Use this section to read up on Alpaca's options trading capabilities.
286
- For more details, please refer to [our documentation page for options trading](https://docs.alpaca.markets/docs/options-trading)
287
-
288
- There is an example jupyter notebook to explain methods of alpaca-py for options trading.
289
-
290
- * [jupyter notebook: options trading basic example with alpaca-py](https://github.com/alpacahq/alpaca-py/blob/master/examples/options/options-trading-basic.ipynb)
291
-
292
- ### Jupyter Notebook Library <a name="colab-library"></a>
293
-
294
- Explore examples for stocks, options, and crypto using alpaca-py. Notebooks for each asset class are provided in their respective directories!
295
-
296
- * [Stocks](https://github.com/alpacahq/alpaca-py/blob/master/examples/stocks/README.md)
297
- * [Crypto](https://github.com/alpacahq/alpaca-py/blob/master/examples/crypto/README.md)
298
- * [Options](https://github.com/alpacahq/alpaca-py/blob/master/examples/options/README.md)
299
- * [Multi-Leg Options](https://github.com/alpacahq/alpaca-py/blob/master/examples/options/README.md)
@@ -1,274 +0,0 @@
1
- [![Alpaca-py](https://github.com/alpacahq/alpaca-py/blob/master/docs/images/alpaca-py-banner.png?raw=true)](https://alpaca.markets/docs/python-sdk)
2
-
3
- [![Downloads](https://pepy.tech/badge/alpaca-py/month)](https://pepy.tech/project/alpaca-py)
4
- [![Python Versions](https://img.shields.io/pypi/pyversions/alpaca-py.svg?logo=python&logoColor=white)](https://pypi.org/project/alpaca-py)
5
- [![GitHub](https://img.shields.io/github/license/alpacahq/alpaca-py?color=blue)](https://github.com/alpacahq/alpaca-py/blob/master/LICENSE.md)
6
- [![PyPI](https://img.shields.io/pypi/v/alpaca-py?color=blue)](https://pypi.org/project/alpaca-py/)
7
-
8
- ## Table of Contents
9
-
10
- - [About](#about)
11
- - [Documentation](#documentation)
12
- - [Installation](#installation)
13
- - [Update](#update)
14
- - [What's New?](#whats-new)
15
- 1. [Broker API](#broker-api-new)
16
- 2. [OOP Design](#oop-design)
17
- 3. [Data Validation](#data-validation)
18
- 4. [Many Clients](#many-clients)
19
- - [API Keys](#api-keys)
20
- 1. [Trading and Market Data API Keys](#trading-api-keys)
21
- 2. [Broker API Keys](#trading-api-keys)
22
- - [Usage](#usage)
23
- 1. [Broker API Example](#broker-api-example)
24
- 2. [Trading API Example](#trading-api-example)
25
- 3. [Market Data API Example](#data-api-example)
26
- - [Contributing](https://github.com/alpacahq/alpaca-py/blob/master/CONTRIBUTING.md)
27
- - [License](https://github.com/alpacahq/alpaca-py/blob/master/LICENSE)
28
-
29
- ## About <a name="about"></a>
30
-
31
- Alpaca-py provides an interface for interacting with the API products Alpaca offers. These API products are provided as various REST, WebSocket and SSE endpoints that allow you to do everything from streaming market data to creating your own investment apps.
32
-
33
- Learn more about the API products Alpaca offers at https://alpaca.markets.
34
-
35
- ## Documentation <a name="documentation"></a>
36
-
37
- Alpaca-py has a supplementary documentation site which contains references for all clients, methods and models found in this codebase. The documentation
38
- also contains examples to get started with alpaca-py.
39
-
40
- You can find the documentation site here: https://alpaca.markets/sdks/python/getting_started.html
41
-
42
- You can also find the API Reference of Alpaca APIs: https://docs.alpaca.markets/reference
43
-
44
- ## Installation <a name="installation"></a>
45
-
46
- Alpaca-py is supported on Python 3.8+. You can install Alpaca-py using pip.
47
-
48
- Run the following command in your terminal.
49
-
50
- ```shell
51
- pip install alpaca-py
52
- ```
53
-
54
- ## Update <a name="update"></a>
55
-
56
- If you already have Alpaca-py installed, and would like to use the latest version available...
57
-
58
- Run the following command in your terminal:
59
-
60
- ```shell
61
- pip install alpaca-py --upgrade
62
- ```
63
-
64
- ## What’s New? <a name="whats-new"></a>
65
-
66
- If you’ve used the previous python SDK alpaca-trade-api, there are a few key differences to be aware of.
67
-
68
- ### Broker API <a name="broker-api-new"></a>
69
-
70
- Alpaca-py lets you use Broker API to start building your investment apps! Learn more at the [Broker](https://docs.alpaca.markets/docs/about-broker-api) page.
71
-
72
- ### OOP Design <a name="oop-design"></a>
73
-
74
- Alpaca-py uses a more OOP approach to submitting requests compared to the previous SDK. To submit a request, you will most likely need to create a request object containing the desired request data. Generally, there is a unique request model for each method.
75
-
76
- Some examples of request models corresponding to methods:
77
-
78
- - `GetOrdersRequest` for `TradingClient.get_orders()`
79
- - `CryptoLatestOrderbookRequest` for `CryptoHistoricalDataClient.get_crypto_latest_orderbook()`
80
-
81
- **Request Models Usage Example**
82
-
83
- To get historical bar data for crypto, you will need to provide a `CryptoBarsRequest` object.
84
-
85
- ```python
86
- from alpaca.data.historical import CryptoHistoricalDataClient
87
- from alpaca.data.requests import CryptoBarsRequest
88
- from alpaca.data.timeframe import TimeFrame
89
- from datetime import datetime
90
-
91
- # no keys required for crypto data
92
- client = CryptoHistoricalDataClient()
93
-
94
- request_params = CryptoBarsRequest(
95
- symbol_or_symbols=["BTC/USD", "ETH/USD"],
96
- timeframe=TimeFrame.Day,
97
- start=datetime(2022, 7, 1)
98
- )
99
-
100
- bars = client.get_crypto_bars(request_params)
101
- ```
102
-
103
- ### Data Validation <a name="data-validation"></a>
104
-
105
- Alpaca-py uses _pydantic_ to validate data models at run-time. This means if you are receiving request data via JSON from a client. You can handle parsing and validation through Alpaca’s request models. All request models can be instantiated by passing in data in dictionary format.
106
-
107
- Here is a rough example of what is possible.
108
-
109
- ```python
110
-
111
- @app.route('/post_json', methods=['POST'])
112
- def do_trade():
113
- # ...
114
-
115
- order_data_json = request.get_json()
116
-
117
- # validate data
118
- MarketOrderRequest(**order_data_json)
119
-
120
- # ...
121
- ```
122
-
123
- ### Many Clients <a name="many-clients"></a>
124
-
125
- Alpaca-py has a lot of client classes. There is a client for each API and even asset class specific clients (`StockHistoricalDataClient`, `CryptoDataStream`, `OptionHistoricalDataClient`). This requires you to pick and choose clients based on your needs.
126
-
127
- **Broker API:** `BrokerClient`
128
-
129
- **Trading API:** `TradingClient`
130
-
131
- **Market Data API:** `StockHistoricalDataClient`, `CryptoHistoricalDataClient`, `NewsClient`, `OptionHistoricalDataClient`, `CryptoDataStream`, `StockDataStream`, `NewsDataStream`, `OptionDataStream`
132
-
133
- ## API Keys <a name="api-keys"></a>
134
-
135
- ### Trading and Market Data API <a name="trading-api-keys"></a>
136
-
137
- In order to use Alpaca’s services you’ll need to sign up for an Alpaca account and retrieve your API keys. Signing up is completely free and takes only a few minutes. Sandbox environments are available to test out the API. To use the sandbox environment, you will need to provide sandbox/paper keys. API keys are passed into Alpaca-py through either `TradingClient`, `StockHistoricalDataClient`, `CryptoHistoricalDataClient`, `NewsClient`, `OptionHistoricalDataClient`, `StockDataStream`, `CryptoDataStream`,`NewsDataStream`, or `OptionDataStream`.
138
-
139
- ### Broker API <a name="broker-api-keys"></a>
140
-
141
- To use the Broker API, you will need to sign up for a broker account and retrieve your Broker API keys. The API keys can be found on the dashboard once you’ve logged in. Alpaca also provides a sandbox environment to test out Broker API. To use the sandbox mode, provide your sandbox keys. Once you have your keys, you can pass them into `BrokerClient` to get started.
142
-
143
- ## Usage <a name="usage"></a>
144
-
145
- Alpaca’s APIs allow you to do everything from building algorithmic trading strategies to building a full brokerage experience for your own end users. Here are some things you can do with Alpaca-py.
146
-
147
- To view full descriptions and examples view the [documentation page](https://alpaca.markets/sdks/python/).
148
-
149
- **Market Data API**: Access live and historical market data for 5000+ stocks, 20+ crypto, and options.
150
-
151
- **Trading API**: Trade stock and crypto with lightning fast execution speeds.
152
-
153
- **Broker API & Connect**: Build investment apps - from robo-advisors to brokerages.
154
-
155
- ### Broker API Example <a name="broker-api-example"></a>
156
-
157
- **Listing All Accounts**
158
-
159
- The `BrokerClient.list_accounts` method allows you to list all the brokerage accounts under your management. The method takes an optional parameter `search_parameters` which requires a `ListAccountsRequest` object. This parameter allows you to filter the list of accounts returned.
160
-
161
- ```python
162
- from alpaca.broker.client import BrokerClient
163
- from alpaca.broker.requests import ListAccountsRequest
164
- from alpaca.broker.enums import AccountEntities
165
-
166
- broker_client = BrokerClient('api-key', 'secret-key')
167
-
168
- # search for accounts created after January 30th 2022.
169
- # Response should contain Contact and Identity fields for each account.
170
- filter = ListAccountsRequest(
171
- created_after=datetime.datetime.strptime("2022-01-30", "%Y-%m-%d"),
172
- entities=[AccountEntities.CONTACT, AccountEntities.IDENTITY]
173
- )
174
-
175
- accounts = broker_client.list_accounts(search_parameters=filter)
176
- ```
177
-
178
- ### Trading API Example <a name="trading-api-example"></a>
179
-
180
- **Submitting an Order**
181
-
182
- To create an order on Alpaca-py you must use an `OrderRequest` object. There are different `OrderRequest` objects based on the type of order you want to make. For market orders, there is `MarketOrderRequest`, limit orders have `LimitOrderRequest`, stop orders `StopOrderRequest`, and trailing stop orders have `TrailingStopOrderRequest`. Each order type have their own required parameters for a successful order.
183
-
184
- ```python
185
- from alpaca.trading.client import TradingClient
186
- from alpaca.trading.requests import MarketOrderRequest
187
- from alpaca.trading.enums import OrderSide, TimeInForce
188
-
189
- trading_client = TradingClient('api-key', 'secret-key')
190
-
191
-
192
- # preparing order data
193
- market_order_data = MarketOrderRequest(
194
- symbol="BTC/USD",
195
- qty=0.0001,
196
- side=OrderSide.BUY,
197
- time_in_force=TimeInForce.DAY
198
- )
199
-
200
- # Market order
201
- market_order = trading_client.submit_order(
202
- order_data=market_order_data
203
- )
204
- ```
205
-
206
- ### Market Data API Example <a name="data-api-example"></a>
207
-
208
- **Querying Historical Bar Data**
209
-
210
- You can request bar data via the HistoricalDataClients. In this example, we query daily bar data for “BTC/USD” and “ETH/USD” since July 1st 2022. You can convert the response to a multi-index pandas dataframe using the `.df` property. There are `StockHistoricalDataClient` and `OptionHistoricalDataClient` that you also could use to fetch equity/options historical data.
211
-
212
- ```python
213
- from alpaca.data.historical import CryptoHistoricalDataClient
214
- from alpaca.data.requests import CryptoBarsRequest
215
- from alpaca.data.timeframe import TimeFrame
216
- from datetime import datetime
217
-
218
- # no keys required for crypto data
219
- client = CryptoHistoricalDataClient()
220
-
221
- request_params = CryptoBarsRequest(
222
- symbol_or_symbols=["BTC/USD", "ETH/USD"],
223
- timeframe=TimeFrame.Day,
224
- start=datetime.strptime("2022-07-01", '%Y-%m-%d')
225
- )
226
-
227
- bars = client.get_crypto_bars(request_params)
228
-
229
- # convert to dataframe
230
- bars.df
231
-
232
- ```
233
-
234
- **Querying News Data** <a name="news-client-example"></a>
235
-
236
- You can query news data via the NewsClient. In this example, we query news data for “TSLA” since July 1st 2022. You can convert the response to a pandas dataframe using the `.df` property.
237
-
238
- ```python
239
- from alpaca.data.historical.news import NewsClient
240
- from alpaca.data.requests import NewsRequest
241
- from datetime import datetime
242
-
243
- # no keys required for news data
244
- client = NewsClient()
245
-
246
- request_params = NewsRequest(
247
- symbols="TSLA",
248
- start=datetime.strptime("2022-07-01", '%Y-%m-%d')
249
- )
250
-
251
- news = client.get_news(request_params)
252
-
253
- # convert to dataframe
254
- news.df
255
-
256
- ```
257
-
258
- ### Options Trading <a name="options-trading"></a>
259
-
260
- We're excited to support options trading! Use this section to read up on Alpaca's options trading capabilities.
261
- For more details, please refer to [our documentation page for options trading](https://docs.alpaca.markets/docs/options-trading)
262
-
263
- There is an example jupyter notebook to explain methods of alpaca-py for options trading.
264
-
265
- * [jupyter notebook: options trading basic example with alpaca-py](https://github.com/alpacahq/alpaca-py/blob/master/examples/options/options-trading-basic.ipynb)
266
-
267
- ### Jupyter Notebook Library <a name="colab-library"></a>
268
-
269
- Explore examples for stocks, options, and crypto using alpaca-py. Notebooks for each asset class are provided in their respective directories!
270
-
271
- * [Stocks](https://github.com/alpacahq/alpaca-py/blob/master/examples/stocks/README.md)
272
- * [Crypto](https://github.com/alpacahq/alpaca-py/blob/master/examples/crypto/README.md)
273
- * [Options](https://github.com/alpacahq/alpaca-py/blob/master/examples/options/README.md)
274
- * [Multi-Leg Options](https://github.com/alpacahq/alpaca-py/blob/master/examples/options/README.md)