Skip to content

Commit 88cf0ae

Browse files
committed
fix #287
1 parent fe0b6b2 commit 88cf0ae

File tree

7 files changed

+7
-50
lines changed

7 files changed

+7
-50
lines changed

tastytrade/__init__.py

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

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

tastytrade/account.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,6 @@ def get(
546546
:param session: the session to use for the request.
547547
:param account_number: the account ID to get.
548548
:param include_closed: whether to include closed accounts in the results
549-
550-
:return: an account if an ID was provided; otherwise, a single account.
551549
"""
552550
if account_number:
553551
data = session._get(f"/customers/me/accounts/{account_number}")

tastytrade/dxfeed/event.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ def from_stream(cls, data: list[Any]) -> list[Event]:
4141
a :class:`~tastyworks.streamer.DXFeedStreamer`.
4242
4343
:param data: list of raw quote data from streamer
44-
45-
:return: list of event objects from data
4644
"""
4745
objs: list[Event] = []
4846
size = len(cls.model_fields)

tastytrade/instruments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,8 @@ class Option(TradeableTastytradeData):
490490
stops_trading_at: datetime
491491
market_time_instrument_collection: str
492492
days_to_expiration: int
493-
expires_at: datetime
494493
is_closing_only: bool
494+
expires_at: datetime | None = None
495495
streamer_symbol: str = ""
496496
listed_market: str | None = None
497497
halted_at: datetime | None = None

tastytrade/order.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class Leg(TastytradeData):
133133
instrument_type: InstrumentType
134134
symbol: str
135135
action: OrderAction
136-
quantity: Decimal | None = None
136+
quantity: Decimal | int | None = None
137137
remaining_quantity: Decimal | None = None
138138
fills: list[FillInfo] | None = None
139139

@@ -149,15 +149,13 @@ class TradeableTastytradeData(TastytradeData):
149149
instrument_type: InstrumentType
150150
symbol: str
151151

152-
def build_leg(self, quantity: Decimal | None, action: OrderAction) -> Leg:
152+
def build_leg(self, quantity: Decimal | int | None, action: OrderAction) -> Leg:
153153
"""
154154
Builds an order :class:`Leg` from the dataclass.
155155
156156
:param quantity:
157157
the quantity of the symbol to trade, set this as `None` for notional orders
158158
:param action: :class:`OrderAction` to perform, e.g. BUY_TO_OPEN
159-
160-
:return: a :class:`Leg` object
161159
"""
162160
return Leg(
163161
instrument_type=self.instrument_type,

tastytrade/session.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -376,35 +376,27 @@ async def a_refresh(self) -> None:
376376
async def a_get_customer(self) -> Customer:
377377
"""
378378
Gets the customer dict from the API.
379-
380-
:return: a Tastytrade 'Customer' object in JSON format.
381379
"""
382380
data = await self._a_get("/customers/me")
383381
return Customer(**data)
384382

385383
def get_customer(self) -> Customer:
386384
"""
387385
Gets the customer dict from the API.
388-
389-
:return: a Tastytrade 'Customer' object in JSON format.
390386
"""
391387
data = self._get("/customers/me")
392388
return Customer(**data)
393389

394390
async def a_validate(self) -> bool:
395391
"""
396392
Validates the current session by sending a request to the API.
397-
398-
:return: True if the session is valid and False otherwise.
399393
"""
400394
response = await self.async_client.post("/sessions/validate")
401395
return response.status_code // 100 == 2
402396

403397
def validate(self) -> bool:
404398
"""
405399
Validates the current session by sending a request to the API.
406-
407-
:return: True if the session is valid and False otherwise.
408400
"""
409401
response = self.sync_client.post("/sessions/validate")
410402
return response.status_code // 100 == 2
@@ -420,24 +412,19 @@ def serialize(self) -> str:
420412
del attrs["sync_client"]
421413
attrs["session_expiration"] = self.session_expiration.strftime(_fmt)
422414
attrs["streamer_expiration"] = self.streamer_expiration.strftime(_fmt)
415+
attrs["headers"] = dict(self.sync_client.headers.copy())
423416
return json.dumps(attrs)
424417

425418
@classmethod
426419
def deserialize(cls, serialized: str) -> Self:
427420
"""
428421
Create a new Session object from a serialized string.
429422
"""
430-
deserialized = json.loads(serialized)
423+
deserialized: dict[str, Any] = json.loads(serialized)
424+
headers = deserialized.pop("headers")
431425
self = cls.__new__(cls)
432426
self.__dict__ = deserialized
433427
base_url = CERT_URL if self.is_test else API_URL
434-
headers = {
435-
"Accept": "application/json",
436-
"Content-Type": "application/json",
437-
"Authorization": self.session_token
438-
if "user" in deserialized
439-
else f"Bearer {self.session_token}",
440-
}
441428
self.session_expiration = datetime.strptime(
442429
deserialized["session_expiration"], _fmt
443430
)

tastytrade/utils.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,13 @@ class PriceEffect(str, Enum):
2929
def now_in_new_york() -> datetime:
3030
"""
3131
Gets the current time in the New York timezone.
32-
33-
:return: current time as datetime
3432
"""
3533
return datetime.now(TZ)
3634

3735

3836
def today_in_new_york() -> date:
3937
"""
4038
Gets the current date in the New York timezone.
41-
42-
:return: current date
4339
"""
4440
return now_in_new_york().date()
4541

@@ -50,8 +46,6 @@ def is_market_open_on(day: date | None = None) -> bool:
5046
during the given day.
5147
5248
:param day: date to check. If not provided defaults to current NY date.
53-
54-
:return: whether the market opens on given day
5549
"""
5650
day = day or today_in_new_york()
5751
date_range = NYSE.valid_days(day, day)
@@ -64,8 +58,6 @@ def get_third_friday(day: date | None = None) -> date:
6458
or the monthly expiration associated with today's month.
6559
6660
:param day: date to check. If not provided defaults to current NY date.
67-
68-
:return: the associated monthly
6961
"""
7062
day = (day or today_in_new_york()).replace(day=1) + timedelta(weeks=2)
7163
while day.weekday() != 4: # Friday
@@ -76,8 +68,6 @@ def get_third_friday(day: date | None = None) -> date:
7668
def get_tasty_monthly() -> date:
7769
"""
7870
Gets the monthly expiration closest to 45 days from the current date.
79-
80-
:return: the closest to 45 DTE monthly expiration
8171
"""
8272
day = today_in_new_york()
8373
exp1 = get_third_friday(day + timedelta(weeks=4))
@@ -101,8 +91,6 @@ def get_future_fx_monthly(day: date | None = None) -> date:
10191
Wednesday.
10292
10393
:param day: date to check. If not provided defaults to current NY date.
104-
105-
:return: the associated monthly
10694
"""
10795
day = (day or today_in_new_york()).replace(day=1) + timedelta(weeks=1)
10896
while day.weekday() != 2: # Wednesday
@@ -120,8 +108,6 @@ def get_future_treasury_monthly(day: date | None = None) -> date:
120108
business day prior.
121109
122110
:param day: date to check. If not provided defaults to current NY date.
123-
124-
:return: the associated monthly
125111
"""
126112
day = day or today_in_new_york()
127113
last_day = _get_last_day_of_month(day)
@@ -143,8 +129,6 @@ def get_future_metal_monthly(day: date | None = None) -> date:
143129
which case they expire on the prior business day.
144130
145131
:param day: date to check. If not provided defaults to current NY date.
146-
147-
:return: the associated monthly
148132
"""
149133
day = day or today_in_new_york()
150134
last_day = _get_last_day_of_month(day)
@@ -164,8 +148,6 @@ def get_future_grain_monthly(day: date | None = None) -> date:
164148
least 2 business days, the last business day of the month.
165149
166150
:param day: date to check. If not provided defaults to current NY date.
167-
168-
:return: the associated monthly
169151
"""
170152
day = day or today_in_new_york()
171153
last_day = _get_last_day_of_month(day)
@@ -185,8 +167,6 @@ def get_future_oil_monthly(day: date | None = None) -> date:
185167
they expire 7 business days prior to the 25th day of the month.
186168
187169
:param day: date to check. If not provided defaults to current NY date.
188-
189-
:return: the associated monthly
190170
"""
191171
last_day = (day or today_in_new_york()).replace(day=25)
192172
first_day = last_day.replace(day=1)
@@ -201,8 +181,6 @@ def get_future_index_monthly(day: date | None = None) -> date:
201181
month.
202182
203183
:param day: date to check. If not provided defaults to current NY date.
204-
205-
:return: the associated monthly
206184
"""
207185
day = day or today_in_new_york()
208186
last_day = _get_last_day_of_month(day)
@@ -224,8 +202,6 @@ def _dasherize(s: str) -> str:
224202
Converts a string from snake case to dasherized.
225203
226204
:param s: string to convert
227-
228-
:return: dasherized string
229205
"""
230206
return s.replace("_", "-")
231207

0 commit comments

Comments
 (0)