For private endpoints of Crypto.com, I am getting the error:
{ id: xx,
method: 'private/get-order-detail',
code: 10007,
message: 'INVALID_NONCE' }
for the following code:
function getOrderStatus() {
var nonce = Math.floor(new Date().setSeconds(new Date().getSeconds() - 10) / 1000);
nonce += 1; // Increment nonce for each request, is this the increase?
var payload = {
"id": orderId,
"method": "private/get-order-detail",
"params": {
"order_id": orderId
},
"nonce": nonce
};
var payloadString = JSON.stringify(payload);
var signature = Utilities.computeHmacSha256Signature(payloadString, secretKey);
var signatureHex = Utilities.base64Encode(signature).toString();
var headers = {
"Content-Type": "application/json",
"API-Key": apiKey,
"Signature": signatureHex,
"Timestamp": nonce
};
var options = {
"method": "post",
"headers": headers,
"payload": payloadString,
"muteHttpExceptions": true
};
var response = UrlFetchApp.fetch("https://api.crypto.com/v2/private/get-order-detail", options);
var data = JSON.parse(response.getContentText());
console.log(data)
return data;
}
From my understanding, the nonce value needs to be increasing on every request?
When I saw the official document of Crypto.com Spot Exchange V2.1 API for Exchange reference documentation,
It seems that the sample value of
nonceis1587846358253.When I saw your script using
new Date('2020-04-26T05:25:58.253Z'),1587878748is returned asnonce. And, the document says aboutcode: 10007,as10007 400 INVALID_NONCE Nonce value differs by more than 30 seconds from server.If my understanding is correct, I thought that this might be the reason for your current issue. If my understanding is correct, how about the following modification?
From:
To:
or
or
Note:
noncecorrectly works for using the API you want to use. Please be careful about this.Reference:
Added:
From your following reply,
I could confirm that your issue of
noncein your question was resolved. And also, I confirmed that your other part script except fornoncewas not correct, and, this is your new issue. In this case, I think that it is required to modify your request. I think that your issue ofnonceof this question can be resolved by my answer. So, how about modifying your request as follows?Modified script:
The function
signRequestis from https://exchange-docs.crypto.com/spot/index.html#request-format.