Setting up Ranger service

Setting up Ranger service

We are pleased to announce that Ranger has arrived to Peatio 1.9, Ranger is a WebSocket service that handles Peatio's notification system for Trading UI and more, it's a complete replacement of Slanger that we used until version 1.9.

This post's goal is to show how easy it is to setup Ranger and test new Trading UI using workbench without any modifications.

The tutorial is aimed for workbench users, but it can be used for users with customized manual installations using almost the same instructions.

Grab the upgrade

Change working directory to your workbench repository, update your workbench's master branch:

$ git checkout master
$ git pull --rebase origin master

Now we need to update Git submodules which include backend microservices and Trading UI:

$ make update

Great, after that you will see that Git submodules were checked out to latest changes and now you can start the workbench containers:

$ make start

NOTE: it will take some time for building new Docker images.

After successful start you can visit your Trading UI using your favorite browser:

http://api.wb.local/

Authorize in Barong and proceed to take a look at Trading UI with working notification system:

http://api.wb.local/trading/eurusd

Your browser will connect to ws.ranger.wb.local and will read all the notification that you get from Peatio such as new bids/asks, trades, orders and global updates of markets.

Enable WebSocket Secure Layer

By default Trading UI connects to Ranger without using SSL, but you can change this behavior if your exchange supports https connections, open config/peatio.env file using your favorite editor in workbench's repository and edit following line:

RANGER_HOST=ws://ws.ranger.wb.local

to

RANGER_HOST=wss://ws.ranger.wb.local

replace ws:// with wss://

Nginx as frontend webserver for Ranger

You ask, we answer.

Yes, you can set any webserver in front of Ranger, you just need to configure it properly, here is an example of configuration using most famous web server — Nginx.

Add following `server` snippet into your `http` directive in your nginx.conf:

server {
    listen 0.0.0.0:10000;
    location / {
        proxy_pass http://ws.ranger.wb.local;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
    }
}

In given snippet we declare listening server on 10000 port that forwards network traffic to local backend service — ws.ranger.wb.local.

NOTE: do not forget to change RANGER_HOST configuration variable to yourdomain.com:10000 to apply changes for Trading UI.

Developers docs

If you want to know what information we send, how we encode it or just take a look at architecture overview, then you need to visit docs on GitHub: [WebSocket API docs](https://github.com/rubykube/peatio/blob/master/docs/api/websocket_api.md)

Still have questions or got some troubles with setting up? Get help in our Telegram channel: @peatio

Images via Shutterstock, Pixabay, and Bitstamp.