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(optionID) data = helper.request_get(url) return(helper.filter(data,info))
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'} 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(url) data.append(otherData) return(helper.filter(data,info))
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['rhs_tradability'] == 'tradable'): ids.append(item['id']) for id in ids: url = urls.marketdata(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))
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(id) data = helper.request_get(url) return(helper.filter(data,info))