StockMarket wAPI

A virtual stock market mod for Minecraft 1.21.1 (NeoForge) with AI-driven news and real-time price changes based on player demand. Uses a custom currency (KABU) and relies on aidbwapi_core for AI and data storage.

96 downloads
0 followers
  1. English / 2. 日本語

StockMarket wAPI Mod (stock_wapi)

An authentic virtual stock market mod for Minecraft 1.21.1 (NeoForge) where stock prices fluctuate in real-time based on AI-generated economic news and player supply and demand. It features a bi-directional exchange mechanism between the unique currency "KABU" and any items, allowing anyone to easily enjoy trading stocks via sign UIs or commands. All AI processing and data persistence are delegated to AI DataBase wAPI Core, allowing this mod to focus entirely on "stock market logic and game experience."

Item Value
Mod ID stock_wapi
Display Name StockMarket wapi mod
Versioning 1.21.1-x.y.z (MC Version-SemVer, independent of core)
Requirements aidbwapi_core required
License Apache License 2.0

🚀 Features & Architecture

1. AI-Driven Price Fluctuation System (Market Engine)

Stock prices are determined during periodic updates by summing the following four factors. The AI does not decide the price directly; it functions as one of the influential factors.

  • Internal Random Fluctuation: Natural price movement based on the base volatility set for each ticker.
  • Trend Tendency: Based on the initial tendency ("Bullish / Bearish / Neutral") set for each ticker, the trend dynamically changes with a certain probability (8%) during each periodic update, forming waves of prosperity and recession.
  • Player Supply & Demand Impact: Aggregates player buy and sell volumes during the update interval and reflects them in the price based on a logarithmic function: $log_{10}(1 + |netDemand|)$. This reflects the actions of market participants in the price while suppressing rapid fluctuations. The timing of demand reflection is at the "periodic update," and prices do not move instantly at the moment of trade.
  • AI Market Sentiment Impact: Market trend data is sent to the LLM via aidbwapi_core, and the "Market Sentiment Score (-N to +N)" returned by the AI is normalized and converted into price impact.

Price Safety Mechanisms

  • Stock prices are managed as integers. The fluctuation range per update is clamped to a maximum of ±10% (configurable via config).
  • Each ticker has a minimum price (minPrice) and a maximum price (maxPrice), and the price is always restricted within this range.
  • Rebound Mechanism: Near the minimum price, downward pressure is weakened and upward correction is strengthened to prevent the price from approaching zero. Bankruptcy or delisting does not occur.

Adaptive Demand Scaling (Adaptive Demand Scaling)

The total transaction volume of the server for the past 5 days (default: 120 updates) is saved as a moving average, which is used to automatically normalize the supply and demand impact. Even if the number of players or transaction scale changes, an appropriate balance is maintained without manual config adjustments.

2. AI News Generation (Market News)

During periodic updates, market trend data (fluctuation summaries for each ticker, world settings, etc.) is sent to aidbwapi_core, and the AI generates economic news text and market sentiment scores.

  • During periodic updates, news is broadcast to all players on the server in the format [StockWapi] via chat. If AI generation fails, fallback news ("Failed to retrieve AI market news due to a communication error. The market is moving solely based on technical factors.") is broadcast instead, and the market price update itself proceeds normally.
  • Latest news and past news history (up to 30 entries, with timestamps, newest first) can be viewed via /stockwapi news.
  • News history is kept indefinitely (stored in GlobalDB).

Behavior on AI Failure

If an AI request fails (e.g., all models unavailable), the stock price is calculated using only other factors with zero AI impact (sentiment=0). Fallback news is broadcast to all players.

For Admins: Troubleshooting AI Errors

  1. /dbwapi ai errors — Check recent error history (HTTP status codes/causes).
  2. /dbwapi model list — View status of all models (Enabled/Disabled, Penalty points).
  3. /dbwapi model enable <KeyName>.<ModelName> — Restore models automatically disabled due to authentication errors, etc.
  4. /dbwapi model reset <KeyName>.<ModelName> — Reset penalties and cooldowns.

3. AI Company Description Auto-Generation (Company Description)

When an admin adds a ticker, the ticker name is sent to aidbwapi_core, and the AI automatically generates a company description and saves it to the DB. This process is executed only at the time of registration. If AI generation fails, a fallback description ("Company description is currently unavailable.") is automatically saved to the DB. Players can view company descriptions via the /stockwapi info <ticker> command or signs. To manually correct or replace a company description, directly edit the companyDesc_XXX key in the DB file (stock_wapi_GlobalDatabase.json). Setting an existing company description to an empty string ("") and restarting the server will trigger the AI to automatically regenerate a new description.

4. Unique Currency "KABU" and Item Exchange (Currency & Exchange)

This mod does not depend on external economy mods and uses its own currency, "KABU".

  • Currency Name: KABU (Integer only, initial balance 0).
  • Balance & Transaction Limits: The maximum balance per player and the limit for a single transaction (including stock trades and item exchanges) is 2 billion KABU (2,000,000,000) (to prevent integer overflow and economic collapse).
  • Players can exchange any items (including vanilla and items from any mod) bi-directionally with KABU. Exchanges can be performed via Sign UI or commands.
  • Multiple items can be registered with different rates (e.g., Diamond = 100 KABU, Gold Ingot = 10 KABU). Registration of exchange targets is done via admin command (/stockwapi admin setrate), and rate information is saved in config/stock_wapi-exchange.json.

Item Exchange Safety Mechanisms

  1. Pre-Inventory Scan: To prevent partial consumption errors due to vanilla specifications, the player's entire inventory is scanned before the exchange process to check if the total amount possessed meets the required amount.
  2. Limit Overrun Block: If an exchange would cause the balance to exceed the limit (2 billion KABU), the process is completely blocked without consuming items.

5. Insider Trading Prevention & Market Integrity (Market Integrity)

To make trading before news disclosure structurally impossible, the update process is executed in the following strict order:

Lock Trading → Update Prices → Save News → Broadcast → Update Signs → Unlock Trading

If a trade is attempted during the lock, the player is notified that trading is currently blocked.

6. Commission System (Commission)

  • Commissions can be collected during buying and selling. Percentages can be set individually for buys and sells. Default is 0%.
  • Commission revenue can either "disappear (default)" or go to a "server-wide administrative account (configurable)". The admin account is not linked to any specific player UUID.
  • View the balance of the admin account with /stockwapi admin balance.

7. Sign Interface (Sign Interface)

By linking functions to sign blocks placed by an administrator, players can buy, sell, exchange, and view news with just a right-click.

  • Signs can only be placed by administrators (/stockwapi admin sign <type> [<arg1>] [<arg2>]).
  • Signs are automatically updated when stock prices update. Trading can be done directly from signs (executed instantly on right-click).
  • Signs cannot be destroyed by anyone other than an administrator (if an OP destroys one, it is automatically unlinked).

Sign Types (7 total)

Type Example Command Sign Display Right-Click Action
price sign price RDM Ticker + Price Display ticker details in chat
list sign list Market Header Display all tickers + prices in chat
buy sign buy RDM 5 Ticker + Qty + Price Instantly buy the specified quantity
sell sign sell RDM 5 Ticker + Qty + Price Instantly sell the specified quantity
exchange sign exchange diamond 10 Item + Qty + KABU Instant Item → KABU exchange
buyitem sign buyitem diamond 10 Item + Qty + KABU Instant KABU → Item purchase
news sign news News Header Display the latest news in chat

Unlinking: /stockwapi admin unsign (execute while looking at the sign)


💻 Requirements & Setup

  • Minecraft: 1.21.1
  • Mod Loader: NeoForge 21.1.219 or later
  • Java: Java 21 or higher
  • Required Dependency: aidbwapi_core (AI Communication & Database Foundation)
  • Side: Required on both Server and Client

Installation:

  1. Ensure aidbwapi_core is set up (AI provider registered and model configured).
  2. Place this mod (stock_wapi-x.x.x.jar) into the mods folder of your server or client and launch.
  3. Upon first launch, three demo preset tickers (RDM, END, OAK) will be automatically generated.

📖 Usage

Server Administrator: Initial Setup

Step 1: Preparing aidbwapi_core

Setup of aidbwapi_core is mandatory for this mod to function. Follow these steps:

1-1. Register AI Provider

Register connection information for your AI service (OpenAI-compatible API) as a "KeyName."

/dbwapi keyname add <KeyName> <API_Endpoint_URL> <API_Key>

⚠ Security Warning: Due to Minecraft's specifications, the full command you type in chat (the plain text API key) will be recorded in the server's logs/latest.log. For security, it is strongly recommended to edit config/aidbwapi_core-keynames.json directly with a text editor and then run /dbwapi reload in-game.

1-2. Register Model

Add the AI model you wish to use to the registered provider.

/dbwapi model add <KeyName>.<ModelName> <DailyLimit> <MinuteLimit>

If limits are omitted or set to -1, they are registered as unlimited. Registering multiple providers/models allows the system to automatically switch if one fails (failover).

1-3. Verify Operation
/dbwapi ai test

If you receive a response from the AI, the setup is complete. If an error occurs, check the details with /dbwapi ai errors.

Step 2: First Launch & Auto Setup

After placing this mod in the mods folder and starting the server, the following will happen:

  • Three demo preset tickers (RDM, END, OAK) will be defined in config/stock_wapi-stocks.json.
  • AI company descriptions for each ticker will be asynchronously generated and saved.
  • The periodic market update scheduler will start (Default: every 1 hour).

Step 3: Register Item Exchange Rates

Set up exchange rates so players can obtain KABU.

/stockwapi admin setrate diamond 100
/stockwapi admin setrate gold_ingot 10

This enables exchanges like "1 Diamond = 100 KABU" and "1 Gold Ingot = 10 KABU."

Step 4: Placing Signs (Optional)

Set up Sign UIs so players can interact with a right-click. Place a sign and execute the following commands while looking at it:

/stockwapi admin sign price RDM             ← Displays RDM price
/stockwapi admin sign buy RDM 5             ← Buys 5 shares of RDM
/stockwapi admin sign sell RDM 5            ← Sells 5 shares of RDM
/stockwapi admin sign exchange diamond 10   ← Exchange 10 Diamonds for KABU
/stockwapi admin sign buyitem diamond 1     ← Purchase 1 Diamond with KABU
/stockwapi admin sign list                  ← Displays all tickers
/stockwapi admin sign news                  ← Displays latest news

Step 5: Adding/Customizing Tickers (Optional)

To add a custom ticker:

/stockwapi admin add ABC "Alpha Beta Corp" 50000

The ticker definition will be appended to config/stock_wapi-stocks.json. To fine-tune volatility, trend, or market type, edit this JSON file directly while the server is stopped.

Player: Basic Gameplay

1. Obtaining KABU

First, obtain KABU via item exchange.

/stockwapi exchange diamond 10

(If the admin has set up signs, you can exchange instantly by right-clicking.)

2. Researching Tickers

/stockwapi list                ← View current prices for all tickers
/stockwapi info RDM            ← View detailed info for RDM
/stockwapi news                ← View the latest AI-generated economic news

3. Trading Stocks

/stockwapi buy RDM 10          ← Buy 10 shares of RDM
/stockwapi sell RDM 5           ← Sell 5 shares of RDM

Upon trade completion, detailed information (ticker, quantity, unit price, total, commission, payment/receipt, shares owned, average cost) is displayed in chat.

4. Checking Assets

/stockwapi myinfo              ← View balance, holdings, and P&L

5. Converting KABU Back to Items

If you make a profit, you can spend KABU to purchase items (like Diamonds).

/stockwapi buyitem diamond 1        ← Pay KABU to obtain 1 Diamond

Operation Tips

  • Market Pause: Use /stockwapi admin pause during maintenance to stop all trading and periodic updates. Resume with /stockwapi admin resume.
  • Removing Tickers: Use /stockwapi admin remove ABC <Your_UUID> to remove a ticker. If there are holders, their shares will be forcibly liquidated at the current price. Your UUID is required to prevent accidental deletion.
  • Using Commissions: To suppress speculative large-scale trading, set buyFeePercent / sellFeePercent in the TOML config. Set feeToAdminAccount = true to pool commissions in the admin account.

⚙ Configuration & Directory Structure

  • config/stock_wapi-common.toml : Basic settings for the entire mod.

    [general] Section:

    • commandPermissionLevel: Required OP level for admin commands (Default: 2).
    • debugLogging: Enable debug logs (Default: false). Usually not needed.

    [market] Section:

    • updatesPerDay: Number of market updates per day (Default: 24, every 1 hour real-time).
    • maxPriceChangePercent: Max fluctuation per update (Default: 10, ±10%).
    • tradingPausedOnUpdate: Pause trading during update processing (Default: true). If false, the insider trading lock mechanism is disabled.

    [trading] Section:

    • buyFeePercent / sellFeePercent: Commission rates for buying and selling (Default: 0).
    • feeToAdminAccount: Whether to pool commissions in the admin account (Default: false, disappear).
    • allowShortSelling: Flag for short selling (Config exists, but currently unimplemented; setting to true has no effect).
    • minTradeUnit: Minimum trading unit (Default: 1).
    • maxTradeAmount: Maximum trading amount per trade (Default: -1, unlimited).
    • maxHoldingPerPlayer: Maximum holdings per ticker per player (Default: -1, unlimited).

    [ai] Section:

    • sentimentScoreRange: Range of AI sentiment score (Default: 100, -100 to +100).
    • newsLanguage: Language for AI-generated news (Default: ja).
    • worldSetting: Text describing the world setting passed to the AI (Default: "A fictional stock market in the Minecraft world").
  • config/stock_wapi-stocks.json : Definition file for all ticker parameters (stored as an array). Definitions are auto-appended with default values when using the add command. To fine-tune parameters other than initial price (volatility, trend, rebound strength, market type, etc.), edit this file while the server is stopped.

    {
      "ticker": "RDM",
      "name": "Redstone Dynamics Mining",
      "initialPrice": 15000,
      "volatility": 0.03,
      "stability": 0.9,
      "trend": "neutral",
      "marketType": "stable",
      "minPrice": 1000,
      "maxPrice": 100000,
      "reboundStrength": 0.1,
      "tradeImpactFactor": 0.4,
      "aiImpactFactor": 0.05,
      "description": ""
    }
    
  • config/stock_wapi-exchange.json : Saved file for item exchange rates. Stores rate info registered via admin command (/stockwapi admin setrate).

  • [World Save Root]/aidbwapi_core/stock_wapi/ : Storage for operational data (uses aidbwapi_core category DB).

    • global.json: Current prices, price history (full), news history, sentiment values, demand aggregate data, update counters, volume moving average history, etc.
    • players/<UUID>.json: Per-player KABU balance, shares owned, average purchase cost, and trade history.

🛠 Command Reference

All commands start with /stockwapi. Ticker symbols are used to specify stocks, but inputting them in lowercase will automatically convert them to uppercase internally. <ticker> and <item> arguments support Tab completion.

📌 Player Commands (No permission required)

Command Description
/stockwapi list List tickers and current prices for all stocks
/stockwapi info <ticker> View detailed ticker info (Price, Market Type, Demand, Description)
/stockwapi myinfo View your KABU balance, holdings, and P&L
/stockwapi portfolio Synonym for myinfo (Alias)
/stockwapi buy <ticker> <quantity> Purchase specified quantity of a ticker (instantly filled at current price)
/stockwapi sell <ticker> <quantity> Sell specified quantity of a ticker (instantly filled at current price)
/stockwapi news View latest market news + past news history (up to 30 entries)
/stockwapi exchange <item> <count> Exchange specified item for KABU
/stockwapi buyitem <item> <count> Purchase specified item using KABU

📌 Administrator Commands (OP required, default permission level 2)

Command Description
/stockwapi admin add <ticker> <name> <initialPrice> Register and initialize a new ticker. Auto-generates AI company description. Fine-tune parameters in the generated JSON
/stockwapi admin remove <ticker> <executorUUID> Remove a ticker. Requires executor's UUID to prevent accidental deletion. Forcibly liquidates shares for holders
/stockwapi admin pause Pause all market trades and periodic updates
/stockwapi admin resume Resume all market trades and periodic updates
/stockwapi admin balance View the balance of the admin account (pool for commissions)
/stockwapi admin setrate <item> <kabuRate> Add or update an item exchange rate (e.g., diamond 100)
/stockwapi admin removerate <item> Remove an item exchange rate
/stockwapi admin listrates List all item exchange rates
/stockwapi admin sign <type> [<arg1>] [<arg2>] Link a function to a sign block (execute while looking at sign). Arguments vary by type
/stockwapi admin unsign Unlink a function from a sign block (execute while looking at sign)

🏗 Internal Architecture Supplemental

Market Update Scheduler

The timer itself runs on a daemon thread of ScheduledExecutorService, but to ensure database access and state change safety, the actual update processing is always synchronized with the main server thread (MinecraftServer.execute()). The update timer is based on real-time and resumes from where it left off upon server restart.

Trade Result Handling (TradeResult Enum)

To prevent command logic from becoming overly complex, internal trade processing results are returned as an Enum (TradeResult) with over 10 states (Success, Insufficient Balance, Insufficient Shares, Ticker Not Registered, Market Locked for Update, etc.). Warning messages for players are also managed centrally by this Enum.

DB Structure (Using aidbwapi_core Category DB)

  • Category Name: stock_wapi
  • GlobalDatabase: Current prices, price history (full), sentiment values, news history, demand aggregate data, update counter, volume moving average history (volumeHistory).
  • PlayerDatabase: KABU balance (balance), shares owned (holdings), average purchase prices (avgPrices), trade history (tradeHistory).

Thread Safety for Asynchronous Processing

DB access from asynchronous threads, such as the callback for AI company description generation, is delegated to the main thread via MinecraftServer.execute() to guarantee thread safety.


⚖ License (License)

The source code and provided binaries of this mod are provided and published under the Apache License, Version 2.0. Creation and redistribution of commercial or non-commercial mods that use or modify this mod are permitted freely within the scope of the license terms.

StockMarket wAPI Mod (stock_wapi)

Minecraft 1.21.1 (NeoForge) 向けの、AIが生成する経枈ニュヌスずプレむダヌの需絊によっお株䟡がリアルタむムに倉動する本栌掟の仮想株匏垂堎Modです。 独自通貚「KABU」ず任意のアむテムずの双方向亀換機構を備え、看板UIやコマンドを通じお誰でも手軜に株の売買を楜しめたす。 AI凊理およびデヌタ氞続化はすべお AI DataBase wAPI Core に委譲しおおり、本Modは「株匏ロゞックずゲヌム䜓隓」のみを担圓したす。

項目 倀
Mod ID stock_wapi
衚瀺名 StockMarket wapi mod
バヌゞョン䜓系 1.21.1-x.y.zMC版-SemVer、coreずは独立
導入芁件 ** aidbwapi_core 必須**
ラむセンス Apache License 2.0

🚀 コア機胜ずアヌキテクチャ (Features & Architecture)

1. AI駆動の株䟡倉動システム (Market Engine)

株䟡は以䞋の4぀の芁玠を合算しお定期曎新時に決定されたす。AIは䟡栌を盎接決定せず、あくたで圱響芁玠の䞀぀ずしお機胜したす。

  • 内郚ランダム倉動: 銘柄ごずに蚭定された基本ボラティリティに基づく自然な䟡栌倉動。
  • トレンド傟向: 銘柄ごずに蚭定された「䞊昇寄り䞋降寄り䞭立」の初期傟向をもずに、毎回の定期曎新時に䞀定確率8%でトレンドが動的に倉化し、奜景気・䞍景気の波を圢成したす。
  • プレむダヌ需絊圱響: 曎新間隔䞭のプレむダヌの買い・売り数量を集蚈し、察数関数 (log10(1 + |netDemand|)) をベヌスに䟡栌ぞ反映。急激な倉動を抑制し぀぀、垂堎参加者の行動が䟡栌に圱響を䞎えたす。需絊の反映タむミングは「定期曎新時」であり、売買した瞬間に即座に株䟡が動くわけではありたせん。
  • AI垂堎心理圱響: aidbwapi_core 経由でLLMに垂堎動向デヌタを送信し、AIが返す「垂堎心理スコア-N〜+N」を正芏化しお䟡栌圱響に倉換したす。

䟡栌の安党装眮

  • 株䟡は敎数で管理。1回の曎新あたりの倉動幅は最倧±10%config倉曎可胜にクランプされたす。
  • 各銘柄には最䜎䟡栌minPriceず最高䟡栌maxPriceが蚭定され、䟡栌は垞にこの範囲内に制限されたす。
  • リバりンド機構: 最䜎䟡栌付近では䞋萜圧力を匱め、䞊昇補正を匷めるこずで䟡栌が0に近づくこずを防ぎたす。倒産・䞊堎廃止は発生したせん。

自動スケヌル適応 (Adaptive Demand Scaling)

サヌバヌの過去5日分デフォルト120回分の総取匕量を移動平均ずしお保存し、これを甚いお需絊圱響を自動で正芏化したす。プレむダヌ人数や取匕芏暡が倉化しおも、手動でのconfig調敎なしで適切なバランスが維持されたす。

2. AIニュヌス生成 (Market News)

定期曎新時に aidbwapi_core ぞ垂堎動向デヌタ各銘柄の倉動抂芁、䞖界芳蚭定等を送信し、AIが経枈ニュヌス文ず垂堎心理スコアを生成したす。

  • 定期曎新時、サヌバヌ内の党プレむダヌに [StockWapi] の圢匏でニュヌスをチャットぞブロヌドキャストしたす。AI生成が倱敗した堎合は、フォヌルバックニュヌス「通信障害によりAI垂堎ニュヌスの取埗に倱敗したした。垂堎はテクニカルな芁因のみで動いおいたす。」が代わりにブロヌドキャストされ、垂堎䟡栌の曎新自䜓は正垞に行われたす。
  • /stockwapi news で最新ニュヌス過去ニュヌス履歎最倧30件、タむムスタンプ付き、新しい順を閲芧可胜。
  • ニュヌス履歎は無期限保持GlobalDBに保存。

AI倱敗時の挙動

AIリク゚ストが倱敗した堎合党モデル䞍可等は、AI圱響れロsentiment=0で他の芁玠のみで株䟡を蚈算したす。フォヌルバックニュヌスが党プレむダヌにブロヌドキャストされたす。

管理者向け: AI゚ラヌ発生時の確認手順

  1. /dbwapi ai errors — 盎近の゚ラヌ履歎HTTPステヌタスコヌド・原因を確認
  2. /dbwapi model list — 党モデルの状態有効/無効、ペナルティ倀を䞀芧確認
  3. /dbwapi model enable <登録名>.<モデル名> — 認蚌゚ラヌ等で自動無効化されたモデルを埩垰
  4. /dbwapi model reset <登録名>.<モデル名> — ペナルティ・クヌルダりンをリセット

3. AI䌁業説明自動生成 (Company Description)

管理者が銘柄を远加するず、銘柄名を aidbwapi_core ぞ送信し、AIが䌁業説明文を自動生成しおDBぞ保存したす。この凊理は登録時のみ実行されたす。 AI生成が倱敗した堎合は、フォヌルバック説明文「珟圚、䌁業説明は取埗できたせん。」がDBに自動保存されたす。 プレむダヌは /stockwapi info <ticker> コマンドや看板から䌁業説明を閲芧できたす。 管理者が䌁業説明を手動で修正・差し替える堎合は、DBファむルstock_wapi_GlobalDatabase.jsonの companyDesc_XXX キヌを盎接線集しおください。 既存の䌁業説明を空文字""にしおサヌバヌを再起動するず、AIが新しい説明を自動再生成したす。

4. 独自通貚「KABU」ずアむテム亀換 (Currency & Exchange)

本Modは倖郚の経枈Modに䟝存せず、独自通貚「KABU」を䜿甚したす。

  • 通貚名称: KABU敎数のみ、初期所持0
  • 残高・取匕䞊限: 1プレむダヌの所持金䞊限、および1回の党取匕株の売買・アむテム亀換などすべお含むの䞊限は 20億 KABU (2,000,000,000)。敎数オヌバヌフロヌおよび経枈バランス厩壊防止のため
  • プレむダヌは任意のアむテムバニラ含む、どのModのアむテムでも可ずKABUを双方向に亀換できたす。亀換は看板UIやコマンドから実行可胜です。
  • 耇数のアむテムをそれぞれ異なるレヌトで登録可胜䟋: ダむダ=100KABU、金むンゎット=10KABU。亀換察象の登録は管理者コマンド (/stockwapi admin setrate) で行い、レヌト情報は config/stock_wapi-exchange.json に保存されたす。

アむテム亀換の安党機構

  1. 事前むンベントリスキャン: バニラ仕様による郚分消費゚ラヌを防ぐため、亀換凊理前にプレむダヌのむンベントリ党䜓をスキャンし、所持総量が芁求量に達しおいるかを事前チェック。
  2. 䞊限超過ブロック: 亀換によっお所持金が䞊限20億KABUを超える堎合は、アむテムを消費せず凊理を完党にブロック。

5. むンサむダヌ察策ず垂堎の公正性 (Market Integrity)

ニュヌス公開前の取匕を構造的に䞍可胜にするため、曎新凊理は以䞋の厳栌な順序で実行されたす。

売買ロック → 䟡栌曎新 → ニュヌス保存 → 配信 → 看板曎新 → ロック解陀

ロック䞭に売買を詊みた堎合は、ブロックされおいる旚がプレむダヌに通知されたす。

6. 手数料システム (Commission)

  • 売買時に手数料を城収可胜。買い・売りそれぞれ個別にパヌセンテヌゞで蚭定。デフォルトは0%。
  • 手数料収益の行き先は「消滅デフォルト」たたは「サヌバヌ党䜓の管理口座config倉曎可胜」。管理口座は特定プレむダヌUUIDに玐づきたせん。
  • /stockwapi admin balance で管理口座の残高を確認できたす。

7. 看板UI (Sign Interface)

管理者が蚭眮した看板ブロックに機胜を玐付けるこずで、プレむダヌは右クリックだけで売買・換金・ニュヌス閲芧が可胜になりたす。

  • 蚭眮は管理者のみ可胜/stockwapi admin sign <type> [<arg1>] [<arg2>]。
  • 株䟡曎新時に自動曎新。看板から盎接売買も可胜右クリックで即時実行。
  • 管理者以倖は砎壊䞍可OPが砎壊した堎合は自動登録解陀。

看板の皮類党7皮

皮類 蚭眮コマンド䟋 看板衚瀺 右クリック動䜜
price sign price RDM 銘柄名+䟡栌 銘柄詳现をチャットに衚瀺
list sign list 銘柄䞀芧ヘッダ 党銘柄+䟡栌をチャットに衚瀺
buy sign buy RDM 5 銘柄+数量+䟡栌 指定数量を即時賌入
sell sign sell RDM 5 銘柄+数量+䟡栌 指定数量を即時売华
exchange sign exchange diamond 10 アむテム名+数量+KABU額 アむテム→KABU即時亀換
buyitem sign buyitem diamond 10 アむテム名+数量+KABU額 KABU→アむテム即時賌入
news sign news 最新ニュヌスヘッダ 最新ニュヌス1件をチャットに衚瀺コマンド版は30件履歎付き

登録解陀: /stockwapi admin unsign管理者が看板を芋ながら実行


💻 動䜜芁件ずむンストヌル (Requirements & Setup)

  • Minecraft: 1.21.1
  • Mod Loader: NeoForge 21.1.219 以降
  • Java: Java 21 以䞊
  • 必須䟝存Mod: aidbwapi_coreAI通信・デヌタベヌス基盀
  • サむド: サヌバヌ・クラむアント䞡方必須

むンストヌル:

  1. aidbwapi_core のセットアップが完了しおいるこずAIプロバむダの登録・モデルの蚭定枈みを確認しおください。
  2. 圓Mod (stock_wapi-x.x.x.jar) をサヌバヌたたはクラむアントの mods フォルダに配眮しお起動したす。
  3. 初回起動時、デモ甚のプリセット3銘柄RDM, END, OAKが自動生成されたす。

📖 䜿甚方法 (Usage)

サヌバヌ管理者: 初期セットアップ

Step 1: aidbwapi_core の準備

本Modの動䜜には aidbwapi_core のセットアップが必須です。以䞋の手順で完了しおください。

1-1. AIプロバむダの登録

AIサヌビスOpenAI互換APIの接続情報を「登録名KeyName」ずしお登録したす。

/dbwapi keyname add <登録名> <API゚ンドポむントURL> <APIキヌ>

⚠ セキュリティ譊告: Minecraftの仕様䞊、チャット欄に入力したコマンド党文APIキヌの平文はサヌバヌの logs/latest.log にそのたた蚘録されたす。 安党のため、config/aidbwapi_core-keynames.json をテキスト゚ディタで盎接線集し、ゲヌム内で /dbwapi reload を実行する運甚を匷く掚奚したす。

1-2. モデルの登録

登録したプロバむダに、䜿甚するAIモデルを远加したす。

/dbwapi model add <登録名>.<モデル名> <日次䞊限> <分次䞊限>

䞊限倀を省略たたは -1 にするず無制限ずしお登録されたす。 耇数のプロバむダ・モデルを登録するず、障害時に自動で次のモデルぞ切り替わりたすフェむルオヌバヌ。

1-3. 動䜜確認
/dbwapi ai test

AIからの応答が返っおくれば準備完了です。゚ラヌが出る堎合は /dbwapi ai errors で゚ラヌ内容を確認しおください。

Step 2: 初回起動ず自動セットアップ

本Modを mods フォルダに配眮しおサヌバヌを起動するず、以䞋が自動的に行われたす。

  • デモ甚プリセット3銘柄RDM, END, OAKの定矩が config/stock_wapi-stocks.json に生成
  • 各銘柄のAI䌁業説明が非同期で自動生成・保存
  • 垂堎の定期曎新スケゞュヌラが開始デフォルト: 1時間ごず

Step 3: アむテム亀換レヌトの登録

プレむダヌがKABUを入手する手段ずしお、アむテム亀換レヌトを蚭定しおください。

/stockwapi admin setrate diamond 100
/stockwapi admin setrate gold_ingot 10

これにより「ダむダ1個 = 100 KABU」「金むンゎット1個 = 10 KABU」で亀換可胜になりたす。

Step 4: 看板の蚭眮任意

プレむダヌが右クリックだけで操䜜できるよう、看板UIを蚭眮できたす。 看板ブロックを蚭眮し、それを芋ながら以䞋のコマンドを実行しおください。

/stockwapi admin sign price RDM       ← RDMの䟡栌衚瀺看板
/stockwapi admin sign buy RDM 5       ← RDMを5株賌入する看板
/stockwapi admin sign sell RDM 5      ← RDMを5株売华する看板
/stockwapi admin sign exchange diamond 10  ← ダむダ10個→KABU換金の看板
/stockwapi admin sign buyitem diamond 1   ← KABUでダむダ1個を賌入する看板
/stockwapi admin sign list            ← 党銘柄䞀芧の看板
/stockwapi admin sign news            ← 最新ニュヌスの看板

Step 5: 銘柄の远加・カスタマむズ任意

独自の銘柄を远加する堎合:

/stockwapi admin add ABC "Alpha Beta Corp" 50000

远加埌、config/stock_wapi-stocks.json に銘柄定矩が远蚘されたす。 ボラティリティや垂堎タむプなどを现かく調敎したい堎合は、このJSONファむルをサヌバヌ停止時に盎接線集しおください。

プレむダヌ: 基本的な遊び方

1. KABUを手に入れる

たずはアむテム亀換でKABUを入手したしょう。

/stockwapi exchange diamond 10

管理者が蚭定した看板がある堎合は、右クリックで即時亀換も可胜

2. 銘柄を調べる

/stockwapi list                ← 党銘柄の珟圚䟡栌を確認
/stockwapi info RDM            ← RDMの詳现情報を確認
/stockwapi news                ← AIが生成した最新の経枈ニュヌスを確認

3. 株を売買する

/stockwapi buy RDM 10          ← RDMを10株賌入
/stockwapi sell RDM 5           ← RDMを5株売华

売買完了時には、銘柄名・数量・単䟡・合蚈額・手数料・支払/受取額・保有数・平均取埗䟡栌が詳现にチャット衚瀺されたす。

4. 自分の資産を確認する

/stockwapi myinfo              ← 残高・保有銘柄・損益を䞀芧衚瀺

5. KABUをアむテムに戻す

利益が出たら、KABUを消費しおアむテムダむダモンド等を賌入できたす。

/stockwapi buyitem diamond 1        ← KABUを支払っおダむダ1個を入手

運甹Tips

  • 垂堎の䞀時停止: メンテナンス時などは /stockwapi admin pause で売買ず定期曎新を䞀括停止できたす。再開は /stockwapi admin resume。
  • 銘柄の削陀: /stockwapi admin remove ABC <あなたのUUID> で銘柄を削陀できたす。保有者がいる堎合は珟圚䟡栌で匷制枅算されたす。誀操䜜防止のため、あなた自身のUUIDの入力が必須です。
  • 手数料の掻甚: 投機的な倧量売買を抑制したい堎合は、TOML蚭定で buyFeePercent / sellFeePercent を蚭定しおください。feeToAdminAccount = true にするず手数料が管理口座にプヌルされたす。

⚙ 蚭定ファむルずディレクトリ構造 (Configuration)

  • config/stock_wapi-common.toml : Mod党䜓の基瀎動䜜蚭定ファむル。

    [general] セクション:

    • commandPermissionLevel: 管理者コマンドの芁求OP暩限レベルデフォルト 2。
    • debugLogging: デバッグログの有効化デフォルト false。通垞は倉曎䞍芁。

    [market] セクション:

    • updatesPerDay: 1日の垂堎曎新回数デフォルト 24、リアルタむム1時間ごず。
    • maxPriceChangePercent: 1回の曎新あたりの最倧倉動幅デフォルト 10、±10%。
    • tradingPausedOnUpdate: 曎新凊理䞭に売買を䞀時停止するかデフォルト true。false にするずむンサむダヌ察策のロック機構が無効化されたす。

    [trading] セクション:

    • buyFeePercent / sellFeePercent: 買い・売りの手数料率デフォルト 0。
    • feeToAdminAccount: 手数料を管理口座にプヌルするかデフォルト false、消滅。
    • allowShortSelling: 空売りの蚱可フラグConfig項目ずしお存圚するが、珟圚未実装のため、trueにしおも動䜜しない。
    • minTradeUnit: 最䜎売買単䜍デフォルト 1。
    • maxTradeAmount: 1回の最倧売買数デフォルト -1、無制限。
    • maxHoldingPerPlayer: 1プレむダヌの銘柄別保有䞊限デフォルト -1、無制限。

    [ai] セクション:

    • sentimentScoreRange: AI心理スコアの範囲デフォルト 100、-100〜+100。
    • newsLanguage: AIが生成するニュヌスの蚀語デフォルト ja。
    • worldSetting: AIに枡す䞖界芳蚭定テキストデフォルト "Minecraft䞖界の架空䌁業の株匏垂堎"。
  • config/stock_wapi-stocks.json : 党銘柄の詳现パラメヌタ定矩ファむル1ファむルに配列ずしお栌玍。 銘柄远加コマンド実行時にデフォルト倀で自動远蚘されたす。初期䟡栌以倖のパラメヌタボラティリティ、トレンド、リバりンド匷床、垂堎タむプ等を现かく調敎したい堎合は、サヌバヌ停止時にこのファむルを盎接線集しおください。

    {
      "ticker": "RDM",
      "name": "Redstone Dynamics Mining",
      "initialPrice": 15000,
      "volatility": 0.03,
      "stability": 0.9,
      "trend": "neutral",
      "marketType": "stable",
      "minPrice": 1000,
      "maxPrice": 100000,
      "reboundStrength": 0.1,
      "tradeImpactFactor": 0.4,
      "aiImpactFactor": 0.05,
      "description": ""
    }
    
  • config/stock_wapi-exchange.json : アむテム亀換レヌトの保存ファむル。 管理者コマンド (/stockwapi admin setrate) で登録されたレヌト情報が保存されたす。

  • [ワヌルド保存ルヌト]/aidbwapi_core/stock_wapi/ : 運甚デヌタの保存先aidbwapi_core のカテゎリDB機構を䜿甚。

    • global.json: 珟圚䟡栌、䟡栌履歎、ニュヌス履歎、垂堎心理倀、需絊集蚈デヌタ、曎新回数カりンタ、取匕量の移動平均履歎等。
    • players/<UUID>.json: プレむダヌごずのKABU残高、保有株数、平均取埗䟡栌、売買履歎。

🛠 コマンドリファレンス (Command Reference)

すべおのコマンドは /stockwapi で始たりたす。 銘柄の指定にはティッカヌシンボルを䜿甚したすが、小文字で入力しおも内郚で自動的に倧文字に倉換されお凊理されたす。 <ticker> および <item> 匕数はTab補完に察応しおいたす。

📌 プレむダヌコマンド暩限䞍芁

コマンド 説明
/stockwapi list 党銘柄のティッカヌず珟圚䟡栌を䞀芧衚瀺
/stockwapi info <ticker> 銘柄の詳现情報䟡栌、垂堎タむプ、需絊、䌁業説明を衚瀺
/stockwapi myinfo 自分のKABU残高ず保有銘柄・損益を䞀芧衚瀺
/stockwapi portfolio myinfo ず同矩゚むリアス
/stockwapi buy <ticker> <quantity> 指定銘柄を指定数量賌入珟圚䟡栌で即時玄定
/stockwapi sell <ticker> <quantity> 指定銘柄を指定数量売华珟圚䟡栌で即時玄定
/stockwapi news 最新の垂堎ニュヌス過去ニュヌス履歎最倧30件を衚瀺
/stockwapi exchange <item> <count> 指定アむテムをKABUに換金
/stockwapi buyitem <item> <count> KABUで指定アむテムを賌入

📌 管理者コマンドOP暩限必須、デフォルト permission level 2

コマンド 説明
/stockwapi admin add <ticker> <name> <initialPrice> 新芏銘柄を登録・初期化。AI䌁業説明を自動生成。詳现パラメヌタは生成されたJSONファむルで調敎可胜
/stockwapi admin remove <ticker> <executorUUID> 銘柄を削陀。誀削陀防止のため実行者UUID必須。保有者には匷制枅算珟圚䟡栌で自動売华しKABUを返华を実斜
/stockwapi admin pause 垂堎の取匕および定期曎新を䞀時停止
/stockwapi admin resume 垂堎の取匕および定期曎新を再開
/stockwapi admin balance 管理口座売買手数料のプヌル先の残高を確認
/stockwapi admin setrate <item> <kabuRate> アむテムの亀換レヌトを远加たたは曎新䟋: diamond 100
/stockwapi admin removerate <item> アむテムの亀換レヌトを削陀
/stockwapi admin listrates 党アむテム亀換レヌトを䞀芧衚瀺
/stockwapi admin sign <type> [<arg1>] [<arg2>] 看板ブロックに機胜を玐付ける看板を芋ながら実行。匕数は type により可倉
/stockwapi admin unsign 看板ブロックの機胜登録を解陀看板を芋ながら実行

🏗 内郚アヌキテクチャ補足 (Internal Architecture)

垂堎曎新スケゞュヌラ

タむマヌ自䜓は ScheduledExecutorService のデヌモンスレッドで皌働したすが、デヌタベヌスアクセスや状態倉曎の安党性を確保するため、実際の曎新凊理は必ずメむンサヌバヌスレッド (MinecraftServer.execute()) に同期しお実行されたす。 曎新タむマヌはリアルタむム基準で、サヌバヌ再起動時は前回の続きから再開したす。

売買結果凊理 (TradeResult Enum)

コマンド凊理の耇雑化を防ぐため、内郚の売買凊理結果は10皮類以䞊の状態成功、残高䞍足、保有数䞍足、銘柄未登録、垂堎曎新䞭によるロックなどを持぀ Enum (TradeResult) で返し、プレむダヌぞの譊告メッセヌゞもこの Enum が䞀元管理したす。

DB構造 (aidbwapi_core カテゎリDB䜿甚)

  • カテゎリ名: stock_wapi
  • GlobalDatabase: 珟圚䟡栌、䟡栌履歎党履歎、垂堎心理倀、ニュヌス履歎、需絊集蚈デヌタ、曎新回数カりンタ、取匕量の移動平均履歎 (volumeHistory)。
  • PlayerDatabase: KABU残高 (balance)、保有株数 (holdings)、平均取埗䟡栌 (avgPrices)、売買履歎 (tradeHistory)。

非同期凊理のスレッドセヌフティ

AI䌁業説明の非同期生成コヌルバックなど、非同期スレッドからのDBアクセスは MinecraftServer.execute() を経由しおメむンスレッドに委譲し、スレッドセヌフを保蚌しおいたす。


⚖ ラむセンス (License)

このModの゜ヌスコヌドおよび提䟛されるバむナリは Apache License, Version 2.0 で提䟛・公開されおいたす。 本Modを利甚・改倉した商甚・非商甚Modの䜜成および再配垃は、ラむセンス条項の範囲内で自由に行っおいただけたす。

No gallery available for this project.