Skip to content

Commit 7970679

Browse files
authored
Mark v1 marketdata endpoints deprecated (#558)
* Mark v1 marketdata endpoints deprecated * format
1 parent 3d905f6 commit 7970679

File tree

4 files changed

+24
-33
lines changed

4 files changed

+24
-33
lines changed

README.md

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ api = REST()
8888
api.get_bars("AAPL", TimeFrame.Hour, "2021-06-08", "2021-06-08", adjustment='raw').df
8989

9090
open high low close volume
91-
timestamp
91+
timestamp
9292
2021-06-08 08:00:00+00:00 126.100 126.3000 125.9600 126.3000 42107
9393
2021-06-08 09:00:00+00:00 126.270 126.4000 126.2200 126.3800 21095
9494
2021-06-08 10:00:00+00:00 126.380 126.6000 125.8400 126.4900 54743
@@ -126,7 +126,7 @@ api = REST()
126126
api.get_bars("AAPL", TimeFrame(45, TimeFrameUnit.Minute), "2021-06-08", "2021-06-08", adjustment='raw').df
127127

128128
open high low close volume trade_count vwap
129-
timestamp
129+
timestamp
130130
2021-06-08 07:30:00+00:00 126.1000 126.1600 125.9600 126.0600 20951 304 126.049447
131131
2021-06-08 08:15:00+00:00 126.0500 126.3000 126.0500 126.3000 21181 349 126.231904
132132
2021-06-08 09:00:00+00:00 126.2700 126.3200 126.2200 126.2800 15955 308 126.284120
@@ -160,7 +160,7 @@ api = REST()
160160
api.get_quotes("AAPL", "2021-06-08", "2021-06-08", limit=10).df
161161

162162
ask_exchange ask_price ask_size bid_exchange bid_price bid_size conditions
163-
timestamp
163+
timestamp
164164
2021-06-08 08:00:00.070928640+00:00 P 143.00 1 0.00 0 [Y]
165165
2021-06-08 08:00:00.070929408+00:00 P 143.00 1 P 102.51 1 [R]
166166
2021-06-08 08:00:00.070976768+00:00 P 143.00 1 P 116.50 1 [R]
@@ -192,7 +192,7 @@ api = REST()
192192
api.get_trades("AAPL", "2021-06-08", "2021-06-08", limit=10).df
193193

194194
exchange price size conditions id tape
195-
timestamp
195+
timestamp
196196
2021-06-08 08:00:00.069956608+00:00 P 126.10 179 [@, T] 1 C
197197
2021-06-08 08:00:00.207859+00:00 K 125.97 1 [@, T, I] 1 C
198198
2021-06-08 08:00:00.207859+00:00 K 125.97 12 [@, T, I] 2 C
@@ -254,7 +254,7 @@ stream.run()
254254

255255
```
256256

257-
## Account & Portfolio Management
257+
## Account & Portfolio Management
258258

259259
The HTTP API document is located at https://docs.alpaca.markets/
260260

@@ -305,7 +305,7 @@ You can access the following information through this object.
305305

306306
#### API REST Methods
307307

308-
| Rest Method | End Point | Result |
308+
| Rest Method | End Point | Result |
309309
| -------------------------------- | -------------------| ------------------------------------------------------------------ |
310310
| get_account() | `GET /account` and | `Account` entity.|
311311
| get_order_by_client_order_id(client_order_id) | `GET /orders` with client_order_id | `Order` entity.|
@@ -318,10 +318,6 @@ You can access the following information through this object.
318318
| get_position(symbol) | `GET /positions/{symbol}` | `Position` entity.|
319319
| list_assets(status=None, asset_class=None) | `GET /assets` | list of `Asset` entities|
320320
| get_asset(symbol) | `GET /assets/{symbol}` | `Asset` entity|
321-
| get_barset(symbols, timeframe, limit, start=None, end=None, after=None, until=None) | `GET /bars/{timeframe}` | Barset with `limit` Bar objects for each of the the requested symbols. `timeframe` can be one of `minute`, `1Min`, `5Min`, `15Min`, `day` or `1D`. `minute` is an alias of `1Min`. Similarly, `day` is an alias of `1D`. `start`, `end`, `after`, and `until` need to be string format, which you can obtain with `pd.Timestamp().isoformat()` `after` cannot be used with `start` and `until` cannot be used with `end`.|
322-
| get_aggs(symbol, timespan, multiplier, _from, to)| `GET /aggs/ticker/{symbol}/range/{multiplier}/{timespan}/{from}/{to}` | `Aggs` entity. `multiplier` is the size of the timespan multiplier. `timespan` is the size of the time window, can be one of `minute`, `hour`, `day`, `week`, `month`, `quarter` or `year`. `_from` and `to` must be in `YYYY-MM-DD` format, e.g. `2020-01-15`.|
323-
| get_last_trade(symbol) | `GET /last/stocks/{symbol}` | `Trade` entity|
324-
| get_last_quote(symbol) | `GET /last_quote/stocks/{symbol}` | `Quote` entity|
325321
| get_clock() | `GET /clock` | `Clock` entity|
326322
| get_calendar(start=None, end=None) | `GET /calendar` | `Calendar` entity|
327323
| get_portfolio_history(date_start=None, date_end=None, period=None, timeframe=None, extended_hours=None) | `GET /account/portfolio/history` | PortfolioHistory entity. PortfolioHistory.df can be used to get the results as a dataframe|
@@ -372,38 +368,21 @@ api.submit_order(
372368
)
373369
```
374370

375-
##### Using `get_barset()` (Deprecated. use `get_bars()` instead)
376-
```python
377-
import pandas as pd
378-
NY = 'America/New_York'
379-
start=pd.Timestamp('2020-08-01', tz=NY).isoformat()
380-
end=pd.Timestamp('2020-08-30', tz=NY).isoformat()
381-
print(api.get_barset(['AAPL', 'GOOG'], 'day', start=start, end=end).df)
382-
383-
# Minute data example
384-
start=pd.Timestamp('2020-08-28 9:30', tz=NY).isoformat()
385-
end=pd.Timestamp('2020-08-28 16:00', tz=NY).isoformat()
386-
print(api.get_barset(['AAPL', 'GOOG'], 'minute', start=start, end=end).df)
387-
388-
```
389-
390-
please note that if you are using limit, it is calculated from the end date. and if end date is not specified, "now" is used. <br>Take that under consideration when using start date with a limit.
391-
392371
---
393372

394373
#### Debugging
395374
Websocket exceptions may occur during execution.
396-
It will usually happen during the `consume()` method, which basically is the
375+
It will usually happen during the `consume()` method, which basically is the
397376
websocket steady-state.<br>
398377
exceptions during the consume method may occur due to:
399378
- server disconnections
400379
- error while handling the response data
401380

402381
We handle the first issue by reconnecting the websocket every time there's a disconnection.
403-
The second issue, is usually a user's code issue. To help you find it, we added a flag to the
382+
The second issue, is usually a user's code issue. To help you find it, we added a flag to the
404383
StreamConn object called `debug`. It is set to False by default, but you can turn it on to get a more
405384
verbose logs when this exception happens.
406-
Turn it on like so `StreamConn(debug=True)`
385+
Turn it on like so `StreamConn(debug=True)`
407386

408387
## Logging
409388
You should define a logger in your app in order to make sure you get all the messages from the different components.<br>

alpaca_trade_api/rest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import deprecation
12
import logging
23
import os
34
from typing import Iterator, List, Optional, Union
@@ -517,6 +518,8 @@ def get_asset(self, symbol: str) -> Asset:
517518
resp = self.get('/assets/{}'.format(symbol))
518519
return self.response_wrapper(resp, Asset)
519520

521+
@deprecation.deprecated(deprecated_in="v1.0.0",
522+
details="Use get_bars instead")
520523
def get_barset(self,
521524
symbols,
522525
timeframe: str,
@@ -563,6 +566,8 @@ def get_barset(self,
563566
resp = self.data_get('/bars/{}'.format(timeframe), params)
564567
return self.response_wrapper(resp, BarSet)
565568

569+
@deprecation.deprecated(deprecated_in="v1.0.0",
570+
details="Use get_bars instead")
566571
def get_aggs(self,
567572
symbol: str,
568573
multiplier: int,
@@ -583,13 +588,17 @@ def get_aggs(self,
583588
))
584589
return self.response_wrapper(resp, Aggs)
585590

591+
@deprecation.deprecated(deprecated_in="v1.0.0",
592+
details="Use get_latest_trade instead")
586593
def get_last_trade(self, symbol: str) -> Trade:
587594
"""
588595
Get the last trade for the given symbol
589596
"""
590597
resp = self.data_get('/last/stocks/{}'.format(symbol))
591598
return self.response_wrapper(resp['last'], Trade)
592599

600+
@deprecation.deprecated(deprecated_in="v1.0.0",
601+
details="Use get_latest_quote instead")
593602
def get_last_quote(self, symbol: str) -> Quote:
594603
"""Get the last quote for the given symbol"""
595604
resp = self.data_get('/last_quote/stocks/{}'.format(symbol))

alpaca_trade_api/stream2.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
The new Alpaca data stream is under stream.py
44
"""
55
import asyncio
6+
import deprecation
67
import json
78
import os
89
import re
@@ -47,8 +48,8 @@ async def _connect(self):
4748
message = {
4849
'action': 'authenticate',
4950
'data': {
50-
'oauth_token': self._oauth
51-
} if self._oauth else {
51+
'oauth_token': self._oauth
52+
} if self._oauth else {
5253
'key_id': self._key_id,
5354
'secret_key': self._secret_key,
5455
}
@@ -200,6 +201,7 @@ def deregister(self, channel_pat):
200201
del self._handlers[channel_pat]
201202

202203

204+
@deprecation.deprecated(deprecated_in="v1.0.0", details="Use Stream instead")
203205
class StreamConn(object):
204206
def __init__(
205207
self,

requirements/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ websocket-client>=0.56.0,<2
66
websockets>=8.0,<10
77
msgpack==1.0.2
88
aiohttp==3.7.4
9-
PyYAML==5.4.1
9+
PyYAML==5.4.1
10+
deprecation==2.1.0

0 commit comments

Comments
 (0)