wiz-trader 0.21.0__tar.gz → 0.22.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wiz_trader
3
- Version: 0.21.0
3
+ Version: 0.22.0
4
4
  Summary: A Python SDK for connecting to the Wizzer.
5
5
  Home-page: https://bitbucket.org/wizzer-tech/quotes_sdk.git
6
6
  Author: Pawan Wagh
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "wiz_trader"
7
- version = "0.21.0"
7
+ version = "0.22.0"
8
8
  description = "A Python SDK for connecting to the Wizzer."
9
9
  readme = "README.md"
10
10
  authors = [
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='wiz_trader',
5
- version='0.21.0',
5
+ version='0.22.0',
6
6
  description='A Python SDK for connecting to the Wizzer.',
7
7
  long_description=open('README.md').read() if open('README.md') else "",
8
8
  long_description_content_type='text/markdown',
@@ -3,6 +3,6 @@
3
3
  from .quotes import QuotesClient
4
4
  from .apis import WizzerClient
5
5
 
6
- __version__ = "0.21.0"
6
+ __version__ = "0.22.0"
7
7
 
8
8
  __all__ = ["QuotesClient", "WizzerClient"]
@@ -193,6 +193,38 @@ class QuotesClient:
193
193
  asyncio.set_event_loop(loop)
194
194
  loop.create_task(self._subscribe_async(instruments))
195
195
 
196
+ 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
+ if self.ws and self.ws.state == State.OPEN:
202
+ to_remove = set(instruments) & self.subscribed_instruments
203
+ if to_remove:
204
+ for batch in self._chunk_list(list(to_remove), self.batch_size):
205
+ logger.info("Unsubscribing from %d instruments", len(batch))
206
+ await self.ws.send(json.dumps({
207
+ "action": self.ACTION_UNSUBSCRIBE,
208
+ "instruments": batch
209
+ }))
210
+ await asyncio.sleep(0.1)
211
+ # remove them from our local set
212
+ self.subscribed_instruments -= to_remove
213
+ else:
214
+ # if we're not connected yet, just remove from the queue
215
+ self.subscribed_instruments -= set(instruments)
216
+
217
+ def unsubscribe(self, instruments: List[str]) -> None:
218
+ """
219
+ Schedule an async unsubscribe so users can call this without 'await'.
220
+ """
221
+ try:
222
+ loop = asyncio.get_event_loop()
223
+ except RuntimeError:
224
+ loop = asyncio.new_event_loop()
225
+ asyncio.set_event_loop(loop)
226
+ loop.create_task(self._unsubscribe_async(instruments))
227
+
196
228
  # You could add a similar unsubscribe wrapper if needed
197
229
 
198
230
  async def close(self) -> None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wiz_trader
3
- Version: 0.21.0
3
+ Version: 0.22.0
4
4
  Summary: A Python SDK for connecting to the Wizzer.
5
5
  Home-page: https://bitbucket.org/wizzer-tech/quotes_sdk.git
6
6
  Author: Pawan Wagh
File without changes
File without changes
File without changes