2020-11-06 17:23:14 +00:00
|
|
|
# piker: trading gear for hackers
|
2021-09-25 14:06:37 +00:00
|
|
|
# Copyright (C) Tyler Goodlet (in stewardship of piker0)
|
2020-11-06 17:23:14 +00:00
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2021-09-25 14:06:37 +00:00
|
|
|
'''
|
|
|
|
Fin-sig-proc for the peeps!
|
2020-09-09 14:46:33 +00:00
|
|
|
|
2021-09-25 14:06:37 +00:00
|
|
|
'''
|
|
|
|
from typing import AsyncIterator
|
2020-09-09 14:46:33 +00:00
|
|
|
|
2021-09-25 14:06:37 +00:00
|
|
|
import numpy as np
|
2020-09-09 14:46:33 +00:00
|
|
|
|
2021-09-25 14:06:37 +00:00
|
|
|
from ._engine import cascade
|
2020-09-09 14:46:33 +00:00
|
|
|
|
2021-09-25 14:06:37 +00:00
|
|
|
__all__ = ['cascade']
|
2020-09-09 14:46:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def latency(
|
|
|
|
source: 'TickStream[Dict[str, float]]', # noqa
|
|
|
|
ohlcv: np.ndarray
|
|
|
|
) -> AsyncIterator[np.ndarray]:
|
2020-09-23 00:23:48 +00:00
|
|
|
"""Latency measurements, broker to piker.
|
2020-09-09 14:46:33 +00:00
|
|
|
"""
|
|
|
|
# TODO: do we want to offer yielding this async
|
|
|
|
# before the rt data connection comes up?
|
|
|
|
|
|
|
|
# deliver zeros for all prior history
|
|
|
|
yield np.zeros(len(ohlcv))
|
|
|
|
|
|
|
|
async for quote in source:
|
|
|
|
ts = quote.get('broker_ts')
|
|
|
|
if ts:
|
|
|
|
# This is codified in the per-broker normalization layer
|
|
|
|
# TODO: Add more measure points and diffs for full system
|
|
|
|
# stack tracing.
|
|
|
|
value = quote['brokerd_ts'] - quote['broker_ts']
|
|
|
|
yield value
|