otp.Symbols#
- class Symbols(db=None, tick_type='ANY', start=utils.adaptive, end=utils.adaptive, date=None, find_params=None, keep_db=False, pattern='%', for_tick_type=None, show_tick_type=False, symbology='', show_original_symbols=False, **kwargs)[source]#
Bases:
onetick.py.core.source.Source
Construct a source that returns ticks with information about symbols in a database. The SYMBOL_NAME field is populated with symbol names. The TICK_TYPE field contains corresponding tick type (enabled by the
show_tick_type
parameter).- Parameters
db (str) – Name of the database where to search symbols
tick_type (str) – Tick type to use. Default is ANY
start (
datetime.datetime
,otp.datetime
,onetick.py.adaptive
) – Time interval from which the data should be taken.end (
datetime.datetime
,otp.datetime
,onetick.py.adaptive
) – Time interval from which the data should be taken.date (
datetime.date
) – Alernative way of setting instead of start/end timeskeep_db (bool) – Flag that indicates whether symbols should have a db prefix.
pattern (str) – SQL syntax patter for symbols. Default is ‘%’
for_tick_type (str) – Fetch only symbols belong to this tick type, if specified.
show_tick_type (bool) – Add the TICK_TYPE column with the information about tick type
symbology (str) – The destination symbology for a symbol name translation. Translation is performed, if destination symbology is not empty and is different from that of the queried database.
show_original_symbols (bool) – Switches original symbol name propagation as a tick field ORIGINAL_SYMBOL_NAME if symbol name translation is performed (if symbology is set). Note that if this parameter is set to True, database symbols with missing translations are also propagated.
Note
Additional fields that can be added to Symbols will be converted to symbol parameters
Examples
This class can be used to get a list of all symbols in the database:
>>> otp.Symbols('NYSE_TAQ', date=otp.dt(2022, 3, 1)).to_df() Time SYMBOL_NAME 0 2022-03-01 AAP 1 2022-03-01 AAPL
Also this class can be used to specify symbols for the main query:
>>> symbols = otp.Symbols('NYSE_TAQ', date=otp.dt(2022, 3, 1)) >>> data = otp.DataSource('NYSE_TAQ', tick_type='TRD', date=otp.dt(2022, 3, 1)) >>> result = otp.run(data, symbols=symbols) >>> result['AAPL'] Time PRICE SIZE 0 2022-03-01 00:00:00.000 1.3 100 1 2022-03-01 00:00:00.001 1.4 10 2 2022-03-01 00:00:00.002 1.4 50 >>> result['AAP'] Time PRICE 0 2022-03-01 00:00:00.000 45.37 1 2022-03-01 00:00:00.001 45.41
Additional fields of the
otp.Symbols
can be used in the main query as symbol parameters:>>> symbols = otp.Symbols('SOME_DB', show_tick_type=True, keep_db=True) >>> symbols['PARAM'] = symbols['SYMBOL_NAME'] + '__' + symbols['TICK_TYPE'] >>> data = otp.DataSource('SOME_DB') >>> data['S_PARAM'] = data.Symbol.PARAM >>> data = otp.merge([data], symbols=symbols) >>> otp.run(data) Time X S_PARAM 0 2003-12-01 00:00:00.000 1 SOME_DB::S1__TT 1 2003-12-01 00:00:00.000 -3 SOME_DB::S2__TT 2 2003-12-01 00:00:00.001 2 SOME_DB::S1__TT 3 2003-12-01 00:00:00.001 -2 SOME_DB::S2__TT 4 2003-12-01 00:00:00.002 3 SOME_DB::S1__TT 5 2003-12-01 00:00:00.002 -1 SOME_DB::S2__TT
See also
FIND_DB_SYMBOLS OneTick event processor