Exemplo n.º 1
0
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))
Exemplo n.º 2
0
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))
Exemplo n.º 3
0
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))
Exemplo n.º 4
0
def chains(login, symbol):
    return ('https://api.robinhood.com/options/chains/{}/'.format(
        helper.id_for_chain(login, symbol)))