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

ibflex.parser.FlexParserError: Can't convert '20200406;214347' to <class 'datetime.date'> #15

Closed
kychanbp opened this issue Apr 8, 2020 · 6 comments · Fixed by #16
Closed

Comments

@kychanbp
Copy link
Contributor

kychanbp commented Apr 8, 2020

I receive this error ibflex.parser.FlexParserError: Can't convert '20200406;214347' to <class 'datetime.date'> today.

The same code works before.

@csingley
Copy link
Owner

csingley commented Apr 8, 2020

Well, it's trying to convert a date/time into a date. Of course it's failing; the semicolon and everything after it isn't supposed to be there.

This means your data doesn't match the ibflex data model. What field is it, exactly, that has '20200406;214347' where my code is expecting a date type?

@kychanbp
Copy link
Contributor Author

kychanbp commented Apr 8, 2020

I think it is in the TransactionTax.date part.

<TransactionTax accountId="XXXXXXXX acctAlias="" model="" currency="HKD" fxRateToBase="0.12899" assetCategory="STK" symbol="2801" description="ISHARES CORE MSCI CH IND ETF" conid="47028221" securityID="HK2801040828" securityIDType="ISIN" cusip="" isin="HK2801040828" listingExchange="SEHK" underlyingConid="" underlyingSymbol="" underlyingSecurityID="" underlyingListingExchange="" issuer="" multiplier="1" strike="" expiry="" putCall="" principalAdjustFactor="" date="20200406;214347" taxDescription="SFC Transaction Levy" quantity="600" reportDate="20200407" taxAmount="-0.39771" tradeId="141292481" tradePrice="24.5500" source="TRADE" code="" levelOfDetail="SUMMARY" />
<TransactionTaxDetail accountId="XXXXXXXXX" acctAlias="" model="" currency="HKD" fxRateToBase="0.12899" assetCategory="STK" symbol="2801" description="ISHARES CORE MSCI CH IND ETF" conid="47028221" securityID="HK2801040828" securityIDType="ISIN" cusip="" isin="HK2801040828" listingExchange="SEHK" underlyingConid="" underlyingSymbol="" underlyingSecurityID="" underlyingListingExchange="" issuer="" multiplier="1" strike="" expiry="" putCall="" principalAdjustFactor="" date="20200406;214347" taxDescription="SFC Transaction Levy" quantity="600" reportDate="20200407" taxAmount="-0.39771" tradeId="141292481" tradePrice="24.5500" source="TRADE" code="" levelOfDetail="DETAIL" />
</TransactionTaxes>

The problem happened after I brought some shares in HK stock exchange. There is no problem in US stocks.

I have looked at the data model. The date in TransactionTax Class is datetime.date. Not sure whether this is exchange specific.

@titov-vv
Copy link
Contributor

titov-vv commented Apr 8, 2020

For me it looks like IB reporting problem rather than ibflex issue. From what I see this '20200406;214347' value should be inside 'dateTime' field, not 'date'...

@csingley
Copy link
Owner

csingley commented Apr 8, 2020

Do we have a reference for the TransactionTax element?

IB is not completely consistent in their reporting formats. ibflex.Types.StatementOfFundsLine.date is also of type datetime.datetime, despite the name.

IIRC, I allowed datetime.datetime converters to also accept a 'naked' date without time... see lines 215-220 in ibflex.parser.

Try changing the data type of ibflex.Types.TransactionTax.date from Optional[datetime.date] to Optional[datetime.datetime]. Does that solve your problem?

@kychanbp
Copy link
Contributor Author

kychanbp commented Apr 8, 2020

Solved by changing datetime.date to datetime.datetime.

But I also need to add a new class TransactionTaxDetail which is the same as TransactionTax

@csingley
Copy link
Owner

csingley commented Apr 8, 2020

Please submit a PR once you've tested the changes. I don't have any data for TransactionTax etc. Thanks.

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 a pull request may close this issue.

3 participants