Basically, I want to use python to query my IB order history and do some analyze afterwards. But I could not find any existing API for me to query these data, does anyone have experience to do this?
You have to use flex queries for that purpose. It has full transaction history including trades, open positions, net asset value history and exchange rates.
Interactive brokers: How to retrieve transaction history records?