Exemplo n.º 1
0
def get_option_market_data(symbol,
                           expirationDate,
                           strike,
                           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 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(symbol, expirationDate, strike, optionType)
    url = urls.marketdata_options(optionID)
    data = helper.request_get(url)

    return (helper.filter(data, info))
Exemplo n.º 2
0
def get_list_market_data(inputSymbols,expirationDate,info=None):
    """Returns a list of option market data for several stock tickers.

    :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.
    :type expirationDate: 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 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(symbol),
                    'expiration_date' : expirationDate,
                    'state' : 'active',
                    'tradability' : 'tradable',
                    'rhs_tradability' : 'tradable'}
        otherData = helper.request_get(url,'pagination',payload)
        for item in otherData:
            if (item['expiration_date'] == expirationDate and item['tradability'] == 'tradable'):
                ids.append(item['id'])

    for id in ids:
        url = urls.marketdata_options(id)
        otherData = helper.request_get(url)
        data.append(otherData)

    return(helper.filter(data,info))
Exemplo n.º 3
0
def get_list_options_of_specific_profitability(inputSymbols,expirationDate,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.
    :type expirationDate: 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)
    ids = []
    data = []
    returnData = []
    url = urls.option_instruments()

    if (typeProfit != "chance_of_profit_short" and typeProfit != "chance_of_profit_long"):
        print("Invalid string for 'typeProfit'. Defaulting to 'chance_of_profit_short'.")
        typeProfit = "chance_of_profit_short"

    for symbol in symbols:
        payload = { 'chain_id' : helper.id_for_chain(symbol),
                    'expiration_date' : expirationDate,
                    'state' : 'active',
                    'tradability' : 'tradable',
                    'rhs_tradability' : 'tradable'}
        otherData = helper.request_get(url,'pagination',payload)
        for item in otherData:
            if (item['tradability'] == 'tradable'):
                ids.append(item['id'])

    for id in ids:
        url = urls.marketdata_options(id)
        otherData = helper.request_get(url)
        data.append(otherData)

    for item in data:
        try:
            floatValue = float(item[typeProfit])
            if (floatValue > profitFloor and floatValue < profitCeiling):
                returnData.append(item)
        except:
            pass

    return(helper.filter(returnData,info))
Exemplo n.º 4
0
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))
Exemplo n.º 5
0
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.

    """
    url = urls.marketdata_options(id)
    data = helper.request_get(url)

    return (helper.filter(data, info))