def on_query_contract(self, data: dict, request: Request) -> None: """""" for d in data["symbols"]: base_currency = d["baseAsset"] quote_currency = d["quoteAsset"] name = f"{base_currency.upper()}/{quote_currency.upper()}" pricetick = 1 min_volume = 1 for f in d["filters"]: if f["filterType"] == "PRICE_FILTER": pricetick = float(f["tickSize"]) elif f["filterType"] == "LOT_SIZE": min_volume = float(f["stepSize"]) contract = ContractData( symbol=d["symbol"], exchange=Exchange.BINANCE, name=name, pricetick=pricetick, size=1, min_volume=min_volume, product=Product.FUTURES, history_data=True, gateway_name=self.gateway_name, ) self.gateway.on_contract(contract) symbol_name_map[contract.symbol] = contract.name self.gateway.write_log("合约信息查询成功")
def on_query_contract(self, data, request): """""" for instrument_data in data: symbol = instrument_data["instrument_id"] contract = ContractData( symbol=symbol, exchange=Exchange.OKEX, name=symbol, product=Product.FUTURES, size=float(instrument_data["contract_val"]), pricetick=float(instrument_data["tick_size"]), history_data=True, gateway_name=self.gateway_name, ) self.gateway.on_contract(contract) instruments.add(instrument_data["instrument_id"]) currencies.add(instrument_data["underlying_index"]) currencies.add(instrument_data["quote_currency"]) self.gateway.write_log("合约信息查询成功") # Start websocket api after instruments data collected self.gateway.ws_api.start() # and query pending orders self.query_order()
def on_query_contract(self, data, request): # type: (dict, Request)->None """""" if self.check_error(data, "查询合约"): return for d in data["data"]: self.currencies.add(d["symbol"]) contract = ContractData( symbol=d["contract_code"], exchange=Exchange.HUOBI, name=d["contract_code"], pricetick=d["price_tick"], size=int(d["contract_size"]), min_volume=1, product=Product.FUTURES, history_data=True, gateway_name=self.gateway_name, ) self.gateway.on_contract(contract) symbol_type_map[contract.symbol] = d["contract_type"] self.gateway.write_log("合约信息查询成功") self.query_order()
def on_query_contract(self, data, request): # type: (dict, Request)->None """""" for d in data: symbol = d["name"] self.symbols.append(symbol) contract = ContractData( symbol=symbol, exchange=Exchange.GATEIO, name=symbol, pricetick=float(d["order_price_round"]), size=int(d["leverage_min"]), min_volume=d["order_size_min"], product=Product.FUTURES, gateway_name=self.gateway_name, history_data=True ) self.gateway.on_contract(contract) self.gateway.write_log("合约信息查询成功") # Connect websocket api after account id and contract symbols collected self.ws_api.connect( self.key, self.secret, self.server, self.proxy_host, self.proxy_port, self.account_id, self.symbols )
def on_query_contract(self, data: dict, request: Request) -> None: """""" if self.check_error(data, "查询合约"): return for d in data["data"]: base_currency = d["base-currency"] quote_currency = d["quote-currency"] name = f"{base_currency.upper()}/{quote_currency.upper()}" pricetick = 1 / pow(10, d["price-precision"]) min_volume = 1 / pow(10, d["amount-precision"]) contract = ContractData( symbol=d["symbol"], exchange=Exchange.HUOBI, name=name, pricetick=pricetick, size=1, min_volume=min_volume, product=Product.SPOT, history_data=True, gateway_name=self.gateway_name, ) self.gateway.on_contract(contract) huobi_symbols.add(contract.symbol) symbol_name_map[contract.symbol] = contract.name self.gateway.write_log("合约信息查询成功")
def on_query_contract(self, data: List, request: Request) -> None: """""" if not data: return for instrument_data in data: symbol = instrument_data["instrument_id"] contract = ContractData( symbol=symbol, exchange=Exchange.OKEX, name=symbol, product=Product.OPTION, size=float(instrument_data["contract_val"]), pricetick=float(instrument_data["tick_size"]), min_volume=float(instrument_data["lot_size"]), option_strike=float(instrument_data["strike"]), option_type=OPTIONTYPE_OKEXO2VT[ instrument_data["option_type"]], option_expiry=datetime.strptime(instrument_data["delivery"], "%Y-%m-%dT%H:%M:%S.%fZ"), option_portfolio=instrument_data["underlying"], option_index=instrument_data["strike"], history_data=True, net_position=True, gateway_name=self.gateway_name, ) contract.option_underlying = "_".join([ contract.option_portfolio, contract.option_expiry.strftime("%Y%m%d") ]) self.gateway.on_contract(contract) self.gateway.write_log("期权合约信息查询成功") # Start websocket api after instruments data collected self.gateway.ws_api.start() # and query pending orders self.query_account() self.query_position() self.query_order()
def on_query_contract(self, data, request): """""" for instrument_data in data: symbol = instrument_data["instrument_id"] contract = ContractData( symbol=symbol, exchange=Exchange.OKEX, name=symbol, product=Product.SPOT, size=1, pricetick=float(instrument_data["tick_size"]), min_volume=float(instrument_data["min_size"]), history_data=True, gateway_name=self.gateway_name) self.gateway.on_contract(contract) instruments.add(instrument_data["instrument_id"]) currencies.add(instrument_data["base_currency"]) currencies.add(instrument_data["quote_currency"]) self.gateway.write_log("合约信息查询成功") # Start websocket api after instruments data collected self.gateway.ws_api.start()