Skip to content

Commit

Permalink
Merge pull request #517 from noLeash/order-req-start-date
Browse files Browse the repository at this point in the history
All orders start date parameter
  • Loading branch information
jmfernandes authored Dec 22, 2024
2 parents 729a0de + d966293 commit 63ae3fc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
12 changes: 8 additions & 4 deletions robin_stocks/robinhood/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
32 changes: 27 additions & 5 deletions robin_stocks/robinhood/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
if query_build:
for index, value in enumerate(query_build):
if index == 0:
url += "?" + value
else:
url += "&" + value

return url
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 63ae3fc

Please sign in to comment.