From c323e20b0b081157f6c2eb5f62cd0977544af04f Mon Sep 17 00:00:00 2001 From: msincenselee Date: Sun, 19 Jan 2020 17:13:23 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=A2=9E=E5=BC=BA]=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E9=A3=8E=E6=8E=A7=E5=BC=95=E6=93=8E=E5=85=A5=E5=8F=A3=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96=E5=BD=93=E5=89=8D=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC=EF=BC=8C=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=90=88=E7=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/trader/engine.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/vnpy/trader/engine.py b/vnpy/trader/engine.py index 21ed4920..2dde15e8 100644 --- a/vnpy/trader/engine.py +++ b/vnpy/trader/engine.py @@ -55,6 +55,8 @@ class MainEngine: self.apps = {} self.exchanges = [] + self.rm_engine = None + os.chdir(TRADER_DIR) # Change working directory self.init_engines() # Initialize function engines @@ -90,6 +92,9 @@ class MainEngine: self.apps[app.app_name] = app engine = self.add_engine(app.engine_class) + if app.app_name == "RiskManager": + self.rm_engine = engine + return engine def init_engines(self): @@ -376,6 +381,8 @@ class OmsEngine(BaseEngine): self.positions = {} self.accounts = {} self.contracts = {} + self.custom_contracts = {} + self.prices = {} self.active_orders = {} @@ -386,6 +393,7 @@ class OmsEngine(BaseEngine): """Add query function to main engine.""" self.main_engine.get_tick = self.get_tick self.main_engine.get_order = self.get_order + self.main_engine.get_price = self.get_price self.main_engine.get_trade = self.get_trade self.main_engine.get_position = self.get_position self.main_engine.get_account = self.get_account @@ -397,6 +405,7 @@ class OmsEngine(BaseEngine): self.main_engine.get_all_accounts = self.get_all_accounts self.main_engine.get_all_contracts = self.get_all_contracts self.main_engine.get_all_active_orders = self.get_all_active_orders + self.main_engine.get_all_custom_contracts = self.get_all_custom_contracts def register_event(self): """""" @@ -412,6 +421,9 @@ class OmsEngine(BaseEngine): tick = event.data self.ticks[tick.vt_symbol] = tick + if tick.last_price: + self.prices[tick.vt_symbol] = tick.last_price + def process_order_event(self, event: Event): """""" order = event.data @@ -450,6 +462,14 @@ class OmsEngine(BaseEngine): """ return self.ticks.get(vt_symbol, None) + def get_price(self, vt_symbol): + """ + get the lastest price by vt_symbol + :param vt_symbol: + :return: + """ + return self.prices.get(vt_symbol, None) + def get_order(self, vt_orderid): """ Get latest order data by vt_orderid. @@ -532,6 +552,17 @@ class OmsEngine(BaseEngine): ] return active_orders + def get_all_custom_contracts(self): + """ + 获取所有自定义合约 + :return: + """ + if len(self.custom_contracts) == 0: + c = CustomContract() + self.custom_contracts = c.get_contracts() + return self.custom_contracts + + class CustomContract(object): """ 定制合约