开云体育

ctrl + shift + ? for shortcuts
© 2025 开云体育

ib.trades() and nightly restarts


 

My intent to have my script run all the time, however I have some issues with the way that ib.trades(), returns after TWS restarts itself automatically through the auto-restart feature.
?
util.df(ib.trades())
?
I have a simple function called called post_midnight_refresh(), that does some log cycling, some basic cleanup, as well as refreshes some variables (and basically disconnects and reconnects after TWS restarts). I understand that I don't have to do that, because as I understand, IB_async library will handle the disconnect / reconnect automatically, however, in order to test why ib. trades() seems to be returned previous day traded symbols, I decided to disconnect and reconnect manually.
?
However that doesn't seem to fix the issue. Any idea how I can get ib.trades() to return only the trades for that day?
?
If I close my python script in Windows and reopen the script (the next day), then all works fine, and ib.trades() just returns trades that I did today, (and not everything from today and yesterday)
?
ib.disconnect()
ib.client.reset()
ib.connect('127.0.0.1', 7496, clientId=0)
?
I also tried to do this before I call ib.trades() to make sure that trades are accurate, but that doesn't seem to fix it either.?
? ? ? ? ib.reqAllOpenOrders()
? ? ? ? ib.reqOpenOrders() # Bind previous opened orders
? ? ? ? ib.reqAutoOpenOrders() ?# Bind all future orders
?
Also, do I actually have to call the above prior to calling ib.trades() ?
?
?


 

IIRC this annoyed me at one point too and I just hacked everything through...

| fgrep "($(date +'%Y, %-m, %-d',)"

You might want to dig deeper for the correct(tm) way or convert the grep into pure Python; w/e. IDK

-Keep us posted