def __init__(self, main_engine: MainEngine, event_engine: EventEngine): """""" super().__init__(main_engine, event_engine, APP_NAME) self.trade_slippage: int = 0 self.timer_interval: int = 3 self.instant_trade: bool = False self.order_count: int = 100000 self.timer_count: int = 0 self.active_orders: Dict[str, Dict[str, OrderData]] = {} self.gateway_map: Dict[str, str] = {} self.ticks: Dict[str, TickData] = {} self.positions: Dict[Tuple[str, Direction], PositionData] = {} # Patch main engine functions self._subscribe = main_engine.subscribe self._query_history = main_engine.query_history main_engine.subscribe = self.subscribe main_engine.query_history = self.query_history main_engine.send_order = self.send_order main_engine.cancel_order = self.cancel_order self.load_setting() self.load_data() self.register_event()
def __init__(self, main_engine: MainEngine, event_engine: EventEngine): """""" super().__init__() self.main_engine = main_engine self.event_engine = event_engine self.rm_engine = main_engine.get_engine(APP_NAME) self.init_ui()
def __init__(self, main_engine: MainEngine, event_engine: EventEngine): super().__init__() self.main_engine = main_engine self.event_engine = event_engine self.recorder_engine = main_engine.get_engine(APP_NAME) self.init_ui() self.register_event() self.recorder_engine.put_event()
def __init__(self, main_engine: MainEngine, event_engine: EventEngine): """""" super().__init__() self.main_engine = main_engine self.event_engine = event_engine self.chart_engine: ChartWizardEngine = main_engine.get_engine(APP_NAME) self.bgs: Dict[str, BarGenerator] = {} self.charts: Dict[str, ChartWidget] = {} self.init_ui() self.register_event()
def __init__(self, main_engine: MainEngine, event_engine: EventEngine): super(CtaManager, self).__init__() self.main_engine = main_engine self.event_engine = event_engine self.cta_engine = main_engine.get_engine(APP_NAME) self.managers = {} self.init_ui() self.register_event() self.cta_engine.init_engine() self.update_class_combo()
def __init__(self, main_engine: MainEngine, event_engine: EventEngine): """""" super().__init__() self.main_engine: MainEngine = main_engine self.event_engine: EventEngine = event_engine self.strategy_engine: StrategyEngine = main_engine.get_engine(APP_NAME) self.managers: Dict[str, StrategyManager] = {} self.init_ui() self.register_event() self.strategy_engine.init_engine() self.update_class_combo()
def __init__(self, main_engine: MainEngine, event_engine: EventEngine): """""" super().__init__() self.main_engine = main_engine self.event_engine = event_engine self.backtester_engine = main_engine.get_engine(APP_NAME) self.class_names = [] self.settings = {} self.target_display = "" self.init_ui() self.register_event() self.backtester_engine.init_engine() self.init_strategy_settings() self.load_backtesting_setting()
SETTINGS["log.console"] = True # 打印信息到终端. binance_settings = { "key": "xx", "secret": "xxx", "session_number": 3, "proxy_host": "127.0.0.1", "proxy_port": 1087 } if __name__ == "__main__": SETTINGS["log.file"] = True event_engine = EventEngine() # 初始化事件引擎 main_engine = MainEngine(event_engine) # 初始化主引擎 main_engine.add_gateway(BinanceGateway) # 添加cta策略的app cta_engine: CtaEngine = main_engine.add_app(CtaStrategyApp) # 添加cta引擎, 实际上就是初始化引擎。 main_engine.write_log("主引擎创建成功") log_engine = main_engine.get_engine("log") event_engine.register(EVENT_CTA_LOG, log_engine.process_log_event) main_engine.write_log("注册日志事件监听") main_engine.connect(binance_settings, "BINANCE") main_engine.write_log("连接BINANCE接口") sleep(10) # 稍作等待策略启动完成。
def main(): """""" qapp = create_qapp() event_engine = EventEngine() main_engine = MainEngine(event_engine) main_engine.add_gateway(BinanceGateway) main_engine.add_gateway(BinancesGateway) main_engine.add_app(CtaStrategyApp) main_engine.add_app(CtaBacktesterApp) main_engine.add_app(DataManagerApp) main_engine.add_app(AlgoTradingApp) main_engine.add_app(DataRecorderApp) main_engine.add_app(RiskManagerApp) main_engine.add_app(SpreadTradingApp) main_window = MainWindow(main_engine, event_engine) main_window.showMaximized() qapp.exec()
interval=Interval(interval), start=start, end=end) data = gate_way.query_history(req) print("start12_end13", data) if __name__ == "__main__": """ for crawling data from Binance exchange. """ SETTINGS["log.file"] = True event_engine = EventEngine() main_engine = MainEngine(event_engine) main_engine.add_gateway(BinanceGateway) # spot # main_engine.add_gateway(BinancesGateway) # future main_engine.connect(binance_setting, "BINANCE") # spot # main_engine.connect(binances_setting, "BINANCES") # future sleep(3) main_engine.write_log("连接BINANCE接口") # spot # main_engine.write_log("连接BINANCES接口") # future gate_way = main_engine.get_gateway("BINANCE") # spot # gate_way = main_engine.get_gateway("BINANCES") # future print(gate_way) symbol = "btcusdt" # spot for lower case while the future will be upper case.
def run(): """ Running in the child process. """ SETTINGS["log.file"] = True event_engine = EventEngine() main_engine = MainEngine(event_engine) main_engine.add_gateway(BinancesGateway) main_engine.add_gateway(BinanceGateway) # cta_engine = main_engine.add_app(CtaStrategyApp) cta_engine: CtaEngine = main_engine.add_app(CtaStrategyApp) main_engine.write_log("主引擎创建成功") # log_engine = main_engine.get_engine("log") log_engine: LogEngine = main_engine.get_engine("log") event_engine.register(EVENT_CTA_LOG, log_engine.process_log_event) main_engine.write_log("注册日志事件监听") # main_engine.connect(binances_setting, "BINANCES") # 连接合约的 main_engine.connect(binance_setting, "BINANCE") # 连接现货的 main_engine.write_log("连接接口成功") sleep(10) cta_engine.init_engine() main_engine.write_log("CTA策略初始化完成") cta_engine.init_all_strategies() sleep(60) # Leave enough time to complete strategy initialization main_engine.write_log("CTA策略全部初始化") cta_engine.start_all_strategies() main_engine.write_log("CTA策略全部启动") while True: sleep(10)