Skip to content

Commit bf434ac

Browse files
committed
add price history fix
1 parent 1310df2 commit bf434ac

3 files changed

Lines changed: 27 additions & 25 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,5 @@ pypirc
117117
tests/parse_level_two.py
118118
certs/
119119
td/td_state.json
120+
tests/api_pipeline.py
121+
tests/api_streaming.py

samples/api_streaming.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,123 +4,123 @@
44
from datetime import timedelta
55
from td.client import TDClient
66

7-
# Create a new session
7+
# Create a new session.
88
TDSession = TDClient(
99
client_id='<CLIENT_ID>',
1010
redirect_uri='<REDIRECT_URI>',
1111
credentials_path='<CREDENTIALS_PATH>'
1212
)
1313

14-
# Login to the session
14+
# Login to the session.
1515
TDSession.login()
1616

17-
# Create a streaming session
17+
# Create a streaming session.
1818
TDStreamingClient = TDSession.create_streaming_session()
1919

20-
# Set the data dump location
20+
# Set the data dump location.
2121
TDStreamingClient.write_behavior(
2222
write='csv',
2323
file_path=r"../td-ameritrade-python-api/samples/raw_data.csv",
2424
append_mode=True
2525
)
2626

27-
# Account Activity
27+
# Account Activity.
2828
TDStreamingClient.account_activity()
2929

30-
# Actives
30+
# Actives.
3131
TDStreamingClient.actives(
3232
service='ACTIVES_NASDAQ',
3333
venue='NASDAQ',
3434
duration='ALL'
3535
)
3636

37-
# Quality of Service
37+
# Quality of Service.
3838
TDStreamingClient.quality_of_service(qos_level='express')
3939

40-
# Level One Quote
40+
# Level One - Quote.
4141
TDStreamingClient.level_one_quotes(
4242
symbols=["SPY", "IVV", "SDS"],
4343
fields=list(range(0, 50))
4444
)
4545

46-
# Level One Option
46+
# Level One - Option.
4747
TDStreamingClient.level_one_options(
4848
symbols=['AAPL_040920C115'],
4949
fields=list(range(0, 42))
5050
)
5151

52-
# Level One Futures
52+
# Level One - Futures.
5353
TDStreamingClient.level_one_futures(
5454
symbols=['/CL'],
5555
fields=list(range(0, 34))
5656
)
5757

58-
# Level One Forex
58+
# Level One - Forex.
5959
TDStreamingClient.level_one_forex(
6060
symbols=['EUR/USD'],
6161
fields=list(range(0, 20))
6262
)
6363

64-
# Level One Futures Options
64+
# Level One - Futures Options.
6565
TDStreamingClient.level_one_futures_options(
6666
symbols=['./EW2J20C2675'],
6767
fields=list(range(0, 36))
6868
)
6969

70-
# Charts Futures
70+
# Charts - Futures.
7171
TDStreamingClient.chart(
7272
service='CHART_EQUITY',
7373
symbols=['AAPL', 'MSFT'],
7474
fields=[0, 1, 2, 3, 4, 5, 6, 7]
7575
)
7676

77-
# Chart History Futures
77+
# Chart History - Futures.
7878
TDStreamingClient.chart_history_futures(
7979
symbol=['/ES'],
8080
frequency='m1',
8181
start_time='1586304000000',
8282
end_time='1586329200000'
8383
)
8484

85-
# Timesale - Equity
85+
# Timesale - Equity.
8686
TDStreamingClient.timesale(
8787
service='TIMESALE_EQUITY',
8888
symbols=['AAPL'],
8989
fields=[0, 1, 2, 3, 4]
9090
)
9191

92-
# Timesale - Futures
92+
# Timesale - Futures.
9393
TDStreamingClient.timesale(
9494
service='TIMESALE_FUTURES',
9595
symbols=['/ES'],
9696
fields=[0, 1, 2, 3, 4]
9797
)
9898

99-
# News Headline
99+
# News Headline.
100100
TDStreamingClient.news_headline(
101101
symbols=['AAPL', 'SPY'],
102102
fields=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
103103
)
104104

105-
# Level Two Quotes
105+
# Level Two - Quotes.
106106
TDStreamingClient.level_two_quotes(
107107
symbols=['IBM'],
108108
fields=[0, 1, 2]
109109
)
110110

111-
# Level Two Options
111+
# Level Two - Options.
112112
TDStreamingClient.level_two_options(
113113
symbols=['AAPL_040920C115'],
114114
fields=[0, 1, 2]
115115
)
116116

117-
# Level Two NASQDAQ
117+
# Level Two - NASQDAQ.
118118
TDStreamingClient.level_two_nasdaq(
119119
symbols=['MSFT'],
120120
fields=[0, 1, 2]
121121
)
122122

123-
# Level Two Total View
123+
# Level Two - Total View.
124124
TDStreamingClient.level_two_total_view(
125125
symbols=['AAPL'],
126126
fields=['0', '1', '2']

td/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def __init__(self, client_id: str, redirect_uri: str, account_number: str = None
115115
else:
116116
self._flask_app = None
117117

118-
# define a new attribute called 'authstate' and initalize it to '' (Blank). This will be used by our login function.
118+
# define a new attribute called 'authstate' and initialize to `False`. This will be used by our login function.
119119
self.authstate = False
120120

121121
# call the state_manager method and update the state to init (initalized)
@@ -702,7 +702,7 @@ def get_quotes(self, instruments: List) -> Dict:
702702
# return the response of the get request.
703703
return self._make_request(method='get', endpoint=endpoint, params=params)
704704

705-
def get_price_history(self, symbol: str, period_type:str = None, period=None, start_date:str = None, end_date:str = None,
705+
def get_price_history(self, symbol: str, period_type:str = None, period: str = None, start_date:str = None, end_date:str = None,
706706
frequency_type: str = None, frequency: str = None, extended_hours: bool = True) -> Dict:
707707
"""Gets historical candle data for a financial instrument.
708708
@@ -748,14 +748,14 @@ def get_price_history(self, symbol: str, period_type:str = None, period=None, st
748748
try:
749749

750750
# check if the period is valid.
751-
if period in VALID_CHART_VALUES[frequency_type][period_type]:
751+
if period in VALID_CHART_VALUES[frequency_type][int(period_type)]:
752752
True
753753
else:
754754
raise IndexError('Invalid Period.')
755755
except:
756756
raise KeyError('Invalid Frequency Type or Period Type you passed through is not valid')
757757

758-
if frequency_type == 'minute' and frequency not in [1, 5, 10, 15, 30]:
758+
if frequency_type == 'minute' and frequency not in ['1', '5', '10', '15', '30']:
759759
raise ValueError('Invalid Minute Frequency, must be 1,5,10,15,30')
760760

761761
# build the params dictionary

0 commit comments

Comments
 (0)