Skip to content
Open
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
11 changes: 10 additions & 1 deletion robin_stocks/robinhood/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import requests
from robin_stocks.robinhood.globals import LOGGED_IN, OUTPUT, SESSION

index_opt_list = ['SPX', 'NDX', 'VIX', 'RUT', 'XSP']

def set_login_state(logged_in):
"""Sets the login state"""
Expand Down Expand Up @@ -61,6 +62,8 @@ def id_for_stock(symbol):
return(None)

url = 'https://api.robinhood.com/instruments/'
if symbol in index_opt_list:
url = 'https://api.robinhood.com/indexes/'
payload = {'symbol': symbol}
data = request_get(url, 'indexzero', payload)

Expand All @@ -82,11 +85,17 @@ def id_for_chain(symbol):
return(None)

url = 'https://api.robinhood.com/instruments/'

if symbol in index_opt_list:
url = 'https://api.robinhood.com/indexes/'
payload = {'symbol': symbol}

data = request_get(url, 'indexzero', payload)

if data:
if symbol in index_opt_list:
sorted_chain_ids = sorted(data['tradable_chain_ids'])
idx = 0 if symbol in ['RUT', 'NDX', 'SPX', 'VIX'] else -1 # , 'SPX' 'SPX',
return(sorted_chain_ids[idx]) # pick first from multi-chain_ids
return(data['tradable_chain_id'])
else:
return(data)
Expand Down
2 changes: 1 addition & 1 deletion robin_stocks/robinhood/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def find_tradable_options(symbol, expirationDate=None, strikePrice=None, optionT
return [None]

payload = {'chain_id': id_for_chain(symbol),
'chain_symbol': symbol,
'chain_symbol': (symbol+"P") if symbol == 'NDX' else ((symbol+'W') if symbol in ['SPX', 'RUT', 'VIX'] else symbol),
'state': 'active'}

if expirationDate:
Expand Down
37 changes: 36 additions & 1 deletion robin_stocks/robinhood/stocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,39 @@ def get_stock_historicals(inputSymbols, interval='hour', span='week', bounds='re
return(filter_data(histData, info))


def get_index_quote_by_id(stock_id, info=None):
"""
Represents basic stock quote information

:param stock_id: robinhood stock id
:type stock_id: str
:param info: Will filter the results to get a specific value. Possible options are url, instrument, execution_date, \
divsor, and multiplier.
:type info: Optional[str]
:return: [dict] If the info parameter is provided, then the function will extract the value of the key \
that matches the info parameter. Otherwise, the whole dictionary is returned.
:Dictionary Keys: * ask_price
* ask_size
* bid_price
* bid_size
* last_trade_price
* last_extended_hours_trade_price
* previous_close
* adjusted_previous_close
* previous_close_date
* symbol
* trading_halted
* has_traded
* last_trade_price_source
* updated_at
* instrument
"""
url = marketdata_index_quotes_url(stock_id)
data = request_get(url)

return (filter_data(data, info))


def get_stock_quote_by_id(stock_id, info=None):
"""
Represents basic stock quote information
Expand Down Expand Up @@ -645,7 +678,9 @@ def get_stock_quote_by_symbol(symbol, info=None):
* updated_at
* instrument
"""

if symbol in index_opt_list:
return get_index_quote_by_id(id_for_stock(symbol))

return get_stock_quote_by_id(id_for_stock(symbol))


Expand Down
3 changes: 3 additions & 0 deletions robin_stocks/robinhood/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ def marketdata_options_url():

# pricebook

def marketdata_index_quotes_url(id):
return ('https://api.robinhood.com/marketdata/indexes/values/v1/{0}/'.format(id))


def marketdata_quotes_url(id):
return ('https://api.robinhood.com/marketdata/quotes/{0}/'.format(id))
Expand Down