Skip to content

Commit bada3a4

Browse files
Ferdous Bhaiclaude
andcommitted
Upgrade to tastytrade 11.0.0 and replace OAuthSession with Session
Breaking changes in tastytrade 11.0.0: - OAuthSession class has been removed - OAuth is now the only authentication method - The Session class now handles OAuth authentication Changes: - Replace all OAuthSession imports with Session - Update tastytrade dependency from >=10.3.0 to >=11.0.0 - Update type hints in ServerContext and function signatures 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 290ea97 commit bada3a4

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

background.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from zoneinfo import ZoneInfo
66

77
import typer
8-
from tastytrade.session import OAuthSession
8+
from tastytrade.session import Session
99
from tastytrade.market_sessions import a_get_market_sessions, ExchangeType, MarketStatus
1010

1111
from agent import create_tastytrader_agent # loads .env internally
@@ -21,13 +21,13 @@
2121
logger = logging.getLogger(__name__)
2222

2323

24-
def create_tastytrade_session() -> OAuthSession:
24+
def create_tastytrade_session() -> Session:
2525
"""Create and return a configured TastyTrade session."""
2626
client_secret = os.getenv("TASTYTRADE_CLIENT_SECRET")
2727
refresh_token = os.getenv("TASTYTRADE_REFRESH_TOKEN")
2828
if not client_secret or not refresh_token:
2929
raise ValueError("Missing required TastyTrade environment variables")
30-
return OAuthSession(client_secret, refresh_token)
30+
return Session(client_secret, refresh_token)
3131

3232

3333
def check_market_open() -> bool:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ readme = "README.md"
66
requires-python = ">=3.12"
77
dependencies = [
88
"mcp[cli]>=v1.14.0",
9-
"tastytrade>=10.3.0",
9+
"tastytrade>=11.0.0",
1010
"humanize>=4.12.3",
1111
"aiolimiter==1.2.1",
1212
"tabulate>=0.9.0",

tasty_agent/server.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from mcp.server.session import ServerSession
1818
from mcp.types import SamplingMessage, TextContent
1919
from tabulate import tabulate
20-
from tastytrade import OAuthSession, Account
20+
from tastytrade import Session, Account
2121
from tastytrade.dxfeed import Quote, Greeks
2222
from tastytrade.instruments import Equity, Option, a_get_option_chain
2323
from tastytrade.market_sessions import a_get_market_sessions, a_get_market_holidays, ExchangeType, MarketStatus
@@ -40,7 +40,7 @@ def to_table(data: Sequence[BaseModel]) -> str:
4040

4141
@dataclass
4242
class ServerContext:
43-
session: OAuthSession
43+
session: Session
4444
account: Account
4545

4646

@@ -64,7 +64,7 @@ async def lifespan(_) -> AsyncIterator[ServerContext]:
6464
)
6565

6666
try:
67-
session = OAuthSession(client_secret, refresh_token)
67+
session = Session(client_secret, refresh_token)
6868
accounts = Account.get(session)
6969
logger.info(f"Successfully authenticated with Tastytrade. Found {len(accounts)} account(s).")
7070
except Exception as e:
@@ -170,12 +170,12 @@ def validate_strike_price(strike_price: Any) -> float:
170170

171171

172172
@cached(ttl=86400, cache=Cache.MEMORY, serializer=PickleSerializer()) # 24 hours
173-
async def get_cached_option_chain(session: OAuthSession, symbol: str):
173+
async def get_cached_option_chain(session: Session, symbol: str):
174174
"""Cache option chains for 24 hours as they rarely change during that timeframe."""
175175
return await a_get_option_chain(session, symbol)
176176

177177

178-
async def get_instrument_details(session: OAuthSession, instrument_specs: list[InstrumentSpec]) -> list[InstrumentDetail]:
178+
async def get_instrument_details(session: Session, instrument_specs: list[InstrumentSpec]) -> list[InstrumentDetail]:
179179
"""Get instrument details with validation and caching."""
180180
async def lookup_single_instrument(spec: InstrumentSpec) -> InstrumentDetail:
181181
symbol = spec.symbol.upper()

0 commit comments

Comments
 (0)