wiz-trader 0.22.0__py3-none-any.whl → 0.24.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.
- wiz_trader/__init__.py +1 -1
- wiz_trader/quotes/client.py +33 -33
- {wiz_trader-0.22.0.dist-info → wiz_trader-0.24.0.dist-info}/METADATA +1 -1
- wiz_trader-0.24.0.dist-info/RECORD +9 -0
- wiz_trader-0.22.0.dist-info/RECORD +0 -9
- {wiz_trader-0.22.0.dist-info → wiz_trader-0.24.0.dist-info}/WHEEL +0 -0
- {wiz_trader-0.22.0.dist-info → wiz_trader-0.24.0.dist-info}/top_level.txt +0 -0
wiz_trader/__init__.py
CHANGED
wiz_trader/quotes/client.py
CHANGED
@@ -60,6 +60,7 @@ class QuotesClient:
|
|
60
60
|
self.subscribed_instruments: set = set()
|
61
61
|
self._running = False
|
62
62
|
self._background_task = None
|
63
|
+
self._loop: Optional[asyncio.AbstractEventLoop] = None
|
63
64
|
|
64
65
|
self._backoff_base = 1
|
65
66
|
self._backoff_factor = 2
|
@@ -162,9 +163,6 @@ class QuotesClient:
|
|
162
163
|
# -- Async core methods (for internal use) --
|
163
164
|
|
164
165
|
async def _subscribe_async(self, instruments: List[str]) -> None:
|
165
|
-
"""
|
166
|
-
Internal async subscription. Use `subscribe()` wrapper to schedule this.
|
167
|
-
"""
|
168
166
|
if self.ws and self.ws.state == State.OPEN:
|
169
167
|
new = set(instruments) - self.subscribed_instruments
|
170
168
|
if new:
|
@@ -177,30 +175,13 @@ class QuotesClient:
|
|
177
175
|
}))
|
178
176
|
await asyncio.sleep(0.1)
|
179
177
|
else:
|
180
|
-
# queue it for next connect
|
181
178
|
self.subscribed_instruments |= set(instruments)
|
182
179
|
|
183
|
-
# -- Public wrappers for plain callback users --
|
184
|
-
|
185
|
-
def subscribe(self, instruments: List[str]) -> None:
|
186
|
-
"""
|
187
|
-
Schedule an async subscribe so users can call this without 'await'.
|
188
|
-
"""
|
189
|
-
try:
|
190
|
-
loop = asyncio.get_event_loop()
|
191
|
-
except RuntimeError:
|
192
|
-
loop = asyncio.new_event_loop()
|
193
|
-
asyncio.set_event_loop(loop)
|
194
|
-
loop.create_task(self._subscribe_async(instruments))
|
195
|
-
|
196
180
|
async def _unsubscribe_async(self, instruments: List[str]) -> None:
|
197
|
-
"""
|
198
|
-
Internal async unsubscription. Use `unsubscribe()` wrapper to schedule this.
|
199
|
-
"""
|
200
|
-
# Only send unsubs if the socket is open
|
201
181
|
if self.ws and self.ws.state == State.OPEN:
|
202
182
|
to_remove = set(instruments) & self.subscribed_instruments
|
203
183
|
if to_remove:
|
184
|
+
self.subscribed_instruments -= to_remove
|
204
185
|
for batch in self._chunk_list(list(to_remove), self.batch_size):
|
205
186
|
logger.info("Unsubscribing from %d instruments", len(batch))
|
206
187
|
await self.ws.send(json.dumps({
|
@@ -208,24 +189,41 @@ class QuotesClient:
|
|
208
189
|
"instruments": batch
|
209
190
|
}))
|
210
191
|
await asyncio.sleep(0.1)
|
211
|
-
# remove them from our local set
|
212
|
-
self.subscribed_instruments -= to_remove
|
213
192
|
else:
|
214
|
-
# if we're not connected yet, just remove from the queue
|
215
193
|
self.subscribed_instruments -= set(instruments)
|
216
194
|
|
195
|
+
# -- Public wrappers for plain callback users --
|
196
|
+
|
197
|
+
def subscribe(self, instruments: List[str]) -> None:
|
198
|
+
"""
|
199
|
+
Schedule subscribe onto the client’s event loop.
|
200
|
+
"""
|
201
|
+
if self._loop:
|
202
|
+
asyncio.run_coroutine_threadsafe(
|
203
|
+
self._subscribe_async(instruments),
|
204
|
+
self._loop
|
205
|
+
)
|
206
|
+
else:
|
207
|
+
self.subscribed_instruments |= set(instruments)
|
208
|
+
|
217
209
|
def unsubscribe(self, instruments: List[str]) -> None:
|
218
210
|
"""
|
219
|
-
Schedule
|
211
|
+
Schedule unsubscribe onto the client’s event loop.
|
220
212
|
"""
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
213
|
+
if self._loop:
|
214
|
+
asyncio.run_coroutine_threadsafe(
|
215
|
+
self._unsubscribe_async(instruments),
|
216
|
+
self._loop
|
217
|
+
)
|
218
|
+
else:
|
219
|
+
self.subscribed_instruments -= set(instruments)
|
220
|
+
|
221
|
+
def unsubscribe_all(self) -> None:
|
222
|
+
"""
|
223
|
+
Unsubscribe from all currently subscribed instruments.
|
224
|
+
"""
|
225
|
+
if self.subscribed_instruments:
|
226
|
+
self.unsubscribe(list(self.subscribed_instruments))
|
229
227
|
|
230
228
|
async def close(self) -> None:
|
231
229
|
"""
|
@@ -252,6 +250,7 @@ class QuotesClient:
|
|
252
250
|
except RuntimeError:
|
253
251
|
loop = asyncio.new_event_loop()
|
254
252
|
asyncio.set_event_loop(loop)
|
253
|
+
self._loop = loop
|
255
254
|
|
256
255
|
try:
|
257
256
|
loop.run_until_complete(self._connect_with_backoff())
|
@@ -274,6 +273,7 @@ class QuotesClient:
|
|
274
273
|
return
|
275
274
|
self._running = True
|
276
275
|
loop = asyncio.get_event_loop()
|
276
|
+
self._loop = loop
|
277
277
|
self._background_task = loop.create_task(self._connect_with_backoff())
|
278
278
|
|
279
279
|
def stop(self) -> None:
|
@@ -0,0 +1,9 @@
|
|
1
|
+
wiz_trader/__init__.py,sha256=hL8zImLBBtwxnrKrTpTqcsIzg5cxFMWDOfTkfKNwo9o,182
|
2
|
+
wiz_trader/apis/__init__.py,sha256=ItWKMOl4omiW0g2f-M7WRW3v-dss_ULd9vYnFyIIT9o,132
|
3
|
+
wiz_trader/apis/client.py,sha256=GY1aAaV4ia1tnFnB2qaNqnv-qeUvkVlvw9xOKN54qIs,59786
|
4
|
+
wiz_trader/quotes/__init__.py,sha256=RF9g9CNP6bVWlmCh_ad8krm3-EWOIuVfLp0-H9fAeEM,108
|
5
|
+
wiz_trader/quotes/client.py,sha256=oPDOKqc9EChID_V0_O7ziCdcDnyM_jC7uuKfkc1GwmI,10959
|
6
|
+
wiz_trader-0.24.0.dist-info/METADATA,sha256=38v7XP4SiKWiNDaIAex2cHkv7afK8ExKzs5pv-MKFzM,87046
|
7
|
+
wiz_trader-0.24.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
8
|
+
wiz_trader-0.24.0.dist-info/top_level.txt,sha256=lnYS_g8LlA6ryKYnvY8xIQ6K2K-xzOsd-99AWgnW6VY,11
|
9
|
+
wiz_trader-0.24.0.dist-info/RECORD,,
|
@@ -1,9 +0,0 @@
|
|
1
|
-
wiz_trader/__init__.py,sha256=P9duxOjg6Hdg46ZYq-qkqtq40XGZap7TDsGyxVG3ZEs,182
|
2
|
-
wiz_trader/apis/__init__.py,sha256=ItWKMOl4omiW0g2f-M7WRW3v-dss_ULd9vYnFyIIT9o,132
|
3
|
-
wiz_trader/apis/client.py,sha256=GY1aAaV4ia1tnFnB2qaNqnv-qeUvkVlvw9xOKN54qIs,59786
|
4
|
-
wiz_trader/quotes/__init__.py,sha256=RF9g9CNP6bVWlmCh_ad8krm3-EWOIuVfLp0-H9fAeEM,108
|
5
|
-
wiz_trader/quotes/client.py,sha256=NBWH1nxI-PKPjTxrU4ibl0xxKbchHm1pWA4JkMLvWBA,11125
|
6
|
-
wiz_trader-0.22.0.dist-info/METADATA,sha256=ZtYSZAMCOYs4ojPbZN5Shp0J2kthsdy7vUlfKFOa8og,87046
|
7
|
-
wiz_trader-0.22.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
8
|
-
wiz_trader-0.22.0.dist-info/top_level.txt,sha256=lnYS_g8LlA6ryKYnvY8xIQ6K2K-xzOsd-99AWgnW6VY,11
|
9
|
-
wiz_trader-0.22.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|