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

Remove incorrect code from contract details decoder #19

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

djkelleher
Copy link

@djkelleher djkelleher commented May 15, 2024

Problem - The current contract details decoder contains a bit of code that should only be used in the bond contract details decoder.

Effect - The function first correctly assigns the timeZoneId, but then later in the function body overwrites it with the timezone TWS is set to use.

Solution - Delete the extra code.

For reference, here is the logic from the official API from Interactive Brokers:

def readLastTradeDate(self, fields, contract: ContractDetails, isBond: bool):
        lastTradeDateOrContractMonth = decode(str, fields)
        if lastTradeDateOrContractMonth is not None:
            if '-' in lastTradeDateOrContractMonth: 
                splitted = lastTradeDateOrContractMonth.split('-')
            else:
                splitted = lastTradeDateOrContractMonth.split()
                
            if len(splitted) > 0:
                if isBond:
                    contract.maturity = splitted[0]
                else:
                    contract.contract.lastTradeDateOrContractMonth = splitted[0]

            if len(splitted) > 1:
                contract.lastTradeTime = splitted[1]

            if isBond and len(splitted) > 2:
                contract.timeZoneId = splitted[2]

@djkelleher djkelleher changed the title remove incorrect code Remove incorrect code from contract details decoder May 15, 2024
@mattsta
Copy link
Contributor

mattsta commented May 16, 2024

Thanks for all the details! You're right this looks broken because we use the different function bondContractDetails() directly.

What contract was causing the problem? Always nice to be able to see the crash before the fix then verify it works after.

I'll probably refactor all those length checks too when adding this since we could just do a series of field = times.pop(0) instead of individual checks for each case.

@djkelleher
Copy link
Author

Update: I just tested on the latest TWS stable (10.19.2m) and this actually isn't an issue anymore (the timezone at index 2 is actually for the exchange rather than TWS).

This was an old PR (Nov 29, 2023) from ib_insync (erdewit/ib_insync#664) that I just copied over here. The issues were originally encountered while pulling contract details for futures contracts on an earlier 10.19 stable release.

I just tested on all futures contracts IB has (I think) and it's never necessary to reassign the timezone since the original value is always correct. I think even though the reassigning works on latest release, it's probably still better to take it out for backwards compatibility reasons and better consistency with the official IB Python client.

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

Successfully merging this pull request may close these issues.

2 participants