@@ -704,6 +704,8 @@ def get_hist_option_REST(
704704 date_range : DateRange ,
705705 interval_size : int = 0 ,
706706 use_rth : bool = True ,
707+ host : str = "127.0.0.1" ,
708+ port : str = "25510"
707709 ) -> pd .DataFrame :
708710 """
709711 Get historical options data.
@@ -717,6 +719,8 @@ def get_hist_option_REST(
717719 :param interval_size: The interval size in milliseconds. Applicable to most requests except ReqType.TRADE.
718720 :param use_rth: If true, timestamps prior to 09:30 EST and after 16:00 EST will be ignored
719721 (only applicable to intervals requests).
722+ :param host: The ip address of the server
723+ :param port: The port of the server
720724
721725 :return: The requested data as a pandas DataFrame.
722726 :raises ResponseError: If the request failed.
@@ -729,7 +733,7 @@ def get_hist_option_REST(
729733 end_fmt = _format_date (date_range .end )
730734 right_fmt = right .value
731735 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 } "
733737 querystring = {"root" : root , "start_date" : start_fmt , "end_date" : end_fmt ,
734738 "strike" : strike_fmt , "exp" : exp_fmt , "right" : right_fmt ,
735739 "ivl" : interval_size , "rth" : use_rth_fmt }
@@ -796,6 +800,8 @@ def get_opt_at_time_REST(
796800 right : OptionRight ,
797801 date_range : DateRange ,
798802 ms_of_day : int = 0 ,
803+ host : str = "127.0.0.1" ,
804+ port : str = "25510"
799805 ) -> pd .DataFrame :
800806 """
801807 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(
807813 :param right: The right of an option. CALL = Bullish; PUT = Bearish
808814 :param date_range: The dates to fetch.
809815 :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
810818
811819 :return: The requested data as a pandas DataFrame.
812820 :raises ResponseError: If the request failed.
@@ -820,7 +828,7 @@ def get_opt_at_time_REST(
820828 end_fmt = _format_date (date_range .end )
821829 right_fmt = right .value
822830
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 } "
824832 querystring = {"root" : root , "start_date" : start_fmt , "end_date" : end_fmt , "strike" : strike_fmt ,
825833 "exp" : exp_fmt , "right" : right_fmt , "ivl" : ms_of_day }
826834 response = requests .get (url , params = querystring )
@@ -870,6 +878,8 @@ def get_stk_at_time_REST(
870878 root : str ,
871879 date_range : DateRange ,
872880 ms_of_day : int = 0 ,
881+ host : str = "127.0.0.1" ,
882+ port : str = "25510"
873883 ) -> pd .DataFrame :
874884 """
875885 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(
878888 :param root: The root / underlying / ticker / symbol.
879889 :param date_range: The dates to fetch.
880890 :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
881893
882894 :return: The requested data as a pandas DataFrame.
883895 :raises ResponseError: If the request failed.
@@ -888,7 +900,7 @@ def get_stk_at_time_REST(
888900 start_fmt = _format_date (date_range .start )
889901 end_fmt = _format_date (date_range .end )
890902
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 } "
892904 querystring = {"root" : root_fmt , "start_date" : start_fmt ,
893905 "end_date" : end_fmt , "ivl" : ms_of_day }
894906 response = requests .get (url , params = querystring )
@@ -943,6 +955,8 @@ def get_hist_stock_REST(
943955 date_range : DateRange ,
944956 interval_size : int = 0 ,
945957 use_rth : bool = True ,
958+ host : str = "127.0.0.1" ,
959+ port : str = "25510"
946960 ) -> pd .DataFrame :
947961 """
948962 Get historical stock data.
@@ -952,6 +966,8 @@ def get_hist_stock_REST(
952966 :param date_range: The dates to fetch.
953967 :param interval_size: The interval size in milliseconds. Applicable only to OHLC & QUOTE requests.
954968 :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
955971
956972 :return: The requested data as a pandas DataFrame.
957973 :raises ResponseError: If the request failed.
@@ -962,7 +978,7 @@ def get_hist_stock_REST(
962978 start_fmt = _format_date (date_range .start )
963979 end_fmt = _format_date (date_range .end )
964980 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 } "
966982 params = {"root" : root , "start_date" : start_fmt , "end_date" : end_fmt ,
967983 "ivl" : interval_size , "rth" : use_rth_fmt }
968984 response = requests .get (url , params = params )
@@ -989,20 +1005,22 @@ def get_dates_stk(self, root: str, req: StockReqType) -> pd.Series:
9891005 body = ListBody .parse (out , header , self ._recv (header .size ), dates = True )
9901006 return body .lst
9911007
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 :
9931009 """
9941010 Get all dates of data available for a given stock contract and request type.
9951011
9961012 :param req: The request type.
9971013 :param root: The root / underlying / ticker / symbol.
1014+ :param host: The ip address of the server
1015+ :param port: The port of the server
9981016
9991017 :return: dAll dates that Theta Data provides data for given a request.
10001018 :raises ResponseError: If the request failed.
10011019 :raises NoData: If there is no data available for the request.
10021020 """
10031021 root_fmt = root .lower ()
10041022 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 } "
10061024 params = {'root' : root_fmt }
10071025 response = requests .get (url , params = params )
10081026 series = parse_list_REST (response , dates = True )
@@ -1043,7 +1061,9 @@ def get_dates_opt_REST(
10431061 root : str ,
10441062 exp : date ,
10451063 strike : float ,
1046- right : OptionRight ) -> pd .Series :
1064+ right : OptionRight ,
1065+ host : str = "127.0.0.1" ,
1066+ port : str = "25510" ) -> pd .Series :
10471067 """
10481068 Get all dates of data available for a given options contract and request type.
10491069
@@ -1052,6 +1072,8 @@ def get_dates_opt_REST(
10521072 :param exp: The expiration date. Must be after the start of `date_range`.
10531073 :param strike: The strike price in USD.
10541074 :param right: The right of an options.
1075+ :param host: The ip address of the server
1076+ :param port: The port of the server
10551077
10561078 :return: All dates that Theta Data provides data for given a request.
10571079 :raises ResponseError: If the request failed.
@@ -1062,7 +1084,7 @@ def get_dates_opt_REST(
10621084 strike_fmt = _format_strike (strike )
10631085 right = right .value
10641086 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 } "
10661088 params = {'root' : root , 'exp' : exp_fmt , 'strike' : strike_fmt , 'right' : right }
10671089 response = requests .get (url , params = params )
10681090 df = parse_list_REST (response , dates = True )
@@ -1096,7 +1118,9 @@ def get_dates_opt_bulk_REST(
10961118 self ,
10971119 req : OptionReqType ,
10981120 root : str ,
1099- exp : date ) -> pd .Series :
1121+ exp : date ,
1122+ host : str = "127.0.0.1" ,
1123+ port : str = "25510" ) -> pd .Series :
11001124 """
11011125 Get all dates of data available for a given options contract and request type.
11021126
@@ -1105,6 +1129,8 @@ def get_dates_opt_bulk_REST(
11051129 :param exp: The expiration date. Must be after the start of `date_range`.
11061130 :param strike: The strike price in USD.
11071131 :param right: The right of an options.
1132+ :param host: The ip address of the server
1133+ :param port: The port of the server
11081134
11091135 :return: All dates that Theta Data provides data for given a request.
11101136 :raises ResponseError: If the request failed.
@@ -1113,7 +1139,7 @@ def get_dates_opt_bulk_REST(
11131139 req = req .name .lower ()
11141140 exp_fmt = _format_date (exp )
11151141 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 } "
11171143 params = {'root' : root , 'exp' : exp_fmt }
11181144 response = requests .get (url , params = params )
11191145 df = parse_list_REST (response , dates = True )
@@ -1136,17 +1162,19 @@ def get_expirations(self, root: str) -> pd.Series:
11361162 body = ListBody .parse (out , header , self ._recv (header .size ), dates = True )
11371163 return body .lst
11381164
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 :
11401166 """
11411167 Get all options expirations for a provided underlying root.
11421168
11431169 :param root: The root / underlying / ticker / symbol.
1170+ :param host: The ip address of the server
1171+ :param port: The port of the server
11441172
11451173 :return: All expirations that ThetaData provides data for.
11461174 :raises ResponseError: If the request failed.
11471175 :raises NoData: If there is no data available for the request.
11481176 """
1149- url = "http://127.0.0.1:25510 /list/expirations"
1177+ url = f "http://{ host } : { port } /list/expirations"
11501178 params = {"root" : root }
11511179 response = requests .get (url , params = params )
11521180 df = parse_list_REST (response )
@@ -1188,14 +1216,16 @@ def get_strikes(self, root: str, exp: date, date_range: DateRange = None,) -> pd
11881216 return s
11891217
11901218
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 :
11921220 """
11931221 Get all options strike prices in US tenths of a cent.
11941222
11951223 :param root: The root / underlying / ticker / symbol.
11961224 :param exp: The expiration date.
11971225 :param date_range: If specified, this function will return strikes only if they have data for every
11981226 day in the date range.
1227+ :param host: The ip address of the server
1228+ :param port: The port of the server
11991229
12001230 :return: The strike prices on the expiration.
12011231 :raises ResponseError: If the request failed.
@@ -1210,7 +1240,7 @@ def get_strikes_REST(self, root: str, exp: date, date_range: DateRange = None,)
12101240 querystring = {"root" : root_fmt , "exp" : exp_fmt }
12111241 else :
12121242 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"
12141244 response = requests .get (url , params = querystring )
12151245 ser = parse_list_REST (response )
12161246 ser = ser .divide (1000 )
@@ -1233,17 +1263,19 @@ def get_roots(self, sec: SecType) -> pd.Series:
12331263 body = ListBody .parse (out , header , self ._recv (header .size ))
12341264 return body .lst
12351265
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 :
12371267 """
12381268 Get all roots for a certain security type.
12391269
12401270 :param sec: The type of security.
1271+ :param host: The ip address of the server
1272+ :param port: The port of the server
12411273
12421274 :return: All roots / underlyings / tickers / symbols for the security type.
12431275 :raises ResponseError: If the request failed.
12441276 :raises NoData: If there is no data available for the request.
12451277 """
1246- url = "http://127.0.0.1:25510 /list/roots"
1278+ url = f "http://{ host } : { port } /list/roots"
12471279 params = {'sec' : sec .value }
12481280 response = requests .get (url , params = params )
12491281 df = parse_list_REST (response )
@@ -1295,6 +1327,8 @@ def get_last_option_REST(
12951327 exp : date ,
12961328 strike : float ,
12971329 right : OptionRight ,
1330+ host : str = "127.0.0.1" ,
1331+ port : str = "25510"
12981332 ) -> pd .DataFrame :
12991333 """
13001334 Get the most recent options tick.
@@ -1304,6 +1338,8 @@ def get_last_option_REST(
13041338 :param exp: The expiration date.
13051339 :param strike: The strike price in USD, rounded to 1/10th of a cent.
13061340 :param right: The right of an options.
1341+ :param host: The ip address of the server
1342+ :param port: The port of the server
13071343
13081344 :return: The requested data as a pandas DataFrame.
13091345 :raises ResponseError: If the request failed.
@@ -1315,7 +1351,7 @@ def get_last_option_REST(
13151351 strike_fmt = _format_strike (strike )
13161352 exp_fmt = _format_date (exp )
13171353
1318- url = f"http://127.0.0.1:25510 /snapshot/option/{ req_fmt } "
1354+ url = f"http://{ host } : { port } /snapshot/option/{ req_fmt } "
13191355 querystring = {"root" : root_fmt , "strike" : strike_fmt , "exp" : exp_fmt , "right" : right_fmt }
13201356 response = requests .get (url , params = querystring )
13211357 df = parse_flexible_REST (response )
@@ -1353,6 +1389,8 @@ def get_last_stock_REST(
13531389 self ,
13541390 req : StockReqType ,
13551391 root : str ,
1392+ host : str = "127.0.0.1" ,
1393+ port : str = "25510"
13561394 ) -> pd .DataFrame :
13571395 """
13581396 Get the most recent options tick.
@@ -1362,6 +1400,8 @@ def get_last_stock_REST(
13621400 :param exp: The expiration date.
13631401 :param strike: The strike price in USD, rounded to 1/10th of a cent.
13641402 :param right: The right of an options.
1403+ :param host: The ip address of the server
1404+ :param port: The port of the server
13651405
13661406 :return: The requested data as a pandas DataFrame.
13671407 :raises ResponseError: If the request failed.
@@ -1370,7 +1410,7 @@ def get_last_stock_REST(
13701410 root_fmt = root .lower ()
13711411 req_fmt = req .name .lower ()
13721412
1373- url = f"http://127.0.0.1:25510 /snapshot/option/{ req_fmt } "
1413+ url = f"http://{ host } : { port } /snapshot/option/{ req_fmt } "
13741414 querystring = {"root" : root_fmt }
13751415 response = requests .get (url , params = querystring )
13761416 df = parse_flexible_REST (response )
0 commit comments