diff --git a/robin_stocks/robinhood/orders.py b/robin_stocks/robinhood/orders.py index 30a6f22..a5589d5 100644 --- a/robin_stocks/robinhood/orders.py +++ b/robin_stocks/robinhood/orders.py @@ -8,31 +8,35 @@ from robin_stocks.robinhood.urls import * @login_required -def get_all_stock_orders(info=None, account_number=None): +def get_all_stock_orders(info=None, account_number=None, start_date=None): """Returns a list of all the orders that have been processed for the account. :param info: Will filter the results to get a specific value. :type info: Optional[str] + :param start_date: Sets the date of when to start returning orders, returns all orders up to current date and time. + :type date: Optional[str] format, should this be sent as a DT object? I believe it's safer to require it to be handed to the function as a string. :returns: Returns a list of dictionaries of key/value pairs for each order. If info parameter is provided, \ a list of strings is returned where the strings are the value of the key that matches info. """ - url = orders_url(account_number=account_number) + url = orders_url(account_number=account_number, start_date=start_date) data = request_get(url, 'pagination') return(filter_data(data, info)) @login_required -def get_all_option_orders(info=None, account_number=None): +def get_all_option_orders(info=None, account_number=None, start_date=None): """Returns a list of all the option orders that have been processed for the account. :param info: Will filter the results to get a specific value. :type info: Optional[str] + :param start_date: Sets the date of when to start returning orders, returns all orders up to current date and time. + :type date: Optional[str] format, should this be sent as a DT object? I believe it's safer to require it to be handed to the function as a string. :returns: Returns a list of dictionaries of key/value pairs for each option order. If info parameter is provided, \ a list of strings is returned where the strings are the value of the key that matches info. """ - url = option_orders_url(account_number=account_number) + url = option_orders_url(account_number=account_number, start_date=start_date) data = request_get(url, 'pagination') return(filter_data(data, info)) diff --git a/robin_stocks/robinhood/urls.py b/robin_stocks/robinhood/urls.py index 353352a..232b222 100644 --- a/robin_stocks/robinhood/urls.py +++ b/robin_stocks/robinhood/urls.py @@ -222,16 +222,27 @@ def option_instruments_url(id=None): return('https://api.robinhood.com/options/instruments/') -def option_orders_url(orderID=None, account_number=None): +def option_orders_url(orderID=None, account_number=None, start_date=None): url = 'https://api.robinhood.com/options/orders/' if orderID: url += '{0}/'.format(orderID) + query_build = [] if account_number: - url += ('?account_numbers='+account_number) + query_build.append(f"account_numbers={account_number}") + if start_date: + query_build.append(f"updated_at[gte]={start_date}") + + if query_build: + for index, value in enumerate(query_build): + if index == 0: + url += "?" + value + else: + url += "&" + value return url + def option_positions_url(account_number): if account_number: return('https://api.robinhood.com/options/positions/?account_numbers='+account_number) @@ -300,11 +311,22 @@ def option_cancel_url(id): return('https://api.robinhood.com/options/orders/{0}/cancel/'.format(id)) -def orders_url(orderID=None, account_number=None): +def orders_url(orderID=None, account_number=None, start_date=None): url = 'https://api.robinhood.com/orders/' if orderID: url += '{0}/'.format(orderID) + + query_build = [] if account_number: - url += ('?account_numbers='+account_number) + query_build.append(f"account_numbers={account_number}") + if start_date: + query_build.append(f"updated_at[gte]={start_date}") - return url \ No newline at end of file + if query_build: + for index, value in enumerate(query_build): + if index == 0: + url += "?" + value + else: + url += "&" + value + + return url diff --git a/setup.py b/setup.py index f68f358..79f5d47 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ long_description = f.read() setup(name='robin_stocks', - version='3.2.1', + version='3.3.0', description='A Python wrapper around the Robinhood API', long_description=long_description, long_description_content_type='text/x-rst',