예제 #1
0
    def get_future_brief(self, identifiers):
        """
        获取期货最新行情
        :param identifiers: 期货代码列表
        :return: pandas.DataFrame,各 column 含义如下
            identifier: 期货代码
            ask_price: 卖价
            ask_size: 卖量
            bid_price: 买价
            bid_size: 买量
            pre_close: 前收价
            latest_price: 最新价
            latest_size: 最新成交量
            latest_time: 最新价成交时间
            volume: 当日累计成交手数
            open_interest: 未平仓合约数量
            open: 开盘价
            high: 最高价
            low: 最低价
            limit_up: 涨停价
            limit_down: 跌停价
        """
        params = FutureQuoteParams()
        params.contract_codes = identifiers

        request = OpenApiRequest(FUTURE_REAL_TIME_QUOTE, biz_model=params)
        response_content = self.__fetch_data(request)
        if response_content:
            response = FutureBriefsResponse()
            response.parse_response_content(response_content)
            if response.is_success():
                return response.briefs
            else:
                raise ApiException(response.code, response.message)
예제 #2
0
    def get_future_bars(self, identifiers, period=BarPeriod.DAY, begin_time=-1, end_time=-1, limit=1000):
        """
        获取期货K线数据
        :param identifiers: 期货代码
        :param period: day: 日K,week: 周K,month:月K ,year:年K,1min:1分钟,5min:5分钟,15min:15分钟,30min:30分钟,60min:60分钟
        :param begin_time: 开始时间
        :param end_time: 结束时间
        :param limit: 数量限制
        :return:
        """
        params = FutureQuoteParams()
        params.contract_codes = identifiers
        if period:
            params.period = period.value
        params.begin_time = begin_time
        params.end_time = end_time
        params.limit = limit

        request = OpenApiRequest(FUTURE_KLINE, biz_model=params)
        response_content = self.__fetch_data(request)
        if response_content:
            response = FutureQuoteBarResponse()
            response.parse_response_content(response_content)
            if response.is_success():
                return response.bars
            else:
                raise ApiException(response.code, response.message)
예제 #3
0
    def get_future_brief(self, identifiers):
        """
        获取期货最新行情
        :param identifiers: 期货代码
        :return:
        """
        params = FutureQuoteParams()
        params.contract_codes = identifiers

        request = OpenApiRequest(FUTURE_REAL_TIME_QUOTE, biz_model=params)
        response_content = self.__fetch_data(request)
        if response_content:
            response = FutureBriefsResponse()
            response.parse_response_content(response_content)
            if response.is_success():
                return response.briefs
            else:
                raise ApiException(response.code, response.message)
예제 #4
0
    def get_future_trade_ticks(self,
                               identifiers,
                               begin_index=0,
                               end_index=30,
                               limit=1000):
        """
        获取期货逐笔成交
        :param identifiers: 期货代码列表
        :param begin_index: 开始索引
        :param end_index: 结束索引
        :param limit: 数量限制
        :return: pandas.DataFrame, 各 column 含义如下
            index: 索引值
            time: 成交时间,精确到毫秒的时间戳
            price: 成交价格
            volume: 成交量
        """
        params = FutureQuoteParams()
        params.contract_codes = identifiers
        params.begin_index = begin_index
        params.end_index = end_index
        params.limit = limit

        request = OpenApiRequest(FUTURE_TICK, biz_model=params)
        response_content = self.__fetch_data(request)
        if response_content:
            response = FutureTradeTickResponse()
            response.parse_response_content(response_content)
            if response.is_success():
                return response.trade_ticks
            else:
                raise ApiException(response.code, response.message)
예제 #5
0
    def get_future_bars(self,
                        identifiers,
                        period=BarPeriod.DAY,
                        begin_time=-1,
                        end_time=-1,
                        limit=1000):
        """
        获取期货K线数据
        :param identifiers: 期货代码列表
        :param period: day: 日K,week: 周K,month:月K ,year:年K,1min:1分钟,5min:5分钟,15min:15分钟,30min:30分钟,60min:60分钟
        :param begin_time: 开始时间. 若是时间戳需要精确到毫秒, 为13位整数;
                                    或是日期时间格式的字符串, 如 "2019-01-01" 或 "2019-01-01 12:00:00"
        :param end_time: 结束时间. 格式同 begin_time
        :param limit: 数量限制
        :return: pandas.DataFrame, 各column 含义如下:
            identifier: 期货合约代码
            time: Bar对应的时间戳, 即Bar的结束时间。Bar的切割方式与交易所一致,以CN1901举例,T日的17:00至T+1日的16:30的数据会被合成一个日级Bar。
            latest_time: Bar 最后的更新时间
            open: 开盘价
            high: 最高价
            low: 最低价
            close: 收盘价
            settlement: 结算价,在未生成结算价时返回0
            volume: 成交量
            open_interest: 未平仓合约数量
        """
        params = FutureQuoteParams()
        params.contract_codes = identifiers
        if period:
            params.period = period.value
        params.begin_time = begin_time
        params.end_time = end_time
        params.limit = limit

        request = OpenApiRequest(FUTURE_KLINE, biz_model=params)
        response_content = self.__fetch_data(request)
        if response_content:
            response = FutureQuoteBarResponse()
            response.parse_response_content(response_content)
            if response.is_success():
                return response.bars
            else:
                raise ApiException(response.code, response.message)