# WiBoSim – Schnittstellen (Stand Sprint A–E) Alle Texte sind deutsch. Beträge in Euro, Prozentwerte als Zahl in Prozent (z. B. `returnPct: 3.2`), sofern nicht anders angegeben; Anteile (`marginUsage`, `util`, Gebühren) als Bruch (0–1). Zeitstempel in Millisekunden (Unix). ## REST | Methode & Pfad | Auth | Body / Antwort | |---|---|---| | `POST /api/register` | – | `{name, password (≥ 8), email?}` → `{token, profile}` (5 je Stunde und IP) | | `POST /api/login` | – | `{name, password}` → `{token, profile}`; nach 10 Fehlversuchen 15 Min. Sperre | | `POST /api/logout` | Bearer | beendet die Sitzung | | `PUT /api/me` | Bearer | `{email?, notify?: {battle, season, achievements, margin, morning, daily}, novice?, password?, oldPassword?}` → `{profile, token}` (neues `token` nur bei Passwortwechsel, alle anderen Sitzungen sind dann abgemeldet) | | `GET /api/info` | – | `{sectors, achievements, battleModes, timeModes, violations, motd, startCash, mailEnabled, fees: {taker, maker, fixed}}` | | `GET /api/market` | – | Marktansicht (siehe `market`) | | `GET /api/news`, `GET /api/events` | – | Listen | | `POST /api/action/:name` | optional | jede WebSocket-Aktion (siehe unten) per REST, Body = Nachricht ohne `type` | | `GET /api/health` | – | `{ok, lastTickAt, players, online, day, season, phase, timeMode}` – 503, wenn der Spieltakt hängt | | `GET /metrics` | – | Prometheus-Text | | `GET /api/admin/overview` | Admin | `{players[], online, season, day, phase, macro, cases[], symbols[], mailEnabled, sectors, uptime, memoryMb, backups[], comments[], tickMs}` | | `GET /api/admin/settings` | Admin | `{values: {game, news, smtp}, schema: {section: {key: {group, label, unit, min, max, enum, type, secret, default}}}, presets}` | | `PUT /api/admin/settings` | Admin | `{game?: {...}, news?: {...}, smtp?: {...}}` → wie GET + `changed: ['game.tickMs', …]`; Fehler als `{error}` | | `GET /api/admin/audit` | Admin | `[{ts, actor, action, detail}]` | | `POST /api/admin/action` | Admin | `{action, id?, value?}` → `{ok, detail}` (Aktionen siehe unten) | | `POST /api/admin/testmail` | Admin | `{to?}` | Authentifizierung: Header `Authorization: Bearer `. Tokens gelten 30 Tage (gleitend). **Admin-Aktionen:** `reset`, `ban`, `unban`, `admin` (value: bool), `cash` (value: Betrag, auch negativ), `clearCompliance`, `mute` (value: Minuten), `unmute`, `delete`, `deleteComment` (value: Kommentar-ID), `endSeason`, `centralBank` (Zinsentscheid jetzt), `nextBill` (Abstimmung jetzt beenden), `earnings` (value: Symbol, Zahlen zum nächsten Handelstag), `news` (value: `{title, sentiment −1…1, sectors[]}`), `broadcast` (value: Text), `backup`. Am eigenen Konto sind `ban`, `delete`, `admin` gesperrt. ## WebSocket `/ws` Nachrichten sind JSON-Objekte mit `type` (≤ 30 Zeichen) und optional `reqId`. Max. 16 KB je Nachricht, Burst 40 / dauerhaft 15 Nachrichten je Sekunde. Antwort auf jede Anfrage: `{type: 'reply', reqId, ok, ...daten}` bzw. `{type:'reply', reqId, ok:false, error}`. ### Client → Server | type | Felder | Antwortdaten | |---|---|---| | `auth` | `token` | `{profile, portfolio, battlePortfolio, battle, parliament, battles, quests, inbox}` | | `logout` | – | – | | `subscribe` | `symbol` | `{symbol, candles, depth, tape}`; danach kommen `book`-Nachrichten für dieses Symbol | | `spectate` | `battleId` (oder null zum Beenden) | `{battle}`; danach `spectate`-Nachrichten (nur angemeldet) | | `order` | `symbol, side ('buy'/'sell'), orderType ('limit','market','stop','stoplimit','takeprofit','trailing'), qty, price? (Limit), trigger? (Stop/TP/Stop-Limit), trailPct? (Trailing, in %), tif? ('day','gtc','gtd','ioc','fok'), expireAt? ('YYYY-MM-DD' bei gtd), peak? (Iceberg), bracket? {stopTrigger \| trailPct, tpTrigger}, oco? {trigger}, account? ('main'/'battle')` | `{order}` | | `cancel` | `orderId` (Zahl oder `c…` für bedingte Orders) | – | | `cancelAll` | `account?` | – | | `portfolio` | – | `{portfolio, battlePortfolio, battle}` | | `journal` | – | `{journal: {rows[], stats}}` | | `company` | `symbol` | `{company}` | | `candles` | `symbol` | `{candles}` | | `calendar` | – | `{calendar: {items[], day, reportingSeason, now}}` | | `briefing` | – | `{briefing}` | | `leaderboard` | – | `{leaderboard}` | | `regulator` | – | `{cases[], violations}` | | `parliament` | – | `{parliament}` | | `vote` | `billId, yes` | `{parliament}` | | `battles` | – | `{battles}` | | `challenge` | `opponent (Name), durationMin, mode` | `{invite}` | | `respond` | `inviteId, accept` | `{battles}` | | `rematch` | `battleId` | `{battles}` | | `queue` | `mode, durationMin, bot?` (bot: sofort gegen Index-Bot) | `{battles}` | | `queueLeave` | – | `{battles}` | | `liveBattles` | – | `{live[]}` | | `quests` | – | `{quests}` | | `league` | – | `{league}` | | `inbox` | – | `{inbox: {items[], unread}}` | | `read` | `ids` (Array) oder weglassen = alle | `{inbox}` | | `profile` | `name` | `{profile}` (öffentlich) | | `friends` / `follow` / `unfollow` | `name` (bei follow/unfollow) | `{friends[]}` | | `comments` | `target` (`stock:NVLT` oder `bill:`) | `{comments[]}` | | `comment` | `target, text (≤ 280)` | `{comment}` | | `me` | – | `{profile}` | | `claimAdmin` | `code` | `{profile}` | ### Server → Client | type | Inhalt | |---|---| | `hello` | `{market, news[], events[], parliament, leaderboard, motd, sectors, battleModes, achievements}` | | `market` | jede Taktung: `{market, trades[]}` | | `book` | `{symbol, depth: {bids[{price,qty,count}], asks[]}, tape[], candle, indicative, status}` | | `portfolio` | `{portfolio, battlePortfolio, battle}` bei Änderungen bzw. alle 3 Takte | | `leaderboard` | alle 5 Takte | | `phase` | `{phase}` (Phasenwechsel) | | `news`, `event` | einzelne Meldung | | `parliament` | `{parliament}` | | `inbox` | `{item, unread}` – neue Benachrichtigung | | `fill` | `{side, symbol, qty, price, account, realized, auction, maker, fee}` | | `dividend` | `{symbol, amount}` | | `condTriggered` | `{text, order?}` | | `marginWarning` / `marginCall` | `{usage}` / `{text}` | | `regulator` | `{case, text}` | | `achievement` | `{achievement: {id, icon, title, desc}}` | | `levelUp` | `{level}` | | `quest` | `{quest}` – erledigt | | `battleInvite`, `battleDeclined`, `battle`, `battleEnd`, `spectate` | Battle-Ereignisse | | `comment`, `commentDeleted` | neue/gelöschte Kommentare | | `season`, `seasonRecap` | Saisonwechsel, persönlicher Rückblick `{recap}` | | `announcement` | `{text}` | | `kicked` | `{text}` – Verbindung wird getrennt (gesperrt/gelöscht) | | `error` | `{error}` (z. B. Ratenbegrenzung) | ## Datenstrukturen (Auszug) **market**: `{day, phase ('closed'|'preopen'|'opening'|'continuous'|'closing'), label, endsAt, randomEnd, openAt, closeAt, nextPreOpen, date, timeMode, turbo, timezone, serverTime, index: {value, change}, tickers[], macro, marketHaltLevel, season: {n, endsAt}, reportingSeason}` **ticker**: `{symbol, name, sector, last, prevClose, open, change, high, low, volume, bid, ask, mcap, vol, pe, divYield, status ('continuous'|'vola'|'call'|'closed'), volaEndsAt, indicative: {price, volume, surplus}|null, htb, borrowRate, earningsIn, exDivIn}` **macro**: `{rate, inflation, gdp, unemployment, consensus, surprise, releasedAt, sentiment, sectorMood, cb: {probs: {'-0.25': 0.2, '0': 0.7, …}, mean, day, hint}, cbAt, lastDecision, history[], targets}` **portfolio**: `{accountId, kind ('main'|'battle'), rules, cash, available, equity, startCash, returnPct, realized, fees, trades, dayPnL, dayPnLPct, longValue, shortValue, shortCapacity, marginUsage, locked, recalls[{symbol, targetShort, deadline}], borrowAccrued, positions[{symbol, qty, avgCost, last, value, pnl, pnlPct, dayChange, short, borrowRate}], orders[{id, symbol, side, type, price, qty, filled, ts, status ('open'|'partial'|'queued'), tif, expireAt, peak, bracket}], cond[{id, symbol, side, type, label, qty, trigger, limit, trailPct, status ('conditional'|'pending'), oco, parent}], compliance, rank: {rank, of}|null, minTradesRanked}` **profile (eigenes)**: `{id, name, email, notify, isAdmin, elo, battleStats, achievements[], allAchievements[], joined, seasonsPlayed, bestReturn, compliance, xp, level, tier, league, novice, unread, recap, mutedUntil, adminSetupOpen}` **company**: Stammdaten, `last, prevClose, mcap, vol, growth, epsTTM, pe, sectorPe, payout, lastDividend, divYield, pendingDividend, exDivIn, consensus, earningsIn, quarters[], analysts {buy, hold, sell, target, low, high, ratings[]}, policy[], holders[], shortInterest, lending {pool, used, util, rate, hardToBorrow, recalled}, flowPrev {day, bots: {mm|noise|momentum|value|panic|inst: {name, desc, qty, pct}}, players}, status, volaEndsAt, indicative, lastAuction, news[], dailyBars[{day, ts, o, h, l, c, v}]` – **kein** Fundamentalwert. **parliament**: `{id, bill {id, title, effects, macro, axis}, endsAt, secretFrom, secret, yes, no (null in der verdeckten Phase), voters, quorum, weight, baseline, probability, register[{name, pct, yes}], myVote, myConflict, sectors, source, inForceDays, laws[], history[]}` **battles**: `{active, account, invites[], history[], queue, modes, durations}` **quests**: `{daily[{id, kind, n, xp, text, progress, done}], weekly[...], xp, level, levelFrom, levelTo}` **league**: `{tier, tierIndex, group, tiers[], size, promote, relegate, table[{pos, name, returnPct, trades, me, level}]}` **leaderboard**: `{season, minTrades, equity[], unranked, day[], week[], sharpe[], elo[], hallOfFame[]}` **calendar.items**: `{ts, dayIn?, kind ('earnings'|'exdiv'|'macro'|'cb'|'bill'|'law'|'auction'|'season'), symbol?, title, detail?}` **briefing**: `{phase, phaseText, news[], today[], holdings[{symbol, qty, last, prevClose, indicative, change}], macro, parliament, index, reportingSeason}` **recap**: `{season, returnPct, equity, rank, of, percentile, trades, bestTrade, worstTrade, winRate, sharpe, tier, newTier, leagueChange, xp, level}`