brndnmtthws / thetagang

ThetaGang is an IBKR bot for collecting money
GNU Affero General Public License v3.0
1.89k stars 248 forks source link

Keeping a Record of Trades #451

Closed algoeng closed 2 weeks ago

algoeng commented 2 weeks ago

While the command line output is very nice, is there a good way to keep a record or log of trades? I am running via a crontab+docker. I have tried to output to a file but it comes out very narrow and so most things in the tables are not readable. Is there a way to get a more readable log? If not is there a best practice to extend and add our own extension to do other custom things, like insert the trade to a database?

brndnmtthws commented 2 weeks ago

I have thought about this, and it would be easy enough to either write everything to a CSV file or maybe a SQLite DB. The only problem is that it won't be a complete record. The best we could do is log the actions taken by thetagang (i.e., submitted an order, canceled an order, etc). IBKR is always going to be the source of truth, and for a complete log of all trades you'd need to use whatever tools provided by IBKR.

As example of where it gets tricky: we can log that an order was submitted, but we may not know if it was filled, because thetagang doesn't run continuously or do any sort of order state synchronization. We also don't have a way to access more detailed information such as the tax lots to determine when each position was entered/exited and at what price. This is a limitation of the IBKR API and I don't think there's any way to get more detailed data or trade logs.

algoeng commented 2 weeks ago

Ah, you are right. I think I might just run a small script from cron after market close to try to get the basics (what orders were filled and what's the account value, etc). Thanks.

algoeng commented 2 weeks ago

No action needed from Thetagang.