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.
- locator_parser/__init__.py +0 -0
- locator_parser/acl.py +73 -0
- locator_parser/actions.py +262 -0
- locator_parser/common.py +368 -0
- locator_parser/io.py +43 -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 +279 -0
- onetick/lib/__init__.py +4 -0
- onetick/lib/instance.py +141 -0
- onetick/py/__init__.py +293 -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 +648 -0
- onetick/py/aggregations/_docs.py +948 -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 +501 -0
- onetick/py/aggregations/other.py +1014 -0
- onetick/py/backports.py +26 -0
- onetick/py/cache.py +374 -0
- onetick/py/callback/__init__.py +5 -0
- onetick/py/callback/callback.py +276 -0
- onetick/py/callback/callbacks.py +131 -0
- onetick/py/compatibility.py +798 -0
- onetick/py/configuration.py +771 -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 +2312 -0
- onetick/py/core/_internal/_state_vars.py +93 -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 +809 -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 +272 -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 +1002 -0
- onetick/py/core/_source/source_methods/joins.py +1413 -0
- onetick/py/core/_source/source_methods/merges.py +605 -0
- onetick/py/core/_source/source_methods/misc.py +1455 -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 +986 -0
- onetick/py/core/_source/symbol.py +205 -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 +216 -0
- onetick/py/core/column_operations/_methods/methods.py +292 -0
- onetick/py/core/column_operations/_methods/op_types.py +160 -0
- onetick/py/core/column_operations/accessors/__init__.py +0 -0
- onetick/py/core/column_operations/accessors/_accessor.py +28 -0
- onetick/py/core/column_operations/accessors/decimal_accessor.py +104 -0
- onetick/py/core/column_operations/accessors/dt_accessor.py +537 -0
- onetick/py/core/column_operations/accessors/float_accessor.py +184 -0
- onetick/py/core/column_operations/accessors/str_accessor.py +1367 -0
- onetick/py/core/column_operations/base.py +1121 -0
- onetick/py/core/cut_builder.py +150 -0
- onetick/py/core/db_constants.py +20 -0
- onetick/py/core/eval_query.py +245 -0
- onetick/py/core/lambda_object.py +441 -0
- onetick/py/core/multi_output_source.py +232 -0
- onetick/py/core/per_tick_script.py +2256 -0
- onetick/py/core/query_inspector.py +464 -0
- onetick/py/core/source.py +1744 -0
- onetick/py/db/__init__.py +2 -0
- onetick/py/db/_inspection.py +1128 -0
- onetick/py/db/db.py +1327 -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 +2398 -0
- onetick/py/license.py +190 -0
- onetick/py/log.py +88 -0
- onetick/py/math.py +935 -0
- onetick/py/misc.py +470 -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 +216 -0
- onetick/py/pyomd_mock.py +47 -0
- onetick/py/run.py +916 -0
- onetick/py/servers.py +173 -0
- onetick/py/session.py +1347 -0
- onetick/py/sources/__init__.py +19 -0
- onetick/py/sources/cache.py +167 -0
- onetick/py/sources/common.py +128 -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 +1045 -0
- onetick/py/sources/empty.py +94 -0
- onetick/py/sources/odbc.py +337 -0
- onetick/py/sources/order_book.py +271 -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 +374 -0
- onetick/py/sources/ticks.py +825 -0
- onetick/py/sql.py +70 -0
- onetick/py/state.py +251 -0
- onetick/py/types.py +2131 -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 +498 -0
- onetick/py/utils/query.py +49 -0
- onetick/py/utils/render.py +1374 -0
- onetick/py/utils/script.py +244 -0
- onetick/py/utils/temp.py +471 -0
- onetick/py/utils/types.py +120 -0
- onetick/py/utils/tz.py +84 -0
- onetick_py-1.177.0.dist-info/METADATA +137 -0
- onetick_py-1.177.0.dist-info/RECORD +152 -0
- onetick_py-1.177.0.dist-info/WHEEL +5 -0
- onetick_py-1.177.0.dist-info/entry_points.txt +2 -0
- onetick_py-1.177.0.dist-info/licenses/LICENSE +21 -0
- onetick_py-1.177.0.dist-info/top_level.txt +2 -0
onetick/py/misc.py
ADDED
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
from onetick.py.compatibility import is_sha2_hashing_supported
|
|
2
|
+
from onetick.py.core.column_operations.base import _Operation
|
|
3
|
+
from onetick.py.types import value2str, string
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def bit_and(value1, value2):
|
|
7
|
+
"""
|
|
8
|
+
Performs the logical AND operation on each pair of corresponding bits of the parameters.
|
|
9
|
+
|
|
10
|
+
Parameters
|
|
11
|
+
----------
|
|
12
|
+
value1: int, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
|
|
13
|
+
value2: int, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
|
|
14
|
+
|
|
15
|
+
Returns
|
|
16
|
+
-------
|
|
17
|
+
:py:class:`~onetick.py.Operation`
|
|
18
|
+
|
|
19
|
+
Examples
|
|
20
|
+
--------
|
|
21
|
+
Basic example:
|
|
22
|
+
|
|
23
|
+
>>> data = otp.Tick(A=1)
|
|
24
|
+
>>> data['AND'] = otp.bit_and(2, 3)
|
|
25
|
+
>>> otp.run(data)
|
|
26
|
+
Time A AND
|
|
27
|
+
0 2003-12-01 1 2
|
|
28
|
+
|
|
29
|
+
You can also pass :py:class:`~onetick.py.Column` as parameter:
|
|
30
|
+
|
|
31
|
+
>>> data = otp.Tick(A=1)
|
|
32
|
+
>>> data['AND'] = otp.bit_and(data['A'], 1)
|
|
33
|
+
>>> otp.run(data)
|
|
34
|
+
Time A AND
|
|
35
|
+
0 2003-12-01 1 1
|
|
36
|
+
|
|
37
|
+
Or use :py:class:`~onetick.py.Operation` as parameter:
|
|
38
|
+
|
|
39
|
+
>>> data = otp.Tick(A=1)
|
|
40
|
+
>>> data['AND'] = otp.bit_and(data['A'] * 2, 3)
|
|
41
|
+
>>> otp.run(data)
|
|
42
|
+
Time A AND
|
|
43
|
+
0 2003-12-01 1 2
|
|
44
|
+
"""
|
|
45
|
+
return _Operation(
|
|
46
|
+
op_func=lambda v1, v2: (f'BIT_AND({value2str(v1)}, {value2str(v2)})', int),
|
|
47
|
+
op_params=[value1, value2],
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def bit_or(value1, value2):
|
|
52
|
+
"""
|
|
53
|
+
Performs the logical OR operation on each pair of corresponding bits of the parameters.
|
|
54
|
+
|
|
55
|
+
Parameters
|
|
56
|
+
----------
|
|
57
|
+
value1: int, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
|
|
58
|
+
value2: int, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
|
|
59
|
+
|
|
60
|
+
Returns
|
|
61
|
+
-------
|
|
62
|
+
:py:class:`~onetick.py.Operation`
|
|
63
|
+
|
|
64
|
+
Examples
|
|
65
|
+
--------
|
|
66
|
+
Basic example:
|
|
67
|
+
|
|
68
|
+
>>> data = otp.Tick(A=1)
|
|
69
|
+
>>> data['OR'] = otp.bit_or(2, 1)
|
|
70
|
+
>>> otp.run(data)
|
|
71
|
+
Time A OR
|
|
72
|
+
0 2003-12-01 1 3
|
|
73
|
+
|
|
74
|
+
You can also pass :py:class:`~onetick.py.Column` as parameter:
|
|
75
|
+
|
|
76
|
+
>>> data = otp.Tick(A=1)
|
|
77
|
+
>>> data['OR'] = otp.bit_or(data['A'], 0)
|
|
78
|
+
>>> otp.run(data)
|
|
79
|
+
Time A OR
|
|
80
|
+
0 2003-12-01 1 1
|
|
81
|
+
|
|
82
|
+
Or use :py:class:`~onetick.py.Operation` as parameter:
|
|
83
|
+
|
|
84
|
+
>>> data = otp.Tick(A=1)
|
|
85
|
+
>>> data['OR'] = otp.bit_or(data['A'] * 2, 3)
|
|
86
|
+
>>> otp.run(data)
|
|
87
|
+
Time A OR
|
|
88
|
+
0 2003-12-01 1 3
|
|
89
|
+
"""
|
|
90
|
+
return _Operation(
|
|
91
|
+
op_func=lambda v1, v2: (f'BIT_OR({value2str(v1)}, {value2str(v2)})', int),
|
|
92
|
+
op_params=[value1, value2],
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def bit_xor(value1, value2):
|
|
97
|
+
"""
|
|
98
|
+
Performs the logical XOR operation on each pair of corresponding bits of the parameters.
|
|
99
|
+
|
|
100
|
+
Parameters
|
|
101
|
+
----------
|
|
102
|
+
value1: int, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
|
|
103
|
+
value2: int, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
|
|
104
|
+
|
|
105
|
+
Returns
|
|
106
|
+
-------
|
|
107
|
+
:py:class:`~onetick.py.Operation`
|
|
108
|
+
|
|
109
|
+
Examples
|
|
110
|
+
--------
|
|
111
|
+
Basic example:
|
|
112
|
+
|
|
113
|
+
>>> data = otp.Tick(A=1)
|
|
114
|
+
>>> data['XOR'] = otp.bit_xor(0b111, 0b011)
|
|
115
|
+
>>> otp.run(data)
|
|
116
|
+
Time A XOR
|
|
117
|
+
0 2003-12-01 1 4
|
|
118
|
+
|
|
119
|
+
You can also pass :py:class:`~onetick.py.Column` as parameter:
|
|
120
|
+
|
|
121
|
+
>>> data = otp.Tick(A=0b001)
|
|
122
|
+
>>> data['XOR'] = otp.bit_xor(data['A'], 0b011)
|
|
123
|
+
>>> otp.run(data)
|
|
124
|
+
Time A XOR
|
|
125
|
+
0 2003-12-01 1 2
|
|
126
|
+
|
|
127
|
+
Or use :py:class:`~onetick.py.Operation` as parameter:
|
|
128
|
+
|
|
129
|
+
>>> data = otp.Tick(A=0b001)
|
|
130
|
+
>>> data['XOR'] = otp.bit_xor(data['A'] * 2, 0b011)
|
|
131
|
+
>>> otp.run(data)
|
|
132
|
+
Time A XOR
|
|
133
|
+
0 2003-12-01 1 1
|
|
134
|
+
"""
|
|
135
|
+
return _Operation(
|
|
136
|
+
op_func=lambda v1, v2: (f'BIT_XOR({value2str(v1)}, {value2str(v2)})', int),
|
|
137
|
+
op_params=[value1, value2],
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def bit_not(value):
|
|
142
|
+
"""
|
|
143
|
+
Performs the logical NOT operation on each bit of the ``value``.
|
|
144
|
+
|
|
145
|
+
Parameters
|
|
146
|
+
----------
|
|
147
|
+
value: int, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
|
|
148
|
+
|
|
149
|
+
Returns
|
|
150
|
+
-------
|
|
151
|
+
:py:class:`~onetick.py.Operation`
|
|
152
|
+
|
|
153
|
+
Examples
|
|
154
|
+
--------
|
|
155
|
+
Basic example:
|
|
156
|
+
|
|
157
|
+
>>> data = otp.Tick(A=1)
|
|
158
|
+
>>> data['NOT'] = otp.bit_not(1)
|
|
159
|
+
>>> otp.run(data)
|
|
160
|
+
Time A NOT
|
|
161
|
+
0 2003-12-01 1 -2
|
|
162
|
+
|
|
163
|
+
You can also pass :py:class:`~onetick.py.Column` as parameter:
|
|
164
|
+
|
|
165
|
+
>>> data = otp.Tick(A=1)
|
|
166
|
+
>>> data['NOT'] = otp.bit_not(data['A'])
|
|
167
|
+
>>> otp.run(data)
|
|
168
|
+
Time A NOT
|
|
169
|
+
0 2003-12-01 1 -2
|
|
170
|
+
|
|
171
|
+
Or use :py:class:`~onetick.py.Operation` as parameter:
|
|
172
|
+
|
|
173
|
+
>>> data = otp.Tick(A=1)
|
|
174
|
+
>>> data['NOT'] = otp.bit_not(data['A'] * 2)
|
|
175
|
+
>>> otp.run(data)
|
|
176
|
+
Time A NOT
|
|
177
|
+
0 2003-12-01 1 -3
|
|
178
|
+
"""
|
|
179
|
+
return _Operation(
|
|
180
|
+
op_func=lambda v: (f'BIT_NOT({value2str(v)})', int),
|
|
181
|
+
op_params=[value],
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def bit_at(value, index):
|
|
186
|
+
"""
|
|
187
|
+
Return bit from ``value`` at ``index`` position from the end (zero-based).
|
|
188
|
+
|
|
189
|
+
Parameters
|
|
190
|
+
----------
|
|
191
|
+
value: int, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
|
|
192
|
+
index: int, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
|
|
193
|
+
|
|
194
|
+
Returns
|
|
195
|
+
-------
|
|
196
|
+
:py:class:`~onetick.py.Operation`
|
|
197
|
+
|
|
198
|
+
Examples
|
|
199
|
+
--------
|
|
200
|
+
Basic example:
|
|
201
|
+
|
|
202
|
+
>>> data = otp.Tick(A=1)
|
|
203
|
+
>>> data['AT'] = otp.bit_at(0b0010, 1)
|
|
204
|
+
>>> otp.run(data)
|
|
205
|
+
Time A AT
|
|
206
|
+
0 2003-12-01 1 1
|
|
207
|
+
|
|
208
|
+
You can also pass :py:class:`~onetick.py.Column` as parameter:
|
|
209
|
+
|
|
210
|
+
>>> data = otp.Tick(A=0b0001)
|
|
211
|
+
>>> data['AT'] = otp.bit_at(data['A'], 0)
|
|
212
|
+
>>> otp.run(data)
|
|
213
|
+
Time A AT
|
|
214
|
+
0 2003-12-01 1 1
|
|
215
|
+
|
|
216
|
+
Or use :py:class:`~onetick.py.Operation` as parameter:
|
|
217
|
+
|
|
218
|
+
>>> data = otp.Tick(A=0b0001)
|
|
219
|
+
>>> data['AT'] = otp.bit_at(data['A'] * 2, 0)
|
|
220
|
+
>>> otp.run(data)
|
|
221
|
+
Time A AT
|
|
222
|
+
0 2003-12-01 1 0
|
|
223
|
+
"""
|
|
224
|
+
return _Operation(
|
|
225
|
+
op_func=lambda v, i: (f'BIT_AT({value2str(v)}, {value2str(i)})', int),
|
|
226
|
+
op_params=[value, index],
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
class _HashCodeOperator(_Operation):
|
|
231
|
+
HASH_TYPES = {
|
|
232
|
+
'sha_1': string[40],
|
|
233
|
+
'sha_224': string[56],
|
|
234
|
+
'sha_256': string[64],
|
|
235
|
+
'sha_384': string[96],
|
|
236
|
+
'sha_512': string[128],
|
|
237
|
+
'lookup3': string[16],
|
|
238
|
+
'metro_hash_64': string[16],
|
|
239
|
+
'city_hash_64': string[16],
|
|
240
|
+
'murmur_hash_64': string[16],
|
|
241
|
+
'sum_of_bytes': string[16],
|
|
242
|
+
'default': string[16],
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
def __init__(self, value, hash_type):
|
|
246
|
+
if hash_type not in self.HASH_TYPES:
|
|
247
|
+
raise ValueError(f'Incorrect hash_type was passed: {hash_type}')
|
|
248
|
+
|
|
249
|
+
if hash_type.startswith('sha') and not is_sha2_hashing_supported():
|
|
250
|
+
raise RuntimeError("SHA2 hashing unavailable on current OneTick version")
|
|
251
|
+
|
|
252
|
+
dtype = self.HASH_TYPES[hash_type]
|
|
253
|
+
|
|
254
|
+
def _repr(_value, _hash_type):
|
|
255
|
+
_value = value2str(_value)
|
|
256
|
+
_hash_type = value2str(_hash_type.upper())
|
|
257
|
+
|
|
258
|
+
return f'COMPUTE_HASH_CODE_STR({_value}, {_hash_type})', dtype
|
|
259
|
+
|
|
260
|
+
super().__init__(op_func=_repr,
|
|
261
|
+
op_params=[value, hash_type])
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def hash_code(value, hash_type):
|
|
265
|
+
"""
|
|
266
|
+
Returns hexadecimal encoded hash code for the specified string with the specified hash function.
|
|
267
|
+
|
|
268
|
+
Note
|
|
269
|
+
----
|
|
270
|
+
Fixed sized string hash result could differ from the same variable length string due to trailing nulls.
|
|
271
|
+
|
|
272
|
+
Parameters
|
|
273
|
+
----------
|
|
274
|
+
value: str, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
|
|
275
|
+
value to calculate hash from
|
|
276
|
+
hash_type: str
|
|
277
|
+
one of following hash types:
|
|
278
|
+
|
|
279
|
+
* `sha_1`
|
|
280
|
+
* `sha_224`
|
|
281
|
+
* `sha_256`
|
|
282
|
+
* `sha_384`
|
|
283
|
+
* `sha_512`
|
|
284
|
+
* `lookup3`
|
|
285
|
+
* `metro_hash_64`
|
|
286
|
+
* `city_hash_64`
|
|
287
|
+
* `murmur_hash_64`
|
|
288
|
+
* `sum_of_bytes`
|
|
289
|
+
* `default`
|
|
290
|
+
|
|
291
|
+
Returns
|
|
292
|
+
-------
|
|
293
|
+
:py:class:`~onetick.py.Operation`
|
|
294
|
+
|
|
295
|
+
See also
|
|
296
|
+
--------
|
|
297
|
+
**COMPUTE_HASH_CODE_STR** OneTick built-in function
|
|
298
|
+
|
|
299
|
+
Examples
|
|
300
|
+
--------
|
|
301
|
+
Basic example:
|
|
302
|
+
|
|
303
|
+
.. testcode::
|
|
304
|
+
:skipif: not is_sha2_hashing_supported()
|
|
305
|
+
|
|
306
|
+
data = otp.Tick(A=1)
|
|
307
|
+
data['HASH'] = otp.hash_code('some_string', 'sha_224')
|
|
308
|
+
df = otp.run(data)
|
|
309
|
+
print(df)
|
|
310
|
+
|
|
311
|
+
.. testoutput::
|
|
312
|
+
|
|
313
|
+
Time A HASH
|
|
314
|
+
0 2003-12-01 1 12d3f96511450121e6343b5ace065ec9de7b2a946b86f7dfab8ac51f
|
|
315
|
+
|
|
316
|
+
You can also pass :py:class:`~onetick.py.Operation` as a ``value`` parameter:
|
|
317
|
+
|
|
318
|
+
.. testcode::
|
|
319
|
+
:skipif: not is_sha2_hashing_supported()
|
|
320
|
+
|
|
321
|
+
data = otp.Tick(A=otp.varstring('some_string'))
|
|
322
|
+
data['HASH'] = otp.hash_code(data['A'], 'sha_224')
|
|
323
|
+
df = otp.run(data)
|
|
324
|
+
print(df)
|
|
325
|
+
|
|
326
|
+
.. testoutput::
|
|
327
|
+
|
|
328
|
+
Time A HASH
|
|
329
|
+
0 2003-12-01 some_string 12d3f96511450121e6343b5ace065ec9de7b2a946b86f7dfab8ac51f
|
|
330
|
+
|
|
331
|
+
For the same string stored in strings with different fixed sizes, the hash value may differ:
|
|
332
|
+
|
|
333
|
+
.. testcode::
|
|
334
|
+
:skipif: not is_sha2_hashing_supported()
|
|
335
|
+
|
|
336
|
+
test_str = 'example'
|
|
337
|
+
data = otp.Tick(A=otp.string[128](test_str))
|
|
338
|
+
data['Fixed'] = otp.hash_code(data['A'], 'sha_1')
|
|
339
|
+
data['Var'] = otp.hash_code(otp.varstring(test_str), 'sha_1')
|
|
340
|
+
df = otp.run(data)
|
|
341
|
+
print(df)
|
|
342
|
+
|
|
343
|
+
.. testoutput::
|
|
344
|
+
|
|
345
|
+
Time A Fixed Var
|
|
346
|
+
0 2003-12-01 example bdab82ec533c09646e45f15dc4e7ad2d2d1a8ff1 c3499c2729730a7f807efb8676a92dcb6f8a3f8f
|
|
347
|
+
"""
|
|
348
|
+
return _HashCodeOperator(value, hash_type)
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
def get_symbology_mapping(dest_symbology, src_symbology=None, symbol=None, timestamp=None):
|
|
352
|
+
"""
|
|
353
|
+
Translates and returns the symbol in ``dest_symbology`` using the current timestamp as the symbol date.
|
|
354
|
+
|
|
355
|
+
The remaining optional parameters are specified to overwrite
|
|
356
|
+
the symbology of the current symbol, the current symbol, and the timestamp, respectively.
|
|
357
|
+
|
|
358
|
+
Parameters
|
|
359
|
+
----------
|
|
360
|
+
dest_symbology: str, :py:class:`~onetick.py.Operation`
|
|
361
|
+
Symbology to translate the symbol name to.
|
|
362
|
+
src_symbology: str, :py:class:`~onetick.py.Operation`
|
|
363
|
+
Symbology from which the symbol will be translated.
|
|
364
|
+
Will be taken from the input symbol name if it has symbology part in it
|
|
365
|
+
or defaults to the symbology of the input database, which is specified in the locator file.
|
|
366
|
+
symbol: str, :py:class:`~onetick.py.Operation`
|
|
367
|
+
Used to specify the input symbol name.
|
|
368
|
+
By default the symbol name of the query is used.
|
|
369
|
+
timestamp: :py:class:`~onetick.py.Operation`
|
|
370
|
+
They symbol date to use when translating symbol name.
|
|
371
|
+
By default the current timestamp of the tick is used.
|
|
372
|
+
|
|
373
|
+
Returns
|
|
374
|
+
-------
|
|
375
|
+
:py:class:`~onetick.py.Operation`
|
|
376
|
+
|
|
377
|
+
See also
|
|
378
|
+
--------
|
|
379
|
+
:py:class:`onetick.py.SymbologyMapping`
|
|
380
|
+
|
|
381
|
+
Examples
|
|
382
|
+
--------
|
|
383
|
+
Get the symbol name in OID symbology:
|
|
384
|
+
|
|
385
|
+
>>> data = otp.Tick(A=1, db=None)
|
|
386
|
+
>>> data['SYMBOLOGY_MAPPING'] = otp.get_symbology_mapping('OID')
|
|
387
|
+
>>> otp.run(data, symbols='TDEQ::US_COMP::AAPL', # doctest: +SKIP
|
|
388
|
+
... date=otp.dt(2022, 1, 3))
|
|
389
|
+
Time A SYMBOLOGY_MAPPING
|
|
390
|
+
0 2022-01-03 1 9706
|
|
391
|
+
|
|
392
|
+
Override source symbology, symbol and symbol date
|
|
393
|
+
(Also note that parameters can be set from columns):
|
|
394
|
+
|
|
395
|
+
>>> data = otp.Tick(A=1, db=None, SYMBOL='MSFT')
|
|
396
|
+
>>> data['SYMBOLOGY_MAPPING'] = otp.get_symbology_mapping('OID', 'TDEQ', data['SYMBOL'], otp.dt(2022, 1, 3))
|
|
397
|
+
>>> otp.run(data, symbols='US_COMP::AAPL', # doctest: +SKIP
|
|
398
|
+
... date=otp.dt(2022, 1, 3))
|
|
399
|
+
Time A SYMBOLOGY_MAPPING
|
|
400
|
+
0 2022-01-03 1 109037
|
|
401
|
+
"""
|
|
402
|
+
params_correct = (
|
|
403
|
+
all(v is not None for v in [src_symbology, symbol, timestamp])
|
|
404
|
+
or all(v is not None for v in [src_symbology, symbol])
|
|
405
|
+
or not any(v is not None for v in [src_symbology, symbol, timestamp])
|
|
406
|
+
)
|
|
407
|
+
if not params_correct:
|
|
408
|
+
raise ValueError("Parameters 'src_symbology' and 'symbol' or"
|
|
409
|
+
" 'src_symbology', 'symbol' and 'timestamp' must be specified together")
|
|
410
|
+
|
|
411
|
+
def op_func(dest_symbology, src_symbology, symbol, timestamp):
|
|
412
|
+
params = [value2str(dest_symbology)]
|
|
413
|
+
for param in [src_symbology, symbol, timestamp]:
|
|
414
|
+
if param is not None:
|
|
415
|
+
params.append(value2str(param))
|
|
416
|
+
params_str = ','.join(params)
|
|
417
|
+
return f'GET_SYMBOLOGY_MAPPING({params_str})', str
|
|
418
|
+
|
|
419
|
+
return _Operation(
|
|
420
|
+
op_func=op_func,
|
|
421
|
+
op_params=[dest_symbology, src_symbology, symbol, timestamp],
|
|
422
|
+
dtype=str,
|
|
423
|
+
)
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
def get_onetick_version():
|
|
427
|
+
"""
|
|
428
|
+
Returns the string with the build name of OneTick.
|
|
429
|
+
Build string may have different format depending on OneTick version.
|
|
430
|
+
|
|
431
|
+
Note
|
|
432
|
+
----
|
|
433
|
+
The version is returned from the server where the query executes.
|
|
434
|
+
Usually it's the same server where the database specified in :func:`otp.run <onetick.py.run>` resides.
|
|
435
|
+
|
|
436
|
+
Returns
|
|
437
|
+
-------
|
|
438
|
+
:py:class:`~onetick.py.Operation`
|
|
439
|
+
|
|
440
|
+
Examples
|
|
441
|
+
--------
|
|
442
|
+
>>> data = otp.Tick(VERSION=otp.get_onetick_version())
|
|
443
|
+
>>> otp.run(data, symbols='US_COMP::') # doctest: +SKIP
|
|
444
|
+
Time VERSION
|
|
445
|
+
0 2003-12-01 BUILD_rel_20250727_update2 (20250727120000)
|
|
446
|
+
"""
|
|
447
|
+
return _Operation(
|
|
448
|
+
op_func=lambda: ('FORMATMESSAGE("%1% (%2%)", GET_ONETICK_RELEASE(), GET_ONETICK_VERSION())', str),
|
|
449
|
+
)
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
def get_username():
|
|
453
|
+
"""
|
|
454
|
+
Returns the string with the name of the user executing the query
|
|
455
|
+
and authenticated login name of the user.
|
|
456
|
+
|
|
457
|
+
Returns
|
|
458
|
+
-------
|
|
459
|
+
:py:class:`~onetick.py.Operation`
|
|
460
|
+
|
|
461
|
+
Examples
|
|
462
|
+
--------
|
|
463
|
+
>>> data = otp.Tick(USER=otp.get_username())
|
|
464
|
+
>>> otp.run(data) # doctest: +SKIP
|
|
465
|
+
Time USER
|
|
466
|
+
0 2003-12-01 onetick (onetick)
|
|
467
|
+
"""
|
|
468
|
+
return _Operation(
|
|
469
|
+
op_func=lambda: ('FORMATMESSAGE("%1% (%2%)", GETUSER(), GET_AUTHENTICATED_USERNAME())', str),
|
|
470
|
+
)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from .eps import (
|
|
2
|
+
OqdSourceDprcMain,
|
|
3
|
+
OqdCorpAction,
|
|
4
|
+
OqdCorpDailyFactor,
|
|
5
|
+
OqdSourceBbgbsym,
|
|
6
|
+
OqdSourceBbgbtkr,
|
|
7
|
+
OqdSourceBbgfgc,
|
|
8
|
+
OqdSourceBbgfgs,
|
|
9
|
+
OqdSourceBbgfgv,
|
|
10
|
+
OqdSourceBbgoid,
|
|
11
|
+
OqdSourceCacs,
|
|
12
|
+
OqdSourceCact,
|
|
13
|
+
OqdSourceDes,
|
|
14
|
+
OqdSourceDprcAll,
|
|
15
|
+
OqdSourceDprcExch,
|
|
16
|
+
OqdSourceSho,
|
|
17
|
+
OqdSourceXoid,
|
|
18
|
+
OqdSourceXref,
|
|
19
|
+
OqdSourceXsym,
|
|
20
|
+
OqdTranslate,
|
|
21
|
+
)
|
|
22
|
+
from .sources import OHLCV, CorporateActions, DescriptiveFields
|