Skip to content

Commit 05f6355

Browse files
authored
Merge pull request #20 from bitholla/develop
Develop
2 parents e37c23e + dd600ec commit 05f6355

File tree

4 files changed

+79
-17
lines changed

4 files changed

+79
-17
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 bitHolla
3+
Copyright (c) 2020 bitHolla
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ const HollaEx = require('hollaex-node-lib');
1010
var client = new HollaEx();
1111
```
1212

13-
You can pass your `apiKey` and `apiSecret` generated from the site as follows:
13+
You can pass the `apiURL` and `baseURL` of the HollaEx-Enabled exchange to connect to. You can also pass your `apiKey` and `apiSecret` generated from the HollaEx-Enabled exchange.
1414

1515
```node
16-
var client = new HollaEx({ apiKey: <MY_API_KEY>, apiSecret: <MY_API_SECRET> });
16+
var client = new HollaEx({
17+
apiURL: <EXCHANGE_API_URL>,
18+
baseURL: <EXCHANGE_BASE_URL>,
19+
apiKey: <MY_API_KEY>,
20+
apiSecret: <MY_API_SECRET>
21+
});
1722
```
1823

1924
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`.
@@ -25,7 +30,13 @@ There is a list of functions you can call which will be added later and they are
2530
### Example:
2631

2732
```node
28-
var client = new HollaEx({ apiKey: <MY_API_KEY>, apiSecret: <MY_API_SECRET> });
33+
var client = new HollaEx({
34+
apiURL: <EXCHANGE_API_URL>,
35+
baseURL: <EXCHANGE_BASE_URL>,
36+
apiKey: <MY_API_KEY>,
37+
apiSecret: <MY_API_SECRET>
38+
});
39+
2940
client
3041
.getTicker('xht-usdt')
3142
.then((res) => {
@@ -59,23 +70,56 @@ client
5970

6071
### Websocket
6172

73+
#### Connecting
74+
6275
You can connect and subscribe to different websocket channels for realtime updates.
6376

77+
To connect, use the `connect` function with the channel you want to subscribe to as the parameter.
78+
6479
```node
6580
const socket = client.connect('orderbook');
66-
socket.on('orderbook', (data) => {
81+
```
82+
83+
To disconnect the websocket, call `disconnect` on the socket connection.
84+
85+
```node
86+
socket.disconnect();
87+
```
88+
89+
#### Channels
90+
91+
Here is the list of channels you can subscribe to:
92+
93+
- `orderbook`
94+
- `trades`
95+
- `user` (Private updates for the user such as balance, user orders etc as explained below)
96+
- `all` (Subscribes to all events)
97+
98+
For public channels (`orderbook`, `trades`), you can subscribe to specific symbols as follows:
99+
`orderbook:xht-usdt`, `trades:xht-usdt`.
100+
101+
#### Events
102+
103+
After connecting to the websocket, you can listen for events coming from the server by using the `on` function.
104+
105+
```node
106+
socket.on(<EVENT>, (data) => {
67107
console.log(data);
68108
});
69109
```
70110

71-
You can only subscribe to specific symbols as follows:
72-
`orderbook:xht-usdt`
73-
Here is the list of events you can subscribe:
111+
Public channels (`orderbook`, `trades`) emit events named after the respective channel. For example, the `orderbook` channel emits the event `orderbook`.
112+
113+
The private channel `user` emits the events `userInfo`, `userOrder`, `userTrade`, `userWallet`, and `userUpdate`.
114+
115+
Each channel also emits a `disconnect`, `reconnect`, `error`, `connect_error`, and `connect_timeout` event.
116+
- `disconnect` is emitted once when the websocket connection is disconnected from the server.
117+
- `reconnect` is emitted once when the server connection is reconnected.
118+
- `error` is emitted when there is an error thrown by the socket connection.
119+
- `connect_error` is emitted when there is an error while the socket connects.
120+
- `connect_timeout` is emitted when the socket connection times out.
74121

75-
- orderbook
76-
- trades
77-
- user (Private updates for the user such as balance, user orders etc as explained below)
78-
- all (It subscribes to all events)
122+
##### Private Events
79123

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

index.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,14 @@ class Socket extends EventEmitter {
351351
this.ioLink[this.ioLink.length - 1].on('error', (error) => {
352352
this.emit('error', error);
353353
});
354+
this.ioLink[this.ioLink.length - 1].on('connect_error', (data) => {
355+
this.emit('connect_error', `Socket Connection Error: ${data}.`);
356+
});
357+
this.ioLink[this.ioLink.length - 1].on('connect_timeout', (data) => {
358+
this.emit('connect_timeout', `Socket Connection Timeout : ${data}.`);
359+
});
354360
this.ioLink[this.ioLink.length - 1].once('disconnect', (data) => {
355-
this.emit('disconnect', `Soscket.io disconnected from server due to: ${data}.`);
361+
this.emit('disconnect', `Socket Disconnect: ${data}.`);
356362
this.subs = this._events;
357363
this.removeAllListeners();
358364
});
@@ -380,16 +386,22 @@ class Socket extends EventEmitter {
380386
this.emit('userOrder', data);
381387
});
382388
this.ioLink[this.ioLink.length - 1].on('trades', (data) => {
383-
this.emit('userTrades', data);
389+
this.emit('userTrade', data);
384390
});
385391
this.ioLink[this.ioLink.length - 1].on('update', (data) => {
386392
this.emit('userUpdate', data);
387393
});
388394
this.ioLink[this.ioLink.length - 1].on('error', (error) => {
389395
this.emit('error', error);
390396
});
397+
this.ioLink[this.ioLink.length - 1].on('connect_error', (data) => {
398+
this.emit('connect_error', `Socket Connection Error: ${data}.`);
399+
});
400+
this.ioLink[this.ioLink.length - 1].on('connect_timeout', (data) => {
401+
this.emit('connect_timeout', `Socket Connection Timeout : ${data}.`);
402+
});
391403
this.ioLink[this.ioLink.length - 1].once('disconnect', (data) => {
392-
this.emit('disconnect', `Socket.io disconnected from server due to: ${data}.`);
404+
this.emit('disconnect', `Socket Disconnect: ${data}.`);
393405
this.subs = this._events;
394406
this.removeAllListeners();
395407
});
@@ -433,8 +445,14 @@ class Socket extends EventEmitter {
433445
this.ioLink[this.ioLink.length - 1].on('error', (error) => {
434446
this.emit('error', error);
435447
});
448+
this.ioLink[this.ioLink.length - 1].on('connect_error', (data) => {
449+
this.emit('connect_error', `Socket Connection Error: ${data}.`);
450+
});
451+
this.ioLink[this.ioLink.length - 1].on('connect_timeout', (data) => {
452+
this.emit('connect_timeout', `Socket Connection Timeout : ${data}.`);
453+
});
436454
this.ioLink[this.ioLink.length - 1].once('disconnect', (data) => {
437-
this.emit('disconnect', `Socket.io disconnected from server due to: ${data}.`);
455+
this.emit('disconnect', `Socket Disconnect: ${data}.`);
438456
this.subs = this._events;
439457
this.removeAllListeners();
440458
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hollaex-node-lib",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"description": "hollaex api and websocket library for nodejs",
55
"main": "index.js",
66
"dependencies": {

0 commit comments

Comments
 (0)