def load_basic_profile(info=None): """Gets the information associated with the personal profile, such as phone number, city, marital status, and date of birth. :param info: The name of the key whose value is to be returned from the function. :type info: Optional[str] :returns: The function returns a dictionary of key/value pairs. If a string \ is passed in to the info parameter, then the function will return a string \ corresponding to the value of the key whose name matches the info parameter. :Dictionary Keys: * user * address * city * state * zipcode * phone_number * marital_status * date_of_birth * citizenship * country_of_residence * number_dependents * signup_as_rhs * tax_id_ssn * updated_at """ url = urls.basic_profile() data = helper.request_get(url) return (helper.filter_data(data, info))
def get_stock_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 = urls.marketdata_quotes(stock_id) data = helper.request_get(url) return (helper.filter_data(data, info))
def get_dividends(info=None): """Returns a list of dividend trasactions that include information such as the percentage rate, amount, shares of held stock, and date paid. :param info: Will filter the results to get a specific value. :type info: Optional[str] :returns: [list] Returns a list of dictionaries of key/value pairs for each divident payment. If info parameter is provided, \ a list of strings is returned where the strings are the value of the key that matches info. :Dictionary Keys: * id * url * account * instrument * amount * rate * position * withholding * record_date * payable_date * paid_at * state * nra_withholding * drip_enabled """ url = urls.dividends() data = helper.request_get(url, 'pagination') return (helper.filter_data(data, info))
def load_investment_profile(info=None): """Gets the information associated with the investment profile. These are the answers to the questionaire you filled out when you made your profile. :param info: The name of the key whose value is to be returned from the function. :type info: Optional[str] :returns: The function returns a dictionary of key/value pairs. \ If a string is passed in to the info parameter, then the function will return \ a string corresponding to the value of the key whose name matches the info parameter. :Dictionary Keys: * user * total_net_worth * annual_income * source_of_funds * investment_objective * investment_experience * liquid_net_worth * risk_tolerance * tax_bracket * time_horizon * liquidity_needs * investment_experience_collected * suitability_verified * option_trading_experience * professional_trader * understand_option_spreads * interested_in_options * updated_at """ url = urls.investment_profile() data = helper.request_get(url) return (helper.filter_data(data, info))
def find_options_by_strike(inputSymbols, strikePrice, optionType=None, info=None): """Returns a list of all the option orders that match the seach parameters :param inputSymbols: The ticker of either a single stock or a list of stocks. :type inputSymbols: str :param strikePrice: Represents the strike price to filter for. :type strikePrice: str :param optionType: Can be either 'call' or 'put' or leave blank to get both. :type optionType: Optional[str] :param info: Will filter the results to get a specific value. :type info: Optional[str] :returns: Returns a list of dictionaries of key/value pairs for all options of the stock that match the search parameters. \ If info parameter is provided, a list of strings is returned where the strings are the value of the key that matches info. """ try: symbols = helper.inputs_to_set(inputSymbols) if optionType: optionType = optionType.lower().strip() except AttributeError as message: print(message, file=helper.get_output()) return [None] data = [] for symbol in symbols: filteredOptions = find_tradable_options(symbol, None, strikePrice, optionType, None) for item in filteredOptions: marketData = get_option_market_data_by_id(item['id']) item.update(marketData[0]) write_spinner() data.extend(filteredOptions) return(helper.filter_data(data, info))
def load_user_profile(info=None): """Gets the information associated with the user profile, such as username, email, and links to the urls for other profiles. :param info: The name of the key whose value is to be returned from the function. :type info: Optional[str] :returns: The function returns a dictionary of key/value pairs. \ If a string is passed in to the info parameter, then the function will return \ a string corresponding to the value of the key whose name matches the info parameter. :Dictionary Keys: * url * id * id_info * username * email * email_verified * first_name * last_name * origin * profile_name * created_at """ url = urls.user_profile() data = helper.request_get(url) return (helper.filter_data(data, info))
def get_crypto_info(symbol, info=None): """Gets information about a crpyto currency. :param symbol: The crypto ticker. :type symbol: str :param info: Will filter the results to have a list of the values that correspond to key that matches info. :type info: Optional[str] :returns: [dict] If info parameter is left as None then will return a dictionary of key/value pairs for each ticker. \ Otherwise, it will be a strings representing the value of the key. :Dictionary Keys: * asset_currency * display_only * id * max_order_size * min_order_size * min_order_price_increment * min_order_quantity_increment * name * quote_currency * symbol * tradability """ url = urls.crypto_currency_pairs() data = helper.request_get(url, 'results') data = [x for x in data if x['asset_currency']['code'] == symbol] if len(data) > 0: data = data[0] else: data = None return (helper.filter_data(data, info))
def get_option_market_data(inputSymbols, expirationDate, strikePrice, optionType, info=None): """Returns the option market data for the stock option, including the greeks, open interest, change of profit, and adjusted mark price. :param inputSymbols: The ticker of the stock. :type inputSymbols: str :param expirationDate: Represents the expiration date in the format YYYY-MM-DD. :type expirationDate: str :param strikePrice: Represents the price of the option. :type strikePrice: str :param optionType: Can be either 'call' or 'put'. :type optionType: str :param info: Will filter the results to get a specific value. :type info: Optional[str] :returns: Returns a dictionary of key/value pairs for the stock. \ If info parameter is provided, the value of the key that matches info is extracted. """ try: symbols = helper.inputs_to_set(inputSymbols) if optionType: optionType = optionType.lower().strip() except AttributeError as message: print(message, file=helper.get_output()) return [None] data = [] for symbol in symbols: optionID = helper.id_for_option(symbol, expirationDate, strikePrice, optionType) marketData = get_option_market_data_by_id(optionID) data.append(marketData) return(helper.filter_data(data, info))
def get_option_instrument_data(symbol, expirationDate, strikePrice, optionType, info=None): """Returns the option instrument data for the stock option. :param symbol: The ticker of the stock. :type symbol: str :param expirationDate: Represents the expiration date in the format YYYY-MM-DD. :type expirationDate: str :param strikePrice: Represents the price of the option. :type strikePrice: str :param optionType: Can be either 'call' or 'put'. :type optionType: str :param info: Will filter the results to get a specific value. :type info: Optional[str] :returns: Returns a dictionary of key/value pairs for the stock. \ If info parameter is provided, the value of the key that matches info is extracted. """ try: symbol = symbol.upper().strip() optionType = optionType.lower().strip() except AttributeError as message: print(message, file=helper.get_output()) return [None] optionID = helper.id_for_option(symbol, expirationDate, strikePrice, optionType) url = urls.option_instruments(optionID) data = helper.request_get(url) return (helper.filter_data(data, info))
def get_ratings(symbol, info=None): """Returns the ratings for a stock, including the number of buy, hold, and sell ratings. :param symbol: The stock ticker. :type symbol: str :param info: Will filter the results to contain a dictionary of values that correspond to the key that matches info. \ Possible values are summary, ratings, and instrument_id :type info: Optional[str] :returns: [dict] If info parameter is left as None then the list will contain a dictionary of key/value pairs for each ticker. \ Otherwise, it will contain the values that correspond to the keyword that matches info. :Dictionary Keys: * summary - value is a dictionary * ratings - value is a list of dictionaries * instrument_id - value is a string * ratings_published_at - value is a string """ try: symbol = symbol.upper().strip() except AttributeError as message: print(message, file=helper.get_output()) return None url = urls.ratings(symbol) data = helper.request_get(url) if not data: return (data) if (len(data['ratings']) == 0): return (data) else: for item in data['ratings']: oldText = item['text'] item['text'] = oldText.encode('UTF-8') return (helper.filter_data(data, info))
def load_security_profile(info=None): """Gets the information associated with the security profile. :param info: The name of the key whose value is to be returned from the function. :type info: Optional[str] :returns: The function returns a dictionary of key/value pairs. \ If a string is passed in to the info parameter, then the function will return \ a string corresponding to the value of the key whose name matches the info parameter. :Dictionary Keys: * user * object_to_disclosure * sweep_consent * control_person * control_person_security_symbol * security_affiliated_employee * security_affiliated_firm_relationship * security_affiliated_firm_name * security_affiliated_person_name * security_affiliated_address * security_affiliated_address_subject * security_affiliated_requires_duplicates * stock_loan_consent_status * agreed_to_rhs * agreed_to_rhs_margin * rhs_stock_loan_consent_status * updated_at """ url = urls.security_profile() data = helper.request_get(url) return (helper.filter_data(data, info))
def get_earnings(symbol, info=None): """Returns the earnings for the different financial quarters. :param symbol: The stock ticker. :type symbol: str :param info: Will filter the results to get a specific value. :type info: Optional[str] :returns: [list] Returns a list of dictionaries. If info parameter is provided, \ a list of strings is returned where the strings are the value \ of the key that matches info. :Dictionary Keys: * symbol * instrument * year * quarter * eps * report * call """ try: symbol = symbol.upper().strip() except AttributeError as message: print(message, file=helper.get_output()) return None url = urls.earnings() payload = {'symbol': symbol} data = helper.request_get(url, 'results', payload) return (helper.filter_data(data, info))
def get_all_positions(info=None): """Returns a list containing every position ever traded. :param info: Will filter the results to get a specific value. :type info: Optional[str] :returns: [list] Returns a list of dictionaries of key/value pairs for each ticker. If info parameter is provided, \ a list of strings is returned where the strings are the value of the key that matches info. :Dictionary Keys: * url * instrument * account * account_number * average_buy_price * pending_average_buy_price * quantity * intraday_average_buy_price * intraday_quantity * shares_held_for_buys * shares_held_for_sells * shares_held_for_stock_grants * shares_held_for_options_collateral * shares_held_for_options_events * shares_pending_from_options_events * updated_at * created_at """ url = urls.positions() data = helper.request_get(url, 'pagination') return (helper.filter_data(data, info))
def get_splits(symbol, info=None): """Returns the date, divisor, and multiplier for when a stock split occureed. :param symbol: The stock ticker. :type symbol: 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] :returns: [list] Returns a list of dictionaries. If info parameter is provided, \ a list of strings is returned where the strings are the value \ of the key that matches info. :Dictionary Keys: * url * instrument * execution_date * multiplier * divisor """ try: symbol = symbol.upper().strip() except AttributeError as message: print(message, file=helper.get_output()) return None url = urls.splits(symbol) data = helper.request_get(url, 'results') return (helper.filter_data(data, info))
def get_name_by_url(url): """Returns the name of a stock from the instrument url. Should be located at ``https://api.robinhood.com/instruments/<id>`` where <id> is the id of the stock. :param url: The url of the stock as a string. :type url: str :returns: [str] Returns the simple name of the stock. If the simple name does not exist then returns the full name. """ data = helper.request_get(url) if not data: return (None) # If stock doesn't have a simple name attribute then get the full name. filter = helper.filter_data(data, info='simple_name') if not filter or filter == "": filter = helper.filter_data(data, info='name') return (filter)
def load_account_profile(info=None): """Gets the information associated with the accounts profile,including day trading information and cash being held by Robinhood. :param info: The name of the key whose value is to be returned from the function. :type info: Optional[str] :returns: The function returns a dictionary of key/value pairs. \ If a string is passed in to the info parameter, then the function will return \ a string corresponding to the value of the key whose name matches the info parameter. :Dictionary Keys: * url * portfolio_cash * can_downgrade_to_cash * user * account_number * type * created_at * updated_at * deactivated * deposit_halted * only_position_closing_trades * buying_power * cash_available_for_withdrawal * cash * cash_held_for_orders * uncleared_deposits * sma * sma_held_for_orders * unsettled_funds * unsettled_debit * crypto_buying_power * max_ach_early_access_amount * cash_balances * margin_balances * sweep_enabled * instant_eligibility * option_level * is_pinnacle_account * rhs_account_number * state * active_subscription_id * locked * permanently_deactivated * received_ach_debit_locked * drip_enabled * eligible_for_fractionals * eligible_for_drip * eligible_for_cash_management * cash_management_enabled * option_trading_on_expiration_enabled * cash_held_for_options_collateral * fractional_position_closing_only * user_id * rhs_stock_loan_consent_status """ url = urls.account_profile() data = helper.request_get(url, 'indexzero') return (helper.filter_data(data, info))
def get_linked_bank_accounts(info=None): """Returns all linked bank accounts. :param info: Will filter the results to get a specific value. :type info: Optional[str] :returns: Returns a list of dictionaries of key/value pairs for each bank. """ url = urls.linked() data = helper.request_get(url, 'results') return (helper.filter_data(data, info))
def get_symbol_by_url(url): """Returns the symbol of a stock from the instrument url. Should be located at ``https://api.robinhood.com/instruments/<id>`` where <id> is the id of the stock. :param url: The url of the stock as a string. :type url: str :returns: [str] Returns the ticker symbol of the stock. """ data = helper.request_get(url) return helper.filter_data(data, info='symbol')
def get_all_watchlists(info=None): """Returns a list of all watchlists that have been created. Everyone has a 'My First List' watchlist. :param info: Will filter the results to get a specific value. :type info: Optional[str] :returns: Returns a list of the watchlists. Keywords are 'url', 'user', and 'name'. """ url = urls.watchlists() data = helper.request_get(url, 'result') return (helper.filter_data(data, info))
def get_fundamentals(inputSymbols, info=None): """Takes any number of stock tickers and returns fundamental information about the stock such as what sector it is in, a description of the company, dividend yield, and market cap. :param inputSymbols: May be a single stock ticker or a list of stock tickers. :type inputSymbols: str or list :param info: Will filter the results to have a list of the values that correspond to key that matches info. :type info: Optional[str] :returns: [list] If info parameter is left as None then the list will contain a dictionary of key/value pairs for each ticker. \ Otherwise, it will be a list of strings where the strings are the values of the key that corresponds to info. :Dictionary Keys: * open * high * low * volume * average_volume_2_weeks * average_volume * high_52_weeks * dividend_yield * float * low_52_weeks * market_cap * pb_ratio * pe_ratio * shares_outstanding * description * instrument * ceo * headquarters_city * headquarters_state * sector * industry * num_employees * year_founded * symbol """ symbols = helper.inputs_to_set(inputSymbols) url = urls.fundamentals() payload = {'symbols': ','.join(symbols)} data = helper.request_get(url, 'results', payload) if (data == None or data == [None]): return data for count, item in enumerate(data): if item is None: print(helper.error_ticker_does_not_exist(symbols[count]), file=helper.get_output()) else: item['symbol'] = symbols[count] data = [item for item in data if item is not None] return (helper.filter_data(data, info))
def get_all_option_positions(info=None): """Returns all option positions ever held for the account. :param info: Will filter the results to get a specific value. :type info: Optional[str] :returns: Returns a list of dictionaries of key/value pairs for each option. If info parameter is provided, \ a list of strings is returned where the strings are the value of the key that matches info. """ url = urls.option_positions() data = helper.request_get(url, 'pagination') return (helper.filter_data(data, info))
def get_subscription_fees(info=None): """Returns a list of subscription fees. :param info: Will filter the results to get a specific value. :type info: Optional[str] :returns: Returns a list of dictionaries of key/value pairs for each fee. If info parameter is provided, \ a list of strings is returned where the strings are the value of the key that matches info. """ url = urls.subscription() data = helper.request_get(url, 'pagination') return (helper.filter_data(data, info))
def get_aggregate_positions(info=None): """Collapses all option orders for a stock into a single dictionary. :param info: Will filter the results to get a specific value. :type info: Optional[str] :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 = urls.aggregate() data = helper.request_get(url, 'pagination') return (helper.filter_data(data, info))
def get_option_market_data_by_id(id, info=None): """Returns the option market data for a stock, including the greeks, open interest, change of profit, and adjusted mark price. :param id: The id of the stock. :type id: str :param info: Will filter the results to get a specific value. :type info: Optional[str] :returns: Returns a dictionary of key/value pairs for the stock. \ If info parameter is provided, the value of the key that matches info is extracted. """ instrument = get_option_instrument_data_by_id(id) url = urls.marketdata_options() payload = { "instruments" : instrument['url'] } data = helper.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':'' } return(helper.filter_data(data, info))
def get_day_trades(info=None): """Returns recent day trades. :param info: Will filter the results to get a specific value. :type info: Optional[str] :returns: Returns a list of dictionaries of key/value pairs for each day trade. If info parameter is provided, \ a list of strings is returned where the strings are the value of the key that matches info. """ account = profiles.load_account_profile('account_number') url = urls.daytrades(account) data = helper.request_get(url, 'regular') return (helper.filter_data(data, info))
def get_documents(info=None): """Returns a list of documents that have been released by Robinhood to the account. :param info: Will filter the results to get a specific value. :type info: Optional[str] :returns: Returns a list of dictionaries of key/value pairs for each document. If info parameter is provided, \ a list of strings is returned where the strings are the value of the key that matches info. """ url = urls.documents() data = helper.request_get(url, 'pagination') return (helper.filter_data(data, info))
def find_options_by_specific_profitability(inputSymbols, expirationDate=None, strikePrice=None, optionType=None, typeProfit="chance_of_profit_short", profitFloor=0.0, profitCeiling=1.0, info=None): """Returns a list of option market data for several stock tickers that match a range of profitability. :param inputSymbols: May be a single stock ticker or a list of stock tickers. :type inputSymbols: str or list :param expirationDate: Represents the expiration date in the format YYYY-MM-DD. Leave as None to get all available dates. :type expirationDate: str :param strikePrice: Represents the price of the option. Leave as None to get all available strike prices. :type strikePrice: str :param optionType: Can be either 'call' or 'put' or leave blank to get both. :type optionType: Optional[str] :param typeProfit: Will either be "chance_of_profit_short" or "chance_of_profit_long". :type typeProfit: str :param profitFloor: The lower percentage on scale 0 to 1. :type profitFloor: int :param profitCeiling: The higher percentage on scale 0 to 1. :type profitCeiling: int :param info: Will filter the results to get a specific value. :type info: Optional[str] :returns: Returns a list of dictionaries of key/value pairs for all stock option market data. \ If info parameter is provided, a list of strings is returned where the strings are the value of the key that matches info. """ symbols = helper.inputs_to_set(inputSymbols) data = [] if (typeProfit != "chance_of_profit_short" and typeProfit != "chance_of_profit_long"): print("Invalid string for 'typeProfit'. Defaulting to 'chance_of_profit_short'.", file=helper.get_output()) typeProfit = "chance_of_profit_short" for symbol in symbols: tempData = find_tradable_options(symbol, expirationDate, strikePrice, optionType, info=None) for option in tempData: if expirationDate and option.get("expiration_date") != expirationDate: continue market_data = get_option_market_data_by_id(option['id']) if len(market_data): option.update(market_data[0]) write_spinner() try: floatValue = float(option[typeProfit]) if (floatValue >= profitFloor and floatValue <= profitCeiling): data.append(option) except: pass return(helper.filter_data(data, info))
def get_bank_account_info(id, info=None): """Returns a single dictionary of bank information :param id: The bank id. :type id: str :param info: Will filter the results to get a specific value. :type info: Optional[str] :returns: Returns a dictinoary of key/value pairs for the bank. If info parameter is provided, \ the value of the key that matches info is extracted. """ url = urls.linked(id) data = helper.request_get(url) return (helper.filter_data(data, info))
def get_option_instrument_data_by_id(id, info=None): """Returns the option instrument information. :param id: The id of the stock. :type id: str :param info: Will filter the results to get a specific value. :type info: Optional[str] :returns: Returns a dictionary of key/value pairs for the stock. \ If info parameter is provided, the value of the key that matches info is extracted. """ url = urls.option_instruments(id) data = helper.request_get(url) return (helper.filter_data(data, info))
def get_instruments_by_symbols(inputSymbols, info=None): """Takes any number of stock tickers and returns information held by the market such as ticker name, bloomberg id, and listing date. :param inputSymbols: May be a single stock ticker or a list of stock tickers. :type inputSymbols: str or list :param info: Will filter the results to have a list of the values that correspond to key that matches info. :type info: Optional[str] :returns: [list] If info parameter is left as None then the list will a dictionary of key/value pairs for each ticker. \ Otherwise, it will be a list of strings where the strings are the values of the key that corresponds to info. :Dictionary Keys: * id * url * quote * fundamentals * splits * state * market * simple_name * name * tradeable * tradability * symbol * bloomberg_unique * margin_initial_ratio * maintenance_ratio * country * day_trade_ratio * list_date * min_tick_size * type * tradable_chain_id * rhs_tradability * fractional_tradability * default_collar_fraction """ symbols = helper.inputs_to_set(inputSymbols) url = urls.instruments() data = [] for item in symbols: payload = {'symbol': item} itemData = helper.request_get(url, 'indexzero', payload) if itemData: data.append(itemData) else: print(helper.error_ticker_does_not_exist(item), file=helper.get_output()) return (helper.filter_data(data, info))