Source code for onetick.py.core._source.symbol

from onetick.py.core._source._symbol_param_column import _SymbolParamColumn


[docs]class SymbolType: def __init__(self): """ You can get symbol name and symbol parameters with this class. Examples -------- >>> symbols = otp.Symbols('SOME_DB') >>> symbols['PARAM'] = 'PAM' >>> ticks = otp.DataSource('SOME_DB', tick_type='TT') >>> ticks['SYMBOL_PARAM'] = ticks.Symbol.PARAM >>> ticks['SYMBOL_NAME'] = ticks.Symbol.name >>> ticks = otp.merge([ticks], symbols=symbols) >>> ticks() Time X SYMBOL_PARAM SYMBOL_NAME 0 2003-12-01 00:00:00.000 1 PAM S1 1 2003-12-01 00:00:00.000 -3 PAM S2 2 2003-12-01 00:00:00.001 2 PAM S1 3 2003-12-01 00:00:00.001 -2 PAM S2 4 2003-12-01 00:00:00.002 3 PAM S1 5 2003-12-01 00:00:00.002 -1 PAM S2 See also -------- | :ref:`Databases, symbols, and tick types <symbols_concept>` | :ref:`Symbol Parameters Objects` """ self._name = _SymbolParamColumn("_SYMBOL_NAME", str) @property def name(self): """ Get symbol name. Returns ------- _SymbolParamColumn Examples -------- >>> symbols = otp.Symbols('SOME_DB') >>> ticks = otp.DataSource('SOME_DB', tick_type='TT') >>> ticks['SYMBOL_NAME'] = ticks.Symbol.name >>> ticks = otp.merge([ticks], symbols=symbols) >>> ticks() Time X SYMBOL_NAME 0 2003-12-01 00:00:00.000 1 S1 1 2003-12-01 00:00:00.000 -3 S2 2 2003-12-01 00:00:00.001 2 S1 3 2003-12-01 00:00:00.001 -2 S2 4 2003-12-01 00:00:00.002 3 S1 5 2003-12-01 00:00:00.002 -1 S2 """ return self._name
[docs] def __getattr__(self, item): """ Get symbol parameter by name. Returns ------- _SymbolParamColumn Examples -------- >>> symbols = otp.Symbols('SOME_DB') >>> symbols['PARAM'] = 'PAM' >>> ticks = otp.DataSource('SOME_DB', tick_type='TT') >>> ticks['SYMBOL_PARAM'] = ticks.Symbol.PARAM >>> ticks = otp.merge([ticks], symbols=symbols) >>> ticks() Time X SYMBOL_PARAM 0 2003-12-01 00:00:00.000 1 PAM 1 2003-12-01 00:00:00.000 -3 PAM 2 2003-12-01 00:00:00.001 2 PAM 3 2003-12-01 00:00:00.001 -2 PAM 4 2003-12-01 00:00:00.002 3 PAM 5 2003-12-01 00:00:00.002 -1 PAM """ return _SymbolParamColumn(f"_SYMBOL_PARAM.{item}", str)
Symbol = SymbolType() # noqa mypy fix