Auto-fetch live marks on strategy page open

On opening the Strategy page, automatically pull the current spot, each leg's
live mid (Mark column) and IV — without touching entry prices. The Reload
button still re-prices unlocked legs to the current mark. Clarified the legs
table hint.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
ojy
2026-05-13 04:38:07 +00:00
parent 5348bf643a
commit e0cbd798b6

View File

@@ -118,7 +118,7 @@
<!-- Legs table (at the bottom) --> <!-- Legs table (at the bottom) -->
<div class="card mb-4" x-show="legs.length > 0 || showManual" x-cloak> <div class="card mb-4" x-show="legs.length > 0 || showManual" x-cloak>
<div class="card-header d-flex align-items-center justify-content-between"> <div class="card-header d-flex align-items-center justify-content-between">
<h3 class="card-title mb-0">Legs <span class="text-secondary small fw-normal">— uncheck a leg to drop it from the chart</span></h3> <h3 class="card-title mb-0">Legs <span class="text-secondary small fw-normal"> Mark = live mid · 🔒 locks entry price · uncheck to drop from chart</span></h3>
<div> <div>
<span class="me-3" :class="netCost >= 0 ? 'text-danger' : 'text-success'"> <span class="me-3" :class="netCost >= 0 ? 'text-danger' : 'text-success'">
Net <strong x-text="netCost >= 0 ? 'debit' : 'credit'"></strong>: Net <strong x-text="netCost >= 0 ? 'debit' : 'credit'"></strong>:
@@ -299,6 +299,8 @@
init() { init() {
this.reload(); this.reload();
// pull live spot / marks / IVs on open (does NOT touch entry prices)
if (this.legs.length > 0 && this.symbol) this.reloadMarket(false);
// re-sync if another tab changed the basket // re-sync if another tab changed the basket
window.addEventListener('storage', (e) => { if (e.key === StrategyStore.KEY) this.reload(); }); window.addEventListener('storage', (e) => { if (e.key === StrategyStore.KEY) this.reload(); });
}, },
@@ -438,9 +440,10 @@
this.reload(); this.reload();
this.flash('Leg added'); this.flash('Leg added');
}, },
// Re-fetch spot + each leg's current mark & IV. Unlocked legs also get // Re-fetch spot + each leg's current mark & IV.
// their entry price reset to the current mark; locked legs keep their entry. // When repriceUnlocked (default — the Reload button), unlocked legs also
async reloadMarket() { // get their entry price reset to the current mark; locked legs always keep it.
async reloadMarket(repriceUnlocked = true) {
if (!this.symbol || this.legs.length === 0) return; if (!this.symbol || this.legs.length === 0) return;
this.refreshing = true; this.refreshing = true;
try { try {
@@ -471,7 +474,7 @@
const mark = Math.round((o.midPrice ?? o.mid ?? o.bsPrice ?? 0) * 100) / 100; const mark = Math.round((o.midPrice ?? o.mid ?? o.bsPrice ?? 0) * 100) / 100;
leg.currentMark = mark; leg.currentMark = mark;
if (o.iv > 0) leg.iv = o.iv; if (o.iv > 0) leg.iv = o.iv;
if (!leg.locked && mark > 0) { leg.entryPrice = mark; relinked++; } if (!leg.locked && repriceUnlocked && mark > 0) { leg.entryPrice = mark; relinked++; }
updated++; updated++;
} }
if (spot > 0) st.spotSnapshot = spot; if (spot > 0) st.spotSnapshot = spot;
@@ -480,11 +483,13 @@
if (spot > 0) this.spot = spot; if (spot > 0) this.spot = spot;
if (this.dteOffset > this.maxDTE) this.dteOffset = this.maxDTE; if (this.dteOffset > this.maxDTE) this.dteOffset = this.maxDTE;
this.$nextTick(() => this.renderChart()); this.$nextTick(() => this.renderChart());
if (repriceUnlocked) {
this.flash(updated > 0 this.flash(updated > 0
? `Reloaded ${updated} leg${updated===1?'':'s'}${relinked?` (${relinked} re-priced)`:''} · spot $${(spot||this.spot).toFixed(2)}` ? `Reloaded ${updated} leg${updated===1?'':'s'}${relinked?` (${relinked} re-priced)`:''} · spot $${(spot||this.spot).toFixed(2)}`
: 'Reloaded — no matching contracts found in the current chain'); : 'Reloaded — no matching contracts found in the current chain');
}
} catch (e) { } catch (e) {
this.flash('Reload failed: ' + e.message); if (repriceUnlocked) this.flash('Reload failed: ' + e.message);
} finally { } finally {
this.refreshing = false; this.refreshing = false;
} }