onesecondtrader 0.10.0__tar.gz → 0.10.1__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 (17) hide show
  1. {onesecondtrader-0.10.0 → onesecondtrader-0.10.1}/PKG-INFO +1 -1
  2. {onesecondtrader-0.10.0 → onesecondtrader-0.10.1}/pyproject.toml +1 -1
  3. {onesecondtrader-0.10.0 → onesecondtrader-0.10.1}/src/onesecondtrader/datafeeds/base_datafeed.py +64 -72
  4. {onesecondtrader-0.10.0 → onesecondtrader-0.10.1}/LICENSE +0 -0
  5. {onesecondtrader-0.10.0 → onesecondtrader-0.10.1}/README.md +0 -0
  6. {onesecondtrader-0.10.0 → onesecondtrader-0.10.1}/src/onesecondtrader/__init__.py +0 -0
  7. {onesecondtrader-0.10.0 → onesecondtrader-0.10.1}/src/onesecondtrader/core/__init__.py +0 -0
  8. {onesecondtrader-0.10.0 → onesecondtrader-0.10.1}/src/onesecondtrader/core/models.py +0 -0
  9. {onesecondtrader-0.10.0 → onesecondtrader-0.10.1}/src/onesecondtrader/core/py.typed +0 -0
  10. {onesecondtrader-0.10.0 → onesecondtrader-0.10.1}/src/onesecondtrader/datafeeds/__init__.py +0 -0
  11. {onesecondtrader-0.10.0 → onesecondtrader-0.10.1}/src/onesecondtrader/messaging/__init__.py +0 -0
  12. {onesecondtrader-0.10.0 → onesecondtrader-0.10.1}/src/onesecondtrader/messaging/eventbus.py +0 -0
  13. {onesecondtrader-0.10.0 → onesecondtrader-0.10.1}/src/onesecondtrader/messaging/events.py +0 -0
  14. {onesecondtrader-0.10.0 → onesecondtrader-0.10.1}/src/onesecondtrader/monitoring/__init__.py +0 -0
  15. {onesecondtrader-0.10.0 → onesecondtrader-0.10.1}/src/onesecondtrader/monitoring/console.py +0 -0
  16. {onesecondtrader-0.10.0 → onesecondtrader-0.10.1}/src/onesecondtrader/monitoring/py.typed +0 -0
  17. {onesecondtrader-0.10.0 → onesecondtrader-0.10.1}/src/onesecondtrader/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: onesecondtrader
3
- Version: 0.10.0
3
+ Version: 0.10.1
4
4
  Summary: The Trading Infrastructure Toolkit for Python. Research, simulate, and deploy algorithmic trading strategies — all in one place.
5
5
  Author: Nils P. Kujath
6
6
  Author-email: 63961429+NilsKujath@users.noreply.github.com
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "onesecondtrader"
3
- version = "0.10.0"
3
+ version = "0.10.1"
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"}
@@ -1,5 +1,5 @@
1
1
  """
2
- This module provides the base class for datafeeds.
2
+ This module provides the base class for all datafeeds.
3
3
  """
4
4
 
5
5
  import abc
@@ -16,24 +16,21 @@ class BaseDatafeed(abc.ABC):
16
16
 
17
17
  def __init__(self, event_bus: eventbus.EventBus) -> None:
18
18
  """
19
- Initializes the datafeed with the provided event bus.
19
+ Initialize the datafeed with the provided event bus.
20
20
 
21
21
  Args:
22
- event_bus (eventbus.EventBus): The event bus to publish events to.
22
+ event_bus: The event bus to publish events to.
23
23
 
24
24
  Attributes:
25
- self.event_bus (eventbus.EventBus): The event bus to publish events to.
26
- self._lock (threading.Lock): Lock for thread safety.
27
- self._is_connected (bool): Whether the datafeed is connected. `True` if
28
- connected, `False` otherwise.
29
- self._streamed_symbols (set[tuple[str, models.TimeFrame]]): Set of symbols
30
- and timeframes that are currently being streamed.
25
+ self.event_bus: The event bus to publish events to.
26
+ self._lock: Lock for thread safety.
27
+ self._is_connected: Flag indicating if the datafeed is connected.
28
+ self._watched_symbols: Set of symbols currently being watched.
31
29
  """
32
30
  self.event_bus = event_bus
33
-
34
31
  self._lock = threading.Lock()
35
32
  self._is_connected = False
36
- self._streamed_symbols: set[tuple[str, models.TimeFrame]] = set()
33
+ self._watched_symbols: set[tuple[str, models.TimeFrame]] = set()
37
34
 
38
35
  def connect(self) -> bool:
39
36
  """
@@ -80,7 +77,6 @@ class BaseDatafeed(abc.ABC):
80
77
  def disconnect(self) -> bool:
81
78
  """
82
79
  Disconnect from the datafeed.
83
- Clears the set of streamed symbols.
84
80
 
85
81
  Returns:
86
82
  bool: True if disconnection successful, False otherwise.
@@ -97,7 +93,7 @@ class BaseDatafeed(abc.ABC):
97
93
  success = self._disconnect()
98
94
  if success:
99
95
  self._is_connected = False
100
- self._streamed_symbols.clear()
96
+ self._watched_symbols.clear()
101
97
  console.logger.info(
102
98
  f"Successfully disconnected from {self.__class__.__name__}"
103
99
  )
@@ -112,7 +108,7 @@ class BaseDatafeed(abc.ABC):
112
108
  f"Disconnection failed for {self.__class__.__name__}: {e}"
113
109
  )
114
110
  self._is_connected = False
115
- self._streamed_symbols.clear()
111
+ self._watched_symbols.clear()
116
112
  return False
117
113
 
118
114
  @abc.abstractmethod
@@ -125,77 +121,71 @@ class BaseDatafeed(abc.ABC):
125
121
  """
126
122
  pass
127
123
 
128
- def start_streaming_for_symbols(
129
- self, symbols: list[tuple[str, models.TimeFrame]]
130
- ) -> bool:
124
+ def watch(self, symbols: list[tuple[str, models.TimeFrame]]) -> bool:
131
125
  """
132
- Start streaming market data for the specified symbols and timeframes.
126
+ Start watching market data for the specified symbols and timeframes.
133
127
 
134
128
  Args:
135
- symbols: List of (symbol, timeframe) tuples to start streaming.
129
+ symbols: List of (symbol, timeframe) tuples to start watching.
136
130
 
137
131
  Returns:
138
- bool: True if streaming started successfully, False otherwise.
132
+ bool: True if watching started successfully, False otherwise.
139
133
  """
140
134
  if not symbols:
141
- console.logger.warning("No symbols provided for streaming")
135
+ console.logger.warning("No symbols provided for watching")
142
136
  return True
143
137
 
144
138
  with self._lock:
145
139
  if not self._is_connected:
146
- console.logger.error("Cannot start streaming: datafeed not connected")
140
+ console.logger.error("Cannot start watching: datafeed not connected")
147
141
  return False
148
142
 
149
- new_symbols = set(symbols) - self._streamed_symbols
143
+ new_symbols = set(symbols) - self._watched_symbols
150
144
  if not new_symbols:
151
- console.logger.info("All requested symbols are already being streamed")
145
+ console.logger.info("All requested symbols are already being watched")
152
146
  return True
153
147
 
154
148
  try:
155
- success = self._start_streaming_for_symbols(list(new_symbols))
149
+ success = self._watch(list(new_symbols))
156
150
  if success:
157
- self._streamed_symbols.update(new_symbols)
151
+ self._watched_symbols.update(new_symbols)
158
152
  console.logger.info(
159
- f"Successfully started streaming for {len(new_symbols)} symbols"
153
+ f"Successfully started watching {len(new_symbols)} symbols"
160
154
  )
161
155
  return True
162
156
  else:
163
- console.logger.error("Failed to start streaming for symbols")
157
+ console.logger.error("Failed to start watching symbols")
164
158
  return False
165
159
  except Exception as e:
166
- console.logger.error(f"Exception while starting streaming: {e}")
160
+ console.logger.error(f"Exception while starting watching: {e}")
167
161
  return False
168
162
 
169
163
  @abc.abstractmethod
170
- def _start_streaming_for_symbols(
171
- self, symbols: list[tuple[str, models.TimeFrame]]
172
- ) -> bool:
164
+ def _watch(self, symbols: list[tuple[str, models.TimeFrame]]) -> bool:
173
165
  """
174
- Implement streaming startup logic for the specific datafeed.
166
+ Implement watching startup logic for the specific datafeed.
175
167
 
176
168
  Args:
177
- symbols: List of (symbol, timeframe) tuples to start streaming.
178
- These are guaranteed to be new symbols not already being streamed.
169
+ symbols: List of (symbol, timeframe) tuples to start watching.
170
+ These are guaranteed to be new symbols not already being watched.
179
171
 
180
172
  Returns:
181
- bool: True if streaming started successfully, False otherwise.
173
+ bool: True if watching started successfully, False otherwise.
182
174
  """
183
175
  pass
184
176
 
185
- def stop_streaming_for_symbols(
186
- self, symbols: list[tuple[str, models.TimeFrame]]
187
- ) -> bool:
177
+ def unwatch(self, symbols: list[tuple[str, models.TimeFrame]]) -> bool:
188
178
  """
189
- Stop streaming market data for the specified symbols and timeframes.
179
+ Stop watching market data for the specified symbols and timeframes.
190
180
 
191
181
  Args:
192
- symbols: List of (symbol, timeframe) tuples to stop streaming.
182
+ symbols: List of (symbol, timeframe) tuples to stop watching.
193
183
 
194
184
  Returns:
195
- bool: True if streaming stopped successfully, False otherwise.
185
+ bool: True if unwatching stopped successfully, False otherwise.
196
186
  """
197
187
  if not symbols:
198
- console.logger.warning("No symbols provided for stopping streaming")
188
+ console.logger.warning("No symbols provided for unwatching")
199
189
  return True
200
190
 
201
191
  with self._lock:
@@ -203,61 +193,63 @@ class BaseDatafeed(abc.ABC):
203
193
  console.logger.warning(
204
194
  "Datafeed not connected, but removing symbols from tracking"
205
195
  )
206
- self._streamed_symbols.difference_update(symbols)
196
+ self._watched_symbols.difference_update(symbols)
207
197
  return True
208
198
 
209
- symbols_to_stop = set(symbols) & self._streamed_symbols
199
+ symbols_to_stop = set(symbols) & self._watched_symbols
210
200
  if not symbols_to_stop:
211
201
  console.logger.info(
212
- "None of the requested symbols are currently being streamed"
202
+ "None of the requested symbols are currently being watched"
213
203
  )
214
204
  return True
215
205
 
216
- console.logger.info(
217
- f"Stopping streaming for {len(symbols_to_stop)} symbols"
218
- )
206
+ console.logger.info(f"Unwatching {len(symbols_to_stop)} symbols")
219
207
  try:
220
- success = self._stop_streaming_for_symbols(list(symbols_to_stop))
208
+ success = self._unwatch(list(symbols_to_stop))
221
209
  if success:
222
- self._streamed_symbols.difference_update(symbols_to_stop)
210
+ self._watched_symbols.difference_update(symbols_to_stop)
223
211
  console.logger.info(
224
- f"Successfully stopped streaming for {len(symbols_to_stop)} "
225
- f"symbols"
212
+ f"Successfully unwatched {len(symbols_to_stop)} symbols"
226
213
  )
227
214
  return True
228
215
  else:
229
- console.logger.error("Failed to stop streaming for symbols")
216
+ console.logger.error("Failed to unwatch symbols")
230
217
  return False
231
218
  except Exception as e:
232
- console.logger.error(f"Exception while stopping streaming: {e}")
233
- self._streamed_symbols.difference_update(symbols_to_stop)
219
+ console.logger.error(f"Exception while unwatching: {e}")
220
+ self._watched_symbols.difference_update(symbols_to_stop)
234
221
  return False
235
222
 
236
223
  @abc.abstractmethod
237
- def _stop_streaming_for_symbols(
238
- self, symbols: list[tuple[str, models.TimeFrame]]
239
- ) -> bool:
224
+ def _unwatch(self, symbols: list[tuple[str, models.TimeFrame]]) -> bool:
240
225
  """
241
- Implement streaming shutdown logic for the specific datafeed.
226
+ Implement unwatching logic for the specific datafeed.
242
227
 
243
228
  Args:
244
- symbols: List of (symbol, timeframe) tuples to stop streaming.
245
- These are guaranteed to be symbols currently being streamed.
229
+ symbols: List of (symbol, timeframe) tuples to stop watching.
230
+ These are guaranteed to be symbols currently being watched.
246
231
 
247
232
  Returns:
248
- bool: True if streaming stopped successfully, False otherwise.
233
+ bool: True if unwatching stopped successfully, False otherwise.
249
234
  """
250
235
  pass
251
236
 
252
- @abc.abstractmethod
253
- def preload_bars(
254
- self, preload_list: list[tuple[str, models.TimeFrame, int]]
255
- ) -> None:
237
+ def is_connected(self) -> bool:
256
238
  """
257
- Preload historical bars for the specified symbols, timeframes, and counts.
239
+ Check if the datafeed is currently connected.
258
240
 
259
- Args:
260
- preload_list: List of (symbol, timeframe, count) tuples specifying
261
- what historical data to preload.
241
+ Returns:
242
+ bool: True if connected, False otherwise.
262
243
  """
263
- pass
244
+ with self._lock:
245
+ return self._is_connected
246
+
247
+ def get_watched_symbols(self) -> set[tuple[str, models.TimeFrame]]:
248
+ """
249
+ Get the set of currently watched symbols and timeframes.
250
+
251
+ Returns:
252
+ set: Set of (symbol, timeframe) tuples currently being watched.
253
+ """
254
+ with self._lock:
255
+ return self._watched_symbols.copy()