Skip to content

Commit db154d2

Browse files
committed
fix cert session issue
1 parent 79055c1 commit db154d2

3 files changed

Lines changed: 21 additions & 7 deletions

File tree

tastytrade/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
BACKTEST_URL = "https://backtester.vast.tastyworks.com"
55
CERT_URL = "https://api.cert.tastyworks.com"
66
VAST_URL = "https://vast.tastyworks.com"
7-
VERSION = "9.12"
7+
VERSION = "9.13"
88

99
__version__ = VERSION
1010
version_str = f"tastyware/tastytrade:v{VERSION}"

tastytrade/session.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,9 @@ def __init__(
362362
#: URL for dxfeed websocket
363363
self.dxlink_url = data["dxlink-url"]
364364
#: expiration for streamer token
365-
self.streamer_expiration = datetime.fromisoformat(
366-
data["expires-at"].replace("Z", "+00:00")
365+
exp = data.get("expires-at")
366+
self.streamer_expiration = (
367+
datetime.fromisoformat(exp.replace("Z", "+00:00")) if exp else None
367368
)
368369

369370
def __enter__(self):
@@ -479,7 +480,11 @@ def serialize(self) -> str:
479480
del attrs["sync_client"]
480481
attrs["user"] = attrs["user"].model_dump()
481482
attrs["session_expiration"] = self.session_expiration.strftime(_fmt)
482-
attrs["streamer_expiration"] = self.streamer_expiration.strftime(_fmt)
483+
attrs["streamer_expiration"] = (
484+
self.streamer_expiration.strftime(_fmt)
485+
if self.streamer_expiration
486+
else None
487+
)
483488
return json.dumps(attrs)
484489

485490
@classmethod
@@ -500,9 +505,8 @@ def deserialize(cls, serialized: str) -> Self:
500505
self.session_expiration = datetime.strptime(
501506
deserialized["session_expiration"], _fmt
502507
)
503-
self.streamer_expiration = datetime.strptime(
504-
deserialized["streamer_expiration"], _fmt
505-
)
508+
exp = deserialized.get("streamer_expiration")
509+
self.streamer_expiration = datetime.strptime(exp, _fmt) if exp else None
506510
self.sync_client = Client(base_url=base_url, headers=headers, proxy=self.proxy)
507511
self.async_client = AsyncClient(
508512
base_url=base_url, headers=headers, proxy=self.proxy

tests/test_session.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
import pytest
24
from proxy import TestCase
35

@@ -46,3 +48,11 @@ def test_session_with_proxy(self):
4648
)
4749
assert session.validate()
4850
session.destroy()
51+
52+
53+
def test_cert_session():
54+
username = os.getenv("TT_USERNAME_SANDBOX")
55+
password = os.getenv("TT_PASSWORD_SANDBOX")
56+
assert username and password
57+
session = Session(username, password, is_test=True)
58+
session.destroy()

0 commit comments

Comments
 (0)