onesecondtrader 0.10.0__py3-none-any.whl → 0.10.1__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.
- onesecondtrader/datafeeds/base_datafeed.py +64 -72
- {onesecondtrader-0.10.0.dist-info → onesecondtrader-0.10.1.dist-info}/METADATA +1 -1
- {onesecondtrader-0.10.0.dist-info → onesecondtrader-0.10.1.dist-info}/RECORD +5 -5
- {onesecondtrader-0.10.0.dist-info → onesecondtrader-0.10.1.dist-info}/LICENSE +0 -0
- {onesecondtrader-0.10.0.dist-info → onesecondtrader-0.10.1.dist-info}/WHEEL +0 -0
|
@@ -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
|
-
|
|
19
|
+
Initialize the datafeed with the provided event bus.
|
|
20
20
|
|
|
21
21
|
Args:
|
|
22
|
-
event_bus
|
|
22
|
+
event_bus: The event bus to publish events to.
|
|
23
23
|
|
|
24
24
|
Attributes:
|
|
25
|
-
self.event_bus
|
|
26
|
-
self._lock
|
|
27
|
-
self._is_connected
|
|
28
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
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
|
|
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
|
|
129
|
+
symbols: List of (symbol, timeframe) tuples to start watching.
|
|
136
130
|
|
|
137
131
|
Returns:
|
|
138
|
-
bool: True if
|
|
132
|
+
bool: True if watching started successfully, False otherwise.
|
|
139
133
|
"""
|
|
140
134
|
if not symbols:
|
|
141
|
-
console.logger.warning("No symbols provided for
|
|
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
|
|
140
|
+
console.logger.error("Cannot start watching: datafeed not connected")
|
|
147
141
|
return False
|
|
148
142
|
|
|
149
|
-
new_symbols = set(symbols) - self.
|
|
143
|
+
new_symbols = set(symbols) - self._watched_symbols
|
|
150
144
|
if not new_symbols:
|
|
151
|
-
console.logger.info("All requested symbols are already being
|
|
145
|
+
console.logger.info("All requested symbols are already being watched")
|
|
152
146
|
return True
|
|
153
147
|
|
|
154
148
|
try:
|
|
155
|
-
success = self.
|
|
149
|
+
success = self._watch(list(new_symbols))
|
|
156
150
|
if success:
|
|
157
|
-
self.
|
|
151
|
+
self._watched_symbols.update(new_symbols)
|
|
158
152
|
console.logger.info(
|
|
159
|
-
f"Successfully started
|
|
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
|
|
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
|
|
160
|
+
console.logger.error(f"Exception while starting watching: {e}")
|
|
167
161
|
return False
|
|
168
162
|
|
|
169
163
|
@abc.abstractmethod
|
|
170
|
-
def
|
|
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
|
|
166
|
+
Implement watching startup logic for the specific datafeed.
|
|
175
167
|
|
|
176
168
|
Args:
|
|
177
|
-
symbols: List of (symbol, timeframe) tuples to start
|
|
178
|
-
These are guaranteed to be new symbols not already being
|
|
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
|
|
173
|
+
bool: True if watching started successfully, False otherwise.
|
|
182
174
|
"""
|
|
183
175
|
pass
|
|
184
176
|
|
|
185
|
-
def
|
|
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
|
|
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
|
|
182
|
+
symbols: List of (symbol, timeframe) tuples to stop watching.
|
|
193
183
|
|
|
194
184
|
Returns:
|
|
195
|
-
bool: True if
|
|
185
|
+
bool: True if unwatching stopped successfully, False otherwise.
|
|
196
186
|
"""
|
|
197
187
|
if not symbols:
|
|
198
|
-
console.logger.warning("No symbols provided for
|
|
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.
|
|
196
|
+
self._watched_symbols.difference_update(symbols)
|
|
207
197
|
return True
|
|
208
198
|
|
|
209
|
-
symbols_to_stop = set(symbols) & self.
|
|
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
|
|
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.
|
|
208
|
+
success = self._unwatch(list(symbols_to_stop))
|
|
221
209
|
if success:
|
|
222
|
-
self.
|
|
210
|
+
self._watched_symbols.difference_update(symbols_to_stop)
|
|
223
211
|
console.logger.info(
|
|
224
|
-
f"Successfully
|
|
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
|
|
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
|
|
233
|
-
self.
|
|
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
|
|
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
|
|
226
|
+
Implement unwatching logic for the specific datafeed.
|
|
242
227
|
|
|
243
228
|
Args:
|
|
244
|
-
symbols: List of (symbol, timeframe) tuples to stop
|
|
245
|
-
These are guaranteed to be symbols currently being
|
|
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
|
|
233
|
+
bool: True if unwatching stopped successfully, False otherwise.
|
|
249
234
|
"""
|
|
250
235
|
pass
|
|
251
236
|
|
|
252
|
-
|
|
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
|
-
|
|
239
|
+
Check if the datafeed is currently connected.
|
|
258
240
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
what historical data to preload.
|
|
241
|
+
Returns:
|
|
242
|
+
bool: True if connected, False otherwise.
|
|
262
243
|
"""
|
|
263
|
-
|
|
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()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: onesecondtrader
|
|
3
|
-
Version: 0.10.
|
|
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
|
|
@@ -3,7 +3,7 @@ onesecondtrader/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hS
|
|
|
3
3
|
onesecondtrader/core/models.py,sha256=gvspEZp7pISZgpHeaKNQfvNJgwZY7DnS_kWpoGwXC-c,3940
|
|
4
4
|
onesecondtrader/core/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
5
|
onesecondtrader/datafeeds/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
-
onesecondtrader/datafeeds/base_datafeed.py,sha256=
|
|
6
|
+
onesecondtrader/datafeeds/base_datafeed.py,sha256=cHt8bdA9zON6CJLjz7blgNcs4xu4-iWxM15s3Gu3FO0,8774
|
|
7
7
|
onesecondtrader/messaging/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
8
|
onesecondtrader/messaging/eventbus.py,sha256=R2K85INeYVwJ1tMOybC3WpRraK0ZKVe8WehCbAzzznU,19359
|
|
9
9
|
onesecondtrader/messaging/events.py,sha256=eaWXQQIUnRNOR-9n5-6lyLbZ6bUtzjD4GI567U_vh4g,23625
|
|
@@ -11,7 +11,7 @@ onesecondtrader/monitoring/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJ
|
|
|
11
11
|
onesecondtrader/monitoring/console.py,sha256=1mrojXkyL4ro7ebkvDMGNQiCL-93WEylRuwnfmEKzVs,299
|
|
12
12
|
onesecondtrader/monitoring/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
13
|
onesecondtrader/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
|
-
onesecondtrader-0.10.
|
|
15
|
-
onesecondtrader-0.10.
|
|
16
|
-
onesecondtrader-0.10.
|
|
17
|
-
onesecondtrader-0.10.
|
|
14
|
+
onesecondtrader-0.10.1.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
15
|
+
onesecondtrader-0.10.1.dist-info/METADATA,sha256=tGtxjkcRkaC39mi4glsawyMVYHmuBDzpsZQwR4-k3nY,9519
|
|
16
|
+
onesecondtrader-0.10.1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
17
|
+
onesecondtrader-0.10.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|