Copy link to clipboard
Copied
Crypto.com API is not very friendly.
Took forever to get account balance authorized. Using same technique, same encoding I cannot get the order created. Always get unauthorized.
<cfscript> apiKey = "#cr_key#"; apiSecret = "#cr_s#"; hmacm = #req_path# & 121 & apikey & #unixdatetimeNow.getTime()#; CrHex = hmac(hmacm, apiSecret, "HmacSHA256"); theKeyBytes = charsetDecode(ApiSecret, "UTF-8"); crsign = lcase(hmac(hmacm, apiSecret, "HmacSHA256")); newbody = serializeJSON({ "api_key": "#cr_key#", "id": "121", "method": "#req_path#", "nonce": "#unixdatetimeNow.getTime()#", "params": {}, "sig": "#crsign#" }); </cfscript>
This works for account balance just fine.
hmacm = #req_path# & 121 & apikey & #unixdatetimeNow.getTime()#;
THIS is the HMACM getting envrypted which works is:
private/get-account-summary121XXXXoZW8Cw75583kiSMqjp1649261460418
This HMACM has no parameters in it which are only {} in the body.
<CFHTTP METHOD="POST" URL="#base_api##req_path#" result="result"> <cfhttpparam type="header" name="Content-Type" value="application/json"> <cfhttpparam type="body" value="#newbody#"> </cfhttp>
But below trying the order. I get Unauthorized no matter what.
<cfscript> apiKey = "#cr_key#"; apiSecret = "#cr_s#"; sparams = serializeJSON({ "instrument_name": "#symb#", "side": "#side#", "type": "#type#", "quantity": #size# }); hmacm = #req_path# & 121 & apikey & sparams & #unixdatetimeNow.getTime()#; CrHex = hmac(hmacm, apiSecret, "HmacSHA256"); theKeyBytes = charsetDecode(ApiSecret, "UTF-8"); crsign = lcase(hmac(hmacm, apiSecret, "HmacSHA256")); newbody = serializeJSON({ "api_key": "#cr_key#", "id": "121", "method": "#req_path#", "nonce": "#unixdatetimeNow.getTime()#", "params": deserializeJSON(sparams), "sig": "#crsign#" }); trybody = serializeJSON({ "id": "121", "method": "#req_path#", "params": deserializeJSON(sparams), "nonce": "#unixdatetimeNow.getTime()#" }); </cfscript>
For the ORDER HMACM I have tried both of these with the sparams (used to avoid params variable) and without:
hmacm = #req_path# & 121 & apikey & sparams & #unixdatetimeNow.getTime()#; hmacm = #req_path# & 121 & apikey & #unixdatetimeNow.getTime()#;
I have tried both these for the HMACM:
private/create-order121XXXXoZW8Cw75583kiSMqjp{"side":"sell","instrument_name":"XLM_USDT","quantity":333,"type":"market"}1649261460418
private/create-order121XXXXoZW8Cw75583kiSMqjp1649261460418
In the order I have tried both the newbody and trybody. Using the same CFHTTP.
<CFHTTP METHOD="POST" URL="#base_api##req_path#" result="result"> <cfhttpparam type="header" name="Content-Type" value="application/json"> <cfhttpparam type="body" value="#newbody#"> </cfhttp>
I'm lost. Some exchanges I have got up and running in 30 minutes. Crypto.com API is proving to be very difficult.
Crypto.com API Documentation link.
https://exchange-docs.crypto.com/spot/index.html?csharp#private-create-orderoffset-smoker
Copy link to clipboard
Copied
<cfscript> apiKey = "#cr_key#"; apiSecret = "#cr_s#"; hmacm = #req_path# & 121 & apikey & #unixdatetimeNow.getTime()#; CrHex = hmac(hmacm, apiSecret, "HmacSHA256"); theKeyBytes = charsetDecode(ApiSecret, "UTF-8"); crsign = lcase(hmac(hmacm, apiSecret, "HmacSHA256")); newbody = serializeJSON({ "api_key": "#cr_key#", "id": "121", "method": "#req_path#", "nonce": "#unixdatetimeNow.getTime()#", "params": {}, "sig": "#crsign#" }); </cfscript>This works for account balance just fine.
hmacm = #req_path# & 121 & apikey & #unixdatetimeNow.getTime()#;
THIS is the HMACM getting envrypted which works is:
private/get-account-summary121XXXXoZW8Cw75583kiSMqjp1649261460418
This HMACM has no parameters in it which are only {} in the body.
<CFHTTP METHOD="POST" URL="#base_api##req_path#" result="result"> <cfhttpparam type="header" name="Content-Type" value="application/json"> <cfhttpparam type="body" value="#newbody#"> </cfhttp>
By @Shehryar25011190w0dc
Even though that works, it is still inefficient. That is because you are passing the API-Key in 2 ways:
The link you've provided suggests that:
<cfscript>
newbody=serializeJSON({
"id": 11,
"params": {
"instrument_name": "ETH_CRO",
"side": "BUY",
"type": "LIMIT",
"price": 100.12,
"quantity": 1.2,
"client_oid": "my_order_0002",
"time_in_force": "GOOD_TILL_CANCEL",
"exec_inst": "POST_ONLY"
},
"nonce": #your_nonce_value#
});
</cfscript>​
Copy link to clipboard
Copied
Have you solved the problem?