def strategy_to_json(self, TianJinMeta):
        data_json = {}
        try:
            signal_finder = SignalFinder()
            for member in TianJinMeta.get_const_member_list():
                member_value = getattr(TianJinMeta, member)
                if member in TianJinMeta.get_portfolio_list():
                    data_json[member] = reference_portfolio(member_value)
                    if data_json[member] == -1:
                        raise CSVConverterError(TianJinMeta.Name, TianJinMeta.Type, "Can't find portfolio: {0}".format(member_value))
                elif member in TianJinMeta.get_signal_list():
                    data_json[member] = (signal_finder.get_signal_id_by_name(member_value), member_value)[isinstance(member_value, int)]
                    if data_json[member] == -1:
                        raise CSVConverterError(TianJinMeta.Name, TianJinMeta.Type, "Can't find signal: {0}".format(member_value))

                elif member in TianJinMeta.get_bool_list():
                    data_json[member] = is_bool(member_value)
                elif member in TianJinMeta.get_MatchStrategyId():
                    data_json[member] = (get_strategy_id_by_name(self.work_dir, member_value), member_value)[isinstance(member_value, int)]
                    if data_json[member] == -1:
                        raise CSVConverterError(TianJinMeta.Name, TianJinMeta.Type, "Can't find matchstrategy:{0}".format(member_value))
                else:
                    data_json[member] = member_value
            data_json['Instruments'] = generate_instruments(TianJinMeta, TianJinMeta.member_list)
            data_json['Ranges'] = generate_ranges(TianJinMeta, TianJinMeta.member_list)
        except Exception as e:
            raise CSVConverterError(TianJinMeta.Name, TianJinMeta.Type, e.message)
        if self.work_dir is not None:
            self.__create_file(data_json)
        return data_json
Beispiel #2
0
    def strategy_to_json(self, HFStrategyMeta):
        data_json = {}
        try:
            signal_finder = SignalFinder()
            for member in HFStrategyMeta.get_const_member_list():
                member_value = getattr(HFStrategyMeta, member)
                if member in HFStrategyMeta.get_portfolio_list():
                    data_json[member] = reference_portfolio(member_value)
                    if data_json[member] == -1:
                        raise CSVConverterError(HFStrategyMeta.Name, HFStrategyMeta.Type, "Can't find portfolio: {0}".format(member_value))
                elif member in HFStrategyMeta.get_signal_list():
                    data_json[member] = (signal_finder.get_signal_id_by_name(member_value), member_value)[isinstance(member_value, int)]
                    if data_json[member] == -1:
                        raise CSVConverterError(HFStrategyMeta.Name, HFStrategyMeta.Type, "Can't find signal: {0}".format(member_value))

                elif member in HFStrategyMeta.get_bool_list():
                    data_json[member] = is_bool(member_value)
                elif member in HFStrategyMeta.get_MatchStrategyId():
                    data_json[member] = (get_strategy_id_by_name(self.work_dir, member_value), member_value)[isinstance(member_value, int)]
                    if data_json[member] == -1:
                        raise CSVConverterError(HFStrategyMeta.Name, HFStrategyMeta.Type, "Can't find matchstrategy:{0}".format(member_value))
                else:
                    data_json[member] = member_value
            data_json['Instruments'] = generate_instruments(HFStrategyMeta, HFStrategyMeta.member_list)
            data_json['Ranges'] = generate_ranges(HFStrategyMeta, HFStrategyMeta.member_list)
        except Exception as e:
            raise CSVConverterError(HFStrategyMeta.Name, HFStrategyMeta.Type, e.message)
        if self.work_dir is not None:
            self.__create_file(data_json)
        return data_json