Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/commands/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ function hlPosition(p: HyperliquidPerpPosition): {
size: string | null;
entry: string | null;
value: string | null;
margin: string | null;
upnl: string | null;
} {
const pos = (p.position ?? p) as Record<string, unknown>;
Expand All @@ -150,7 +151,10 @@ function hlPosition(p: HyperliquidPerpPosition): {
const v = Math.abs(parseFloat(size)) * parseFloat(entry);
if (Number.isFinite(v)) value = v.toFixed(2);
}
return { coin, size, entry, value, upnl: hlNum(pos.unrealizedPnl) };
// Collateral locked against the position — explains why free/withdrawable USDC
// can be far below the account value.
const margin = hlNum(pos.marginUsed);
return { coin, size, entry, value, margin, upnl: hlNum(pos.unrealizedPnl) };
}

// A spot balance worth showing — a strictly positive total. Used as the single
Expand Down Expand Up @@ -215,14 +219,14 @@ function printHyperliquid(hl?: HyperliquidBalanceSummary | null): void {
console.log(
` ${c.dim("COIN".padEnd(10))}${c.dim("SIZE".padEnd(16))}${c.dim(
"ENTRY".padEnd(12)
)}${c.dim("VALUE".padEnd(12))}${c.dim("PnL")}`
)}${c.dim("VALUE".padEnd(12))}${c.dim("MARGIN".padEnd(12))}${c.dim("PnL")}`
);
for (const p of positions) {
const { coin, size, entry, value, upnl } = hlPosition(p);
const { coin, size, entry, value, margin, upnl } = hlPosition(p);
console.log(
` ${c.cyan(coin.padEnd(10))}${clip(size ?? "—", 14).padEnd(16)}${usd(
entry
).padEnd(12)}${usd(value).padEnd(12)}${pnl(upnl)}`
).padEnd(12)}${usd(value).padEnd(12)}${usd(margin).padEnd(12)}${pnl(upnl)}`
);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/lib/api/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,13 +600,17 @@ export interface HyperliquidPerpPosition {
entryPx?: string | number | null;
positionValue?: string | number | null;
unrealizedPnl?: string | number | null;
// Collateral locked against the position — surfaced so the balance view can
// explain why free/withdrawable USDC is below the account value.
marginUsed?: string | number | null;
leverage?: { type?: string; value?: number; rawUsd?: string } | null;
position?: {
coin?: string | null;
szi?: string | number | null;
entryPx?: string | number | null;
positionValue?: string | number | null;
unrealizedPnl?: string | number | null;
marginUsed?: string | number | null;
[key: string]: unknown;
};
[key: string]: unknown;
Expand Down