def save_setting(self) -> None: """""" setting = [] for spread in self.spreads.values(): leg_settings = [] for leg in spread.legs.values(): price_multiplier = spread.price_multipliers[leg.vt_symbol] trading_multiplier = spread.trading_multipliers[leg.vt_symbol] inverse_contract = spread.inverse_contracts[leg.vt_symbol] leg_setting = { "vt_symbol": leg.vt_symbol, "price_multiplier": price_multiplier, "trading_multiplier": trading_multiplier, "inverse_contract": inverse_contract } leg_settings.append(leg_setting) spread_setting = { "name": spread.name, "leg_settings": leg_settings, "active_symbol": spread.active_leg.vt_symbol, "min_volume": spread.min_volume } setting.append(spread_setting) save_json(self.setting_filename, setting)
def save_setting(self): """""" setting = { "tick": self.tick_recordings, "bar": self.bar_recordings } save_json(self.setting_filename, setting)
def save_setting(self) -> None: """""" setting = { "trade_slippage": self.trade_slippage, "timer_interval": self.timer_interval, "instant_trade": self.instant_trade } save_json(self.setting_filename, setting)
def remove_strategy_setting(self, strategy_name: str): """ Update setting file. """ if strategy_name not in self.strategy_setting: return self.strategy_setting.pop(strategy_name) save_json(self.setting_filename, self.strategy_setting)
def sync_strategy_data(self, strategy: CtaTemplate): """ Sync strategy data into json file. """ data = strategy.get_variables() data.pop("inited") # Strategy status (inited, trading) should not be synced. data.pop("trading") self.strategy_data[strategy.strategy_name] = data save_json(self.data_filename, self.strategy_data)
def update_strategy_setting(self, strategy_name: str, setting: dict): """ Update setting file. """ strategy = self.strategies[strategy_name] self.strategy_setting[strategy_name] = { "class_name": strategy.__class__.__name__, "vt_symbol": strategy.vt_symbol, "setting": setting, } save_json(self.setting_filename, self.strategy_setting)
def save_strategy_setting(self): """ Save setting file. """ strategy_setting = {} for name, strategy in self.strategies.items(): strategy_setting[name] = { "class_name": strategy.__class__.__name__, "vt_symbols": strategy.vt_symbols, "setting": strategy.get_parameters() } save_json(self.setting_filename, strategy_setting)
def save_data(self) -> None: """""" position_data = [] for position in self.positions.values(): if not position.volume: continue d = { "vt_symbol": position.vt_symbol, "volume": position.volume, "price": position.price, "direction": position.direction.value } position_data.append(d) save_json(self.data_filename, position_data)
def save_setting(self): """""" setting: dict = {} for strategy in self.strategies.values(): setting[strategy.name] = { "name": strategy.name, "vt_symbol": strategy.vt_symbol, "size": strategy.size, "net_pos": strategy.net_pos, "open_price": strategy.open_price, "last_price": strategy.last_price, "create_time": strategy.create_time, "note_text": strategy.note_text, } save_json(self.setting_filename, setting)
def start_backtesting(self): """""" class_name = self.class_combo.currentText() vt_symbol = self.symbol_line.text() interval = self.interval_combo.currentText() start = self.start_date_edit.date().toPyDate() end = self.end_date_edit.date().toPyDate() rate = float(self.rate_line.text()) slippage = float(self.slippage_line.text()) size = float(self.size_line.text()) pricetick = float(self.pricetick_line.text()) capital = float(self.capital_line.text()) if self.inverse_combo.currentText() == "正向": inverse = False else: inverse = True # Save backtesting parameters backtesting_setting = { "class_name": class_name, "vt_symbol": vt_symbol, "interval": interval, "rate": rate, "slippage": slippage, "size": size, "pricetick": pricetick, "capital": capital, "inverse": inverse, } save_json(self.setting_filename, backtesting_setting) # Get strategy setting old_setting = self.settings[class_name] dialog = BacktestingSettingEditor(class_name, old_setting) i = dialog.exec() if i != dialog.Accepted: return new_setting = dialog.get_setting() self.settings[class_name] = new_setting result = self.backtester_engine.start_backtesting( class_name, vt_symbol, interval, start, end, rate, slippage, size, pricetick, capital, inverse, new_setting ) if result: self.statistics_monitor.clear_data() self.chart.clear_data() self.trade_button.setEnabled(False) self.order_button.setEnabled(False) self.daily_button.setEnabled(False) self.candle_button.setEnabled(False) self.trade_dialog.clear_data() self.order_dialog.clear_data() self.daily_dialog.clear_data() self.candle_dialog.clear_data()
def save_algo_setting(self): """""" save_json(self.setting_filename, self.algo_settings)
def save_setting(self): """""" setting = self.get_setting() save_json(self.setting_filename, setting)