// Ausführungsmeldung (fill): enthält den Bestand vor der Ausführung, damit der Client // „gekauft“, „verkauft“, „leer verkauft“ und „eingedeckt“ unterscheiden kann. import { test } from 'node:test'; import assert from 'node:assert/strict'; import os from 'node:os'; import fs from 'node:fs'; import path from 'node:path'; process.env.NODE_ENV = 'test'; process.env.TIME_MODE = 'turbo'; process.env.DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), 'wibosim-fill-')); const { settings } = await import('./settings.js'); const { Store } = await import('./store.js'); const { Game } = await import('./game.js'); Object.assign(settings.game, { dayMs: 60_000, tickMs: 1000, staticCorridor: 0.5, dynamicCorridor: 0.3, marketHaltPct: 0.5, recallsEnabled: false }); settings.news.enabled = false; test('Ausführungsmeldung nennt den Bestand vor der Ausführung', async () => { const clock = { t: Date.now() }; const g = new Game({ store: new Store(fs.mkdtempSync(path.join(os.tmpdir(), 'wibosim-fl-'))), now: () => clock.t }); const a = (await g.register({ name: 'Fuellerin', password: 'geheim123' })).player; for (let i = 0; i < 400 && g.market.phase !== 'continuous'; i++) { clock.t += 1000; g.tick(); } assert.equal(g.market.phase, 'continuous'); const fills = []; g.sendTo = (id, m) => { if (m.type === 'fill' && id === a.id) fills.push(m); }; const sym = 'RHBK'; g.placeOrder(a, { symbol: sym, side: 'buy', type: 'market', qty: 10 }); assert.ok(fills.length >= 1); assert.equal(fills[0].before, 0); assert.equal(fills[0].side, 'buy'); fills.length = 0; g.placeOrder(a, { symbol: sym, side: 'sell', type: 'market', qty: 10 }); assert.equal(fills[0].before, 10); // gewöhnlicher Verkauf fills.length = 0; g.placeOrder(a, { symbol: sym, side: 'sell', type: 'market', qty: 5 }); assert.equal(fills[0].before, 0); // Leerverkauf assert.equal(a.positions[sym].qty, -5); fills.length = 0; g.placeOrder(a, { symbol: sym, side: 'buy', type: 'market', qty: 5 }); assert.equal(fills[0].before, -5); // Eindecken });