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
onetick/py/misc.py
ADDED
|
@@ -0,0 +1,437 @@
|
|
|
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
|
+
class _BitAndOperator(_Operation):
|
|
7
|
+
def __init__(self, value1, value2):
|
|
8
|
+
super().__init__(dtype=int)
|
|
9
|
+
|
|
10
|
+
def _repr(_value1, _value2):
|
|
11
|
+
return f'BIT_AND({str(_value1)}, {str(_value2)})'
|
|
12
|
+
|
|
13
|
+
self._repr = _repr(value1, value2)
|
|
14
|
+
|
|
15
|
+
def __str__(self):
|
|
16
|
+
return self._repr
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def bit_and(value1, value2):
|
|
20
|
+
"""
|
|
21
|
+
Performs the logical AND operation on each pair of corresponding bits of the parameters.
|
|
22
|
+
|
|
23
|
+
Parameters
|
|
24
|
+
----------
|
|
25
|
+
value1: int, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
|
|
26
|
+
value2: int, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
|
|
27
|
+
|
|
28
|
+
Returns
|
|
29
|
+
-------
|
|
30
|
+
:py:class:`~onetick.py.Operation`
|
|
31
|
+
|
|
32
|
+
Examples
|
|
33
|
+
--------
|
|
34
|
+
Basic example:
|
|
35
|
+
|
|
36
|
+
>>> data = otp.Tick(A=1)
|
|
37
|
+
>>> data['AND'] = otp.bit_and(2, 3)
|
|
38
|
+
>>> otp.run(data)
|
|
39
|
+
Time A AND
|
|
40
|
+
0 2003-12-01 1 2
|
|
41
|
+
|
|
42
|
+
You can also pass :py:class:`~onetick.py.Column` as parameter:
|
|
43
|
+
|
|
44
|
+
>>> data = otp.Tick(A=1)
|
|
45
|
+
>>> data['AND'] = otp.bit_and(data['A'], 1)
|
|
46
|
+
>>> otp.run(data)
|
|
47
|
+
Time A AND
|
|
48
|
+
0 2003-12-01 1 1
|
|
49
|
+
|
|
50
|
+
Or use :py:class:`~onetick.py.Operation` as parameter:
|
|
51
|
+
|
|
52
|
+
>>> data = otp.Tick(A=1)
|
|
53
|
+
>>> data['AND'] = otp.bit_and(data['A'] * 2, 3)
|
|
54
|
+
>>> otp.run(data)
|
|
55
|
+
Time A AND
|
|
56
|
+
0 2003-12-01 1 2
|
|
57
|
+
"""
|
|
58
|
+
return _BitAndOperator(value1, value2)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class _BitOrOperator(_Operation):
|
|
62
|
+
def __init__(self, value1, value2):
|
|
63
|
+
super().__init__(dtype=int)
|
|
64
|
+
|
|
65
|
+
def _repr(_value1, _value2):
|
|
66
|
+
return f'BIT_OR({str(_value1)}, {str(_value2)})'
|
|
67
|
+
|
|
68
|
+
self._repr = _repr(value1, value2)
|
|
69
|
+
|
|
70
|
+
def __str__(self):
|
|
71
|
+
return self._repr
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def bit_or(value1, value2):
|
|
75
|
+
"""
|
|
76
|
+
Performs the logical OR operation on each pair of corresponding bits of the parameters.
|
|
77
|
+
|
|
78
|
+
Parameters
|
|
79
|
+
----------
|
|
80
|
+
value1: int, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
|
|
81
|
+
value2: int, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
|
|
82
|
+
|
|
83
|
+
Returns
|
|
84
|
+
-------
|
|
85
|
+
:py:class:`~onetick.py.Operation`
|
|
86
|
+
|
|
87
|
+
Examples
|
|
88
|
+
--------
|
|
89
|
+
Basic example:
|
|
90
|
+
|
|
91
|
+
>>> data = otp.Tick(A=1)
|
|
92
|
+
>>> data['OR'] = otp.bit_or(2, 1)
|
|
93
|
+
>>> otp.run(data)
|
|
94
|
+
Time A OR
|
|
95
|
+
0 2003-12-01 1 3
|
|
96
|
+
|
|
97
|
+
You can also pass :py:class:`~onetick.py.Column` as parameter:
|
|
98
|
+
|
|
99
|
+
>>> data = otp.Tick(A=1)
|
|
100
|
+
>>> data['OR'] = otp.bit_or(data['A'], 0)
|
|
101
|
+
>>> otp.run(data)
|
|
102
|
+
Time A OR
|
|
103
|
+
0 2003-12-01 1 1
|
|
104
|
+
|
|
105
|
+
Or use :py:class:`~onetick.py.Operation` as parameter:
|
|
106
|
+
|
|
107
|
+
>>> data = otp.Tick(A=1)
|
|
108
|
+
>>> data['OR'] = otp.bit_or(data['A'] * 2, 3)
|
|
109
|
+
>>> otp.run(data)
|
|
110
|
+
Time A OR
|
|
111
|
+
0 2003-12-01 1 3
|
|
112
|
+
"""
|
|
113
|
+
return _BitOrOperator(value1, value2)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def bit_xor(value1, value2):
|
|
117
|
+
"""
|
|
118
|
+
Performs the logical XOR operation on each pair of corresponding bits of the parameters.
|
|
119
|
+
|
|
120
|
+
Parameters
|
|
121
|
+
----------
|
|
122
|
+
value1: int, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
|
|
123
|
+
value2: int, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
|
|
124
|
+
|
|
125
|
+
Returns
|
|
126
|
+
-------
|
|
127
|
+
:py:class:`~onetick.py.Operation`
|
|
128
|
+
|
|
129
|
+
Examples
|
|
130
|
+
--------
|
|
131
|
+
Basic example:
|
|
132
|
+
|
|
133
|
+
>>> data = otp.Tick(A=1)
|
|
134
|
+
>>> data['XOR'] = otp.bit_xor(0b111, 0b011)
|
|
135
|
+
>>> otp.run(data)
|
|
136
|
+
Time A XOR
|
|
137
|
+
0 2003-12-01 1 4
|
|
138
|
+
|
|
139
|
+
You can also pass :py:class:`~onetick.py.Column` as parameter:
|
|
140
|
+
|
|
141
|
+
>>> data = otp.Tick(A=0b001)
|
|
142
|
+
>>> data['XOR'] = otp.bit_xor(data['A'], 0b011)
|
|
143
|
+
>>> otp.run(data)
|
|
144
|
+
Time A XOR
|
|
145
|
+
0 2003-12-01 1 2
|
|
146
|
+
|
|
147
|
+
Or use :py:class:`~onetick.py.Operation` as parameter:
|
|
148
|
+
|
|
149
|
+
>>> data = otp.Tick(A=0b001)
|
|
150
|
+
>>> data['XOR'] = otp.bit_xor(data['A'] * 2, 0b011)
|
|
151
|
+
>>> otp.run(data)
|
|
152
|
+
Time A XOR
|
|
153
|
+
0 2003-12-01 1 1
|
|
154
|
+
"""
|
|
155
|
+
return _Operation(dtype=int, op_str=f'BIT_XOR({str(value1)}, {str(value2)})')
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def bit_not(value):
|
|
159
|
+
"""
|
|
160
|
+
Performs the logical NOT operation on each bit of the ``value``.
|
|
161
|
+
|
|
162
|
+
Parameters
|
|
163
|
+
----------
|
|
164
|
+
value: int, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
|
|
165
|
+
|
|
166
|
+
Returns
|
|
167
|
+
-------
|
|
168
|
+
:py:class:`~onetick.py.Operation`
|
|
169
|
+
|
|
170
|
+
Examples
|
|
171
|
+
--------
|
|
172
|
+
Basic example:
|
|
173
|
+
|
|
174
|
+
>>> data = otp.Tick(A=1)
|
|
175
|
+
>>> data['NOT'] = otp.bit_not(1)
|
|
176
|
+
>>> otp.run(data)
|
|
177
|
+
Time A NOT
|
|
178
|
+
0 2003-12-01 1 -2
|
|
179
|
+
|
|
180
|
+
You can also pass :py:class:`~onetick.py.Column` as parameter:
|
|
181
|
+
|
|
182
|
+
>>> data = otp.Tick(A=1)
|
|
183
|
+
>>> data['NOT'] = otp.bit_not(data['A'])
|
|
184
|
+
>>> otp.run(data)
|
|
185
|
+
Time A NOT
|
|
186
|
+
0 2003-12-01 1 -2
|
|
187
|
+
|
|
188
|
+
Or use :py:class:`~onetick.py.Operation` as parameter:
|
|
189
|
+
|
|
190
|
+
>>> data = otp.Tick(A=1)
|
|
191
|
+
>>> data['NOT'] = otp.bit_not(data['A'] * 2)
|
|
192
|
+
>>> otp.run(data)
|
|
193
|
+
Time A NOT
|
|
194
|
+
0 2003-12-01 1 -3
|
|
195
|
+
"""
|
|
196
|
+
return _Operation(dtype=int, op_str=f'BIT_NOT({str(value)})')
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def bit_at(value, index):
|
|
200
|
+
"""
|
|
201
|
+
Return bit from ``value`` at ``index`` position from the end (zero-based).
|
|
202
|
+
|
|
203
|
+
Parameters
|
|
204
|
+
----------
|
|
205
|
+
value: int, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
|
|
206
|
+
index: int, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
|
|
207
|
+
|
|
208
|
+
Returns
|
|
209
|
+
-------
|
|
210
|
+
:py:class:`~onetick.py.Operation`
|
|
211
|
+
|
|
212
|
+
Examples
|
|
213
|
+
--------
|
|
214
|
+
Basic example:
|
|
215
|
+
|
|
216
|
+
>>> data = otp.Tick(A=1)
|
|
217
|
+
>>> data['AT'] = otp.bit_at(0b0010, 1)
|
|
218
|
+
>>> otp.run(data)
|
|
219
|
+
Time A AT
|
|
220
|
+
0 2003-12-01 1 1
|
|
221
|
+
|
|
222
|
+
You can also pass :py:class:`~onetick.py.Column` as parameter:
|
|
223
|
+
|
|
224
|
+
>>> data = otp.Tick(A=0b0001)
|
|
225
|
+
>>> data['AT'] = otp.bit_at(data['A'], 0)
|
|
226
|
+
>>> otp.run(data)
|
|
227
|
+
Time A AT
|
|
228
|
+
0 2003-12-01 1 1
|
|
229
|
+
|
|
230
|
+
Or use :py:class:`~onetick.py.Operation` as parameter:
|
|
231
|
+
|
|
232
|
+
>>> data = otp.Tick(A=0b0001)
|
|
233
|
+
>>> data['AT'] = otp.bit_at(data['A'] * 2, 0)
|
|
234
|
+
>>> otp.run(data)
|
|
235
|
+
Time A AT
|
|
236
|
+
0 2003-12-01 1 0
|
|
237
|
+
"""
|
|
238
|
+
return _Operation(dtype=int, op_str=f'BIT_AT({str(value)}, {str(index)})')
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
class _HashCodeOperator(_Operation):
|
|
242
|
+
HASH_TYPES = {
|
|
243
|
+
'sha_1': string[40],
|
|
244
|
+
'sha_224': string[56],
|
|
245
|
+
'sha_256': string[64],
|
|
246
|
+
'sha_384': string[96],
|
|
247
|
+
'sha_512': string[128],
|
|
248
|
+
'lookup3': string[16],
|
|
249
|
+
'metro_hash_64': string[16],
|
|
250
|
+
'city_hash_64': string[16],
|
|
251
|
+
'murmur_hash_64': string[16],
|
|
252
|
+
'sum_of_bytes': string[16],
|
|
253
|
+
'default': string[16],
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
def __init__(self, value, hash_type):
|
|
257
|
+
if hash_type not in self.HASH_TYPES:
|
|
258
|
+
raise ValueError(f'Incorrect hash_type was passed: {hash_type}')
|
|
259
|
+
|
|
260
|
+
if hash_type.startswith('sha') and not is_sha2_hashing_supported():
|
|
261
|
+
raise RuntimeError("SHA2 hashing unavailable on current OneTick version")
|
|
262
|
+
|
|
263
|
+
dtype = self.HASH_TYPES[hash_type]
|
|
264
|
+
|
|
265
|
+
super().__init__(dtype=dtype)
|
|
266
|
+
|
|
267
|
+
def _repr(_value, _hash_type):
|
|
268
|
+
_value = value2str(_value)
|
|
269
|
+
_hash_type = value2str(_hash_type.upper())
|
|
270
|
+
|
|
271
|
+
return f'COMPUTE_HASH_CODE_STR({_value}, {_hash_type})'
|
|
272
|
+
|
|
273
|
+
self._repr = _repr(value, hash_type)
|
|
274
|
+
|
|
275
|
+
def __str__(self):
|
|
276
|
+
return self._repr
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def hash_code(value, hash_type):
|
|
280
|
+
"""
|
|
281
|
+
Returns hexadecimal encoded hash code for the specified string with the specified hash function.
|
|
282
|
+
|
|
283
|
+
Note
|
|
284
|
+
----
|
|
285
|
+
Fixed sized string hash result could differ from the same variable length string due to trailing nulls.
|
|
286
|
+
|
|
287
|
+
Parameters
|
|
288
|
+
----------
|
|
289
|
+
value: str, :py:class:`~onetick.py.Operation`, :py:class:`~onetick.py.Column`
|
|
290
|
+
value to calculate hash from
|
|
291
|
+
hash_type: str
|
|
292
|
+
one of following hash types:
|
|
293
|
+
|
|
294
|
+
* `sha_1`
|
|
295
|
+
* `sha_224`
|
|
296
|
+
* `sha_256`
|
|
297
|
+
* `sha_384`
|
|
298
|
+
* `sha_512`
|
|
299
|
+
* `lookup3`
|
|
300
|
+
* `metro_hash_64`
|
|
301
|
+
* `city_hash_64`
|
|
302
|
+
* `murmur_hash_64`
|
|
303
|
+
* `sum_of_bytes`
|
|
304
|
+
* `default`
|
|
305
|
+
|
|
306
|
+
Returns
|
|
307
|
+
-------
|
|
308
|
+
:py:class:`~onetick.py.Operation`
|
|
309
|
+
|
|
310
|
+
See also
|
|
311
|
+
--------
|
|
312
|
+
**COMPUTE_HASH_CODE_STR** OneTick built-in function
|
|
313
|
+
|
|
314
|
+
Examples
|
|
315
|
+
--------
|
|
316
|
+
Basic example:
|
|
317
|
+
|
|
318
|
+
.. testcode::
|
|
319
|
+
:skipif: not is_sha2_hashing_supported()
|
|
320
|
+
|
|
321
|
+
data = otp.Tick(A=1)
|
|
322
|
+
data['HASH'] = otp.hash_code('some_string', 'sha_224')
|
|
323
|
+
df = otp.run(data)
|
|
324
|
+
print(df)
|
|
325
|
+
|
|
326
|
+
.. testoutput::
|
|
327
|
+
|
|
328
|
+
Time A HASH
|
|
329
|
+
0 2003-12-01 1 12d3f96511450121e6343b5ace065ec9de7b2a946b86f7dfab8ac51f
|
|
330
|
+
|
|
331
|
+
You can also pass :py:class:`~onetick.py.Operation` as a ``value`` parameter:
|
|
332
|
+
|
|
333
|
+
.. testcode::
|
|
334
|
+
:skipif: not is_sha2_hashing_supported()
|
|
335
|
+
|
|
336
|
+
data = otp.Tick(A=otp.varstring('some_string'))
|
|
337
|
+
data['HASH'] = otp.hash_code(data['A'], 'sha_224')
|
|
338
|
+
df = otp.run(data)
|
|
339
|
+
print(df)
|
|
340
|
+
|
|
341
|
+
.. testoutput::
|
|
342
|
+
|
|
343
|
+
Time A HASH
|
|
344
|
+
0 2003-12-01 some_string 12d3f96511450121e6343b5ace065ec9de7b2a946b86f7dfab8ac51f
|
|
345
|
+
|
|
346
|
+
For the same string stored in strings with different fixed sizes, the hash value may differ:
|
|
347
|
+
|
|
348
|
+
.. testcode::
|
|
349
|
+
:skipif: not is_sha2_hashing_supported()
|
|
350
|
+
|
|
351
|
+
test_str = 'example'
|
|
352
|
+
data = otp.Tick(A=otp.string[128](test_str))
|
|
353
|
+
data['Fixed'] = otp.hash_code(data['A'], 'sha_1')
|
|
354
|
+
data['Var'] = otp.hash_code(otp.varstring(test_str), 'sha_1')
|
|
355
|
+
df = otp.run(data)
|
|
356
|
+
print(df)
|
|
357
|
+
|
|
358
|
+
.. testoutput::
|
|
359
|
+
|
|
360
|
+
Time A Fixed Var
|
|
361
|
+
0 2003-12-01 example bdab82ec533c09646e45f15dc4e7ad2d2d1a8ff1 c3499c2729730a7f807efb8676a92dcb6f8a3f8f
|
|
362
|
+
"""
|
|
363
|
+
return _HashCodeOperator(value, hash_type)
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
def get_symbology_mapping(dest_symbology, src_symbology=None, symbol=None, timestamp=None):
|
|
367
|
+
"""
|
|
368
|
+
Translates and returns the symbol in ``dest_symbology`` using the current timestamp as the symbol date.
|
|
369
|
+
|
|
370
|
+
The remaining optional parameters are specified to overwrite
|
|
371
|
+
the symbology of the current symbol, the current symbol, and the timestamp, respectively.
|
|
372
|
+
|
|
373
|
+
Parameters
|
|
374
|
+
----------
|
|
375
|
+
dest_symbology: str, :py:class:`~onetick.py.Operation`
|
|
376
|
+
Symbology to translate the symbol name to.
|
|
377
|
+
src_symbology: str, :py:class:`~onetick.py.Operation`
|
|
378
|
+
Symbology from which the symbol will be translated.
|
|
379
|
+
Will be taken from the input symbol name if it has symbology part in it
|
|
380
|
+
or defaults to the symbology of the input database, which is specified in the locator file.
|
|
381
|
+
symbol: str, :py:class:`~onetick.py.Operation`
|
|
382
|
+
Used to specify the input symbol name.
|
|
383
|
+
By default the symbol name of the query is used.
|
|
384
|
+
timestamp: :py:class:`~onetick.py.Operation`
|
|
385
|
+
They symbol date to use when translating symbol name.
|
|
386
|
+
By default the current timestamp of the tick is used.
|
|
387
|
+
|
|
388
|
+
Returns
|
|
389
|
+
-------
|
|
390
|
+
:py:class:`~onetick.py.Operation`
|
|
391
|
+
|
|
392
|
+
See also
|
|
393
|
+
--------
|
|
394
|
+
:py:class:`onetick.py.SymbologyMapping`
|
|
395
|
+
|
|
396
|
+
Examples
|
|
397
|
+
--------
|
|
398
|
+
Get the symbol name in OID symbology:
|
|
399
|
+
|
|
400
|
+
>>> data = otp.Tick(A=1, db=None)
|
|
401
|
+
>>> data['SYMBOLOGY_MAPPING'] = otp.get_symbology_mapping('OID')
|
|
402
|
+
>>> otp.run(data, symbols='TDEQ::US_COMP::AAPL', # doctest: +SKIP
|
|
403
|
+
... date=otp.dt(2022, 1, 3))
|
|
404
|
+
Time A SYMBOLOGY_MAPPING
|
|
405
|
+
0 2022-01-03 1 9706
|
|
406
|
+
|
|
407
|
+
Override source symbology, symbol and symbol date:
|
|
408
|
+
|
|
409
|
+
>>> data = otp.Tick(A=1, db=None)
|
|
410
|
+
>>> data['SYMBOLOGY_MAPPING'] = otp.get_symbology_mapping('OID', 'TDEQ', 'MSFT', otp.dt(2022, 1, 3))
|
|
411
|
+
>>> otp.run(data, symbols='US_COMP::AAPL', # doctest: +SKIP
|
|
412
|
+
... date=otp.dt(2022, 1, 3))
|
|
413
|
+
Time A SYMBOLOGY_MAPPING
|
|
414
|
+
0 2022-01-03 1 109037
|
|
415
|
+
"""
|
|
416
|
+
params_correct = (
|
|
417
|
+
all([src_symbology, symbol, timestamp])
|
|
418
|
+
or all([src_symbology, symbol])
|
|
419
|
+
or not any([src_symbology, symbol, timestamp])
|
|
420
|
+
)
|
|
421
|
+
if not params_correct:
|
|
422
|
+
raise ValueError("Parameters 'src_symbology' and 'symbol' or"
|
|
423
|
+
" 'src_symbology', 'symbol' and 'timestamp' must be specified together")
|
|
424
|
+
|
|
425
|
+
def op_func(dest_symbology, src_symbology, symbol, timestamp):
|
|
426
|
+
params = [value2str(dest_symbology)]
|
|
427
|
+
for param in [src_symbology, symbol, timestamp]:
|
|
428
|
+
if param is not None:
|
|
429
|
+
params.append(value2str(param))
|
|
430
|
+
params_str = ','.join(params)
|
|
431
|
+
return f'GET_SYMBOLOGY_MAPPING({params_str})', str
|
|
432
|
+
|
|
433
|
+
return _Operation(
|
|
434
|
+
op_func=op_func,
|
|
435
|
+
op_params=[dest_symbology, src_symbology, symbol, timestamp],
|
|
436
|
+
dtype=str,
|
|
437
|
+
)
|
|
@@ -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
|