Skip to content

Commit 6fc6cca

Browse files
committed
order_id is now int, fix candle bug
1 parent d725cad commit 6fc6cca

File tree

7 files changed

+21
-19
lines changed

7 files changed

+21
-19
lines changed

.github/CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ Secrets are protected by Github and are not visible to anyone. You can read more
1212
4. Navigate to the forked repository's settings page and click on "Secrets and variables" > "Actions".
1313
5. Click on "New repository secret" to add your Tastytrade username named `TT_USERNAME`.
1414
6. Finally, do the same with your password, naming it `TT_PASSWORD`.
15+
7. Make sure you have at least one share of long $F in your account, which will be used to place the OCO complex order (nothing will fill).

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
project = 'tastytrade'
1010
copyright = '2024, Graeme Holliday'
1111
author = 'Graeme Holliday'
12-
release = '7.8'
12+
release = '7.9'
1313

1414
# -- General configuration ---------------------------------------------------
1515
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name='tastytrade',
10-
version='7.8',
10+
version='7.9',
1111
description='An unofficial SDK for Tastytrade!',
1212
long_description=LONG_DESCRIPTION,
1313
long_description_content_type='text/markdown',

tastytrade/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
API_URL = 'https://api.tastyworks.com'
44
CERT_URL = 'https://api.cert.tastyworks.com'
5-
VERSION = '7.8'
5+
VERSION = '7.9'
66

77
logger = logging.getLogger(__name__)
88
logger.setLevel(logging.DEBUG)

tastytrade/account.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from pydantic import BaseModel
77

88
from tastytrade.order import (InstrumentType, NewComplexOrder, NewOrder,
9-
OrderStatus, PlacedComplexOrder, PlacedOrder,
10-
PlacedOrderResponse, PriceEffect)
9+
OrderAction, OrderStatus, PlacedComplexOrder,
10+
PlacedOrder, PlacedOrderResponse, PriceEffect)
1111
from tastytrade.session import ProductionSession, Session
1212
from tastytrade.utils import (TastytradeError, TastytradeJsonDataclass,
1313
today_in_new_york, validate_response)
@@ -335,7 +335,7 @@ class Transaction(TastytradeJsonDataclass):
335335
symbol: Optional[str] = None
336336
instrument_type: Optional[InstrumentType] = None
337337
underlying_symbol: Optional[str] = None
338-
action: Optional[str] = None
338+
action: Optional[OrderAction] = None
339339
quantity: Optional[Decimal] = None
340340
price: Optional[Decimal] = None
341341
regulatory_fees: Optional[Decimal] = None
@@ -873,7 +873,7 @@ def get_live_complex_orders(
873873
def get_complex_order(
874874
self,
875875
session: Session,
876-
order_id: str
876+
order_id: int
877877
) -> PlacedComplexOrder:
878878
"""
879879
Gets a complex order with the given ID.
@@ -894,7 +894,7 @@ def get_complex_order(
894894

895895
return PlacedComplexOrder(**data)
896896

897-
def get_order(self, session: Session, order_id: str) -> PlacedOrder:
897+
def get_order(self, session: Session, order_id: int) -> PlacedOrder:
898898
"""
899899
Gets an order with the given ID.
900900
@@ -913,7 +913,7 @@ def get_order(self, session: Session, order_id: str) -> PlacedOrder:
913913

914914
return PlacedOrder(**data)
915915

916-
def delete_complex_order(self, session: Session, order_id: str) -> None:
916+
def delete_complex_order(self, session: Session, order_id: int) -> None:
917917
"""
918918
Delete a complex order by ID.
919919
@@ -927,7 +927,7 @@ def delete_complex_order(self, session: Session, order_id: str) -> None:
927927
)
928928
validate_response(response)
929929

930-
def delete_order(self, session: Session, order_id: str) -> None:
930+
def delete_order(self, session: Session, order_id: int) -> None:
931931
"""
932932
Delete an order by ID.
933933
@@ -1136,7 +1136,7 @@ def place_complex_order(
11361136
def replace_order(
11371137
self,
11381138
session: Session,
1139-
old_order_id: str,
1139+
old_order_id: int,
11401140
new_order: NewOrder
11411141
) -> PlacedOrder:
11421142
"""

tastytrade/streamer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,8 @@ async def subscribe_candle(
626626
:param end_time: ending time for the data range
627627
:param extended_trading_hours: whether to include extended trading
628628
"""
629-
await self._channel_request(EventType.CANDLE)
629+
if self._subscription_state[EventType.CANDLE] != 'CHANNEL_OPENED':
630+
await self._channel_request(EventType.CANDLE)
630631
message = {
631632
'type': 'FEED_SUBSCRIPTION',
632633
'channel': self._channels[EventType.CANDLE],

tests/test_account.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ def test_get_effective_margin_requirements(session, account):
7373

7474
@pytest.fixture(scope='session')
7575
def new_order(session):
76-
symbol = Equity.get_equity(session, 'NVDA')
76+
symbol = Equity.get_equity(session, 'F')
7777
leg = symbol.build_leg(Decimal(1), OrderAction.BUY_TO_OPEN)
7878

7979
return NewOrder(
8080
time_in_force=OrderTimeInForce.DAY,
8181
order_type=OrderType.LIMIT,
8282
legs=[leg],
83-
price=Decimal(10), # if this fills the US has crumbled
83+
price=Decimal(3),
8484
price_effect=PriceEffect.DEBIT
8585
)
8686

@@ -97,7 +97,7 @@ def test_get_order(session, account, placed_order):
9797

9898
def test_replace_and_delete_order(session, account, new_order, placed_order):
9999
modified_order = new_order.model_copy()
100-
modified_order.price = Decimal(11)
100+
modified_order.price = Decimal('3.01')
101101
replaced = account.replace_order(session, placed_order.id, modified_order)
102102
sleep(3)
103103
account.delete_order(session, replaced.id)
@@ -116,23 +116,23 @@ def test_get_live_orders(session, account):
116116

117117

118118
def test_place_oco_order(session, account):
119-
# account must have a share of NVDA for this to work
120-
symbol = Equity.get_equity(session, 'NVDA')
119+
# account must have a share of F for this to work
120+
symbol = Equity.get_equity(session, 'F')
121121
closing = symbol.build_leg(Decimal(1), OrderAction.SELL_TO_CLOSE)
122122
oco = NewComplexOrder(
123123
orders=[
124124
NewOrder(
125125
time_in_force=OrderTimeInForce.GTC,
126126
order_type=OrderType.LIMIT,
127127
legs=[closing],
128-
price=Decimal('2500'), # will never fill
128+
price=Decimal('100'), # will never fill
129129
price_effect=PriceEffect.CREDIT
130130
),
131131
NewOrder(
132132
time_in_force=OrderTimeInForce.GTC,
133133
order_type=OrderType.STOP,
134134
legs=[closing],
135-
stop_trigger=Decimal('25'), # will never fill
135+
stop_trigger=Decimal('3'), # will never fill
136136
price_effect=PriceEffect.CREDIT
137137
)
138138
]

0 commit comments

Comments
 (0)