Skip to content

NodeJs wrapper for the Wazirx exchange REST and WebSocket APIs.

License

Notifications You must be signed in to change notification settings

rinoldev/wazirx-connector-nodejs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wazirx NodeJS

Npm Version

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

Notice

We are now at 1.0 and there may be things breaking, don't hesitate to raise an issue if you feel so!

Installation

Generate API KEY and Secret Key from Wazirx website here

Clone the repo and run the

npm install

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
    • Call connect method for initiating connection
    • Single and multiple streams supported
    • All methods runs with await call inside async function

Planned

  • Exception handling with responses
  • High level abstraction

Getting Started

REST Client

Require Wazirx Node Rest Client:

const { Client } = require('@wazirx/node-client').v1;

Create a new instance of the REST Client:

// If you only plan on touching public API endpoints, no need to pass any arguments
let client = new Client();
// Otherwise provide an apiKey and secretKey as keyword arguments
let client = new Client(apiKey, secretKey);

Create various requests:

General Endpoints

Ping

client.ping

Response:

{ data: {}, status: 200 }

Server time

client.time

Response:

{ data: { serverTime: 1641952885079 }, status: 200 }

System status

client.systemStatus

Response:

{
  data: { status: 'normal', message: 'System is running normally.' },
  status: 200
}

Exchange info

client.exchangeInfo

Response:

{
  data: {
    "timezone": "UTC",
    "serverTime": 1641952969748,
    "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.order({symbol: 'btcinr', side:'buy', type: 'limit', recvWindow: 10000, quantity:1, price:50});

Response:

{data:{"id"=>27007862, "symbol"=>"btcinr", "type"=>"limit", "side"=>"buy",
"status"=>"wait", "price"=>"210.0", "origQty"=>"1.0", "executedQty"=>"0.0",
"createdTime"=>1632310960000, "updatedTime"=>1632310960000}}
For other methods follow this.
For example and better understanding the api client usage refer here

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

WebSocket Client

Require Wazirx Node WebSocket Client:

const { WsClient } = require('@wazirx/node-client').v1;

Create a new instance of the REST Client:

# If you only plan on touching public API endpoints, you can forgo any arguments
let ws = new WsClient();
# Otherwise provide an api_key and secret_key as keyword arguments
let ws = new WsClient(apiKey, secretKey);

Make sure to call connect before start using other Methods

await ws.connect().catch((err) => {
  console.log(err);
});

Create various WebSocket streams:

  # Pass the symbol/symbols to subscribe to trades
  await ws.trades(['btcinr','wrxinr'], 0, 'subscribe');

  # Pass the symbol/symbols to subscribe to depth
  await ws.depth(['btcinr','wrxinr'], 0, 'subscribe');

  # For all market tickers
  await ws.allMarketTicker(['btcinr','wrxinr'], 0, 'subscribe');
Note:
  • symbol can be Array for multiple.
  • 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.

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

await ws.userStream(['orderUpdate', 'ownTrade', 'outboundAccountPosition'], 0, 'subscribe');
For other websocket methods follow this.
For example and better understanding the websocket client usage refer here

Development

After checking out the repo, run npm install to install dependencies. Then, run npm test to run the tests. You can also run node sample/index.js 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.

About

NodeJs wrapper for the Wazirx exchange REST and WebSocket APIs.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 50.7%
  • JavaScript 49.3%