예제 #1
0
    def get_option_chain(self, symbol, expiry):
        """
        获取美股期权链
        :param symbol: 股票代码
        :param expiry: 过期日(类似2019-01-04或者1546578000000)
        :return:
        """
        params = MultipleContractParams()
        param = SingleContractParams()
        param.symbol = symbol
        if isinstance(expiry, six.string_types) and re.match('[0-9]{4}\-[0-9]{2}\-[0-9]{2}', expiry):
            param.expiry = int(delorean.parse(expiry, timezone=eastern, dayfirst=False).datetime.timestamp() * 1000)
        else:
            param.expiry = expiry
        params.contracts = [param]
        request = OpenApiRequest(OPTION_CHAIN, biz_model=params)
        response_content = self.__fetch_data(request)
        if response_content:
            response = OptionChainsResponse()
            response.parse_response_content(response_content)
            if response.is_success():
                return response.chain
            else:
                raise ApiException(response.code, response.message)

        return None
    def get_option_chain(self, symbol, expiry, option_filter=None, **kwargs):
        """
        query option chain with filter
        :param symbol: underlying stock symbol
        :param expiry: expiration date ( like '2021-06-18' or 1560484800000 )
        :param option_filter: option filter conditions, tigeropen.quote.domain.filter.OptionFilter
        :param kwargs: optional. specify option_filter parameters directly without option_filer,
                        like: open_interest_min=100, delta_min=0.1
        :return: pandas.DataFrame,the columns are as follows:
            identifier: option identifier
            symbol: underlying stock symbol
            expiry: option expiration date. timestamp in millisecond, like 1560484800000
            strike: strike price
            put_call: option direction. 'CALL' or 'PUT'
            multiplier: option multiplier
            ask_price:
            ask_size:
            bid_price:
            bid_size:
            pre_close:
            latest_price:
            volume:
            open_interest:
        """
        params = OptionChainParams()
        param = SingleContractParams()
        param.symbol = symbol
        if isinstance(expiry, str) and re.match('[0-9]{4}-[0-9]{2}-[0-9]{2}',
                                                expiry):
            param.expiry = int(
                delorean.parse(expiry, timezone=eastern,
                               dayfirst=False).datetime.timestamp() * 1000)
        else:
            param.expiry = expiry
        params.contracts = [param]
        params.option_filter = option_filter if option_filter else OptionFilter(
            **kwargs)
        params.version = OPEN_API_SERVICE_VERSION_V3
        request = OpenApiRequest(OPTION_CHAIN, biz_model=params)
        response_content = self.__fetch_data(request)
        if response_content:
            response = OptionChainsResponse()
            response.parse_response_content(response_content)
            if response.is_success():
                return response.chain
            else:
                raise ApiException(response.code, response.message)

        return None
예제 #3
0
    def get_option_chain(self, symbol, expiry):
        """
        获取美股期权链
        :param symbol: 股票代码
        :param expiry: 过期日 ( 类似 '2021-06-18' 或者 1560484800000 )
        :return: pandas.DataFrame,各 column 含义如下:
            identifier: 期权代码
            symbol: 期权对应的正股代码
            expiry: 期权到期日,毫秒级别的时间戳
            strike: 行权价
            put_call: 期权的方向
            multiplier: 乘数
            ask_price: 卖价
            ask_size: 卖量
            bid_price: 买价
            bid_size: 买量
            pre_close: 前收价
            latest_price: 最新价
            volume: 成交量
            open_interest: 未平仓数量
        """
        params = MultipleContractParams()
        param = SingleContractParams()
        param.symbol = symbol
        if isinstance(expiry, six.string_types) and re.match(
                '[0-9]{4}\-[0-9]{2}\-[0-9]{2}', expiry):
            param.expiry = int(
                delorean.parse(expiry, timezone=eastern,
                               dayfirst=False).datetime.timestamp() * 1000)
        else:
            param.expiry = expiry
        params.contracts = [param]
        request = OpenApiRequest(OPTION_CHAIN, biz_model=params)
        response_content = self.__fetch_data(request)
        if response_content:
            response = OptionChainsResponse()
            response.parse_response_content(response_content)
            if response.is_success():
                return response.chain
            else:
                raise ApiException(response.code, response.message)

        return None
예제 #4
0
    def get_option_trade_ticks(self, identifiers):
        """
        获取期权逐笔成交
        :param identifiers: 期权代码
        :return:
        """
        params = MultipleContractParams()
        contracts = []
        for identifier in identifiers:
            symbol, expiry, put_call, strike = extract_option_info(identifier)
            if symbol is None or expiry is None or put_call is None or strike is None:
                continue
            param = SingleContractParams()
            param.symbol = symbol
            param.expiry = int(delorean.parse(expiry, timezone=eastern, dayfirst=False).datetime.timestamp() * 1000)
            param.put_call = put_call
            param.strike = strike
            contracts.append(param)
        params.contracts = contracts

        request = OpenApiRequest(OPTION_TRADE_TICK, biz_model=params)
        response_content = self.__fetch_data(request)
        if response_content:
            response = OptionTradeTickResponse()
            response.parse_response_content(response_content)
            if response.is_success():
                return response.trade_ticks
            else:
                raise ApiException(response.code, response.message)

        return None
예제 #5
0
    def get_option_briefs(self, identifiers):
        """
        获取期权最新行情
        :param identifiers: 期权代码列表
        :return: pandas.DataFrame, 各 column 的含义如下:
            identifier: 期权代码
            symbol: 期权对应的正股代码
            expiry: 到期日,毫秒级时间戳
            strike: 行权价
            put_call: 期权方向
            multiplier: 乘数
            ask_price: 卖价
            ask_size: 卖量
            bid_price: 买价
            bid_size: 买量
            pre_close: 前收价
            latest_price: 最新价
            latest_time: 最新交易时间
            volume: 成交量
            open_interest: 未平仓数量
            open: 开盘价
            high: 最高价
            low: 最低价
            rates_bonds: 无风险利率
            volatility: 历史波动率
        """
        params = MultipleContractParams()
        contracts = []
        for identifier in identifiers:
            symbol, expiry, put_call, strike = extract_option_info(identifier)
            if symbol is None or expiry is None or put_call is None or strike is None:
                continue
            param = SingleContractParams()
            param.symbol = symbol
            param.expiry = int(
                delorean.parse(expiry, timezone=eastern,
                               dayfirst=False).datetime.timestamp() * 1000)
            param.put_call = put_call
            param.strike = strike
            contracts.append(param)
        params.contracts = contracts

        request = OpenApiRequest(OPTION_BRIEF, biz_model=params)
        response_content = self.__fetch_data(request)
        if response_content:
            response = OptionBriefsResponse()
            response.parse_response_content(response_content)
            if response.is_success():
                return response.briefs
            else:
                raise ApiException(response.code, response.message)

        return None