logo

Ranger development guide

#Repository

git clone https://github.com/rubykube/peatio-core.git

#Quick Start

Install dependencies

Make sure you have ruby and ruby-gem package manager installed on you machine.

$ ruby --version
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
$ gem --version
3.0.4
$ bundler --version
Bundler version 1.17.3

If ruby or gem is missing please refer to your OS documentation to install them (or install them using RVM).

If bundler is missing you can install it by running:

gem install bundler

Finally install ranger dependencies:

bundle install

Generate a key pair

./bin/peatio security keygen

Start ranger

Make sure you have a local RabbitMQ server running, then run the following commands to start ranger.

export JWT_PUBLIC_KEY=$(<secrets/rsa-key.pub | base64 -w0)
./bin/peatio service start ranger

#Connect to public channels

wscat --connect "localhost:8081?stream=global.tickers&stream=eurusd.trades"

Inject fake messages

./bin/peatio inject peatio_events

After injecting messages you should see a public trade event in wscat output.

#Authenticate to Ranger

Forge a JWT

In a ruby console (irb) run the following commands to generate a 10 hours valid JWT:

require "openssl"
require "jwt"
secret_key = OpenSSL::PKey.read(File.read("secrets/rsa-key"))
jwt_algo = "RS256"

payload = {
    "iat": Time.now().to_i,
    "exp": Time.now().to_i + 36000, # Expires in ten hours
    "sub": 'session',
    "iss": 'barong',
    "aud": [ 'peatio', 'barong' ],
    "jti": '1111111111',
    "uid": 'IDABC0000001',
    "email": '[email protected]',
    "role": 'admin',
    "level": 3,
    "state": 'active',
    "referral_id": nil
}

puts JWT.encode(payload, secret_key, jwt_algo)

Then, store the output JWT in a shell variable and connect to ranger:

JWT="eyJhbGciOiJSUzI1NiJ9...."

wscat -H "authorization: Bearer ${JWT}" --connect "localhost:8081?stream=global.tickers&stream=order&stream=trade"

Inject fake messages

./bin/peatio inject peatio_events

After injecting messages you should see a private order and trade event in wscat output.