//go:build live package lkgateway import ( "context" "testing" "time" ) func TestLiveCabinetData(t *testing.T) { rc, _ := NewRuntimeConfig("/var/lib/bj/.bj/setup.json") globalRC = rc fs := rc.Snapshot().Fancy ctx := context.Background() for _, c := range []string{"БР-1545", "БР-704"} { t0 := time.Now() on, err := lkOnlinePortfolio(ctx, rc, c) if err != nil { t.Logf("%s онлайн: ERR %v", c, err) } else { t.Logf("%s ОНЛАЙН (%v) на %s: всего %.2f ₽, бумаги %.2f, деньги %.2f, вложено %.2f, P&L %.2f (%.1f%%), позиций %d/%d", c, time.Since(t0).Round(time.Millisecond), on.AsOf, on.Total, on.Securities, on.CashRUB, on.Cost, on.PnL, on.PnLPct, on.Priced, len(on.Positions)) for i, p := range on.Positions { if i > 5 { break } t.Logf(" %-14s %-28.28s %-10s %10.0f × ср.%.4g → цена %.4g (%s) = %.2f ₽, P&L %.2f (%.1f%%) %s", p.ISIN, p.Name, p.Kind, p.Quantity, p.AvgPrice, p.Price, map[bool]string{true: "%", false: "₽"}[p.InPct], p.Value, p.PnL, p.PnLPct, p.Note) } for _, m := range on.Cash { t.Logf(" деньги %s %.2f", m.Currency, m.Amount) } } for _, d := range []time.Time{time.Now(), time.Date(2025, 12, 31, 0, 0, 0, 0, time.Local), time.Date(2024, 6, 30, 0, 0, 0, 0, time.Local)} { t0 = time.Now() ar, err := lkArchivePortfolio(ctx, fs, c, d) if err != nil { t.Logf("%s архив %s: ERR %v", c, d.Format("02.01.2006"), err) continue } t.Logf("%s АРХИВ на %s (%v): всего %.2f ₽, бумаги %.2f, деньги %.2f, бал.стоимость %.2f, P&L %.2f, позиций %d (с котировкой %d)", c, ar.AsOf, time.Since(t0).Round(time.Millisecond), ar.Total, ar.Securities, ar.CashRUB, ar.Cost, ar.PnL, len(ar.Positions), ar.Priced) for i, p := range ar.Positions { if i > 6 { break } t.Logf(" %-14s %-28.28s %-10s %10.2f × бал.%.4g → кот.%.4g (%s) = %.2f ₽ %s", p.ISIN, p.Name, p.Kind, p.Quantity, p.AvgPrice, p.Price, map[bool]string{true: "%", false: "₽"}[p.InPct], p.Value, p.Note) } for _, m := range ar.Cash { t.Logf(" деньги %s %.2f", m.Currency, m.Amount) } } t0 = time.Now() ops, err := lkArchiveOperations(ctx, fs, c, time.Date(2026, 1, 1, 0, 0, 0, 0, time.Local), time.Now()) if err != nil { t.Logf("%s операции: ERR %v", c, err) continue } t.Logf("%s ОПЕРАЦИИ с 01.01.2026 (%v): %d", c, time.Since(t0).Round(time.Millisecond), len(ops)) for i, o := range ops { if i > 8 { break } t.Logf(" %s %-12s %-3s %-28.28s %10.0f × %.4g = %.2f %s (%.2f ₽)", o.Date, o.Kind, o.Side, o.Name, o.Quantity, o.Price, o.Amount, o.Currency, o.AmountRUB) } } }