Crypto.com API:创建订单



Crypto.com API不是很友好。

花了很长时间才获得账户余额授权。使用相同的技术,相同的编码,我无法创建订单。总是未经授权。

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

这对账户余额很有效。

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

这是HMACM正在被加密,其工作原理是:

private/get-account-summary121XXXXoZW8Cw75583kiSMqjp1649261460418

这个HMACM中没有参数,这些参数只在主体中{}。

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

但下面尝试一下订单。不管怎样,我都是未经授权的。

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

对于ORDER HMACM,我尝试了使用sparams(用于避免params变量(和不使用这两种方法

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

我已经为HMACM:尝试了这两种方法

private/create-order12XoZW8Cw75583kiSMqjp{"侧面":"出售","仪器名称":"XLM_USDT","数量":333,"类型":"市场"}1649261460418

私人/创建订单121XXXXoZW8Cw75583kiSMqjp1649261460418

按照顺序,我已经试过新手和试用版。使用相同的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>

我迷路了。我在30分钟内完成了一些交流。事实证明,Crypto.com API非常困难。

Crypto.com API文档链接。

https://exchange-docs.crypto.com/spot/index.html?csharp#private-创建订单

终于破解了它。向后工作到帐户摘要工作。可能是SELL和MARKET的大写字母。

我只是使用了简单的cfset来按字母顺序排列字符串。

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

最新更新