11import requests
22from .entity import (
33 Aggs , Aggsv2 , Aggsv2Set ,
4- Trade , Trades ,
5- Quote , Quotes ,
4+ Trade , Trades , TradesV2 ,
5+ Quote , Quotes , QuotesV2 ,
66 Exchange , SymbolTypeMap , ConditionMap ,
77 Company , Dividends , Splits , Earnings , Financials , NewsList , Ticker
88)
99from alpaca_trade_api .common import get_polygon_credentials
10+ from deprecated import deprecated
1011
1112
1213def _is_list_like (o ):
@@ -41,6 +42,10 @@ def symbol_type_map(self):
4142 path = '/meta/symbol-types'
4243 return SymbolTypeMap (self .get (path ))
4344
45+ @deprecated (
46+ 'historic_trades v1 is deprecated and will be removed from the ' +
47+ 'Polygon API in the future. Please upgrade to historic_trades_v2.'
48+ )
4449 def historic_trades (self , symbol , date , offset = None , limit = None ):
4550 path = '/historic/trades/{}/{}' .format (symbol , date )
4651 params = {}
@@ -52,6 +57,28 @@ def historic_trades(self, symbol, date, offset=None, limit=None):
5257
5358 return Trades (raw )
5459
60+ def historic_trades_v2 (
61+ self , symbol , date , timestamp = None , timestamp_limit = None ,
62+ reverse = None , limit = None
63+ ):
64+ path = '/ticks/stocks/trades/{}/{}' .format (symbol , date )
65+ params = {}
66+ if timestamp is not None :
67+ params ['timestamp' ] = timestamp
68+ if timestamp_limit is not None :
69+ params ['timestampLimit' ] = timestamp_limit
70+ if reverse is not None :
71+ params ['reverse' ] = reverse
72+ if limit is not None :
73+ params ['limit' ] = limit
74+ raw = self .get (path , params , 'v2' )
75+
76+ return TradesV2 (raw )
77+
78+ @deprecated (
79+ 'historic_quotes v1 is deprecated and will be removed from the ' +
80+ 'Polygon API in the future. Please upgrade to historic_quotes_v2.'
81+ )
5582 def historic_quotes (self , symbol , date , offset = None , limit = None ):
5683 path = '/historic/quotes/{}/{}' .format (symbol , date )
5784 params = {}
@@ -63,6 +90,24 @@ def historic_quotes(self, symbol, date, offset=None, limit=None):
6390
6491 return Quotes (raw )
6592
93+ def historic_quotes_v2 (
94+ self , symbol , date , timestamp = None , timestamp_limit = None ,
95+ reverse = None , limit = None
96+ ):
97+ path = '/ticks/stocks/nbbo/{}/{}' .format (symbol , date )
98+ params = {}
99+ if timestamp is not None :
100+ params ['timestamp' ] = timestamp
101+ if timestamp_limit is not None :
102+ params ['timestampLimit' ] = timestamp_limit
103+ if reverse is not None :
104+ params ['reverse' ] = reverse
105+ if limit is not None :
106+ params ['limit' ] = limit
107+ raw = self .get (path , params , 'v2' )
108+
109+ return QuotesV2 (raw )
110+
66111 def historic_agg (self , size , symbol ,
67112 _from = None , to = None , limit = None ):
68113 path = '/historic/agg/{}/{}' .format (size , symbol )
0 commit comments