1

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-order

Merle_the_Pearl
  • 1,391
  • 3
  • 18
  • 25
  • You haven't linked the API reference but assuming it's the one I looked at, you don't appear to be doing what it says. I would recommend reading the documentation and use the examples they have as a guide. It does tell you there how format the data to send. – haxtbh Apr 07 '22 at 11:15
  • I have read it many times. I have formatted the Request sample exactly as requested. https://exchange-docs.crypto.com/spot/index.html?csharp#private-create-order I have confirmed my parameters are formatted JSON wise exactly as the expected output. Many folks are not happy with the Crypto.com API Documentation either. As related some API's get done in 30minuts. – Merle_the_Pearl Apr 07 '22 at 14:40
  • Read the Digital Signing section. Combine all the ordered parameter keys as key + value (no spaces, no delimiters). Let's call this the parameter string, see the example there on how the params should be formatted. – haxtbh Apr 08 '22 at 04:51
  • I have formatted things multiple different ways. Digital signing works fine for Account Balances when String is {}. But no good when Sending BUY/SELL Paramaters as shown in document. Perhaps you could post a code example if you have it working? – Merle_the_Pearl Apr 08 '22 at 15:45
  • `I have formatted things multiple different ways` It doesn't sound like you've tried the way the documentation mentions: *"Combine all the _ordered_ parameter keys as `key + value` (no spaces, no delimiters)..."* (not as json). Since what you've tried so far hasn't worked, try that. – SOS Apr 08 '22 at 23:08
  • I can get that working for account. private/get-account-summary121qerXoZW8Cw75583kiSMqjpcurrencyXLM1649542559242 : But not on create order. private/create-order121XXXXoZW8Cw75583kiSMqjpinstrument_nameXLM_USDTsideselltypemarketquantity2001649542228552 : also tried private/create-order121XXXXoZW8Cw75583kiSMqjpinstrumentnameXLMUSDTsideselltypemarketquantity2001649542228552 – Merle_the_Pearl Apr 09 '22 at 22:17
  • The docs say *"Combine all the **ordered** parameter keys..."* – SOS Apr 20 '22 at 13:55
  • Sending this for key (it is in AlphaBetOrder) - All Required Parameters Present: private/create-order121XXXXoZW8Cw75583kiSMqjpinstrument_nameXLM_USDTsideselltypemarketquantity2001650651117582 – Merle_the_Pearl Apr 22 '22 at 18:34

1 Answers1

0

Cracked it finally. Worked backwards to the Account Summary working. Might have been capital letters for SELL and MARKET.

I just used simple cfsets to arrange the strings in alphabetical order as well.

<cfset unixdatetimeNow = dateConvert( "local2Utc", now() )>

<cfset pl = "instrument_nameXLM_USDTquantity5000sideSELLtypeMARKET">

<cfset strp = '{"instrument_name": "XLM_USDT","quantity": 5000,"side": "SELL","type": "MARKET"}'>

<cfscript>
  apiKey = "#cr_key#";
  apiSecret = "#cr_s#";

  hmacm = #req_path# & 121 & apikey & #pl# & #unixdatetimeNow.getTime()#;

  CrHex = hmac(hmacm, apiSecret, "HmacSHA256");

  theKeyBytes = charsetDecode(ApiSecret, "UTF-8");
  crsign = lcase(hmac(hmacm, apiSecret, "HmacSHA256"));

</cfscript>

<cfset fullbody = '{"api_key": "#cr_key#","id": 121,"method": "#req_path#","params": #strp#,"sig": "#crsign#","nonce": #unixdatetimeNow.getTime()#}'>

<CFHTTP METHOD="POST" URL="#base_api##req_path#" result="result">
<cfhttpparam type="header" name="Content-Type" value="application/json">
<cfhttpparam type="body" value="#fullbody#">
</cfhttp> 
Merle_the_Pearl
  • 1,391
  • 3
  • 18
  • 25