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
    def get_option_bars(self, identifiers, begin_time=-1, end_time=4070880000000):
        """
        获取K线(DAY)数据
        :param identifiers: 期权代码
        :param begin_time: 开始时间
        :param end_time: 结束时间
        :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 = SingleOptionQuoteParams()
            param.symbol = symbol
            param.expiry = int(delorean.parse(expiry, timezone=eastern, dayfirst=False).datetime.timestamp() * 1000)
            param.put_call = put_call
            param.strike = strike
            param.period = BarPeriod.DAY.value
            param.begin_time = begin_time
            param.end_time = end_time
            contracts.append(param)
        params.contracts = contracts

        request = OpenApiRequest(OPTION_KLINE, biz_model=params)
        response_content = self.__fetch_data(request)
        if response_content:
            response = OptionQuoteBarResponse()
            response.parse_response_content(response_content)
            if response.is_success():
                return response.bars
            else:
                raise ApiException(response.code, response.message)
    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
Exemple #4
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
Exemple #5
0
    def get_option_bars(self,
                        identifiers,
                        begin_time=-1,
                        end_time=4070880000000):
        """
        获取期权日K数据
        :param identifiers: 期权代码列表
        :param begin_time: 开始时间. 若是时间戳需要精确到毫秒, 为13位整数;
                                    或是日期时间格式的字符串, 如 "2019-01-01" 或 "2019-01-01 12:00:00"
        :param end_time: 结束时间. 格式同 begin_time
        :return: pandas.DataFrame, 各 column 含义如下:
            time: 毫秒级时间戳
            open: 开盘价
            high: 最高价
            low: 最低价
            close: 收盘价
            volume: 成交量
            open_interest: 未平仓数量
            expiry: 期权到期时间
            strike: 行权价
            put_call: 期权方向
        """
        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 = SingleOptionQuoteParams()
            param.symbol = symbol
            param.expiry = int(
                delorean.parse(expiry, timezone=eastern,
                               dayfirst=False).datetime.timestamp() * 1000)
            param.put_call = put_call
            param.strike = strike
            param.period = BarPeriod.DAY.value
            param.begin_time = begin_time
            param.end_time = end_time
            contracts.append(param)
        params.contracts = contracts

        request = OpenApiRequest(OPTION_KLINE, biz_model=params)
        response_content = self.__fetch_data(request)
        if response_content:
            response = OptionQuoteBarResponse()
            response.parse_response_content(response_content)
            if response.is_success():
                return response.bars
            else:
                raise ApiException(response.code, response.message)
Exemple #6
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