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/__init__.py
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
# pylama:ignore=E402,W0611
|
|
2
|
+
import os
|
|
3
|
+
from . import _version
|
|
4
|
+
__version__ = _version.VERSION
|
|
5
|
+
__webapi__: bool = os.getenv('OTP_WEBAPI', default='').lower() not in ('0', 'false', 'no', '')
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def __validate_onetick_query_integration(): # noqa
|
|
9
|
+
"""Logic that checks correctness of integration of python with onetick.query and/or onetick.query_webapi.
|
|
10
|
+
One of the modules should be installed and available to import.
|
|
11
|
+
|
|
12
|
+
We first try to import onetick.query and NumPy_OneTickQuery, and if it fails,
|
|
13
|
+
before raising an exception, we check if onetick.query_webapi is installed.
|
|
14
|
+
If it is installed, we set OTP_WEBAPI environment variable and avoid raising any exception/warning.
|
|
15
|
+
"""
|
|
16
|
+
global __webapi__
|
|
17
|
+
|
|
18
|
+
if os.getenv("OTP_SKIP_OTQ_VALIDATION"):
|
|
19
|
+
return
|
|
20
|
+
|
|
21
|
+
_otq_import_ex = None
|
|
22
|
+
|
|
23
|
+
try:
|
|
24
|
+
# this import will fail if onetick python directory is not in sys.path
|
|
25
|
+
import onetick.query # noqa
|
|
26
|
+
try:
|
|
27
|
+
# this import will fail if numpy directory is not in sys.path on old OneTick versions
|
|
28
|
+
import NumPy_OneTickQuery
|
|
29
|
+
except ModuleNotFoundError as e:
|
|
30
|
+
_otq_import_ex = e
|
|
31
|
+
except Exception:
|
|
32
|
+
pass
|
|
33
|
+
except ImportError as e:
|
|
34
|
+
_otq_import_ex = e
|
|
35
|
+
|
|
36
|
+
import sysconfig
|
|
37
|
+
|
|
38
|
+
config_vars = sysconfig.get_config_vars()
|
|
39
|
+
|
|
40
|
+
ot_bin_path = os.path.join("bin")
|
|
41
|
+
ot_python_path = os.path.join(ot_bin_path, "python")
|
|
42
|
+
ot_numpy_path = os.path.join(
|
|
43
|
+
ot_bin_path,
|
|
44
|
+
"numpy",
|
|
45
|
+
"python"
|
|
46
|
+
# short python version 27, 36, 37, etc
|
|
47
|
+
+ config_vars["py_version_nodot"]
|
|
48
|
+
# suffix at the end, either empty string for python with the standard memory allocator,
|
|
49
|
+
# or 'm' for python with the py-malloc allocator
|
|
50
|
+
+ config_vars["abiflags"],
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
pythonpath = os.environ.get('PYTHONPATH')
|
|
54
|
+
|
|
55
|
+
missed_required = __get_missed_paths(pythonpath, ot_bin_path, ot_python_path)
|
|
56
|
+
missed_optional = __get_missed_paths(pythonpath, ot_numpy_path)
|
|
57
|
+
|
|
58
|
+
import warnings
|
|
59
|
+
if len(missed_required + missed_optional) != 3:
|
|
60
|
+
# TODO: move to onetick.py.compatibility
|
|
61
|
+
if _otq_import_ex is None and onetick.query.OneTickLib.get_build_number() >= 20230711120000:
|
|
62
|
+
warnings.warn(
|
|
63
|
+
'Using PYTHONPATH to specify the location of OneTick python libraries is deprecated.'
|
|
64
|
+
' Starting from OneTick build 20230711 onetick-py is also distributed as the part of the build,'
|
|
65
|
+
' and it will override onetick-py you may have installed from pip.'
|
|
66
|
+
' Use MAIN_ONE_TICK_DIR instead.'
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
try:
|
|
70
|
+
from .. import __search_main_one_tick_dir
|
|
71
|
+
main_one_tick_dirs = __search_main_one_tick_dir()
|
|
72
|
+
except ImportError:
|
|
73
|
+
# this exception will be raised if PYTHONPATH was used to specify the location of OneTick libraries
|
|
74
|
+
# and onetick-py doesn't exist in the specified OneTick or have older version than these lines
|
|
75
|
+
main_one_tick_dirs = None
|
|
76
|
+
|
|
77
|
+
if _otq_import_ex is None:
|
|
78
|
+
return
|
|
79
|
+
|
|
80
|
+
# PY-1033: if we can't import onetick.query, but can import onetick.query_webapi
|
|
81
|
+
# then we can just use it and don't need to raise any exception (even if OTP_WEBAPI is not set)
|
|
82
|
+
try:
|
|
83
|
+
import onetick.query_webapi
|
|
84
|
+
__webapi__ = True
|
|
85
|
+
return
|
|
86
|
+
except ImportError:
|
|
87
|
+
print('onetick.query_webapi is not available')
|
|
88
|
+
|
|
89
|
+
if isinstance(_otq_import_ex, ImportError):
|
|
90
|
+
raise ImportError(
|
|
91
|
+
'The above exception is probably raised '
|
|
92
|
+
'because your python version is unsupported in this OneTick build'
|
|
93
|
+
) from _otq_import_ex
|
|
94
|
+
|
|
95
|
+
# numpy directory is not needed on the latest onetick versions
|
|
96
|
+
# so checking it only if we couldn't import library
|
|
97
|
+
missed_paths = missed_required or missed_optional
|
|
98
|
+
|
|
99
|
+
if missed_paths or not main_one_tick_dirs:
|
|
100
|
+
|
|
101
|
+
if not missed_paths:
|
|
102
|
+
missed_paths = [ot_bin_path, ot_python_path, ot_numpy_path]
|
|
103
|
+
|
|
104
|
+
missed_paths = ', '.join(
|
|
105
|
+
"'" + os.path.join("<path-to-OneTick-dist>", p) + "'"
|
|
106
|
+
for p in missed_paths
|
|
107
|
+
)
|
|
108
|
+
if __webapi__:
|
|
109
|
+
raise ImportError(
|
|
110
|
+
"Environment variable OTP_WEBAPI is set, but we can't import onetick.query_webapi.\n"
|
|
111
|
+
"because we can't find it and related libraries.\n"
|
|
112
|
+
"Please, make sure you installed it with pip.\n"
|
|
113
|
+
"If you want to use OneTick distributed version\n"
|
|
114
|
+
f", make sure that directories {missed_paths} exist and:\n"
|
|
115
|
+
"- either those directories are specified in PYTHONPATH,\n"
|
|
116
|
+
"- or <path-to-OneTick-dist> directory is specified in MAIN_ONE_TICK_DIR (recommended)."
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
raise ImportError(
|
|
120
|
+
"We can't import onetick.query, because we can't find it and related libraries.\n"
|
|
121
|
+
f"Please, make sure that directories {missed_paths} exist and:\n"
|
|
122
|
+
"- either those directories are specified in PYTHONPATH,\n"
|
|
123
|
+
"- or <path-to-OneTick-dist> directory is specified in MAIN_ONE_TICK_DIR (recommended)."
|
|
124
|
+
) from _otq_import_ex
|
|
125
|
+
|
|
126
|
+
raise _otq_import_ex
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def __get_missed_paths(env, *paths, found_callback=None):
|
|
130
|
+
from pathlib import Path
|
|
131
|
+
|
|
132
|
+
missed_paths = []
|
|
133
|
+
env = env or ''
|
|
134
|
+
global_python_path = env.split(os.pathsep)
|
|
135
|
+
for p in paths:
|
|
136
|
+
match = False
|
|
137
|
+
for gb in global_python_path:
|
|
138
|
+
if Path(gb).match(f"*/{p}"):
|
|
139
|
+
match = True
|
|
140
|
+
if found_callback:
|
|
141
|
+
found_callback(gb, p)
|
|
142
|
+
break
|
|
143
|
+
if not match:
|
|
144
|
+
missed_paths.append(p)
|
|
145
|
+
return missed_paths
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def __set_onetick_path_variables():
|
|
149
|
+
if __webapi__ or os.getenv("OTP_SKIP_OTQ_VALIDATION"):
|
|
150
|
+
return
|
|
151
|
+
import warnings
|
|
152
|
+
import onetick.query as otq
|
|
153
|
+
from pathlib import Path
|
|
154
|
+
|
|
155
|
+
onetick_query_init = Path(otq.__file__)
|
|
156
|
+
|
|
157
|
+
# pylint: disable=global-variable-undefined
|
|
158
|
+
global __main_one_tick_dir__, __one_tick_bin_dir__, __one_tick_python_dir__
|
|
159
|
+
__one_tick_python_dir__ = str(onetick_query_init.parents[2])
|
|
160
|
+
__one_tick_bin_dir__ = str(onetick_query_init.parents[3])
|
|
161
|
+
__main_one_tick_dir__ = str(onetick_query_init.parents[4])
|
|
162
|
+
|
|
163
|
+
if os.name == 'nt' and __one_tick_bin_dir__ not in os.environ.get('PATH', '').split(os.pathsep):
|
|
164
|
+
warnings.warn(
|
|
165
|
+
f'OneTick {__one_tick_bin_dir__} is not specified in PATH environment variable.'
|
|
166
|
+
' Some functionality, e.g. using per-tick script, may be unavailable in this case.'
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
__validate_onetick_query_integration()
|
|
171
|
+
__set_onetick_path_variables()
|
|
172
|
+
|
|
173
|
+
# -------------------------------------------- #
|
|
174
|
+
|
|
175
|
+
from ._stack_info import _modify_stack_info_in_onetick_query
|
|
176
|
+
_modify_stack_info_in_onetick_query()
|
|
177
|
+
|
|
178
|
+
# -------------------------------------------- #
|
|
179
|
+
|
|
180
|
+
from onetick.py import functions, aggregations
|
|
181
|
+
from onetick.py.functions import (
|
|
182
|
+
concat, join, join_by_time, apply_query, apply, cut, qcut, merge, coalesce, corp_actions, format,
|
|
183
|
+
join_with_aggregated_window
|
|
184
|
+
)
|
|
185
|
+
from onetick.py.types import (
|
|
186
|
+
msectime, nsectime, string, nan, inf, datetime, date, dt, varstring,
|
|
187
|
+
_int as int, uint, long, ulong, byte, short, decimal,
|
|
188
|
+
Year, Quarter, Month, Week, Day, Hour, Minute, Second, Milli, Nano,
|
|
189
|
+
default_by_type, timedelta,
|
|
190
|
+
)
|
|
191
|
+
from onetick.py.sources import (Tick, TTicks, Ticks, Orders, Trades, NBBO, Quotes, Query, CSV, ReadCache, ReadParquet,
|
|
192
|
+
Custom, query, Symbols, Empty, DataSource, LocalCSVTicks, SymbologyMapping,
|
|
193
|
+
ObSnapshot, ObSnapshotWide, ObSnapshotFlat, ObSummary, ObSize, ObVwap, ObNumLevels,
|
|
194
|
+
by_symbol, ODBC, SplitQueryOutputBySymbol, DataFile, PointInTime,
|
|
195
|
+
ReadSnapshot, ShowSnapshotList, FindSnapshotSymbols)
|
|
196
|
+
from onetick.py.utils import adaptive, range, perf
|
|
197
|
+
from onetick.py.session import Session, TestSession, Config, Locator, HTTPSession
|
|
198
|
+
from onetick.py.servers import RemoteTS, LoadBalancing, FaultTolerance
|
|
199
|
+
from onetick.py.db import DB, RefDB
|
|
200
|
+
from onetick.py.db._inspection import databases, derived_databases
|
|
201
|
+
from onetick.py.cache import create_cache, delete_cache, modify_cache_config
|
|
202
|
+
from onetick.py import state
|
|
203
|
+
from onetick.py.core.source import Source, MetaFields
|
|
204
|
+
from onetick.py.core.multi_output_source import MultiOutputSource
|
|
205
|
+
from onetick.py.core.eval_query import eval # noqa: it is ok to redefine built-in function
|
|
206
|
+
from onetick.py.core.per_tick_script import (
|
|
207
|
+
# TODO: wanna access per_tick_script classes as otp.script.static and so on
|
|
208
|
+
Static as static,
|
|
209
|
+
TickDescriptorFields as tick_descriptor_fields,
|
|
210
|
+
tick_list_tick,
|
|
211
|
+
tick_set_tick,
|
|
212
|
+
tick_deque_tick,
|
|
213
|
+
dynamic_tick,
|
|
214
|
+
)
|
|
215
|
+
from onetick.py.callback import CallbackBase
|
|
216
|
+
from onetick.py.sql import SqlQuery
|
|
217
|
+
from onetick.py.run import run, run_async
|
|
218
|
+
from onetick.py.math import rand, now
|
|
219
|
+
from onetick.py.misc import (
|
|
220
|
+
bit_and, bit_or, bit_at, bit_xor, bit_not,
|
|
221
|
+
hash_code,
|
|
222
|
+
get_symbology_mapping,
|
|
223
|
+
get_onetick_version,
|
|
224
|
+
get_username,
|
|
225
|
+
)
|
|
226
|
+
from onetick.py.core.column import Column
|
|
227
|
+
from onetick.py.core.column_operations.base import Operation, Expr as expr, Raw as raw, OnetickParameter as param
|
|
228
|
+
from onetick.py.core.per_tick_script import remote, Once, once, logf, throw_exception
|
|
229
|
+
from onetick.py.configuration import config
|
|
230
|
+
from onetick.py import oqd
|
|
231
|
+
from onetick.py.otq import otli
|
|
232
|
+
OneTickLib = otli.OneTickLib
|
|
233
|
+
|
|
234
|
+
try:
|
|
235
|
+
from pandas import date_range
|
|
236
|
+
except Exception:
|
|
237
|
+
pass
|
|
238
|
+
|
|
239
|
+
meta_fields = MetaFields()
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def __getattr__(name):
|
|
243
|
+
# actually, these values are not evaluated on module loading anymore,
|
|
244
|
+
# so they can be used without fear
|
|
245
|
+
# but let's raise deprecation warning anyway
|
|
246
|
+
# to encourage users to use otp.config only
|
|
247
|
+
defaults = dict(
|
|
248
|
+
# lambdas are needed in case some config values are not set,
|
|
249
|
+
# so we don't raise exception on getting any attribute
|
|
250
|
+
DEFAULT_START_TIME=lambda: config.default_start_time,
|
|
251
|
+
DEFAULT_END_TIME=lambda: config.default_end_time,
|
|
252
|
+
DEFAULT_TZ=lambda: config.tz,
|
|
253
|
+
DEFAULT_SYMBOL=lambda: config.default_symbol,
|
|
254
|
+
DEFAULT_DB=lambda: config.default_db,
|
|
255
|
+
DEFAULT_DB_SYMBOL=lambda: config.default_db_symbol,
|
|
256
|
+
)
|
|
257
|
+
if name in defaults:
|
|
258
|
+
import warnings
|
|
259
|
+
warnings.warn(
|
|
260
|
+
f'Using otp.{name} is deprecated, use otp.config.* properties instead.',
|
|
261
|
+
FutureWarning
|
|
262
|
+
)
|
|
263
|
+
return defaults[name]()
|
|
264
|
+
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
# aliases
|
|
268
|
+
funcs = functions # type: ignore # noqa
|
|
269
|
+
agg = aggregations # type: ignore # noqa
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
# set pandas default pandas options to show all columns
|
|
273
|
+
import pandas as _pd
|
|
274
|
+
|
|
275
|
+
_pd.set_option("display.max_columns", None)
|
|
276
|
+
_pd.set_option("display.expand_frame_repr", False)
|
|
277
|
+
_pd.set_option("max_colwidth", None)
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
from onetick.py.otq import otq as _otq
|
|
281
|
+
try:
|
|
282
|
+
__build__ = str(_otq.OneTickLib.get_build_number())
|
|
283
|
+
except AttributeError:
|
|
284
|
+
__build__ = 'webapi'
|
|
285
|
+
|
|
286
|
+
# initialize logger module and import public api
|
|
287
|
+
from .log import get_logger
|
|
288
|
+
|
|
289
|
+
del (_version,
|
|
290
|
+
_otq,
|
|
291
|
+
_pd,
|
|
292
|
+
_modify_stack_info_in_onetick_query,
|
|
293
|
+
otli)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import traceback
|
|
3
|
+
from typing import List
|
|
4
|
+
|
|
5
|
+
from .configuration import config
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# dictionary to save traceback lines
|
|
9
|
+
_TRACE_LINES = {}
|
|
10
|
+
# dictionary to save traceback tuples
|
|
11
|
+
_TRACE_TUPLES = {}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _get_id_with_traceback(tb_list: List[str]) -> str:
|
|
15
|
+
"""
|
|
16
|
+
Save traceback in some memory-efficient way
|
|
17
|
+
and return unique id of the traceback.
|
|
18
|
+
"""
|
|
19
|
+
trace_list = []
|
|
20
|
+
for line in tb_list:
|
|
21
|
+
if line not in _TRACE_LINES:
|
|
22
|
+
# using the same string objects for different tracebacks
|
|
23
|
+
_TRACE_LINES[line] = line
|
|
24
|
+
trace_list.append(_TRACE_LINES[line])
|
|
25
|
+
|
|
26
|
+
trace_tuple = tuple(trace_list)
|
|
27
|
+
trace_hash = str(hash(trace_tuple))
|
|
28
|
+
if trace_hash not in _TRACE_TUPLES:
|
|
29
|
+
# using the same tuple objects for different tracebacks
|
|
30
|
+
_TRACE_TUPLES[trace_hash] = trace_tuple
|
|
31
|
+
return trace_hash
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _get_traceback_with_id(trace_hash: str) -> str:
|
|
35
|
+
"""
|
|
36
|
+
Get our custom saved traceback from dictionary by hash.
|
|
37
|
+
"""
|
|
38
|
+
return ''.join(_TRACE_TUPLES[trace_hash])
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _modify_stack_info_in_onetick_query():
|
|
42
|
+
"""
|
|
43
|
+
Change stack_info parameter in all OneTick's event processors.
|
|
44
|
+
Save full traceback instead of filename + line number.
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
def modify_init(cls):
|
|
48
|
+
old_init = cls.__init__
|
|
49
|
+
|
|
50
|
+
def new_init(self, *args, **kwargs):
|
|
51
|
+
old_init(self, *args, **kwargs)
|
|
52
|
+
if config.show_stack_info and hasattr(self, 'stack_info'):
|
|
53
|
+
self.stack_info = _get_id_with_traceback(traceback.format_stack()[:-1])
|
|
54
|
+
|
|
55
|
+
cls.__init__ = new_init
|
|
56
|
+
|
|
57
|
+
from onetick.py.otq import otq
|
|
58
|
+
eps_classes = (
|
|
59
|
+
cls for cls in otq.__dict__.values()
|
|
60
|
+
if isinstance(cls, type) and issubclass(cls, otq.EpBase) and cls is not otq.EpBase
|
|
61
|
+
)
|
|
62
|
+
for ep_cls in eps_classes:
|
|
63
|
+
modify_init(ep_cls)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _add_stack_info_to_exception(exc):
|
|
67
|
+
"""
|
|
68
|
+
Find stack_info parameter in OneTick exception message.
|
|
69
|
+
Get stack trace and append it to the passed exception.
|
|
70
|
+
"""
|
|
71
|
+
if not config.show_stack_info:
|
|
72
|
+
return exc
|
|
73
|
+
|
|
74
|
+
_, _, location_details = str(exc).partition('Problem location details:')
|
|
75
|
+
stack_info_uuid = None
|
|
76
|
+
for block in location_details.strip().split(','):
|
|
77
|
+
name, _, value = block.partition('=')
|
|
78
|
+
if name == 'stack_info':
|
|
79
|
+
stack_info_uuid = value
|
|
80
|
+
break
|
|
81
|
+
|
|
82
|
+
if not stack_info_uuid:
|
|
83
|
+
return exc
|
|
84
|
+
|
|
85
|
+
stack_info = _get_traceback_with_id(stack_info_uuid)
|
|
86
|
+
|
|
87
|
+
if exc.args:
|
|
88
|
+
exc.args = (exc.args[0] + os.linesep + stack_info, *exc.args[1:])
|
|
89
|
+
return exc
|
onetick/py/_version.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from .functions import (compute, max, min, high_tick, low_tick, high_time, low_time, first, last, first_time, last_time,
|
|
2
|
+
count, vwap, first_tick, last_tick, distinct, sum, average, mean, stddev, tw_average, median,
|
|
3
|
+
ob_num_levels, ob_size, ob_snapshot, ob_snapshot_wide, ob_snapshot_flat, ob_summary, ob_vwap,
|
|
4
|
+
generic, correlation, option_price, ranking, variance, percentile, find_value_for_percentile,
|
|
5
|
+
exp_w_average, exp_tw_average, standardized_moment, portfolio_price, multi_portfolio_price,
|
|
6
|
+
return_ep, implied_vol, linear_regression)
|
|
7
|
+
|
|
8
|
+
try:
|
|
9
|
+
from .num_distinct import num_distinct
|
|
10
|
+
except ImportError:
|
|
11
|
+
pass
|