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/sql.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from onetick.py.otq import otq
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class SqlQuery(otq.SqlQuery):
|
|
5
|
+
def __init__(self, sql_statement: str, merge_all_symbols: bool = False, separate_dbname: bool = False):
|
|
6
|
+
"""
|
|
7
|
+
Constructs SQL query object.
|
|
8
|
+
|
|
9
|
+
Parameters
|
|
10
|
+
----------
|
|
11
|
+
sql_statement:
|
|
12
|
+
The SQL statement string.
|
|
13
|
+
merge_all_symbols:
|
|
14
|
+
If set to True, ticks returned by the query for all symbols get merged into a single time series.
|
|
15
|
+
separate_dbname:
|
|
16
|
+
If set to True, and ``merge_all_symbols`` is set to True,
|
|
17
|
+
*SYMBOL_NAME* field contains a symbol name without the database name,
|
|
18
|
+
and *DB_NAME* field contains the database name for a symbol.
|
|
19
|
+
|
|
20
|
+
See also
|
|
21
|
+
--------
|
|
22
|
+
:py:func:`otp.run <onetick.py.run>`
|
|
23
|
+
|
|
24
|
+
Examples
|
|
25
|
+
--------
|
|
26
|
+
|
|
27
|
+
Select two fields from a single tick type and symbol and return first three ticks from a single day:
|
|
28
|
+
|
|
29
|
+
>>> otp.run(
|
|
30
|
+
... otp.SqlQuery("select PRICE,SIZE from US_COMP.TRD"
|
|
31
|
+
... " where symbol_name = 'AAPL'"
|
|
32
|
+
... " and start_time = '2022-03-01 00:00:00 GMT' and end_time = '2022-03-02 00:00:00 GMT'"
|
|
33
|
+
... " limit 3")
|
|
34
|
+
... )
|
|
35
|
+
Time PRICE SIZE
|
|
36
|
+
0 2022-03-01 00:00:00.000 1.3 100
|
|
37
|
+
1 2022-03-01 00:00:00.001 1.4 10
|
|
38
|
+
2 2022-03-01 00:00:00.002 1.4 50
|
|
39
|
+
|
|
40
|
+
Join quotes and trades:
|
|
41
|
+
|
|
42
|
+
>>> otp.run(
|
|
43
|
+
... otp.SqlQuery("select t.PRICE,q.ASK_PRICE,q.BID_PRICE"
|
|
44
|
+
... " from US_COMP.TRD t join US_COMP.QTE q"
|
|
45
|
+
... " on sametime_as_existing(t.timestamp, q.timestamp, 0) = TRUE"
|
|
46
|
+
... " where t.symbol_name = 'AAPL' and q.symbol_name = 'AAPL'"
|
|
47
|
+
... " and start_time = '2022-03-01 00:00:00 GMT' and end_time = '2022-03-02 00:00:00 GMT'"
|
|
48
|
+
... " limit 2")
|
|
49
|
+
... )
|
|
50
|
+
Time T.PRICE Q.ASK_PRICE Q.BID_PRICE
|
|
51
|
+
0 2022-03-01 00:00:00.001 1.4 1.5 1.2
|
|
52
|
+
1 2022-03-01 00:00:00.002 1.4 1.4 1.3
|
|
53
|
+
|
|
54
|
+
Calculate average price of trades across several symbols:
|
|
55
|
+
|
|
56
|
+
>>> otp.run(
|
|
57
|
+
... otp.SqlQuery("select COUNT(*) as COUNT, AVG(PRICE) as AVG_PRICE"
|
|
58
|
+
... " from US_COMP.TRD"
|
|
59
|
+
... " where symbol_name in ('AAPL', 'AAP')"
|
|
60
|
+
... " and start_time = '2022-03-01 00:00:00 GMT' and end_time = '2022-03-02 00:00:00 GMT'",
|
|
61
|
+
... merge_all_symbols=True)
|
|
62
|
+
... )
|
|
63
|
+
Time COUNT AVG_PRICE
|
|
64
|
+
0 2022-03-01 19:00:00 5.0 18.976
|
|
65
|
+
"""
|
|
66
|
+
super().__init__(sql_statement)
|
|
67
|
+
if merge_all_symbols:
|
|
68
|
+
self.set_merge_all_symbols_flag(merge_all_symbols)
|
|
69
|
+
if separate_dbname:
|
|
70
|
+
self.set_separate_dbname_flag(separate_dbname)
|
onetick/py/state.py
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import warnings
|
|
2
|
+
|
|
3
|
+
from onetick.py import types as ott
|
|
4
|
+
from onetick.py.core._internal._state_objects import (
|
|
5
|
+
_StateColumn, TickList, TickSet, TickSetUnordered, TickDeque,
|
|
6
|
+
_TickListTick, _TickSetTick, _TickDequeTick, _DynamicTick,
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
AVAILABLE_SCOPES = (
|
|
11
|
+
"BRANCH", # A branch-scope state variable is visible to all event processors of the branch its declarator EP
|
|
12
|
+
# belongs to (a branch is a maximal long chain of EPs, each node of which has at most 1 _source and at most 1 sink).
|
|
13
|
+
"ALL_INPUTS", # An all-inputs-scope state variable is visible to all event processors of the input subgraph of its
|
|
14
|
+
# declarator EP (input subgraph of a particular node is the subset of nodes directly or indirectly feeding it).
|
|
15
|
+
"ALL_OUTPUTS", # An all-outputs-scope state variable is visible to all event processors of the output subgraph of
|
|
16
|
+
# its declarator EP (output subgraph of a particular node is the subset of nodes directly or indirectly fed by it).
|
|
17
|
+
"QUERY", # A query scope state variable is visible to all event processors of the graph.
|
|
18
|
+
"CROSS_SYMBOL", # A cross-symbol scope state variable is visible to all event processors across all unbound
|
|
19
|
+
# symbols. Cross-symbol scope state variables cannot be modified after initialization.
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def var(default_value, scope="query"):
|
|
24
|
+
"""
|
|
25
|
+
Defines a state variable. Supports int, float and string values.
|
|
26
|
+
|
|
27
|
+
Parameters
|
|
28
|
+
----------
|
|
29
|
+
default_value: any
|
|
30
|
+
Default value of the state variable
|
|
31
|
+
scope: str
|
|
32
|
+
Scope for the state variable. Possible values are: query, branch, cross_symbol.
|
|
33
|
+
Default: query
|
|
34
|
+
|
|
35
|
+
Returns
|
|
36
|
+
-------
|
|
37
|
+
a state variable that should be assigned to a _source
|
|
38
|
+
|
|
39
|
+
Examples
|
|
40
|
+
--------
|
|
41
|
+
>>> data = otp.Ticks(dict(X=[0, 1, 2]))
|
|
42
|
+
>>> data.state_vars['SUM'] = otp.state.var(0)
|
|
43
|
+
>>> data.state_vars['SUM'] += data['X']
|
|
44
|
+
>>> data['SUM'] = data.state_vars['SUM']
|
|
45
|
+
>>> otp.run(data)[['X', 'SUM']]
|
|
46
|
+
X SUM
|
|
47
|
+
0 0 0
|
|
48
|
+
1 1 1
|
|
49
|
+
2 2 3
|
|
50
|
+
"""
|
|
51
|
+
scope = _validate_and_preprocess_scope(scope)
|
|
52
|
+
|
|
53
|
+
dtype = ott.get_object_type(default_value)
|
|
54
|
+
|
|
55
|
+
if dtype is ott.msectime:
|
|
56
|
+
raise TypeError("State variables do not support msectime type")
|
|
57
|
+
# elif dtype is ott.nsectime:
|
|
58
|
+
# raise TypeError("State variables do not support nsectime type")
|
|
59
|
+
elif ott.is_time_type(dtype):
|
|
60
|
+
dtype = ott.nsectime
|
|
61
|
+
|
|
62
|
+
# pylint: disable-next=unidiomatic-typecheck
|
|
63
|
+
if type(default_value) is str:
|
|
64
|
+
if len(default_value) > ott.string.DEFAULT_LENGTH:
|
|
65
|
+
dtype = ott.string[len(default_value)]
|
|
66
|
+
|
|
67
|
+
res = _StateColumn("__STATE_COLUMN", dtype, obj_ref=None, default_value=default_value, scope=scope)
|
|
68
|
+
|
|
69
|
+
return res
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def tick_list(default_value=None, scope='query', schema=None) -> TickList:
|
|
73
|
+
"""
|
|
74
|
+
Defines a state tick list.
|
|
75
|
+
|
|
76
|
+
Parameters
|
|
77
|
+
----------
|
|
78
|
+
default_value: :class:`otp.Source <onetick.py.Source>`, :py:func:`eval query <onetick.py.eval>`
|
|
79
|
+
Evaluated query to initialize tick list from.
|
|
80
|
+
scope: str
|
|
81
|
+
Scope for the state variable.
|
|
82
|
+
Possible values are: query, branch, cross_symbol, all_inputs, all_outputs
|
|
83
|
+
schema: dict, list
|
|
84
|
+
Desired schema for the created tick list. If not passed, schema will be inherited from ``default_value``.
|
|
85
|
+
if ``default_value`` is not passed as well, schema will contain fields of the main Source object.
|
|
86
|
+
|
|
87
|
+
If schema is passed as a list, it will select only these fields from the schema of ``default_value``
|
|
88
|
+
or main :class:`Source <onetick.py.Source>` object.
|
|
89
|
+
|
|
90
|
+
Examples
|
|
91
|
+
--------
|
|
92
|
+
>>> data = otp.Tick(A=1)
|
|
93
|
+
>>> data.state_vars['LIST'] = otp.state.tick_list(otp.Ticks(B=[1, 2, 3]))
|
|
94
|
+
>>> data = data.state_vars['LIST'].dump()
|
|
95
|
+
>>> otp.run(data)[['B']]
|
|
96
|
+
B
|
|
97
|
+
0 1
|
|
98
|
+
1 2
|
|
99
|
+
2 3
|
|
100
|
+
"""
|
|
101
|
+
scope = _validate_and_preprocess_scope(scope)
|
|
102
|
+
return TickList('', obj_ref=None, default_value=default_value, scope=scope, schema=schema)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def tick_set(insertion_policy, key_fields, default_value=None, scope='query', schema=None) -> TickSet:
|
|
106
|
+
"""
|
|
107
|
+
Defines a state tick set.
|
|
108
|
+
|
|
109
|
+
Parameters
|
|
110
|
+
----------
|
|
111
|
+
insertion_policy: 'oldest' or 'latest'
|
|
112
|
+
'oldest' specifies not to overwrite ticks with the same keys.
|
|
113
|
+
'latest' makes the last inserted tick overwrite the one with the same keys (if existing).
|
|
114
|
+
key_fields: str, list of str
|
|
115
|
+
The values of the specified fields will be used as keys.
|
|
116
|
+
default_value: :class:`otp.Source <onetick.py.Source>`, :py:func:`eval query <onetick.py.eval>`
|
|
117
|
+
Evaluated query to initialize tick set from.
|
|
118
|
+
scope: str
|
|
119
|
+
Scope for the state variable.
|
|
120
|
+
Possible values are: query, branch, cross_symbol, all_inputs, all_outputs
|
|
121
|
+
schema: dict, list
|
|
122
|
+
Desired schema for the created tick set. If not passed, schema will be inherited from ``default_value``.
|
|
123
|
+
if ``default_value`` is not passed as well, schema will contain fields of the main Source object.
|
|
124
|
+
|
|
125
|
+
If schema is passed as a list, it will select only these fields from the schema of ``default_value``
|
|
126
|
+
or main :class:`Source <onetick.py.Source>` object.
|
|
127
|
+
|
|
128
|
+
Examples
|
|
129
|
+
--------
|
|
130
|
+
>>> data = otp.Tick(A=1)
|
|
131
|
+
>>> data.state_vars['SET'] = otp.state.tick_set('oldest', 'B', otp.Ticks(B=[1, 1, 2, 2, 3, 3]))
|
|
132
|
+
>>> data = data.state_vars['SET'].dump()
|
|
133
|
+
>>> otp.run(data)[['B']]
|
|
134
|
+
B
|
|
135
|
+
0 1
|
|
136
|
+
1 2
|
|
137
|
+
2 3
|
|
138
|
+
"""
|
|
139
|
+
scope = _validate_and_preprocess_scope(scope)
|
|
140
|
+
return TickSet('',
|
|
141
|
+
insertion_policy=insertion_policy, key_fields=key_fields,
|
|
142
|
+
obj_ref=None, default_value=default_value, scope=scope,
|
|
143
|
+
schema=schema)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def tick_set_unordered(insertion_policy,
|
|
147
|
+
key_fields,
|
|
148
|
+
default_value=None,
|
|
149
|
+
max_distinct_keys=-1,
|
|
150
|
+
scope='query',
|
|
151
|
+
schema=None) -> TickSetUnordered:
|
|
152
|
+
"""
|
|
153
|
+
Defines unordered tick set.
|
|
154
|
+
|
|
155
|
+
Parameters
|
|
156
|
+
----------
|
|
157
|
+
insertion_policy: 'oldest' or 'latest'
|
|
158
|
+
'oldest' specifies not to overwrite ticks with the same keys.
|
|
159
|
+
'latest' makes the last inserted tick overwrite the one with the same keys (if existing).
|
|
160
|
+
key_fields: str, list of str
|
|
161
|
+
The values of the specified fields will be used as keys.
|
|
162
|
+
max_distinct_keys: int
|
|
163
|
+
Expected size of the unordered tick set. It will be used to allocate memory to hold ticks in the tick set.
|
|
164
|
+
It should have the same order as the expected amounts of ticks held in the set. Default value of -1 indicates
|
|
165
|
+
that expected amount of ticks is not known in advance.
|
|
166
|
+
If this value is set correctly, the performance of unordered tick set is expected to be better
|
|
167
|
+
than that of normal tick set.
|
|
168
|
+
|
|
169
|
+
.. warning::
|
|
170
|
+
If ``max_distinct_keys`` value is set too low, the performance of unordered tick set
|
|
171
|
+
may be considerably worse than that of normal tick set.
|
|
172
|
+
In particular, **default value of -1 will lead to bad performance and should be avoided**
|
|
173
|
+
|
|
174
|
+
default_value: :class:`otp.Source <onetick.py.Source>`, :py:func:`eval query <onetick.py.eval>`
|
|
175
|
+
Evaluated query to initialize unordered tick set from.
|
|
176
|
+
scope: str,
|
|
177
|
+
Scope for the state variable.
|
|
178
|
+
Possible values are: query, branch, cross_symbol, all_inputs, all_outputs
|
|
179
|
+
schema: dict, list
|
|
180
|
+
Desired schema for the created unordered tick set. If not passed,
|
|
181
|
+
schema will be inherited from ``default_value``.
|
|
182
|
+
if ``default_value`` is not passed as well, schema will contain fields of the main Source object.
|
|
183
|
+
|
|
184
|
+
If schema is passed as a list, it will select only these fields from the schema of ``default_value``
|
|
185
|
+
or main :class:`Source <onetick.py.Source>` object.
|
|
186
|
+
|
|
187
|
+
Examples
|
|
188
|
+
--------
|
|
189
|
+
>>> data = otp.Tick(A=1)
|
|
190
|
+
>>> data.state_vars['SET'] = otp.state.tick_set_unordered('oldest', 'B',
|
|
191
|
+
... otp.Ticks(B=[1, 1, 2, 2, 3, 3]),
|
|
192
|
+
... max_distinct_keys=5)
|
|
193
|
+
>>> data = data.state_vars['SET'].dump()
|
|
194
|
+
>>> otp.run(data)[['B']]
|
|
195
|
+
B
|
|
196
|
+
0 1
|
|
197
|
+
1 2
|
|
198
|
+
2 3
|
|
199
|
+
"""
|
|
200
|
+
scope = _validate_and_preprocess_scope(scope)
|
|
201
|
+
if max_distinct_keys == -1:
|
|
202
|
+
warnings.warn('Unordered tick set with max_distinct_keys == -1 is expected to be inefficient. '
|
|
203
|
+
'Please consider using regular tick set instead.', stacklevel=2)
|
|
204
|
+
return TickSetUnordered(
|
|
205
|
+
'',
|
|
206
|
+
insertion_policy=insertion_policy, max_distinct_keys=max_distinct_keys, key_fields=key_fields,
|
|
207
|
+
obj_ref=None, default_value=default_value, scope=scope, schema=schema
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def tick_deque(default_value=None, scope='query', schema=None) -> TickDeque:
|
|
212
|
+
"""
|
|
213
|
+
Defines a state tick deque.
|
|
214
|
+
|
|
215
|
+
Parameters
|
|
216
|
+
----------
|
|
217
|
+
default_value: :class:`otp.Source <onetick.py.Source>`, :py:func:`eval query <onetick.py.eval>`
|
|
218
|
+
Evaluated query to initialize tick deque from.
|
|
219
|
+
scope: str
|
|
220
|
+
Scope for the state variable.
|
|
221
|
+
Possible values are: query, branch, cross_symbol, all_inputs, all_outputs
|
|
222
|
+
schema: dict, list
|
|
223
|
+
Desired schema for the created tick deque. If not passed, schema will be inherited from ``default_value``.
|
|
224
|
+
if ``default_value`` is not passed as well, schema will contain fields of the main Source object.
|
|
225
|
+
|
|
226
|
+
If schema is passed as a list, it will select only these fields from the schema of ``default_value``
|
|
227
|
+
or main :class:`Source <onetick.py.Source>` object.
|
|
228
|
+
|
|
229
|
+
Examples
|
|
230
|
+
--------
|
|
231
|
+
>>> data = otp.Tick(A=1)
|
|
232
|
+
>>> data.state_vars['DEQUE'] = otp.state.tick_deque(otp.Ticks(B=[1, 2, 3]))
|
|
233
|
+
>>> data = data.state_vars['DEQUE'].dump()
|
|
234
|
+
>>> otp.run(data)[['B']]
|
|
235
|
+
B
|
|
236
|
+
0 1
|
|
237
|
+
1 2
|
|
238
|
+
2 3
|
|
239
|
+
"""
|
|
240
|
+
scope = _validate_and_preprocess_scope(scope)
|
|
241
|
+
return TickDeque('', obj_ref=None, default_value=default_value, scope=scope, schema=schema)
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def _validate_and_preprocess_scope(scope):
|
|
245
|
+
if isinstance(scope, str):
|
|
246
|
+
scope = scope.upper()
|
|
247
|
+
if scope not in AVAILABLE_SCOPES:
|
|
248
|
+
raise ValueError(f"unknown scope {scope}, please use one of {AVAILABLE_SCOPES}")
|
|
249
|
+
else:
|
|
250
|
+
raise ValueError(f"scope should be one of the following strings: {AVAILABLE_SCOPES}")
|
|
251
|
+
return scope
|