Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All orders start date parameter #517

Merged
merged 6 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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