Phase 4.2 / 0.2: realistischer Demo-Modus (Exit-Slippage + Fees)
- DemoModel (pure, getestet): ExitFillPrice (Signalpreis minus halber Spread, geclamped) + CloseWithFees (Erlös zum Fill-Preis minus Round-Trip-Fee). - CopyTradingEngine Demo-Close nutzt es: ExitPrice = realistischer Fill statt Signalpreis, RealizedPnl netto nach Fees, ClosedTrade.TotalFees befuellt. -> Demo-PnL ist nicht mehr systematisch geschoent (Master-Validierung brauchbar). - DemoModelTests (Fill-Clamping, Round-Trip-Fee, 0-Fee). 207 Tests gruen. Build/Smoke gruen. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
b259f310d3
commit
54ed1a414e
@@ -633,8 +633,14 @@ namespace PolyTraderSharp.Services
|
||||
{
|
||||
_positionRepo.DeleteDemo(account.AccountId, signal.TokenId);
|
||||
|
||||
decimal exitUsd = TradeMath.ExitValue(openPos.Size, signal.Price);
|
||||
decimal realizedPnl = TradeMath.RealizedPnl(openPos.Size, signal.Price, openPos.AmountUsd);
|
||||
// Phase 4.2: realistischer Demo-Close (Exit-Slippage + Fees), statt zum
|
||||
// Signalpreis ohne Kosten – sonst ist Demo als Master-Validierung wertlos.
|
||||
int demoFeeBps = _state.MarketCache.TryGetValue(signal.TokenId, out var demoMd)
|
||||
? (demoMd.TakerFeeBps > 0 ? demoMd.TakerFeeBps : FeeModel.FallbackBps(demoMd.Category))
|
||||
: FeeModel.FallbackBps(null);
|
||||
var (exitUsd, realizedPnl, totalFees) = DemoModel.CloseWithFees(
|
||||
openPos.Size, signal.Price, openPos.AmountUsd, demoFeeBps, DemoModel.FallbackHalfSpread);
|
||||
decimal demoExitPrice = DemoModel.ExitFillPrice(signal.Price, DemoModel.FallbackHalfSpread);
|
||||
|
||||
_state.GlobalPnl += realizedPnl;
|
||||
account.UpdateBalance(account.AvailableBalance + exitUsd);
|
||||
@@ -652,10 +658,11 @@ namespace PolyTraderSharp.Services
|
||||
Outcome = signal.Outcome,
|
||||
Side = signal.Side,
|
||||
EntryPrice = openPos.EntryPrice,
|
||||
ExitPrice = signal.Price,
|
||||
ExitPrice = demoExitPrice,
|
||||
Size = openPos.Size,
|
||||
RealizedPnl = realizedPnl,
|
||||
PnlPercent = TradeMath.PnlPercent(realizedPnl, openPos.AmountUsd),
|
||||
TotalFees = totalFees,
|
||||
OpenedAt = openPos.OpenedAt,
|
||||
ClosedAt = DateTime.UtcNow,
|
||||
ExitReason = signal.Reason
|
||||
|
||||
Reference in New Issue
Block a user