/** * Position history — persists position lifecycle events to ~/.perp/positions.jsonl * Enables agents to review past trades, analyze P&L, and learn from history. */ import type { StreamEvent } from "./event-stream.js"; export interface PositionRecord { id: string; exchange: string; symbol: string; side: "long" | "short"; entryPrice: string; exitPrice?: string; size: string; realizedPnl?: string; unrealizedPnl?: string; openedAt: string; closedAt?: string; updatedAt: string; status: "open" | "closed" | "updated"; duration?: number; meta?: Record; } export interface PositionStats { totalTrades: number; wins: number; losses: number; winRate: number; totalPnl: number; avgPnl: number; bestTrade: number; worstTrade: number; avgDuration: number; longestTrade: number; shortestTrade: number; bySymbol: Record; byExchange: Record; } /** Append a position record to the log */ export declare function logPosition(record: PositionRecord): void; /** Read position history with optional filters */ export declare function readPositionHistory(opts?: { symbol?: string; exchange?: string; status?: string; limit?: number; since?: string; }): PositionRecord[]; /** Compute aggregate stats from closed position records */ export declare function getPositionStats(opts?: { exchange?: string; since?: string; }): PositionStats; /** * Returns a wrapper around the event callback that intercepts position events * and logs them to the position history file. * * Usage: * const loggedOnEvent = attachPositionLogger(originalOnEvent); * startEventStream(adapter, { onEvent: loggedOnEvent, ... }); */ export declare function attachPositionLogger(onEvent: (event: StreamEvent) => void): (event: StreamEvent) => void;