csingley / ibflex

Python parser for Interactive Brokers Flex XML statements
MIT License
85 stars 41 forks source link

Problem Parsing IBFlex statement #51

Closed pascaloberle closed 2 years ago

pascaloberle commented 2 years ago

Hello,

I have a simple code retrieving my IB Flex trading activity

token = 'myvalidtoken'
query_id = '583460'
response = client.download(token, query_id)
response = parser.parse(response)
stmt = response.FlexStatements[0]

The reponse looks good I receive a correct XML structure but the parser is not happy with it apparently and going through this problem below (hiding my accountid for privacy consideration)


ParserError: Unknown string format: b'<FlexQueryResponse queryName="Trades YTD" type="AF">\n<FlexStatements count="1">\n<FlexStatement accountId="UXXXXXXXX" fromDate="20220103" toDate="20220520" period="YearToDate" whenGenerated="20220523;103059">\n<Trades>\n<Trade symbol="AAOI" tradeDate="20220107" fifoPnlRealized="0" buySell="SELL" quantity="-100" tradePrice="4.8" currency="USD" />\n<Trade symbol="AAOI" tradeDate="20220119" fifoPnlRealized="233.97086" buySell="BUY" quantity="200" tradePrice="4.05" currency="USD" />\n<Trade symbol="AAOI" tradeDate="20220202" fifoPnlRealized="0" buySell="SELL" quantity="-125" tradePrice="4.15" currency="USD" />\n<Trade symbol="AAOI" tradeDate="20220222" fifoPnlRealized="0" buySell="SELL" quantity="-125" tradePrice="3.99" currency="USD" />\n<Trade symbol="AAOI" tradeDate="20220307" fifoPnlRealized="27.592442" buySell="BUY" quantity="50" tradePrice="3.57" currency="USD" />\n<Trade symbol="AAOI" tradeDate="20220307" fifoPnlRealized="94.519868" buySell="BUY" quantity="200" tradePrice="3.568" currency="USD" />\n<Trade symbol="AAON" tradeDate="20220202" fifoPnlRealized="0" buySell="SELL" quantity="-4" tradePrice="63.95" currency="USD" />\n<Trade symbol="AAON" tradeDate="20220209" fifoPnlRealized="0" buySell="SELL" quantity="-4" tradePrice="59.93" currency="USD" />\n<Trade symbol="AAON" tradeDate="20220215" fifoPnlRealized="11.252432" buySell="BUY" quantity="8" tradePrice="60.158" currency="USD" />\n<Trade symbol="AAPL" tradeDate="20220124" fifoPnlRealized="0" buySell="BUY" quantity="2" tradePrice="159.88" currency="USD" />\n<Trade symbol="AAPL" tradeDate="20220211" fifoPnlRealized="22.91798"

...

Any idea what can be wrong? I am attaching a XML sample of my response in a .txt format if it can help in the debugging, Thanks in advance for your help!

statement.txt

pascaloberle commented 2 years ago

It was a problem in my code false problem sorry! my Track Record module is now working and powered by your code thank you very much for the great tool. www.pascal-hedgefund.com

csingley commented 2 years ago

Glad it worked out. If you’re doing audit/tax, you might take a gander at my capgains repo. It’s not really “library-ized” for 3rd party use, but the core lot-matching algorithm has handled quite a bit of transaction volume (in stocks, bonds, options, and weird reorgs) with its output audited (as in paid CPAs). So it’s pretty solid