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

Problem Parsing IBFlex statement #51

Closed
pascaloberle opened this issue May 23, 2022 · 2 comments
Closed

Problem Parsing IBFlex statement #51

pascaloberle opened this issue May 23, 2022 · 2 comments

Comments

@pascaloberle
Copy link

pascaloberle commented May 23, 2022

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
Copy link
Author

pascaloberle commented May 23, 2022

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
Copy link
Owner

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

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

No branches or pull requests

2 participants