onesecondtrader 0.28.0__py3-none-any.whl → 0.30.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,11 @@
1
+ __all__ = [
2
+ "Indicator",
3
+ "Open",
4
+ "High",
5
+ "Low",
6
+ "Close",
7
+ "Volume",
8
+ ]
9
+
10
+ from .base import Indicator
11
+ from .bar import Open, High, Low, Close, Volume
@@ -0,0 +1,47 @@
1
+ from onesecondtrader import events
2
+ from .base import Indicator
3
+
4
+
5
+ class Open(Indicator):
6
+ @property
7
+ def name(self) -> str:
8
+ return "OPEN"
9
+
10
+ def _compute_indicator(self, incoming_bar: events.BarReceived) -> float:
11
+ return incoming_bar.open
12
+
13
+
14
+ class High(Indicator):
15
+ @property
16
+ def name(self) -> str:
17
+ return "HIGH"
18
+
19
+ def _compute_indicator(self, incoming_bar: events.BarReceived) -> float:
20
+ return incoming_bar.high
21
+
22
+
23
+ class Low(Indicator):
24
+ @property
25
+ def name(self) -> str:
26
+ return "LOW"
27
+
28
+ def _compute_indicator(self, incoming_bar: events.BarReceived) -> float:
29
+ return incoming_bar.low
30
+
31
+
32
+ class Close(Indicator):
33
+ @property
34
+ def name(self) -> str:
35
+ return "CLOSE"
36
+
37
+ def _compute_indicator(self, incoming_bar: events.BarReceived) -> float:
38
+ return incoming_bar.close
39
+
40
+
41
+ class Volume(Indicator):
42
+ @property
43
+ def name(self) -> str:
44
+ return "VOLUME"
45
+
46
+ def _compute_indicator(self, incoming_bar: events.BarReceived) -> float:
47
+ return float(incoming_bar.volume) if incoming_bar.volume is not None else 0.0
@@ -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.30.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,16 @@ 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=sGRS3cpN2yLBYws66eVeqY-bAIHg0o6pgFvrkzZtm0Q,170
11
+ onesecondtrader/indicators/bar.py,sha256=0H07mKNiUx5cE1fQvx1oPVY0R_MXcmAAgsLek175vTk,1115
12
+ onesecondtrader/indicators/base.py,sha256=WGqjp9mmkR2PZ5ZC8zL9ddeTfUrB0hX3bjnq1W4HKuI,1658
10
13
  onesecondtrader/messaging/__init__.py,sha256=vMRDabHBgse_vZRTRFtnU8M8v2sY_o4pHjGzgu3hp3E,115
11
14
  onesecondtrader/messaging/eventbus.py,sha256=Y8VbDZlEz8Q6KcCkfXRKsVIixsctBMRW1a5ANw297Ls,1576
12
15
  onesecondtrader/messaging/subscriber.py,sha256=ImpFmu5IstLXLoKVMaebmLp5MXN6225vHLdTL1ZOPvw,2106
13
16
  onesecondtrader/models/__init__.py,sha256=cH5xyniz78MQjM9_-fFdP1ZW6FFLTmayMwQauFO23bU,135
14
17
  onesecondtrader/models/data.py,sha256=TqUvTtjpmzTJT8ZdTYnlVoyI7Qck2IsseCazWZxJgD0,173
15
18
  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,,
19
+ onesecondtrader-0.30.0.dist-info/METADATA,sha256=WBtjr3Eh-kk7ZK4Q7MCF9Dv_UDhJgbGAeMeW_8il5FI,9682
20
+ onesecondtrader-0.30.0.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
21
+ onesecondtrader-0.30.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
22
+ onesecondtrader-0.30.0.dist-info/RECORD,,