Menu
Development

How to build a Crypto Pump and Dump Trading Bot using Discord

I have discovered a crypto pump and dump trading group called “KuCoin Pump Signal” at the Discord chat platform, somewhere in July 2021.

Since I have already been deeply involved into crypto trading and mining, I came with an idea on how to build a crypto pump and dump trading bot, by using this kind of chat group to get the crypto coin name immediately after a signal appears and place the orders at KuCoin exchange.

For those who haven’t had a chance to trade with crypto, this kind of trading behaviour is mostly planned.

Pump and Dump (P&D) is a common scheme used in cryptocurrency trading that involves inflating the price of an owned cryptocurrency through misleading statements, in order to sell the cheaply purchased cryptocurrency at a higher price.

Source: Wikipedia

First of all, I started analysing the first pump and waiting for the coin name to appear in the chat group at the planned time and then – manually placing orders at KuCoin.

My first crypto coin trade, using a signal triggered on 02.10.2021. at 07:00 PM
My first pump and dump trading, using a signal triggered on 02.10.2021. at 07:00 PM

I have placed market buy order at DINO-USDT trade with a stake of 100 USDT (≈$100). Immediately after the market order had been filled, I placed another sell limit order, with an increased target price of 20% (while their projected gain was 500-900%).

A few seconds later, when I realised that I had already placed my buy order too late and that the price drops down every second, I panically canceled my sell limit order and sold everything by the market type of sell order. Lost 37 USDT. Lesson learned.

After a disappointing failure, a week later I have tried the strategy once more and it returned with negative profit again. I knew I’ve done something wrong, as there were tons of users in the chat group, posting their success trades with profits over $5k.

Therefore, I decided to find a way to programmatically fetch the coin name and automate the trades at KuCoin crypto exchange platform using their API.

Developing the bot – attempt #1

I started analysing HTTP traffic going from my browser to Discord chat platform. Of course, I have been trying to get the fastest route to the coin signal as possible. While scanning the requests at Discord, I have discovered that, after the Discord chat group webpage has been loaded, it triggered a GET request.

https://discord.com/api/v9/channels/{CHANNEL_ID}/messages?limit=50

I quickly copied the whole request as cURL and did a paste into Postman. There were also a few additional (required) header parameters in this request.

Discord request required 3 header parameters - Accept, Authorization, Referer
Discord request required 3 header parameters Accept, Authorization and Referer

I realised that I could change the GET parameter limit from 50 to 1 and actually get the latest Discord chat group message posted. The response was very useful.

Discord response returned what I actually wanted - the coin name DINO
Discord response returned what I actually wanted – the coin name DINO

have written a Node.js script that will be executed 10-15 seconds before the coin pump signal. A code is using axios promise-based dependency to send a request to Discord public API over and over again until it finds a matching phrase.

I used regex to find a USDT matching pair from data[0].content value
I used regex to find a USDT matching pair from data[0].content value

And it worked! I could easily fetch the coin name once the signal triggers at the exact planned time, in less than a second!

I had to go to the KuCoin API docs and do a little research on how to programatically place limit and market orders using Node.js. Their documentation is well written, for both newbies and professionals in trading.

https://docs.kucoin.com/#place-a-new-order

I decided to go with a market buy order, immediately after I receive the coin name signal from Discord chat group.

I have used kucoin-node-sdk package for placing buy orders at the API.

Function for placing market buy orders at KuCoin API
Function for placing market buy orders at KuCoin API

After the order has been created and filled, the script will fetch the order details and check if it is either filled or not. Then it will get its fill price and amount of filled coins, then forward the data to the limit sell order function with the same amount of coins, but with an increased price by 20% (later specified by the script parameter).

Looping the function until the market order has been filled
Looping the function until the market order has been filled
Placing a limit sell order at KuCoin API
Placing a limit sell order at KuCoin API

After testing the pump & dump situation, using a fake/mock signal in my own Discord group, then forwarding the coin name to the script and finally – placing the orders at the KuCoin sandbox environment, I realised that the bot was actually performing really wonderful.

Total execution time was 891ms since the script got the coin name signal from Discord.
Total execution time of pump and dump trading was 891ms since the script got the coin name signal from Discord.

Immediately after receiving a Discord group coin name signal, the script placed a market buy order at KuCoin in 383ms, fetched the order details, did the calculations and successfully placed a new limit sell order in 508ms.

And BOOM! After I had started the bot on the real pump signal at the Discord group on 23.10.2021, I returned with a profit of 23.91% (the stake was 200 USDT).

Improving the bot speed – attempt #2

After doing a brief testing and research, I had noticed that I could easily replace all API GET request information with a live web socket. I had done two things that would speed up the bot a bit more:

  • Replace Discord API with Discord web socket (for fetching the coin signal message in real time)
  • Use KuCoin web socket to get the order details after it has been successfully filled

I have found a web socket connection while inspecting requests in my browser. Therefore I quickly realised that the socket receives a new message every time someone posts into a Discord chat group. So, let’s focus on that WS request.

Discord opened a live socket connection immediately after the page has loaded

Obviously, receiving data was encoded. So I reverse-engineered the Discord Javascript file and found a way to decode the data, parse it and use for my bot.

So, let’s first create a web socket connection to Discord.

Socket request had compress=zlib-stream query string parameter included, so I installed zlib-sync.

Afterwards, I have created onmessage callback where I would actually read live socket messages, decode them and retrieve the coin name signal from Discord chat group message by parsing the result with a regular expression. Also, it was required to send an authorization token as a reply to the first heartbeat message from Discord.

After a successful connection, I needed to send an authorization token in order to get the Discord chat group messages.

This worked perfectly after sending a simple test message to my own Discord group. The script successfully established a web socket connection to Discord with a valid authorization, and got the token name by parsing the RegEx.

Let’s now focus on the KuCoin web socket listed on their documentation page. The following code will actually replace my previous processOrder() API call function with a live socket.

I have decided to usekucoin-node-sdk dependency again to get the details or changes of my latest crypto buy order.

I have subscribed to the KuCoin’s private order change event to get the data of my order

Finally, after wrapping up all the things I mentioned above, I had decided to test the bot on the next real KuCoin Pump and Dump signal from the Discord group, and it worked.

It returned me a profit of 11.94%, while the stake was 450 USDT. What a brilliant buy/sell trade in less than 1 second!

Relocating VPS server – attempt #3

After I had finally deployed my bot to the production, I came up to an idea on how to optimise the script a little bit more by using the VPS server in the closest datacenter to Discord and KuCoin location as possible.

After purchasing and trying 36 Linux VPS servers in several continents, different countries, among various datacenters and providers (AWS, DigitalOcean, Google, Linode, Vultr, etc), overall the fastest VPS cloud provider was DigitalOcean (in the FRA1 datacenter), returning responses from Discord and KuCoin in less than 1 millisecond.

Response time provided by pinging discord.com (routed behind CloudFlare)
Response time provided by pinging discord.com (routed behind CloudFlare)
Besides KuCoin was routed over CloudFlare as well, ping and HTTP API responses were really impressive
Besides KuCoin was routed over CloudFlare as well, ping and HTTP API responses to api.kucoin.com were really impressive

Dependencies used:

  • axios (fetching web requests)
  • kucoin-node-sdk (accessing the KuCoin API)
  • uuid (generating unique uuidv4 for KuCoin orders)
  • lodash (helper functions for string and object manipulation)
  • minimist (providing input parameters/arguments to the script)
  • ws (web socket for Discord and KuCoin)
  • erlpack, zlib-sync (decoding Discord web socket response messages)

DISCLAIMER: This article is meant for educational purposes only. Therefore I’m not responsible for any harm/illegal activity that may happen.

5 Comments

  • Robin
    December 24, 2021 at 2:08 am

    bot is sick! You broke down the steps so clearly

    Reply
  • Isidora
    June 14, 2022 at 11:34 am

    I’ve been trading with software for a while now and it’s been working great! I’ve been able to make a lot of money with it and I’m really happy with the results.

    Of course, had to do a bit of improvements, but the base code is helpful.

    Reply
  • Tommy
    October 10, 2022 at 7:16 am

    You could have just asked Kucoin where they are hosted. They would have told you AWS tokyo. AWS has 11 data centers in Tokyo but there is a way to get your instance in the same one.

    Reply
  • CryptoGuruZ
    December 27, 2022 at 1:15 am

    The process you followed to create a crypto pump and dump bot is just fckn IMPRESSIVE! Thanks for sharing your knowledge and insights.

    Reply
  • boostaro
    January 9, 2024 at 6:36 am

    Thank you so much!

    Reply

Leave a Reply to Robin Cancel Reply