Wazirx

Gem Version

This is an official Ruby wrapper for the Wazirx exchange REST and WebSocket APIs.

Notice

We are now at 1.0 and there are breaking changes, mainly with some method names and the casing of keys. Be sure to check out the code while I work on better documentation.

Installation

Add this line to your application's Gemfile:

gem 'wazirx'

And then execute:

$ bundle

Or install it yourself as:

$ gem install wazirx

Features

Current

  • Basic implementation of REST API
    • Easy to use authentication
    • Methods return parsed JSON
    • No need to generate timestamps
    • No need to generate signatures
  • Basic implementation of WebSocket API
    • Pass procs or lambdas to event handlers
    • Single and multiple streams supported
    • Runs on EventMachine

Planned

  • Exception handling with responses
  • High level abstraction

Getting Started

REST Client

Require Wazirx:

require 'wazirx'

Create a new instance of the REST Client:

# If you only plan on touching public API endpoints, you can forgo any arguments
client = Wazirx::Client::REST.new
# Otherwise provide an api_key and secret_key as keyword arguments
client = Wazirx::Client::REST.new api_key: 'x', secret_key: 'y'

Create various requests:

General Endpoints

Ping

client.ping

Response:

{}

Server time

client.time

Response:

{
    "serverTime": 1632375945160
}

System status

client.system_status

Response:

{
    "status": "normal",
    "message": "System is running normally."
}

Exchange info

client.exchange_info

Response:

{
    "timezone": "UTC",
    "serverTime": 1632376074413,
    "symbols": [
        {
            "symbol": "wrxinr",
            "status": "trading",
            "baseAsset": "wrx",
            "quoteAsset": "inr",
            "baseAssetPrecision": 5,
            "quoteAssetPrecision": 0,
            "orderTypes": [
                "limit",
                "stop_limit"
            ],
            "isSpotTradingAllowed": true,
            "filters": [
                {
                    "filterType": "PRICE_FILTER",
                    "minPrice": "1",
                    "tickSize": "1"
                }
            ]
        }
    ]
}

Create an order

client.create_order! symbol: 'btcinr', side: 'buy', type: 'limit',
  quantity: '100.00000000', price: '0.00055000', recvWindow: 1000

Response:

{"id"=>27007862, "symbol"=>"btcinr", "type"=>"limit", "side"=>"buy",
"status"=>"wait", "price"=>"210.0", "origQty"=>"2.0", "executedQty"=>"0.0",
"createdTime"=>1632310960000, "updatedTime"=>1632310960000}

Required and optional parameters, as well as enum values, can currently be found on the Wazirx GitHub Page. Parameters should always be passed to client methods as keyword arguments in snake_case form.

WebSocket Client

Require Wazirx and EventMachine:

require 'wazirx'
require 'eventmachine'

Create a new instance of the WebSocket Client:

client = Wazirx::Client::WebSocket.new

Create various WebSocket streams, wrapping calls inside EM.run:

EM.run do

  # Pass the symbol/symbols to subscribe to trades
  client.trades symbol: ['btcinr','wrxinr'], id: 0, action: 'subscribe'

  # Pass the symbol/symbols to subscribe to depth
  client.depth symbol: ['btcinr','wrxinr'], id: 0, action: 'subscribe'

 # For all market tickers
 client.all_market_ticker id: 0, action: 'subscribe'

end
Note:
  • symbol can be Array for multiple symbols or String for single symbol.
  • id by default is 0, for unique identification any positive integer can be used.
  • action only needs to pass in case of unsubscribe, default is subscribe if no data passed.

User Data Stream

User data streams utilize both the REST and WebSocket APIs.

Require Binance and EventMachine:

require 'wazirx'
require 'eventmachine'

Create a new instance of the REST Client and WebSocket Client:

ws    = Wazirx::Client::WebSocket.new api_key: 'x', secret_key: 'y'

Request a listen key from the REST API, and then create a WebSocket stream using it.

EM.run do
  ws.user_stream streams: ['orderUpdate', 'ownTrade', 'outboundAccountPosition', id: 0, action: 'subscribe']
end

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Contributing

Bug reports and pull requests are welcome on GitHub at Issues.

License

The gem is available as open source under the terms of the MIT License.