otp.merge#
- merge(sources, align_schema=True, symbols=None, identify_input_ts=False, presort=adaptive, concurrency=default, batch_size=default, output_type_index=None)[source]#
Merges ticks from the
sources
into a single output ordered by the timestamp- Parameters
sources (list) – List of sources to merge
align_schema (bool) – If set to True, then table is added right after merge. We recommended to keep True to prevent problems with different tick schemas. Default: True
symbols (str, list of str or functions,
Source
) – Symbol(s) to run the query for passed as a string, a list of strings, or as a “symbols” query which results include theSYMBOL_NAME
column. The start/end times for the symbols query will taken from therun()
params. See symbols for more details.identify_input_ts (bool) – If set to False, the fields SYMBOL_NAME and TICK_TYPE are not appended to the output ticks.
presort (bool) – Add the presort EP in case of bound symbols. Applicable only when
symbols
is not None. By default, it is set to True ifsymbols
are set and to False otherwise.concurrency (int) – Specifies number of CPU cores to utilize for the
presort
By default, the value from otp.config.default_concurrency is used.batch_size (int) – Specifies the query batch size for the
presort
. By default, the value from otp.config.default_batch_size is used.output_type_index (int) – Specifies index of source in
sources
from which type and properties of output will be taken. Useful when merging sources that inherited fromSource
. By default, output object type will beSource
.
- Returns
A time series of ticks.
- Return type
Source
or same class assources[output_type_index]
Examples
merge
is used to merge different data sources>>> data1 = otp.Ticks(X=[1, 2], Y=['a', 'd']) >>> data2 = otp.Ticks(X=[-1, -2], Y=['*', '-']) >>> data = otp.funcs.merge([data1, data2]) >>> otp.run(data) Time X Y 0 2003-12-01 00:00:00.000 1 a 1 2003-12-01 00:00:00.000 -1 * 2 2003-12-01 00:00:00.001 2 d 3 2003-12-01 00:00:00.001 -2 -
Merge series from multiple symbols into one series
>>> data = otp.Ticks(X=[1]) >>> data['SYMBOL_NAME'] = data['_SYMBOL_NAME'] >>> symbols = otp.Ticks(SYMBOL_NAME=['A', 'B']) >>> data = otp.merge([data], symbols=symbols) >>> data() Time X SYMBOL_NAME 0 2003-12-01 1 A 1 2003-12-01 1 B
Adding symbols param before merge
>>> symbols = otp.Ticks(SYMBOL_NAME=['S1', 'S2'], param=[1, -1]) >>> def func(symbol): ... pre = otp.Ticks(X=[1]) ... pre["SYMBOL_NAME"] = symbol.name ... pre["PARAM"] = symbol.param ... return pre >>> data = otp.funcs.merge([func], symbols=symbols) >>> otp.run(data)[['PARAM', 'SYMBOL_NAME']] PARAM SYMBOL_NAME 0 1 S1 1 -1 S2
See also
MERGE OneTick event processor