示例#1
0
    def __init__(self, process, finish=None, maxsize=500, parent=None):
        """

        Parameters
        ----------
        process: 每个数据bar事件来时的回调方法
        finish: 数据结束的回调方法
        maxsize: 缓存大小,默认500
        """
        # assert isinstance(config, Config)
        LoggerInterface.__init__(self, parent=parent)
        ConfigInterface.__init__(self, parent=parent)
        self.__check_tf(self.config.time_frame)
        self.__maxsize = maxsize
        self.__dq = Queue(maxsize=maxsize * 2)  # 数据缓存器,避免数据在内存里过大,造成内存不足的错误
        self.__symbol = self.config.symbols[0]
        self.__start_time = int(
            get_datetime(self.config.start_time).timestamp())
        if self.config.end_time:
            self.__end_time = int(
                get_datetime(self.config.end_time).timestamp())
        else:  # 如果没有指定结束时间,默认查询到最近的数据
            self.__end_time = int(time.time())
        self.__handle = process  # 行情数据监听函数(可以想象成java的interface)
        self.__finish = finish  # 数据结束函数
        self._finished = False
        self.logger_name = "DataGenerator"
示例#2
0
    def __init__(self, parent=None):
        """初始化事件引擎"""
        # 事件队列
        LoggerInterface.__init__(self, parent=parent)
        self.logger_name = "EventEngine"
        self.__queue = None
        self.__count_lock = Lock()
        self.__count = 0  # 计数器,用于辅助实现优先级队列
        self.__file_opened = []
        # 事件引擎开关
        self.__active = False
        self.__finished = False
        self.__thread = None
        self.__exc_type = None
        self.__exc_value = None
        self.__exc_traceback = None
        # 计时器,用于触发计时器事件
        # self.__timer = QTimer()
        # self.__timer.timeout.connect(self.__onTimer)

        # 这里的__handlers是一个字典,用来保存对应的事件调用关系
        # 其中每个键对应的值是一个列表,列表中保存了对该事件进行监听的函数功能
        self.__handlers = {}
        # 注册异步事件
        self.register(EVENT_ASYNC, lambda event: event.content['func']())
        self.register(EVENT_FINISH, self._stop)
        self.register(EVENT_EXIT, self._stop)
示例#3
0
 def __init__(self,
              environment: Environment,
              parent: LoggerInterface = None):
     assert isinstance(environment, Environment)
     self.__environment = environment
     LoggerInterface.__init__(self, parent=parent)
     self.logger_name = "EnvironmentSetter"
示例#4
0
    def __init__(self, process, finish=None, maxsize=500, parent=None):
        """

        Parameters
        ----------
        process: 每个数据bar事件来时的回调方法
        finish: 数据结束的回调方法
        maxsize: 缓存大小,默认500
        """
        # assert isinstance(config, Config)
        LoggerInterface.__init__(self, parent=parent)
        ConfigInterface.__init__(self, parent=parent)
        self.__check_tf(self.config.time_frame)
        self.__maxsize = maxsize
        self.__dq = Queue(maxsize=maxsize * 2)  # 数据缓存器,避免数据在内存里过大,造成内存不足的错误
        self.__symbol = self.config.symbols[0]
        self.__start_time = int(get_datetime(self.config.start_time).timestamp())
        if self.config.end_time:
            self.__end_time = int(get_datetime(self.config.end_time).timestamp())
        else:  # 如果没有指定结束时间,默认查询到最近的数据
            self.__end_time = int(time.time())
        self.__handle = process  # 行情数据监听函数(可以想象成java的interface)
        self.__finish = finish  # 数据结束函数
        self._finished = False
        self.logger_name = "DataGenerator"
示例#5
0
 def __init__(self, engine, code, parent=None):
     """Constructor"""
     super().__init__()
     LoggerInterface.__init__(self, parent=parent)
     APIInterface.__init__(self)
     Runnable.__init__(self)
     ConfigInterface.__init__(self, parent=parent)
     self.__id = self.next_auto_inc()
     self.user = self.config.user
     self.user_dir = UserDirectory(User(self.config.user))
     self.__strategy_code = StrategyCode(self.config.name, code)
     self.__code_parser = None
     self.engine = proxy(engine)
     self.time_frame = self.config.time_frame
     self.symbols = self.config.symbols
     self.start_time = self.config.start_time
     self.end_time = self.config.end_time
     self.capital_base = self.config.capital_base
     self.handlers = {}
     self.signal_factory = SignalFactory()
     self.signals = {}
     self.system_functions = {}
     self.series_storage = {}
     self.printer = FilePrinter(self.config.user, self.config.name,
                                self.engine)
     self.__context = {}
     self._setting()
     self.logger_name = "Strategy"
示例#6
0
 def __init__(self, engine, code, parent=None):
     """Constructor"""
     super().__init__()
     LoggerInterface.__init__(self, parent=parent)
     APIInterface.__init__(self)
     Runnable.__init__(self)
     ConfigInterface.__init__(self, parent=parent)
     self.__id = self.next_auto_inc()
     self.user = self.config.user
     self.user_dir = UserDirectory(User(self.config.user))
     self.__strategy_code = StrategyCode(self.config.name, code)
     self.__code_parser = None
     self.engine = proxy(engine)
     self.time_frame = self.config.time_frame
     self.symbols = self.config.symbols
     self.start_time = self.config.start_time
     self.end_time = self.config.end_time
     self.capital_base = self.config.capital_base
     self.handlers = {}
     self.signal_factory = SignalFactory()
     self.signals = {}
     self.system_functions = {}
     self.series_storage = {}
     self.printer = FilePrinter(self.config.user, self.config.name, self.engine)
     self.__context = {}
     self._setting()
     self.logger_name = "Strategy"
示例#7
0
    def __init__(self, parent=None):
        """初始化事件引擎"""
        # 事件队列
        LoggerInterface.__init__(self, parent=parent)
        self.logger_name = "EventEngine"
        self.__queue = None
        self.__count_lock = Lock()
        self.__count = 0  # 计数器,用于辅助实现优先级队列
        self.__file_opened = []
        # 事件引擎开关
        self.__active = False
        self.__finished = False
        self.__thread = None
        self.__exc_type = None
        self.__exc_value = None
        self.__exc_traceback = None
        # 计时器,用于触发计时器事件
        # self.__timer = QTimer()
        # self.__timer.timeout.connect(self.__onTimer)

        # 这里的__handlers是一个字典,用来保存对应的事件调用关系
        # 其中每个键对应的值是一个列表,列表中保存了对该事件进行监听的函数功能
        self.__handlers = {}
        # 注册异步事件
        self.register(EVENT_ASYNC, lambda event: event.content['func']())
        self.register(EVENT_FINISH, self._stop)
        self.register(EVENT_EXIT, self._stop)
示例#8
0
 def __init__(self, currency=Currency("USD"), parent=None):
     LoggerInterface.__init__(self, parent=parent)
     ConfigInterface.__init__(self, parent=parent)
     self._capital_base = None
     self._capital_net = None
     self._capital_cash = None
     self._capital_available = None
     self._capital_margin = None
     self._currency = currency
     self.logger_name = "AccountManager"
示例#9
0
 def __init__(self, currency=Currency("USD"), parent=None):
     LoggerInterface.__init__(self, parent=parent)
     ConfigInterface.__init__(self, parent=parent)
     self._capital_base = None
     self._capital_net = None
     self._capital_cash = None
     self._capital_available = None
     self._capital_margin = None
     self._currency = currency
     self.logger_name = "AccountManager"
示例#10
0
 def __init__(self):
     LoggerInterface.__init__(self)
     ConfigInterface.__init__(self)
     Runnable.__init__(self)
     self.__code = None
     self.__strategy = None
     self.__strategy_engine = None
     self.__tb_data_generator = None
     self.__rt_data_generator = None
     self.__strategy_parameters = None
     self.__initialized = False
     self.logger_name = 'RuntimeSignal'
示例#11
0
 def __init__(self):
     LoggerInterface.__init__(self)
     ConfigInterface.__init__(self)
     self.__code = None
     self.__strategy = None
     self.__strategy_engine = None
     self.__data_generator = None
     self.__strategy_parameters = None
     self.__performance_manager = None
     self.__is_alive = False
     self.__initialized = False
     self.logger_name = 'RuntimeSignal'
示例#12
0
 def __init__(self):
     LoggerInterface.__init__(self)
     ConfigInterface.__init__(self)
     Runnable.__init__(self)
     self.__code = None
     self.__strategy = None
     self.__strategy_engine = None
     self.__tb_data_generator = None
     self.__rt_data_generator = None
     self.__strategy_parameters = None
     self.__initialized = False
     self.logger_name = 'RuntimeSignal'
示例#13
0
 def __init__(self, engine, parent=None):
     LoggerInterface.__init__(self, parent=parent)
     Runnable.__init__(self)
     APIInterface.__init__(self)
     ConfigInterface.__init__(self, parent=parent)
     self._engine = proxy(engine)  # 避免循环引用
     self._tick_cache = {}
     self._running = False
     self._data_view = QuotationDataView()
     self._symbol_pool = {}
     self.current_time = None  # 目前数据运行到的时间,用于计算回测进度
     self._min_time_frame = None
     self._count = 0
     self.logger_name = "QuotationManager"
示例#14
0
 def __init__(self, engine, quotation_manager, account_manager, parent=None):
     APIInterface.__init__(self)
     LoggerInterface.__init__(self, parent=parent)
     ConfigInterface.__init__(self, parent=parent)
     self._engine = proxy(engine)
     self.__quotation_manager = proxy(quotation_manager)
     self.__account_manager = proxy(account_manager)
     self.__factory = TradingDataFactory(parent=self)
     self.__orders_ur = defaultdict(OrdersUr)  # orders unrealized 还未被处理的订单请求
     self.__orders_done = {}  # 保存所有已处理报单数据的字典
     self.__orders_todo = {}  # 保存所有未处理报单(即挂单)数据的字典 key:id
     self.__orders_todo_index = {}  # 同上 key:symbol
     self.__positions = {}  # Key:id, value:position with responding id
     self.__current_positions = {}  # key:symbol,value:current position
     self.max_margin = 0
     self.logger_name = "TradingManager"
示例#15
0
 def __init__(self, parent=None):
     """Constructor"""
     LoggerInterface.__init__(self, parent=parent)
     Runnable.__init__(self)
     ConfigInterface.__init__(self, parent=parent)
     APIInterface.__init__(self)
     self.__event_engine = EventEngine(parent=self)  # 事件处理引擎
     self.__quotation_manager = QuotationManager(self, parent=self)  # 行情数据管理器
     if self.config.running_mode == RunningMode.backtest:
         self.__account_manager = BfAccountManager(parent=self)  # 账户管理
     else:
         self.__account_manager = FDTAccountManager(parent=self)
         self.mongo_user = MongoUser(self.config.user)
     self.__trading_manager = TradingManager(self, self.__quotation_manager, self.__account_manager,
                                             parent=self)  # 交易管理器
     if self.config.running_mode == RunningMode.backtest:
         self.__account_manager.set_trading_manager(self.__trading_manager)
     self.__strategys = {}  # 策略管理器
     self.__profit_records = []  # 保存账户净值的列表
     self.logger_name = "StrategyEngine"
示例#16
0
    def __init__(self, process, finish=None, maxsize=500, parent=None):
        """

        Parameters
        ----------
        config: BfConfig对象
        process: 每个数据bar事件来时的回调方法
        finish: 数据结束的回调方法
        maxsize: 缓存大小,默认500
        """
        LoggerInterface.__init__(self, parent=parent)
        ConfigInterface.__init__(self, parent=parent)
        self.__check_tf(self.config.time_frame)
        self.__maxsize = maxsize
        self.__dq = Queue(maxsize=maxsize * 2)  # 数据缓存器,避免数据在内存里过大,造成内存不足的错误
        self.__receiver = TickDataReceiver(parent=self)
        self.__receiver.register_event(self.config.symbols[0], self.product)
        self.__symbol = self.config.symbols[0]
        self.__handle = process  # 行情数据监听函数(可以想象成java的interface)
        self.__finish = finish  # 数据结束函数
        self._finished = False
        self.logger_name = "TickDataGenerator"
示例#17
0
    def __init__(self, process, finish=None, maxsize=500, parent=None):
        """

        Parameters
        ----------
        config: BfConfig对象
        process: 每个数据bar事件来时的回调方法
        finish: 数据结束的回调方法
        maxsize: 缓存大小,默认500
        """
        LoggerInterface.__init__(self, parent=parent)
        ConfigInterface.__init__(self, parent=parent)
        self.__check_tf(self.config.time_frame)
        self.__maxsize = maxsize
        self.__dq = Queue(maxsize=maxsize * 2)  # 数据缓存器,避免数据在内存里过大,造成内存不足的错误
        self.__receiver = TickDataReceiver(parent=self)
        self.__receiver.register_event(self.config.symbols[0], self.product)
        self.__symbol = self.config.symbols[0]
        self.__handle = process  # 行情数据监听函数(可以想象成java的interface)
        self.__finish = finish  # 数据结束函数
        self._finished = False
        self.logger_name = "TickDataGenerator"
示例#18
0
 def __init__(self, parent=None):
     LoggerInterface.__init__(self, parent=parent)
     Runnable.__init__(self)
     self.factory = DataClientFactory(parent=self)
示例#19
0
 def __init__(self, parent=None):
     super().__init__()
     LoggerInterface.__init__(self, parent=parent)
     self.done = Deferred()
     self._tick_event = dict()
示例#20
0
 def __init__(self, environment: Environment, parent: LoggerInterface = None):
     assert isinstance(environment, Environment)
     self.__environment = environment
     LoggerInterface.__init__(self, parent=parent)
     self.logger_name = "EnvironmentSetter"