# otp.ops.sametime_as_existing

### sametime_as_existing(left_time, right_time, delay_msec)

If `delay_msec` is positive, it returns **True** for a tick from the passed left time series and the latest tick
from the passed right time series that arrived at least by `delay_msec` before the tick from the left time series.

If `delay_msec` is negative, it returns **True** for a tick from the passed left time series and the latest tick
from the passed right time series that arrived at most `delay_msec` after the tick from the left time series;
that is, the latest tick from the interval `(-Inf, t1 + |delay_msec|]`, where `t1` is the timestamp of the tick
from the left time series.

Can be used only in the `on` parameter of [`onetick.py.join()`](https://docs.pip.distribution.sol.onetick.com/api/functions/join.html.md#onetick.py.join).

* **Parameters:**
  * **left_time** ([`Column`](https://docs.pip.distribution.sol.onetick.com/api/operation/root.html.md#onetick.py.Column)) -- Timestamp column of the left source (`left['TIMESTAMP']`).
  * **right_time** ([`Column`](https://docs.pip.distribution.sol.onetick.com/api/operation/root.html.md#onetick.py.Column)) -- Timestamp column of the right source (`right['TIMESTAMP']`).
  * **delay_msec** ([*int*](https://docs.pip.distribution.sol.onetick.com/api/types/int.html.md#onetick.py.int)) -- Delay in milliseconds.
* **Return type:**
  [`Operation`](https://docs.pip.distribution.sol.onetick.com/api/operation/root.html.md#onetick.py.Operation)

### Examples

Join each tick from the left source with the latest tick from the right source
that arrived at least 2 milliseconds before it:

```pycon
>>> left = otp.Ticks(A=[1, 2, 3], offset=[3, 5, 7])
>>> right = otp.Ticks(B=[10, 20, 30, 40], offset=[0, 2, 4, 6])
>>> data = otp.join(left, right, on=otp.ops.sametime_as_existing(left['TIMESTAMP'], right['TIMESTAMP'], 2))
>>> otp.run(data)
                     Time  A   B
0 2003-12-01 00:00:00.003  1  10
1 2003-12-01 00:00:00.005  2  20
2 2003-12-01 00:00:00.007  3  30
```

With negative delay ticks from the right source that arrived less than 2 milliseconds after
the tick from the left source are also considered:

```pycon
>>> data = otp.join(left, right, on=otp.ops.sametime_as_existing(left['TIMESTAMP'], right['TIMESTAMP'], -2))
>>> otp.run(data)
                     Time  A   B
0 2003-12-01 00:00:00.003  1  30
1 2003-12-01 00:00:00.005  2  40
2 2003-12-01 00:00:00.007  3  40
```

#### SEE ALSO
[`onetick.py.join()`](https://docs.pip.distribution.sol.onetick.com/api/functions/join.html.md#onetick.py.join)
<br/>
[`onetick.py.ops.sametime()`](https://docs.pip.distribution.sol.onetick.com/api/functions/join/sametime.html.md#onetick.py.ops.sametime)
<br/>
**SAMETIME_AS_EXISTING** OneTick function
<br/>
**JOIN** OneTick event processor
<br/>
