# FX Rate And Live Pricing Rules

## Purpose

USD/KRW is part of the trade. It changes KRW exposure, KRW profit, KRW loss, and position size.

The agent must never use a hidden or stale exchange-rate assumption for buy/sell sizing.

## Required FX Fields

Every buy/sell or position-size recommendation must include:

- `usdkrw`
- `fx_source`
- `fx_timestamp`
- `price_usd`
- `price_source`
- `price_timestamp`
- `budget_krw`
- `calculated_shares`
- `approx_exposure_krw`

If the agent cannot verify price or FX, it must say:

`NEEDS LIVE PRICE/FX`

and avoid exact share-count recommendations.

## Preferred Sources

Use the most current available source:

1. Broker quote and broker FX when available.
2. yfinance `KRW=X` for USD/KRW and ticker live/near-live quote.
3. Major market-data pages such as Investing.com, Wise, XE, Nasdaq, or exchange/ETF provider data.
4. Manual user-provided broker FX if the user pastes it during market hours.

For actual order sizing, broker quote and broker FX win over public web sources.

## Staleness Rules

- During US market hours, FX and price should ideally be under 5 minutes old for tactical trades.
- For SOXL/SOXS or same-day trades, stale FX/price means no exact share count.
- For slower swing plans, end-of-day FX is acceptable only if clearly labeled.

## Position Sizing Formula

`shares = floor(budget_krw / (price_usd * usdkrw * (1 + fee_buffer)))`

Default fee/slippage buffer:

- `0.15%` until the user's exact broker fee is known.

## Easy Use

Dashboard:

- Use `account_growth_command_center.html` and the `환율 / 수량 계산` card.
- The dashboard calculator is intentionally manual so the user can paste broker price and broker FX during live trading.

Command line:

```bash
python3 outputs/position_size_calculator.py SOXL --account main --budget-krw 10000000 --price-usd 50 --usdkrw 1450
```

Live mode after installing yfinance:

```bash
python3 outputs/position_size_calculator.py SOXL --account main --budget-krw 10000000 --live
```

Live JSON mode:

```bash
python3 outputs/position_size_calculator.py SOXL --account main --budget-krw 10000000 --live --json
```

Current setup status:

- `yfinance` is installed.
- Live mode uses yfinance ticker data and `KRW=X` for USD/KRW.
- Network access may need approval depending on the Codex sandbox state.

JSON output for automation:

```bash
python3 outputs/position_size_calculator.py AMD --account main --budget-krw 5000000 --price-usd 120 --usdkrw 1450 --json
```

## Account Guardrail

If account is `sub` and ticker is leveraged or inverse, the calculator and reports must return:

`NOT ELIGIBLE IN SUB ACCOUNT`
