KarmicP
KarmicP

Reputation: 3

Python pass a dictionary as an argument

I'm trying to pass a dictionary opt_chain as an argument

opt_chain = {
  'symbol': 'AAPL',
  'contractType': 'CALL',
  'optionType': 'S',
  'fromDate': '2021-07-18',
  'afterDate': '2021-07-19',
  'strikeCount': 4,
  'includeQuotes': True,
  'range': 'ITM',
  'strategy': 'ANALYTICAL',
  'volatility': 29.0
}

to the function api get_options_chain

But I get the following error

    option_chains = td_client.get_options_chain(args_dictionary = opt_chain)
TypeError: get_options_chain() got an unexpected keyword argument 'args_dictionary'

Here is the code that I run (excerpt):

opt_chain = {
  'symbol': 'AAPL',
  'contractType': 'CALL',
  'optionType': 'S',
  'fromDate': '2021-07-18',
  'afterDate': '2021-07-19',
  'strikeCount': 4,
  'includeQuotes': True,
  'range': 'ITM',
  'strategy': 'ANALYTICAL',
  'volatility': 29.0
}

option_chains = td_client.get_options_chain(args_dictionary = opt_chain)
pprint.pprint(option_chains)

This is Python v3.6.9

Any help is greatly appreciated,

Thank you

Upvotes: 0

Views: 102

Answers (3)

Dream
Dream

Reputation: 71

The issue is, td_client.get_options_chain method is not taking an argument called args_dictionary. It is expecting an argument called option_chain. You can either pass opt_chain as keyword argument like td_client.get_options_chain(option_chain = opt_chain) or you can directly pass opt_chain like td_client.get_options_chain(opt_chain) since it is the first argument td_client.get_options_chain is expecting.

    option_chains = td_client.get_options_chain(option_chain = opt_chain)

OR

    option_chains = td_client.get_options_chain(opt_chain)

Upvotes: 0

Ramarao Amara
Ramarao Amara

Reputation: 3486

In your code, option_chains = td_client.get_options_chain(args_dictionary = opt_chain) here args_dictionary was not expected in the API call, it should be 'option_chain'

option_chains = td_client.get_options_chain(option_chain=opt_chain)

Upvotes: 0

dir
dir

Reputation: 729

It looks like your code is perfect here, but the way you're calling the get_options_chain function of the TDClient library is incorrect.

Let's walk through this... The error you're receiving here is TypeError: get_options_chain() got an unexpected keyword argument 'args_dictionary'. This indicates that the function is not expecting a parameter called args_dictionary which you are setting in your parameters here (args_dictionary = opt_chain).

After looking at the library, I believe the fix is just passing in the dictionary without defining it as an argument, like so:

option_chains = td_client.get_options_chain(opt_chain)

If you look at the source code for the function, it does not require you to strictly define the argument name, and only takes in one argument anyways.

Upvotes: 1

Related Questions