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_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_latest_notification(login): """Returns the time of the latest notification. :returns: Returns a dictionary of key/value pairs. But there is only one key, 'last_viewed_at' """ url = urls.notifications(True) data = helper.request_get(login, url) return (data)
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_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_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 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_margin_calls(login, symbol=None): """Returns either all margin calls or margin calls for a specific stock. :param symbol: Will determine which stock to get margin calls for. :type symbol: Optional[str] :returns: Returns a list of dictionaries of key/value pairs for each margin call. """ url = urls.margin() if symbol: try: symbol = symbol.upper().strip() except AttributeError as message: print(message) return None payload = {'equity_instrument_id', helper.id_for_stock(login, symbol)} data = helper.request_get(login, url, 'results', payload) else: data = helper.request_get(login, url, 'results') return (data)
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_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_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_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_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_total_dividends(login): """Returns a float number representing the total amount of dividends paid to the account. :returns: Total dollar amount of dividends paid to the account as a 2 precision float. """ url = urls.dividends() data = helper.request_get(login, url, 'pagination') dividend_total = 0 for item in data: dividend_total += float(item['amount']) return (dividend_total)
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_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 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_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 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 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 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 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_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 get_name_by_url(login, 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 symbol: The url of the stock as a string. :type symbol: str :returns: Returns the simple name of the stock. If the simple name does not exist then returns the full name. """ data = helper.request_get(login, url) if not data['simple_name']: return data['name'] else: return data['simple_name']
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_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))