csingley / ibflex

Python parser for Interactive Brokers Flex XML statements

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

kychanbp opened this issue · comments

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

The same code works before.

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?

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.

commented

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'...

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?

Solved by changing datetime.date to datetime.datetime.

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

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