otp.inspection.DB#
- class DB(name, context=utils.default)#
Bases:
object
An object of available databases that the
otp.databases()
function returns. It helps to make initial analysis on the database level: available tick types, dates with data, symbols, tick schema, etc.- property access_info: dict#
Get access info for this database and current user.
All dates are returned in GMT timezone.
This function result is cached, cache will be cleared after each
otp.databases
call.Examples
>>> some_db = otp.databases()['SOME_DB'] >>> some_db.access_info {'DB_NAME': 'SOME_DB', 'READ_ACCESS': 1, 'WRITE_ACCESS': 1, 'MIN_AGE_SET': 0, 'MIN_AGE_MSEC': 0, 'MAX_AGE_SET': 0, 'MAX_AGE_MSEC': 0, 'MIN_START_DATE_SET': 0, 'MIN_START_DATE_MSEC': Timestamp('1970-01-01 00:00:00'), 'MAX_END_DATE_SET': 0, 'MAX_END_DATE_MSEC': Timestamp('1970-01-01 00:00:00'), 'MIN_AGE_DB_DAYS': 0, 'MIN_AGE_DB_DAYS_SET': 0, 'MAX_AGE_DB_DAYS': 0, 'MAX_AGE_DB_DAYS_SET': 0, 'CEP_ACCESS': 0, 'DESTROY_ACCESS': 0}
See also
ACCESS_INFO OneTick event processor
- show_config(config_type='locator_entry')#
Shows the specified configuration for a database.
- Parameters
config_type (str) –
If ‘locator_entry’ is specified, a string representing db’s locator entry along with VDB_FLAG (this flag equals 1 when the database is virtual and 0 otherwise) will be returned.
If ‘db_time_intervals’ is specified, then time intervals configured in the locator file will be propagated including additional information, such as LOCATION, ARCHIVE_DURATION, DAY_BOUNDARY_TZ, DAY_BOUNDARY_OFFSET, ALTERNATIVE_LOCATIONS, etc.
- Return type
Examples
>>> some_db = otp.databases()['SOME_DB'] >>> print(some_db.show_config()['LOCATOR_STRING']) <DB ARCHIVE_COMPRESSION_TYPE="NATIVE_PLUS_GZIP" ID="SOME_DB" SYMBOLOGY="BZX" TICK_TIMESTAMP_TYPE="NANOS" > <LOCATIONS > <LOCATION ACCESS_METHOD="file" DAY_BOUNDARY_TZ="EST5EDT" END_TIME="21000101000000" LOCATION="..." START_TIME="20021230000000" /> </LOCATIONS> <RAW_DATA /> </DB> >>> some_db.show_config(config_type='db_time_intervals') {'START_DATE': 1041206400000, 'END_DATE': 4102444800000, 'GROWABLE_ARCHIVE_FLAG': 0, 'ARCHIVE_DURATION': 0, 'LOCATION': '...', 'DAY_BOUNDARY_TZ': 'EST5EDT', 'DAY_BOUNDARY_OFFSET': 0, 'ALTERNATIVE_LOCATIONS': ''}
See also
DB/SHOW_CONFIG OneTick event processor
- property min_acl_start_date: Optional[datetime.date]#
Minimum start date set in ACL for current user. Returns None if not set.
- property max_acl_end_date: Optional[datetime.date]#
Maximum end date set in ACL for current user. Returns None if not set.
- dates(respect_acl=False)#
Returns list of dates in GMT timezone for which data is available.
- Returns
Returns
None
when there is no data in the database- Return type
datetime.date
orNone
Examples
>>> some_db = otp.databases()['SOME_DB'] >>> some_db.dates() [datetime.date(2003, 12, 1)]
- property last_date#
The latest date on which db has data and the current user has access to.
- Returns
Returns
None
when there is no data in the database- Return type
datetime.date
orNone
Examples
>>> some_db = otp.databases()['SOME_DB'] >>> some_db.last_date datetime.date(2003, 12, 1)
- tick_types(date=None, timezone=None)#
Returns list of tick types for the
date
.- Parameters
- Returns
List with string values of available tick types.
- Return type
Examples
>>> nyse_taq_db = otp.databases()['NYSE_TAQ'] >>> nyse_taq_db.tick_types(date=otp.dt(2022, 3, 1)) ['QTE', 'TRD']
- schema(date=None, tick_type=None, timezone=None)#
Gets the schema of the database.
- Parameters
date (
otp.dt
,datetime.datetime
, optional) – Date for the schema.None
means thelast_date
tick_type (str, optional) – Specifies a tick type for schema.
None
means use the one available tick type, if there are multiple tick types then it raises theException
. It uses thetick_types()
method.timezone (str, optional) – Allows to specify a timezone for searching tick types.
- Returns
Dict where keys are field names and values are
onetick.py
types. It’s compatible with theonetick.py.Source.schema
methods.- Return type
Examples
>>> nyse_taq_db = otp.databases()['NYSE_TAQ'] >>> nyse_taq_db.schema(tick_type='TRD', date=otp.dt(2022, 3, 1)) {'PRICE': <class 'float'>, 'SIZE': <class 'int'>}
- symbols(date=None, timezone=None, tick_type=None, pattern='.*')#
Finds a list of available symbols in the database
- Parameters
date (
otp.dt
,datetime.datetime
, optional) – Date for the symbols look up.None
means thelast_date
tick_type (str, optional) – Tick type for symbols.
None
means union across all tick types.timezone (str, optional) – Timezone for the lookup.
None
means the default timezone.pattern (str) – Regular expression to select symbols.
- Return type
Examples
>>> nyse_taq_db = otp.databases()['NYSE_TAQ'] >>> nyse_taq_db.symbols(date=otp.dt(2022, 3, 1), tick_type='TRD', pattern='^AAP.*') ['AAP', 'AAPL']