onesecondtrader 0.47.0__tar.gz → 0.49.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 (35) hide show
  1. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/PKG-INFO +1 -1
  2. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/pyproject.toml +1 -1
  3. onesecondtrader-0.49.0/src/onesecondtrader/events/__init__.py +8 -0
  4. onesecondtrader-0.49.0/src/onesecondtrader/indicators/__init__.py +17 -0
  5. onesecondtrader-0.49.0/src/onesecondtrader/indicators/base.py +142 -0
  6. onesecondtrader-0.49.0/src/onesecondtrader/indicators/market_fields.py +166 -0
  7. onesecondtrader-0.49.0/src/onesecondtrader/indicators/moving_averages.py +104 -0
  8. onesecondtrader-0.47.0/src/onesecondtrader/events/__init__.py +0 -7
  9. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/LICENSE +0 -0
  10. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/README.md +0 -0
  11. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/src/onesecondtrader/__init__.py +0 -0
  12. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/src/onesecondtrader/events/base.py +0 -0
  13. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/src/onesecondtrader/events/market/__init__.py +0 -0
  14. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/src/onesecondtrader/events/market/bar_processed.py +0 -0
  15. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/src/onesecondtrader/events/market/bar_received.py +0 -0
  16. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/src/onesecondtrader/events/orders/__init__.py +0 -0
  17. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/src/onesecondtrader/events/orders/base.py +0 -0
  18. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/src/onesecondtrader/events/orders/expirations.py +0 -0
  19. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/src/onesecondtrader/events/orders/fills.py +0 -0
  20. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/src/onesecondtrader/events/requests/__init__.py +0 -0
  21. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/src/onesecondtrader/events/requests/base.py +0 -0
  22. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/src/onesecondtrader/events/requests/order_cancellation.py +0 -0
  23. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/src/onesecondtrader/events/requests/order_modification.py +0 -0
  24. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/src/onesecondtrader/events/requests/order_submission.py +0 -0
  25. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/src/onesecondtrader/events/responses/__init__.py +0 -0
  26. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/src/onesecondtrader/events/responses/base.py +0 -0
  27. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/src/onesecondtrader/events/responses/cancellations.py +0 -0
  28. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/src/onesecondtrader/events/responses/modifications.py +0 -0
  29. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/src/onesecondtrader/events/responses/orders.py +0 -0
  30. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/src/onesecondtrader/models/__init__.py +0 -0
  31. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/src/onesecondtrader/models/bar_fields.py +0 -0
  32. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/src/onesecondtrader/models/bar_period.py +0 -0
  33. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/src/onesecondtrader/models/order_types.py +0 -0
  34. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/src/onesecondtrader/models/rejection_reasons.py +0 -0
  35. {onesecondtrader-0.47.0 → onesecondtrader-0.49.0}/src/onesecondtrader/models/trade_sides.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: onesecondtrader
3
- Version: 0.47.0
3
+ Version: 0.49.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
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "onesecondtrader"
3
- version = "0.47.0"
3
+ version = "0.49.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,8 @@
1
+ """
2
+ Defines the event message objects propagated through the system.
3
+ """
4
+
5
+ from .base import EventBase
6
+ from . import market, orders, requests, responses
7
+
8
+ __all__ = ["EventBase", "market", "orders", "requests", "responses"]
@@ -0,0 +1,17 @@
1
+ """
2
+ Provides a library of common technical indicators and a base class for creating custom ones.
3
+ """
4
+
5
+ from .base import IndicatorBase
6
+ from .moving_averages import SimpleMovingAverage
7
+ from .market_fields import Open, High, Low, Close, Volume
8
+
9
+ __all__ = [
10
+ "IndicatorBase",
11
+ "SimpleMovingAverage",
12
+ "Open",
13
+ "High",
14
+ "Low",
15
+ "Close",
16
+ "Volume",
17
+ ]
@@ -0,0 +1,142 @@
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 IndicatorBase(abc.ABC):
13
+ """
14
+ Base class for scalar technical indicators with per-symbol history.
15
+
16
+ The class provides a thread-safe mechanism for storing and retrieving indicator values computed from incoming market bars, keyed by symbol.
17
+ It does not manage input windows or rolling computation state.
18
+
19
+ Subclasses define a stable indicator identifier via the `name` property and implement `_compute_indicator`, which computes a single scalar value per incoming bar.
20
+ Indicators with multiple conceptual outputs must be implemented as multiple single-output indicators (e.g. Bollinger Bands must be implemented via three separate indicators `BBUpper`, `BBMiddle`, and `BBLower`).
21
+
22
+ The update mechanism is thread-safe.
23
+ Indicator computation is performed outside the internal lock.
24
+ Subclasses that maintain internal state are responsible for ensuring its thread safety and must not access `_history_data`.
25
+
26
+ Indicator values are stored per symbol in bounded FIFO buffers.
27
+ Missing data and out-of-bounds access yield `numpy.nan`.
28
+
29
+ The `plot_at` attribute is an opaque identifier forwarded to the charting backend and has no intrinsic meaning within the indicator subsystem.
30
+ """
31
+
32
+ def __init__(self, max_history: int = 100, plot_at: int = 99) -> None:
33
+ """
34
+ Parameters:
35
+ max_history:
36
+ Maximum number of indicator values retained per symbol.
37
+ Cannot be less than 1.
38
+ plot_at:
39
+ Opaque plotting identifier forwarded to the charting backend.
40
+ """
41
+ self._lock = threading.Lock()
42
+ self._max_history = max(1, int(max_history))
43
+ self._history_data: dict[str, collections.deque[float]] = {}
44
+ self._plot_at = plot_at
45
+
46
+ @property
47
+ @abc.abstractmethod
48
+ def name(self) -> str:
49
+ """
50
+ Canonical indicator name.
51
+
52
+ Returns:
53
+ Stable identifier used for charting and downstream integration.
54
+ """
55
+ pass
56
+
57
+ @abc.abstractmethod
58
+ def _compute_indicator(self, incoming_bar: events.market.BarReceived) -> float:
59
+ """
60
+ Compute the indicator value for a single market bar.
61
+
62
+ This method is executed outside the internal lock.
63
+ Implementations must not access `_history_data` and must ensure thread safety of any internal computation state.
64
+
65
+ Parameters:
66
+ incoming_bar:
67
+ Market bar used as input for indicator computation.
68
+
69
+ Returns:
70
+ Computed indicator value.
71
+ """
72
+ pass
73
+
74
+ def update(self, incoming_bar: events.market.BarReceived) -> None:
75
+ """
76
+ Update the indicator with a new market bar.
77
+
78
+ The computed value is appended to the per-symbol history buffer.
79
+
80
+ Parameters:
81
+ incoming_bar:
82
+ Market bar triggering the update.
83
+ """
84
+ symbol = incoming_bar.symbol
85
+
86
+ value = self._compute_indicator(incoming_bar)
87
+
88
+ with self._lock:
89
+ if symbol not in self._history_data:
90
+ self._history_data[symbol] = collections.deque(maxlen=self._max_history)
91
+
92
+ self._history_data[symbol].append(value)
93
+
94
+ def latest(self, symbol: str) -> float:
95
+ """
96
+ Return the most recent indicator value for a symbol.
97
+
98
+ Parameters:
99
+ symbol:
100
+ Symbol identifier.
101
+
102
+ Returns:
103
+ Most recent value, or `numpy.nan` if unavailable.
104
+ """
105
+ return self[symbol, -1]
106
+
107
+ def __getitem__(self, key: tuple[str, int]) -> float:
108
+ """
109
+ Retrieve an indicator value by symbol and index.
110
+
111
+ Indexing follows standard Python sequence semantics.
112
+ Negative indices refer to positions relative to the most recent value.
113
+
114
+ Parameters:
115
+ key:
116
+ `(symbol, index)` pair specifying the symbol and history offset.
117
+
118
+ Returns:
119
+ Indicator value at the specified position, or `numpy.nan` if unavailable.
120
+ """
121
+ symbol, index = key
122
+
123
+ with self._lock:
124
+ history = self._history_data.get(symbol)
125
+
126
+ if history is None:
127
+ return np.nan
128
+
129
+ try:
130
+ return history[index]
131
+ except IndexError:
132
+ return np.nan
133
+
134
+ @property
135
+ def plot_at(self) -> int:
136
+ """
137
+ Plotting identifier.
138
+
139
+ Returns:
140
+ Opaque identifier consumed by the charting backend.
141
+ """
142
+ return self._plot_at
@@ -0,0 +1,166 @@
1
+ from __future__ import annotations
2
+
3
+ import numpy as np
4
+
5
+ from onesecondtrader import events, indicators
6
+
7
+
8
+ class Open(indicators.IndicatorBase):
9
+ """
10
+ Open price indicator.
11
+
12
+ This indicator exposes the open price of each incoming market bar as a scalar time series.
13
+ Values are stored per symbol and can be accessed historically via the indicator interface.
14
+ """
15
+
16
+ @property
17
+ def name(self) -> str:
18
+ """
19
+ Canonical indicator name.
20
+
21
+ Returns:
22
+ Fixed identifier for the open price indicator.
23
+ """
24
+ return "OPEN"
25
+
26
+ def _compute_indicator(self, incoming_bar: events.market.BarReceived) -> float:
27
+ """
28
+ Extract the open price from an incoming market bar.
29
+
30
+ Parameters:
31
+ incoming_bar:
32
+ Market bar used as input.
33
+
34
+ Returns:
35
+ Open price of the bar.
36
+ """
37
+ return incoming_bar.open
38
+
39
+
40
+ class High(indicators.IndicatorBase):
41
+ """
42
+ High price indicator.
43
+
44
+ This indicator exposes the high price of each incoming market bar as a scalar time series.
45
+ Values are stored per symbol and can be accessed historically via the indicator interface.
46
+ """
47
+
48
+ @property
49
+ def name(self) -> str:
50
+ """
51
+ Canonical indicator name.
52
+
53
+ Returns:
54
+ Fixed identifier for the high price indicator.
55
+ """
56
+ return "HIGH"
57
+
58
+ def _compute_indicator(self, incoming_bar: events.market.BarReceived) -> float:
59
+ """
60
+ Extract the high price from an incoming market bar.
61
+
62
+ Parameters:
63
+ incoming_bar:
64
+ Market bar used as input.
65
+
66
+ Returns:
67
+ High price of the bar.
68
+ """
69
+ return incoming_bar.high
70
+
71
+
72
+ class Low(indicators.IndicatorBase):
73
+ """
74
+ Low price indicator.
75
+
76
+ This indicator exposes the low price of each incoming market bar as a scalar time series.
77
+ Values are stored per symbol and can be accessed historically via the indicator interface.
78
+ """
79
+
80
+ @property
81
+ def name(self) -> str:
82
+ """
83
+ Canonical indicator name.
84
+
85
+ Returns:
86
+ Fixed identifier for the low price indicator.
87
+ """
88
+ return "LOW"
89
+
90
+ def _compute_indicator(self, incoming_bar: events.market.BarReceived) -> float:
91
+ """
92
+ Extract the low price from an incoming market bar.
93
+
94
+ Parameters:
95
+ incoming_bar:
96
+ Market bar used as input.
97
+
98
+ Returns:
99
+ Low price of the bar.
100
+ """
101
+ return incoming_bar.low
102
+
103
+
104
+ class Close(indicators.IndicatorBase):
105
+ """
106
+ Close price indicator.
107
+
108
+ This indicator exposes the close price of each incoming market bar as a scalar time series.
109
+ Values are stored per symbol and can be accessed historically via the indicator interface.
110
+ """
111
+
112
+ @property
113
+ def name(self) -> str:
114
+ """
115
+ Canonical indicator name.
116
+
117
+ Returns:
118
+ Fixed identifier for the close price indicator.
119
+ """
120
+ return "CLOSE"
121
+
122
+ def _compute_indicator(self, incoming_bar: events.market.BarReceived) -> float:
123
+ """
124
+ Extract the close price from an incoming market bar.
125
+
126
+ Parameters:
127
+ incoming_bar:
128
+ Market bar used as input.
129
+
130
+ Returns:
131
+ Close price of the bar.
132
+ """
133
+ return incoming_bar.close
134
+
135
+
136
+ class Volume(indicators.IndicatorBase):
137
+ """
138
+ Volume indicator.
139
+
140
+ This indicator exposes the traded volume of each incoming market bar as a scalar time series.
141
+ Values are stored per symbol and can be accessed historically via the indicator interface.
142
+ Missing volume values yield `numpy.nan`.
143
+ """
144
+
145
+ @property
146
+ def name(self) -> str:
147
+ """
148
+ Canonical indicator name.
149
+
150
+ Returns:
151
+ Fixed identifier for the volume indicator.
152
+ """
153
+ return "VOLUME"
154
+
155
+ def _compute_indicator(self, incoming_bar: events.market.BarReceived) -> float:
156
+ """
157
+ Extract the volume from an incoming market bar.
158
+
159
+ Parameters:
160
+ incoming_bar:
161
+ Market bar used as input.
162
+
163
+ Returns:
164
+ Volume of the bar, or `numpy.nan` if unavailable.
165
+ """
166
+ return float(incoming_bar.volume) if incoming_bar.volume is not None else np.nan
@@ -0,0 +1,104 @@
1
+ from __future__ import annotations
2
+
3
+ import collections
4
+ import numpy as np
5
+
6
+ from onesecondtrader import events, indicators, models
7
+
8
+
9
+ class SimpleMovingAverage(indicators.IndicatorBase):
10
+ """
11
+ Simple Moving Average (SMA) indicator.
12
+
13
+ This indicator computes the arithmetic mean of a selected bar field over a fixed rolling window.
14
+ One scalar value is produced per incoming bar and stored per symbol.
15
+
16
+ The rolling window is maintained independently for each symbol.
17
+ Until the window is fully populated, the indicator yields `numpy.nan`.
18
+ """
19
+
20
+ def __init__(
21
+ self,
22
+ period: int = 200,
23
+ max_history: int = 100,
24
+ bar_field: models.BarField = models.BarField.CLOSE,
25
+ plot_at: int = 0,
26
+ ) -> None:
27
+ """
28
+ Parameters:
29
+ period:
30
+ Window size used to compute the moving average.
31
+ max_history:
32
+ Maximum number of computed indicator values retained per symbol.
33
+ bar_field:
34
+ Bar field used as the input series.
35
+ plot_at:
36
+ Opaque plotting identifier forwarded to the charting backend.
37
+ """
38
+ super().__init__(max_history=max_history, plot_at=plot_at)
39
+
40
+ self.period: int = max(1, int(period))
41
+ self.bar_field: models.BarField = bar_field
42
+ self._window: dict[str, collections.deque[float]] = {}
43
+
44
+ @property
45
+ def name(self) -> str:
46
+ """
47
+ Canonical indicator name.
48
+
49
+ Returns:
50
+ Identifier encoding the indicator type, period, and bar field.
51
+ """
52
+ return f"SMA_{self.period}_{self.bar_field.name}"
53
+
54
+ def _compute_indicator(self, incoming_bar: events.market.BarReceived) -> float:
55
+ """
56
+ Compute the simple moving average for a single received bar.
57
+
58
+ Parameters:
59
+ incoming_bar:
60
+ Market bar used as input for the computation.
61
+
62
+ Returns:
63
+ Simple moving average value, or `numpy.nan` if the rolling window is not yet fully populated.
64
+ """
65
+ symbol = incoming_bar.symbol
66
+ if symbol not in self._window:
67
+ self._window[symbol] = collections.deque(maxlen=self.period)
68
+
69
+ window = self._window[symbol]
70
+ value = self._extract_field(incoming_bar)
71
+ window.append(value)
72
+
73
+ if len(window) < self.period:
74
+ return np.nan
75
+ return sum(window) / self.period
76
+
77
+ def _extract_field(self, incoming_bar: events.market.BarReceived) -> float:
78
+ """
79
+ Extract the configured bar field from an incoming bar.
80
+
81
+ Parameters:
82
+ incoming_bar:
83
+ Market bar providing the input data.
84
+
85
+ Returns:
86
+ Extracted field value, or `numpy.nan` if unavailable.
87
+ """
88
+ match self.bar_field:
89
+ case models.BarField.OPEN:
90
+ return incoming_bar.open
91
+ case models.BarField.HIGH:
92
+ return incoming_bar.high
93
+ case models.BarField.LOW:
94
+ return incoming_bar.low
95
+ case models.BarField.CLOSE:
96
+ return incoming_bar.close
97
+ case models.BarField.VOLUME:
98
+ return (
99
+ float(incoming_bar.volume)
100
+ if incoming_bar.volume is not None
101
+ else np.nan
102
+ )
103
+ case _:
104
+ return incoming_bar.close
@@ -1,7 +0,0 @@
1
- """
2
- Defines the event message objects propagated through the system.
3
- """
4
-
5
- from .base import EventBase
6
-
7
- __all__ = ["EventBase"]