<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: ɐʇɯon3ɹ</title>
    <description>The latest articles on DEV Community by ɐʇɯon3ɹ (@atmon3r).</description>
    <link>https://dev.to/atmon3r</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F561547%2F236acd96-f414-4c8f-841e-3d3b3375697a.jpg</url>
      <title>DEV Community: ɐʇɯon3ɹ</title>
      <link>https://dev.to/atmon3r</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/atmon3r"/>
    <language>en</language>
    <item>
      <title>Create bot for coindeal with nodejs - Part 1</title>
      <dc:creator>ɐʇɯon3ɹ</dc:creator>
      <pubDate>Sun, 29 Aug 2021 20:32:02 +0000</pubDate>
      <link>https://dev.to/atmon3r/part-1-create-bot-for-coindeal-with-nodejs-5a63</link>
      <guid>https://dev.to/atmon3r/part-1-create-bot-for-coindeal-with-nodejs-5a63</guid>
      <description>&lt;p&gt;&lt;a href="https://coindeal.com/" rel="noopener noreferrer"&gt;Coindeal&lt;/a&gt; is a recognized exchange platform. It allows you to trade from several cryptocurrencies.&lt;br&gt;
Like any good platform, coindeal has an API for developers that can be used to automate certain actions. &lt;/p&gt;

&lt;p&gt;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.&lt;br&gt;
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 &lt;/p&gt;
&lt;h4&gt;
  
  
  Requirement
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Valid coindeal account&lt;/li&gt;
&lt;li&gt;Nodejs and npm&lt;/li&gt;
&lt;li&gt;Some free time &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;From your coindeal account, you will need to generate a pair of keys for using the API, you can generate it from the tab:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Account -&amp;gt; API &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Floz9j7dg2460brkp33v6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Floz9j7dg2460brkp33v6.png" alt="Coindeal API account"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, from the api page, click on the button "Create new pair of key":&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpg0vlaejqlsbaecvgdpm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpg0vlaejqlsbaecvgdpm.png" alt="Coindeal API"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will see a window appear with your pair of keys, keep them preciously and never communicate them to anyone &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0pa10m5k6ru7ozfvj0lz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0pa10m5k6ru7ozfvj0lz.png" alt="Coindeal Keys"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Configuration
&lt;/h4&gt;

&lt;p&gt;Let's start by creating the bot project.&lt;br&gt;
For this, the base of nodejs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;coindeal-bot
&lt;span class="nb"&gt;cd &lt;/span&gt;coindeal-bot
npm init &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nano b64encode.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add this code by modifying the &lt;code&gt;{publicKey}&lt;/code&gt; and &lt;code&gt;{privateKey}&lt;/code&gt; values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;{publicKey}:{privateKey}&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;buff&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Buffer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;utf-8&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;base64&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;buff&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;base64&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;base64&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And run the script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node b64encode.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faa3vhbodde4y96cf1iv1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faa3vhbodde4y96cf1iv1.png" alt="b64 coindeal result"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You have obtained your final key which will be used from our bot to call the API &lt;/p&gt;

&lt;h4&gt;
  
  
  Start playing
&lt;/h4&gt;

&lt;p&gt;Let's create our bot!&lt;br&gt;
To begin with, we are going to retrieve some information from our account to see if the keys are working correctly. &lt;br&gt;
For this, we will use the &lt;a href="https://apigateway.coindeal.com/api/doc#operation/v1getWalletOperations" rel="noopener noreferrer"&gt;Get wallet operations&lt;/a&gt; endpoint of coindeal &lt;/p&gt;

&lt;p&gt;We will need a simple and efficient library to make the API calls, I chose &lt;a href="https://github.com/axios/axios" rel="noopener noreferrer"&gt;axios&lt;/a&gt;&lt;br&gt;
Let's install it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i axios
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create your bot file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nano myBot.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And add your first code:&lt;br&gt;
Attention, thinks to edit &lt;code&gt;{yourBase64Key}&lt;/code&gt; in headers of axios with your keys that we encrypted in the configuration step &lt;/p&gt;

&lt;p&gt;The base url for calling operations is this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://apigateway.coindeal.com/api/v1/wallets/{currency}/operations
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For this example, I used the currency "btc" but you can use any currency base.&lt;br&gt;
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&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;axios&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;axios&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getOperations&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;    
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;get&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://apigateway.coindeal.com/api/v1/wallets/btc/operations&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
            &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Authorization&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Basic {yourBase64Key}&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;accept&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;   
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;getOperations&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just run your bot:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node myBot.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb6wjzspb9mhv5tx28q7o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb6wjzspb9mhv5tx28q7o.png" alt="Coindeal result first call"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will see the trading transactions you made for the selected currency appear. &lt;/p&gt;

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

&lt;h4&gt;
  
  
  Info Links:
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://github.com/atmoner/coindeal-bot" rel="noopener noreferrer"&gt;https://github.com/atmoner/coindeal-bot&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://coindeal.com/" rel="noopener noreferrer"&gt;https://coindeal.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://apigateway.coindeal.com/api/doc" rel="noopener noreferrer"&gt;https://apigateway.coindeal.com/api/doc&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/axios/axios" rel="noopener noreferrer"&gt;https://github.com/axios/axios&lt;/a&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>coindeal</category>
      <category>cryptocurrency</category>
      <category>bot</category>
    </item>
  </channel>
</rss>
