ByteX Exchange
  • Welcome!
  • 🍎Introduction
  • 📖API Documentation
    • REST API
    • Nodejs Library
Powered by GitBook
On this page
  • Requirements
  • Usage
  • Import Library
  • Making Requests
  • Available Functions
  • Websocket Client
  • Channel Subscriptions
  • Listen to events

Was this helpful?

  1. API Documentation

Nodejs Library

Connect with ByteX Exchange using Hollaex kit Nodejs Library

PreviousREST API

Last updated 3 years ago

Was this helpful?

Requirements

  • Knowledge of basic usage of Nodejs and npm

  • Nodejs version >= 12

  • Install by running npm i hollaex-node-lib or yarn add hollaex-node-lib in your project

Usage

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

Import Library

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

Making Requests

// // 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

Command
Parameters
Description

getKit

Get exchange information e.g. name, valid languages, description, etc.

getConstants

Tick size, min price, max price, min size and max size of each symbol pair and coin

getTicker

symbol

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

Orderbook containing list of bids and asks

getOrderbooks

Orderbook containing list of bids and asks for all symbols

getTrade

symbol (optional)

List of last trades

getUser

User’s personal information

getBalance

User’s wallet balance

getDeposits

currency (optional), limit (optional, default=50, max=100), page (optional, default=1), orderBy (optional, default=id), order (optional, default=asc, asc or desc), startDate (optional, default=0, format=ISO8601), endDate (optional, default=NOW, format=ISO8601)

User’s list of all deposits

getWithdrawals

currency (optional), limit (optional, default=50, max=100), page (optional, default=1), orderBy (optional, default=id), order (optional, default=asc, asc or desc), startDate (optional, default=0, format=ISO8601), endDate (optional, default=NOW, format=ISO8601)

User’s list of all withdrawals

requestWithdrawal

currency, amount, address (receipient’s)

Create a new withdrawal request. Disable Two-Factor Authentication to be able to use this function. Must confirm within 5 minutes via email to complete withdrawal

getUserTrades

symbol (optional), limit (optional, default=50, max=100), page (optional, default=1), orderBy (optional, default=id), order (optional, default=desc, asc or desc), startDate (optional, default=0, format=ISO8601), endDate (optional, default=NOW, format=ISO8601)

User’s list of all trades

getOrder

orderId

Get specific information about a certain order

getOrders

symbol (optional), limit (optional, default=50, max=100), page (optional, default=1), orderBy (optional, default=id), order (optional, default=desc, enum=asc, desc), startDate (optional, default=0, format=ISO8601), endDate (optional, default=NOW, format=ISO8601)

Get the list of all user orders. It can be filter by passing the symbol

createOrder

symbol, side (buy or sell), size, type (market or limit), price, stop (optional), meta (optional, object with optional properties e.g. post_only)

Create a new order

cancelOrder

orderId

Cancel a specific order with its ID

cancelAllOrders

symbol (optional)

Cancel all open order. It can be filter by passing the symbol

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:

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

To disconnect:

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

// 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);

ByteX Exchange is an Hollaex Kit Enabled Exchange, so you can learn more information on API usage, instructions & examples from their .

📖
hollaex-node-lib
the guide.
Github Repo