What is the best way to retrieve CoinEx API using access ID and secret key in JavaScript?

Having trouble fetching account information using the CoinEx API and encountering an error.

For more information on the API, please visit:

API Invocation Description

Acquire Market Statistics

Inquire Account Info

Note : This account is only for test purposes (Sharing access ID and secret key publicly).

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

Outcome : Signature issue detected.

Answer №1

When hashing with MD5, it appears that you are only hashing the secret key.

The provided link specifies that you should hash either the entire query string, including the arguments in sequence (as outlined in the "Generate String To Sign" section).

It is recommended to perform the following steps:

let queryString = "access_id="+AccessID+"&tonce="+ServerTime+"&secret_key="+SecretKey
let Signature=CryptoJS.MD5(queryString).toString().toUpperCase();

Next, append the queryString to the URL argument in your fetch() function.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unpredicted organization when combining react, mapbox-gl, custom layer, and three.js

I am currently working on utilizing mapbox gl to showcase gltf buildings through a custom layer. Additionally, I am displaying the default 3d-buildings provided by mapbox in this manner: export default { id: '3d-buildings', source: 'c ...

What purpose does the additional symbol "$()" serve in the selector "$($())"?

Currently, I am looking to incorporate a jQuery scrollspy feature into one of my ongoing projects. Upon coming across this jsfiddle (https://jsfiddle.net/mekwall/up4nu/), I successfully integrated it into my project. However, I have hit a roadblock while ...

Exploring the versatility of multi-dimensional arrays using JSON encoding

Here are the scripts I've written in Python and PHP to multiply two matrices in a Python file. $arr2=array(array(array(1,2),array(3,5)) ,array(array(4,6)array(2,7))) echo json_encode($arr2); $rtu= shell_exec("C:/Python27/python 1234.py ".json_encode( ...

A perfectly organized and justified menu with evenly spaced horizontal list items

I couldn't find a solution to evenly spacing out a series of list items for a menu styled list. After realizing CSS alone wasn't enough, I decided to incorporate some javascript (jQuery). My goal was to have equal padding between each LI without ...

What steps should I take to address and resolve this problem with my Angular $scope?

One of my partials utilizes a single controller named CaseNotesCtrl. However, I am encountering difficulties accessing $scope variables within this partial. Below is the code snippet: <div class="row" ng-show="$parent.loggedin" ng-controller="CaseNotes ...

Using OctoberCMS to perform database queries and retrieve data in JSON format

I created a database table named categories with the following columns: id name types active ID - INT, auto increment NAME - VARCHAR TYPES - JSONABLE ACTIVE - INT Here is an example of a record in the database: 1 | Test Category | ["1","2"] | 1 2 | A ...

Is it possible to dynamically change HTML content by utilizing a JSON file?

Looking to implement a JavaScript loop (using jQuery) that can dynamically populate the HTML file with content from a JSON file based on matching <div> ids to the JSON "id" values. The solution should be scalable and able to handle any number of < ...

Issues with managing multiple user sessions in express-session

I've been struggling with an issue for a few days now and haven't been able to find a solution. I've scoured forums and documentation, but nothing seems to work. I have a website built in Node.js, using express-session and passport for sessi ...

Steps to display the Sidebar on top of the main information page

One unique feature of my website is the FiltersSideBar located on the left side of the page. It contains various filters to refine search results. To optimize user experience, I implemented a function that hides the sidebar at specific browser window size ...

Is it possible to create a personalized serialize form when sending an AJAX POST request

How can I format form data on an AJAX POST request differently than the default $("#formid").serialze()? The current result is not suitable for my needs, as it looks like this: `poststring="csrfmiddlewaretoken=bb9SOkN756QSgTbdJYDTvIz7KYtAdZ4A&colname= ...

Creating an animated link with a dynamic underline featuring a trio of vibrant colors

I'm having trouble figuring out how to animate my links on hover with 3 different colors. I attempted using the linear-gradient property but it doesn't seem to be working. Any suggestions on how to proceed? Below is an example of what I'm a ...

Activate audio and trigger notification

I'm looking to incorporate a small beep sound into my web application before displaying an alert message. Here's what I currently have: if(_none_valid) { $.playSound('/static/wav/beep_error.wav').delay(300); alert('ERROR: ...

Issue with incremental static generation in version 13 not functioning as expected

Is ISR working for anyone in the NextJS 13 Beta version? I have set revalidate to 15 as follows. export const revalidate = 15; However, even after running `npm run build`, the page still remains a statically generated site (SSG). The symbol is showing u ...

How come my Python script encounters UnicodeDecodeError in IntelliJ but runs without any issues when executed in the command line?

My program has a simple task of loading a .json file that includes a unique character. While the program runs smoothly in Terminal, I encounter an error in IntelliJ: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 2 ...

Tips for conducting a simultaneous test on several devices

Struggling to execute a single test script on multiple devices, regardless of efforts. There is one test apk and script obtained from a website as a sample. The script locates a textbox in the application, enters "Hello World!" into it, then completes the ...

``Can you please explain how one can retrieve data from a website using a script

I am looking to develop a script that can track prices on a travel website. I don't have any issues with extracting the data from a file ... but I'm unsure how to automate retrieving the entire site with that information. Here is the command I ...

Tips for adjusting the header color in materialize framework?

I've been working on a web template and I'm looking to customize the color displayed in the Android browser (maybe using JS?). The default color is blue. How can I go about changing it? https://i.sstatic.net/RxLbS.jpg Appreciate any help! ...

The project is not being recognized by 'webpack' when running within it

Every time I attempt to execute 'webpack' in my project, the command line shows me this error message: 'webpack' is not recognized as an internal or external command, operable program or batch file. I have installed webpack using th ...

Tips on avoiding redirection when submitting a form

Upon making an AJAX call to a page, I receive a form with user parameters. This form is later submitted to a URL in order to create a session for the same user in advance. When that person visits the site, they should see their name displayed. To achieve ...

Transform the column's datetime into a date in the where condition when using sequelize

Hey there, I'm looking to convert a datetime column into just date format while running a query. Could someone assist me with creating a Sequelize query based on the example below? select * from ev_events where DATE(event_date) <= '2016-10- ...