Ejemplo n.º 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"
Ejemplo n.º 2
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"
Ejemplo n.º 3
0
 def _get_data(self, symbol, time_frame, start_time=None, end_time=None):
     data = self.with_time_cost_count(fx_mysql.get_period_bars)(symbol, time_frame,
                                                                get_datetime(start_time).timestamp(),
                                                                get_datetime(end_time).timestamp())
     result = list(map(partial(_get_bar_from_dict, symbol, time_frame), data))
     data.clear()
     return result
Ejemplo n.º 4
0
 def progress(self):
     et = get_datetime(self.__setting['end_time']).timestamp()
     st = get_datetime(self.__setting['start_time']).timestamp()
     ct = self.__strategy_engine.current_time
     if ct:
         return min((ct - st) / (et - st) * 100, 100)
     else:
         return 0
Ejemplo n.º 5
0
 def progress(self):
     et = get_datetime(self.__config['end_time']).timestamp()
     st = get_datetime(self.__config['start_time']).timestamp()
     ct = self.__strategy_engine.current_time
     if ct:
         return min((ct - st) / (et - st) * 100, 100)
     else:
         return 0
Ejemplo n.º 6
0
 def progress(self):
     if not self.__is_alive:
         return 0
     et = get_datetime(self._config['end_time']).timestamp()
     st = get_datetime(self._config['start_time']).timestamp()
     ct = self.__strategy_engine.current_time
     if ct:
         return min((ct - st) / (et - st) * 100, 100)
     else:
         return 0
Ejemplo n.º 7
0
 def _get_data(self,
               symbol,
               time_frame,
               start_time=None,
               end_time=None):
     data = self.with_time_cost_count(fx_mysql.get_period_bars)(
         symbol, time_frame, get_datetime(start_time).timestamp(),
         get_datetime(end_time).timestamp())
     result = list(
         map(partial(_get_bar_from_dict, symbol, time_frame), data))
     data.clear()
     return result
Ejemplo n.º 8
0
def _get_bar_from_dataframe(symbol, time_frame, data):
    bar = Bar(symbol)
    bar.time_frame = time_frame
    for field in ['open', 'high', 'low', 'close', 'volume']:
        setattr(bar, field, data[field])
    bar.timestamp = get_datetime(data.name).timestamp()
    return bar
Ejemplo n.º 9
0
def _get_bar_from_dataframe(symbol, time_frame, data):
    bar = Bar(symbol)
    bar.time_frame = time_frame
    for field in ['open', 'high', 'low', 'close', 'volume']:
        setattr(bar, field, data[field])
    bar.timestamp = get_datetime(data.name).timestamp()
    return bar
Ejemplo n.º 10
0
 def __data_to_event(symbol, time_frame, data):
     bar = Bar(symbol)
     bar.time_frame = time_frame
     for field in ['open','high','low','close','volume']:
         setattr(bar,field,data[field])
     bar.time = get_datetime(data.name).timestamp()
     event = Event(EVENT_BAR_SYMBOL[symbol][time_frame],{'data':bar})
     return(event)
Ejemplo n.º 11
0
    def __init__(self, config, process, finish=None, maxsize=500):
        """

        Parameters
        ----------
        config: BfConfig对象
        process: 每个数据bar事件来时的回调方法
        finish: 数据结束的回调方法
        maxsize: 缓存大小,默认500
        """
        # assert isinstance(config, Config)
        self.__check_tf(config.time_frame)
        self.__maxsize = maxsize
        self.__dq = Queue(maxsize=maxsize * 2)  # 数据缓存器,避免数据在内存里过大,造成内存不足的错误
        self.__config = config
        self.__symbol = config.symbols[0]
        self.__start_time = int(get_datetime(config.start_time).timestamp())
        if config.end_time:
            self.__end_time = int(get_datetime(config.end_time).timestamp())
        else:  # 如果没有指定结束时间,默认查询到最近的数据
            self.__end_time = int(time.time())
        self.__handle = process  # 行情数据监听函数(可以想象成java的interface)
        self.__finish = finish  # 数据结束函数
        self._finished = False
Ejemplo n.º 12
0
 def _get_data(self, symbol, time_frame, start_time=None, end_time=None):
     data = fx.get_period_bars(symbol, time_frame,
                               get_datetime(start_time).timestamp(),
                               get_datetime(end_time).timestamp())
     return list(map(partial(_get_bar_from_dict, symbol, time_frame), data))