Complete step-by-step guide on running a Nash trading bot via VPS
Just recently, Fabio released a simple maker bot to run on Nash. Since our community would like to help out in adding liquidity and/or volume, but doesn’t have the technical knowledge to set the bot up, I wanted to step in and provide you guys with a detailed guide on running this (or basically any) bot.
There are two ways to run this bot: either locally on your computer, or remotely via a VPS (Virtual Private Server, or simply put, a server in the cloud). The first option requires you to be online the entire time. Because if you turn off your computer, the script disconnects and the trading will halt. For this reason, it’s more convenient to run it on a VPS, so you can leave it running 24/7 without thinking about it.
This guide will only cover the VPS option, which costs $5 per month. If you rather run it locally, go to the repository and get it running on your local machine using some of the guidance in this article.
Step1: Setting up a VPS
In this guide I’m going to use DigitalOcean as an example. There are many more, but this is my preferred provider when I need a server. So for starters, sign up for an account (Disclaimer: the link contains my referral code. This way I get credits to host StakingNEX.io on, but of course feel free to remove it if you want. No hard feelings 😊):
Create a server
After signing up and completing the registration, you land on your dashboard. Click on the green ‘Create’ button on the top-right corner and select ‘Droplets’ (DigitalOcean’s way of naming their servers):
Now you’ll find yourself in the droplet creation section. This page contains several settings.
Choose an image: Select ‘Ubuntu — 18.04.3 (LTS) x64’. This is the default value.
Choose a plan: Select ‘Standard’, the default setting. For the pricing selector below, the default is set on $40 and it looks like that is the cheapest option, but there is an arrow pointing to the left on the $40 option. Click that to browse to the cheaper versions, and select the $5 option.
Add block storage: Leave it empty.
Choose a datacenter region: Select the region closest to you. It doesn’t matter if you select numbers 1, 2 or 3. These are just their different locations in that region. Since I live in Amsterdam, this is an easy pick for me.
VPC Network: Leave it on ‘No VPC’.
Select additional options: No selections needed.
Authentication: My preferred method is via SSH, this will let a key that runs on you computer authenticate your machine with the server when logging in, so you don’t need to enter a password every time. Instructions on setting that up are under the ‘New SSH Key’ button below that option or follow this detailed guide. If you don’t want to put in that extra effort and are just fine with entering a password upon logging in, choose the ‘Password’ option and provide one. This guide will follow this route for simplicity sake.
All further options can be left at their default. Click the big ‘Create Droplet’ button at the bottom.
After clicking, you’ll get redirected to the Droplets section of the site and you see a progress bar indicating the creation of your new server.
Connect to your server
After this is done, it is time to log into your server. The method for this depends on your platform. You need the IP address of your droplet to connect, this is located at the location we just saw the progress bar in during creation. Click on it to copy it automatically.
Mac OS: Press cmd+space, type ‘Terminal’ and hit enter to open the Terminal app. In there, type in:
Because it is the first time connecting to this server, it will prompt you the following:
The authenticity of host ‘184.108.40.206 (220.127.116.11)’ can’t be established. ECDSA key fingerprint is SHA256:[signature].
Are you sure you want to continue connecting (yes/no)?
Type in ‘yes’ to continue. It will now ask for your password that you specified. For safety reasons this is not showing while you type it out, so don’t panic when you don’t see anything change while typing. Press enter, and…. Congrats! You’re now logged in to your new server :)
Windows: Works sort of the same way as the above, but Windows doesn’t have something to connect via SSH to out of the box. No worries though, the internet is full with guides on how to connect to your server via SSH with PuTTY. If you don’t know your username: it’s ‘root’.
Step 2: Server configuration
It is not an advised method to work under the root user for security reasons. So if you like to play safe, follow this guide to set your server up properly. But because we’re only going to run a simple bot script, I’d say that it’s okay to leave it like this. If you plan to do more with your server, like hosting websites and such, following that guide is strongly advised.
Now for the real stuff…
This next part is going to consist of copy pasting several commands into the server to install all packages needed to run the bot. If it contains multiple lines, copy paste them one at a time. Sometimes along the way it will ask you ‘Do you want to continue? [Y/n]’. You can hit enter here, since it will then automatically select the uppercased Y.
Ready? Let’s go!
Update packages and install cURL
sudo apt update && sudo apt install curl
Install Node 10 & Yarn
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bashsudo apt install -y nodejsnpm install -g yarn
Install Git and clone the repository
sudo apt install gitgit clone https://github.com/canesin/pingpong.git && cd pingpong
Install the bot…
…And now, let’s run the bot!
node build/index.js btc_usdc prod
Cannot find module ‘../pingpong_prod_key.json’ ? Well okay, let’s create it!
Step 3: Create an API key on Nash
You were probably already thinking:
‘How the hell would the above command trigger a bot that acts upon my account? I didn’t provide any account details? ‘ - You
Well, this is where API keys come in. You generate one via your Nash account, and the secret cryptographic data it contains, holds the key to your account.
The creation process is quite simple:
Create a key: Head over to Nash’s API keys page. This page shows you all generated keys. Click on ‘Generate new key’.
A modal pops up. For security reasons, Nash asks you to provide your password and 2FA to make sure it is really you that is creating a key. After filling this in, it asks for a name that you want to associate this key with. Let’s call it ‘Simple Maker Bot’ and click ‘Create key’.
It will now generate your keys. After it is done, it asks you to provide withdraw addresses that you want this API key to whitelist. Click on ‘Add address’ and copy paste your preferred address. Be it BTC/NEO/ETH, it doesn’t really matter. The reason you’re doing this is that IF a third party gets access to your API key, he or she can only withdraw the whitelisted currency to the whitelisted address. So it is important that you provide one. Don’t worry: you can always add or update them later. Click ‘Continue’ when done.
It will now show you what you came for: the combination of your ‘API key’ and ‘secret’. Both are needed to operate on it, you cannot run the bot with only the key or secret. This will only be shown once, and therefore it is important that you save it. So let’s do that. Click on ‘Download API key and secret as JSON’ and name it ‘pingpong_prod_key.json’. It is important that the filename is exactly like this, otherwise the bot won’t work.
After you saved the JSON file as ‘pingpong_prod_key.json’, click on ‘I have saved my secret’.
The next step is depending on if you are using Mac OS or Windows, since we’re going to copy this new JSON file to your server.
Mac OS: Open the folder in Finder where you just downloaded the JSON file in. In Terminal, press cmd+t to open up a new tab. Now, type in
scp (including trailing space) and then go to Finder and drag the JSON file into Terminal. This will put in the path of the file. Hit the spacebar again and type
root@[ip-address]:/root/pingpong. Of course, replace
ip-address with your server’s address.
You will end up with a command that looks something like the following:
scp pingpong_prod_key.json firstname.lastname@example.org:/root/pingpong
After you entered your password, you will see some progress happening. You know it’s complete when you see 100%.
Windows: Works with almost exactly the same command, but uses
pscp instead of
scp at the beginning. The path to your JSON file can be copied by holding the Shift key, and right-clicking on the JSON and select ‘Copy as path’. If it doesn’t work, then I’m not sure since I’m not a Windows user. Maybe check out this guide.
Step 4: Run the bot!
The moment you’ve been waiting for has arrived. First check if your API key uploaded correctly by going back to the server tab in the terminal (or by pressing cmd+w to close the current one). Make sure you are in the pingpong directory (the name is shown next to where your typing cursor is), type
ls and hit enter. If you see your shiny ‘pingpong_prod_key.json’ in the list of files, you know it worked.
So here we are… Run the command you tried to run before creating the API key, and see what happens ;-) Of course, make sure your have balance in your trading contract.
node ~/pingpong/build/index.js btc_usdc prod
Congrats on your first API order! 🎉 Hopefully the first of many. In the command you entered, you see that you can specify the market to trade on. In this case it will run on BTC-USDC. You can change this to another market that you like, but it has to be in the configuration file, which I will talk about in the next section.
Also, if you still receive the ‘Insufficient funds’ error, you have some configuration to do.
Out of the box, the bot comes with some preconfigured settings. These are adjustable with the following command:
This opens up the configuration file in an application called Nano, the default text-editor of Ubuntu (the operating system your server is running on).
I’m not gonna dive into the details of configuration. That is something you have to figure out by yourself, or join the Telegram channel created for trading to discuss strategies. I’ve lowered the sizeupperlimit to 0.007 and sizelowerlimit to 0.003 on the BTC-USDC market. These values represent the value of the first currency in the market, in this case BTC. So 0.003 in my example is at this point of writing around $27. Adjust these upper and lower limits to your own liking.
After being done editing, press ctrl+x for the ‘Exit’ command. It will ask you if you want to save your modified buffer, which simply means if you want to save your changes. Press ‘y’ to answer with yes and hit enter on the filename question afterwards. It will use the current filename as default so we don’t want to change that.
Step 5: Letting the bot run while being offline
No point in setting up a VPS when you’re not taking advantage of it.
To utilize the advantage, we’re going to use an application called Screen. First, cancel the bot that is running by pressing ctrl+c. Be aware that stopping the bot doesn’t cancel your open order. So on Nash’s Orders page, cancel your open trade. Now go back to your terminal and type:
sudo apt install screen
To start a new screen session, simply type the ‘screen’ command.
Screen is mainly controlled through keyboard shortcuts. In this welcome screen, press spacebar or enter to continue.
After pressing a key, it looks like nothing really happened, but in reality you are now operating on a parallel screen, so to say. Start the bot again by going into the folder and running the command:
node ~/pingpong/build/index.js btc_usdc prod
After doing this, you can now safely ‘detatch’ from this screen by pressing cntrl+a+d. All the commands for Screen start with ctrl+a, followed by the first letter of the action. So in this case detach.
Now you are set to close your computer and do anything you like. If you get back and want to resume your session, enter
screen -r in the terminal. And voila, you’re back at your orders :)
If you want to stop the screen you are working in, type in
exit and hit enter.
Sometimes there are too many screens open by accident. To close them all off, enter the following:
This all might sound complicated, but you’ll get used to it in no time. As long as you remember how to detach and resume, you’ll be fine :)
Enjoy the ride. Also, if you found anything in this guide that doesn’t work, or works differently on your side, feel free to contact me on Telegram.