Ejemplo n.º 1
0
    def load_setting(self) -> None:
        """"""
        # For normal spread
        setting = load_json(self.setting_filename)

        for spread_setting in setting:
            self.add_spread(
                spread_setting["name"],
                spread_setting["leg_settings"],
                spread_setting["active_symbol"],
                spread_setting.get("min_volume", 1),
                save=False
            )

        # For advanced spread
        setting = load_json(self.advanced_filename)

        for spread_setting in setting:
            self.add_advanced_spread(
                spread_setting["name"],
                spread_setting["leg_settings"],
                spread_setting["price_formula"],
                spread_setting["active_symbol"],
                spread_setting.get("min_volume", 1),
                save=False
            )
Ejemplo n.º 2
0
    def load_data(self) -> None:
        """"""
        data = load_json(self.data_filename)
        if not data:
            return

        today = datetime.now().strftime("%Y-%m-%d")
        date_changed = False

        date = data.pop("date")
        for key, d in data.items():
            reference, vt_symbol = key.split(",")

            if date == today:
                pos = d["open_pos"]
            else:
                pos = d["last_pos"]
                date_changed = True

            self.result_symbols.add(vt_symbol)
            self.contract_results[(reference, vt_symbol)] = ContractResult(
                self, reference, vt_symbol, pos)

        # Re-save latest data if date changed
        if date_changed:
            self.save_data()
Ejemplo n.º 3
0
    def load_backtesting_setting(self):
        """"""
        setting = load_json(self.setting_filename)
        if not setting:
            return

        self.class_combo.setCurrentIndex(
            self.class_combo.findText(setting["class_name"]))

        self.symbol_line.setText(setting["vt_symbol"])

        self.interval_combo.setCurrentIndex(
            self.interval_combo.findText(setting["interval"]))

        start_str = setting.get("start", "")
        if start_str:
            start_dt = QtCore.QDate.fromString(start_str, "yyyy-MM-dd")
            self.start_date_edit.setDate(start_dt)

        self.rate_line.setText(str(setting["rate"]))
        self.slippage_line.setText(str(setting["slippage"]))
        self.size_line.setText(str(setting["size"]))
        self.pricetick_line.setText(str(setting["pricetick"]))
        self.capital_line.setText(str(setting["capital"]))

        if not setting["inverse"]:
            self.inverse_combo.setCurrentIndex(0)
        else:
            self.inverse_combo.setCurrentIndex(1)
Ejemplo n.º 4
0
    def load_setting(self):
        """"""
        setting = load_json(self.setting_filename)
        if not setting:
            return

        self.update_setting(setting)
Ejemplo n.º 5
0
    def load_algo_setting(self):
        """"""
        self.algo_settings = load_json(self.setting_filename)

        for setting_name, setting in self.algo_settings.items():
            self.put_setting_event(setting_name, setting)

        self.write_log("算法配置载入成功")
Ejemplo n.º 6
0
    def load_order(self) -> None:
        """"""
        order_data = load_json(self.order_filename)

        date = order_data.get("date", "")
        today = datetime.now().strftime("%Y-%m-%d")
        if date == today:
            self.order_reference_map = order_data["data"]
Ejemplo n.º 7
0
    def load_setting(self) -> None:
        """"""
        setting = load_json(self.setting_filename)

        if setting:
            self.trade_slippage = setting["trade_slippage"]
            self.timer_interval = setting["timer_interval"]
            self.instant_trade = setting["instant_trade"]
Ejemplo n.º 8
0
    def load_data(self) -> None:
        """"""
        position_data = load_json(self.data_filename)

        for d in position_data:
            vt_symbol = d["vt_symbol"]
            direction = Direction(d["direction"])

            position = self.get_position(vt_symbol, direction)
            position.volume = d["volume"]
            position.price = d["price"]
Ejemplo n.º 9
0
    def load_strategy_setting(self):
        """
        Load setting file.
        """
        strategy_setting = load_json(self.setting_filename)

        for strategy_name, strategy_config in strategy_setting.items():
            self.add_strategy(
                strategy_config["class_name"],
                strategy_name,
                strategy_config["vt_symbols"],
                strategy_config["setting"]
            )
Ejemplo n.º 10
0
 def load_setting(self) -> None:
     """"""
     setting = load_json(self.setting_filename)
     if "timer_interval" in setting:
         self.timer_interval = setting["timer_interval"]
Ejemplo n.º 11
0
 def load_setting(self):
     """"""
     setting = load_json(self.setting_filename)
     self.tick_recordings = setting.get("tick", {})
     self.bar_recordings = setting.get("bar", {})
Ejemplo n.º 12
0
 def load_strategy_data(self):
     """
     Load strategy data from json file.
     """
     self.strategy_data = load_json(self.data_filename)