Skip to content

fix(exchange): widen MEXC recvWindow to 60s and retry on 700003#3822

Merged
TaprootFreak merged 2 commits into
developfrom
fix/exchange-mexc-recvwindow
Jun 4, 2026
Merged

fix(exchange): widen MEXC recvWindow to 60s and retry on 700003#3822
TaprootFreak merged 2 commits into
developfrom
fix/exchange-mexc-recvwindow

Conversation

@TaprootFreak
Copy link
Copy Markdown
Collaborator

@TaprootFreak TaprootFreak commented Jun 4, 2026

Problem

Liquidity-management pipelines that trade on MEXC (e.g. the XMR deficit rule) intermittently fail with:

mexc {"code":700003,"msg":"Timestamp for this request is outside of the recvWindow."}

The failing order aborts before any trade is placed (input/output amounts are null), so no funds are moved — but the deficit goes unhandled during episodes.

Root cause (evidence-based)

App Insights (appi-dfx-api-prd) shows MEXC round-trip latency from the API egress has a heavy tail: p50 ≈ 270 ms, but p99 ≈ 4–6 s and outliers up to ~70 s. Every captured timestamp-rejection (HTTP 400) has a duration > 5 s; fast calls never get rejected. It is therefore a latency problem, not host clock skew.

The signed requests carried no recvWindow, so MEXC applied its 5 s default and rejected any call slower than that:

  • ccxt path (fetchBalance etc.): no options.recvWindow set.
  • custom signed REST path (MexcService.request): no recvWindow param.

Fix

  • config.mexc: set options.recvWindow = 60000 (MEXC maximum). ccxt reads this directly at sign time, so it applies to all ccxt-routed signed calls.
  • MexcService: send recvWindow=60000 on the custom signed REST path and retry once with a fresh timestamp on error 700003 (covers the rare >60 s outlier endpoints like capital/deposit/hisrec).

Scope is limited to MEXC (the only exchange exhibiting this).

Test plan

  • type-check, format:check, lint pass locally
  • config.spec.ts, exchange.service.spec.ts, exchange.controller.spec.ts pass
  • CI green
  • Observe MEXC 700003 failures disappear on develop/DEV after deploy

MEXC round-trip latency from the API egress has a heavy tail (p99 ~5s,
outliers >60s). Signed requests carried no recvWindow, so MEXC's 5s
default rejected slow calls with error 700003 ("Timestamp for this
request is outside of the recvWindow"), failing liquidity-management
pipelines (e.g. the XMR deficit rule) before any order was placed.

Set recvWindow to the MEXC maximum (60s) on both the ccxt client options
and the custom signed REST path, and retry the custom path once with a
fresh timestamp on 700003.
@TaprootFreak TaprootFreak marked this pull request as ready for review June 4, 2026 17:43
@TaprootFreak TaprootFreak requested a review from davidleomay as a code owner June 4, 2026 17:43
Comment on lines +176 to +177
// max recvWindow (60s) to tolerate MEXC round-trip latency spikes that otherwise reject the request with error 700003
params.recvWindow = '60000';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This duplicates config -> DRY

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — extracted into a single source Config.mexcRecvWindow, now referenced by both the ccxt options and the custom signed REST path (42f8a22).

Avoid duplicating the 60000 literal across the ccxt options and the
custom signed REST path by reading both from Config.mexcRecvWindow.
@TaprootFreak TaprootFreak merged commit c6899af into develop Jun 4, 2026
7 checks passed
@TaprootFreak TaprootFreak deleted the fix/exchange-mexc-recvwindow branch June 4, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants