Files
wibosim/server/public/js/possizeui.js
T
db9979andClaude Opus 5.5 ee613a2ce3 Handel: Absichern mit einem Klick, Positionsgrößen-Rechner, eigene Trades im Chart, Kursalarme in Prozent
- Depot: Knopf Absichern/Stop ändern je Position (Long/Short, Haupt-, Battle-, Fondsdepot), 5/10/15 %, optional Trailing, Klartext mit Auslösekurs und Ergebnis ab Einstand
- Orderticket: aufklappbarer Positionsgrößen-Rechner (Risiko in % oder €, Stop-Abstand aus Auslöser), Gebühren und Kaufkraft/Short-Kapazität berücksichtigt
- Kurschart: eigene Käufe/Verkäufe als Dreiecke, aktive Stops/Limits/Take-Profit als Linien mit Tooltip, abschaltbar, Textalternative; neue Leseaktion myTrades
- Kursalarme: seit Kauf (±X % zum Einstand, einmalig) und Tagesbewegung (einmal je Tag), Meldung über die zentrale Hinweis-Prüfung

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018i4GUhQVoPUusUzxgxLWkK
2026-12-05 09:20:21 +00:00

73 lines
5.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Positionsgrößen-Rechner im Orderticket (Anzeige). Die Rechnung steht in possize.js, die Werte des Tickets
// (Kurs, Seite, Depot, Auslöser) liefert trade.js. Aufklappbar, auch im Einsteiger-Modus sichtbar.
import { positionSize, capText } from './possize.js';
import { $, num, int, eur, frac, patch, setText, store } from './util.js';
const saved = store.get('trdPsRisk', null);
let riskVal = saved && saved.v > 0 ? saved.v : 1;
let riskUnit = saved?.unit === 'eur' ? 'eur' : 'pct';
let last = null; // letztes Ergebnis (für „Übernehmen“)
const parse = (x) => { const raw = String(x ?? '').trim().replace(/\s/g, '').replace(',', '.'); const n = Number(raw); return raw !== '' && Number.isFinite(n) ? n : null; };
const dec = (x, d = 2) => String(Math.round(x * 10 ** d) / 10 ** d).replace('.', ',');
export function psHtml() {
return `<details id="psCalc" class="ps-calc"><summary>Positionsgröße berechnen <small class="muted">– wie viel Risiko?</small></summary>
<div class="ps-body">
<p class="small muted ps-intro">Lege fest, wie viel du höchstens verlieren willst, falls dein Stop greift. Der Rechner schlägt die Stückzahl vor – Gebühren für Kauf und Verkauf sind grob eingerechnet.</p>
<div class="row2">
<div class="field"><label for="psRisk">Höchstens verlieren</label>
<span class="ps-in"><input id="psRisk" type="text" inputmode="decimal" autocomplete="off" value="${dec(riskVal)}">
<select id="psUnit" aria-label="Einheit des Risikos"><option value="pct"${riskUnit === 'pct' ? ' selected' : ''}>% Depot</option><option value="eur"${riskUnit === 'eur' ? ' selected' : ''}>Euro</option></select></span></div>
<div class="field"><label for="psStop">Stop-Abstand (%)</label>
<input id="psStop" type="text" inputmode="decimal" autocomplete="off" aria-describedby="psStopSrc"><small class="muted ps-src" id="psStopSrc"></small></div>
</div>
<div class="ps-out" id="psOut" aria-live="polite"></div>
<button type="button" class="btn small" id="psApply" data-ps="apply" disabled>Stückzahl übernehmen</button>
</div></details>`;
}
/** Eingaben im Rechner: Risiko merken, eigener Stop-Abstand hat Vorrang vor dem Auslöser */
export function psInput(target) {
if (target.id === 'psRisk' || target.id === 'psUnit') {
const v = parse($('#psRisk')?.value);
riskUnit = $('#psUnit')?.value === 'eur' ? 'eur' : 'pct';
if (v > 0) { riskVal = v; store.set('trdPsRisk', { v: riskVal, unit: riskUnit }); }
}
if (target.id === 'psStop') target._own = String(target.value).trim() !== '';
}
/**
* Anzeige aktualisieren (nur wenn aufgeklappt).
* @param {{price, side, equity, available, shortCapacity, pos, noShort, fees, maxQty, auto: {pct, src}|null}} ctx
*/
export function psUpdate(ctx) {
const box = $('#psCalc');
if (!box?.open) return;
const se = $('#psStop');
if (!se._own && document.activeElement !== se) se.value = ctx.auto?.pct > 0 ? dec(ctx.auto.pct) : se.value || '5';
setText($('#psStopSrc'), se._own ? 'eigene Eingabe' : ctx.auto?.pct > 0 ? `aus ${ctx.auto.src}` : 'Vorschlag – oder eigenen Wert eintragen');
const stopPct = parse(se.value);
const riskIn = parse($('#psRisk').value);
const isPct = $('#psUnit').value !== 'eur';
const r = positionSize({ price: ctx.price, stopPct, side: ctx.side, equity: ctx.equity, riskPct: isPct ? riskIn : null, riskEur: isPct ? null : riskIn,
available: ctx.available, shortCapacity: ctx.shortCapacity, pos: ctx.pos, noShort: ctx.noShort, fees: ctx.fees, maxQty: ctx.maxQty });
last = r;
$('#psApply').disabled = !r.ok;
if (!r.ok) {
patch($('#psOut'), `<p class="small ${r.why === 'Risiko fehlt' || r.why === 'Stop-Abstand fehlt' ? 'muted' : 'warn'}">${r.why === 'Risiko fehlt' ? 'Bitte ein Risiko eintragen.' : r.why === 'Stop-Abstand fehlt' ? 'Bitte einen Stop-Abstand eintragen.' : r.why === 'Kein Kurs' ? 'Für diesen Wert gibt es noch keinen Kurs.' : `Kein Vorschlag: ${r.why}.`}</p>`);
return;
}
const buy = ctx.side !== 'sell';
const share = ctx.equity > 0 ? r.notional / ctx.equity : null;
patch($('#psOut'), `<dl class="ps-rows">
<div><dt>Vorschlag</dt><dd><b class="num">${int(r.qty)} Stück</b>${r.capped ? ` <small class="warn">${capText(r.capped)}</small>` : ''}</dd></div>
<div><dt>Kurswert</dt><dd><span class="num">${eur(r.notional)}</span>${share !== null ? ` <small class="muted">(${frac(share, 0)} vom Depot)</small>` : ''}</dd></div>
<div><dt>Stop bei ca.</dt><dd><span class="num">${num(r.stopPrice)} €</span> <small class="muted">(${buy ? '−' : '+'}${dec(stopPct, 1)} %)</small></dd></div>
<div><dt>Verlust beim Stop</dt><dd><span class="num">ca. ${eur(r.risk)}</span> <small class="muted">inkl. Gebühren · Budget ${eur(r.budget)}</small></dd></div>
</dl>${buy ? '' : '<p class="small muted">Verkauf ohne Bestand ist ein Leerverkauf – der Stop liegt dann über dem Kurs.</p>'}`);
}
/** vorgeschlagene Stückzahl (oder null) */
export function psApply() { return last?.ok ? last.qty : null; }