Пример #1
0
    def get_contracts(self,
                      symbol,
                      sec_type=SecurityType.STK,
                      currency=None,
                      exchange=None):
        """
        批量获取合约
        :param symbol:
        :param sec_type: 合约类型 tigeropen.common.consts.SecurityType
        :param currency: 币种 tigeropen.common.consts.Currency
        :param exchange: 交易所
        :return: 合约对象列表, 每个列表项的对象信息同 get_contract 返回
        """
        params = ContractParams()
        params.account = self._account
        params.secret_key = self._secret_key
        params.symbols = symbol if isinstance(symbol, list) else [symbol]
        params.sec_type = get_enum_value(sec_type)
        params.currency = get_enum_value(currency)
        params.exchange = exchange

        request = OpenApiRequest(CONTRACTS, biz_model=params)
        response_content = self.__fetch_data(request)
        if response_content:
            response = ContractsResponse()
            response.parse_response_content(response_content)
            if response.is_success():
                return response.contracts
            else:
                raise ApiException(response.code, response.message)

        return None
Пример #2
0
    def get_contract(self,
                     symbol,
                     sec_type=SecurityType.STK,
                     currency=None,
                     exchange=None,
                     expiry=None,
                     strike=None,
                     put_call=None):
        """
        获取合约
        :param symbol:
        :param sec_type: 合约类型 tigeropen.common.consts.SecurityType
        :param currency: 币种 tigeropen.common.consts.Currency
        :param exchange: 交易所
        :param expiry: 合约到期日(期货/期权) yyyyMMdd
        :param strike: 行权价(期权)
        :param put_call: CALL/PUT
        :return: Contract 对象. 有如下属性:
            symbol: 合约 symbol
            identifier: 合约唯一标识
            currency: 币种
            exchange: 交易所
            name: 合约名称
            sec_type: 合约类型
            long_initial_margin: 做多初始保证金比例
            long_maintenance_margin: 做多维持保证金比例
            short_fee_rate: 做空费率
            short_margin: 做空保证金
            shortable: 做空池剩余
            multiplier: 合约乘数
            expiry: 合约到期日(期货/期权)
            contract_month: 合约月份(期货)
            strike: 行权价(期权)
            put_call: 看跌/看涨(期权)
        """
        params = ContractParams()
        params.account = self._account
        params.secret_key = self._secret_key
        params.symbol = symbol
        params.sec_type = get_enum_value(sec_type)
        params.currency = get_enum_value(currency)
        if expiry:
            params.expiry = expiry
        if strike:
            params.strike = strike
        if put_call:
            params.right = put_call
        params.exchange = exchange

        request = OpenApiRequest(CONTRACT, biz_model=params)
        response_content = self.__fetch_data(request)
        if response_content:
            response = ContractsResponse()
            response.parse_response_content(response_content)
            if response.is_success():
                return response.contracts[0] if len(
                    response.contracts) == 1 else None
            else:
                raise ApiException(response.code, response.message)

        return None