How To Fetch CoinEx API With Access ID And Secret Key In JavaScript?

I Trying To Fetch CoinEx API And Get Account Info But I Receive Error .

API Documentation :

API Invocation Description

Acquire Market Statistics

Inquire Account Info

Note : This Account Is Only For Test (Sharing Access ID And Secret Key In Public)

<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/core.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/md5.js"></script>
<script>
let ServerTime=0;
let AccessID="61CFB9AB7F0B46B18F26EE2E3F155F4C";
let SecretKey="109E2A9E37DD4257D4C6DEDFE3F261A269EEB98DAA48B3E1";
let Signature=CryptoJS.MD5(SecretKey).toString().toUpperCase();

Process();
async function Process()
{
await MarketStatistics();
await AccountInfo(ServerTime,AccessID,SecretKey,Signature);
}

async function MarketStatistics()
{
let MarketStatistics_Fetch=await fetch("https://api.coinex.com/v1/market/ticker/all");
let MarketStatistics_JSON=await MarketStatistics_Fetch.json();

ServerTime=parseInt(MarketStatistics_JSON.data.date);
}

async function AccountInfo(ServerTime,AccessID,SecretKey,Signature)
{
let AccountInfo_Fetch=await fetch("https://api.coinex.com/v1/balance/info"+"?"+"access_id="+AccessID+"&"+"tonce="+ServerTime+"&"+"secret_key="+SecretKey,{method:"get",headers:{"authorization":Signature}});
let AccountInfo_JSON=await AccountInfo_Fetch.json();

alert(AccountInfo_JSON.message);
}
</script>
</html>

Result : Signature error.

Maybe I’m misunderstanding something here:

let Signature=CryptoJS.MD5(SecretKey).toString().toUpperCase();

First of all, I would expect the hash to already be a string, and wouldn’t converting it to uppercase corrupt the hash?

Might be this?

Use 32-bit MD5 Algorithm Signature

Use MD5 algorithm to encrypt the signature string, convert encrypted result to uppercase, get signature data and put signature data in HTTP Header - authorization:

authorization: C6F0DDA352101C2258F992A277397F4A

Here is how it looks in the example demo they have:

return crypto
  .createHash("md5")
  .update(text)
  .digest("hex")
  .toUpperCase();

Although, not knowing anything about the API I’m not sure if it’s even doing the same thing. It’s just what I found skimming through it.

1 Like

I’m doing anything they said in api documentation !

Sure, it just looked odd to me.

Might not just be you.

I didn’t test anything, just wanted to let you know.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.