Skip to content

Commit be12c06

Browse files
authored
Merge pull request #86 from alpacahq/doc_fixes
Updated README
2 parents bd8589b + 3444b58 commit be12c06

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

README.md

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
# alpaca-trade-api-python
55

6-
`alpaca-trade-api-python` is a python library for the Alpaca trade API.
6+
`alpaca-trade-api-python` is a python library for the [Alpaca Commission Free Trading API](https://alpaca.markets).
77
It allows rapid trading algo development easily, with support for the
8-
both REST and streaming interfaces. For details of each API behavior,
9-
please see the online API document.
8+
both REST and streaming data interfaces. For details of each API behavior,
9+
please see the online [API document](https://docs.alpaca.markets).
1010

11-
Note this module supports only python version 3.5 and above, due to
12-
the async/await keyword use.
11+
Note this module supports only python version 3.6 and above, due to
12+
the async/await and websockets module dependency.
1313

1414
## Install
1515

@@ -19,41 +19,47 @@ $ pip3 install alpaca-trade-api
1919

2020
## Example
2121

22-
In order to call Alpaca's trade API, you need to obtain API key pairs.
23-
Replace <key_id> and <secret_key> with what you get from the web console.
22+
In order to call Alpaca's trade API, you need to sign up for a account and obtain API key pairs. Replace <key_id> and <secret_key> with what you get from the web console.
2423

2524
### REST example
2625
```python
2726
import alpaca_trade_api as tradeapi
2827

29-
api = tradeapi.REST('<key_id>', '<secret_key>')
28+
api = tradeapi.REST('<key_id>', '<secret_key>', api_version='v2') # or use ENV Vars shown below
3029
account = api.get_account()
3130
api.list_positions()
3231
```
3332

3433
## API Document
3534

36-
The HTTP API document is located in https://docs.alpaca.markets/
35+
The HTTP API document is located at https://docs.alpaca.markets/
36+
37+
## API Version
38+
39+
API Version now defaults to 'v2', however if you still have a 'v1' account, you may need to specify api_version='v1' to properly use the API until you migrate.
3740

3841
## Authentication
3942

4043
The Alpaca API requires API key ID and secret key, which you can obtain from the
4144
web console after you sign in. You can pass `key_id` and `secret_key` to the initializers of
4245
`REST` or `StreamConn` as arguments, or set up environment variables as
43-
follows.
46+
outlined below.
4447

45-
- APCA_API_KEY_ID: key ID
46-
- APCA_API_SECRET_KEY: secret key
48+
## Alpaca Environment Variables
4749

48-
## Base URL
50+
The Alpaca SDK will check the environment for a number of variables which can be used rather than hard-coding these into your scripts.
4951

50-
The base URL for API calls defaults to `https://api.alpaca.markets/`. This endpoint
51-
is for live trading. You can change the base URL to `https://paper-api.alpaca.markets`
52-
for paper trading. You can specify the API URL with the environment variable `APCA_API_BASE_URL`.
52+
| Environment | default | Description |
53+
| ----------- | ------- | ----------- |
54+
| APCA_API_KEY_ID=<key_id> | | Your API Key |
55+
| APCA_API_SECRET_KEY=<secret_key> | | Your API Secret Key |
56+
| APCA_API_BASE_URL=url | https://api.alpaca.markets (for live)<br/>https://paper-api.alpaca.markets (for paper) | Specify the URL for API calls, *Default is live, you must specify this to switch to paper endpoint!* |
57+
| APCA_API_DATA_URL=url | https://data.alpaca.markets | Endpoint for data API |
58+
| APCA_RETRY_MAX=3 | 3 | The number of subsequent API calls to retry on timeouts |
59+
| APCA_RETRY_WAIT=3 | 3 | seconds to wait between each retry attempt |
60+
| APCA_RETRY_CODES=429,504 | 429,504 | comma-separated HTTP status code for which retry is attempted |
61+
| POLYGON_WS_URL | wss://alpaca.socket.polygon.io/stocks | Endpoint for streaming polygon data. You likely don't need to change this unless you want to proxy it for example |
5362

54-
The environment variable `APCA_API_DATA_URL` can also be changed to configure the
55-
endpoint for returning data from the `/bars` endpoint. By default, it will use
56-
`https://data.alpaca.markets`.
5763

5864
## REST
5965

@@ -79,15 +85,9 @@ The `Entity` class also converts timestamp string field to a pandas.Timestamp
7985
object. Its `_raw` property returns the original raw primitive data unmarshaled
8086
from the response JSON text.
8187

82-
When a REST API call sees the 429 or 504 status code, this library retries 3 times
83-
by default, with 3 seconds apart between each call. These are configurable with
84-
the following environment variables.
85-
86-
- APCA_RETRY_MAX: the number of subsequent API calls to retry, defaults to 3
87-
- APCA_RETRY_WAIT: seconds to wait between each call, defaults to 3
88-
- APCA_RETRY_CODES: comma-separated HTTP status code for which retry is attempted
88+
Please note that the API is throttled, currently 200 requests per minute, per account. If your client exceeds this number, a 429 Too many requests status will be returned and this library will retry according to the retry environment variables as configured.
8989

90-
If the retry exceeds, or other API error is returned, `alpaca_trade_api.rest.APIError` is raised.
90+
If the retries are exceeded, or other API error is returned, `alpaca_trade_api.rest.APIError` is raised.
9191
You can access the following information through this object.
9292

9393
- the API error code: `.code` property
@@ -146,7 +146,7 @@ Calls `GET /calendar` and returns a `Calendar` entity.
146146

147147
## StreamConn
148148

149-
The `StreamConn` class provides WebSocket/NATS-based event-driven
149+
The `StreamConn` class provides WebSocket-based event-driven
150150
interfaces. Using the `on` decorator of the instance, you can
151151
define custom event handlers that are called when the pattern
152152
is matched on the channel name. Once event handlers are set up,
@@ -160,7 +160,7 @@ Alpaca's account/trade updates events and Polygon's price updates.
160160
One connection is established when the `subscribe()` is called with
161161
the corresponding channel names. For example, if you subscribe to
162162
`account_updates`, a WebSocket connects to Alpaca stream API, and
163-
if `AM.*` given to the `subscribe()` method, a NATS connection is
163+
if `AM.*` given to the `subscribe()` method, a WebSocket connection is
164164
established to Polygon's interface.
165165

166166
The `run` method is a short-cut to start subscribing to channels and
@@ -183,12 +183,12 @@ a `ValueError` is raised when registering it as an event handler.
183183
```python
184184
conn = StreamConn()
185185

186-
@conn.on(r'account_updates')
186+
@conn.on(r'^account_updates$')
187187
async def on_account_updates(conn, channel, account):
188188
print('account', account)
189189

190190

191-
@conn.on(r'^AM.')
191+
@conn.on(r'^AM$')
192192
def on_bars(conn, channel, bar):
193193
print('bars', bar)
194194

0 commit comments

Comments
 (0)