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

bug fix, and add account_number (for IRA account) #387

Merged
merged 4 commits into from
Jun 17, 2023
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
46 changes: 9 additions & 37 deletions robin_stocks/robinhood/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,43 +334,15 @@ def get_option_market_data_by_id(id, info=None):

"""
instrument = get_option_instrument_data_by_id(id)
url = marketdata_options_url()
payload = {
"instruments" : instrument['url']
}
data = request_get(url, 'results', payload)

if not data:
data= {
'adjusted_mark_price':'',
'ask_price':'',
Copy link
Author

@mw66 mw66 Jun 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g it makes no sense to check if data['ask_price'] is empty in the caller, and all other dict keys; instead the caller should just check if data is None.

'ask_size':'',
'bid_price':'',
'bid_size':'',
'break_even_price':'',
'high_price':'',
'instrument':'',
'last_trade_price':'',
'last_trade_size':'',
'low_price':'',
'mark_price':'',
'open_interest':'',
'previous_close_date':'',
'previous_close_price':'',
'volume':'',
'chance_of_profit_long':'',
'chance_of_profit_short':'',
'delta':'',
'gamma':'',
'implied_volatility':'',
'rho':'',
'theta':'',
'vega':'',
'high_fill_rate_buy_price':'',
'high_fill_rate_sell_price':'',
'low_fill_rate_buy_price':'',
'low_fill_rate_sell_price':''
}
if instrument is None:
# e.g. 503 Server Error: Service Unavailable for url: https://api.robinhood.com/options/instruments/d1058013-09a2-4063-b6b0-92717e17d0c0/
return None # just return None which the caller can easily check; do NOT use faked empty data, it will only cause future problem
else:
payload = {
"instruments" : instrument['url']
}
url = marketdata_options_url()
data = request_get(url, 'results', payload)

return(filter_data(data, info))

Expand Down
4 changes: 2 additions & 2 deletions robin_stocks/robinhood/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def get_all_open_stock_orders(info=None):


@login_required
def get_all_open_option_orders(info=None):
def get_all_open_option_orders(info=None, account_number=None):
"""Returns a list of all the orders that are currently open.

:param info: Will filter the results to get a specific value.
Expand All @@ -80,7 +80,7 @@ def get_all_open_option_orders(info=None):
a list of strings is returned where the strings are the value of the key that matches info.

"""
url = option_orders_url()
url = option_orders_url(account_number=account_number)
data = request_get(url, 'pagination')

data = [item for item in data if item['cancel_url'] is not None]
Expand Down
11 changes: 7 additions & 4 deletions robin_stocks/robinhood/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,14 @@ def option_instruments_url(id=None):
return('https://api.robinhood.com/options/instruments/')


def option_orders_url(orderID=None):
def option_orders_url(orderID=None, account_number=None):
url = 'https://api.robinhood.com/options/orders/'
if orderID:
return('https://api.robinhood.com/options/orders/{0}/'.format(orderID))
else:
return('https://api.robinhood.com/options/orders/')
url += '{0}/'.format(orderID)
if account_number:
url += ('?account_numbers='+account_number)

return url


def option_positions_url(account_number):
Expand Down