> For the complete documentation index, see [llms.txt](https://docs.bytex.ca/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bytex.ca/api-documentation/nodejs-library.md).

# Nodejs Library

## Requirements&#x20;

* Knowledge of basic usage of Nodejs and npm
* Nodejs version >= 12
* Install [hollaex-node-lib](https://www.npmjs.com/package/hollaex-node-lib) by running <mark style="color:green;">`npm i hollaex-node-lib`</mark> or <mark style="color:green;">`yarn add hollaex-node-lib`</mark> in your project

## Usage

Using the Hollaex Kit Nodejs Library, the following guide is modified to communicate with the ByteX Exchange.

### Import Library

```javascript
const kit = require('hollaex-node-lib');

const client = new kit({
	apiURL: 'https://api.bytex.ca',
	baseURL: '/v2',
	apiKey: '<MY_API_KEY>',
	apiSecret: '<MY_API_SECRET>'
});
```

Put your **API Key** for `<MY_API_KEY>` & **API Secret** for `<MY_API_SECRET>` in the above code that you can generate from [the guide.](/api-documentation.md#generate-your-api-key)

### Making Requests

```javascript
// // Initialize Client using above example...

client
	.getTicker('usdt-cad')
	.then((res) => {
		console.log('The volume is: ', res.volume);
	})
	.catch((err) => {
		console.log(err);
	});

client
	.getTrade({ symbol: 'usdt-cad' })
	.then((res) => {
		console.log('Public trades: ', res);
	})
	.catch((err) => {
		console.log(err);
	});A
```

### Available Functions

<table><thead><tr><th width="229.1612269987839" align="center">Command</th><th width="260.1212603827857" align="center">Parameters</th><th align="center">Description</th></tr></thead><tbody><tr><td align="center"><code>getKit</code></td><td align="center"></td><td align="center">Get exchange information e.g. name, valid languages, description, etc.</td></tr><tr><td align="center"><code>getConstants</code></td><td align="center"></td><td align="center">Tick size, min price, max price, min size and max size of each symbol pair and coin</td></tr><tr><td align="center"><code>getTicker</code></td><td align="center"><strong>symbol</strong></td><td align="center">Last, high, low, open and close price and volume within the last 24 hours</td></tr><tr><td align="center"><code>getTickers</code></td><td align="center"></td><td align="center">Last, high, low, open and close price and volume within the last 24 hours for all symbols</td></tr><tr><td align="center"><code>getOrderbook</code></td><td align="center"><strong>symbol</strong></td><td align="center">Orderbook containing list of bids and asks</td></tr><tr><td align="center"><code>getOrderbooks</code></td><td align="center"></td><td align="center">Orderbook containing list of bids and asks for all symbols</td></tr><tr><td align="center"><code>getTrade</code></td><td align="center"><strong>symbol</strong> (<em>optional</em>)</td><td align="center">List of last trades</td></tr><tr><td align="center"><code>getUser</code></td><td align="center"></td><td align="center">User’s personal information</td></tr><tr><td align="center"><code>getBalance</code></td><td align="center"></td><td align="center">User’s wallet balance</td></tr><tr><td align="center"><code>getDeposits</code></td><td align="center"><strong>currency</strong> (<em>optional</em>), <strong>limit</strong> (<em>optional</em>, <em>default</em>=<code>50</code>, <em>max</em>=<code>100</code>), <strong>page</strong> (<em>optional</em>, <em>default</em>=<code>1</code>), <strong>orderBy</strong> (<em>optional</em>, <em>default</em>=<code>id</code>), <strong>order</strong> (<em>optional</em>, <em>default</em>=<code>asc</code>, <code>asc</code> or <code>desc</code>), <strong>startDate</strong> (<em>optional</em>, <em>default</em>=<code>0</code>, <em>format</em>=<code>ISO8601</code>), <strong>endDate</strong> (<em>optional</em>, <em>default</em>=<code>NOW</code>, <em>format</em>=<code>ISO8601</code>)<br><br></td><td align="center">User’s list of all deposits</td></tr><tr><td align="center"><code>getWithdrawals</code></td><td align="center"><strong>currency</strong> (<em>optional</em>), <strong>limit</strong> (<em>optional</em>, <em>default</em>=<code>50</code>, <em>max</em>=<code>100</code>), <strong>page</strong> (<em>optional</em>, <em>default</em>=<code>1</code>), <strong>orderBy</strong> (<em>optional</em>, <em>default</em>=<code>id</code>), <strong>order</strong> (<em>optional</em>, <em>default</em>=<code>asc</code>, <code>asc</code> or <code>desc</code>), <strong>startDate</strong> (<em>optional</em>, <em>default</em>=<code>0</code>, <em>format</em>=<code>ISO8601</code>), <strong>endDate</strong> (<em>optional</em>, <em>default</em>=<code>NOW</code>, <em>format</em>=<code>ISO8601</code>)</td><td align="center">User’s list of all withdrawals</td></tr><tr><td align="center"><code>requestWithdrawal</code></td><td align="center"><strong>currency</strong>, <strong>amount</strong>, <strong>address</strong> (<em>receipient’s</em>)</td><td align="center">Create a new withdrawal request. <strong>Disable Two-Factor Authentication to be able to use this function. Must confirm within 5 minutes via email to complete withdrawal</strong></td></tr><tr><td align="center"><code>getUserTrades</code></td><td align="center"><strong>symbol</strong> (<em>optional</em>), <strong>limit</strong> (<em>optional</em>, <em>default</em>=<code>50</code>, <em>max</em>=<code>100</code>), <strong>page</strong> (<em>optional</em>, <em>default</em>=<code>1</code>), <strong>orderBy</strong> (<em>optional</em>, <em>default</em>=<code>id</code>), <strong>order</strong> (<em>optional</em>, <em>default</em>=<code>desc</code>, <code>asc</code> or <code>desc</code>), <strong>startDate</strong> (<em>optional</em>, <em>default</em>=<code>0</code>, <em>format</em>=<code>ISO8601</code>), <strong>endDate</strong> (<em>optional</em>, <em>default</em>=<code>NOW</code>, <em>format</em>=<code>ISO8601</code>)</td><td align="center">User’s list of all trades</td></tr><tr><td align="center"><code>getOrder</code></td><td align="center"><strong>orderId</strong></td><td align="center">Get specific information about a certain order</td></tr><tr><td align="center"><code>getOrders</code></td><td align="center"><strong>symbol</strong> (<em>optional</em>), <strong>limit</strong> (<em>optional</em>, <em>default</em>=<code>50</code>, <em>max</em>=<code>100</code>), <strong>page</strong> (<em>optional</em>, <em>default</em>=<code>1</code>), <strong>orderBy</strong> (<em>optional</em>, <em>default</em>=<code>id</code>), <strong>order</strong> (<em>optional</em>, <em>default</em>=<code>desc</code>, <em>enum</em>=<code>asc</code>, <code>desc</code>), <strong>startDate</strong> (<em>optional</em>, <em>default</em>=<code>0</code>, <em>format</em>=<code>ISO8601</code>), <strong>endDate</strong> (<em>optional</em>, <em>default</em>=<code>NOW</code>, <em>format</em>=<code>ISO8601</code>)<br><br></td><td align="center">Get the list of all user orders. It can be filter by passing the symbol</td></tr><tr><td align="center"><code>createOrder</code></td><td align="center"><strong>symbol</strong>, <strong>side</strong> (<code>buy</code> or <code>sell</code>), <strong>size</strong>, <strong>type</strong> (<code>market</code> or <code>limit</code>), <strong>price</strong>, <strong>stop</strong> (<em>optional</em>), <strong>meta</strong> (<em>optional</em>, object with optional properties e.g. <code>post_only</code>)</td><td align="center">Create a new order</td></tr><tr><td align="center"><code>cancelOrder</code></td><td align="center"><strong>orderId</strong></td><td align="center">Cancel a specific order with its ID</td></tr><tr><td align="center"><code>cancelAllOrders</code></td><td align="center"><strong>symbol</strong> (<em>optional</em>)</td><td align="center">Cancel all open order. It can be filter by passing the symbol</td></tr></tbody></table>

{% hint style="info" %}
ByteX Exchange is an Hollaex Kit Enabled Exchange, so you can learn more information on  API usage, instructions & examples from their [Github Repo](https://github.com/bitholla/hollaex-node-lib/tree/2.0).
{% endhint %}

## Websocket Client

> This guide uses `hollaex-node-lib` and assumes that you have already configured your code to assign `client` variable/constant (as shown above) before trying this.

To make a connection:

```javascript
var new_connetion = client.connect(['orderbook', 'trade']);
```

To disconnect:

```javascript
new_connetion.disconnect();
```

### Channel Subscriptions

* orderbook
* trades
* order (Only available with authentication. Receive order updates)
* wallet (Only available with authentication. Receive balance updates)

### Listen to events

After connection, You can listen for these events from the server by using the on method:

* message
* open
* close
* error
* unexpected-response etc.

#### **Example**

```javascript
// Initialize Client using above example...
const socket1 = client.connect('trades:usdt-cad');

socket1.on('trades', (data) => {
	console.log(data);
});

const socket2 = client.connect('all');

socket2.on('orderbook', (data) => {
	console.log(data);
});

// You have to use a token to use these  otherwise the socket disconnects
socket2.on('userInfo', (data) => {
	console.log(data);
});


setTimeout(() => {
	socket2.disconnect();
}, 5);

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.bytex.ca/api-documentation/nodejs-library.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
