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

Error retrieving options chain #2

Closed
lmsanch opened this issue Dec 22, 2019 · 1 comment
Closed

Error retrieving options chain #2

lmsanch opened this issue Dec 22, 2019 · 1 comment

Comments

@lmsanch
Copy link

lmsanch commented Dec 22, 2019

I am trying to retrieve option chain for an optionable sotck, for example, DD.
TDSessions has get_options_chains method, but I am probably no using it correctly. Could you please provide an example around retrieving option chains?

TDSession.get_options_chain({'symbol': 'DD', 'strikeCount': 5, 'toDate': '2020-02-15'})

Returns

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-13-d85b4ef1ae8a> in <module>
      1 TDSession.get_options_chain({'symbol': 'DD',
      2                              'strikeCount': 5,
----> 3                              'toDate': '2020-02-15'})

~/Documents/SGXCode/DWPA/td/client.py in get_options_chain(self, option_chain)
    930 
    931         # this request requires an API key, so let's add that.
--> 932         option_chain.add_chain_key(
    933             key_name="apikey", key_value=self.config["consumer_id"]
    934         )

AttributeError: 'dict' object has no attribute 'add_chain_key'

I can retrieve stock quotes w/o problems, so the authentications for my account is working fine.

@dvd9604
Copy link
Contributor

dvd9604 commented Jan 2, 2020

Hey Imsanch,

TDSession.get_option_chain expects an instance of OptionChain as its argument, so you have to first create your option chain object then pass it to your request like below.

# Import OptionChain class
from td.option_chain import OptionChain

# Create an instance of OC with your args
option_chain_1 = OptionChain(symbol='DD', strikeCount=5, toDate = '2020-02-15')

# Make API call for your chain by passing the option chain object
TDSession.get_options_chain(option_chain_1)

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

3 participants