feat: add day trading game skeleton (#128)#151
Conversation
Implement a day-trading mini-game with simulated stock market. - MockMarket with 10 real-world ticker symbols and +\-3% random price movement - Optional AlpacaMarket provider (auto-detected via env vars, no install required) - Portfolio with JSON persistence (cash, holdings, transaction history) - Live-updating stock ticker via ANSI escape codes (background thread) - Chip-to-dollar deposit/withdraw system (1 chip = $10 trading dollars) - Auto-convert remaining trading cash back to chips on exit - Full game loop: view portfolio, buy, sell, lookup, history Closes ufosc#128
There was a problem hiding this comment.
Pull request overview
This PR implements a day-trading mini-game for the terminal casino, allowing players to convert chips to trading dollars and simulate stock market trading. The implementation includes a mock market with randomized price movements and optional integration with Alpaca's paper trading API. Portfolio data is persisted to JSON files, and the game features live-updating stock tickers using ANSI escape codes and background threads.
Changes:
- Added a complete day-trading game with portfolio management and transaction history
- Implemented MockMarket with 10 ticker symbols and simulated price movements
- Added optional AlpacaMarket integration for live paper-trading data
- Created JSON-based portfolio persistence system with chip-to-dollar conversion
Reviewed changes
Copilot reviewed 6 out of 8 changed files in this pull request and generated 21 comments.
Show a summary per file
| File | Description |
|---|---|
| requirements.txt | Added comment documenting optional alpaca-py dependency |
| casino/main.py | Registered "day trading" game in GAME_HANDLERS dictionary |
| casino/games/init.py | Added daytrading module to imports and exports |
| casino/games/daytrading/init.py | Created module initialization exporting play_daytrading |
| casino/games/daytrading/portfolio.py | Implemented Portfolio and Transaction classes with JSON persistence |
| casino/games/daytrading/market.py | Implemented MarketProvider interface with MockMarket and AlpacaMarket |
| casino/games/daytrading/daytrading.py | Implemented main game loop with live ticker updates and trading operations |
| .gitignore | Excluded portfolios directory from version control |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Hi StecuPM, can you please resubmit a new PR or copy and incorporate the PR Template into this PR? Now that we have that template, all PRs will need to use it; this includes PRs opened before it was implemented. |
|
Hi, I have just incorporated the PR Template as requested. |
many inter-dependent packages were using incompatible versions and other packages were not compatible with Python v.3.13.0. I have no didea how this wasn't an issue earlier. I've also clarified the readme.md (in a separate commit) to clarify TERMINALCASINO is a Python v.3.13.0 project. I suspect contributors have been using older Python versions mistakenly, up until now.
I couldn't run your PR on my local machine successfully. There appear to be issues with module discovery.
Please resolve these bugs and commit your changes. Also, re-pull the PR's history as I updated the requirements.txt and fixed broken docstrings in blackjack.py that crashed the program.
@kevin8999 did you have any success running this on your local? This bug seems unique to this branch, as main has a similar |
I was able to run it after performing the following modifications: Modification (1/2)
Modification (2/2)
It seems like these were issues present in the original |



Type of Change
Related Issue
Fixes issue #128
Changes
New files:
casino/games/daytrading/__init__.py— package init, exportsplay_daytradingcasino/games/daytrading/market.py—MarketProviderABC,MockMarket(10 stocks, ±3% random movement),AlpacaMarket(optional, auto-detected via env vars)casino/games/daytrading/portfolio.py—PortfolioandTransactiondataclasses with JSON save/load persistencecasino/games/daytrading/daytrading.py— main game loop, live-updating stock ticker (ANSI + background thread), chip-to-dollar deposit/withdraw system, buy/sell/lookup/history UIModified files:
casino/games/__init__.py— addeddaytradingimportcasino/main.py— added"day trading"toGAME_HANDLERSrequirements.txt— added optionalalpaca-pycomment.gitignore— addedcasino/games/daytrading/portfolios/(user-generated JSON saves)Why these changes were necessary:
Issue #128 requested a day-trading game skeleton with JSON-based user state persistence. The implementation provides a fully playable simulated stock market that works out of the box with zero API keys, while supporting optional Alpaca paper-trading for live data.
Testing
python -m casino.main[E]nter, select "Day Trading"[L]ookup— verify all 10 stocks visible, prices update live every second[B]uy/[S]ell— verify portfolio updates and cash deducted/added[V]iew— verify holdings displayed with current prices[H]istory— verify transaction log[D]eposit/[W]ithdraw— verify chip-to-dollar conversion both ways[Q]uit— verify auto-conversion of remaining cash back to chipsChecklist
Output Screenshots
Next Steps
AI Disclosure
Claude Code (Claude Opus 4.6) was used to iterate on bug fixes (ANSI cursor positioning, live ticker, deposit/withdraw system). All code was reviewed, tested, and adjusted manually.