onetick-py 1.177.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. locator_parser/__init__.py +0 -0
  2. locator_parser/acl.py +73 -0
  3. locator_parser/actions.py +262 -0
  4. locator_parser/common.py +368 -0
  5. locator_parser/io.py +43 -0
  6. locator_parser/locator.py +150 -0
  7. onetick/__init__.py +101 -0
  8. onetick/doc_utilities/__init__.py +3 -0
  9. onetick/doc_utilities/napoleon.py +40 -0
  10. onetick/doc_utilities/ot_doctest.py +140 -0
  11. onetick/doc_utilities/snippets.py +279 -0
  12. onetick/lib/__init__.py +4 -0
  13. onetick/lib/instance.py +141 -0
  14. onetick/py/__init__.py +293 -0
  15. onetick/py/_stack_info.py +89 -0
  16. onetick/py/_version.py +2 -0
  17. onetick/py/aggregations/__init__.py +11 -0
  18. onetick/py/aggregations/_base.py +648 -0
  19. onetick/py/aggregations/_docs.py +948 -0
  20. onetick/py/aggregations/compute.py +286 -0
  21. onetick/py/aggregations/functions.py +2216 -0
  22. onetick/py/aggregations/generic.py +104 -0
  23. onetick/py/aggregations/high_low.py +80 -0
  24. onetick/py/aggregations/num_distinct.py +83 -0
  25. onetick/py/aggregations/order_book.py +501 -0
  26. onetick/py/aggregations/other.py +1014 -0
  27. onetick/py/backports.py +26 -0
  28. onetick/py/cache.py +374 -0
  29. onetick/py/callback/__init__.py +5 -0
  30. onetick/py/callback/callback.py +276 -0
  31. onetick/py/callback/callbacks.py +131 -0
  32. onetick/py/compatibility.py +798 -0
  33. onetick/py/configuration.py +771 -0
  34. onetick/py/core/__init__.py +0 -0
  35. onetick/py/core/_csv_inspector.py +93 -0
  36. onetick/py/core/_internal/__init__.py +0 -0
  37. onetick/py/core/_internal/_manually_bound_value.py +6 -0
  38. onetick/py/core/_internal/_nodes_history.py +250 -0
  39. onetick/py/core/_internal/_op_utils/__init__.py +0 -0
  40. onetick/py/core/_internal/_op_utils/every_operand.py +9 -0
  41. onetick/py/core/_internal/_op_utils/is_const.py +10 -0
  42. onetick/py/core/_internal/_per_tick_scripts/tick_list_sort_template.script +121 -0
  43. onetick/py/core/_internal/_proxy_node.py +140 -0
  44. onetick/py/core/_internal/_state_objects.py +2312 -0
  45. onetick/py/core/_internal/_state_vars.py +93 -0
  46. onetick/py/core/_source/__init__.py +0 -0
  47. onetick/py/core/_source/_symbol_param.py +95 -0
  48. onetick/py/core/_source/schema.py +97 -0
  49. onetick/py/core/_source/source_methods/__init__.py +0 -0
  50. onetick/py/core/_source/source_methods/aggregations.py +809 -0
  51. onetick/py/core/_source/source_methods/applyers.py +296 -0
  52. onetick/py/core/_source/source_methods/columns.py +141 -0
  53. onetick/py/core/_source/source_methods/data_quality.py +301 -0
  54. onetick/py/core/_source/source_methods/debugs.py +272 -0
  55. onetick/py/core/_source/source_methods/drops.py +120 -0
  56. onetick/py/core/_source/source_methods/fields.py +619 -0
  57. onetick/py/core/_source/source_methods/filters.py +1002 -0
  58. onetick/py/core/_source/source_methods/joins.py +1413 -0
  59. onetick/py/core/_source/source_methods/merges.py +605 -0
  60. onetick/py/core/_source/source_methods/misc.py +1455 -0
  61. onetick/py/core/_source/source_methods/pandases.py +155 -0
  62. onetick/py/core/_source/source_methods/renames.py +356 -0
  63. onetick/py/core/_source/source_methods/sorts.py +183 -0
  64. onetick/py/core/_source/source_methods/switches.py +142 -0
  65. onetick/py/core/_source/source_methods/symbols.py +117 -0
  66. onetick/py/core/_source/source_methods/times.py +627 -0
  67. onetick/py/core/_source/source_methods/writes.py +986 -0
  68. onetick/py/core/_source/symbol.py +205 -0
  69. onetick/py/core/_source/tmp_otq.py +222 -0
  70. onetick/py/core/column.py +209 -0
  71. onetick/py/core/column_operations/__init__.py +0 -0
  72. onetick/py/core/column_operations/_methods/__init__.py +4 -0
  73. onetick/py/core/column_operations/_methods/_internal.py +28 -0
  74. onetick/py/core/column_operations/_methods/conversions.py +216 -0
  75. onetick/py/core/column_operations/_methods/methods.py +292 -0
  76. onetick/py/core/column_operations/_methods/op_types.py +160 -0
  77. onetick/py/core/column_operations/accessors/__init__.py +0 -0
  78. onetick/py/core/column_operations/accessors/_accessor.py +28 -0
  79. onetick/py/core/column_operations/accessors/decimal_accessor.py +104 -0
  80. onetick/py/core/column_operations/accessors/dt_accessor.py +537 -0
  81. onetick/py/core/column_operations/accessors/float_accessor.py +184 -0
  82. onetick/py/core/column_operations/accessors/str_accessor.py +1367 -0
  83. onetick/py/core/column_operations/base.py +1121 -0
  84. onetick/py/core/cut_builder.py +150 -0
  85. onetick/py/core/db_constants.py +20 -0
  86. onetick/py/core/eval_query.py +245 -0
  87. onetick/py/core/lambda_object.py +441 -0
  88. onetick/py/core/multi_output_source.py +232 -0
  89. onetick/py/core/per_tick_script.py +2256 -0
  90. onetick/py/core/query_inspector.py +464 -0
  91. onetick/py/core/source.py +1744 -0
  92. onetick/py/db/__init__.py +2 -0
  93. onetick/py/db/_inspection.py +1128 -0
  94. onetick/py/db/db.py +1327 -0
  95. onetick/py/db/utils.py +64 -0
  96. onetick/py/docs/__init__.py +0 -0
  97. onetick/py/docs/docstring_parser.py +112 -0
  98. onetick/py/docs/utils.py +81 -0
  99. onetick/py/functions.py +2398 -0
  100. onetick/py/license.py +190 -0
  101. onetick/py/log.py +88 -0
  102. onetick/py/math.py +935 -0
  103. onetick/py/misc.py +470 -0
  104. onetick/py/oqd/__init__.py +22 -0
  105. onetick/py/oqd/eps.py +1195 -0
  106. onetick/py/oqd/sources.py +325 -0
  107. onetick/py/otq.py +216 -0
  108. onetick/py/pyomd_mock.py +47 -0
  109. onetick/py/run.py +916 -0
  110. onetick/py/servers.py +173 -0
  111. onetick/py/session.py +1347 -0
  112. onetick/py/sources/__init__.py +19 -0
  113. onetick/py/sources/cache.py +167 -0
  114. onetick/py/sources/common.py +128 -0
  115. onetick/py/sources/csv.py +642 -0
  116. onetick/py/sources/custom.py +85 -0
  117. onetick/py/sources/data_file.py +305 -0
  118. onetick/py/sources/data_source.py +1045 -0
  119. onetick/py/sources/empty.py +94 -0
  120. onetick/py/sources/odbc.py +337 -0
  121. onetick/py/sources/order_book.py +271 -0
  122. onetick/py/sources/parquet.py +168 -0
  123. onetick/py/sources/pit.py +191 -0
  124. onetick/py/sources/query.py +495 -0
  125. onetick/py/sources/snapshots.py +419 -0
  126. onetick/py/sources/split_query_output_by_symbol.py +198 -0
  127. onetick/py/sources/symbology_mapping.py +123 -0
  128. onetick/py/sources/symbols.py +374 -0
  129. onetick/py/sources/ticks.py +825 -0
  130. onetick/py/sql.py +70 -0
  131. onetick/py/state.py +251 -0
  132. onetick/py/types.py +2131 -0
  133. onetick/py/utils/__init__.py +70 -0
  134. onetick/py/utils/acl.py +93 -0
  135. onetick/py/utils/config.py +186 -0
  136. onetick/py/utils/default.py +49 -0
  137. onetick/py/utils/file.py +38 -0
  138. onetick/py/utils/helpers.py +76 -0
  139. onetick/py/utils/locator.py +94 -0
  140. onetick/py/utils/perf.py +498 -0
  141. onetick/py/utils/query.py +49 -0
  142. onetick/py/utils/render.py +1374 -0
  143. onetick/py/utils/script.py +244 -0
  144. onetick/py/utils/temp.py +471 -0
  145. onetick/py/utils/types.py +120 -0
  146. onetick/py/utils/tz.py +84 -0
  147. onetick_py-1.177.0.dist-info/METADATA +137 -0
  148. onetick_py-1.177.0.dist-info/RECORD +152 -0
  149. onetick_py-1.177.0.dist-info/WHEEL +5 -0
  150. onetick_py-1.177.0.dist-info/entry_points.txt +2 -0
  151. onetick_py-1.177.0.dist-info/licenses/LICENSE +21 -0
  152. onetick_py-1.177.0.dist-info/top_level.txt +2 -0
@@ -0,0 +1,123 @@
1
+ from typing import Optional
2
+
3
+ import onetick.py as otp
4
+ from onetick.py.otq import otq
5
+
6
+ from onetick.py.core.source import Source
7
+ from onetick.py.core.column_operations.base import OnetickParameter
8
+
9
+ from .. import types as ott
10
+ from .. import utils
11
+
12
+ from .common import update_node_tick_type, AdaptiveTickType
13
+
14
+
15
+ class SymbologyMapping(Source):
16
+ _PROPERTIES = Source._PROPERTIES + ["_p_dest_symbology"]
17
+
18
+ def __init__(
19
+ self,
20
+ dest_symbology: Optional[str] = None,
21
+ tick_type: Optional[AdaptiveTickType] = utils.adaptive,
22
+ start=utils.adaptive,
23
+ end=utils.adaptive,
24
+ symbols=utils.adaptive,
25
+ schema=None,
26
+ **kwargs,
27
+ ):
28
+ """
29
+ Shows symbology mapping information for specified securities stored in the reference database.
30
+
31
+ Input (source) symbology is taken from the input symbol,
32
+ if it has a symbology part in it (e.g., RIC::REUTERS::MSFT),
33
+ or defaults to that of the input database, which is specified in the locator file.
34
+
35
+ Parameter ``symbol_date`` must be set in :py:func:`otp.run <onetick.py.run>`
36
+ for this source to work.
37
+
38
+ Parameters
39
+ ----------
40
+ dest_symbology: str, :py:class:`otp.param <onetick.py.core.column_operations.base.OnetickParameter>`
41
+ Specifying the destination symbology for symbol translation.
42
+ tick_type: str
43
+ Tick type to set on the OneTick's graph node.
44
+ Can be used to specify database name with tick type or tick type only.
45
+
46
+ By default setting this parameter is not required, database is usually set
47
+ with parameter ``symbols`` or in :py:func:`otp.run <onetick.py.run>`.
48
+ start:
49
+ Custom start time of the source.
50
+ If set, will override the value specified in :py:func:`otp.run <onetick.py.run>`.
51
+ end:
52
+ Custom end time of the source.
53
+ If set, will override the value specified in :py:func:`otp.run <onetick.py.run>`.
54
+ symbols:
55
+ Symbol(s) from which data should be taken.
56
+ If set, will override the value specified in :py:func:`otp.run <onetick.py.run>`.
57
+
58
+ Examples
59
+ --------
60
+
61
+ Getting mapping for OID symbology for one symbol:
62
+
63
+ >>> data = otp.SymbologyMapping(dest_symbology='OID')
64
+ >>> otp.run(data, symbols='US_COMP::AAPL', # doctest: +SKIP
65
+ ... symbol_date=otp.dt(2022, 1, 3),
66
+ ... date=otp.dt(2022, 1, 3))
67
+ Time END_DATETIME MAPPED_SYMBOL_NAME
68
+ 0 2022-01-03 2022-01-04 9706
69
+
70
+ Getting mapping for all symbols in `US_COMP` database in single source:
71
+
72
+ >>> data = otp.SymbologyMapping(dest_symbology='OID')
73
+ >>> data = otp.merge([data],
74
+ ... symbols=otp.Symbols('US_COMP', keep_db=True),
75
+ ... identify_input_ts=True)
76
+ >>> data = data[['SYMBOL_NAME', 'MAPPED_SYMBOL_NAME']]
77
+ >>> otp.run(data, # doctest: +SKIP
78
+ ... symbol_date=otp.dt(2022, 1, 3),
79
+ ... date=otp.dt(2022, 1, 3))
80
+ Time SYMBOL_NAME MAPPED_SYMBOL_NAME
81
+ 0 2022-01-03 US_COMP::A 3751
82
+ 1 2022-01-03 US_COMP::AA 647321
83
+ 2 2022-01-03 US_COMP::AAA 695581
84
+ 3 2022-01-03 US_COMP::AAAU 673522
85
+ 4 2022-01-03 US_COMP::AAC 703090
86
+ ... ... ... ...
87
+ 11746 2022-01-03 US_COMP::ZWS 273584
88
+ 11747 2022-01-03 US_COMP::ZY 704054
89
+ 11748 2022-01-03 US_COMP::ZYME 655470
90
+ 11749 2022-01-03 US_COMP::ZYNE 633589
91
+ 11750 2022-01-03 US_COMP::ZYXI 208375
92
+ """
93
+ if self._try_default_constructor(schema=schema, **kwargs):
94
+ return
95
+
96
+ if dest_symbology is None:
97
+ raise TypeError("Missing required argument: 'dest_symbology'")
98
+
99
+ if isinstance(dest_symbology, OnetickParameter):
100
+ dest_symbology = dest_symbology.parameter_expression
101
+
102
+ self._p_dest_symbology = dest_symbology
103
+
104
+ super().__init__(
105
+ _symbols=symbols,
106
+ _start=start,
107
+ _end=end,
108
+ _base_ep_func=lambda: self.base_ep(dest_symbology, tick_type),
109
+ schema=schema,
110
+ **kwargs,
111
+ )
112
+
113
+ self.schema['MAPPED_SYMBOL_NAME'] = str
114
+ self.schema['END_DATETIME'] = ott.nsectime
115
+
116
+ @property
117
+ def dest_symbology(self):
118
+ return self._p_dest_symbology
119
+
120
+ def base_ep(self, dest_symbology, tick_type):
121
+ src = Source(otq.SymbologyMapping(dest_symbology=dest_symbology))
122
+ update_node_tick_type(src, tick_type)
123
+ return src
@@ -0,0 +1,374 @@
1
+ import warnings
2
+
3
+ import onetick.py as otp
4
+ from onetick.py.otq import otq
5
+
6
+ from onetick.py.core.source import Source
7
+ from onetick.py.core.column_operations.base import Raw, OnetickParameter
8
+ from onetick.py.core.eval_query import _QueryEvalWrapper
9
+ from onetick.py.core._source.tmp_otq import TmpOtq
10
+ from onetick.py.compatibility import is_symbols_prepend_db_name_supported
11
+
12
+ from .. import types as ott
13
+ from .. import utils
14
+
15
+ from .common import update_node_tick_type
16
+
17
+
18
+ class Symbols(Source):
19
+ """
20
+ Construct a source that returns ticks with information about symbols in a database.
21
+ The SYMBOL_NAME field is populated with symbol names. The TICK_TYPE field contains
22
+ corresponding tick type (enabled by the ``show_tick_type`` parameter).
23
+
24
+ Parameters
25
+ ----------
26
+ db: str, :py:func:`eval query <onetick.py.eval>`
27
+ Name of the database where to search symbols.
28
+ By default the database used by :py:func:`otp.run <onetick.py.run>` will be inherited.
29
+ keep_db: bool
30
+ Flag that indicates whether symbols should have a db prefix.
31
+ pattern: str
32
+ Usual and special characters can be used to search for symbols.
33
+ Special characters are:
34
+
35
+ * ``%`` - any number of any characters (zero too)
36
+ * ``_`` - any single character
37
+ * ``\\`` - used to escape special characters
38
+
39
+ For example, if you want symbol name starting with ``NQ``, you should write ``NQ%``.
40
+ If you want symbol name to contain literal ``%`` character, you should write ``NQ\\%``.
41
+ ``\\`` is a special character too, so it need to be escaped too
42
+ if you want symbol name to contain literal backslash, e.g. ``NQ\\\\M23``.
43
+ Default is ``%``.
44
+
45
+ for_tick_type: str
46
+ Fetch only symbols belong to this tick type, if specified.
47
+ Otherwise fetch symbols for all tick types.
48
+ show_tick_type: bool
49
+ Add the **TICK_TYPE** column with the information about tick type
50
+ symbology: str
51
+ The destination symbology for a symbol name translation.
52
+ Translation is performed, if destination symbology is not empty
53
+ and is different from that of the queried database.
54
+ show_original_symbols: bool
55
+ Switches original symbol name propagation as a tick field ORIGINAL_SYMBOL_NAME
56
+ if symbol name translation is performed (if `symbology` is set).
57
+ Note that if this parameter is set to True,
58
+ database symbols with missing translations are also propagated.
59
+ discard_on_match: bool
60
+ If True, then parameter ``pattern`` filters out symbols to return from the database.
61
+ cep_method: str
62
+ The method to be used for extracting database symbols in CEP mode.
63
+ Possible values are:
64
+
65
+ * *use_db*: symbols will be extracted from the database with intervals
66
+ specified by the ``poll_frequency`` parameter, and new symbols will be output.
67
+ * *use_cep_adapter*: CEP adapter will be used to retrieve and propagate the symbols with every heartbeat.
68
+ * Default: None, the EP will work the same way as for historical queries,
69
+ i.e. will query the database for symbols once.
70
+ poll_frequency: int
71
+ Specifies the time interval in *minutes* to check the database for new symbols.
72
+ This parameter can be specified only if ``cep_method`` is set to *use_db*.
73
+ The minimum value is 1 minute.
74
+ symbols_to_return: str
75
+ Indicates whether all symbols must be returned or only those which are in the query time range.
76
+ Possible values are:
77
+
78
+ * *all_in_db*: All symbols are returned.
79
+ * *with_tick_in_query_range*: Only the symbols which have ticks in the query time range are returned.
80
+ This option is allowed only when ``cep_method`` is set to *use_cep_adapter*.
81
+
82
+ _tick_type: str
83
+ Custom tick type for the node of the graph.
84
+ By default "ANY" tick type will be set.
85
+ tick_type: str
86
+ .. attention::
87
+
88
+ This parameter is deprecated, use parameter ``_tick_type`` instead.
89
+ Do not confuse this parameter with ``for_tick_type``.
90
+ This parameter is used for low-level customization of OneTick graph nodes and is rarely needed.
91
+
92
+ start: :py:class:`datetime.datetime`, :py:class:`otp.datetime <onetick.py.datetime>`
93
+ Custom start time of the query.
94
+ By default the start time used by :py:func:`otp.run <onetick.py.run>` will be inherited.
95
+ end: :py:class:`datetime.datetime`, :py:class:`otp.datetime <onetick.py.datetime>`
96
+ Custom end time of the query.
97
+ By default the start time used by :py:func:`otp.run <onetick.py.run>` will be inherited.
98
+ date: :py:class:`datetime.date`
99
+ Alternative way of setting instead of ``start``/``end`` times.
100
+
101
+
102
+ Note
103
+ ----
104
+ Additional fields that can be added to Symbols will be converted to symbol parameters
105
+
106
+ See also
107
+ --------
108
+ | :ref:`Symbols guide <static/concepts/symbols:Symbols: bound and unbound>`
109
+ | **FIND_DB_SYMBOLS** OneTick event processor
110
+
111
+ Examples
112
+ --------
113
+
114
+ This class can be used to get a list of all symbols in the database:
115
+
116
+ >>> symbols = otp.Symbols('US_COMP', date=otp.dt(2022, 3, 1))
117
+ >>> otp.run(symbols)
118
+ Time SYMBOL_NAME
119
+ 0 2022-03-01 AAP
120
+ 1 2022-03-01 AAPL
121
+
122
+ By default database name and time interval will be inherited from :py:func:`otp.run <onetick.py.run>`:
123
+
124
+ >>> data = otp.Symbols()
125
+ >>> otp.run(data, symbols='US_COMP::', date=otp.dt(2022, 3, 1))
126
+ Time SYMBOL_NAME
127
+ 0 2022-03-01 AAP
128
+ 1 2022-03-01 AAPL
129
+
130
+ Parameter ``keep_db`` can be used to show database name in a SYMBOL_NAME field.
131
+ It is useful when querying symbols for many databases:
132
+
133
+ >>> data = otp.Symbols(keep_db=True)
134
+ >>> data = otp.merge([data], symbols=['SOME_DB::', 'SOME_DB_2::'])
135
+ >>> otp.run(data, date=otp.config.default_start_time) # doctest: +ELLIPSIS
136
+ Time SYMBOL_NAME
137
+ 0 2003-12-01 SOME_DB::S1
138
+ 1 2003-12-01 SOME_DB::S2
139
+ 2 2003-12-01 SOME_DB_2::S1
140
+ 3 2003-12-01 SOME_DB_2::S2
141
+
142
+ By default symbols for all tick types are returned.
143
+ You can set parameter ``show_tick_type`` to print the tick type for each symbol:
144
+
145
+ >>> symbols = otp.Symbols('US_COMP', show_tick_type=True)
146
+ >>> otp.run(symbols, date=otp.dt(2022, 3, 1))
147
+ Time SYMBOL_NAME TICK_TYPE
148
+ 0 2022-03-01 AAP TRD
149
+ 1 2022-03-01 AAPL QTE
150
+ 2 2022-03-01 AAPL TRD
151
+
152
+ Parameter ``for_tick_type`` can be used to specify a single tick type for which to return symbols:
153
+
154
+ >>> symbols = otp.Symbols('US_COMP', show_tick_type=True, for_tick_type='TRD')
155
+ >>> otp.run(symbols, date=otp.dt(2022, 3, 1))
156
+ Time SYMBOL_NAME TICK_TYPE
157
+ 0 2022-03-01 AAP TRD
158
+ 1 2022-03-01 AAPL TRD
159
+
160
+ Parameter ``pattern`` can be used to specify the pattern to filter symbol names:
161
+
162
+ >>> symbols = otp.Symbols('US_COMP', show_tick_type=True, for_tick_type='TRD', pattern='AAP_')
163
+ >>> otp.run(symbols, date=otp.dt(2022, 3, 1))
164
+ Time SYMBOL_NAME TICK_TYPE
165
+ 0 2022-03-01 AAPL TRD
166
+
167
+ Parameter ``discard_on_match`` can be used to use ``pattern`` to filter out symbols instead:
168
+
169
+ >>> symbols = otp.Symbols('US_COMP', show_tick_type=True, for_tick_type='TRD',
170
+ ... pattern='AAP_', discard_on_match=True)
171
+ >>> otp.run(symbols, date=otp.dt(2022, 3, 1))
172
+ Time SYMBOL_NAME TICK_TYPE
173
+ 0 2022-03-01 AAP TRD
174
+
175
+ ``otp.Symbols`` object can be used to specify symbols for the main query:
176
+
177
+ >>> symbols = otp.Symbols('US_COMP')
178
+ >>> data = otp.DataSource('US_COMP', tick_type='TRD')
179
+ >>> result = otp.run(data, symbols=symbols, date=otp.dt(2022, 3, 1))
180
+ >>> result['AAPL']
181
+ Time PRICE SIZE
182
+ 0 2022-03-01 00:00:00.000 1.3 100
183
+ 1 2022-03-01 00:00:00.001 1.4 10
184
+ 2 2022-03-01 00:00:00.002 1.4 50
185
+ >>> result['AAP']
186
+ Time PRICE
187
+ 0 2022-03-01 00:00:00.000 45.37
188
+ 1 2022-03-01 00:00:00.001 45.41
189
+
190
+ Additional fields of the ``otp.Symbols`` can be used in the main query as symbol parameters:
191
+
192
+ >>> symbols = otp.Symbols('SOME_DB', show_tick_type=True, keep_db=True)
193
+ >>> symbols['PARAM'] = symbols['SYMBOL_NAME'] + '__' + symbols['TICK_TYPE']
194
+ >>> data = otp.DataSource('SOME_DB')
195
+ >>> data['S_PARAM'] = data.Symbol['PARAM', str]
196
+ >>> data = otp.merge([data], symbols=symbols)
197
+ >>> otp.run(data)
198
+ Time X S_PARAM
199
+ 0 2003-12-01 00:00:00.000 1 SOME_DB::S1__TT
200
+ 1 2003-12-01 00:00:00.000 -3 SOME_DB::S2__TT
201
+ 2 2003-12-01 00:00:00.001 2 SOME_DB::S1__TT
202
+ 3 2003-12-01 00:00:00.001 -2 SOME_DB::S2__TT
203
+ 4 2003-12-01 00:00:00.002 3 SOME_DB::S1__TT
204
+ 5 2003-12-01 00:00:00.002 -1 SOME_DB::S2__TT
205
+
206
+ **Escaping special characters in the pattern**
207
+
208
+ When using patterns with special character, be aware that python strings ``\\`` is a special character too
209
+ and need to be escaped as well:
210
+
211
+ >>> print('back\\\\slash')
212
+ back\\slash
213
+
214
+ Pattern ``NQ\\\\M23`` in python should be written as ``NQ\\\\\\\\M23``:
215
+
216
+ >>> print('NQ\\\\\\\\M23')
217
+ NQ\\\\M23
218
+
219
+ Escaping character ``\\`` in python can be avoided with raw strings:
220
+
221
+ >>> print(r'NQ\\\\M23')
222
+ NQ\\\\M23
223
+ """
224
+
225
+ _PROPERTIES = Source._PROPERTIES + ["_p_db",
226
+ "_p_pattern",
227
+ "_p_start",
228
+ "_p_end",
229
+ "_p_for_tick_type",
230
+ "_p_keep_db"]
231
+
232
+ def __init__(
233
+ self,
234
+ db=None,
235
+ find_params=None,
236
+ keep_db=False,
237
+ pattern='%',
238
+ for_tick_type=None,
239
+ show_tick_type=False,
240
+ symbology='',
241
+ show_original_symbols=False,
242
+ discard_on_match=None,
243
+ cep_method=None,
244
+ poll_frequency=None,
245
+ symbols_to_return=None,
246
+ tick_type=utils.adaptive,
247
+ _tick_type=utils.adaptive,
248
+ start=utils.adaptive,
249
+ end=utils.adaptive,
250
+ date=None,
251
+ schema=None,
252
+ **kwargs,
253
+ ):
254
+ if self._try_default_constructor(schema=schema, **kwargs):
255
+ return
256
+
257
+ if isinstance(pattern, OnetickParameter):
258
+ pattern = pattern.parameter_expression
259
+
260
+ self._p_db = db
261
+ self._p_pattern = pattern
262
+ self._p_start = start
263
+ self._p_end = end
264
+ self._p_keep_db = keep_db
265
+ self._p_for_tick_type = for_tick_type
266
+
267
+ if tick_type is not utils.adaptive:
268
+ warnings.warn("In otp.Symbols parameter 'tick_type' is deprecated."
269
+ " Previously it was incorrectly interpreted by users as a tick type"
270
+ " for which symbols in the database will be searched."
271
+ " Instead right now it sets a tick type for a node in OneTick graph "
272
+ " (this results in symbols from all tick types returned from this source)."
273
+ " Use parameter 'for_tick_type' to find the symbols for a particular tick type"
274
+ " and use parameter '_tick_type' if you want set a tick type for a node in OneTick graph.",
275
+ FutureWarning, stacklevel=2)
276
+
277
+ if date and isinstance(date, (ott.datetime, ott.date)):
278
+ start = date.start
279
+ end = date.end
280
+
281
+ _symbol = utils.adaptive
282
+ _tmp_otq = None
283
+ if db:
284
+ if isinstance(db, list):
285
+ _symbol = [f"{str(_db).split(':')[0]}::" for _db in db] # noqa
286
+ elif isinstance(db, _QueryEvalWrapper):
287
+ _tmp_otq = TmpOtq()
288
+ _symbol = db.to_eval_string(tmp_otq=_tmp_otq)
289
+ else:
290
+ _symbol = f"{str(db).split(':')[0]}::" # noqa
291
+
292
+ if find_params is not None:
293
+ warnings.warn("In otp.Symbols parameter 'find_params' is deprecated."
294
+ " Use named parameters instead.",
295
+ FutureWarning, stacklevel=2)
296
+
297
+ _find_params = find_params if find_params is not None else {}
298
+
299
+ _find_params.setdefault('pattern', pattern)
300
+ if for_tick_type:
301
+ _find_params['tick_type_field'] = for_tick_type
302
+ _find_params.setdefault('show_tick_type', show_tick_type)
303
+
304
+ _find_params.setdefault('symbology', symbology)
305
+ _find_params.setdefault('show_original_symbols', show_original_symbols)
306
+
307
+ if 'prepend_db_name' in _find_params:
308
+ raise ValueError('Use parameter `keep_db` instead of passing `prepend_db_name` in `find_params`')
309
+
310
+ if discard_on_match is not None:
311
+ _find_params.setdefault('discard_on_match', discard_on_match)
312
+ if cep_method is not None:
313
+ if not isinstance(cep_method, str) or cep_method not in ('use_cep_adapter', 'use_db'):
314
+ raise ValueError(f"Wrong value for parameter 'cep_method': {cep_method}")
315
+ _find_params.setdefault('cep_method', cep_method.upper())
316
+ if poll_frequency is not None:
317
+ _find_params.setdefault('poll_frequency', poll_frequency)
318
+ if symbols_to_return is not None:
319
+ if not isinstance(symbols_to_return, str) or symbols_to_return not in ('all_in_db',
320
+ 'with_ticks_in_query_range'):
321
+ raise ValueError(f"Wrong value for parameter 'symbols_to_return': {symbols_to_return}")
322
+ _find_params.setdefault('symbols_to_return', symbols_to_return.upper())
323
+
324
+ if tick_type is not utils.adaptive and _tick_type is not utils.adaptive:
325
+ raise ValueError("Parameters 'tick_type' and '_tick_type' can't be set simultaneously")
326
+ elif tick_type is not utils.adaptive:
327
+ ep_tick_type = tick_type
328
+ elif _tick_type is not utils.adaptive:
329
+ ep_tick_type = _tick_type
330
+ else:
331
+ ep_tick_type = utils.adaptive
332
+
333
+ super().__init__(
334
+ _symbols=_symbol,
335
+ _start=start,
336
+ _end=end,
337
+ _base_ep_func=lambda: self.base_ep(ep_tick_type=ep_tick_type,
338
+ keep_db=keep_db, **_find_params),
339
+ )
340
+
341
+ self.schema['SYMBOL_NAME'] = str
342
+
343
+ if _find_params['show_tick_type']:
344
+ self.schema['TICK_TYPE'] = str
345
+
346
+ if _find_params['symbology'] and _find_params['show_original_symbols']:
347
+ self.schema['ORIGINAL_SYMBOL_NAME'] = str
348
+
349
+ if _tmp_otq:
350
+ self._tmp_otq.merge(_tmp_otq)
351
+
352
+ def base_ep(self, ep_tick_type, keep_db, **params):
353
+ use_prepend_db_name = is_symbols_prepend_db_name_supported()
354
+ if use_prepend_db_name and not keep_db:
355
+ params['prepend_db_name'] = False
356
+
357
+ src = Source(otq.FindDbSymbols(**params))
358
+
359
+ update_node_tick_type(src, ep_tick_type)
360
+ src.schema['SYMBOL_NAME'] = str
361
+
362
+ if not keep_db and not use_prepend_db_name:
363
+ src["SYMBOL_NAME"] = src["SYMBOL_NAME"].str.regex_replace('.*::', '')
364
+
365
+ return src
366
+
367
+ @staticmethod
368
+ def duplicate(obj, db=None):
369
+ return Symbols(db=obj._p_db if db is None else db,
370
+ pattern=obj._p_pattern,
371
+ start=obj._p_start,
372
+ end=obj._p_end,
373
+ keep_db=obj._p_keep_db,
374
+ for_tick_type=obj._p_for_tick_type)