From b55ff111a4a735d02dc74a5e3b758d7b1f3c170c Mon Sep 17 00:00:00 2001 From: jackyu66git Date: Sun, 3 May 2026 22:47:44 +0800 Subject: [PATCH] perf: scan interval 50ms fixed HL allMids pushes ~200ms, scan at 50ms catches every update within 1 tick. Async entry goroutine means no blocking. --- README.md | 7 +++---- main.go | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 095df86..068b0f4 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,7 @@ PriceStore ─────────┼───────────── └──────────────┘ │ ┌─────────▼─────────┐ - │ ScanBGHL (50-250ms │ - │ random jitter) │ + │ ScanBGHL (50ms) │ │ BG ↔ HL only │ └─────────┬─────────┘ │ @@ -98,7 +97,7 @@ Then open [http://localhost:8888](http://localhost:8888) for the Web dashboard. | `BITGET_API_KEY` / `BITGET_API_SECRET` / `BITGET_PASSPHRASE` | — | Bitget API credentials (test mode skips) | | `HL_PRIVATE_KEY` / `HL_ADDRESS` | — | HyperLiquid wallet credentials (test mode skips) | -> **Note:** Scan interval is fixed at **50-250ms random jitter** (not configurable). This prevents lock-step with HyperLiquid's ~200ms push cycle. +> **Note:** Scan interval is fixed at **50ms**. At this rate the scanner catches every HyperLiquid ~200ms push without any jitter. ## Fee Model @@ -113,7 +112,7 @@ Round trip (2 legs entry + 2 legs exit): **0.07%** total fees. ## Trading Logic -1. **Scanner** runs every 50-250ms (random jitter to avoid lock-step with exchange push cycles), checks all 6 coins for BG ↔ HL spread +1. **Scanner** runs every 50ms, checks all 6 coins for BG ↔ HL spread 2. **Entry** when net profit ≥ `TRADE_THRESHOLD` (after full round-trip fees) - Uses scan-time prices directly (no re-read from store to avoid WS jitter) - Synchronous execution in the scanner tick (no goroutine delay) diff --git a/main.go b/main.go index f9a1e3c..9cd4fe0 100644 --- a/main.go +++ b/main.go @@ -115,15 +115,15 @@ func main() { // Main loop lastHour := -1 - // Random jitter 50-250ms to avoid lock-step with exchange push cycles - jitterMin, jitterMax := 50, 250 + // Fixed 50ms scan interval + jitterMin, jitterMax := 50, 50 randInterval := func() time.Duration { return time.Duration(jitterMin+rand.Intn(jitterMax-jitterMin+1)) * time.Millisecond } scannerTick := time.NewTimer(randInterval()) statusTick := time.NewTicker(30 * time.Second) - log.Printf("[Monitor] Scanner running every %d-%dms (random jitter)", jitterMin, jitterMax) + log.Printf("[Monitor] Scanner running every %dms", jitterMin) runLoop := true for runLoop {