0.3.2 • Published 5 years ago

exir-node-lib v0.3.2

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

exir-node-lib

Exir crypto exchange nodejs library

Usage

const Exir = require('exir-node-lib');

var client = new Exir();

You can pass your Access_Token generated from the site as follows:

var client = new Exir({ accessToken: MY_ACCESS_TOKEN });

There is a list of functions you can call which will be added later and they are not at this point implemented yet.

getTicker

var client = new Exir({ accessToken: MY_ACCESS_TOKEN });
client
	.getTicker('btc-eur')
	.then((res) => {
		let data = JSON.parse(res);
		console.log('The volume is', data.volume);
	})
	.catch((err) => {
		console.log(err);
	});
CommandParametersDescription
getTickersymbol e.g. btc-eurLast, high, low, open and close price and volume within the last 24 hours
getOrderbooksymbol (optional) e.g. btc-eurOrderbook containing list of bids and asks
getTradesymbol (optional) e.g. btc-eurList of last trades
getConstantTick size, min price, max price, min size and max size of each symbol pair
getUserUser's personal information
getBalanceUser's wallet balance
getDepositUser's list of all deposits
getWithdrawalUser's list of all withdrawals
getUserTradeUser's list of all trades
getOrderorderIdGet specific information about a certain order
getAllOrdersymbol (optional) e.g. btc-eurGet the list of all user orders. It can be filter by passing the symbol
createOrdersymbol, side (buy or sell), size (amount), type (market or limit), pricecreate a new order
cancelOrderorderIdCancel a specific order with its ID
cancelAllOrdersymbol (optional) e.g. btc-eurCancel all open order. It can be filter by passing the symbol

Websocket

You can connect and subscribe to different websocket channels for realtime updates.

const socket = client.connect('orderbook');
socket.on('orderbook', (data) => {
	console.log(data);
});

You can only subscribe to specific symbols as follows: orderbook:btc-eur Here is the list of events you can subscribe:

  • orderbook
  • ticker
  • trades
  • chart
  • user (Private updates for the user such as balance, user orders etc as explained below)
  • all (It subsribes to all events)

When you subscribe to private updates on user you should listen for the events as follows:

const socket = client.connect('user');

socket.on('userInfo', (data) => {
	console.log(data);
});
socket.on('userOrder', (data) => {
	console.log(data);
});
socket.on('userTrade', (data) => {
	console.log(data);
});
socket.on('userWallet', (data) => {
	console.log(data);
});
socket.on('userUpdate', (data) => {
	console.log(data);
});

userInfo, userOrder, userTrade, userWallet are only partial and send data once. These sockets are similar to GET requests and you should not expect any updates after you receive the first set of data. However userUpdate is what is used for all updates on user's private data.

These are list of userUpdate client gets after subscribtion.

  • userUpdate: Updates related to the user's pivate information are as follows:
    • order_queued: When a user order is added to the queue.
    {
    	"type": "order_queued",
    	"data": {
    		"id": "ac7717d4-04e9-4430-a21b-08d32b2c34cd",
    		"created_by": 79,
    		"price": 1001,
    		"side": "sell",
    		"size": 2,
    		"symbol": "bch-btc",
    		"filled": 0,
    		"type": "limit"
    	}
    }
    • order_processed: When a user order has been processed in the queue.
    {
    	"type": "order_processed",
    	"data": { "id": "ac7717d4-04e9-4430-a21b-08d32b2c34cd" }
    }
    • order_canceled: When a user order has been canceled in the queue, so it has not been added to the orderbook.
    {
    	"type": "order_canceled",
    	"data": {
    		"id": "ac7717d4-04e9-4430-a21b-08d32b2c34cd",
    		"message": "Insufficent balance to perform the order."
    	}
    }
    • order_added: When a user order is added to the orderbook.
    {
    	"type": "order_added",
    	"data": {
    		"id": "ac7717d4-04e9-4430-a21b-08d32b2c34cd",
    		"created_by": 79,
    		"price": 1001,
    		"side": "sell",
    		"size": 2,
    		"symbol": "bch-btc",
    		"filled": 0,
    		"type": "limit"
    	}
    }
    • order_partialy_filled: When a user order is update because it was taken some part by another order.
    {
    	"type": "order_partialy_filled",
    	"data": {
    		"id": "ac7717d4-04e9-4430-a21b-08d32b2c34cd",
    		"created_by": 79,
    		"price": 1001,
    		"side": "sell",
    		"size": 2,
    		"type": "limit"
    	}
    }
    • order_filled: When a user order is taken by another other in a trade.
    {
      "type": "order_filled",
      "data": [
        {
          "id": "ac7717d4-04e9-4430-a21b-08d32b2c34cd"
        },
        {
          "id": "bc7717d4-04e9-4430-a21b-08d32b2c34cd"
        },
        ...
      ]
    }
    • order_updated: When a user updates the order.
    {
    	"type": "order_updated",
    	"data": {
    		"id": "ac7717d4-04e9-4430-a21b-08d32b2c34cd",
    		"created_by": 79,
    		"price": 1001,
    		"side": "sell",
    		"size": 2,
    		"type": "limit"
    	}
    }
    • order_remove: When a user order is taken or the user cancel the orders/orders.
    {
      "type": "order_remove",
      "data": [
        {
          "id": "ac7717d4-04e9-4430-a21b-08d32b2c34cd"
        },
        {
          "id": "bc7717d4-04e9-4430-a21b-08d32b2c34cd"
        },
        ...
      ]
    }
    • trade: When a trade happens in the orderbook.
    {
      "type": "trade",
      "data": [
        {
          "order": { "id": "1efd30b6-fcb5-44da-82c1-82d9def2ddbd", "size": 0.2 },
          "price": 999,
          "side": "sell",
          "size": 0.1,
          "fee": 0,
          "timestamp": "2017-07-26T13:20:40.464Z"
        },
        ...
      ]
    }
    • deposit: When a user get a deposit in his account. Status = pending or completed
    {
    	"type": "deposit",
    	"data": {
    		"amount": 3000,
    		"currency": "fiat",
    		"status": false
    	},
    	"balance": {
    		"fiat_balance": 0,
    		"btc_balance": 300000,
    		"updated_at": "2017-07-26T13:20:40.464Z"
    	}
    }
    • withdrawal: When a user performs a withdrawal in his account. Status = pending or completed
    {
    	"type": "withdrawal",
    	"data": {
    		"amount": 5000,
    		"currency": "btc",
    		"status": true
    	},
    	"balance": {
    		"fiat_balance": 0,
    		"btc_balance": 300000,
    		"updated_at": "2017-07-26T13:20:40.464Z"
    	}
    }

Example

You can run the example by going to example folder and running:

node app.js

Documentation

For adding additional functionalities simply go to index.js and add more features. You can read more about api documentation at https://apidocs.exir.io You should create your token on the platform in setting->api keys