I try to get do a POST test-order API call, for the MEXC-Global API, and I always get an error and the KI could not solve the problem, can anyone else help me with it?
Here is my problem curl-info:
st ring(35) "{"code":500,"msg":"Internal error"}" array(37) { ["url"]=> string(201) "https://api.mexc.com/api/v3/order/test?timestamp=1700891018.787&symbol=SLTUSDT&side=BUY&type=LIMIT&quantity=0.0002&price=30000&signature=MY_SIGNATUR" ["content_type"]=> string(16) "application/json" ["http_code"]=> int(400) ["header_size"]=> int(469) ["request_size"]=> int(582) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(0) ["redirect_count"]=> int(0) ["total_time"]=> float(0.286157) ["namelookup_time"]=> float(0.000274) ["connect_time"]=> float(0.004934) ["pretransfer_time"]=> float(0.026281) ["size_upload"]=> float(84) ["size_download"]=> float(35) ["speed_download"]=> float(122) ["speed_upload"]=> float(293) ["download_content_length"]=> float(35) ["upload_content_length"]=> float(84) ["starttransfer_time"]=> float(0.286132) ["redirect_time"]=> float(0) ["redirect_url"]=> string(0) "" ["primary_ip"]=> string(13) "SERVER_IP" ["certinfo"]=> array(0) { } ["primary_port"]=> int(443) ["local_ip"]=> string(13) "MY_IP" ["local_port"]=> int(48306) ["http_version"]=> int(2) ["protocol"]=> int(2) ["ssl_verifyresult"]=> int(0) ["scheme"]=> string(5) "HTTPS" ["appconnect_time_us"]=> int(28448) ["connect_time_us"]=> int(5206) ["namelookup_time_us"]=> int(485) ["pretransfer_time_us"]=> int(28484) ["redirect_time_us"]=> int(0) ["starttransfer_time_us"]=> int(287498) ["total_time_us"]=> int(287522) }
We have a 400-Error
Here is my used code:
$symbol = 'SLTUSDT';
$serverTime = 1656298742; //Unix-Timestamp in Nano-sek
$secretKey = 'MY_SECRET_KEY';
$timestamp = $serverTime / 1000 + 1000;
$method = 'POST';
$path = '%2Fapi%2Fv3%2Forder%2Ftest'; //URL_encoded path-string
// Query string for a limit order
$params = [
'symbol' => $symbol,
'side' => 'BUY',
'type' => 'LIMIT',
'quantity' => '0.0002',
'price' => '30000'
];
// Generate the signature
$stringToSign = 'timestamp=' . $timestamp . '&method=' . $method . '&path=' . $path;
$signature = hash_hmac('sha256', $stringToSign, $secretKey);
// Set the headers
$headers = [
'Content-Type: application/json',
'X-MEXC-APIKEY: MY_API_KEY',
'Authorization: Bearer MY_API_SECRET',
'X-MEXC-API-Signature: ' . $signature,
'X-MEXC-API-Timestamp: ' . $timestamp,
'recvWindow: 50000'
];
// Generate the URL
//$url = 'https://api.mexc.com/api/v3/order/test?symbol=' . $symbol;
$url='https://api.mexc.com/api/v3/order/test?timestamp='.$timestamp.'&symbol='.$symbol.'&side='.$params['side'].'&type='.$params['type']
.'&quantity='.$params['quantity'].'&price='.$params['price'].'&signature='.$signature;
// Make the API call
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params)); // For a limit order
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Here is the detailed problem analysis overview from the google-ki:
Yes, the provided cURL info indicates a 400 Bad Request error. This means that the request sent by the client to the server could not be processed due to something that is perceived to be a client error.
Here's a breakdown of the relevant cURL info:
url: https://api.mexc.com/api/v3/order/test?timestamp=1700884164.457&signature=MY_SIGNATUR&symbol=SLTUSDT This shows the URL used for the API request, including the timestamp, signature, and symbol.
http_code: 400 This confirms the 400 Bad Request error code.
total_time: 0.286617 This shows the total time taken for the API request, including DNS lookup, connection establishment, and data transfer.
download_content_length: 35 This shows the size of the response received from the server, which is 35 bytes.
speed_download: 122 This indicates the average download speed, which is 122 bytes per second.
Based on the provided information, it's evident that the API request is reaching the server and receiving a response, but the response contains an error message due to a 400 Bad Request error.
Possible Causes of the 400 Error
Malformed Request Syntax: The request syntax may be incorrect, such as an invalid timestamp format, missing parameters, or incorrect signature calculation.
Invalid Request Message Framing: The request message framing may be invalid, such as an incorrect content type or missing headers.
Deceptive Request Routing: The request routing may be deceptive, such as using a proxy or VPN that masks the client's origin.
Recommendations
Verify Request Syntax: Double-check the request syntax, including the timestamp format, parameter values, and signature calculation.
Validate Request Message Framing: Ensure that the request message framing is correct, including the content type and required headers.
Check Deceptive Request Routing: Verify that you are not using a proxy or VPN that might be masking the client's origin and causing routing issues.
Review MEXC API Documentation: Refer to the MEXC API documentation for specific requirements and guidelines for the /order/test endpoint.
Contact MEXC Support: If the error persists, contact MEXC support for further assistance and provide the cURL info for detailed investigation.