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
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
from typing import TYPE_CHECKING, Optional
|
|
2
|
+
|
|
3
|
+
if TYPE_CHECKING:
|
|
4
|
+
from onetick.py.core.source import Source # hack for annotations
|
|
5
|
+
|
|
6
|
+
import onetick.py as otp
|
|
7
|
+
from onetick.py.otq import otq
|
|
8
|
+
from onetick.py.core.column import _Column
|
|
9
|
+
from ._base import _Aggregation, _MultiColumnAggregation
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Generic(_Aggregation, _MultiColumnAggregation):
|
|
13
|
+
NAME = 'GENERIC_AGGREGATION'
|
|
14
|
+
EP = otq.GenericAggregation
|
|
15
|
+
|
|
16
|
+
FIELDS_TO_SKIP = ['column_name', 'all_fields', 'output_field_name']
|
|
17
|
+
FIELDS_MAPPING = dict(_Aggregation.FIELDS_MAPPING, **{
|
|
18
|
+
'query_name': 'QUERY_NAME',
|
|
19
|
+
'bucket_delimiter': 'BUCKET_DELIMITERS',
|
|
20
|
+
})
|
|
21
|
+
FIELDS_DEFAULT = dict(_Aggregation.FIELDS_DEFAULT, **{
|
|
22
|
+
'bucket_delimiter': None,
|
|
23
|
+
})
|
|
24
|
+
_validations_to_skip = ['running_all_fields']
|
|
25
|
+
|
|
26
|
+
def __init__(self,
|
|
27
|
+
query_fun,
|
|
28
|
+
bucket_delimiter: bool = False,
|
|
29
|
+
**kwargs):
|
|
30
|
+
self._query: Optional['Source'] = None
|
|
31
|
+
self._query_fun = query_fun
|
|
32
|
+
self._query_params: Optional[dict] = None
|
|
33
|
+
self.bucket_delimiter = 'D' if bucket_delimiter else None
|
|
34
|
+
|
|
35
|
+
# init variables which will be set later
|
|
36
|
+
self.query_name: Optional[str] = None
|
|
37
|
+
self._query_schema: Optional[dict] = None
|
|
38
|
+
|
|
39
|
+
if 'all_fields' in kwargs:
|
|
40
|
+
raise ValueError("Parameter 'all_fields' for generic aggregation is meaningless. "
|
|
41
|
+
"Aggregated source will have all fields returned by 'query_fun'.")
|
|
42
|
+
# we don't want to set hard limit on the output of order book aggregations
|
|
43
|
+
kwargs['all_fields'] = True
|
|
44
|
+
super().__init__(column=_Column('TIMESTAMP'), **kwargs)
|
|
45
|
+
|
|
46
|
+
def _set_query_params(self, **kwargs):
|
|
47
|
+
self._query_params = kwargs
|
|
48
|
+
|
|
49
|
+
def apply(self, src: 'Source', name: Optional[str] = None, **kwargs) -> 'Source':
|
|
50
|
+
"""Applies generic aggregation to Source and sets proper schema
|
|
51
|
+
|
|
52
|
+
Parameters
|
|
53
|
+
----------
|
|
54
|
+
src: Source
|
|
55
|
+
Source to apply aggregation
|
|
56
|
+
name: str, optional
|
|
57
|
+
Name of output column. If not specified, will be used self.column_name
|
|
58
|
+
kwargs: dict
|
|
59
|
+
Parameters to be passed to `query_fun()` when creating aggregation query
|
|
60
|
+
"""
|
|
61
|
+
self._set_query_params(**kwargs)
|
|
62
|
+
return super().apply(src, name=name)
|
|
63
|
+
|
|
64
|
+
def _make_query_object(self, schema):
|
|
65
|
+
query_params = self._query_params if self._query_params else {}
|
|
66
|
+
query = otp.DataSource(symbols='LOCAL::', tick_type='ANY', schema_policy='manual', schema=schema)
|
|
67
|
+
query = self._query_fun(query, **query_params)
|
|
68
|
+
return query
|
|
69
|
+
|
|
70
|
+
def _detect_query_fun_schema(self, res):
|
|
71
|
+
# this will be translated to passthrough with symbol and tick type set
|
|
72
|
+
if self._query is None:
|
|
73
|
+
self._query = self._make_query_object(res.schema)
|
|
74
|
+
|
|
75
|
+
return self._query.schema.copy()
|
|
76
|
+
|
|
77
|
+
def _modify_source(self, res: 'Source', **kwargs):
|
|
78
|
+
query_schema = self._detect_query_fun_schema(res)
|
|
79
|
+
|
|
80
|
+
# schema will be used when validating output
|
|
81
|
+
if self._query_schema is None:
|
|
82
|
+
self._query_schema = query_schema
|
|
83
|
+
|
|
84
|
+
if self._query is None:
|
|
85
|
+
raise RuntimeError('Attempted to use `self._query` before initialization')
|
|
86
|
+
|
|
87
|
+
# query_name will be used to create ep
|
|
88
|
+
query_name = self._query._store_in_tmp_otq(
|
|
89
|
+
res._tmp_otq, operation_suffix='generic_aggregation', add_passthrough=False,
|
|
90
|
+
)
|
|
91
|
+
self.query_name = f'THIS::{query_name}'
|
|
92
|
+
|
|
93
|
+
def _get_common_schema(self, src, name):
|
|
94
|
+
super()._get_common_schema(src, name)
|
|
95
|
+
return {
|
|
96
|
+
column: src.schema[column]
|
|
97
|
+
for column in map(str, self.group_by)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
def _get_output_schema(self, src, name=None):
|
|
101
|
+
schema = self._query_schema.copy()
|
|
102
|
+
if self.bucket_delimiter:
|
|
103
|
+
schema['DELIMITER'] = str
|
|
104
|
+
return schema
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
from typing import Union, TYPE_CHECKING
|
|
2
|
+
from copy import deepcopy
|
|
3
|
+
|
|
4
|
+
if TYPE_CHECKING:
|
|
5
|
+
from onetick.py.core.source import Source # hack for annotations
|
|
6
|
+
|
|
7
|
+
from onetick.py.core.column import _Column
|
|
8
|
+
from onetick.py import types as ott
|
|
9
|
+
from onetick.py.otq import otq
|
|
10
|
+
|
|
11
|
+
from ._base import (
|
|
12
|
+
_AggregationTSType, _AggregationTSSelection, _KeepTs, _FloatAggregation, _ExpectLargeInts, _AllColumnsAggregation,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Max(_AggregationTSType, _ExpectLargeInts):
|
|
17
|
+
|
|
18
|
+
NAME = "HIGH"
|
|
19
|
+
EP = otq.High
|
|
20
|
+
require_type = (int, float, ott.nsectime, ott._inf)
|
|
21
|
+
|
|
22
|
+
FIELDS_MAPPING = deepcopy(_AggregationTSType.FIELDS_MAPPING)
|
|
23
|
+
FIELDS_MAPPING.update(_ExpectLargeInts.FIELDS_MAPPING)
|
|
24
|
+
FIELDS_DEFAULT = deepcopy(_AggregationTSType.FIELDS_DEFAULT)
|
|
25
|
+
FIELDS_DEFAULT.update(_ExpectLargeInts.FIELDS_DEFAULT)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class Min(Max):
|
|
29
|
+
NAME = "LOW"
|
|
30
|
+
EP = otq.Low
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class HighTick(_AggregationTSType, _AggregationTSSelection, _KeepTs, _FloatAggregation, _AllColumnsAggregation):
|
|
34
|
+
EP = otq.HighTick
|
|
35
|
+
NAME = 'HIGH_TICK'
|
|
36
|
+
DEFAULT_OUTPUT_NAME = 'HIGH_TICK'
|
|
37
|
+
|
|
38
|
+
FIELDS_MAPPING = deepcopy(_AggregationTSType.FIELDS_MAPPING)
|
|
39
|
+
FIELDS_MAPPING.update(_AggregationTSSelection.FIELDS_MAPPING)
|
|
40
|
+
FIELDS_MAPPING['n'] = 'NUM_TICKS'
|
|
41
|
+
FIELDS_DEFAULT = deepcopy(_AggregationTSType.FIELDS_DEFAULT)
|
|
42
|
+
FIELDS_DEFAULT.update(_AggregationTSSelection.FIELDS_DEFAULT)
|
|
43
|
+
FIELDS_DEFAULT['n'] = 1
|
|
44
|
+
|
|
45
|
+
FIELDS_TO_SKIP = ['output_field_name', 'all_fields']
|
|
46
|
+
|
|
47
|
+
def __init__(self, column: Union[str, _Column], n: int = 1, *args, **kwargs):
|
|
48
|
+
"""
|
|
49
|
+
Select `n` ticks with the highest values in the `column` field
|
|
50
|
+
"""
|
|
51
|
+
super().__init__(column, *args, **kwargs)
|
|
52
|
+
self.n = n
|
|
53
|
+
|
|
54
|
+
@staticmethod
|
|
55
|
+
def validate_output_name(*args, **kwargs):
|
|
56
|
+
# HighTick and LowTick aggregations don't have output fields
|
|
57
|
+
pass
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class LowTick(HighTick):
|
|
61
|
+
EP = otq.LowTick
|
|
62
|
+
NAME = 'LOW_TICK'
|
|
63
|
+
DEFAULT_OUTPUT_NAME = 'LOW_TICK'
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class HighTime(_AggregationTSType, _AggregationTSSelection, _FloatAggregation):
|
|
67
|
+
NAME = "HIGH_TIME"
|
|
68
|
+
EP = otq.HighTime
|
|
69
|
+
|
|
70
|
+
FIELDS_MAPPING = deepcopy(_AggregationTSType.FIELDS_MAPPING)
|
|
71
|
+
FIELDS_MAPPING.update(_AggregationTSSelection.FIELDS_MAPPING)
|
|
72
|
+
FIELDS_DEFAULT = deepcopy(_AggregationTSType.FIELDS_DEFAULT)
|
|
73
|
+
FIELDS_DEFAULT.update(_AggregationTSSelection.FIELDS_DEFAULT)
|
|
74
|
+
output_field_type = ott.nsectime
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class LowTime(HighTime):
|
|
78
|
+
"""Returns timestamp of tick with lowest value of input field"""
|
|
79
|
+
NAME = "LOW_TIME"
|
|
80
|
+
EP = otq.LowTime
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
from typing import TYPE_CHECKING
|
|
2
|
+
from copy import deepcopy
|
|
3
|
+
|
|
4
|
+
if TYPE_CHECKING:
|
|
5
|
+
from onetick.py.core.source import Source # hack for annotations
|
|
6
|
+
|
|
7
|
+
from onetick.py.otq import otq
|
|
8
|
+
|
|
9
|
+
from onetick.py.core.column import _Column
|
|
10
|
+
from onetick.py import types as ott
|
|
11
|
+
|
|
12
|
+
from ._base import _Aggregation
|
|
13
|
+
from ._docs import (_running_doc,
|
|
14
|
+
_all_fields_doc,
|
|
15
|
+
_bucket_interval_doc,
|
|
16
|
+
_bucket_time_doc,
|
|
17
|
+
_bucket_units_doc,
|
|
18
|
+
_bucket_end_condition_doc,
|
|
19
|
+
_boundary_tick_bucket_doc,
|
|
20
|
+
_group_by_doc,
|
|
21
|
+
_groups_to_display_doc)
|
|
22
|
+
from onetick.py.docs.utils import docstring
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# OneTick build >= 20220913120000
|
|
26
|
+
if hasattr(otq, 'NumDistinct'):
|
|
27
|
+
|
|
28
|
+
class NumDistinct(_Aggregation):
|
|
29
|
+
NAME = 'NUM_DISTINCT'
|
|
30
|
+
EP = otq.NumDistinct
|
|
31
|
+
|
|
32
|
+
FIELDS_MAPPING = deepcopy(_Aggregation.FIELDS_MAPPING)
|
|
33
|
+
FIELDS_MAPPING['keys'] = 'KEYS'
|
|
34
|
+
|
|
35
|
+
FIELDS_TO_SKIP = ['column_name', 'end_condition_per_group']
|
|
36
|
+
|
|
37
|
+
output_field_type = int
|
|
38
|
+
|
|
39
|
+
def __init__(self, keys, *args, **kwargs):
|
|
40
|
+
super().__init__(column=_Column('TIMESTAMP'), *args, **kwargs)
|
|
41
|
+
if isinstance(keys, str):
|
|
42
|
+
keys = [keys]
|
|
43
|
+
self._keys = keys
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
def keys(self):
|
|
47
|
+
return ott.value2str(','.join(self._keys))
|
|
48
|
+
|
|
49
|
+
def apply(self, src, name='VALUE'):
|
|
50
|
+
return super().apply(src, name)
|
|
51
|
+
|
|
52
|
+
def validate_input_columns(self, src: 'Source'):
|
|
53
|
+
for column in self._keys:
|
|
54
|
+
if column not in src.schema:
|
|
55
|
+
raise TypeError(f"Aggregation {self.__class__.__name__} uses"
|
|
56
|
+
f" column '{column}' as input, which doesn't exist")
|
|
57
|
+
|
|
58
|
+
@docstring(parameters=[_running_doc, _all_fields_doc,
|
|
59
|
+
_bucket_interval_doc, _bucket_units_doc, _bucket_time_doc,
|
|
60
|
+
_bucket_end_condition_doc, _boundary_tick_bucket_doc, _group_by_doc, _groups_to_display_doc])
|
|
61
|
+
def num_distinct(*args, **kwargs):
|
|
62
|
+
"""
|
|
63
|
+
Outputs number of distinct values for a specified set of key fields.
|
|
64
|
+
|
|
65
|
+
Parameters
|
|
66
|
+
----------
|
|
67
|
+
keys: str or list of str or list of :py:class:`~onetick.py.Column`
|
|
68
|
+
Specifies a list of tick attributes for which unique values are found.
|
|
69
|
+
The ticks in the input time series must contain those attributes.
|
|
70
|
+
|
|
71
|
+
Examples
|
|
72
|
+
--------
|
|
73
|
+
>>> data = otp.Ticks(dict(X=[1, 3, 2, 1, 3]))
|
|
74
|
+
>>> data = data.agg({'X': otp.agg.num_distinct('X')})
|
|
75
|
+
>>> otp.run(data)
|
|
76
|
+
Time X
|
|
77
|
+
0 2003-12-04 3
|
|
78
|
+
|
|
79
|
+
See also
|
|
80
|
+
--------
|
|
81
|
+
**NUM_DISTINCT** OneTick event processor
|
|
82
|
+
"""
|
|
83
|
+
return NumDistinct(*args, **kwargs)
|