11from datetime import date , datetime
22from decimal import Decimal
3- from typing import Any , Literal , Optional , Union , overload
3+ from typing import Any , Literal , Optional , Union , cast , overload
44
55import httpx
66from pydantic import BaseModel , model_validator
2222from tastytrade .session import Session
2323from tastytrade .utils import (
2424 PriceEffect ,
25- TastytradeError ,
2625 TastytradeData ,
26+ TastytradeError ,
2727 set_sign_for ,
2828 today_in_new_york ,
2929 validate_response ,
@@ -94,9 +94,10 @@ class AccountBalance(TastytradeData):
9494 @classmethod
9595 def validate_price_effects (cls , data : Any ) -> Any :
9696 if isinstance (data , dict ):
97+ data = cast (dict [str , Any ], data )
9798 key = "unsettled-cryptocurrency-fiat-amount"
98- effect = data .get ("unsettled-cryptocurrency-fiat-effect" )
99- if effect == PriceEffect .DEBIT :
99+ effect : Any = data .get ("unsettled-cryptocurrency-fiat-effect" )
100+ if effect == PriceEffect .DEBIT . value :
100101 data [key ] = - abs (Decimal (data [key ]))
101102 return set_sign_for (data , ["pending_cash" , "buying_power_adjustment" ])
102103
@@ -149,8 +150,9 @@ class AccountBalanceSnapshot(TastytradeData):
149150 @classmethod
150151 def validate_price_effects (cls , data : Any ) -> Any :
151152 if isinstance (data , dict ):
153+ data = cast (dict [str , Any ], data )
152154 key = "unsettled-cryptocurrency-fiat-amount"
153- effect = data .get ("unsettled-cryptocurrency-fiat-effect" )
155+ effect : Any = data .get ("unsettled-cryptocurrency-fiat-effect" )
154156 if effect == PriceEffect .DEBIT :
155157 data [key ] = - abs (Decimal (data [key ]))
156158 return set_sign_for (data , ["pending_cash" ])
@@ -614,7 +616,8 @@ async def a_get_balance_snapshots(
614616 :param end_date: the ending date of the range.
615617 :param snapshot_date: the date of the snapshot to get.
616618 :param time_of_day:
617- the time of day of the snapshots to get, either 'EOD' (End Of Day) or 'BOD' (Beginning Of Day).
619+ the time of day of the snapshots to get, either 'EOD' (End Of Day) or 'BOD'
620+ (Beginning Of Day).
618621 """
619622 paginate = False
620623 if page_offset is None :
@@ -629,7 +632,7 @@ async def a_get_balance_snapshots(
629632 "snapshot-date" : snapshot_date ,
630633 "time-of-day" : time_of_day ,
631634 }
632- snapshots = []
635+ snapshots : list [ AccountBalanceSnapshot ] = []
633636 while True :
634637 response = await session .async_client .get (
635638 f"/accounts/{ self .account_number } /balance-snapshots" ,
@@ -677,7 +680,8 @@ def get_balance_snapshots(
677680 :param end_date: the ending date of the range.
678681 :param snapshot_date: the date of the snapshot to get.
679682 :param time_of_day:
680- the time of day of the snapshots to get, either 'EOD' (End Of Day) or 'BOD' (Beginning Of Day).
683+ the time of day of the snapshots to get, either 'EOD' (End Of Day) or 'BOD'
684+ (Beginning Of Day).
681685 """
682686 paginate = False
683687 if page_offset is None :
@@ -692,7 +696,7 @@ def get_balance_snapshots(
692696 "snapshot-date" : snapshot_date ,
693697 "time-of-day" : time_of_day ,
694698 }
695- snapshots = []
699+ snapshots : list [ AccountBalanceSnapshot ] = []
696700 while True :
697701 response = session .sync_client .get (
698702 f"/accounts/{ self .account_number } /balance-snapshots" ,
@@ -878,7 +882,7 @@ async def a_get_history(
878882 "end-at" : end_at ,
879883 }
880884 # loop through pages and get all transactions
881- txns = []
885+ txns : list [ Transaction ] = []
882886 while True :
883887 response = await session .async_client .get (
884888 f"/accounts/{ self .account_number } /transactions" ,
@@ -973,7 +977,7 @@ def get_history(
973977 "end-at" : end_at ,
974978 }
975979 # loop through pages and get all transactions
976- txns = []
980+ txns : list [ Transaction ] = []
977981 while True :
978982 response = session .sync_client .get (
979983 f"/accounts/{ self .account_number } /transactions" ,
@@ -1376,7 +1380,7 @@ async def a_get_order_history(
13761380 "end-at" : end_at ,
13771381 }
13781382 # loop through pages and get all transactions
1379- orders = []
1383+ orders : list [ PlacedOrder ] = []
13801384 while True :
13811385 response = await session .async_client .get (
13821386 f"/accounts/{ self .account_number } /orders" ,
@@ -1457,7 +1461,7 @@ def get_order_history(
14571461 "end-at" : end_at ,
14581462 }
14591463 # loop through pages and get all transactions
1460- orders = []
1464+ orders : list [ PlacedOrder ] = []
14611465 while True :
14621466 response = session .sync_client .get (
14631467 f"/accounts/{ self .account_number } /orders" ,
@@ -1500,11 +1504,11 @@ async def a_get_complex_order_history(
15001504 paginate = True
15011505 params = {"per-page" : per_page , "page-offset" : page_offset }
15021506 # loop through pages and get all transactions
1503- orders = []
1507+ orders : list [ PlacedComplexOrder ] = []
15041508 while True :
15051509 response = await session .async_client .get (
15061510 f"/accounts/{ self .account_number } /complex-orders" ,
1507- params = { k : v for k , v in params . items () if v is not None } ,
1511+ params = params ,
15081512 )
15091513 validate_response (response )
15101514 json = response .json ()
@@ -1539,11 +1543,11 @@ def get_complex_order_history(
15391543 paginate = True
15401544 params = {"per-page" : per_page , "page-offset" : page_offset }
15411545 # loop through pages and get all transactions
1542- orders = []
1546+ orders : list [ PlacedComplexOrder ] = []
15431547 while True :
15441548 response = session .sync_client .get (
15451549 f"/accounts/{ self .account_number } /complex-orders" ,
1546- params = { k : v for k , v in params . items () if v is not None } ,
1550+ params = params ,
15471551 )
15481552 validate_response (response )
15491553 json = response .json ()
@@ -1698,7 +1702,7 @@ async def a_get_order_chains(
16981702 response = await client .get (
16991703 f"{ VAST_URL } /order-chains" ,
17001704 headers = headers ,
1701- params = params ,
1705+ params = params , # type: ignore[arg-type]
17021706 )
17031707 validate_response (response )
17041708 chains = response .json ()["data" ]["items" ]
@@ -1736,7 +1740,7 @@ def get_order_chains(
17361740 response = httpx .get (
17371741 f"{ VAST_URL } /order-chains" ,
17381742 headers = headers ,
1739- params = params ,
1743+ params = params , # type: ignore[arg-type]
17401744 )
17411745 validate_response (response )
17421746 chains = response .json ()["data" ]["items" ]
0 commit comments