You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用MEXC Spot V3 API查询账户信息时持续返回400错误求助

Fix for MEXC Spot V3 API 400 Error

The 400 error occurs because your request is missing the required signature parameter for this private API endpoint. MEXC requires all authenticated requests to include a HMAC-SHA256 signature generated from the query string using your secret key. Here's how to resolve the issue:

Required Changes

  • Generate an integer timestamp (no decimal places)
  • Compute the HMAC-SHA256 signature of the query string
  • Append the signature to the request URL
  • Use the digest package to handle signature generation

Corrected Code

library(httr)
library(digest)

access.key = "###"
secret.key = "###"

# Generate integer timestamp in milliseconds (no decimals)
timestamp <- as.character(round(as.numeric(Sys.time()) * 1000))

# Create query string to sign
query_string <- paste0("timestamp=", timestamp)

# Compute HMAC-SHA256 signature
signature <- hmac(key = secret.key, object = query_string, algo = "sha256", raw = FALSE)

# Build full URL with timestamp and signature
full.url <- paste0("https://api.mexc.com/api/v3/account?", query_string, "&signature=", signature)

headers <- c(
  "X-MEXC-APIKEY" = access.key,
  "Content-Type" = "application/json"
)

test_get <- httr::GET(full.url, config = add_headers(headers))

# Check response details
cat("Status Code:", test_get$status_code, "\n")
cat("Response Content:", content(test_get, "text"), "\n")

Key Explanations

  1. Integer Timestamp: MEXC expects timestamps as integers (no decimal points). Using round() ensures you don't send invalid values like 1620000000.123 which would fail validation.
  2. Signature Generation: The signature is created by hashing the query string (only the timestamp=XXX segment) with your secret key using HMAC-SHA256. This is mandatory for all private endpoints.
  3. URL Construction: The signature must be added as a query parameter to the request URL for authentication.

Additional Checks

  • Confirm your API key has Spot Account Read permissions enabled in your MEXC account settings.
  • Ensure your system clock is synchronized (timestamps must be within 5 seconds of MEXC's server time to avoid "timestamp expired" errors).

内容的提问来源于stack exchange,提问作者Nick Amato

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 18:43:27