Skip to content

Enhance Bank functionality with new game mechanics and API updates#162

Open
saiseahawks wants to merge 1 commit into
Open-Coding-Society:masterfrom
ApplicatorsCSA:master
Open

Enhance Bank functionality with new game mechanics and API updates#162
saiseahawks wants to merge 1 commit into
Open-Coding-Society:masterfrom
ApplicatorsCSA:master

Conversation

@saiseahawks
Copy link
Copy Markdown
Contributor

  • Added new fields for game state: experience points (xp), level, and quest progress.
  • Introduced methods for managing game state, including experience gain and quest initialization.
  • Updated balance management methods to support new game features.
  • Modified database mappings to use JSONB for certain fields, improving performance.
  • Refactored BankApiController to streamline dependencies and enhance API structure.
  • Adjusted security configuration to permit access to bank-related endpoints.

Summary

Adds a quantitative trading / learning game on top of the Bank feature. Market data, indicators, ML, backtesting, news sentiment, and paper trading live in mvc/quant/ and are exposed through /bank/quant/* (and /api/bank/quant/*). The Bank entity gains RPG-style progression (XP, level, quests). Market data can come from Yahoo Finance, Alpha Vantage, or bundled CSV files.

Why

The frontend needs one backend surface for the Bank quant game: prices, indicators, backtests, ML predictions, news/sentiment, and paper trades tied to Bank balance. Putting everything under /bank keeps cash balance as the single source of truth and avoids spreading logic across controllers.

What changed

New package: src/main/java/com/open/spring/mvc/quant/

  • MarketDataService — Daily OHLCV from Yahoo (no key), Alpha Vantage (ALPHAVANTAGE_API_KEY), or local CSV. Config: market.provider = auto | yahoo | alphavantage. Caching to reduce rate limits.
  • IndicatorService — SMA, RSI, Bollinger Bands, MACD, simple signals
  • NewsService — Sentiment snapshot (stubbed; can swap to real news API later)
  • MLService — Linear regression / random forest train + predict
  • BacktestService — Backtest MA, RSI, MACD, ML strategies vs buy-and-hold
  • PaperTradeService — Paper buy/sell; updates Bank.balance; positions in memory per personId
  • DTOsBar, Headline, SentimentSnapshot, PaperPortfolio, BacktestResult, MLTrainResponse

New static data: src/main/resources/market-data/

  • AAPL.csv, AMZN.csv, TSLA.csv — offline fallback when live providers fail or for local dev without API keys

BankApiController refactor

Single controller at /bank and /api/bank:

Core bank

  • GET /byPerson
  • POST /deposit
  • POST /withdraw

Quant

  • GET /quant/market/history
  • POST /quant/indicators/calc
  • GET /quant/news/sentiment
  • POST /quant/ml/train
  • POST /quant/backtest/run
  • POST /quant/paper/order
  • GET /quant/paper/portfolio

Uses constructor injection instead of field @Autowired.

Breaking change: Removed old endpoints (leaderboard, loans, analytics, NPC progress, bulk import/export). Restore or migrate if other clients still use them.

Bank entity

  • New: xp, level, questProgress (Run Backtest, Beat Buy&Hold, Sharpe >= 1.0, Train ML Model, Use News Boost)
  • addXp() and simple leveling
  • setBalance(amount, source) records profit history by source (e.g. paper_trade_buy)
  • JSON columns use jsonb for MySQL
  • lastRunStats is @Transient to avoid SQLite schema errors on startup

Security (MvcSecurityConfig)

  • permitAll() for /bank/** (game can call without session)
  • /api/bank/** still requires JWT (ROLE_USER+)

Minor

  • BankJpaRepository / BankService — cleanup only

Local dev

export JAVA_HOME=$(/usr/libexec/java_home -v 21)
export MARKET_PROVIDER=yahoo
./mvnw spring-boot:run

- Added new fields for game state: experience points (xp), level, and quest progress.
- Introduced methods for managing game state, including experience gain and quest initialization.
- Updated balance management methods to support new game features.
- Modified database mappings to use JSONB for certain fields, improving performance.
- Refactored BankApiController to streamline dependencies and enhance API structure.
- Adjusted security configuration to permit access to bank-related endpoints.
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

Successfully merging this pull request may close these issues.

1 participant