Ejemplo n.º 1
0
def find_tradable_options_for_stock(symbol,optionType='both',info=None):
    """Returns a list of all available options for a stock.

    :param symbol: The ticker of the stock.
    :type symbol: str
    :param optionType: Can be either 'call' or 'put' or left blank to get both.
    :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 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()
        optionType = optionType.lower().strip()
    except AttributeError as message:
        print(message)
        return [None]

    url = urls.option_instruments()
    if (optionType == 'call' or optionType == 'put'):
        payload = { 'chain_id' : helper.id_for_chain(symbol),
                    'state' : 'active',
                    'tradability' : 'tradable',
                    'type' : optionType}
    else:
        payload = { 'chain_id' : helper.id_for_chain(symbol),
                    'state' : 'active',
                    'tradability' : 'tradable'}

    data = helper.request_get(url,'pagination',payload)
    return(helper.filter(data,info))
Ejemplo n.º 2
0
def find_options_for_list_of_stocks_by_expiration_date(inputSymbols,
                                                       expirationDate,
                                                       optionType='both',
                                                       info=None):
    """Returns a list of all the option orders that match the seach parameters

    :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 optionType: Can be either 'call' or 'put' or leave blank to get both.
    :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(symbol),
                'expiration_date': expirationDate,
                'state': 'active',
                'tradability': 'tradable',
                'rhs_tradability': 'tradable',
                'type': optionType
            }
        else:
            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['rhs_tradability'] == 'tradable'
                data.append(item)

    for item in data:
        marketData = get_option_market_data_by_id(item['id'])
        item.update(marketData)

    return (helper.filter(data, info))
Ejemplo n.º 3
0
def find_tradable_options(symbol,
                          expirationDate=None,
                          strikePrice=None,
                          optionType=None,
                          info=None):
    """Returns a list of all available options for a stock.

    :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 strikePrice: Represents the strike price of the option.
    :type strikePrice: str
    :param optionType: Can be either 'call' or 'put' or left blank to get both.
    :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 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, file=helper.get_output())
        return [None]

    url = urls.option_instruments()
    if not helper.id_for_chain(symbol):
        print("Symbol {} is not valid for finding options.".format(symbol),
              file=helper.get_output())
        return [None]

    payload = {
        'chain_id': helper.id_for_chain(symbol),
        'chain_symbol': symbol,
        'state': 'active'
    }

    if expirationDate:
        payload['expiration_dates'] = expirationDate
    if strikePrice:
        payload['strike_price'] = strikePrice
    if optionType:
        payload['type'] = optionType

    data = helper.request_get(url, 'pagination', payload)
    return (helper.filter_data(data, info))
Ejemplo n.º 4
0
def get_available_option_calls(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(symbol),
                'state' : 'active',
                'tradability' : 'tradable',
                'type' : 'call'}
    data = helper.request_get(url,'pagination',payload)

    return(helper.filter(data,info))
Ejemplo n.º 5
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'}
        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))
Ejemplo n.º 6
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))
Ejemplo n.º 7
0
def find_options_for_stock_by_expiration_and_strike(symbol,
                                                    expirationDate,
                                                    strike,
                                                    optionType='both',
                                                    info=None):
    """Returns a list of all the option orders that match the seach parameters

    :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' or leave blank to get both.
    :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.

    """
    try:
        symbol = symbol.upper().strip()
        option_type = optionType.lower().strip()
    except AttributeError as message:
        print(message)
        return [None]

    url = urls.option_instruments()
    payload = {
        'chain_id': helper.id_for_chain(symbol),
        'expiration_date': expirationDate,
        'strike_price': strike,
        'state': 'active',
        'tradability': 'tradable',
        'rhs_tradability': 'tradable'
    }
    if option_type == 'put' or option_type == 'call':
        payload['type'] = option_type

    data = helper.request_get(url, 'pagination', payload)
    data = [
        item for item in data if item['expiration_date'] == expirationDate
        and item['tradability'] == 'tradable'
    ]
    for item in data:
        market_data = get_option_market_data_by_id(item['id'])
        item.update(market_data)

    return helper.filter(data, info)
Ejemplo n.º 8
0
def chains(symbol):
    return ('https://api.robinhood.com/options/chains/{}/'.format(
        helper.id_for_chain(symbol)))