|
21 | 21 | from websockets.asyncio.client import ClientConnection, connect |
22 | 22 | from websockets.exceptions import ConnectionClosed |
23 | 23 |
|
24 | | -from tastytrade import logger |
| 24 | +from tastytrade import logger, version_str |
25 | 25 | from tastytrade.account import Account, AccountBalance, CurrentPosition, TradingStatus |
26 | 26 | from tastytrade.dxfeed import ( |
27 | 27 | Event, |
|
48 | 48 | CERT_STREAMER_URL = "wss://streamer.cert.tastyworks.com" |
49 | 49 | STREAMER_URL = "wss://streamer.tastyworks.com" |
50 | 50 |
|
51 | | -DXLINK_VERSION = "0.1-js/1.0.0-beta.4" |
| 51 | +DXLINK_VERSION = "0.1-DXF-JS/0.3.0" |
52 | 52 |
|
53 | 53 |
|
54 | 54 | class QuoteAlert(TastytradeJsonDataclass): |
@@ -361,6 +361,7 @@ async def _subscribe( |
361 | 361 | "auth-token": self.token, |
362 | 362 | "action": subscription.value, |
363 | 363 | "request-id": self.request_id, |
| 364 | + "source": version_str, |
364 | 365 | } |
365 | 366 | if value: |
366 | 367 | message["value"] = value |
@@ -512,17 +513,23 @@ async def _connect(self) -> None: |
512 | 513 | logger.debug("Feed configured: %s", message) |
513 | 514 | elif message["type"] == "KEEPALIVE": |
514 | 515 | pass |
| 516 | + elif message["type"] == "ERROR": |
| 517 | + logger.error(f"Fatal streamer error: {message['message']}") |
| 518 | + asyncio.create_task(self.close()) |
| 519 | + return |
515 | 520 | else: |
516 | | - logger.error(f"Streamer error: {message}") |
| 521 | + logger.error(f"Unknown message: {message}") |
517 | 522 | except ConnectionClosed as e: |
518 | 523 | logger.error(f"Websocket connection closed with {e}") |
519 | 524 | if e.rcvd and e.rcvd.code == 1009: |
520 | 525 | logger.error( |
521 | 526 | "Subscription message too long! Try reducing the number of symbols." |
522 | 527 | ) |
| 528 | + asyncio.create_task(self.close()) |
523 | 529 | return |
524 | 530 | except asyncio.CancelledError: |
525 | 531 | logger.debug("Websocket interrupted, cancelling main loop.") |
| 532 | + asyncio.create_task(self.close()) |
526 | 533 | return |
527 | 534 | logger.debug("Websocket connection closed, retrying...") |
528 | 535 | reconnecting = True |
|
0 commit comments