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