# Live Dashboard Sync Guide

## Current Practical Setup

The new practical dashboard is:

`/Users/jangbogeun/Documents/Codex/2026-06-06/2/outputs/trading_order_dashboard.html`

It reads:

`/Users/jangbogeun/Documents/Codex/2026-06-06/2/outputs/live_account_state.json`

The dashboard refreshes the JSON state every 30 seconds when opened through HTTP.

## Local Server

Run:

```bash
python3 /Users/jangbogeun/Documents/Codex/2026-06-06/2/outputs/dashboard_server.py
```

Then open on the Mac:

```text
http://127.0.0.1:8765/trading_order_dashboard.html
```

Phone on same Wi-Fi can open the LAN URL printed by the server.

## Kakao 상세보기 Link

KakaoTalk cannot open:

- `localhost`
- `127.0.0.1`
- `file://...`

For Kakao 상세보기 to open the dashboard, set a reachable URL:

```bash
python3 /Users/jangbogeun/Documents/Codex/2026-06-06/2/outputs/set_kakao_dashboard_url.py "https://YOUR_PUBLIC_DASHBOARD_URL/trading_order_dashboard.html"
```

Current quick public URL generated on 2026-06-07:

```text
https://drive-trades-charitable-generating.trycloudflare.com/trading_order_dashboard.html
```

This is a Cloudflare Quick Tunnel URL. It works while the `cloudflared tunnel` process and local dashboard server are running. It is not a permanent production URL.

The sender priority is:

1. `KAKAO_DASHBOARD_URL`
2. `DASHBOARD_PUBLIC_URL`
3. `KAKAO_LINK_URL`
4. `outputs/dashboard_public_url.txt`
5. fallback `https://finance.yahoo.com`

## Anywhere Access Requirement

If you want the phone and this server to stay synced as long as either side has internet, a cloud-accessible state path is required.

Best options:

1. `Cloudflare Tunnel` from this Mac/server
   - Fastest private-ish setup.
   - Kakao 상세보기 can point to the tunnel URL.
   - Dashboard reads local `live_account_state.json`.

2. `GitHub Pages + live_account_state.json`
   - Simple static hosting.
   - Good for dashboard viewing.
   - Less ideal for private account data unless repository is private and access is controlled.

3. `Supabase/Firebase/Cloudflare Workers KV`
   - Best long-term design.
   - Automations write latest state to cloud.
   - Dashboard reads the same cloud state from phone/Mac.
   - Kakao links to the hosted dashboard.

## Recommended Next Step

Use Cloudflare Tunnel first:

- It makes the current local dashboard reachable from Kakao quickly.
- It avoids building a full backend before the workflow is proven.
- Later, replace it with Supabase/Firebase/KV if persistent cloud state is needed.

## State Refresh

After a new screenshot/account update, run:

```bash
python3 /Users/jangbogeun/Documents/Codex/2026-06-06/2/outputs/update_live_account_state.py
```

The dashboard will refresh within 30 seconds if opened through the HTTP server.
