feat: accept valuation amount instead of price for rebalancing input

For holdings with quantity > 0, the input now accepts the total
valuation amount and derives the current price by dividing by quantity.
Holdings with quantity 0 (target-only) still accept price directly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
zephyrdark 2026-02-18 21:51:05 +09:00
parent fe48e20642
commit 238c4d1caf

View File

@ -111,8 +111,13 @@ export default function RebalancePage() {
setError(null);
try {
const priceMap: Record<string, number> = {};
for (const [ticker, price] of Object.entries(prices)) {
priceMap[ticker] = parseFloat(price);
for (const [ticker, value] of Object.entries(prices)) {
const qty = getHoldingQty(ticker);
if (qty > 0) {
priceMap[ticker] = parseFloat(value) / qty;
} else {
priceMap[ticker] = parseFloat(value);
}
}
const body: Record<string, unknown> = {
@ -190,23 +195,25 @@ export default function RebalancePage() {
{/* Price Input */}
<Card className="mb-6">
<CardHeader>
<CardTitle> </CardTitle>
<CardTitle> </CardTitle>
</CardHeader>
<CardContent>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
{Object.keys(prices).map((ticker) => {
const target = targets.find((t) => t.ticker === ticker);
const qty = getHoldingQty(ticker);
const isValuation = qty > 0;
return (
<div key={ticker}>
<Label htmlFor={`price-${ticker}`}>
{nameMap[ticker] || ticker} {target ? `(목표 ${target.target_ratio}%)` : ''} - {getHoldingQty(ticker)}
{nameMap[ticker] || ticker} {target ? `(목표 ${target.target_ratio}%)` : ''} - {qty}
</Label>
<Input
id={`price-${ticker}`}
type="number"
value={prices[ticker]}
onChange={(e) => setPrices((prev) => ({ ...prev, [ticker]: e.target.value }))}
placeholder="현재 가격"
placeholder={isValuation ? '평가 금액' : '현재 가격'}
className="mt-1"
/>
</div>