Skip to content

Commit 4f0f686

Browse files
authored
fix oauth refresh bug (#255)
1 parent 8b3af21 commit 4f0f686

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

tastytrade/__init__.py

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

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

tastytrade/session.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,14 +578,18 @@ def refresh(self) -> None:
578578
"""
579579
Refreshes the acccess token using the stored refresh token.
580580
"""
581-
response = self.sync_client.post(
581+
request = self.sync_client.build_request(
582+
"POST",
582583
"/oauth/token",
583584
json={
584585
"grant_type": "refresh_token",
585586
"client_secret": self.provider_secret,
586587
"refresh_token": self.refresh_token,
587588
},
588589
)
590+
# Don't send the Authorization header for this request
591+
request.headers.pop("Authorization", None)
592+
response = self.sync_client.send(request)
589593
validate_response(response)
590594
data = response.json()
591595
# update the relevant tokens
@@ -602,14 +606,18 @@ async def a_refresh(self) -> None:
602606
"""
603607
Refreshes the acccess token using the stored refresh token.
604608
"""
605-
response = await self.async_client.post(
609+
request = self.async_client.build_request(
610+
"POST",
606611
"/oauth/token",
607612
json={
608613
"grant_type": "refresh_token",
609614
"client_secret": self.provider_secret,
610615
"refresh_token": self.refresh_token,
611616
},
612617
)
618+
# Don't send the Authorization header for this request
619+
request.headers.pop("Authorization", None)
620+
response = await self.async_client.send(request)
613621
validate_response(response)
614622
data = response.json()
615623
# update the relevant tokens

tests/test_instruments.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,25 @@ async def test_get_option_chain_async(session: Session):
147147
chain = await a_get_option_chain(session, "SPY")
148148
assert chain != {}
149149
for options in chain.values():
150-
await Option.a_get(session, options[0].symbol)
150+
single = await Option.a_get(session, options[0].symbol)
151+
multiple = await Option.a_get(session, [options[0].symbol, options[1].symbol])
152+
assert isinstance(single, Option)
153+
assert isinstance(multiple, list)
151154
break
152155

153156

154157
def test_get_option_chain(session: Session):
155158
chain = get_option_chain(session, "SPY")
156159
assert chain != {}
157160
for options in chain.values():
158-
Option.get(session, options[0].symbol)
161+
single = Option.get(session, options[0].symbol)
162+
# test setting symbol
163+
old = single.streamer_symbol
164+
single._set_streamer_symbol()
165+
assert single.streamer_symbol == old
166+
multiple = Option.get(session, [options[0].symbol, options[1].symbol])
167+
assert isinstance(single, Option)
168+
assert isinstance(multiple, list)
159169
break
160170

161171

0 commit comments

Comments
 (0)