studerw / td-ameritrade-client

TD Ameritrade Java Client
Apache License 2.0
69 stars 47 forks source link

Option class: BigDecimalNanDeserializer needed for volatility + theoreticalOptionValue #31

Closed Somanko closed 4 years ago

Somanko commented 4 years ago

Getting Exception as these 2 returns NaN for MSFT getOptionChain

higgsja commented 4 years ago

Having this issue on option chains. Tracked it down to DefaultMapper public static <T> T fromJson(InputStream in, TypeReference<T> typeReference) { try (BufferedInputStream ignored = new BufferedInputStream(in)) { return defaultMapper.readValue(in, typeReference); } catch (IOException e) { throw new RuntimeException(e); } with an exception like: Cannot deserialize value of typejava.math.BigDecimalfrom String "NaN": not a valid representation at [Source: (BufferedInputStream); line: 1, column: 38443] (through reference chain: com.studerw.tda.model.option.OptionChain["putExpDateMap"]->java.util.LinkedHashMap["2020-10-23:5"]->java.util.LinkedHashMap["42.0"]->java.util.ArrayList[0]

Apparently some field on the return is not a number but I am not smart enough to track further. I've tried a couple tickers, same result.

I'll also post this under #31.

studerw commented 4 years ago

I know how to fix that. Give me a few hours to take a look...

On Sun, Oct 18, 2020, at 18:36, higgsja wrote:

Having this issue on option chains. Tracked it down to DefaultMapper public static <T> T fromJson(InputStream in, TypeReference<T> typeReference) { try (BufferedInputStream ignored = new BufferedInputStream(in)) { return defaultMapper.readValue(in, typeReference); } catch (IOException e) { throw new RuntimeException(e); } with an exception like: Cannot deserialize value of typejava.math.BigDecimalfrom String "NaN": not a valid representation at [Source: (BufferedInputStream); line: 1, column: 38443] (through reference chain: com.studerw.tda.model.option.OptionChain["putExpDateMap"]->java.util.LinkedHashMap["2020-10-23:5"]->java.util.LinkedHashMap["42.0"]->java.util.ArrayList[0]

Apparently some field on the return is not a number but I am not smart enough to track further. I've tried a couple tickers, same result.

I'll also post this under #31 https://github.com/studerw/td-ameritrade-client/issues/31.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/studerw/td-ameritrade-client/issues/31#issuecomment-711434273, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABQHJA7PFGDUIPBYPL4WHC3SLNUYVANCNFSM4SU7GBVA.

higgsja commented 4 years ago

Thanks!!

studerw commented 4 years ago

@higgsja what version are you using? The latest build or the last release 2.2.0?

higgsja commented 4 years ago

2.2.0

If you cannot recreate this issue let me know. Could be I have another incorrect version of some jar file.

higgsja commented 4 years ago

Went ahead and looked through the jar versions. Seems ok. Let me know if you discover the issue on this or if I can help further.

studerw commented 4 years ago

Can you build the master branch and then trying using 2.3.0-SNAPSHOT in your project? The fix to your issue is in one of the last few commits.

On Tue, Oct 20, 2020, at 12:38, higgsja wrote:

Went ahead and looked through the jar versions. Seems ok. Let me know if you discover the issue on this or if I can help further.

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

higgsja commented 4 years ago

I can try ...

higgsja commented 4 years ago

Ok, that works in a limited way: Huge number of 'WARN com.studerw.tda.parse.BigDecimalNanDeserializer - volatility using invalid NAN instead of a valid double' for the various elements including the greeks, etc. Could be tdAmeritrade does not actually provide those elements?

However, it does not fail and the basic info is now available.

Thanks!!!

studerw commented 4 years ago

Yeah I think the problem is that TDAs internal API is in Java, and a lot of these doubles are too close to zero for JavaScript to represent so the JS converts to NAN. So we lose precision but there isn’t any good way to solve it on our end. TDA would need to use a better library for representing very small floating point numbers without truncating them to NAN.

On Tue, Oct 20, 2020, at 17:56, higgsja wrote:

Ok, that works in a limited way: Huge number of 'WARN com.studerw.tda.parse.BigDecimalNanDeserializer - volatility using invalid NAN instead of a valid double' for the various elements including the greeks, etc. Could be tdAmeritrade does not actually provide those elements?

However, it does not fail and the basic info is now available.

Thanks!!!

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

higgsja commented 4 years ago

harrumph.

I sent a message to the tdAmeritrade team last May. They answered (not a useful answer) yesterday. Clearly not a priority ...

studerw commented 4 years ago

@higgsja, I made and published new release 2.3.0 if you want the fixes for NAN. I'm going to close this unless there is something else.