Create bot for coindeal with nodejs - Part 1
Tags: node, coindeal, cryptocurrency, bot
Published: 2021-08-29 20:32:02

[Coindeal](https://coindeal.com/) 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/loz9j7dg2460brkp33v6.png)

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

![Coindeal API](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pg0vlaejqlsbaecvgdpm.png)

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

![Coindeal Keys](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0pa10m5k6ru7ozfvj0lz.png)

#### Configuration 

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

```shell
mkdir coindeal-bot
cd coindeal-bot
npm init -y
```

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 

```shell
nano b64encode.js
```

Add this code by modifying the `{publicKey}` and `{privateKey}` values:
```js
const str = '{publicKey}:{privateKey}';
const buff = Buffer.from(str, 'utf-8');
const base64 = buff.toString('base64');

console.log(base64);
```

And run the script:
```shell
node b64encode.js
```
![b64 coindeal result](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aa3vhbodde4y96cf1iv1.png)

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](https://apigateway.coindeal.com/api/doc#operation/v1getWalletOperations) endpoint of coindeal 

We will need a simple and efficient library to make the API calls, I chose [axios](https://github.com/axios/axios)
Let's install it:
```shell
npm i axios
```

Create your bot file 
```shell
nano myBot.js
```

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

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 


```js
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();
```

Just run your bot:
```shell
node myBot.js
```
![Coindeal result first call](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b6wjzspb9mhv5tx28q7o.png)

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