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,85 @@
|
|
|
1
|
+
from onetick.py.core.source import Source
|
|
2
|
+
|
|
3
|
+
from .. import utils
|
|
4
|
+
|
|
5
|
+
from .common import _common_passthrough_base_ep
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Orders(Source):
|
|
9
|
+
def __init__(
|
|
10
|
+
self, db="S_ORDERS_FIX", symbol=utils.adaptive, start=utils.adaptive, end=utils.adaptive, schema=None, **kwargs,
|
|
11
|
+
):
|
|
12
|
+
super().__init__(
|
|
13
|
+
_symbols=symbol, _start=start, _end=end, _base_ep_func=lambda: self.base_ep(db), schema=schema, **kwargs,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
self.schema['ID'] = str
|
|
17
|
+
self.schema['BUY_FLAG'] = int
|
|
18
|
+
self.schema['SIDE'] = str
|
|
19
|
+
self.schema['STATE'] = str
|
|
20
|
+
self.schema['ORDTYPE'] = str
|
|
21
|
+
self.schema['PRICE'] = float
|
|
22
|
+
self.schema['PRICE_FILLED'] = float
|
|
23
|
+
self.schema['QTY'] = int
|
|
24
|
+
self.schema['QTY_FILLED'] = int
|
|
25
|
+
|
|
26
|
+
def base_ep(self, db):
|
|
27
|
+
return _common_passthrough_base_ep(db, 'ORDER')
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class Quotes(Source):
|
|
31
|
+
def __init__(
|
|
32
|
+
self, db=utils.adaptive_to_default, symbol=utils.adaptive, start=utils.adaptive, end=utils.adaptive,
|
|
33
|
+
schema=None, **kwargs,
|
|
34
|
+
):
|
|
35
|
+
super().__init__(
|
|
36
|
+
_symbols=symbol, _start=start, _end=end, _base_ep_func=lambda: self.base_ep(db), schema=schema, **kwargs,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
self.schema['ASK_PRICE'] = float
|
|
40
|
+
self.schema['BID_PRICE'] = float
|
|
41
|
+
self.schema['ASK_SIZE'] = int
|
|
42
|
+
self.schema['BID_SIZE'] = int
|
|
43
|
+
|
|
44
|
+
def base_ep(self, db):
|
|
45
|
+
return _common_passthrough_base_ep(db, 'QTE')
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class Trades(Source):
|
|
49
|
+
"""
|
|
50
|
+
Trade source object.
|
|
51
|
+
add 'PRICE' and 'SIZE' fields to schema
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
def __init__(
|
|
55
|
+
self, db=utils.adaptive_to_default, symbol=utils.adaptive, date=None, start=utils.adaptive, end=utils.adaptive,
|
|
56
|
+
schema=None, **kwargs,
|
|
57
|
+
):
|
|
58
|
+
if date:
|
|
59
|
+
start, end = date.start, date.end
|
|
60
|
+
super().__init__(
|
|
61
|
+
_symbols=symbol, _start=start, _end=end, _base_ep_func=lambda: self.base_ep(db), schema=schema, **kwargs,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
self.schema['PRICE'] = float
|
|
65
|
+
self.schema['SIZE'] = int
|
|
66
|
+
|
|
67
|
+
def base_ep(self, db):
|
|
68
|
+
return _common_passthrough_base_ep(db, 'TRD')
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class NBBO(Source):
|
|
72
|
+
def __init__(
|
|
73
|
+
self, db="TAQ_NBBO", symbol=utils.adaptive, start=utils.adaptive, end=utils.adaptive, schema=None, **kwargs,
|
|
74
|
+
):
|
|
75
|
+
super().__init__(
|
|
76
|
+
_symbols=symbol, _start=start, _end=end, _base_ep_func=lambda: self.base_ep(db), schema=schema, **kwargs,
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
self.schema['ASK_PRICE'] = float
|
|
80
|
+
self.schema['BID_PRICE'] = float
|
|
81
|
+
self.schema['ASK_SIZE'] = int
|
|
82
|
+
self.schema['BID_SIZE'] = int
|
|
83
|
+
|
|
84
|
+
def base_ep(self, db):
|
|
85
|
+
return _common_passthrough_base_ep(db, 'NBBO')
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from onetick.py.otq import otq
|
|
4
|
+
|
|
5
|
+
from onetick.py.core.source import Source
|
|
6
|
+
from onetick.py.backports import Literal
|
|
7
|
+
|
|
8
|
+
from .. import utils
|
|
9
|
+
from ..compatibility import (
|
|
10
|
+
is_data_file_query_supported,
|
|
11
|
+
is_data_file_query_symbology_supported,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
from .common import update_node_tick_type
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class DataFile(Source):
|
|
18
|
+
|
|
19
|
+
_PROPERTIES = Source._PROPERTIES + [
|
|
20
|
+
'_file',
|
|
21
|
+
'_msg_format',
|
|
22
|
+
'_symbol_name_field',
|
|
23
|
+
'_symbology',
|
|
24
|
+
'_timestamp_column',
|
|
25
|
+
'_time_assignment',
|
|
26
|
+
'_file_contents',
|
|
27
|
+
'_format_file',
|
|
28
|
+
'_config_dir',
|
|
29
|
+
'_db',
|
|
30
|
+
'_tick_type',
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
def __init__(
|
|
34
|
+
self,
|
|
35
|
+
file: Optional[str] = None,
|
|
36
|
+
msg_format: Literal['arrow', 'json'] = 'arrow',
|
|
37
|
+
symbol_name_field: str = 'SYMBOL_NAME',
|
|
38
|
+
symbology: Optional[str] = None,
|
|
39
|
+
timestamp_column: Optional[str] = None,
|
|
40
|
+
time_assignment=utils.adaptive,
|
|
41
|
+
file_contents: Optional[str] = None,
|
|
42
|
+
format_file: Optional[str] = None,
|
|
43
|
+
config_dir: Optional[str] = None,
|
|
44
|
+
start=utils.adaptive,
|
|
45
|
+
end=utils.adaptive,
|
|
46
|
+
db=utils.adaptive,
|
|
47
|
+
tick_type=utils.adaptive,
|
|
48
|
+
symbols=utils.adaptive_to_default,
|
|
49
|
+
schema=None,
|
|
50
|
+
**kwargs,
|
|
51
|
+
):
|
|
52
|
+
"""
|
|
53
|
+
Reads data streams in supported formats from file or file content,
|
|
54
|
+
processes these streams to generate ticks,
|
|
55
|
+
and queries the result against a list of symbols.
|
|
56
|
+
|
|
57
|
+
Continuous event processing (CEP) of the data file is currently supported only for the JSON format.
|
|
58
|
+
For other formats, or if the file content is specified,
|
|
59
|
+
EP will function without continuous processing (no exception will be thrown).
|
|
60
|
+
|
|
61
|
+
Note
|
|
62
|
+
----
|
|
63
|
+
The method is supported only on 64-bit Windows/Linux platforms.
|
|
64
|
+
|
|
65
|
+
Parameters
|
|
66
|
+
----------
|
|
67
|
+
file:
|
|
68
|
+
Specifies the path of the file to process.
|
|
69
|
+
The parameter **DATA_FILE_PATH** in the OneTick configuration file specifies the set of directories
|
|
70
|
+
where this file is searched for if the value of this parameter is a relative path.
|
|
71
|
+
|
|
72
|
+
When run on a tick server with the **TICK_SERVER_DATA_CACHE_DIR** OneTick configuration variable
|
|
73
|
+
pointing to a directory,
|
|
74
|
+
this method will attempt to fetch the file from the host
|
|
75
|
+
if the file is not found locally.
|
|
76
|
+
Fetched files will be cached in this directory.
|
|
77
|
+
|
|
78
|
+
To use AWS S3 file system paths,
|
|
79
|
+
the **AWS_ACCESS_KEY_ID** and **AWS_SECRET_ACCESS_KEY** environment variables must be set.
|
|
80
|
+
Note: Currently, AWS S3 is supported only for the ``arrow`` format.
|
|
81
|
+
msg_format:
|
|
82
|
+
Specifies the format of input data: *arrow* or *json*.
|
|
83
|
+
symbol_name_field:
|
|
84
|
+
Defines the field expected to contain the symbol name.
|
|
85
|
+
Its data type should be either `string` or `varstring`.
|
|
86
|
+
When one or more symbols are specified for the query or this method,
|
|
87
|
+
only ticks corresponding to those symbols will be propagated.
|
|
88
|
+
symbology:
|
|
89
|
+
Defines the symbology of symbol names (values of ``symbol_name_field``) in the data file.
|
|
90
|
+
If specified, to find correct time series in the file for the query symbol
|
|
91
|
+
this method will first search for synonym[s] of the symbols
|
|
92
|
+
in the specified symbology using reference database.
|
|
93
|
+
Then it will find the history of this new symbol for the query interval
|
|
94
|
+
and finally will query the data file using the symbol names from history.
|
|
95
|
+
timestamp_column:
|
|
96
|
+
If provided, the value of this field will be used to set the timestamps for the ticks.
|
|
97
|
+
In the case of ``msg_format=arrow``, the Arrow type of this field must be `DATE64`, `TIMESTAMP`
|
|
98
|
+
or `INT64` with metadata `"TIMESTAMP_TYPE=NANO/MILLI"`.
|
|
99
|
+
time_assignment:
|
|
100
|
+
Specifies whether the timestamps for the ticks are set to either the start time or end time of the query.
|
|
101
|
+
file_contents:
|
|
102
|
+
If not empty, this method treats its value as a stream from which it should read and construct ticks.
|
|
103
|
+
format_file:
|
|
104
|
+
Specifies the absolute path of the message format file. This parameter applies only to *json* format.
|
|
105
|
+
config_dir:
|
|
106
|
+
Specifies the directory of the normalization file. This parameter applies only to *json* format.
|
|
107
|
+
start:
|
|
108
|
+
Custom start time of the query.
|
|
109
|
+
By default, the start time used by :py:func:`otp.run <onetick.py.run>` will be inherited.
|
|
110
|
+
end:
|
|
111
|
+
Custom end time of the query.
|
|
112
|
+
By default, the start time used by :py:func:`otp.run <onetick.py.run>` will be inherited.
|
|
113
|
+
db: str
|
|
114
|
+
Custom database name for the node of the graph.
|
|
115
|
+
By default, the database used by :py:func:`otp.run <onetick.py.run>` will be inherited.
|
|
116
|
+
tick_type: str
|
|
117
|
+
Custom tick type for the node of the graph.
|
|
118
|
+
By default, "ANY" tick type will be set.
|
|
119
|
+
symbols: str or list of str
|
|
120
|
+
Custom symbol name for the node of the graph.
|
|
121
|
+
By default, the symbol name used by :py:func:`otp.run <onetick.py.run>` will be inherited.
|
|
122
|
+
schema: dict
|
|
123
|
+
Set the schema of the python :py:class:`~onetick.py.Source` object of this class.
|
|
124
|
+
|
|
125
|
+
Schema can't be automatically derived from the file, so it should be set manually
|
|
126
|
+
for Python-level type checking to work.
|
|
127
|
+
kwargs:
|
|
128
|
+
Deprecated. Use ``schema`` instead.
|
|
129
|
+
Set the schema of the python :py:class:`~onetick.py.Source` object of this class.
|
|
130
|
+
|
|
131
|
+
See also
|
|
132
|
+
--------
|
|
133
|
+
**DATA_FILE_QUERY** OneTick event processor
|
|
134
|
+
|
|
135
|
+
Examples
|
|
136
|
+
--------
|
|
137
|
+
|
|
138
|
+
Get data from the arrow file:
|
|
139
|
+
|
|
140
|
+
.. testcode::
|
|
141
|
+
:skipif: not is_data_file_query_supported()
|
|
142
|
+
|
|
143
|
+
import os
|
|
144
|
+
path_to_arrow_file = os.path.join(csv_path, 'data.arrow')
|
|
145
|
+
|
|
146
|
+
data = otp.DataFile(path_to_arrow_file)
|
|
147
|
+
df = otp.run(data)
|
|
148
|
+
print(df)
|
|
149
|
+
|
|
150
|
+
.. testoutput::
|
|
151
|
+
|
|
152
|
+
Time A SYMBOL_NAME T_TIME
|
|
153
|
+
0 2003-12-04 1 AAPL 2003-12-01 00:00:00
|
|
154
|
+
1 2003-12-04 3 AAPL 2003-12-01 02:00:00
|
|
155
|
+
|
|
156
|
+
The ``symbol_name_field`` parameter can be used to specify the name of the field containing symbol names.
|
|
157
|
+
The default value for this parameter is **SYMBOL_NAME**, and this field must be specified in the Arrow file.
|
|
158
|
+
The symbols specified for the query will determine which data will be queried from the Arrow file:
|
|
159
|
+
|
|
160
|
+
.. testcode::
|
|
161
|
+
:skipif: not is_data_file_query_supported()
|
|
162
|
+
|
|
163
|
+
data = otp.DataFile(path_to_arrow_file)
|
|
164
|
+
df = otp.run(data, symbols='MSFT')
|
|
165
|
+
print(df)
|
|
166
|
+
|
|
167
|
+
.. testoutput::
|
|
168
|
+
|
|
169
|
+
Time A SYMBOL_NAME T_TIME
|
|
170
|
+
0 2003-12-04 2 MSFT 2003-12-01 01:00:00
|
|
171
|
+
|
|
172
|
+
To get all symbols from file, you can specify a database without a symbol when running query:
|
|
173
|
+
|
|
174
|
+
.. testcode::
|
|
175
|
+
:skipif: not is_data_file_query_supported()
|
|
176
|
+
|
|
177
|
+
data = otp.DataFile(path_to_arrow_file)
|
|
178
|
+
df = otp.run(data, symbols=f'{otp.config.default_db}::')
|
|
179
|
+
print(df)
|
|
180
|
+
|
|
181
|
+
.. testoutput::
|
|
182
|
+
|
|
183
|
+
Time A SYMBOL_NAME T_TIME
|
|
184
|
+
0 2003-12-04 1 AAPL 2003-12-01 00:00:00
|
|
185
|
+
1 2003-12-04 2 MSFT 2003-12-01 01:00:00
|
|
186
|
+
2 2003-12-04 3 AAPL 2003-12-01 02:00:00
|
|
187
|
+
|
|
188
|
+
Default time assigned to ticks is query end time.
|
|
189
|
+
Use parameter ``time_assignment`` to change the timestamps for ticks to the query start time:
|
|
190
|
+
|
|
191
|
+
.. testcode::
|
|
192
|
+
:skipif: not is_data_file_query_supported()
|
|
193
|
+
|
|
194
|
+
data = otp.DataFile(path_to_arrow_file, time_assignment='start')
|
|
195
|
+
df = otp.run(data)
|
|
196
|
+
print(df)
|
|
197
|
+
|
|
198
|
+
.. testoutput::
|
|
199
|
+
|
|
200
|
+
Time A SYMBOL_NAME T_TIME
|
|
201
|
+
0 2003-12-01 1 AAPL 2003-12-01 00:00:00
|
|
202
|
+
1 2003-12-01 3 AAPL 2003-12-01 02:00:00
|
|
203
|
+
|
|
204
|
+
Or use parameter ``timestamp_column`` to get the timestamps from some field:
|
|
205
|
+
|
|
206
|
+
.. testcode::
|
|
207
|
+
:skipif: not is_data_file_query_supported()
|
|
208
|
+
|
|
209
|
+
data = otp.DataFile(path_to_arrow_file, timestamp_column='T_TIME')
|
|
210
|
+
df = otp.run(data)
|
|
211
|
+
print(df)
|
|
212
|
+
|
|
213
|
+
.. testoutput::
|
|
214
|
+
|
|
215
|
+
Time A SYMBOL_NAME T_TIME
|
|
216
|
+
0 2003-12-01 00:00:00 1 AAPL 2003-12-01 00:00:00
|
|
217
|
+
1 2003-12-01 02:00:00 3 AAPL 2003-12-01 02:00:00
|
|
218
|
+
|
|
219
|
+
The schema of the data can't be checked when constructing query at the Python level,
|
|
220
|
+
so in order to use the fields of the source in other onetick-py methods,
|
|
221
|
+
schema must be specified manually:
|
|
222
|
+
|
|
223
|
+
.. testcode::
|
|
224
|
+
:skipif: not is_data_file_query_supported()
|
|
225
|
+
|
|
226
|
+
data = otp.DataFile(path_to_arrow_file,
|
|
227
|
+
schema={'A': int, 'SYMBOL_NAME': str, 'T_TIME': otp.nsectime})
|
|
228
|
+
data['B'] = data['A'] * 2
|
|
229
|
+
df = otp.run(data)
|
|
230
|
+
print(df)
|
|
231
|
+
|
|
232
|
+
.. testoutput::
|
|
233
|
+
|
|
234
|
+
Time A SYMBOL_NAME T_TIME B
|
|
235
|
+
0 2003-12-04 1 AAPL 2003-12-01 00:00:00 2
|
|
236
|
+
1 2003-12-04 3 AAPL 2003-12-01 02:00:00 6
|
|
237
|
+
"""
|
|
238
|
+
if self._try_default_constructor(schema=schema, **kwargs):
|
|
239
|
+
return
|
|
240
|
+
|
|
241
|
+
if not is_data_file_query_supported():
|
|
242
|
+
raise RuntimeError("The otp.DataFile is not supported on this OneTick build")
|
|
243
|
+
|
|
244
|
+
if not file and not file_contents:
|
|
245
|
+
raise ValueError("One of the parameters 'file' or 'file_contents' must be specified")
|
|
246
|
+
|
|
247
|
+
if msg_format not in {'json', 'arrow'}:
|
|
248
|
+
raise ValueError(f"Unknown value for the parameter 'msg_format': {msg_format}")
|
|
249
|
+
|
|
250
|
+
if timestamp_column and time_assignment is not utils.adaptive:
|
|
251
|
+
raise ValueError("The parameters 'timestamp_column' and 'time_assignment' cannot be set simultaneously")
|
|
252
|
+
|
|
253
|
+
if time_assignment is utils.adaptive:
|
|
254
|
+
time_assignment = 'end'
|
|
255
|
+
|
|
256
|
+
if time_assignment not in {'start', 'end'}:
|
|
257
|
+
raise ValueError(f"Unknown value for parameter 'time_assignment': {time_assignment}")
|
|
258
|
+
|
|
259
|
+
if msg_format != 'json' and (format_file or config_dir):
|
|
260
|
+
raise ValueError("The parameters 'format_file' and 'config_dir' can only be specified with 'json' format")
|
|
261
|
+
|
|
262
|
+
self._file = file
|
|
263
|
+
self._msg_format = msg_format.upper()
|
|
264
|
+
self._symbol_name_field = symbol_name_field
|
|
265
|
+
self._symbology = symbology
|
|
266
|
+
self._timestamp_column = timestamp_column
|
|
267
|
+
self._time_assignment = f'_{time_assignment.upper()}_TIME'
|
|
268
|
+
self._file_contents = file_contents
|
|
269
|
+
self._format_file = format_file
|
|
270
|
+
self._config_dir = config_dir
|
|
271
|
+
self._db = db
|
|
272
|
+
self._tick_type = tick_type
|
|
273
|
+
|
|
274
|
+
super().__init__(
|
|
275
|
+
_symbols=symbols, _start=start, _end=end, _base_ep_func=lambda: self.base_ep(schema=schema, **kwargs),
|
|
276
|
+
schema=schema, **kwargs,
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
def base_ep(self, schema=None, **kwargs):
|
|
280
|
+
|
|
281
|
+
ep_kwargs = {}
|
|
282
|
+
if self._symbology is not None:
|
|
283
|
+
if is_data_file_query_symbology_supported(throw_warning=True,
|
|
284
|
+
feature_name="parameter 'symbology' in otp.DataFile"):
|
|
285
|
+
ep_kwargs['symbology'] = self._symbology
|
|
286
|
+
|
|
287
|
+
src = Source(
|
|
288
|
+
otq.DataFileQuery(
|
|
289
|
+
file=self._file or '',
|
|
290
|
+
msg_format=self._msg_format,
|
|
291
|
+
symbol_name_field=self._symbol_name_field,
|
|
292
|
+
timestamp_column=self._timestamp_column or '',
|
|
293
|
+
time_assignment=self._time_assignment,
|
|
294
|
+
file_contents=self._file_contents or '',
|
|
295
|
+
format_file=self._format_file or '',
|
|
296
|
+
config_dir=self._config_dir or '',
|
|
297
|
+
**ep_kwargs,
|
|
298
|
+
),
|
|
299
|
+
schema=schema,
|
|
300
|
+
**kwargs,
|
|
301
|
+
)
|
|
302
|
+
|
|
303
|
+
update_node_tick_type(src, self._tick_type, self._db)
|
|
304
|
+
|
|
305
|
+
return src
|