Skip to content

Commit

Permalink
fix small candle bug, use accept and content type headers in sessions (
Browse files Browse the repository at this point in the history
  • Loading branch information
Graeme22 authored Jun 14, 2024
1 parent 8a716d6 commit e5906be
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
project = 'tastytrade'
copyright = '2024, Graeme Holliday'
author = 'Graeme Holliday'
release = '7.6'
release = '7.7'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ isort==5.13.2
types-requests==2.31.0.20240406
types-pytz==2024.1.0.20240417
websockets==12.0
pandas_market_calendars==4.4.0
pandas_market_calendars==4.3.3
pydantic==2.7.1
pytest==8.2.1
pytest_cov==5.0.0
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name='tastytrade',
version='7.6',
version='7.7',
description='An unofficial SDK for Tastytrade!',
long_description=LONG_DESCRIPTION,
long_description_content_type='text/x-rst',
Expand Down
2 changes: 1 addition & 1 deletion tastytrade/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

API_URL = 'https://api.tastyworks.com'
CERT_URL = 'https://api.cert.tastyworks.com'
VERSION = '7.6'
VERSION = '7.7'

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
Expand Down
11 changes: 1 addition & 10 deletions tastytrade/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -1021,9 +1021,6 @@ def place_order(
url = f'{session.base_url}/accounts/{self.account_number}/orders'
if dry_run:
url += '/dry-run'
headers = session.headers
# required because we're passing the JSON as a string
headers['Content-Type'] = 'application/json'
json = order.model_dump_json(exclude_none=True, by_alias=True)

response = requests.post(url, headers=session.headers, data=json)
Expand Down Expand Up @@ -1054,9 +1051,6 @@ def place_complex_order(
'/complex-orders')
if dry_run:
url += '/dry-run'
headers = session.headers
# required because we're passing the JSON as a string
headers['Content-Type'] = 'application/json'
json = order.model_dump_json(exclude_none=True, by_alias=True)

response = requests.post(url, headers=session.headers, data=json)
Expand All @@ -1082,13 +1076,10 @@ def replace_order(
:return: a :class:`PlacedOrder` object for the modified order.
"""
headers = session.headers
# required because we're passing the JSON as a string
headers['Content-Type'] = 'application/json'
response = requests.put(
(f'{session.base_url}/accounts/{self.account_number}/orders'
f'/{old_order_id}'),
headers=headers,
headers=session.headers,
data=new_order.model_dump_json(
exclude={'legs'},
exclude_none=True,
Expand Down
2 changes: 1 addition & 1 deletion tastytrade/dxfeed/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class EventType(str, Enum):
class Event(BaseModel):
@validator('*', pre=True)
def change_nan_to_none(cls, v):
if v == 'NaN' or v == 'Infinity':
if v == 'NaN' or v == 'Infinity' or v == '-Infinity':
return None
return v

Expand Down
12 changes: 10 additions & 2 deletions tastytrade/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ def __init__(
self.remember_token: Optional[str] = \
json['data']['remember-token'] if remember_me else None
#: The headers to use for API requests
self.headers: Dict[str, str] = {'Authorization': self.session_token}
self.headers: Dict[str, str] = {
'Accept': 'application/json',
'Authorization': self.session_token,
'Content-Type': 'application/json'
}
self.validate()

# Pull streamer tokens and urls
Expand Down Expand Up @@ -167,7 +171,11 @@ def __init__(
#: The base url to use for API requests
self.base_url: str = API_URL
#: The headers to use for API requests
self.headers: Dict[str, str] = {'User-Agent': UserAgent().random}
self.headers: Dict[str, str] = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'User-Agent': UserAgent().random
}

if two_factor_authentication is not None:
headers = {
Expand Down
2 changes: 1 addition & 1 deletion tastytrade/streamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
CERT_STREAMER_URL = 'wss://streamer.cert.tastyworks.com'
STREAMER_URL = 'wss://streamer.tastyworks.com'

DXLINK_VERSION = '0.1-js/0.40.4-WB2'
DXLINK_VERSION = '0.1-js/1.0.0-beta.4'


class QuoteAlert(TastytradeJsonDataclass):
Expand Down

0 comments on commit e5906be

Please sign in to comment.