Example #1
0
    def get_latest_saved_record(self, entity):
        order = eval("self.data_schema.{}.desc()".format(
            self.get_evaluated_time_field()))

        #: 对于k线这种数据,最后一个记录有可能是没完成的,所以取两个
        #: 同一周期内只保留最新的一个数据
        records = get_data(
            entity_id=entity.id,
            provider=self.provider,
            data_schema=self.data_schema,
            order=order,
            limit=2,
            return_type="domain",
            session=self.session,
            level=self.level,
        )
        if records:
            #: delete unfinished kdata
            if len(records) == 2:
                if is_in_same_interval(t1=records[0].timestamp,
                                       t2=records[1].timestamp,
                                       level=self.level):
                    self.session.delete(records[1])
                    self.session.flush()
            return records[0]
        return None
Example #2
0
    def get_latest_saved_record(self, entity):
        # step = time.time()
        order = eval('self.data_schema.{}.desc()'.format(self.get_evaluated_time_field()))
        # self.logger.info("get order: {}".format(time.time()-step))

        # 对于k线这种数据,最后一个记录有可能是没完成的,所以取两个,总是删掉最后一个数据,更新之
        # self.logger.info("record info: {}, {}, {}".format(entity.id, order, self.level))
        records = get_data(region=self.region,
                           entity_id=entity.id,
                           provider=self.provider,
                           data_schema=self.data_schema,
                           order=order,
                           limit=2,
                           return_type='domain',
                           session=self.session,
                           level=self.level)
        # self.logger.info("get record: {}".format(time.time()-step))

        if records:
            # delete unfinished kdata
            if len(records) == 2:
                if is_in_same_interval(t1=records[0].timestamp, t2=records[1].timestamp, level=self.level):
                    self.session.delete(records[0])
                    self.session.flush()
                    return records[1]
            return records[0]
        return None