Skip to content

Commit

Permalink
order_id is now int, fix candle bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Graeme22 committed Jul 16, 2024
1 parent d725cad commit 6fc6cca
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 19 deletions.
1 change: 1 addition & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ Secrets are protected by Github and are not visible to anyone. You can read more
4. Navigate to the forked repository's settings page and click on "Secrets and variables" > "Actions".
5. Click on "New repository secret" to add your Tastytrade username named `TT_USERNAME`.
6. Finally, do the same with your password, naming it `TT_PASSWORD`.
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).
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.8'
release = '7.9'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
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.8',
version='7.9',
description='An unofficial SDK for Tastytrade!',
long_description=LONG_DESCRIPTION,
long_description_content_type='text/markdown',
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.8'
VERSION = '7.9'

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
Expand Down
16 changes: 8 additions & 8 deletions tastytrade/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from pydantic import BaseModel

from tastytrade.order import (InstrumentType, NewComplexOrder, NewOrder,
OrderStatus, PlacedComplexOrder, PlacedOrder,
PlacedOrderResponse, PriceEffect)
OrderAction, OrderStatus, PlacedComplexOrder,
PlacedOrder, PlacedOrderResponse, PriceEffect)
from tastytrade.session import ProductionSession, Session
from tastytrade.utils import (TastytradeError, TastytradeJsonDataclass,
today_in_new_york, validate_response)
Expand Down Expand Up @@ -335,7 +335,7 @@ class Transaction(TastytradeJsonDataclass):
symbol: Optional[str] = None
instrument_type: Optional[InstrumentType] = None
underlying_symbol: Optional[str] = None
action: Optional[str] = None
action: Optional[OrderAction] = None
quantity: Optional[Decimal] = None
price: Optional[Decimal] = None
regulatory_fees: Optional[Decimal] = None
Expand Down Expand Up @@ -873,7 +873,7 @@ def get_live_complex_orders(
def get_complex_order(
self,
session: Session,
order_id: str
order_id: int
) -> PlacedComplexOrder:
"""
Gets a complex order with the given ID.
Expand All @@ -894,7 +894,7 @@ def get_complex_order(

return PlacedComplexOrder(**data)

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

return PlacedOrder(**data)

def delete_complex_order(self, session: Session, order_id: str) -> None:
def delete_complex_order(self, session: Session, order_id: int) -> None:
"""
Delete a complex order by ID.
Expand All @@ -927,7 +927,7 @@ def delete_complex_order(self, session: Session, order_id: str) -> None:
)
validate_response(response)

def delete_order(self, session: Session, order_id: str) -> None:
def delete_order(self, session: Session, order_id: int) -> None:
"""
Delete an order by ID.
Expand Down Expand Up @@ -1136,7 +1136,7 @@ def place_complex_order(
def replace_order(
self,
session: Session,
old_order_id: str,
old_order_id: int,
new_order: NewOrder
) -> PlacedOrder:
"""
Expand Down
3 changes: 2 additions & 1 deletion tastytrade/streamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,8 @@ async def subscribe_candle(
:param end_time: ending time for the data range
:param extended_trading_hours: whether to include extended trading
"""
await self._channel_request(EventType.CANDLE)
if self._subscription_state[EventType.CANDLE] != 'CHANNEL_OPENED':
await self._channel_request(EventType.CANDLE)
message = {
'type': 'FEED_SUBSCRIPTION',
'channel': self._channels[EventType.CANDLE],
Expand Down
14 changes: 7 additions & 7 deletions tests/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ def test_get_effective_margin_requirements(session, account):

@pytest.fixture(scope='session')
def new_order(session):
symbol = Equity.get_equity(session, 'NVDA')
symbol = Equity.get_equity(session, 'F')
leg = symbol.build_leg(Decimal(1), OrderAction.BUY_TO_OPEN)

return NewOrder(
time_in_force=OrderTimeInForce.DAY,
order_type=OrderType.LIMIT,
legs=[leg],
price=Decimal(10), # if this fills the US has crumbled
price=Decimal(3),
price_effect=PriceEffect.DEBIT
)

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

def test_replace_and_delete_order(session, account, new_order, placed_order):
modified_order = new_order.model_copy()
modified_order.price = Decimal(11)
modified_order.price = Decimal('3.01')
replaced = account.replace_order(session, placed_order.id, modified_order)
sleep(3)
account.delete_order(session, replaced.id)
Expand All @@ -116,23 +116,23 @@ def test_get_live_orders(session, account):


def test_place_oco_order(session, account):
# account must have a share of NVDA for this to work
symbol = Equity.get_equity(session, 'NVDA')
# account must have a share of F for this to work
symbol = Equity.get_equity(session, 'F')
closing = symbol.build_leg(Decimal(1), OrderAction.SELL_TO_CLOSE)
oco = NewComplexOrder(
orders=[
NewOrder(
time_in_force=OrderTimeInForce.GTC,
order_type=OrderType.LIMIT,
legs=[closing],
price=Decimal('2500'), # will never fill
price=Decimal('100'), # will never fill
price_effect=PriceEffect.CREDIT
),
NewOrder(
time_in_force=OrderTimeInForce.GTC,
order_type=OrderType.STOP,
legs=[closing],
stop_trigger=Decimal('25'), # will never fill
stop_trigger=Decimal('3'), # will never fill
price_effect=PriceEffect.CREDIT
)
]
Expand Down

0 comments on commit 6fc6cca

Please sign in to comment.