DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Create bot for coindeal with nodejs - Part 1
ɐʇɯon3ΙΉ
ɐʇɯon3ΙΉ

Posted on

Create bot for coindeal with nodejs - Part 1

Coindeal is a recognized exchange platform. It allows you to trade from several cryptocurrencies.
Like any good platform, coindeal has an API for developers that can be used to automate certain actions.

I will explain how to use the coindeal api using nodejs. In this first part, we will retrieve the information from our coindeal with a simple code.
in the second part, we will see how to automate buy and sell actions and let our bot run so that it brings us money

Requirement

  • Valid coindeal account
  • Nodejs and npm
  • Some free time

From your coindeal account, you will need to generate a pair of keys for using the API, you can generate it from the tab:

Account -> API

Like this:

Coindeal API account

Then, from the api page, click on the button "Create new pair of key":

Coindeal API

You will see a window appear with your pair of keys, keep them preciously and never communicate them to anyone

Coindeal Keys

Configuration

Let's start by creating the bot project.
For this, the base of nodejs:

mkdir coindeal-bot
cd coindeal-bot
npm init -y
Enter fullscreen mode Exit fullscreen mode

Here is our project ready to start!
The first step will be to convert our keys to base64, this is necessary for authentication to the API.
For that, we will create a file which will only be used for the conversion of the keys

nano b64encode.js
Enter fullscreen mode Exit fullscreen mode

Add this code by modifying the {publicKey} and {privateKey} values:

const str = '{publicKey}:{privateKey}';
const buff = Buffer.from(str, 'utf-8');
const base64 = buff.toString('base64');

console.log(base64);
Enter fullscreen mode Exit fullscreen mode

And run the script:

node b64encode.js
Enter fullscreen mode Exit fullscreen mode

b64 coindeal result

You have obtained your final key which will be used from our bot to call the API

Start playing

Let's create our bot!
To begin with, we are going to retrieve some information from our account to see if the keys are working correctly.
For this, we will use the Get wallet operations endpoint of coindeal

We will need a simple and efficient library to make the API calls, I chose axios
Let's install it:

npm i axios
Enter fullscreen mode Exit fullscreen mode

Create your bot file

nano myBot.js
Enter fullscreen mode Exit fullscreen mode

And add your first code:
Attention, thinks to edit {yourBase64Key} in headers of axios with your keys that we encrypted in the configuration step

The base url for calling operations is this:

https://apigateway.coindeal.com/api/v1/wallets/{currency}/operations
Enter fullscreen mode Exit fullscreen mode

For this example, I used the currency "btc" but you can use any currency base.
Obviously, to have a result of the call, you will have to have done some btc trade, otherwise, adjust the value by the currency you use the most

const axios = require('axios');

async function getOperations() {    
    const config = {
        method: 'get',
        url: 'https://apigateway.coindeal.com/api/v1/wallets/btc/operations',
        headers: { 
            'Authorization': 'Basic {yourBase64Key}',
            'accept': 'application/json'
        }
    }   
    let res = await axios(config)
    console.log(res.data);
}

getOperations();
Enter fullscreen mode Exit fullscreen mode

Just run your bot:

node myBot.js
Enter fullscreen mode Exit fullscreen mode

Coindeal result first call

You will see the trading transactions you made for the selected currency appear.

This demonstrates the easiest way to make calls from the coindeal API.
Obviously, there is still a lot of endpoint to explore but we will see that in part 2

Info Links:

https://github.com/atmoner/coindeal-bot

https://coindeal.com/

https://apigateway.coindeal.com/api/doc

https://github.com/axios/axios

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.