onesecondtrader 0.28.0__py3-none-any.whl → 0.29.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.
@@ -0,0 +1,5 @@
1
+ __all__ = [
2
+ "Indicator",
3
+ ]
4
+
5
+ from .base import Indicator
@@ -0,0 +1,50 @@
1
+ from __future__ import annotations
2
+
3
+ import abc
4
+ import collections
5
+ import threading
6
+
7
+ import numpy as np
8
+
9
+ from onesecondtrader import events
10
+
11
+
12
+ class Indicator(abc.ABC):
13
+ def __init__(self, max_history: int = 100, plot_at: int = 99) -> None:
14
+ self._lock = threading.Lock()
15
+ self._max_history = max(1, int(max_history))
16
+ # Keyed by symbol only - each strategy subscribes to one timeframe, so the indicator only sees bars from that timeframe.
17
+ self._history: dict[str, collections.deque[float]] = {}
18
+ # 0 = main price chart, 1-98 = subcharts, 99 = no plot
19
+ self._plot_at = plot_at
20
+
21
+ @property
22
+ @abc.abstractmethod
23
+ def name(self) -> str:
24
+ pass
25
+
26
+ @abc.abstractmethod
27
+ def _compute_indicator(self, incoming_bar: events.BarReceived) -> float:
28
+ pass
29
+
30
+ def update(self, incoming_bar: events.BarReceived) -> None:
31
+ symbol = incoming_bar.symbol
32
+ value = self._compute_indicator(incoming_bar)
33
+ with self._lock:
34
+ if symbol not in self._history:
35
+ self._history[symbol] = collections.deque(maxlen=self._max_history)
36
+ self._history[symbol].append(value)
37
+
38
+ def latest(self, symbol: str) -> float:
39
+ with self._lock:
40
+ history = self._history.get(symbol, collections.deque())
41
+ return history[-1] if history else np.nan
42
+
43
+ def history(self, symbol: str) -> collections.deque[float]:
44
+ with self._lock:
45
+ h = self._history.get(symbol, collections.deque())
46
+ return collections.deque(h, maxlen=self._max_history)
47
+
48
+ @property
49
+ def plot_at(self) -> int:
50
+ return self._plot_at
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: onesecondtrader
3
- Version: 0.28.0
3
+ Version: 0.29.0
4
4
  Summary: The Trading Infrastructure Toolkit for Python. Research, simulate, and deploy algorithmic trading strategies — all in one place.
5
5
  License-File: LICENSE
6
6
  Author: Nils P. Kujath
@@ -7,13 +7,15 @@ onesecondtrader/events/bases.py,sha256=g-ykq2jgcitIAueRurUlqAq0jINQwuhSWi_khAniP
7
7
  onesecondtrader/events/market.py,sha256=IfHuIGfp_IUiw-dFay4c4RYmkoNzshxbhuWTglBqfN0,509
8
8
  onesecondtrader/events/requests.py,sha256=2KXwSckiar9-fy8wkN3vcSIeOkeBfeo_XhUhrNKEd2Q,831
9
9
  onesecondtrader/events/responses.py,sha256=w_BH1nkkPyxQjh30EXEVFcUGDoMprFc2PuAaqpVrQ8A,1436
10
+ onesecondtrader/indicators/__init__.py,sha256=aWJ4I9HC0rBDEYiKQiKxRAuAbMD0ZWP9_wp8fzQFThY,60
11
+ onesecondtrader/indicators/base.py,sha256=WGqjp9mmkR2PZ5ZC8zL9ddeTfUrB0hX3bjnq1W4HKuI,1658
10
12
  onesecondtrader/messaging/__init__.py,sha256=vMRDabHBgse_vZRTRFtnU8M8v2sY_o4pHjGzgu3hp3E,115
11
13
  onesecondtrader/messaging/eventbus.py,sha256=Y8VbDZlEz8Q6KcCkfXRKsVIixsctBMRW1a5ANw297Ls,1576
12
14
  onesecondtrader/messaging/subscriber.py,sha256=ImpFmu5IstLXLoKVMaebmLp5MXN6225vHLdTL1ZOPvw,2106
13
15
  onesecondtrader/models/__init__.py,sha256=cH5xyniz78MQjM9_-fFdP1ZW6FFLTmayMwQauFO23bU,135
14
16
  onesecondtrader/models/data.py,sha256=TqUvTtjpmzTJT8ZdTYnlVoyI7Qck2IsseCazWZxJgD0,173
15
17
  onesecondtrader/models/orders.py,sha256=y6Ar-6fMqaOd_hRnRGvfWUF0Z13H_2hfTOW3ROOk0A8,254
16
- onesecondtrader-0.28.0.dist-info/METADATA,sha256=heQCUCvcEuwy8W9mzjn6fm9_wR8sGP1T7weYq9b19eQ,9682
17
- onesecondtrader-0.28.0.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
18
- onesecondtrader-0.28.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
19
- onesecondtrader-0.28.0.dist-info/RECORD,,
18
+ onesecondtrader-0.29.0.dist-info/METADATA,sha256=J964c1BV0xcF4WUoreu-NgsPZINMM7hjyXHnk78HIEY,9682
19
+ onesecondtrader-0.29.0.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
20
+ onesecondtrader-0.29.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
21
+ onesecondtrader-0.29.0.dist-info/RECORD,,