Skip to content

Commit

Permalink
Merge pull request #387 from mw66/master
Browse files Browse the repository at this point in the history
bug fix, and add account_number (for IRA account)
  • Loading branch information
jmfernandes authored Jun 17, 2023
2 parents 2a34e26 + c789636 commit 0e24a10
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 43 deletions.
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':'',
'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

0 comments on commit 0e24a10

Please sign in to comment.