A TD Ameritrade API client for Python. Includes historical data for equities and ETFs, options chains, streaming order book data, complex order construction, and more.
Description of Bug
The get_option_chain function does not return the price for the specific option and only the quote for the nearest to the current market price of the underlying security.
This should not be the case when specifying a specific option type, price, from_date and to_date for today's expiration
Code to Reproduce
specific option strike price
strike_price = 441
option chain
r = c.get_option_chain("QQQ",
contract_type=c.Options.ContractType.PUT,
strike_count=1,
include_quotes=None,
strategy=c.Options.Strategy.SINGLE,
interval=None,
strike=strike_price,
strike_range=c.Options.StrikeRange.ALL,
from_date=datetime.date(2024, 3, 5),
to_date=datetime.date(2024, 3, 5),
volatility=None,
underlying_price=None,
interest_rate=None,
days_to_expiration=1,
exp_month=None,
option_type=None)
assert r.status_code == 200, r.raise_for_status()
print(json.dumps(r.json(), indent=4))
IMPORTANT: Remember to anonymize your code. Be sure to replace API keys/Client IDs with placeholders. Also, never, ever share the contents of your token file.
Expected Behavior
The request should return the option price for the 441 PUT and not the 436 PUT
Description of Bug The get_option_chain function does not return the price for the specific option and only the quote for the nearest to the current market price of the underlying security. This should not be the case when specifying a specific option type, price, from_date and to_date for today's expiration
Code to Reproduce specific option strike price strike_price = 441
option chain r = c.get_option_chain("QQQ", contract_type=c.Options.ContractType.PUT, strike_count=1, include_quotes=None, strategy=c.Options.Strategy.SINGLE, interval=None, strike=strike_price, strike_range=c.Options.StrikeRange.ALL, from_date=datetime.date(2024, 3, 5), to_date=datetime.date(2024, 3, 5), volatility=None, underlying_price=None, interest_rate=None, days_to_expiration=1, exp_month=None, option_type=None) assert r.status_code == 200, r.raise_for_status() print(json.dumps(r.json(), indent=4)) IMPORTANT: Remember to anonymize your code. Be sure to replace API keys/Client IDs with placeholders. Also, never, ever share the contents of your token file.
Expected Behavior The request should return the option price for the 441 PUT and not the 436 PUT
Actual Behavior { "symbol": "QQQ", "status": "SUCCESS", "underlying": null, "strategy": "SINGLE", "interval": 0.0, "isDelayed": false, "isIndex": false, "interestRate": 5.585, "underlyingPrice": 435.655, "volatility": 29.0, "daysToExpiration": 0.0, "numberOfContracts": 1, "putExpDateMap": { "2024-03-05:0": { "436.0": [ { "putCall": "PUT", "symbol": "QQQ_030524P436", "description": "QQQ Mar 5 2024 436 Put", "exchangeName": "OPR", "bid": 0.95, "ask": 0.97, "last": 0.95, "mark": 0.96, "bidSize": 93, "askSize": 129, "bidAskSize": "93X129", "lastSize": 0, "highPrice": 1.38, "lowPrice": 0.1, "openPrice": 0.0, "closePrice": 0.05, "totalVolume": 98470, "tradeDate": null, "tradeTimeInLong": 1709663024668, "quoteTimeInLong": 1709663025745, "netChange": 0.89, "volatility": 10.393, "delta": -0.561, "gamma": 0.202, "theta": -0.563, "vega": 0.074, "rho": -0.004, "openInterest": 8204, ... } }, "callExpDateMap": {} }
Error/Exception Log, If Applicable See here to learn how to turn on debug logging: https://tda-api.readthedocs.io/en/latest/help.html Not Applicable
Very helpful wrapper and greatly appreciated. One small issue. Thank you.