@@ -704,6 +704,8 @@ def get_hist_option_REST(
704
704
date_range : DateRange ,
705
705
interval_size : int = 0 ,
706
706
use_rth : bool = True ,
707
+ host : str = "127.0.0.1" ,
708
+ port : str = "25510"
707
709
) -> pd .DataFrame :
708
710
"""
709
711
Get historical options data.
@@ -717,6 +719,8 @@ def get_hist_option_REST(
717
719
:param interval_size: The interval size in milliseconds. Applicable to most requests except ReqType.TRADE.
718
720
:param use_rth: If true, timestamps prior to 09:30 EST and after 16:00 EST will be ignored
719
721
(only applicable to intervals requests).
722
+ :param host: The ip address of the server
723
+ :param port: The port of the server
720
724
721
725
:return: The requested data as a pandas DataFrame.
722
726
:raises ResponseError: If the request failed.
@@ -729,7 +733,7 @@ def get_hist_option_REST(
729
733
end_fmt = _format_date (date_range .end )
730
734
right_fmt = right .value
731
735
use_rth_fmt = str (use_rth ).lower ()
732
- url = f"http://127.0.0.1:25510 /hist/option/{ req_fmt } "
736
+ url = f"http://{ host } : { port } /hist/option/{ req_fmt } "
733
737
querystring = {"root" : root , "start_date" : start_fmt , "end_date" : end_fmt ,
734
738
"strike" : strike_fmt , "exp" : exp_fmt , "right" : right_fmt ,
735
739
"ivl" : interval_size , "rth" : use_rth_fmt }
@@ -796,6 +800,8 @@ def get_opt_at_time_REST(
796
800
right : OptionRight ,
797
801
date_range : DateRange ,
798
802
ms_of_day : int = 0 ,
803
+ host : str = "127.0.0.1" ,
804
+ port : str = "25510"
799
805
) -> pd .DataFrame :
800
806
"""
801
807
Returns the last tick at a provided millisecond of the day for a given request type.
@@ -807,6 +813,8 @@ def get_opt_at_time_REST(
807
813
:param right: The right of an option. CALL = Bullish; PUT = Bearish
808
814
:param date_range: The dates to fetch.
809
815
:param ms_of_day: The time of day in milliseconds.
816
+ :param host: The ip address of the server
817
+ :param port: The port of the server
810
818
811
819
:return: The requested data as a pandas DataFrame.
812
820
:raises ResponseError: If the request failed.
@@ -820,7 +828,7 @@ def get_opt_at_time_REST(
820
828
end_fmt = _format_date (date_range .end )
821
829
right_fmt = right .value
822
830
823
- url = f"http://127.0.0.1:25510 /at_time/option/{ req_fmt } "
831
+ url = f"http://{ host } : { port } /at_time/option/{ req_fmt } "
824
832
querystring = {"root" : root , "start_date" : start_fmt , "end_date" : end_fmt , "strike" : strike_fmt ,
825
833
"exp" : exp_fmt , "right" : right_fmt , "ivl" : ms_of_day }
826
834
response = requests .get (url , params = querystring )
@@ -870,6 +878,8 @@ def get_stk_at_time_REST(
870
878
root : str ,
871
879
date_range : DateRange ,
872
880
ms_of_day : int = 0 ,
881
+ host : str = "127.0.0.1" ,
882
+ port : str = "25510"
873
883
) -> pd .DataFrame :
874
884
"""
875
885
Returns the last tick at a provided millisecond of the day for a given request type.
@@ -878,6 +888,8 @@ def get_stk_at_time_REST(
878
888
:param root: The root / underlying / ticker / symbol.
879
889
:param date_range: The dates to fetch.
880
890
:param ms_of_day: The time of day in milliseconds.
891
+ :param host: The ip address of the server
892
+ :param port: The port of the server
881
893
882
894
:return: The requested data as a pandas DataFrame.
883
895
:raises ResponseError: If the request failed.
@@ -888,7 +900,7 @@ def get_stk_at_time_REST(
888
900
start_fmt = _format_date (date_range .start )
889
901
end_fmt = _format_date (date_range .end )
890
902
891
- url = f"http://127.0.0.1:25510 /at_time/stock/{ req_fmt } "
903
+ url = f"http://{ host } : { port } /at_time/stock/{ req_fmt } "
892
904
querystring = {"root" : root_fmt , "start_date" : start_fmt ,
893
905
"end_date" : end_fmt , "ivl" : ms_of_day }
894
906
response = requests .get (url , params = querystring )
@@ -943,6 +955,8 @@ def get_hist_stock_REST(
943
955
date_range : DateRange ,
944
956
interval_size : int = 0 ,
945
957
use_rth : bool = True ,
958
+ host : str = "127.0.0.1" ,
959
+ port : str = "25510"
946
960
) -> pd .DataFrame :
947
961
"""
948
962
Get historical stock data.
@@ -952,6 +966,8 @@ def get_hist_stock_REST(
952
966
:param date_range: The dates to fetch.
953
967
:param interval_size: The interval size in milliseconds. Applicable only to OHLC & QUOTE requests.
954
968
:param use_rth: If true, timestamps prior to 09:30 EST and after 16:00 EST will be ignored.
969
+ :param host: The ip address of the server
970
+ :param port: The port of the server
955
971
956
972
:return: The requested data as a pandas DataFrame.
957
973
:raises ResponseError: If the request failed.
@@ -962,7 +978,7 @@ def get_hist_stock_REST(
962
978
start_fmt = _format_date (date_range .start )
963
979
end_fmt = _format_date (date_range .end )
964
980
use_rth_fmt = str (use_rth ).lower ()
965
- url = f"http://127.0.0.1:25510 /hist/stock/{ req_fmt } "
981
+ url = f"http://{ host } : { port } /hist/stock/{ req_fmt } "
966
982
params = {"root" : root , "start_date" : start_fmt , "end_date" : end_fmt ,
967
983
"ivl" : interval_size , "rth" : use_rth_fmt }
968
984
response = requests .get (url , params = params )
@@ -989,20 +1005,22 @@ def get_dates_stk(self, root: str, req: StockReqType) -> pd.Series:
989
1005
body = ListBody .parse (out , header , self ._recv (header .size ), dates = True )
990
1006
return body .lst
991
1007
992
- def get_dates_stk_REST (self , root : str , req : StockReqType ) -> pd .Series :
1008
+ def get_dates_stk_REST (self , root : str , req : StockReqType , host : str = "127.0.0.1" , port : str = "25510" ) -> pd .Series :
993
1009
"""
994
1010
Get all dates of data available for a given stock contract and request type.
995
1011
996
1012
:param req: The request type.
997
1013
:param root: The root / underlying / ticker / symbol.
1014
+ :param host: The ip address of the server
1015
+ :param port: The port of the server
998
1016
999
1017
:return: dAll dates that Theta Data provides data for given a request.
1000
1018
:raises ResponseError: If the request failed.
1001
1019
:raises NoData: If there is no data available for the request.
1002
1020
"""
1003
1021
root_fmt = root .lower ()
1004
1022
req_fmt = req .name .lower ()
1005
- url = f"http://127.0.0.1:25510 /list/dates/stock/{ req_fmt } "
1023
+ url = f"http://{ host } : { port } /list/dates/stock/{ req_fmt } "
1006
1024
params = {'root' : root_fmt }
1007
1025
response = requests .get (url , params = params )
1008
1026
series = parse_list_REST (response , dates = True )
@@ -1043,7 +1061,9 @@ def get_dates_opt_REST(
1043
1061
root : str ,
1044
1062
exp : date ,
1045
1063
strike : float ,
1046
- right : OptionRight ) -> pd .Series :
1064
+ right : OptionRight ,
1065
+ host : str = "127.0.0.1" ,
1066
+ port : str = "25510" ) -> pd .Series :
1047
1067
"""
1048
1068
Get all dates of data available for a given options contract and request type.
1049
1069
@@ -1052,6 +1072,8 @@ def get_dates_opt_REST(
1052
1072
:param exp: The expiration date. Must be after the start of `date_range`.
1053
1073
:param strike: The strike price in USD.
1054
1074
:param right: The right of an options.
1075
+ :param host: The ip address of the server
1076
+ :param port: The port of the server
1055
1077
1056
1078
:return: All dates that Theta Data provides data for given a request.
1057
1079
:raises ResponseError: If the request failed.
@@ -1062,7 +1084,7 @@ def get_dates_opt_REST(
1062
1084
strike_fmt = _format_strike (strike )
1063
1085
right = right .value
1064
1086
sec = SecType .OPTION .value .lower ()
1065
- url = f"http://127.0.0.1:25510 /list/dates/{ sec } /{ req } "
1087
+ url = f"http://{ host } : { port } /list/dates/{ sec } /{ req } "
1066
1088
params = {'root' : root , 'exp' : exp_fmt , 'strike' : strike_fmt , 'right' : right }
1067
1089
response = requests .get (url , params = params )
1068
1090
df = parse_list_REST (response , dates = True )
@@ -1096,7 +1118,9 @@ def get_dates_opt_bulk_REST(
1096
1118
self ,
1097
1119
req : OptionReqType ,
1098
1120
root : str ,
1099
- exp : date ) -> pd .Series :
1121
+ exp : date ,
1122
+ host : str = "127.0.0.1" ,
1123
+ port : str = "25510" ) -> pd .Series :
1100
1124
"""
1101
1125
Get all dates of data available for a given options contract and request type.
1102
1126
@@ -1105,6 +1129,8 @@ def get_dates_opt_bulk_REST(
1105
1129
:param exp: The expiration date. Must be after the start of `date_range`.
1106
1130
:param strike: The strike price in USD.
1107
1131
:param right: The right of an options.
1132
+ :param host: The ip address of the server
1133
+ :param port: The port of the server
1108
1134
1109
1135
:return: All dates that Theta Data provides data for given a request.
1110
1136
:raises ResponseError: If the request failed.
@@ -1113,7 +1139,7 @@ def get_dates_opt_bulk_REST(
1113
1139
req = req .name .lower ()
1114
1140
exp_fmt = _format_date (exp )
1115
1141
sec = SecType .OPTION .value .lower ()
1116
- url = f"http://127.0.0.1:25510 /list/dates/{ sec } /{ req } "
1142
+ url = f"http://{ host } : { port } /list/dates/{ sec } /{ req } "
1117
1143
params = {'root' : root , 'exp' : exp_fmt }
1118
1144
response = requests .get (url , params = params )
1119
1145
df = parse_list_REST (response , dates = True )
@@ -1136,17 +1162,19 @@ def get_expirations(self, root: str) -> pd.Series:
1136
1162
body = ListBody .parse (out , header , self ._recv (header .size ), dates = True )
1137
1163
return body .lst
1138
1164
1139
- def get_expirations_REST (self , root : str ) -> pd .Series :
1165
+ def get_expirations_REST (self , root : str , host : str = "127.0.0.1" , port : str = "25510" ) -> pd .Series :
1140
1166
"""
1141
1167
Get all options expirations for a provided underlying root.
1142
1168
1143
1169
:param root: The root / underlying / ticker / symbol.
1170
+ :param host: The ip address of the server
1171
+ :param port: The port of the server
1144
1172
1145
1173
:return: All expirations that ThetaData provides data for.
1146
1174
:raises ResponseError: If the request failed.
1147
1175
:raises NoData: If there is no data available for the request.
1148
1176
"""
1149
- url = "http://127.0.0.1:25510 /list/expirations"
1177
+ url = f "http://{ host } : { port } /list/expirations"
1150
1178
params = {"root" : root }
1151
1179
response = requests .get (url , params = params )
1152
1180
df = parse_list_REST (response )
@@ -1188,14 +1216,16 @@ def get_strikes(self, root: str, exp: date, date_range: DateRange = None,) -> pd
1188
1216
return s
1189
1217
1190
1218
1191
- def get_strikes_REST (self , root : str , exp : date , date_range : DateRange = None ,) -> pd .Series :
1219
+ def get_strikes_REST (self , root : str , exp : date , date_range : DateRange = None , host : str = "127.0.0.1" , port : str = "25510" ) -> pd .Series :
1192
1220
"""
1193
1221
Get all options strike prices in US tenths of a cent.
1194
1222
1195
1223
:param root: The root / underlying / ticker / symbol.
1196
1224
:param exp: The expiration date.
1197
1225
:param date_range: If specified, this function will return strikes only if they have data for every
1198
1226
day in the date range.
1227
+ :param host: The ip address of the server
1228
+ :param port: The port of the server
1199
1229
1200
1230
:return: The strike prices on the expiration.
1201
1231
:raises ResponseError: If the request failed.
@@ -1210,7 +1240,7 @@ def get_strikes_REST(self, root: str, exp: date, date_range: DateRange = None,)
1210
1240
querystring = {"root" : root_fmt , "exp" : exp_fmt }
1211
1241
else :
1212
1242
querystring = {"root" : root_fmt , "exp" : exp_fmt }
1213
- url = "http://127.0.0.1:25510 /list/strikes"
1243
+ url = f "http://{ host } : { port } /list/strikes"
1214
1244
response = requests .get (url , params = querystring )
1215
1245
ser = parse_list_REST (response )
1216
1246
ser = ser .divide (1000 )
@@ -1233,17 +1263,19 @@ def get_roots(self, sec: SecType) -> pd.Series:
1233
1263
body = ListBody .parse (out , header , self ._recv (header .size ))
1234
1264
return body .lst
1235
1265
1236
- def get_roots_REST (self , sec : SecType ) -> pd .Series :
1266
+ def get_roots_REST (self , sec : SecType , host : str = "127.0.0.1" , port : str = "25510" ) -> pd .Series :
1237
1267
"""
1238
1268
Get all roots for a certain security type.
1239
1269
1240
1270
:param sec: The type of security.
1271
+ :param host: The ip address of the server
1272
+ :param port: The port of the server
1241
1273
1242
1274
:return: All roots / underlyings / tickers / symbols for the security type.
1243
1275
:raises ResponseError: If the request failed.
1244
1276
:raises NoData: If there is no data available for the request.
1245
1277
"""
1246
- url = "http://127.0.0.1:25510 /list/roots"
1278
+ url = f "http://{ host } : { port } /list/roots"
1247
1279
params = {'sec' : sec .value }
1248
1280
response = requests .get (url , params = params )
1249
1281
df = parse_list_REST (response )
@@ -1295,6 +1327,8 @@ def get_last_option_REST(
1295
1327
exp : date ,
1296
1328
strike : float ,
1297
1329
right : OptionRight ,
1330
+ host : str = "127.0.0.1" ,
1331
+ port : str = "25510"
1298
1332
) -> pd .DataFrame :
1299
1333
"""
1300
1334
Get the most recent options tick.
@@ -1304,6 +1338,8 @@ def get_last_option_REST(
1304
1338
:param exp: The expiration date.
1305
1339
:param strike: The strike price in USD, rounded to 1/10th of a cent.
1306
1340
:param right: The right of an options.
1341
+ :param host: The ip address of the server
1342
+ :param port: The port of the server
1307
1343
1308
1344
:return: The requested data as a pandas DataFrame.
1309
1345
:raises ResponseError: If the request failed.
@@ -1315,7 +1351,7 @@ def get_last_option_REST(
1315
1351
strike_fmt = _format_strike (strike )
1316
1352
exp_fmt = _format_date (exp )
1317
1353
1318
- url = f"http://127.0.0.1:25510 /snapshot/option/{ req_fmt } "
1354
+ url = f"http://{ host } : { port } /snapshot/option/{ req_fmt } "
1319
1355
querystring = {"root" : root_fmt , "strike" : strike_fmt , "exp" : exp_fmt , "right" : right_fmt }
1320
1356
response = requests .get (url , params = querystring )
1321
1357
df = parse_flexible_REST (response )
@@ -1353,6 +1389,8 @@ def get_last_stock_REST(
1353
1389
self ,
1354
1390
req : StockReqType ,
1355
1391
root : str ,
1392
+ host : str = "127.0.0.1" ,
1393
+ port : str = "25510"
1356
1394
) -> pd .DataFrame :
1357
1395
"""
1358
1396
Get the most recent options tick.
@@ -1362,6 +1400,8 @@ def get_last_stock_REST(
1362
1400
:param exp: The expiration date.
1363
1401
:param strike: The strike price in USD, rounded to 1/10th of a cent.
1364
1402
:param right: The right of an options.
1403
+ :param host: The ip address of the server
1404
+ :param port: The port of the server
1365
1405
1366
1406
:return: The requested data as a pandas DataFrame.
1367
1407
:raises ResponseError: If the request failed.
@@ -1370,7 +1410,7 @@ def get_last_stock_REST(
1370
1410
root_fmt = root .lower ()
1371
1411
req_fmt = req .name .lower ()
1372
1412
1373
- url = f"http://127.0.0.1:25510 /snapshot/option/{ req_fmt } "
1413
+ url = f"http://{ host } : { port } /snapshot/option/{ req_fmt } "
1374
1414
querystring = {"root" : root_fmt }
1375
1415
response = requests .get (url , params = querystring )
1376
1416
df = parse_flexible_REST (response )
0 commit comments