-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession.py
More file actions
38 lines (30 loc) · 1.04 KB
/
session.py
File metadata and controls
38 lines (30 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import logging
import os
from dotenv import load_dotenv
from tastytrade import OAuthSession
logger = logging.getLogger(__name__)
class ApplicationSession:
"""
It provides access to the session object and reads configuration from a config file.
"""
def __init__(self) -> None:
try:
load_dotenv()
TT_API_CLIENT_SECRET = os.getenv('TT_API_CLIENT_SECRET')
TT_REFRESH_TOKEN = os.getenv('TT_REFRESH_TOKEN')
self._session = OAuthSession(TT_API_CLIENT_SECRET, TT_REFRESH_TOKEN)
self.initialized = True # Mark as initialized
except Exception as e:
logger.error(f"Error initializing ApplicationSession: {str(e)}")
raise
@property
def session(self) -> OAuthSession:
"""
Get the session object.
Returns:
Session: The session object.
"""
if not hasattr(self, '_session'):
raise AttributeError("Session not initialized")
self._session.refresh()
return self._session