Пример #1
0
    def __init__(self, db_path, calendar, start_session, end_session):
        self.conn = check_and_create_engine(db_path, False)

        if start_session != end_session:
            if not calendar.is_session(start_session):
                raise ValueError(
                    "Start session %s is invalid!" % start_session
                )
            if not calendar.is_session(end_session):
                raise ValueError(
                    "End session %s is invalid!" % end_session
                )

        self._start_session = start_session
        self._end_session = end_session
        self._calendar = calendar

        try:
            self.conn.connect()
        except sa.exc.OperationalError:
            # can't connect to db. might mean that the database is not created yey.
            # let's create it. (happens in first time usage)
            self.ensure_database(db_path)

        self.ensure_table()
Пример #2
0
    def __init__(self, path, read_all_threshold=3000):
        self.conn = check_and_create_engine(path, False)

        # Cache of fully read np.array for the carrays in the daily bar table.
        # raw_array does not use the same cache, but it could.
        # Need to test keeping the entire array in memory for the course of a
        # process first.
        self._spot_cols = {}
        self._read_all_threshold = read_all_threshold

        # caching the calendar-sessions like this prevent problems during ingestion
        # where the reader is first initialized when there are still no bars
        self._sessions = pd.DatetimeIndex([], dtype='datetime64[ns, UTC]', freq='C')

        self._calendar_offsets_c = {}
        self._first_rows_c = {}
        self._last_rows_c = {}
        self._first_trading_day_c = {}