onesecondtrader 0.11.0__tar.gz → 0.12.0__tar.gz

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.
Files changed (21) hide show
  1. {onesecondtrader-0.11.0 → onesecondtrader-0.12.0}/PKG-INFO +4 -2
  2. {onesecondtrader-0.11.0 → onesecondtrader-0.12.0}/pyproject.toml +1 -1
  3. onesecondtrader-0.12.0/src/onesecondtrader/indicators/base_indicator.py +137 -0
  4. onesecondtrader-0.12.0/src/onesecondtrader/monitoring/py.typed +0 -0
  5. onesecondtrader-0.12.0/src/onesecondtrader/py.typed +0 -0
  6. onesecondtrader-0.11.0/src/onesecondtrader/datafeeds/__init__.py +0 -2
  7. {onesecondtrader-0.11.0 → onesecondtrader-0.12.0}/LICENSE +0 -0
  8. {onesecondtrader-0.11.0 → onesecondtrader-0.12.0}/README.md +0 -0
  9. {onesecondtrader-0.11.0 → onesecondtrader-0.12.0}/src/onesecondtrader/__init__.py +0 -0
  10. {onesecondtrader-0.11.0 → onesecondtrader-0.12.0}/src/onesecondtrader/core/__init__.py +0 -0
  11. {onesecondtrader-0.11.0 → onesecondtrader-0.12.0}/src/onesecondtrader/core/models.py +0 -0
  12. {onesecondtrader-0.11.0 → onesecondtrader-0.12.0}/src/onesecondtrader/core/py.typed +0 -0
  13. {onesecondtrader-0.11.0/src/onesecondtrader/monitoring → onesecondtrader-0.12.0/src/onesecondtrader/datafeeds}/__init__.py +0 -0
  14. {onesecondtrader-0.11.0 → onesecondtrader-0.12.0}/src/onesecondtrader/datafeeds/base_datafeed.py +0 -0
  15. {onesecondtrader-0.11.0 → onesecondtrader-0.12.0}/src/onesecondtrader/datafeeds/csv_datafeed.py +0 -0
  16. /onesecondtrader-0.11.0/src/onesecondtrader/monitoring/py.typed → /onesecondtrader-0.12.0/src/onesecondtrader/indicators/__init__.py +0 -0
  17. {onesecondtrader-0.11.0 → onesecondtrader-0.12.0}/src/onesecondtrader/messaging/__init__.py +0 -0
  18. {onesecondtrader-0.11.0 → onesecondtrader-0.12.0}/src/onesecondtrader/messaging/eventbus.py +0 -0
  19. {onesecondtrader-0.11.0 → onesecondtrader-0.12.0}/src/onesecondtrader/messaging/events.py +0 -0
  20. /onesecondtrader-0.11.0/src/onesecondtrader/py.typed → /onesecondtrader-0.12.0/src/onesecondtrader/monitoring/__init__.py +0 -0
  21. {onesecondtrader-0.11.0 → onesecondtrader-0.12.0}/src/onesecondtrader/monitoring/console.py +0 -0
@@ -1,7 +1,8 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: onesecondtrader
3
- Version: 0.11.0
3
+ Version: 0.12.0
4
4
  Summary: The Trading Infrastructure Toolkit for Python. Research, simulate, and deploy algorithmic trading strategies — all in one place.
5
+ License-File: LICENSE
5
6
  Author: Nils P. Kujath
6
7
  Author-email: 63961429+NilsKujath@users.noreply.github.com
7
8
  Requires-Python: >=3.11
@@ -9,6 +10,7 @@ Classifier: Programming Language :: Python :: 3
9
10
  Classifier: Programming Language :: Python :: 3.11
10
11
  Classifier: Programming Language :: Python :: 3.12
11
12
  Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
12
14
  Requires-Dist: pandas (>=2.3.1,<3.0.0)
13
15
  Requires-Dist: python-dotenv (>=1.0.0,<2.0.0)
14
16
  Description-Content-Type: text/markdown
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "onesecondtrader"
3
- version = "0.11.0"
3
+ version = "0.12.0"
4
4
  description = "The Trading Infrastructure Toolkit for Python. Research, simulate, and deploy algorithmic trading strategies — all in one place."
5
5
  authors = [
6
6
  {name = "Nils P. Kujath",email = "63961429+NilsKujath@users.noreply.github.com"}
@@ -0,0 +1,137 @@
1
+ """
2
+ This module provides the base class for all indicators.
3
+ """
4
+
5
+ import abc
6
+ import collections
7
+ import threading
8
+
9
+ import numpy as np
10
+ from onesecondtrader.core import models
11
+ from onesecondtrader.monitoring import console
12
+
13
+
14
+ class BaseIndicator(abc.ABC):
15
+ """
16
+ Base class for all indicators.
17
+
18
+ If new market data is received, the indicator is updated by calling the
19
+ `<indicator_instance>.update(incoming_bar)` method.
20
+
21
+ When programming a new indicator, only the `name` property and the
22
+ `_compute_indicator()` method need to be implemented.
23
+
24
+ Examples:
25
+ >>> from onesecondtrader.indicators import base_indicator
26
+ >>> from onesecondtrader.core import models
27
+ >>> class DummyCloseIndicator(base_indicator.BaseIndicator):
28
+ ... @property
29
+ ... def name(self) -> str:
30
+ ... return "dummy_close_indicator"
31
+ ... def _compute_indicator(self, incoming_bar: models.Bar):
32
+ ... return incoming_bar.close
33
+ ...
34
+ >>> dummy_close_indicator = DummyCloseIndicator(max_history=10)
35
+ >>> incoming_bar = models.Bar(
36
+ ... open=100.0, high=101.0, low=99.0, close=100.5, volume=10000
37
+ ... )
38
+ >>> dummy_close_indicator.update(incoming_bar)
39
+ >>> dummy_close_indicator[0]
40
+ 100.5
41
+ >>> dummy_close_indicator[-1]
42
+ nan
43
+ >>> next_incoming_bar = models.Bar(
44
+ ... open=100.0, high=101.0, low=99.0, close=101.0, volume=10000
45
+ ... )
46
+ >>> dummy_close_indicator.update(next_incoming_bar)
47
+ >>> dummy_close_indicator[0]
48
+ 101.0
49
+ >>> dummy_close_indicator[-1]
50
+ 100.5
51
+ """
52
+
53
+ def __init__(self, max_history: int = 100) -> None:
54
+ """
55
+ Initialize the indicator with a maximum lookback history length.
56
+
57
+ Args:
58
+ max_history (int): Maximum lookback history length as number of periods.
59
+ Defaults to 100.
60
+
61
+ Attributes:
62
+ self._lock (threading.Lock): Lock to protect concurrent access to the
63
+ indicator's state.
64
+ self._history (collections.deque): Deque to store the lookback history.
65
+ """
66
+ if max_history < 1:
67
+ console.logger.warning(
68
+ f"max_history must be >= 1, got {max_history}; defaulting to 1"
69
+ )
70
+ max_history = 1
71
+ self._lock: threading.Lock = threading.Lock()
72
+
73
+ self._history: collections.deque[float] = collections.deque(maxlen=max_history)
74
+
75
+ @property
76
+ @abc.abstractmethod
77
+ def name(self) -> str:
78
+ """
79
+ Name of the indicator.
80
+ This property must be implemented by subclasses.
81
+
82
+ Returns:
83
+ str: Name of the indicator.
84
+ """
85
+ pass
86
+
87
+ def update(self, incoming_bar: models.Bar) -> None:
88
+ """
89
+ Updates the indicator based on an incoming closed bar by calling
90
+ `self._compute_indicator()`.
91
+ """
92
+ new_value = self._compute_indicator(incoming_bar)
93
+ with self._lock:
94
+ self._history.append(new_value)
95
+
96
+ def __getitem__(self, index: int) -> float:
97
+ """
98
+ Return the indicator value at the given index with tolerant indexing.
99
+
100
+ Indexing rules:
101
+
102
+ - `0` returns the current (most recent) value
103
+ - `-1` returns the previous value, `-2` two periods back, and so on
104
+ - For convenience, a positive `k` behaves like `-k` (e.g., `1 == -1`,
105
+ `2 == -2`)
106
+ - Out-of-range indices return `np.nan` instead of raising an `IndexError`.
107
+ """
108
+ normalized: int
109
+ if index == 0:
110
+ normalized = -1
111
+ elif index > 0:
112
+ normalized = -(index + 1)
113
+ else:
114
+ normalized = index - 1
115
+
116
+ with self._lock:
117
+ try:
118
+ return self._history[normalized]
119
+ except IndexError:
120
+ return np.nan
121
+
122
+ @property
123
+ def latest(self) -> float:
124
+ """
125
+ The latest (most recent) indicator value.
126
+
127
+ Equivalent to self[0]. Returns numpy.nan when no value is available yet.
128
+ """
129
+ return self[0]
130
+
131
+ @abc.abstractmethod
132
+ def _compute_indicator(self, incoming_bar: models.Bar) -> float:
133
+ """
134
+ Computes the new indicator value based on an incoming closed bar.
135
+ This method must be implemented by subclasses.
136
+ """
137
+ pass
File without changes
@@ -1,2 +0,0 @@
1
- from .base_datafeed import BaseDatafeed as BaseDatafeed
2
- from .csv_datafeed import CSVDatafeed as CSVDatafeed