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.
- locator_parser/__init__.py +0 -0
- locator_parser/acl.py +73 -0
- locator_parser/actions.py +266 -0
- locator_parser/common.py +365 -0
- locator_parser/io.py +41 -0
- locator_parser/locator.py +150 -0
- onetick/__init__.py +101 -0
- onetick/doc_utilities/__init__.py +3 -0
- onetick/doc_utilities/napoleon.py +40 -0
- onetick/doc_utilities/ot_doctest.py +140 -0
- onetick/doc_utilities/snippets.py +280 -0
- onetick/lib/__init__.py +4 -0
- onetick/lib/instance.py +138 -0
- onetick/py/__init__.py +290 -0
- onetick/py/_stack_info.py +89 -0
- onetick/py/_version.py +2 -0
- onetick/py/aggregations/__init__.py +11 -0
- onetick/py/aggregations/_base.py +645 -0
- onetick/py/aggregations/_docs.py +912 -0
- onetick/py/aggregations/compute.py +286 -0
- onetick/py/aggregations/functions.py +2216 -0
- onetick/py/aggregations/generic.py +104 -0
- onetick/py/aggregations/high_low.py +80 -0
- onetick/py/aggregations/num_distinct.py +83 -0
- onetick/py/aggregations/order_book.py +427 -0
- onetick/py/aggregations/other.py +1014 -0
- onetick/py/backports.py +26 -0
- onetick/py/cache.py +373 -0
- onetick/py/callback/__init__.py +5 -0
- onetick/py/callback/callback.py +275 -0
- onetick/py/callback/callbacks.py +131 -0
- onetick/py/compatibility.py +752 -0
- onetick/py/configuration.py +736 -0
- onetick/py/core/__init__.py +0 -0
- onetick/py/core/_csv_inspector.py +93 -0
- onetick/py/core/_internal/__init__.py +0 -0
- onetick/py/core/_internal/_manually_bound_value.py +6 -0
- onetick/py/core/_internal/_nodes_history.py +250 -0
- onetick/py/core/_internal/_op_utils/__init__.py +0 -0
- onetick/py/core/_internal/_op_utils/every_operand.py +9 -0
- onetick/py/core/_internal/_op_utils/is_const.py +10 -0
- onetick/py/core/_internal/_per_tick_scripts/tick_list_sort_template.script +121 -0
- onetick/py/core/_internal/_proxy_node.py +140 -0
- onetick/py/core/_internal/_state_objects.py +2307 -0
- onetick/py/core/_internal/_state_vars.py +87 -0
- onetick/py/core/_source/__init__.py +0 -0
- onetick/py/core/_source/_symbol_param.py +95 -0
- onetick/py/core/_source/schema.py +97 -0
- onetick/py/core/_source/source_methods/__init__.py +0 -0
- onetick/py/core/_source/source_methods/aggregations.py +810 -0
- onetick/py/core/_source/source_methods/applyers.py +296 -0
- onetick/py/core/_source/source_methods/columns.py +141 -0
- onetick/py/core/_source/source_methods/data_quality.py +301 -0
- onetick/py/core/_source/source_methods/debugs.py +270 -0
- onetick/py/core/_source/source_methods/drops.py +120 -0
- onetick/py/core/_source/source_methods/fields.py +619 -0
- onetick/py/core/_source/source_methods/filters.py +1001 -0
- onetick/py/core/_source/source_methods/joins.py +1393 -0
- onetick/py/core/_source/source_methods/merges.py +566 -0
- onetick/py/core/_source/source_methods/misc.py +1325 -0
- onetick/py/core/_source/source_methods/pandases.py +155 -0
- onetick/py/core/_source/source_methods/renames.py +356 -0
- onetick/py/core/_source/source_methods/sorts.py +183 -0
- onetick/py/core/_source/source_methods/switches.py +142 -0
- onetick/py/core/_source/source_methods/symbols.py +117 -0
- onetick/py/core/_source/source_methods/times.py +627 -0
- onetick/py/core/_source/source_methods/writes.py +702 -0
- onetick/py/core/_source/symbol.py +202 -0
- onetick/py/core/_source/tmp_otq.py +222 -0
- onetick/py/core/column.py +209 -0
- onetick/py/core/column_operations/__init__.py +0 -0
- onetick/py/core/column_operations/_methods/__init__.py +4 -0
- onetick/py/core/column_operations/_methods/_internal.py +28 -0
- onetick/py/core/column_operations/_methods/conversions.py +215 -0
- onetick/py/core/column_operations/_methods/methods.py +294 -0
- onetick/py/core/column_operations/_methods/op_types.py +150 -0
- onetick/py/core/column_operations/accessors/__init__.py +0 -0
- onetick/py/core/column_operations/accessors/_accessor.py +30 -0
- onetick/py/core/column_operations/accessors/decimal_accessor.py +92 -0
- onetick/py/core/column_operations/accessors/dt_accessor.py +464 -0
- onetick/py/core/column_operations/accessors/float_accessor.py +160 -0
- onetick/py/core/column_operations/accessors/str_accessor.py +1374 -0
- onetick/py/core/column_operations/base.py +1061 -0
- onetick/py/core/cut_builder.py +149 -0
- onetick/py/core/db_constants.py +20 -0
- onetick/py/core/eval_query.py +244 -0
- onetick/py/core/lambda_object.py +442 -0
- onetick/py/core/multi_output_source.py +193 -0
- onetick/py/core/per_tick_script.py +2253 -0
- onetick/py/core/query_inspector.py +465 -0
- onetick/py/core/source.py +1663 -0
- onetick/py/db/__init__.py +2 -0
- onetick/py/db/_inspection.py +1042 -0
- onetick/py/db/db.py +1423 -0
- onetick/py/db/utils.py +64 -0
- onetick/py/docs/__init__.py +0 -0
- onetick/py/docs/docstring_parser.py +112 -0
- onetick/py/docs/utils.py +81 -0
- onetick/py/functions.py +2354 -0
- onetick/py/license.py +188 -0
- onetick/py/log.py +88 -0
- onetick/py/math.py +947 -0
- onetick/py/misc.py +437 -0
- onetick/py/oqd/__init__.py +22 -0
- onetick/py/oqd/eps.py +1195 -0
- onetick/py/oqd/sources.py +325 -0
- onetick/py/otq.py +211 -0
- onetick/py/pyomd_mock.py +47 -0
- onetick/py/run.py +841 -0
- onetick/py/servers.py +173 -0
- onetick/py/session.py +1342 -0
- onetick/py/sources/__init__.py +19 -0
- onetick/py/sources/cache.py +167 -0
- onetick/py/sources/common.py +126 -0
- onetick/py/sources/csv.py +642 -0
- onetick/py/sources/custom.py +85 -0
- onetick/py/sources/data_file.py +305 -0
- onetick/py/sources/data_source.py +1049 -0
- onetick/py/sources/empty.py +94 -0
- onetick/py/sources/odbc.py +337 -0
- onetick/py/sources/order_book.py +238 -0
- onetick/py/sources/parquet.py +168 -0
- onetick/py/sources/pit.py +191 -0
- onetick/py/sources/query.py +495 -0
- onetick/py/sources/snapshots.py +419 -0
- onetick/py/sources/split_query_output_by_symbol.py +198 -0
- onetick/py/sources/symbology_mapping.py +123 -0
- onetick/py/sources/symbols.py +357 -0
- onetick/py/sources/ticks.py +825 -0
- onetick/py/sql.py +70 -0
- onetick/py/state.py +256 -0
- onetick/py/types.py +2056 -0
- onetick/py/utils/__init__.py +70 -0
- onetick/py/utils/acl.py +93 -0
- onetick/py/utils/config.py +186 -0
- onetick/py/utils/default.py +49 -0
- onetick/py/utils/file.py +38 -0
- onetick/py/utils/helpers.py +76 -0
- onetick/py/utils/locator.py +94 -0
- onetick/py/utils/perf.py +499 -0
- onetick/py/utils/query.py +49 -0
- onetick/py/utils/render.py +1139 -0
- onetick/py/utils/script.py +244 -0
- onetick/py/utils/temp.py +471 -0
- onetick/py/utils/types.py +118 -0
- onetick/py/utils/tz.py +82 -0
- onetick_py-1.162.2.dist-info/METADATA +148 -0
- onetick_py-1.162.2.dist-info/RECORD +152 -0
- onetick_py-1.162.2.dist-info/WHEEL +5 -0
- onetick_py-1.162.2.dist-info/entry_points.txt +2 -0
- onetick_py-1.162.2.dist-info/licenses/LICENSE +21 -0
- onetick_py-1.162.2.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import onetick.py as otp
|
|
2
|
+
from onetick.py.otq import otq
|
|
3
|
+
|
|
4
|
+
from onetick.py.core.source import Source
|
|
5
|
+
|
|
6
|
+
from .. import utils
|
|
7
|
+
|
|
8
|
+
from .common import update_node_tick_type
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ReadParquet(Source):
|
|
12
|
+
def __init__(
|
|
13
|
+
self,
|
|
14
|
+
parquet_file_path=None,
|
|
15
|
+
where=None,
|
|
16
|
+
time_assignment="end",
|
|
17
|
+
discard_fields=None,
|
|
18
|
+
fields=None,
|
|
19
|
+
symbol_name_field=None,
|
|
20
|
+
symbol=utils.adaptive,
|
|
21
|
+
db=utils.adaptive_to_default,
|
|
22
|
+
tick_type=utils.adaptive,
|
|
23
|
+
start=utils.adaptive,
|
|
24
|
+
end=utils.adaptive,
|
|
25
|
+
schema=None,
|
|
26
|
+
**kwargs,
|
|
27
|
+
):
|
|
28
|
+
"""
|
|
29
|
+
Read ticks from Parquet file
|
|
30
|
+
|
|
31
|
+
Parameters
|
|
32
|
+
----------
|
|
33
|
+
parquet_file_path: str
|
|
34
|
+
Specifies the path or URL of the Parquet file to read.
|
|
35
|
+
where: str, None
|
|
36
|
+
Specifies a criterion for selecting the ticks to propagate.
|
|
37
|
+
time_assignment: str
|
|
38
|
+
Timestamps of the ticks created by `ReadParquet` are set to the start/end of the query or to the given
|
|
39
|
+
tick field depending on the `time_assignment` parameter.
|
|
40
|
+
Possible values are `start` and `end` (for `_START_TIME` and `_END_TIME`) or a field name.
|
|
41
|
+
Default: `end`
|
|
42
|
+
discard_fields: list, str, None
|
|
43
|
+
A list of fields (`list` or comma-separated string) to be discarded from the output ticks.
|
|
44
|
+
fields: list, str, None
|
|
45
|
+
A list of fields (`list` or comma-separated string) to be picked from the output ticks.
|
|
46
|
+
The opposite to `discard_fields`.
|
|
47
|
+
symbol_name_field: str, None
|
|
48
|
+
Field that is expected to contain the symbol name.
|
|
49
|
+
When this parameter is set and one or more symbols containing time series
|
|
50
|
+
(i.e. `[dbname]::[time series name]` and not just `[dbname]::`) are bound to the query or to this EP,
|
|
51
|
+
only rows belonging to those symbols will be propagated.
|
|
52
|
+
symbol: str, list of str, :class:`Source`, :class:`query`, :py:func:`eval query <onetick.py.eval>`
|
|
53
|
+
Symbol(s) from which data should be taken.
|
|
54
|
+
tick_type: str
|
|
55
|
+
Tick type.
|
|
56
|
+
Default: ANY.
|
|
57
|
+
start: :py:class:`otp.datetime <onetick.py.datetime>`
|
|
58
|
+
Start time for tick generation. By default the start time of the query will be used.
|
|
59
|
+
end: :py:class:`otp.datetime <onetick.py.datetime>`
|
|
60
|
+
End time for tick generation. By default the end time of the query will be used.
|
|
61
|
+
schema: dict
|
|
62
|
+
Dictionary of columns names with their types.
|
|
63
|
+
You should set schema manually, if you want to use fields in `onetick-py` query description
|
|
64
|
+
before its execution.
|
|
65
|
+
kwargs:
|
|
66
|
+
Deprecated. Use ``schema`` instead.
|
|
67
|
+
Dictionary of columns names with their types.
|
|
68
|
+
|
|
69
|
+
See also
|
|
70
|
+
--------
|
|
71
|
+
| **READ_FROM_PARQUET** OneTick event processor
|
|
72
|
+
| :py:meth:`onetick.py.Source.write_parquet`
|
|
73
|
+
|
|
74
|
+
Examples
|
|
75
|
+
--------
|
|
76
|
+
Simple Parquet file read:
|
|
77
|
+
|
|
78
|
+
>>> data = otp.ReadParquet("/path/to/parquet/file")
|
|
79
|
+
>>> otp.run(data) # doctest: +SKIP
|
|
80
|
+
|
|
81
|
+
Read Parquet file and filter fields:
|
|
82
|
+
|
|
83
|
+
>>> data = otp.ReadParquet("/path/to/parquet/file", fields=["some_field", "another_field"])
|
|
84
|
+
>>> otp.run(data) # doctest: +SKIP
|
|
85
|
+
|
|
86
|
+
Read Parquet file and filter rows:
|
|
87
|
+
|
|
88
|
+
>>> data = otp.ReadParquet("/path/to/parquet/file", where="PRICE > 20")
|
|
89
|
+
>>> otp.run(data) # doctest: +SKIP
|
|
90
|
+
"""
|
|
91
|
+
if self._try_default_constructor(schema=schema, **kwargs):
|
|
92
|
+
return
|
|
93
|
+
|
|
94
|
+
if parquet_file_path is None:
|
|
95
|
+
raise ValueError("Missing required parameter `parquet_file_path`")
|
|
96
|
+
|
|
97
|
+
if discard_fields and fields:
|
|
98
|
+
raise ValueError("`discard_fields` and `fields` cannot be specified at the same time")
|
|
99
|
+
|
|
100
|
+
if where is None:
|
|
101
|
+
where = ""
|
|
102
|
+
|
|
103
|
+
if discard_fields is None:
|
|
104
|
+
discard_fields = ""
|
|
105
|
+
elif isinstance(discard_fields, list):
|
|
106
|
+
discard_fields = ",".join(discard_fields)
|
|
107
|
+
|
|
108
|
+
if fields is None:
|
|
109
|
+
fields = ""
|
|
110
|
+
elif isinstance(fields, list):
|
|
111
|
+
fields = ",".join(fields)
|
|
112
|
+
|
|
113
|
+
if time_assignment in {"start", "end"}:
|
|
114
|
+
time_assignment = f"_{time_assignment}_time".upper()
|
|
115
|
+
|
|
116
|
+
super().__init__(
|
|
117
|
+
_symbols=symbol,
|
|
118
|
+
_start=start,
|
|
119
|
+
_end=end,
|
|
120
|
+
_base_ep_func=lambda: self.base_ep(
|
|
121
|
+
db=db,
|
|
122
|
+
tick_type=tick_type,
|
|
123
|
+
parquet_file_path=parquet_file_path,
|
|
124
|
+
where=where,
|
|
125
|
+
time_assignment=time_assignment,
|
|
126
|
+
discard_fields=discard_fields,
|
|
127
|
+
fields=fields,
|
|
128
|
+
symbol_name_field=symbol_name_field,
|
|
129
|
+
),
|
|
130
|
+
schema=schema,
|
|
131
|
+
**kwargs,
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
def base_ep(
|
|
135
|
+
self,
|
|
136
|
+
parquet_file_path,
|
|
137
|
+
where=None,
|
|
138
|
+
time_assignment="end",
|
|
139
|
+
discard_fields=None,
|
|
140
|
+
fields=None,
|
|
141
|
+
symbol_name_field=None,
|
|
142
|
+
db=utils.adaptive_to_default,
|
|
143
|
+
tick_type=utils.adaptive,
|
|
144
|
+
start=utils.adaptive,
|
|
145
|
+
end=utils.adaptive,
|
|
146
|
+
):
|
|
147
|
+
if not hasattr(otq, "ReadFromParquet"):
|
|
148
|
+
raise RuntimeError("Current version of OneTick don't support READ_FROM_PARQUET EP")
|
|
149
|
+
|
|
150
|
+
node_kwargs = {}
|
|
151
|
+
if symbol_name_field:
|
|
152
|
+
node_kwargs["symbol_name_field"] = symbol_name_field
|
|
153
|
+
|
|
154
|
+
src = Source(
|
|
155
|
+
otq.ReadFromParquet(
|
|
156
|
+
parquet_file_path=parquet_file_path,
|
|
157
|
+
time_assignment=time_assignment,
|
|
158
|
+
where=where,
|
|
159
|
+
discard_fields=discard_fields,
|
|
160
|
+
fields=fields,
|
|
161
|
+
**node_kwargs,
|
|
162
|
+
)
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
if db and tick_type:
|
|
166
|
+
update_node_tick_type(src, tick_type, db)
|
|
167
|
+
|
|
168
|
+
return src
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
from typing import List, Union
|
|
2
|
+
|
|
3
|
+
import onetick.py as otp
|
|
4
|
+
from onetick.py.backports import Literal
|
|
5
|
+
from onetick.py.core.source import Source
|
|
6
|
+
from onetick.py.otq import otq
|
|
7
|
+
|
|
8
|
+
from .. import types as ott
|
|
9
|
+
from .. import utils
|
|
10
|
+
from ..compatibility import is_supported_point_in_time
|
|
11
|
+
from .common import update_node_tick_type
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def PointInTime( # NOSONAR
|
|
15
|
+
source: 'Source',
|
|
16
|
+
times: List[Union[str, ott.datetime]],
|
|
17
|
+
offsets: List[int],
|
|
18
|
+
offset_type: Literal['time_msec', 'num_ticks'] = 'time_msec',
|
|
19
|
+
db=utils.adaptive_to_default,
|
|
20
|
+
tick_type=utils.adaptive,
|
|
21
|
+
symbol=utils.adaptive_to_default,
|
|
22
|
+
start=utils.adaptive,
|
|
23
|
+
end=utils.adaptive,
|
|
24
|
+
) -> 'Source':
|
|
25
|
+
"""
|
|
26
|
+
This function propagates ticks from ``source`` that are offset by
|
|
27
|
+
the specified number of milliseconds or by the specified number of ticks
|
|
28
|
+
relative to the timestamps specified in ``times``.
|
|
29
|
+
|
|
30
|
+
Output tick may be generated for each specified timestamp and offset pair.
|
|
31
|
+
|
|
32
|
+
If ``source`` doesn't have a tick with specified timestamp and offset, then output tick is not generated.
|
|
33
|
+
|
|
34
|
+
Fields **TICK_TIME** and **OFFSET** are also added to the output ticks,
|
|
35
|
+
specifying original timestamp of the tick and the offset that was specified for it.
|
|
36
|
+
|
|
37
|
+
Note
|
|
38
|
+
----
|
|
39
|
+
In order for this method to have reasonable performance,
|
|
40
|
+
the set of queried timestamps has to be relatively small.
|
|
41
|
+
|
|
42
|
+
In other words, the points in time, which the user is interested in,
|
|
43
|
+
have to be quite few in order usage of this method to be justified.
|
|
44
|
+
|
|
45
|
+
Parameters
|
|
46
|
+
----------
|
|
47
|
+
source:
|
|
48
|
+
The source from which the data will be queried.
|
|
49
|
+
times:
|
|
50
|
+
List of timestamps to get query ticks from.
|
|
51
|
+
offsets:
|
|
52
|
+
List of integers specifying offsets for each timestamp.
|
|
53
|
+
offset_type: 'time_msec' or 'num_ticks'
|
|
54
|
+
The type of offset: number of milliseconds or the number of ticks.
|
|
55
|
+
db: str
|
|
56
|
+
This parameter is used to set database part of a tick type of the OneTick graph node.
|
|
57
|
+
Should not be specified in most cases,
|
|
58
|
+
default value will be deduced depending on configuration and query structure.
|
|
59
|
+
tick_type: str
|
|
60
|
+
This parameter is used to set tick type part of a tick type of the OneTick graph node.
|
|
61
|
+
Should not be specified in most cases,
|
|
62
|
+
default value will be deduced depending on configuration and query structure.
|
|
63
|
+
symbol: str
|
|
64
|
+
This parameter is used to set bound symbol of the OneTick graph node.
|
|
65
|
+
Should not be specified in most cases,
|
|
66
|
+
default value will be deduced depending on configuration and query structure.
|
|
67
|
+
start:
|
|
68
|
+
Can be used to specify custom start time for this source.
|
|
69
|
+
By default start time of the query will be inherited when running the query.
|
|
70
|
+
end:
|
|
71
|
+
Can be used to specify custom start time for this source.
|
|
72
|
+
By default end time of the query will be inherited when running the query.
|
|
73
|
+
|
|
74
|
+
See also
|
|
75
|
+
--------
|
|
76
|
+
| **POINT_IN_TIME** OneTick event processor
|
|
77
|
+
| :meth:`onetick.py.Source.point_in_time`
|
|
78
|
+
| :func:`onetick.py.join_by_time`
|
|
79
|
+
|
|
80
|
+
Examples
|
|
81
|
+
--------
|
|
82
|
+
|
|
83
|
+
Quotes for testing:
|
|
84
|
+
|
|
85
|
+
.. testcode::
|
|
86
|
+
|
|
87
|
+
qte = otp.Ticks(ASK_PRICE=[20, 21, 22, 23, 24, 25], BID_PRICE=[20, 21, 22, 23, 24, 25])
|
|
88
|
+
print(otp.run(qte))
|
|
89
|
+
|
|
90
|
+
.. testoutput::
|
|
91
|
+
|
|
92
|
+
Time ASK_PRICE BID_PRICE
|
|
93
|
+
0 2003-12-01 00:00:00.000 20 20
|
|
94
|
+
1 2003-12-01 00:00:00.001 21 21
|
|
95
|
+
2 2003-12-01 00:00:00.002 22 22
|
|
96
|
+
3 2003-12-01 00:00:00.003 23 23
|
|
97
|
+
4 2003-12-01 00:00:00.004 24 24
|
|
98
|
+
5 2003-12-01 00:00:00.005 25 25
|
|
99
|
+
|
|
100
|
+
Getting quotes exactly at specified timestamps:
|
|
101
|
+
|
|
102
|
+
.. testcode::
|
|
103
|
+
:skipif: not is_supported_point_in_time()
|
|
104
|
+
|
|
105
|
+
data = otp.PointInTime(qte,
|
|
106
|
+
times=[otp.dt(2003, 12, 1, 0, 0, 0, 1000), '20031201000000.003'],
|
|
107
|
+
offsets=[0])
|
|
108
|
+
print(otp.run(data))
|
|
109
|
+
|
|
110
|
+
.. testoutput::
|
|
111
|
+
|
|
112
|
+
Time ASK_PRICE BID_PRICE TICK_TIME OFFSET
|
|
113
|
+
0 2003-12-01 00:00:00.001 21 21 2003-12-01 00:00:00.001 0
|
|
114
|
+
1 2003-12-01 00:00:00.003 23 23 2003-12-01 00:00:00.003 0
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
Offset may be positive or negative.
|
|
118
|
+
If several offsets are specified, several output ticks may be generated for a single timestamp:
|
|
119
|
+
|
|
120
|
+
.. testcode::
|
|
121
|
+
:skipif: not is_supported_point_in_time()
|
|
122
|
+
|
|
123
|
+
data = otp.PointInTime(qte,
|
|
124
|
+
times=[otp.dt(2003, 12, 1, 0, 0, 0, 3000)],
|
|
125
|
+
offsets=[0, 1])
|
|
126
|
+
print(otp.run(data))
|
|
127
|
+
|
|
128
|
+
.. testoutput::
|
|
129
|
+
|
|
130
|
+
Time ASK_PRICE BID_PRICE TICK_TIME OFFSET
|
|
131
|
+
0 2003-12-01 00:00:00.003 23 23 2003-12-01 00:00:00.003 0
|
|
132
|
+
1 2003-12-01 00:00:00.003 24 24 2003-12-01 00:00:00.004 1
|
|
133
|
+
|
|
134
|
+
By default the number of milliseconds is used as an offset.
|
|
135
|
+
You can also specify the number of ticks as an offset:
|
|
136
|
+
|
|
137
|
+
.. testcode::
|
|
138
|
+
:skipif: not is_supported_point_in_time()
|
|
139
|
+
|
|
140
|
+
data = otp.PointInTime(qte,
|
|
141
|
+
times=[otp.dt(2003, 12, 1, 0, 0, 0, 3000)],
|
|
142
|
+
offsets=[-1, 1],
|
|
143
|
+
offset_type='num_ticks')
|
|
144
|
+
print(otp.run(data))
|
|
145
|
+
|
|
146
|
+
.. testoutput::
|
|
147
|
+
|
|
148
|
+
Time ASK_PRICE BID_PRICE TICK_TIME OFFSET
|
|
149
|
+
0 2003-12-01 00:00:00.003 22 22 2003-12-01 00:00:00.002 -1
|
|
150
|
+
1 2003-12-01 00:00:00.003 24 24 2003-12-01 00:00:00.004 1
|
|
151
|
+
"""
|
|
152
|
+
if not is_supported_point_in_time():
|
|
153
|
+
raise RuntimeError('PointInTime event processor is not supported on this OneTick version')
|
|
154
|
+
|
|
155
|
+
res = otp.Source(_symbols=symbol, _start=start, _end=end)
|
|
156
|
+
|
|
157
|
+
times = [
|
|
158
|
+
t if isinstance(t, str) else ott._format_datetime(t, '%Y%m%d%H%M%S.%f', add_nano_suffix=True)
|
|
159
|
+
for t in times or []
|
|
160
|
+
]
|
|
161
|
+
|
|
162
|
+
if offset_type not in ('time_msec', 'num_ticks'):
|
|
163
|
+
raise ValueError(f"Wrong value for parameter 'offset_type': {offset_type}")
|
|
164
|
+
|
|
165
|
+
query_name = source._store_in_tmp_otq(
|
|
166
|
+
res._tmp_otq,
|
|
167
|
+
operation_suffix='point_in_time',
|
|
168
|
+
# set default symbol, even if it's not set by user, symbol's value doesn't matter in this case
|
|
169
|
+
symbols=otp.config.get('default_symbol', 'ANY')
|
|
170
|
+
)
|
|
171
|
+
otq_query = f'THIS::{query_name}'
|
|
172
|
+
|
|
173
|
+
pit_params = dict(
|
|
174
|
+
otq_query=otq_query,
|
|
175
|
+
offset_type=offset_type.upper(),
|
|
176
|
+
offsets=','.join(map(str, offsets)),
|
|
177
|
+
times=','.join(map(str, times)),
|
|
178
|
+
)
|
|
179
|
+
res.source(otq.PointInTime(**pit_params))
|
|
180
|
+
|
|
181
|
+
res.schema.set(**source.schema)
|
|
182
|
+
res.schema.update(
|
|
183
|
+
**{
|
|
184
|
+
'TICK_TIME': otp.nsectime,
|
|
185
|
+
'OFFSET': int,
|
|
186
|
+
}
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
update_node_tick_type(res, tick_type, db)
|
|
190
|
+
|
|
191
|
+
return res
|