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,26 @@
1
+ # A common place to put backports for specific versions of Python
2
+
3
+ import sys
4
+
5
+ if sys.version_info >= (3, 8):
6
+ from typing import Literal
7
+ from functools import singledispatchmethod, lru_cache
8
+ else:
9
+ from typing_extensions import Literal
10
+ from singledispatchmethod import singledispatchmethod
11
+ from backports.functools_lru_cache import lru_cache
12
+
13
+
14
+ if sys.version_info >= (3, 9):
15
+ import zoneinfo
16
+ from functools import cached_property, cache
17
+ import ast
18
+ astunparse = ast.unparse
19
+ else:
20
+ from backports.cached_property import cached_property
21
+ from astunparse import unparse as astunparse
22
+ from backports import zoneinfo
23
+
24
+ def cache(user_function):
25
+ 'Simple lightweight unbounded cache. Sometimes called "memoize".'
26
+ return lru_cache(maxsize=None)(user_function)
onetick/py/cache.py ADDED
@@ -0,0 +1,374 @@
1
+ from typing import Any, Callable, List, Optional, Tuple, Union
2
+ from types import FunctionType
3
+ from datetime import datetime
4
+
5
+ import onetick.py as otp
6
+ from onetick.py.otq import otq
7
+ from onetick.py.core.source import Source
8
+ from onetick.py.sources.common import update_node_tick_type
9
+ from onetick.py.sources.cache import process_otq_params
10
+ from onetick.py.types import datetime as otp_datetime
11
+
12
+ from . import configuration
13
+
14
+
15
+ def _check_status(df):
16
+ if "STATUS" not in df:
17
+ raise RuntimeError("Empty response returned")
18
+
19
+ status = df["STATUS"][0]
20
+ if status != "SUCCESS":
21
+ raise RuntimeError(f"Error status returned: {status}")
22
+
23
+
24
+ def _convert_dt_to_str(dt: Union[str, datetime, otp_datetime]):
25
+ if isinstance(dt, str):
26
+ return dt
27
+ elif isinstance(dt, (datetime, otp_datetime)):
28
+ return dt.strftime('%Y%m%d%H%M%S.%f')
29
+ raise ValueError(f"Unsupported value for 'dt' parameter: {type(dt)}")
30
+
31
+
32
+ def _convert_time_intervals(
33
+ time_intervals_to_cache: List[Tuple[Union[str, datetime, otp_datetime], Union[str, datetime, otp_datetime]]],
34
+ ):
35
+ return "\n".join(
36
+ [
37
+ f"{_convert_dt_to_str(start_time)},{_convert_dt_to_str(end_time)}"
38
+ for start_time, end_time in time_intervals_to_cache
39
+ ]
40
+ )
41
+
42
+
43
+ def create_cache(
44
+ cache_name: str,
45
+ query: Union['Source', Callable, str, None] = None,
46
+ inheritability: bool = True,
47
+ otq_params: Union[dict, None] = None,
48
+ time_granularity: int = 0,
49
+ time_granularity_units: Optional[str] = None,
50
+ timezone: str = "",
51
+ time_intervals_to_cache: Optional[List[tuple]] = None,
52
+ allow_delete_to_everyone: bool = False,
53
+ allow_update_to_everyone: bool = False,
54
+ allow_search_to_everyone: bool = True,
55
+ cache_expiration_interval: int = 0,
56
+ tick_type: str = "ANY",
57
+ symbol: Optional[str] = None,
58
+ db: Optional[str] = None,
59
+ ):
60
+ """
61
+ Create cache via CREATE_CACHE EP
62
+
63
+ If :py:class:`onetick.py.Source` or callable passed as ``query`` parameter,
64
+ cache will be created only for current session.
65
+
66
+ Also, this case or passing absolute path to .otq as ``query`` parameter are supported
67
+ only for caching on local OneTick server.
68
+
69
+ Parameters ``symbol``, ``db`` and ``tick_type`` could be omitted if you want to use
70
+ default symbol, default database and ``ANY`` tick type.
71
+
72
+ Parameters
73
+ ----------
74
+ cache_name: str
75
+ Name of the cache to be created.
76
+ query: :py:class:`onetick.py.Source`, callable, str
77
+ Query to be cached or path to .otq file (in ``filename.otq::QueryName`` format).
78
+ Only queries residing on the server that runs the caching event processors are currently supported.
79
+ For local OneTick server you can pass absolute path to local .otq file.
80
+ inheritability: bool
81
+ Indicates whether results can be obtained by combining time intervals that were cached with intervals
82
+ freshly computed to obtain results for larger intervals.
83
+ otq_params: dict
84
+ OTQ params of the query to be cached.
85
+ Setting `otq_params` in :py:class:`onetick.py.ReadCache` may not override this `otq_params`
86
+ if cache not invalidated.
87
+ time_granularity: int
88
+ Value N for seconds/days/months granularity means that start and end time of the query have to be on N
89
+ second/day/month boundaries relative to start of the day/month/year.
90
+ This doesn't affect the frequency of data within the cache, just the start and end dates.
91
+ time_granularity_units: str, None
92
+ Units used in ``time_granularity`` parameter. Possible values: 'none', 'days', 'months', 'seconds' or None.
93
+ timezone: str
94
+ Timezone of the query to be cached.
95
+ time_intervals_to_cache: List[tuple]
96
+ List of tuples with start and end times in ``[(<start_time_1>, <end_time_1>), ...]`` format,
97
+ where ``<start_time>`` and ``<end_time>`` should be one of these:
98
+
99
+ * string in ``YYYYMMDDhhmmss[.msec]`` format.
100
+ * :py:class:`datetime.datetime`
101
+ * :py:class:`onetick.py.types.datetime`
102
+
103
+ If specified only these time intervals can be cached. Ignored if ``inheritability=True``.
104
+ If you try to make a query outside defined interval, error will be raised.
105
+ allow_delete_to_everyone: bool
106
+ When set to ``True`` everyone is allowed to delete the cache.
107
+ allow_update_to_everyone: bool
108
+ When set to ``True`` everyone is allowed to update the cache.
109
+ allow_search_to_everyone: bool
110
+ When set to ``True`` everyone is allowed to read the cached data.
111
+ cache_expiration_interval: int
112
+ If set to a non-zero value determines the periodicity of cache clearing, in seconds.
113
+ The cache will be cleared every X seconds, triggering new query executions when data is requested.
114
+ tick_type: str
115
+ Tick type.
116
+ symbol: str, list of str, list of otq.Symbol, :py:class:`onetick.py.Source`, :pandas:`pandas.DataFrame`, optional
117
+ ``symbols`` parameter of ``otp.run()``.
118
+ db: str
119
+ Database.
120
+
121
+ Note
122
+ ----
123
+ This function does NOT populate the cache, it's only reserves the cache name in the OneTick memory.
124
+ Cache is only populated when an attempt is made to read the data from it via :py:class:`onetick.py.ReadCache`.
125
+
126
+ See also
127
+ --------
128
+ | **CREATE_CACHE** OneTick event processor
129
+ | :py:class:`onetick.py.ReadCache`
130
+ | :py:func:`onetick.py.delete_cache`
131
+
132
+ Examples
133
+ --------
134
+ Simple cache creation from .otq file on OneTick server under ``OTQ_FILE_PATH``
135
+
136
+ >>> otp.create_cache( # doctest: +SKIP
137
+ ... cache_name="some_cache", query="CACHE_EXAMPLE.otq::slowquery",
138
+ ... tick_type="TRD", db="LOCAL",
139
+ ... )
140
+
141
+ Cache creation from function
142
+
143
+ >>> def query_func():
144
+ ... return otp.DataSource("COMMON", tick_type="TRD", symbols="AAPL")
145
+ >>> otp.create_cache(
146
+ ... cache_name="some_cache", query=query_func, tick_type="TRD", db="LOCAL",
147
+ ... )
148
+
149
+ Create cache for time intervals with different datetime types:
150
+
151
+ >>> otp.create_cache( # doctest: +SKIP
152
+ ... cache_name="some_cache",
153
+ ... query="query_example.otq::query"),
154
+ ... inheritability=False,
155
+ ... time_intervals_to_cache=[
156
+ ... ("20220601123000.000000", "20220601183000.000000"),
157
+ ... (datetime(2022, 6, 2, 12, 30), datetime(2003, 1, 2, 18, 30)),
158
+ ... (otp.datetime(2022, 6, 3, 12, 30), otp.datetime(2022, 6, 3, 18, 30)),
159
+ ... ],
160
+ ... timezone="GMT",
161
+ ... tick_type="TRD",
162
+ ... db="LOCAL",
163
+ ... )
164
+
165
+ Create cache with OTQ params:
166
+
167
+ >>> otp.create_cache( # doctest: +SKIP
168
+ ... cache_name="some_cache",
169
+ ... query="query_example.otq::query"),
170
+ ... otq_params={"some_param": "some_value"},
171
+ ... timezone="GMT",
172
+ ... tick_type="TRD",
173
+ ... db="LOCAL",
174
+ ... )
175
+ """
176
+ if query is None:
177
+ raise ValueError("Parameter `query` should be set")
178
+
179
+ if time_granularity_units is None:
180
+ time_granularity_units = "none"
181
+
182
+ if time_granularity_units not in {'none', 'days', 'months', 'seconds'}:
183
+ raise ValueError(f"Incorrect `time_granularity_units` param value passed: {time_granularity_units}")
184
+
185
+ time_granularity_units = time_granularity_units.upper()
186
+
187
+ if symbol is None:
188
+ symbol = configuration.config.default_symbol
189
+
190
+ if db is None:
191
+ db = configuration.config.default_db
192
+
193
+ time_intervals_str = ""
194
+ if time_intervals_to_cache:
195
+ time_intervals_str = _convert_time_intervals(time_intervals_to_cache)
196
+
197
+ otq_params_str = process_otq_params(otq_params)
198
+
199
+ otq_file_path = None
200
+ if query:
201
+ if isinstance(query, FunctionType):
202
+ query = query()
203
+
204
+ if isinstance(query, Source):
205
+ # will create sub-query after source is initialized below
206
+ otq_file_path = 'THIS::create_cache_query'
207
+ elif isinstance(query, str):
208
+ otq_file_path = query
209
+ else:
210
+ raise ValueError(f"Passed `query` parameter value with incorrect type: {type(query)}")
211
+
212
+ source = Source(
213
+ otq.CreateCache(
214
+ cache_name=cache_name,
215
+ otq_file_path=otq_file_path,
216
+ inheritability=inheritability,
217
+ otq_params=otq_params_str,
218
+ time_granularity=time_granularity,
219
+ time_granularity_units=time_granularity_units,
220
+ timezone=timezone,
221
+ time_intervals_to_cache=time_intervals_str,
222
+ allow_delete_to_everyone=allow_delete_to_everyone,
223
+ allow_update_to_everyone=allow_update_to_everyone,
224
+ allow_search_to_everyone=allow_search_to_everyone,
225
+ cache_expiration_interval=cache_expiration_interval,
226
+ ),
227
+ )
228
+
229
+ if isinstance(query, Source):
230
+ # create temp file with query
231
+ query._store_in_tmp_otq(source._tmp_otq, name='create_cache_query')
232
+
233
+ update_node_tick_type(source, tick_type, db)
234
+
235
+ res = otp.run(source, symbols=symbol)
236
+ _check_status(res)
237
+
238
+
239
+ def delete_cache(
240
+ cache_name: str,
241
+ apply_to_entire_cache: bool = True,
242
+ per_cache_otq_params: Union[dict, None] = None,
243
+ tick_type: str = "ANY",
244
+ symbol: Optional[str] = None,
245
+ db: Optional[str] = None,
246
+ ):
247
+ """
248
+ Delete cache via DELETE_CACHE EP
249
+
250
+ Parameters
251
+ ----------
252
+ cache_name: str
253
+ Name of the cache to be deleted.
254
+ apply_to_entire_cache: bool
255
+ When set to ``True`` deletes the cache for all symbols and time intervals.
256
+ per_cache_otq_params: dict
257
+ Deletes cache that have been associated with this OTQ parameters during its creation.
258
+ Value of this parameter should be equal to the value of ``otq_params`` of
259
+ :func:`<onetick.py.create_cache>`.
260
+ tick_type: str
261
+ Tick type.
262
+ symbol: str, list of str, list of otq.Symbol, :py:class:`onetick.py.Source`, :pandas:`pandas.DataFrame`, optional
263
+ ``symbols`` parameter of ``otp.run()``.
264
+ db: str
265
+ Database.
266
+
267
+ See also
268
+ --------
269
+ | **DELETE_CACHE** OneTick event processor
270
+ | :py:class:`onetick.py.ReadCache`
271
+ | :py:func:`onetick.py.create_cache`
272
+
273
+ Examples
274
+ --------
275
+ Simple cache deletion
276
+
277
+ >>> otp.delete_cache( # doctest: +SKIP
278
+ ... cache_name="some_cache", tick_type="TRD", symbol="SYM", db="LOCAL",
279
+ ... )
280
+ """
281
+ if symbol is None:
282
+ symbol = configuration.config.default_symbol
283
+
284
+ if db is None:
285
+ db = configuration.config.default_db
286
+
287
+ source = Source(
288
+ otq.DeleteCache(
289
+ cache_name=cache_name,
290
+ apply_to_entire_cache=apply_to_entire_cache,
291
+ per_cache_otq_params=process_otq_params(per_cache_otq_params),
292
+ ),
293
+ )
294
+
295
+ update_node_tick_type(source, tick_type, db)
296
+
297
+ res = otp.run(source, symbols=symbol)
298
+ _check_status(res)
299
+
300
+
301
+ def modify_cache_config(
302
+ cache_name: str,
303
+ param_name: str,
304
+ param_value: Any,
305
+ tick_type: str = "ANY",
306
+ symbol: Optional[str] = None,
307
+ db: Optional[str] = None,
308
+ ):
309
+ """
310
+ Modify cache configuration via MODIFY_CACHE_CONFIG EP
311
+
312
+ Parameters
313
+ ----------
314
+ cache_name: str
315
+ Name of the cache to be deleted.
316
+ param_name: str
317
+ The name of the configuration parameter to be changed.
318
+ Supported parameters:
319
+
320
+ * ``inheritability``
321
+ * ``time_granularity``
322
+ * ``time_granularity_units``
323
+ * ``timezone``
324
+ * ``allow_search_to_everyone``
325
+ * ``allow_delete_to_everyone``
326
+ * ``allow_update_to_everyone``
327
+
328
+ param_value: Any
329
+ New value of configuration parameter. Will be converted to string.
330
+ tick_type: str
331
+ Tick type.
332
+ symbol: str, list of str, list of otq.Symbol, :py:class:`onetick.py.Source`, :pandas:`pandas.DataFrame`, optional
333
+ ``symbols`` parameter of ``otp.run()``.
334
+ db: str
335
+ Database.
336
+
337
+ See also
338
+ --------
339
+ | **MODIFY_CACHE_CONFIG** OneTick event processor
340
+ | :py:class:`onetick.py.ReadCache`
341
+ | :py:func:`onetick.py.create_cache`
342
+
343
+ Examples
344
+ --------
345
+ Simple cache config modification
346
+
347
+ >>> otp.modify_cache_config( # doctest: +SKIP
348
+ ... cache_name="some_cache",
349
+ ... param_name="time_granularity",
350
+ ... param_value=3,
351
+ ... tick_type="TRD", symbol="SYM", db="LOCAL",
352
+ ... )
353
+ """
354
+ if symbol is None:
355
+ symbol = configuration.config.default_symbol
356
+
357
+ if db is None:
358
+ db = configuration.config.default_db
359
+
360
+ param_name = param_name.upper()
361
+ param_value = str(param_value)
362
+
363
+ source = Source(
364
+ otq.ModifyCacheConfig(
365
+ cache_name=cache_name,
366
+ config_parameter_name=param_name,
367
+ config_parameter_value=param_value,
368
+ ),
369
+ )
370
+
371
+ update_node_tick_type(source, tick_type, db)
372
+
373
+ res = otp.run(source, symbols=symbol)
374
+ _check_status(res)
@@ -0,0 +1,5 @@
1
+ from .callback import CallbackBase
2
+ from .callbacks import (
3
+ LogCallback,
4
+ ManualDataframeCallback,
5
+ )
@@ -0,0 +1,276 @@
1
+ from onetick.py.otq import otq
2
+
3
+
4
+ class CallbackBase(otq.CallbackBase):
5
+ """
6
+ Base class for user-defined callback classes
7
+ for :py:func:`onetick.py.run` callback mode.
8
+
9
+ Note
10
+ ----
11
+ Callbacks are executed sequentially, so make sure
12
+ they don't take too much time to execute.
13
+
14
+ See also
15
+ --------
16
+ :py:func:`onetick.py.run`
17
+
18
+ Examples
19
+ --------
20
+ >>> t = otp.Ticks(A=[1, 2, 3])
21
+ >>> class NumTicksCallback(otp.CallbackBase):
22
+ ... def __init__(self):
23
+ ... self.num_ticks = 0
24
+ ... def process_tick(self, tick, time):
25
+ ... self.num_ticks += 1
26
+ >>> callback = NumTicksCallback()
27
+ >>> otp.run(t, callback=callback)
28
+ >>> callback.num_ticks
29
+ 3
30
+ """
31
+
32
+ # pylint: disable-next=useless-parent-delegation
33
+ def __init__(self):
34
+ """
35
+ Method ``__init__()`` can be used for callback initialization.
36
+ Can be used to define some variables for future use
37
+ in callback methods.
38
+ """
39
+ super().__init__()
40
+
41
+ def replicate(self):
42
+ """
43
+ Called to replicate the callback object for each output node.
44
+ May also be used for internal copying of callback object.
45
+
46
+ Returns
47
+ -------
48
+ By default reference to this callback object
49
+ """
50
+ return self
51
+
52
+ def process_callback_label(self, callback_label):
53
+ """
54
+ Called immediately before :meth:`process_symbol_name`
55
+ to supply label assigned to callback.
56
+
57
+ Parameters
58
+ ----------
59
+ callback_label: str
60
+ label assigned to this callback object
61
+ """
62
+ pass
63
+
64
+ def process_symbol_name(self, symbol_name):
65
+ """
66
+ Invoked to supply the name of the security that produces
67
+ all the ticks that will be delivered to this callback object.
68
+ If these ticks are provided by several securities,
69
+ the ``symbol_name`` parameter is set to empty string.
70
+
71
+ Parameters
72
+ ----------
73
+ symbol_name: str
74
+ name of security
75
+
76
+ Examples
77
+ --------
78
+ >>> t = otp.Tick(A=1)
79
+ >>> class SymbolNameCallback(otp.CallbackBase):
80
+ ... def process_symbol_name(self, symbol_name):
81
+ ... self.symbol_name = symbol_name
82
+ >>> callback = SymbolNameCallback()
83
+ >>> otp.run(t, callback=callback, symbols='DEMO_L1::X')
84
+ >>> callback.symbol_name
85
+ 'DEMO_L1::X'
86
+ """
87
+ pass
88
+
89
+ def process_symbol_group_name(self, symbol_group_name):
90
+ """
91
+ Called when a named group of securities, i.e. portfolio, is processed.
92
+
93
+ Parameters
94
+ ----------
95
+ symbol_group_name: str
96
+ The name of security group.
97
+ """
98
+ pass
99
+
100
+ def process_tick_type(self, tick_type):
101
+ """
102
+ Reports the type of the security ticks which are processed by this callback object.
103
+ This method is called before any call to
104
+ :meth:`process_tick_descriptor` or :meth:`process_tick`.
105
+ It is called immediately after :meth:`process_symbol_name`.
106
+
107
+ Parameters
108
+ ----------
109
+ tick_type: str
110
+ The name of tick type.
111
+
112
+ Examples
113
+ --------
114
+ >>> t = otp.Tick(A=1, symbol='DEMO_L1', tick_type='TT_TT')
115
+ >>> class TickTypeCallback(otp.CallbackBase):
116
+ ... def process_tick_type(self, tick_type):
117
+ ... self.tick_type = tick_type
118
+ >>> callback = TickTypeCallback()
119
+ >>> otp.run(t, callback=callback)
120
+ >>> callback.tick_type
121
+ 'DEMO_L1::TT_TT'
122
+ """
123
+ pass
124
+
125
+ def process_tick_descriptor(self, tick_descriptor):
126
+ """
127
+ This method is invoked before the first call to :meth:`process_tick`
128
+ and every time before tick structure changes.
129
+
130
+ Parameters
131
+ ----------
132
+ tick_descriptor: list of tuple
133
+ First element of each tuple is field's name
134
+ and the second one is a dictionary ``{'type': string_field_type}``.
135
+
136
+ Examples
137
+ --------
138
+ >>> t = otp.Tick(A=1)
139
+ >>> class TickDescriptorCallback(otp.CallbackBase):
140
+ ... def process_tick_descriptor(self, tick_descriptor):
141
+ ... self.tick_descriptor = tick_descriptor
142
+ >>> callback = TickDescriptorCallback()
143
+ >>> otp.run(t, callback=callback)
144
+ >>> callback.tick_descriptor
145
+ [('A', {'type': 'int'})]
146
+ """
147
+ pass
148
+
149
+ def process_tick(self, tick, time):
150
+ """
151
+ Called to deliver each tick.
152
+
153
+ Note
154
+ ----
155
+ If you are making query through WebAPI mode, use ``process_ticks`` callback method instead.
156
+
157
+ Parameters
158
+ ----------
159
+ tick: dict
160
+ mapping of field names to field values
161
+ time: :py:class:`datetime.datetime`
162
+ timestamp of the tick in GMT timezone.
163
+
164
+ Examples
165
+ --------
166
+ >>> t = otp.Tick(A=1)
167
+ >>> class ProcessTickCallback(otp.CallbackBase):
168
+ ... def process_tick(self, tick, time):
169
+ ... self.result = (tick, time)
170
+ >>> callback = ProcessTickCallback()
171
+ >>> otp.run(t, callback=callback)
172
+ >>> callback.result
173
+ ({'A': 1}, datetime.datetime(2003, 12, 1, 5, 0))
174
+ """
175
+ pass
176
+
177
+ def process_ticks(self, ticks):
178
+ """
179
+ Called after getting all ticks for WebAPI queries.
180
+
181
+ Due to limitation of WebAPI mode ``process_tick`` callback method, which invoked on each tick, isn't supported.
182
+ Instead, WebAPI supports ``process_ticks`` method which invoked for processing the data
183
+ after the query is finished.
184
+ All ticks are returned on the ``ticks`` variable.
185
+
186
+ Parameters
187
+ ----------
188
+ ticks: dict
189
+ mapping of field names to field values
190
+
191
+ Examples
192
+ --------
193
+ >>> t = otp.Tick(A=1)
194
+ >>> class ProcessTicksCallback(otp.CallbackBase):
195
+ ... def __init__(self):
196
+ ... self.result = {}
197
+ ...
198
+ ... def process_ticks(self, ticks):
199
+ ... self.result = ticks
200
+ >>> callback = ProcessTicksCallback()
201
+ >>> otp.run(t, callback=callback) # doctest: +SKIP
202
+ >>> callback.result # doctest: +SKIP
203
+ {'Time': array(['2003-12-01T00:00:00.000000000'], dtype='datetime64[ns]'), 'A': array([1])}
204
+ """
205
+ pass
206
+
207
+ def process_sorting_order(self, sorted_by_time_flag):
208
+ """
209
+ Informs whether the ticks that will be submitted to this callback object
210
+ will be ordered by time.
211
+
212
+ Parameters
213
+ ----------
214
+ sorted_by_time_flag: bool
215
+ Indicates whether the incoming ticks will be sorted by time.
216
+ """
217
+ pass
218
+
219
+ def process_data_quality_change(self, symbol_name, data_quality, time):
220
+ """
221
+ Called to report a data quality change, such as collection outage.
222
+
223
+ Parameters
224
+ ----------
225
+ symbol_name: str
226
+ Symbol name for each data quality change is propagated.
227
+ data_quality: int
228
+ parameter has following meaning:
229
+
230
+ * `QUALITY_UNKNOWN` = -1,
231
+ * `QUALITY_OK`,
232
+ * `QUALITY_STALE` = 1,
233
+ * `QUALITY_MISSING` = 2,
234
+ * `QUALITY_PATCHED` = 4,
235
+ * `QUALITY_MOUNT_BAD` = 9,
236
+ * `QUALITY_DISCONNECT` = 17,
237
+ * `QUALITY_COLLECTOR_FAILURE` = 33,
238
+ * `QUALITY_DELAY_STITCHING_WITH_RT` = 64,
239
+ * `QUALITY_OK_STITCHING_WITH_RT` = 66
240
+ time: :py:class:`datetime.datetime`
241
+ Time of the change in GMT timezone.
242
+ """
243
+ pass
244
+
245
+ def process_error(self, error_code, error_msg):
246
+ """
247
+ Called to report a per-security error or per-security warning.
248
+
249
+ Parameters
250
+ ----------
251
+ error_code: int
252
+ Values of error code less than 1000 are warnings.
253
+ Warnings signal issues which might not affect results of the query
254
+ and thus could be chosen to be ignored
255
+ error_msg: str
256
+ Error message
257
+ """
258
+ pass
259
+
260
+ def done(self):
261
+ """
262
+ Invoked when all the raw or computed ticks for a given request
263
+ were submitted to the callback using the :meth:`process_tick` method.
264
+
265
+ Examples
266
+ --------
267
+ >>> t = otp.Tick(A=1)
268
+ >>> class DoneCallback(otp.CallbackBase):
269
+ ... def done(self):
270
+ ... self.done = True
271
+ >>> callback = DoneCallback()
272
+ >>> otp.run(t, callback=callback)
273
+ >>> callback.done
274
+ True
275
+ """
276
+ pass