refactor(oneshot): switch from scalper to Dominant Side Hold strategy

Previous behaviour: enter any side with positive momentum, exit at TP (+1 tick),
cycle back to IDLE — causing rapid buy-sell-buy loops on low-probability tokens.

New strategy:
- Enter ONLY the side the market already prices as probable winner (mid >= MIN_DOMINANT_MID)
- Hold position to market expiry; on-chain redeemer settles at $1.00 win / $0.00 loss
- Emergency stop-loss only (absolute mid floor, e.g. 0.20) for catastrophic reversals
- One entry per market slot — no re-entry while POSITION_OPEN

Key changes:
- SignalEngine: detect dominant side (up.mid vs down.mid), require MIN_DOMINANT_MID
  threshold, new scoring weights (mid 45% / imbalance 35% / spread 20%)
- PositionEngine: remove TP, slope-drop, time-reduce exits; add expired handler;
  stop-loss is now an absolute mid floor instead of relative-to-entry ticks
- oneshot.js: expirePosition() clears state without submitting sell orders;
  flattenPosition() only called for emergency stops; update cfg vars
- constants.js: add SIG_NO_DOMINANT, SIG_LOW_DOMINANT, EXIT_EXPIRED reason codes
- .env.example: replace ONESHOT_TP_TICKS with MIN_DOMINANT_MID, STOP_LOSS_MID,
  TTE_MIN, TTE_MAX

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
direkturcrypto
2026-02-24 14:05:44 +07:00
co-authored by Claude Sonnet 4.6
parent 707d654749
commit bf09d30376
5 changed files with 325 additions and 291 deletions
+30 -9
View File
@@ -127,9 +127,11 @@ SNIPER_SHARES=5
# ─────────────────────────────────────────────
# ONESHOT ENGINE (oneshot.js / npm run oneshot-sim)
# Anti-Flip 5m microstructure execution engine.
# Evaluates book features on every tick and enters only when
# momentum, depth, and spread conditions align.
# Dominant Side Hold strategy.
# Enters ONLY the side that the market already prices as the probable
# winner (mid >= ONESHOT_MIN_DOMINANT_MID), then holds the position
# to market expiry for on-chain redemption at $1.00.
# No take-profit sells. No momentum-based exits.
# ALWAYS test with DRY_RUN=true before going live.
# ─────────────────────────────────────────────
@@ -145,17 +147,36 @@ ONESHOT_POLL_INTERVAL_MS=300
# USDC risk per trade — size = floor(ONESHOT_BASE_RISK_USDC / entryPrice), min 5 shares
ONESHOT_BASE_RISK_USDC=5
# Take-profit in ticks above entry price (1 tick = tickSize, e.g. 0.01)
ONESHOT_TP_TICKS=1
# ── Entry filters ──────────────────────────────────────────────────────
# Minimum composite score to trigger entry (01, higher = more selective)
ONESHOT_SCORE_THRESHOLD=0.60
# Minimum mid price for the dominant side to qualify as an entry candidate.
# Example: 0.60 means the token must be priced at ≥60% probability of winning.
# Lower = more trades but more uncertain outcomes. Higher = fewer but more confident.
ONESHOT_MIN_DOMINANT_MID=0.60
# Minimum composite score to trigger entry (01).
# Score is based on: mid price strength (45%), order-book imbalance (35%), spread (20%).
ONESHOT_SCORE_THRESHOLD=0.55
# TTE (time-to-expiry) window in seconds for entry.
# Only enter when the market is between TTE_MIN and TTE_MAX seconds from closing.
# Narrowing this window means entering later when direction is clearer.
ONESHOT_TTE_MIN=20
ONESHOT_TTE_MAX=90
# Minimum shares at the best bid AND best ask for the depth hard gate
ONESHOT_MIN_TOP_SIZE=10
# ── Exit settings ──────────────────────────────────────────────────────
# Emergency stop-loss: exit if the token's mid price drops below this absolute level.
# Protects against a complete market reversal (e.g. entered UP at 0.70, price drops to 0.18).
# Set to 0 to disable (pure hold-to-expiry — binary win/loss outcome).
ONESHOT_STOP_LOSS_MID=0.20
# ── Risk settings ──────────────────────────────────────────────────────
# Number of consecutive losses before entering cooldown
# Number of consecutive emergency exits (losses) before entering cooldown
ONESHOT_MAX_CONSEC_LOSSES=2
# Number of market slots to skip during cooldown
@@ -167,7 +188,7 @@ ONESHOT_DAILY_LOSS_CAP=20
# Maximum milliseconds to wait for a FOK fill ack (timeout → cancel → IDLE)
ONESHOT_FILL_TIMEOUT_MS=800
# Enable verbose debug logging (discovery probes, gate results, feature scores, heartbeat)
# Enable verbose debug logging (discovery probes, gate results, scoring, heartbeat)
# Can also be enabled with: npm run oneshot-debug
# Or on the command line: ONESHOT_DEBUG=true npm run oneshot
ONESHOT_DEBUG=false