onetick-py 1.162.2__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 +266 -0
  4. locator_parser/common.py +365 -0
  5. locator_parser/io.py +41 -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 +280 -0
  12. onetick/lib/__init__.py +4 -0
  13. onetick/lib/instance.py +138 -0
  14. onetick/py/__init__.py +290 -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 +645 -0
  19. onetick/py/aggregations/_docs.py +912 -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 +427 -0
  26. onetick/py/aggregations/other.py +1014 -0
  27. onetick/py/backports.py +26 -0
  28. onetick/py/cache.py +373 -0
  29. onetick/py/callback/__init__.py +5 -0
  30. onetick/py/callback/callback.py +275 -0
  31. onetick/py/callback/callbacks.py +131 -0
  32. onetick/py/compatibility.py +752 -0
  33. onetick/py/configuration.py +736 -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 +2307 -0
  45. onetick/py/core/_internal/_state_vars.py +87 -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 +810 -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 +270 -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 +1001 -0
  58. onetick/py/core/_source/source_methods/joins.py +1393 -0
  59. onetick/py/core/_source/source_methods/merges.py +566 -0
  60. onetick/py/core/_source/source_methods/misc.py +1325 -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 +702 -0
  68. onetick/py/core/_source/symbol.py +202 -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 +215 -0
  75. onetick/py/core/column_operations/_methods/methods.py +294 -0
  76. onetick/py/core/column_operations/_methods/op_types.py +150 -0
  77. onetick/py/core/column_operations/accessors/__init__.py +0 -0
  78. onetick/py/core/column_operations/accessors/_accessor.py +30 -0
  79. onetick/py/core/column_operations/accessors/decimal_accessor.py +92 -0
  80. onetick/py/core/column_operations/accessors/dt_accessor.py +464 -0
  81. onetick/py/core/column_operations/accessors/float_accessor.py +160 -0
  82. onetick/py/core/column_operations/accessors/str_accessor.py +1374 -0
  83. onetick/py/core/column_operations/base.py +1061 -0
  84. onetick/py/core/cut_builder.py +149 -0
  85. onetick/py/core/db_constants.py +20 -0
  86. onetick/py/core/eval_query.py +244 -0
  87. onetick/py/core/lambda_object.py +442 -0
  88. onetick/py/core/multi_output_source.py +193 -0
  89. onetick/py/core/per_tick_script.py +2253 -0
  90. onetick/py/core/query_inspector.py +465 -0
  91. onetick/py/core/source.py +1663 -0
  92. onetick/py/db/__init__.py +2 -0
  93. onetick/py/db/_inspection.py +1042 -0
  94. onetick/py/db/db.py +1423 -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 +2354 -0
  100. onetick/py/license.py +188 -0
  101. onetick/py/log.py +88 -0
  102. onetick/py/math.py +947 -0
  103. onetick/py/misc.py +437 -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 +211 -0
  108. onetick/py/pyomd_mock.py +47 -0
  109. onetick/py/run.py +841 -0
  110. onetick/py/servers.py +173 -0
  111. onetick/py/session.py +1342 -0
  112. onetick/py/sources/__init__.py +19 -0
  113. onetick/py/sources/cache.py +167 -0
  114. onetick/py/sources/common.py +126 -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 +1049 -0
  119. onetick/py/sources/empty.py +94 -0
  120. onetick/py/sources/odbc.py +337 -0
  121. onetick/py/sources/order_book.py +238 -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 +357 -0
  129. onetick/py/sources/ticks.py +825 -0
  130. onetick/py/sql.py +70 -0
  131. onetick/py/state.py +256 -0
  132. onetick/py/types.py +2056 -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 +499 -0
  141. onetick/py/utils/query.py +49 -0
  142. onetick/py/utils/render.py +1139 -0
  143. onetick/py/utils/script.py +244 -0
  144. onetick/py/utils/temp.py +471 -0
  145. onetick/py/utils/types.py +118 -0
  146. onetick/py/utils/tz.py +82 -0
  147. onetick_py-1.162.2.dist-info/METADATA +148 -0
  148. onetick_py-1.162.2.dist-info/RECORD +152 -0
  149. onetick_py-1.162.2.dist-info/WHEEL +5 -0
  150. onetick_py-1.162.2.dist-info/entry_points.txt +2 -0
  151. onetick_py-1.162.2.dist-info/licenses/LICENSE +21 -0
  152. onetick_py-1.162.2.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,357 @@
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
+
9
+ from .. import types as ott
10
+ from .. import utils
11
+
12
+ from .common import update_node_tick_type
13
+
14
+
15
+ class Symbols(Source):
16
+ """
17
+ Construct a source that returns ticks with information about symbols in a database.
18
+ The SYMBOL_NAME field is populated with symbol names. The TICK_TYPE field contains
19
+ corresponding tick type (enabled by the ``show_tick_type`` parameter).
20
+
21
+ Parameters
22
+ ----------
23
+ db: str
24
+ Name of the database where to search symbols.
25
+ By default the database used by :py:func:`otp.run <onetick.py.run>` will be inherited.
26
+ keep_db: bool
27
+ Flag that indicates whether symbols should have a db prefix.
28
+ pattern: str
29
+ Usual and special characters can be used to search for symbols.
30
+ Special characters are:
31
+
32
+ * ``%`` - any number of any characters (zero too)
33
+ * ``_`` - any single character
34
+ * ``\\`` - used to escape special characters
35
+
36
+ For example, if you want symbol name starting with ``NQ``, you should write ``NQ%``.
37
+ If you want symbol name to contain literal ``%`` character, you should write ``NQ\\%``.
38
+ ``\\`` is a special character too, so it need to be escaped too
39
+ if you want symbol name to contain literal backslash, e.g. ``NQ\\\\M23``.
40
+ Default is ``%``.
41
+
42
+ for_tick_type: str
43
+ Fetch only symbols belong to this tick type, if specified.
44
+ Otherwise fetch symbols for all tick types.
45
+ show_tick_type: bool
46
+ Add the **TICK_TYPE** column with the information about tick type
47
+ symbology: str
48
+ The destination symbology for a symbol name translation.
49
+ Translation is performed, if destination symbology is not empty
50
+ and is different from that of the queried database.
51
+ show_original_symbols: bool
52
+ Switches original symbol name propagation as a tick field ORIGINAL_SYMBOL_NAME
53
+ if symbol name translation is performed (if `symbology` is set).
54
+ Note that if this parameter is set to True,
55
+ database symbols with missing translations are also propagated.
56
+ discard_on_match: bool
57
+ If True, then parameter ``pattern`` filters out symbols to return from the database.
58
+ cep_method: str
59
+ The method to be used for extracting database symbols in CEP mode.
60
+ Possible values are:
61
+
62
+ * *use_db*: symbols will be extracted from the database with intervals
63
+ specified by the ``poll_frequency`` parameter, and new symbols will be output.
64
+ * *use_cep_adapter*: CEP adapter will be used to retrieve and propagate the symbols with every heartbeat.
65
+ * Default: None, the EP will work the same way as for historical queries,
66
+ i.e. will query the database for symbols once.
67
+ poll_frequency: int
68
+ Specifies the time interval in *minutes* to check the database for new symbols.
69
+ This parameter can be specified only if ``cep_method`` is set to *use_db*.
70
+ The minimum value is 1 minute.
71
+ symbols_to_return: str
72
+ Indicates whether all symbols must be returned or only those which are in the query time range.
73
+ Possible values are:
74
+
75
+ * *all_in_db*: All symbols are returned.
76
+ * *with_tick_in_query_range*: Only the symbols which have ticks in the query time range are returned.
77
+ This option is allowed only when ``cep_method`` is set to *use_cep_adapter*.
78
+
79
+ _tick_type: str
80
+ Custom tick type for the node of the graph.
81
+ By default "ANY" tick type will be set.
82
+ tick_type: str
83
+ .. attention::
84
+
85
+ This parameter is deprecated, use parameter ``_tick_type`` instead.
86
+ Do not confuse this parameter with ``for_tick_type``.
87
+ This parameter is used for low-level customization of OneTick graph nodes and is rarely needed.
88
+
89
+ start: :py:class:`datetime.datetime`, :py:class:`otp.datetime <onetick.py.datetime>`
90
+ Custom start time of the query.
91
+ By default the start time used by :py:func:`otp.run <onetick.py.run>` will be inherited.
92
+ end: :py:class:`datetime.datetime`, :py:class:`otp.datetime <onetick.py.datetime>`
93
+ Custom end time of the query.
94
+ By default the start time used by :py:func:`otp.run <onetick.py.run>` will be inherited.
95
+ date: :py:class:`datetime.date`
96
+ Alternative way of setting instead of ``start``/``end`` times.
97
+
98
+
99
+ Note
100
+ ----
101
+ Additional fields that can be added to Symbols will be converted to symbol parameters
102
+
103
+ See also
104
+ --------
105
+ | :ref:`Symbols guide <static/concepts/symbols:Symbols: bound and unbound>`
106
+ | **FIND_DB_SYMBOLS** OneTick event processor
107
+
108
+ Examples
109
+ --------
110
+
111
+ This class can be used to get a list of all symbols in the database:
112
+
113
+ >>> symbols = otp.Symbols('US_COMP', date=otp.dt(2022, 3, 1))
114
+ >>> otp.run(symbols)
115
+ Time SYMBOL_NAME
116
+ 0 2022-03-01 AAP
117
+ 1 2022-03-01 AAPL
118
+
119
+ By default database name and time interval will be inherited from :py:func:`otp.run <onetick.py.run>`:
120
+
121
+ >>> data = otp.Symbols()
122
+ >>> otp.run(data, symbols='US_COMP::', date=otp.dt(2022, 3, 1))
123
+ Time SYMBOL_NAME
124
+ 0 2022-03-01 AAP
125
+ 1 2022-03-01 AAPL
126
+
127
+ Parameter ``keep_db`` can be used to show database name in a SYMBOL_NAME field.
128
+ It is useful when querying symbols for many databases:
129
+
130
+ >>> data = otp.Symbols(keep_db=True)
131
+ >>> data = otp.merge([data], symbols=['SOME_DB::', 'SOME_DB_2::'])
132
+ >>> otp.run(data, date=otp.config.default_start_time) # doctest: +ELLIPSIS
133
+ Time SYMBOL_NAME
134
+ 0 2003-12-01 SOME_DB::S1
135
+ 1 2003-12-01 SOME_DB::S2
136
+ 2 2003-12-01 SOME_DB_2::S1
137
+ 3 2003-12-01 SOME_DB_2::S2
138
+
139
+ By default symbols for all tick types are returned.
140
+ You can set parameter ``show_tick_type`` to print the tick type for each symbol:
141
+
142
+ >>> symbols = otp.Symbols('US_COMP', show_tick_type=True)
143
+ >>> otp.run(symbols, date=otp.dt(2022, 3, 1))
144
+ Time SYMBOL_NAME TICK_TYPE
145
+ 0 2022-03-01 AAP TRD
146
+ 1 2022-03-01 AAPL QTE
147
+ 2 2022-03-01 AAPL TRD
148
+
149
+ Parameter ``for_tick_type`` can be used to specify a single tick type for which to return symbols:
150
+
151
+ >>> symbols = otp.Symbols('US_COMP', show_tick_type=True, for_tick_type='TRD')
152
+ >>> otp.run(symbols, date=otp.dt(2022, 3, 1))
153
+ Time SYMBOL_NAME TICK_TYPE
154
+ 0 2022-03-01 AAP TRD
155
+ 1 2022-03-01 AAPL TRD
156
+
157
+ Parameter ``pattern`` can be used to specify the pattern to filter symbol names:
158
+
159
+ >>> symbols = otp.Symbols('US_COMP', show_tick_type=True, for_tick_type='TRD', pattern='AAP_')
160
+ >>> otp.run(symbols, date=otp.dt(2022, 3, 1))
161
+ Time SYMBOL_NAME TICK_TYPE
162
+ 0 2022-03-01 AAPL TRD
163
+
164
+ Parameter ``discard_on_match`` can be used to use ``pattern`` to filter out symbols instead:
165
+
166
+ >>> symbols = otp.Symbols('US_COMP', show_tick_type=True, for_tick_type='TRD',
167
+ ... pattern='AAP_', discard_on_match=True)
168
+ >>> otp.run(symbols, date=otp.dt(2022, 3, 1))
169
+ Time SYMBOL_NAME TICK_TYPE
170
+ 0 2022-03-01 AAP TRD
171
+
172
+ ``otp.Symbols`` object can be used to specify symbols for the main query:
173
+
174
+ >>> symbols = otp.Symbols('US_COMP')
175
+ >>> data = otp.DataSource('US_COMP', tick_type='TRD')
176
+ >>> result = otp.run(data, symbols=symbols, date=otp.dt(2022, 3, 1))
177
+ >>> result['AAPL']
178
+ Time PRICE SIZE
179
+ 0 2022-03-01 00:00:00.000 1.3 100
180
+ 1 2022-03-01 00:00:00.001 1.4 10
181
+ 2 2022-03-01 00:00:00.002 1.4 50
182
+ >>> result['AAP']
183
+ Time PRICE
184
+ 0 2022-03-01 00:00:00.000 45.37
185
+ 1 2022-03-01 00:00:00.001 45.41
186
+
187
+ Additional fields of the ``otp.Symbols`` can be used in the main query as symbol parameters:
188
+
189
+ >>> symbols = otp.Symbols('SOME_DB', show_tick_type=True, keep_db=True)
190
+ >>> symbols['PARAM'] = symbols['SYMBOL_NAME'] + '__' + symbols['TICK_TYPE']
191
+ >>> data = otp.DataSource('SOME_DB')
192
+ >>> data['S_PARAM'] = data.Symbol['PARAM', str]
193
+ >>> data = otp.merge([data], symbols=symbols)
194
+ >>> otp.run(data)
195
+ Time X S_PARAM
196
+ 0 2003-12-01 00:00:00.000 1 SOME_DB::S1__TT
197
+ 1 2003-12-01 00:00:00.000 -3 SOME_DB::S2__TT
198
+ 2 2003-12-01 00:00:00.001 2 SOME_DB::S1__TT
199
+ 3 2003-12-01 00:00:00.001 -2 SOME_DB::S2__TT
200
+ 4 2003-12-01 00:00:00.002 3 SOME_DB::S1__TT
201
+ 5 2003-12-01 00:00:00.002 -1 SOME_DB::S2__TT
202
+
203
+ **Escaping special characters in the pattern**
204
+
205
+ When using patterns with special character, be aware that python strings ``\\`` is a special character too
206
+ and need to be escaped as well:
207
+
208
+ >>> print('back\\\\slash')
209
+ back\\slash
210
+
211
+ Pattern ``NQ\\\\M23`` in python should be written as ``NQ\\\\\\\\M23``:
212
+
213
+ >>> print('NQ\\\\\\\\M23')
214
+ NQ\\\\M23
215
+
216
+ Escaping character ``\\`` in python can be avoided with raw strings:
217
+
218
+ >>> print(r'NQ\\\\M23')
219
+ NQ\\\\M23
220
+ """
221
+
222
+ _PROPERTIES = Source._PROPERTIES + ["_p_db",
223
+ "_p_pattern",
224
+ "_p_start",
225
+ "_p_end",
226
+ "_p_for_tick_type",
227
+ "_p_keep_db"]
228
+
229
+ def __init__(
230
+ self,
231
+ db=None,
232
+ find_params=None,
233
+ keep_db=False,
234
+ pattern='%',
235
+ for_tick_type=None,
236
+ show_tick_type=False,
237
+ symbology='',
238
+ show_original_symbols=False,
239
+ discard_on_match=None,
240
+ cep_method=None,
241
+ poll_frequency=None,
242
+ symbols_to_return=None,
243
+ tick_type=utils.adaptive,
244
+ _tick_type=utils.adaptive,
245
+ start=utils.adaptive,
246
+ end=utils.adaptive,
247
+ date=None,
248
+ schema=None,
249
+ **kwargs,
250
+ ):
251
+ if self._try_default_constructor(schema=schema, **kwargs):
252
+ return
253
+
254
+ if isinstance(pattern, OnetickParameter):
255
+ pattern = pattern.parameter_expression
256
+
257
+ self._p_db = db
258
+ self._p_pattern = pattern
259
+ self._p_start = start
260
+ self._p_end = end
261
+ self._p_keep_db = keep_db
262
+ self._p_for_tick_type = for_tick_type
263
+
264
+ if tick_type is not utils.adaptive:
265
+ warnings.warn("In otp.Symbols parameter 'tick_type' is deprecated."
266
+ " Previously it was incorrectly interpreted by users as a tick type"
267
+ " for which symbols in the database will be searched."
268
+ " Instead right now it sets a tick type for a node in OneTick graph "
269
+ " (this results in symbols from all tick types returned from this source)."
270
+ " Use parameter 'for_tick_type' to find the symbols for a particular tick type"
271
+ " and use parameter '_tick_type' if you want set a tick type for a node in OneTick graph.",
272
+ FutureWarning, stacklevel=2)
273
+
274
+ if date and (isinstance(date, ott.datetime) or isinstance(date, ott.date)):
275
+ start = date.start
276
+ end = date.end
277
+
278
+ _symbol = utils.adaptive
279
+ if db:
280
+ if isinstance(db, list):
281
+ _symbol = [f"{str(_db).split(':')[0]}::" for _db in db] # noqa
282
+ else:
283
+ _symbol = f"{str(db).split(':')[0]}::" # noqa
284
+
285
+ if find_params is not None:
286
+ warnings.warn("In otp.Symbols parameter 'find_params' is deprecated."
287
+ " Use named parameters instead.",
288
+ FutureWarning, stacklevel=2)
289
+
290
+ _find_params = find_params if find_params is not None else {}
291
+
292
+ _find_params.setdefault('pattern', pattern)
293
+ if for_tick_type:
294
+ _find_params['tick_type_field'] = for_tick_type
295
+ _find_params.setdefault('show_tick_type', show_tick_type)
296
+
297
+ _find_params.setdefault('symbology', symbology)
298
+ _find_params.setdefault('show_original_symbols', show_original_symbols)
299
+
300
+ if discard_on_match is not None:
301
+ _find_params.setdefault('discard_on_match', discard_on_match)
302
+ if cep_method is not None:
303
+ if not isinstance(cep_method, str) or cep_method not in ('use_cep_adapter', 'use_db'):
304
+ raise ValueError(f"Wrong value for parameter 'cep_method': {cep_method}")
305
+ _find_params.setdefault('cep_method', cep_method.upper())
306
+ if poll_frequency is not None:
307
+ _find_params.setdefault('poll_frequency', poll_frequency)
308
+ if symbols_to_return is not None:
309
+ if not isinstance(symbols_to_return, str) or symbols_to_return not in ('all_in_db',
310
+ 'with_ticks_in_query_range'):
311
+ raise ValueError(f"Wrong value for parameter 'symbols_to_return': {symbols_to_return}")
312
+ _find_params.setdefault('symbols_to_return', symbols_to_return.upper())
313
+
314
+ if tick_type is not utils.adaptive and _tick_type is not utils.adaptive:
315
+ raise ValueError("Parameters 'tick_type' and '_tick_type' can't be set simultaneously")
316
+ elif tick_type is not utils.adaptive:
317
+ ep_tick_type = tick_type
318
+ elif _tick_type is not utils.adaptive:
319
+ ep_tick_type = _tick_type
320
+ else:
321
+ ep_tick_type = utils.adaptive
322
+
323
+ super().__init__(
324
+ _symbols=_symbol,
325
+ _start=start,
326
+ _end=end,
327
+ _base_ep_func=lambda: self.base_ep(ep_tick_type=ep_tick_type,
328
+ keep_db=keep_db, **_find_params),
329
+ )
330
+
331
+ self.schema['SYMBOL_NAME'] = str
332
+
333
+ if _find_params['show_tick_type']:
334
+ self.schema['TICK_TYPE'] = str
335
+
336
+ if _find_params['symbology'] and _find_params['show_original_symbols']:
337
+ self.schema['ORIGINAL_SYMBOL_NAME'] = str
338
+
339
+ def base_ep(self, ep_tick_type, keep_db, **params):
340
+ src = Source(otq.FindDbSymbols(**params))
341
+
342
+ update_node_tick_type(src, ep_tick_type)
343
+ src.schema['SYMBOL_NAME'] = str
344
+
345
+ if not keep_db:
346
+ src["SYMBOL_NAME"] = src["SYMBOL_NAME"].str.regex_replace('.*::', '')
347
+
348
+ return src
349
+
350
+ @staticmethod
351
+ def duplicate(obj, db=None):
352
+ return Symbols(db=obj._p_db if db is None else db,
353
+ pattern=obj._p_pattern,
354
+ start=obj._p_start,
355
+ end=obj._p_end,
356
+ keep_db=obj._p_keep_db,
357
+ for_tick_type=obj._p_for_tick_type)