Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get options chains for futures when using a test account. #181

Open
jackroc97 opened this issue Dec 6, 2024 · 6 comments
Open

Can't get options chains for futures when using a test account. #181

jackroc97 opened this issue Dec 6, 2024 · 6 comments

Comments

@jackroc97
Copy link

jackroc97 commented Dec 6, 2024

Describe the bug
I can use use the get_future_option_chain or NestedFutureOptionChain.get_chain functions to retrieve the options chains for futures when I use my production account, but not when I use a test/sandbox account.

How to reproduce

# the following works as expected...
session = Session('prod_user', 'prod_pass')
chain = get_future_option_chain(session, '/ES')

# however this does not work
session = Session('test_user', 'test_pass', is_test=True)
chain = get_future_option_chain(session, '/ES')

I get the following output when using get_future_option_chain with a test account:

{
	"name": "ValidationError",
	"message": "1 validation error for FutureOption
streamer-symbol
  Field required [type=missing, input_value={'active': True, 'days-to...: 0, 'supported': True}}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.10/v/missing",
	"stack": "---------------------------------------------------------------------------
ValidationError                           Traceback (most recent call last)
Cell In[16], line 1
----> 1 chain = get_future_option_chain(session, '/ES')
      2 print(chain)

File ~/dev/algo_trading/tastytrade_api_sandbox/.venv/lib/python3.11/site-packages/tastytrade/instruments.py:1345, in get_future_option_chain(session, symbol)
   1343 chain = defaultdict(list)
   1344 for i in data[\"items\"]:
-> 1345     option = FutureOption(**i)
   1346     chain[option.expiration_date].append(option)
   1348 return chain

File ~/dev/algo_trading/tastytrade_api_sandbox/.venv/lib/python3.11/site-packages/pydantic/main.py:214, in BaseModel.__init__(self, **data)
    212 # `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks
    213 __tracebackhide__ = True
--> 214 validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
    215 if self is not validated_self:
    216     warnings.warn(
    217         'A custom validator is returning a value other than `self`.\
'
    218         \"Returning anything other than `self` from a top level model validator isn't supported when validating via `__init__`.\
\"
    219         'See the `model_validator` docs (https://docs.pydantic.dev/latest/concepts/validators/#model-validators) for more details.',
    220         stacklevel=2,
    221     )

ValidationError: 1 validation error for FutureOption
streamer-symbol
  Field required [type=missing, input_value={'active': True, 'days-to...: 0, 'supported': True}}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.10/v/missing"
}
@Graeme22
Copy link
Contributor

Graeme22 commented Dec 6, 2024

This is a known limitation of the sandbox account. Technically we could get it working by making some of the fields optional, but some of them like streamer_symbol are extremely important so it's probably better to just raise an error.
However sandbox accounts are currently getting a major overhaul according to Tasty, so this may change in the near future.

@jackroc97
Copy link
Author

Thanks @Graeme22. Has TastyTrade publicly posted any info about this overhaul? If so do you have a link?

@Graeme22
Copy link
Contributor

Graeme22 commented Dec 6, 2024

Not that I know of, I've been talking to them directly. Early January is the current date they're shooting for releasing it. Until then I'd recommend staying away from the sandbox accounts though, they're not very useful currently.

@jackroc97
Copy link
Author

Thanks for the info. Just curious, if you do not use the sandbox accounts, how do you go about "paper trading" or forward testing your strategies?

Additionally, I think I may have found a work-around, at least for my particular use-case. I create a prod session and a test session, and use the prod session for fetching options chain info and the test session for placing orders as shown below:

from datetime import datetime, timedelta

from tastytrade import Account, Session
from tastytrade.instruments import get_future_option_chain
from tastytrade.order import *

prod_session = Session('prod_user', 'prod_pass', is_test=False)
test_session = Session('test_user', 'test_pass', is_test=True)

prod_account: Account = Account.get_accounts(prod_session)[0]
test_account: Account = Account.get_accounts(test_session)[0]

chain = get_future_option_chain(prod_session, '/ES')

exp = datetime.now().date() + timedelta(days=4)
futopt = chain[exp][10]

order = NewOrder(
    time_in_force=OrderTimeInForce.DAY,
    order_type=OrderType.MARKET,
    legs = [
        futopt.build_leg(Decimal(1), OrderAction.BUY_TO_OPEN)
    ]
)

response = test_account.place_order(test_session, order)
print(response)

The code runs, but futures are done trading for the week so the order does not submit. I do get the expected response though (that the trading session is not active). Am I missing any obvious signs of why this approach would be a bad idea?

@Graeme22
Copy link
Contributor

Graeme22 commented Dec 6, 2024

I've done something similar and it works ok, however the sandbox sessions have problems in other areas, e.g. their arbitrary rules for fills and a lot of unsupported symbols and instrument types.

@Graeme22
Copy link
Contributor

Graeme22 commented Dec 6, 2024

I typically just use production sessions and keep a close eye on the trades, or place them at prices I know they won't fill at for testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants