def get_contracts(self, symbol, sec_type=SecurityType.STK, currency=Currency.USD, exchange=None): params = ContractParams() params.account = self._account params.symbol = symbol if sec_type: params.sec_type = sec_type.value if currency: params.currency = currency.value 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 else: raise ApiException(response.code, response.message) return None
def get_contract(self, symbol, sec_type=SecurityType.STK, currency=None, exchange=None, expiry=None, strike=None, right=None): params = ContractParams() params.account = self._account params.symbol = symbol if sec_type: params.sec_type = sec_type.value if currency: params.currency = currency.value if expiry: params.expiry = expiry if strike: params.strike = strike if right: params.right = right 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
def get_contracts(self, symbol, sec_type=SecurityType.STK, currency=None, exchange=None): """ 批量获取合约 :param symbol: :param sec_type: :param currency: :param exchange: :return: 合约对象列表, 每个列表项的对象信息同 get_contract 返回 """ params = ContractParams() params.account = self._account params.symbols = symbol if isinstance(symbol, list) else [symbol] if sec_type: params.sec_type = sec_type.value if currency: params.currency = currency.value 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
def get_contract(self, symbol, sec_type=SecurityType.STK, currency=None, exchange=None, expiry=None, strike=None, right=None): """ 获取合约 :param symbol: :param sec_type: :param currency: :param exchange: :param expiry: :param strike: :param right: :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.symbol = symbol if sec_type: params.sec_type = sec_type.value if currency: params.currency = currency.value if expiry: params.expiry = expiry if strike: params.strike = strike if right: params.right = right 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