td-ameritrade-client icon indicating copy to clipboard operation
td-ameritrade-client copied to clipboard

Option Chain Parse failure from getOptionChain()

Open bosohn opened this issue 4 years ago • 7 comments

Hi,

I am getting the following exception from getOptionChain() when I issued it today for OSTK. Could you please check this issue? I just tested with 2.4.0. If you cannot reproduce with OSTK, I can try to find other symbol that has the same issue.

com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type java.math.BigDecimal from String "NaN": not a valid representation at [Source: (BufferedInputStream); line: 1, column: 681] (through reference chain: com.studerw.tda.model.option.OptionChain["putExpDateMap"]->java.util.LinkedHashMap["2021-02-12:3"]->java.util.LinkedHashMap["46.0"]->java.util.ArrayList[0]->com.studerw.tda.model.option.Option["volatility"])

Thank you!

bosohn avatar Feb 09 '21 20:02 bosohn

hi @bosohn

I just tried this using this branch of an example here and it worked. Just add your client id and refresh token to src/main/resources/tda-api.properties file then run mvn clean install and run mvn exec:java -Dexec.cleanupDaemonThreads=false.

I can attach the output if you want, but the point is that it didn't have an issue using the version in this pom (2.4.0).

studerw avatar Feb 10 '21 00:02 studerw

Hi,

It works fine for other symbols but there are certain symbols that fails with the exception. I tried SRNE and got java.lang.RuntimeException: com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type java.math.BigDecimal from String "NaN": not a valid representation at [Source: (BufferedInputStream); line: 1, column: 309603] (through reference chain: com.studerw.tda.model.option.OptionChain["callExpDateMap"]->java.util.LinkedHashMap["2022-01-21:346"]->java.util.LinkedHashMap["1.0"]->java.util.ArrayList[0]->com.studerw.tda.model.option.Option["volatility"])

For OSTK this time, I got java.lang.RuntimeException: com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type com.studerw.tda.model.account.OptionDeliverable$AssetType from String "STOCK": not one of the values accepted for Enum class: [MUTUAL_FUND, CURRENCY, INDEX, FIXED_INCOME, OPTION, CASH_EQUIVALENT, EQUITY] at [Source: (BufferedInputStream); line: 1, column: 441577] (through reference chain: com.studerw.tda.model.option.OptionChain["putExpDateMap"]->java.util.LinkedHashMap["2022-01-21:346"]->java.util.LinkedHashMap["2.5"]->java.util.ArrayList[1]->com.studerw.tda.model.option.Option["optionDeliverablesList"]->java.util.ArrayList[1]->com.studerw.tda.model.account.OptionDeliverable["assetType"])

For INO, I get correct response Option Chain: com.studerw.tda.model.option.OptionChain@6b5176f2[ symbol=INO status=SUCCESS underlying= strategy=SINGLE interval=0.0 isDelayed=false isIndex=false daysToExpiration=0.0 interestRate=0.1 underlyingPrice=13.825 volatility=29.0 callExpDateMap={2021-02-12:3={2.0=[com.studerw.tda.model.option.Option@ec0c838[ putCall=CALL symbol=INO_021221C2 description=INO Feb 12 2021 2 Call (Weekly) exchangeName=OPR ....

Somehow it consistently fails for some symbols and works for others.

bosohn avatar Feb 10 '21 03:02 bosohn

Can you check out the project and then build it with mvn clean install? It will install a SNAPSHOT version into your local repository. Then in your own project make sure you are using that SNAPSHOT version by updating your pom or Gradle build file or whatever you are using.

I think maybe you’re not using the latest version.

On Tue, Feb 9, 2021, at 22:30, bosohn wrote:

Hi,

It works fine for other symbols but there are certain symbols that fails with the exception. I tried SRNE and got java.lang.RuntimeException: com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type java.math.BigDecimal from String "NaN": not a valid representation at [Source: (BufferedInputStream); line: 1, column: 309603] (through reference chain: com.studerw.tda.model.option.OptionChain["callExpDateMap"]->java.util.LinkedHashMap["2022-01-21:346"]->java.util.LinkedHashMap["1.0"]->java.util.ArrayList[0]->com.studerw.tda.model.option.Option["volatility"])

For OSTK this time, I got java.lang.RuntimeException: com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type com.studerw.tda.model.account.OptionDeliverable$AssetType from String "STOCK": not one of the values accepted for Enum class: [MUTUAL_FUND, CURRENCY, INDEX, FIXED_INCOME, OPTION, CASH_EQUIVALENT, EQUITY] at [Source: (BufferedInputStream); line: 1, column: 441577] (through reference chain: com.studerw.tda.model.option.OptionChain["putExpDateMap"]->java.util.LinkedHashMap["2022-01-21:346"]->java.util.LinkedHashMap["2.5"]->java.util.ArrayList[1]->com.studerw.tda.model.option.Option["optionDeliverablesList"]->java.util.ArrayList[1]->com.studerw.tda.model.account.OptionDeliverable["assetType"])

For INO, I get correct response Option Chain: com.studerw.tda.model.option.OptionChain@6b5176f2[ symbol=INO status=SUCCESS underlying= strategy=SINGLE interval=0.0 isDelayed=false isIndex=false daysToExpiration=0.0 interestRate=0.1 underlyingPrice=13.825 volatility=29.0 callExpDateMap={2021-02-12:3={2.0=[com.studerw.tda.model.option.Option@ec0c838[ putCall=CALL symbol=INO_021221C2 description=INO Feb 12 2021 2 Call (Weekly) exchangeName=OPR ....

Somehow it consistently fails for some symbols and works for others.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/studerw/td-ameritrade-client/issues/40#issuecomment-776414013, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABQHJAZDDLG7RWLSWIKSKW3S6H4XFANCNFSM4XLU7EVA.

studerw avatar Feb 10 '21 04:02 studerw

I just tried again with that same branch using all three of the symbols you listed and it works fine.

https://github.com/studerw/tda-client-example/blob/option_chain_test/src/main/java/org/example/MainExample.java

I also deleted all the saved artifacts for this client in my ~/.m2/repository/com/studerw/ directory to force a download of the 2.4.0 version from Maven Central.

Again, I think you are using a bad version somehow. Do you want to check in your project (without any token / client_id) stuff, of course? I can take a look. I will try it again a few more times during the day - maybe it's just an issue when prices are at a certain level, but I don't think that's it.

studerw avatar Feb 11 '21 16:02 studerw

Sorry, I've been busy. I will get back to it over the weekend. I appreciate your help and thanks for the nice software.

Just wanted to ask you whether there's any TD API that provides earning dates and ex-dividend dates. I tried instrument info API from your API but it didn't return those information, also wondering whether there's an example on how to place spread or synthetic option order with multiple legs.

bosohn avatar Feb 12 '21 02:02 bosohn

I verified that it works fine with 2.4.0. Thanks for your help. Any information on the items I mentioned above for API?

bosohn avatar Feb 18 '21 23:02 bosohn

One more question: When I retrieve option chain 'underlyingPrice' field of OptionChain is often not valid as shown below for GLRE $4.25 (retrieved after market close today) while today's close is $7.86. For some symbols underlying price is $0.

  1. Could you check why incorrect price is returned for 'underlyingPrice' field?
  2. Field 'underlying' of OptionChain seems to be null. Is it not supplied by TD or dropped by client?

{"delayed":false,"index":false,"symbol":"GLRE","status":"SUCCESS","strategy":"SINGLE","interval":0.0,"isDelayed":false,"isIndex":false,"daysToExpiration":0.0,"interestRate":0.1,"underlyingPrice":4.25,"volatility":29.0,"callExpDateMap":{"2021-02-19:1":{"2.5":[{"inTheMoney":true,"mini":false,"nonStandard":false,"putCall":"CALL","symbol":"GLRE_021921C2.5","description":"GLRE Feb 19 2021 2.5 Call","exchangeName":"OPR","bidPrice":4.5,"askPrice":6.6,"lastPrice":0.0,"bidAskSize":"80X20","markPrice":5.55,"bidSize":80,"askSize":20,"lastSize":0,"highPrice":0.0,

bosohn avatar Feb 19 '21 00:02 bosohn