alpaca-py-nopandas 0.1.0__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 (62) hide show
  1. alpaca_py_nopandas-0.1.0/LICENSE +201 -0
  2. alpaca_py_nopandas-0.1.0/PKG-INFO +299 -0
  3. alpaca_py_nopandas-0.1.0/README.md +274 -0
  4. alpaca_py_nopandas-0.1.0/alpaca/__init__.py +2 -0
  5. alpaca_py_nopandas-0.1.0/alpaca/broker/__init__.py +8 -0
  6. alpaca_py_nopandas-0.1.0/alpaca/broker/client.py +2360 -0
  7. alpaca_py_nopandas-0.1.0/alpaca/broker/enums.py +528 -0
  8. alpaca_py_nopandas-0.1.0/alpaca/broker/models/__init__.py +7 -0
  9. alpaca_py_nopandas-0.1.0/alpaca/broker/models/accounts.py +347 -0
  10. alpaca_py_nopandas-0.1.0/alpaca/broker/models/cip.py +265 -0
  11. alpaca_py_nopandas-0.1.0/alpaca/broker/models/documents.py +159 -0
  12. alpaca_py_nopandas-0.1.0/alpaca/broker/models/funding.py +114 -0
  13. alpaca_py_nopandas-0.1.0/alpaca/broker/models/journals.py +71 -0
  14. alpaca_py_nopandas-0.1.0/alpaca/broker/models/rebalancing.py +80 -0
  15. alpaca_py_nopandas-0.1.0/alpaca/broker/models/trading.py +13 -0
  16. alpaca_py_nopandas-0.1.0/alpaca/broker/requests.py +1135 -0
  17. alpaca_py_nopandas-0.1.0/alpaca/common/__init__.py +6 -0
  18. alpaca_py_nopandas-0.1.0/alpaca/common/constants.py +13 -0
  19. alpaca_py_nopandas-0.1.0/alpaca/common/enums.py +64 -0
  20. alpaca_py_nopandas-0.1.0/alpaca/common/exceptions.py +47 -0
  21. alpaca_py_nopandas-0.1.0/alpaca/common/models.py +21 -0
  22. alpaca_py_nopandas-0.1.0/alpaca/common/requests.py +82 -0
  23. alpaca_py_nopandas-0.1.0/alpaca/common/rest.py +438 -0
  24. alpaca_py_nopandas-0.1.0/alpaca/common/types.py +7 -0
  25. alpaca_py_nopandas-0.1.0/alpaca/common/utils.py +89 -0
  26. alpaca_py_nopandas-0.1.0/alpaca/data/__init__.py +5 -0
  27. alpaca_py_nopandas-0.1.0/alpaca/data/enums.py +184 -0
  28. alpaca_py_nopandas-0.1.0/alpaca/data/historical/__init__.py +13 -0
  29. alpaca_py_nopandas-0.1.0/alpaca/data/historical/corporate_actions.py +76 -0
  30. alpaca_py_nopandas-0.1.0/alpaca/data/historical/crypto.py +299 -0
  31. alpaca_py_nopandas-0.1.0/alpaca/data/historical/news.py +63 -0
  32. alpaca_py_nopandas-0.1.0/alpaca/data/historical/option.py +230 -0
  33. alpaca_py_nopandas-0.1.0/alpaca/data/historical/screener.py +72 -0
  34. alpaca_py_nopandas-0.1.0/alpaca/data/historical/stock.py +226 -0
  35. alpaca_py_nopandas-0.1.0/alpaca/data/historical/utils.py +30 -0
  36. alpaca_py_nopandas-0.1.0/alpaca/data/live/__init__.py +11 -0
  37. alpaca_py_nopandas-0.1.0/alpaca/data/live/crypto.py +168 -0
  38. alpaca_py_nopandas-0.1.0/alpaca/data/live/news.py +62 -0
  39. alpaca_py_nopandas-0.1.0/alpaca/data/live/option.py +88 -0
  40. alpaca_py_nopandas-0.1.0/alpaca/data/live/stock.py +199 -0
  41. alpaca_py_nopandas-0.1.0/alpaca/data/live/websocket.py +390 -0
  42. alpaca_py_nopandas-0.1.0/alpaca/data/mappings.py +84 -0
  43. alpaca_py_nopandas-0.1.0/alpaca/data/models/__init__.py +7 -0
  44. alpaca_py_nopandas-0.1.0/alpaca/data/models/bars.py +83 -0
  45. alpaca_py_nopandas-0.1.0/alpaca/data/models/base.py +45 -0
  46. alpaca_py_nopandas-0.1.0/alpaca/data/models/corporate_actions.py +309 -0
  47. alpaca_py_nopandas-0.1.0/alpaca/data/models/news.py +90 -0
  48. alpaca_py_nopandas-0.1.0/alpaca/data/models/orderbooks.py +59 -0
  49. alpaca_py_nopandas-0.1.0/alpaca/data/models/quotes.py +78 -0
  50. alpaca_py_nopandas-0.1.0/alpaca/data/models/screener.py +68 -0
  51. alpaca_py_nopandas-0.1.0/alpaca/data/models/snapshots.py +132 -0
  52. alpaca_py_nopandas-0.1.0/alpaca/data/models/trades.py +204 -0
  53. alpaca_py_nopandas-0.1.0/alpaca/data/requests.py +580 -0
  54. alpaca_py_nopandas-0.1.0/alpaca/data/timeframe.py +148 -0
  55. alpaca_py_nopandas-0.1.0/alpaca/py.typed +0 -0
  56. alpaca_py_nopandas-0.1.0/alpaca/trading/__init__.py +5 -0
  57. alpaca_py_nopandas-0.1.0/alpaca/trading/client.py +784 -0
  58. alpaca_py_nopandas-0.1.0/alpaca/trading/enums.py +412 -0
  59. alpaca_py_nopandas-0.1.0/alpaca/trading/models.py +697 -0
  60. alpaca_py_nopandas-0.1.0/alpaca/trading/requests.py +604 -0
  61. alpaca_py_nopandas-0.1.0/alpaca/trading/stream.py +225 -0
  62. alpaca_py_nopandas-0.1.0/pyproject.toml +49 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2022 Alpaca
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,299 @@
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)