Ejemplo n.º 1
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))
Ejemplo n.º 2
0
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))
Ejemplo 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))
Ejemplo n.º 4
0
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))
Ejemplo n.º 5
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))