def get_quotes(login, *inputSymbols, info=None): """Takes any number of stock tickers and returns information pertaining to its price. :param inputSymbols: This is a variable length parameter that represents a stock ticker. \ May be several tickers seperated by commas or a list of 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: 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. """ symbols = helper.inputs_to_set(inputSymbols) url = urls.quotes() payload = {'symbols': ','.join(symbols)} data = helper.request_get(login, 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])) data = [item for item in data if item is not None] return (helper.filter(data, info))
def get_list_market_data(login, *inputSymbols, expirationDate, info=None): """Returns a list of option market data for several stock tickers. :param inputSymbols: This is a variable length parameter that represents a stock ticker. \ May be several tickers seperated by commas or a list of tickers. :type inputSymbols: str or list :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) ids = [] data = [] url = urls.option_instruments() for symbol in symbols: payload = { 'chain_id': helper.id_for_chain(login, symbol), 'expiration_date': expirationDate, 'state': 'active', 'tradability': 'tradable' } otherData = helper.request_get(url, 'pagination', payload) for item in otherData: ids.append(item['id']) for id in ids: url = urls.marketdata(id) otherData = helper.request_get(login, url) data.append(otherData) return (helper.filter(data, info))
def get_option_instrument_data(login, symbol, expirationDate, strike, 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 strike: Represents the price of the option. :type strike: 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) return [None] optionID = helper.id_for_option(login, symbol, expirationDate, strike, optionType) url = urls.option_instruments(optionID) data = helper.request_get(login, url) return (helper.filter(data, info))
def get_ratings(login, 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: 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. In this case, \ the value will also be a dictionary. """ try: symbol = symbol.upper().strip() except AttributeError as message: print(message) return None url = urls.ratings(login, symbol) data = helper.request_get(login, url) 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, info))
def get_available_option_calls(login, symbol, info=None): """Returns a list of all available option calls for a stock. :param symbol: The ticker of the stock. :type symbol: 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 calls of the stock. If info parameter is provided, \ a list of strings is returned where the strings are the value of the key that matches info. """ try: symbol = symbol.upper().strip() except AttributeError as message: print(message) return [None] url = urls.option_instruments() payload = { 'chain_id': helper.id_for_chain(login, symbol), 'state': 'active', 'tradability': 'tradable', 'type': 'call' } data = helper.request_get(login, url, 'pagination', payload) return (helper.filter(data, info))
def find_options_for_stock_by_expiration_and_strike(login, symbol, expirationDate, strike, optionType='both', info=None): """Returns a list of all the option orders that match the seach parameters :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 strike: Represents the price of the option. :type strike: str :param optionType: Can be either 'call' or 'put'. :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: symbol = symbol.upper().strip() optionType = optionType.lower().strip() except AttributeError as message: print(message) return [None] if (optionType == 'call'): calls = get_available_option_calls(login, symbol) listOfCalls = [ item for item in calls if item["expiration_date"] == expirationDate and float(item["strike_price"]) == float(strike) ] mergedList = listOfCalls elif (optionType == 'put'): puts = get_available_option_puts(login, symbol) listOfPuts = [ item for item in puts if item["expiration_date"] == expirationDate and float(item["strike_price"]) == float(strike) ] mergedList = listOfPuts else: calls = get_available_option_calls(login, symbol) puts = get_available_option_puts(login, symbol) listOfCalls = [ item for item in calls if item["expiration_date"] == expirationDate and float(item["strike_price"]) == float(strike) ] listOfPuts = [ item for item in puts if item["expiration_date"] == expirationDate and float(item["strike_price"]) == float(strike) ] mergedList = listOfCalls + listOfPuts for item in mergedList: marketData = get_option_market_data_by_id(item['id']) item.update(marketData) return (helper.filter(mergedList, info))
def get_all_watchlists(login, info=None): """Returns a list of all watchlists that have been created. Everone has a 'default' 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(login, url, 'pagination') return (helper.filter(data, info))
def get_linked_bank_accounts(login, 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(login, url, 'results') return (helper.filter(data, info))
def get_aggregate_positions(login, 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(login, url, 'pagination') return (helper.filter(data, info))
def get_all_option_positions(login, 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(login, url, 'pagination') return (helper.filter(data, info))
def get_wire_transfers(login, info=None): """Returns a list of wire transfers. :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 wire transfer. 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.wiretransfers() data = helper.request_get(login, url, 'pagination') return (helper.filter(data, info))
def get_bank_transfers(login, info=None): """Returns all bank transfers made for the account. :param info: Will filter the results to get a specific value. 'direction' gives if it was deposit or withdrawl. :type info: Optional[str] :returns: Returns a list of dictionaries of key/value pairs for each transfer. 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.banktransfers() data = helper.request_get(login, url, 'pagination') return (helper.filter(data, info))
def get_watchlist_by_name(login, name='Default', info=None): """Returns a list of information related to the stocks in a single watchlist. :param name: The name of the watchlist to get data from. :type name: Optional[str] :param info: Will filter the results to get a specific value. :type info: Optional[str] :returns: Returns a list of dictionaries that contain the instrument urls and a url that references itself. """ url = urls.watchlists(name) data = helper.request_get(login, url, 'pagination') return (helper.filter(data, info))
def load_security_profile(login, 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. """ url = urls.security_profile() data = helper.request_get(login, url) return (helper.filter(data, info))
def get_documents(login, 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(login, url, 'pagination') return (helper.filter(data, info))
def get_day_trades(login, 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(login, url, 'pagination') return (helper.filter(data, info))
def get_bank_account_info(login, 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(login, url) return (helper.filter(data, info))
def load_portfolio_profile(login, info=None): """Gets the information associated with the portfolios profile, such as withdrawable amount, market value of account, and excess margin. :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. """ url = urls.portfolio_profile() data = helper.request_get(login, url, 'indexzero') return (helper.filter(data, info))
def get_dividends(login, 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: 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. """ url = urls.dividends() data = helper.request_get(login, url, 'pagination') return (helper.filter(data, info))
def load_account_profile(login, 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. """ url = urls.account_profile() data = helper.request_get(login, url, 'indexzero') return (helper.filter(data, info))
def find_options_for_list_of_stocks_by_expiration_date(login, *inputSymbols, expirationDate, optionType='both', info=None): """Returns a list of all the option orders that match the seach parameters :param inputSymbols: This is a variable length parameter that represents a stock ticker. \ May be several tickers seperated by commas or a list of tickers. :type inputSymbols: str or list :param expirationDate: Represents the expiration date in the format YYYY-MM-DD. :type expirationDate: str :param optionType: Can be either 'call' or 'put'. :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. """ symbols = helper.inputs_to_set(inputSymbols) try: optionType = optionType.lower().strip() except AttributeError as message: print(message) return [None] data = [] url = urls.option_instruments() for symbol in symbols: if (optionType == 'put' or optionType == 'call'): payload = { 'chain_id': helper.id_for_chain(login, symbol), 'expiration_date': expirationDate, 'state': 'active', 'tradability': 'tradable', 'type': optionType } else: payload = { 'chain_id': helper.id_for_chain(login, symbol), 'expiration_date': expirationDate, 'state': 'active', 'tradability': 'tradable' } otherData = helper.request_get(login, url, 'pagination', payload) for item in otherData: if item['expiration_date'] == expirationDate: data.append(item) for item in data: marketData = get_option_market_data_by_id(item['id']) item.update(marketData) return (helper.filter(data, info))
def get_all_positions(login, 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: 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. """ # comments url = urls.positions() data = helper.request_get(login, url, 'pagination') return (helper.filter(data, info))
def get_current_positions(login, info=None): """Returns a list of stocks/options that are currently held. :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 ticker. 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.positions() payload = {'nonzero': 'true'} data = helper.request_get(login, url, 'pagination', payload) return (helper.filter(data, info))
def get_option_instrument_data_by_id(login, 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(login, url) return (helper.filter(data, info))
def load_basic_profile(login, 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. """ url = urls.basic_profile() data = helper.request_get(login, url) return (helper.filter(data, info))
def get_option_market_data_by_id(login, 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. """ url = urls.marketdata(id) data = helper.request_get(login, url) return (helper.filter(data, info))
def get_instrument_by_url(login, url, info=None): """Takes a single url for the stock. 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. Can be found in several locations including \ in the dictionary returned from get_instruments_by_symbols(\*inputSymbols,info=None) :type url: 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: 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. """ data = helper.request_get(login, url, 'regular') return (helper.filter(data, info))
def get_chains(login, symbol, info=None): """Returns the chain information of an option. :param symbol: The ticker of the stock. :type symbol: 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 option. If info parameter is provided, \ a list of strings is returned where the strings are the value of the key that matches info. """ try: symbol = symbol.upper().strip() except AttributeError as message: print(message) return None url = urls.chains(symbol) data = helper.request_get(login, url) return (helper.filter(data, info))
def get_popularity(login, symbol, info=None): """Returns the number of open positions. :param symbol: The stock ticker. :type symbol: str :param info: Will filter the results to be a string value. :type info: Optional[str] :returns: 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. """ try: symbol = symbol.upper().strip() except AttributeError as message: print(message) return None url = urls.popularity(login, symbol) data = helper.request_get(login, url) return (helper.filter(data, info))
def get_splits(login, 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: 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. """ try: symbol = symbol.upper().strip() except AttributeError as message: print(message) return None url = urls.splits(symbol) data = helper.request_get(login, url, 'results') return (helper.filter(data, info))