tenth version
Deploy / Test, build and deploy (push) Successful in 1m46s

This commit is contained in:
2026-06-08 14:58:56 +00:00
parent 20cc8506ad
commit 7626c1b831
17 changed files with 917 additions and 27 deletions
+32
View File
@@ -2,6 +2,7 @@ package position
import (
"context"
"errors"
"testing"
"time"
@@ -183,3 +184,34 @@ func TestOnExitFillUsesLotInRealizedEdgeCommissionBase(t *testing.T) {
t.Fatalf("realized edge=%s, want -10 bps", updated.RealizedEdgeBps)
}
}
func TestOnExitFillRejectsOverfillWithCriticalRiskEvent(t *testing.T) {
ctx := context.Background()
repo := testutil.NewMemoryRepository()
manager := NewManager(repo)
openAt := time.Now().UTC()
pos := domain.Position{
AccountIDHash: "hash",
InstrumentUID: "uid",
OpenTradeDate: openAt,
Lots: 3,
Lot: 1,
AvgBuyPrice: decimal.NewFromInt(100),
Status: domain.PositionHoldingOvernight,
OpenedAt: &openAt,
}
updated, err := manager.OnExitFill(ctx, pos, domain.Order{
InstrumentUID: "uid",
FilledLots: 5,
AvgFillPrice: decimal.NewFromInt(110),
})
if !errors.Is(err, ErrExitFillExceedsPositionLots) {
t.Fatalf("err=%v, want ErrExitFillExceedsPositionLots", err)
}
if updated.Lots != 3 || updated.Status != domain.PositionHoldingOvernight {
t.Fatalf("position was mutated despite overfill: %+v", updated)
}
if len(repo.RiskEvents) != 1 || repo.RiskEvents[0].Severity != domain.SeverityCritical || repo.RiskEvents[0].EventType != "exit_overfill" {
t.Fatalf("risk events=%+v, want one critical exit_overfill", repo.RiskEvents)
}
}