Skip to content

Commit 79055c1

Browse files
committed
fix exp serialization
1 parent 4d09466 commit 79055c1

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tastytrade/session.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ class User(TastytradeJsonDataclass):
262262
nickname: Optional[str] = None
263263

264264

265+
_fmt = "%Y-%m-%d %H:%M:%S%z"
266+
267+
265268
class Session:
266269
"""
267270
Contains a local user login which can then be used to interact with the
@@ -475,6 +478,8 @@ def serialize(self) -> str:
475478
del attrs["async_client"]
476479
del attrs["sync_client"]
477480
attrs["user"] = attrs["user"].model_dump()
481+
attrs["session_expiration"] = self.session_expiration.strftime(_fmt)
482+
attrs["streamer_expiration"] = self.streamer_expiration.strftime(_fmt)
478483
return json.dumps(attrs)
479484

480485
@classmethod
@@ -492,6 +497,12 @@ def deserialize(cls, serialized: str) -> Self:
492497
"Content-Type": "application/json",
493498
"Authorization": self.session_token,
494499
}
500+
self.session_expiration = datetime.strptime(
501+
deserialized["session_expiration"], _fmt
502+
)
503+
self.streamer_expiration = datetime.strptime(
504+
deserialized["streamer_expiration"], _fmt
505+
)
495506
self.sync_client = Client(base_url=base_url, headers=headers, proxy=self.proxy)
496507
self.async_client = AsyncClient(
497508
base_url=base_url, headers=headers, proxy=self.proxy

0 commit comments

Comments
 (0)