otp.DB#

class DB(name=None, src=None, date=None, symbol=None, tick_type=None, kind='archive', db_properties=None, db_locations=None, write=True, clean_up=True, destroy_access=False)[source]#

Creates database object. Add db to locator and acl. By default creates temporary database A class to configure databases locator and acl properties and to write data to db with or without OneTick session. Note: already presented ticks can’t be update during db creation or by add method.

Parameters
  • name (str) – Database name In case you want to specify derived db, you should specify in “parent//derived” format

  • src (optional) – Data to add to database

  • clean_up (bool, optional) – Flag that controls temporary database cleanup

  • date (datetime.datetime, optional) – src will be added to this date

  • symbol (str, optional) – symbol name to add data

  • tick_type (str, optional) – tick type to add data

  • db_properties (dict, optional) – Properties of database to add to locator

  • db_locations (list of dict, optional) – Locations of database to add to locator (This parameter is list, because database in locator can have several location sections)

  • write (bool, optional) – Flag that controls access to write to database

  • destroy_access (bool, optional) – Flag that controls access to destroy to database

Examples

>>> data = otp.Ticks(X=['hello', 'world!'])
>>> db = otp.DB("MYDB")
>>> db.add(data)
>>> session.use(db)
>>> data = otp.run(otp.DataSource(db))
>>> data["X"]  # field names saved uppercased only
0    hello
1    world!
Name: X, dtype: object

You can specify derived db by using // as a separator and/or write using src param

>>> data = otp.Ticks(X=['parent1', 'parent2'])
>>> db = otp.DB("DB_A", data)
>>> data = otp.Ticks(X=['derived1', 'derived2'])
>>> db_derived = otp.DB("DB_A//DB_D")
>>> session.use(db_derived)
>>> db_derived.add(data)
>>> data = otp.run(otp.DataSource([db, db_derived]))
>>> data["X"]
0    parent1
1    derived1
2    parent2
3    derived2
Name: X, dtype: object
Variables
  • Dict (properties) – list of locator database properties

  • List[Dict] (locations) – database location properties

add(src, date=None, symbol=None, tick_type=None, timezone=None, **kwargs)#

Add data to database. If ticks with the same timestamp are already presented in database old values won’t be updated.

Parameters
  • src (otp.Source) – source that will be written to the database.

  • date (datetime or None) – date of the day in which the data will be saved. The timestamps of the ticks should be between the start and the end of the day. Be default, it is set to otp.config.default_date.

  • symbol (str or Column) – resulting symbol name string or column to get symbol name from. Be default, it is set to otp.config.default_db_symbol.

  • tick_type (str or Column) – resulting tick type string or column to get tick type from. If tick type is None then an attempt will be taken to get tick type name automatically based on the src source’s schema. (ORDER, QTE, TRD and NBBO tick types are supported).

  • timezone (str) – This timezone will be used for running the query. By default, it is set to otp.config.tz.

  • kwargs – other arguments that will be passed to otp.db.write_to_db() function.