• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Crypto.com API : Create Order

New Here ,
Jun 25, 2022 Jun 25, 2022

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

Views

183

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 26, 2022 Jun 26, 2022

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:

  • via a GET (as part of the URL variable hmacm);
  • via a POST (as part of the newbody variable).

 

The link you've provided suggests that:

  1.  the HTTP POST should be to a URL that ends in .../private/create-order
  2.  the body should contain something like 
    <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>​

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 13, 2022 Jul 13, 2022

Copy link to clipboard

Copied

LATEST

Have you solved the problem?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation