exir-node-lib
v1.0.1
Published
EXIR api and websocket library for nodejs
Downloads
6
Readme
exir-node-lib
Nodejs library for EXIR.io exchange.
This library is specifically for end users and traders to connect to pro.exir.io exchange. It connects to EXIR.io by default.
Usage
const exir = require('exir-node-lib');
const client = new exir();baseURL is set to default to /v2 unless you need to connect to an older version of EXIR.
To use private requests that require authentication, you should pass your apiKey and apiSecret generated from the Security page in your user account.
You can also pass the field apiExpiresAfter which is the length of time in seconds each request is valid for. The default value is 60.
Example:
const client = new exir({
apiKey: '<MY_API_KEY>',
apiSecret: '<MY_API_SECRET>'
});
client
.getTicker('btc-usdt')
.then((res) => {
console.log('The volume is: ', res.volume);
})
.catch((err) => {
console.log(err);
});
client
.getTrades({ symbol: 'btc-usdt' })
.then((res) => {
console.log('Public trades: ', res);
})
.catch((err) => {
console.log(err);
});Available functions:
| Command | Parameters | Description |
| - | - | - |
| getTicker | symbol: EXIR trading symbol e.g. btc-usdt | Last, high, low, open and close price and volume within the last 24 hours |
| getTickers | | Last, high, low, open and close price and volume within the last 24 hours for all symbols |
| getOrderbook | symbol: EXIR trading symbol e.g. btc-usdt | Orderbook containing list of bids and asks |
| getOrderbooks | | Orderbook containing list of bids and asks for all symbols |
| getTrades | opts: Object with additional paramsopts.symbol: (optional) EXIR trading symbol e.g. btc-usdt | List of last trades |
| getUser | | User's personal information |
| getBalance | | User's wallet balance |
| getDeposits | opts: Object with additional paramsopts.currency: (optional) Filter data set by assetopts.status: (optional) Filter data set statusopts.dismissed: (optional) Filter data set dismissedopts.rejected: (optional) Filter data set rejectedopts.processing: (optional) Filter data set processingopts.waiting: (optional) Filter data set waitingopts.limit: (optional, default=50, max=50) Number of items to getopts.page: (optional, default=1) Page number of dataopts.orderBy: (optional) Field to order data byopts.order: (optional, enum=[asc, desc]) Specify ascending or descending orderopts.startDate: (optional, format=ISO8601) Start date of data setopts.endDate: (optional, format=ISO8601) End date of data setopts.transactionId: (optional) Filter data set by TXIDopts.address: (optional) Filter data set by address | User's list of all deposits |
| getWithdrawals | opts: Object with additional paramsopts.currency: (optional) Filter data set by assetopts.status: (optional) Filter data set statusopts.dismissed: (optional) Filter data set dismissedopts.rejected: (optional) Filter data set rejectedopts.processing: (optional) Filter data set processingopts.waiting: (optional) Filter data set waitingopts.limit: (optional, default=50, max=50) Number of items to getopts.page: (optional, default=1) Page number of dataopts.orderBy: (optional) Field to order data byopts.order: (optional, enum=[asc, desc]) Specify ascending or descending orderopts.startDate: (optional, format=ISO8601) Start date of data setopts.endDate: (optional, format=ISO8601) End date of data setopts.transactionId: (optional) Filter data set by TXIDopts.address: (optional) Filter data set by address | User's list of all withdrawals |
| makeWithdrawal | currency: Currency code e.g. btcamount: Withdrawal amountaddress: Address to withdrawal toopts: Object with additional paramsopts.network: (required if asset has multiple networks) Blockchain network to create address for e.g. trx | Create a new withdrawal request |
| getUserTrades | opts: Object with additional paramsopts.symbol: (optional) EXIR trading symbol e.g. btc-usdtopts.limit: (optional, default=50, max=50) Number of items to getopts.page: (optional, default=1) Page number of dataopts.orderBy: (optional) Field to order data byopts.order: (optional, enum=[asc, desc]) Specify ascending or descending orderopts.startDate: (optional, format=ISO8601) Start date of data setopts.endDate: (optional, format=ISO8601) End date of data set | User's list of all trades |
| getOrder | orderId: EXIR Network Order ID | Get specific information about a certain order |
| getOrders | opts: Object with additional paramsopts.symbol: (optional) EXIR trading symbol e.g. btc-usdtopts.side: (optional, enum=[buy, sell]) Order sideopts.status: (optional) Filter data set statusopts.limit: (optional, default=50, max=50) Number of items to getopts.page: (optional, default=1) Page number of dataopts.orderBy: (optional) Field to order data byopts.order: (optional, enum=[asc, desc])opts.startDate: (optional, format=ISO8601) Start date of data setopts.endDate: (optional, format=ISO8601) End date of data set | Get the list of all user orders. It can be filter by passing the symbol |
| createOrder | symbol: EXIR trading symbol e.g. btc-usdtside (enum=[buy, sell]): Order sidesize: Size of order to placetype: (enum=[market, limit] Order typeprice: (required if limit order type) Order priceopts: Object with additional paramsopts.stop: (optional) Stop price for orderopts.meta: (optional) Object with additional meta configurationsopts.meta.post_only: (optional, default=false) Make post only order opts.meta.note: (optional) Custom note for order | Create a new order |
| cancelOrder | orderId: EXIR Network order ID | Cancel a specific order with its ID |
| cancelAllOrders | symbol: EXIR trading symbol e.g. btc-usdt | Cancel all the active orders of a user, filtered by currency pair symbol |
| getMiniCharts | assets: The list of assets to get the mini charts foropts.from: (optional) Start Dateopts.to: (optional) End Dateopts.quote: (optional) Quote asset to receive prices based on | Get trade history HOLCV for all pairs |
| getQuickTradeQuote | spending_currency: Currency symbol of the spending currencyreceiving_currency: Currency symbol of the receiving currencyopts.spending_amount: (optional) Spending amountopts.receiving_amount: (optional) Receiving amount | Get Quick Trade Quote |
| executeOrder | token: Token | Execute Order |
Websocket
Functions
You can connect and subscribe to different websocket channels for realtime updates.
To connect, use the connect function with the channels you want to subscribe to in an array as the parameter. The connection will reconnect on it's own unless you call disconnect.
client.connect(['orderbook', 'trade']);To disconnect the websocket, call disconnect.
client.disconnect();To subscribe to more channels after connection, use subscribe.
client.subscribe(['order', 'wallet']);To unsubscribe from channels after connection, use unsubscribe.
client.unsubscribe(['orderbook']);Channels
Here is the list of channels you can subscribe to:
orderbook(Available publicly)trade(Available publicly)order(Only available with authentication. Receive order updates)usertrade(Only available with authentication. Receive user trades)wallet(Only available with authentication. Receive balance updates)deposit(Only available with authentication. Receive deposit notifications)withdrawal(Only available with authentication. Receive withdrawal notifications)
For public channels (orderbook, trade), you can subscribe to specific symbols as follows:
orderbook:btc-usdt, trade:btc-usdt. Not passing a symbol will subscribe to all symbols.
Events
After connecting to the websocket, you can listen for events coming from the server by using the on function for the ws property of the client.
The events available are default websocket events e.g. message, open, close, error, unexpected-response, etc.
client.ws.on('message', (data) => {
data = JSON.parse(data);
console.log(data);
});These are exapmles of data responses from the server.
orderbook: Updates related to the user's private information are as follows:
{ "topic": "orderbook", "action": "partial", "symbol": "btc-usdt", "data": { "bids": [ [0.1, 0.1], ... ], "asks": [ [1, 1], ... ], "timestamp": "2020-12-15T06:45:27.766Z" }, "time": 1608015328 }trade: Updates related to the user's private information are as follows:
{ "topic": "trade", "action": "partial", "symbol": "btc-usdt", "data": [ { "size": 0.012, "price": 300, "side": "buy", "timestamp": "2020-12-15T07:25:28.887Z" }, ... ], "time": 1608015328 }wallet: Updates related to the user's private information are as follows:
{ "topic": "wallet", "action": "partial", "user_id": 1, "data": { "usdt_balance": 1, "usdt_available": 1, "btc_balance": 1, "btc_available": 1, "xmr_balance": 1, "xmr_available": 1, "btc_balance": 1, "btc_available": 1, "eth_balance": 1, "eth_available": 1, ..., "updated_at": "2020-12-15T08:41:24.048Z" }, "time": 1608021684 }order: Websocket messages relating the the user's orders.
The
statusof the order can benew,pfilled,filled, andcanceled.The
actionof the data determines what caused it to happen. All three are explained below:partial: All previous and current orders. Is the first order data received when connecting. Max: 50. Descending order.{ "topic": "order", "action": "partial", "user_id": 1, "data": [ { "id": "7d3d9545-b7e6-4e7f-84a0-a39efa4cb173", "side": "buy", "symbol": "btc-usdt", "type": "limit", "size": 0.1, "filled": 0, "price": 1, "stop": null, "status": "new", "fee": 0, "fee_coin": "btc", "meta": {}, "fee_structure": { "maker": 0.1, "taker": 0.1 }, "created_at": "2020-11-30T07:45:43.819Z", "created_by": 1 }, ... ], "time": 1608022610 }insert: When user's order is added. The status of the order can be eithernew,pfilled, orfilled.{ "topic": "order", "action": "insert", "user_id": 1, "symbol": "btc-usdt", "data": [ { "id": "7d3d9545-b7e6-4e7f-84a0-a39efa4cb173", "side": "buy", "symbol": "btc-usdt", "type": "limit", "size": 0.1, "filled": 0, "price": 1, "stop": null, "status": "new", "fee": 0, "fee_coin": "btc", "meta": {}, "fee_structure": { "maker": 0.1, "taker": 0.1 }, "created_at": "2020-11-30T07:45:43.819Z", "updated_at": "2020-12-15T08:56:45.066Z", "created_by": 1 }, ... ], "time": 1608022610 }update: When user's order status is updated. Status can bepfilled,filled, andcanceled.{ "topic": "order", "action": "insert", "user_id": 1, "symbol": "btc-usdt", "data": [ { "id": "7d3d9545-b7e6-4e7f-84a0-a39efa4cb173", "side": "buy", "symbol": "btc-usdt", "type": "limit", "size": 0.1, "filled": 0, "price": 1, "stop": null, "status": "new", "fee": 0, "fee_coin": "btc", "meta": {}, "fee_structure": { "maker": 0.1, "taker": 0.1 }, "created_at": "2020-11-30T07:45:43.819Z", "updated_at": "2020-12-15T08:56:45.066Z", "created_by": 1 }, ... ], "time": 1608022610 }
deposit: Updates related to the user's private information are as follows:
{ "topic": "deposit", "action": "insert", "user_id": 1, "data": { "amount": 1, "currency": "btc", "status": "COMPLETED", "transaction_id": "123", ... }, "time": 1608021684 }withdrawal: Updates related to the user's private information are as follows:
{ "topic": "withdrawal", "action": "insert", "user_id": 1, "data": { "amount": 1, "currency": "btc", "status": "COMPLETED", "transaction_id": "123", ... }, "time": 1608021684 }
Example
You can run the example by going to example folder and running:
node example/exir.jsDocumentation
For adding additional functionalities simply go to index.js and add more features. You can read more about api documentation at https://apidocs.exir.com You should create your token on the platform in security->Api Key keys
