Skip to content

Commit ef017a5

Browse files
authored
Merge pull request #23 from bitvavo/chore/add_unsubscribe
Fix on: [chore: add unsubscribe websocket method #18](#18) ### Add - `unsubscribe` Websocket action
2 parents 88c7d1b + 9c6ebbf commit ef017a5

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ To trade and execute your advanced trading strategies, Bitvavo SDK for Node.js i
4545
* [Trades Subscription](#trades-subscription)
4646
* [Book Subscription](#book-subscription)
4747
* [Book Subscription With Local Copy](#book-subscription-with-local-copy)
48+
* [Unsubscribe](#unsubscribe)
4849

4950
## Installation
5051
```
@@ -2822,3 +2823,14 @@ bitvavo.websocket.subscriptionBook('LTC-EUR', (book) => {
28222823
nonce: 41175 }
28232824
```
28242825
</details>
2826+
2827+
#### Unsubscribe
2828+
Unsubscribe from a previously opened websocket connection.
2829+
```javascript
2830+
bitvavo.websocket.unsubscribe('LTC-EUR', 'account')
2831+
```
2832+
<details>
2833+
<summary>View Response</summary>
2834+
```javascript
2835+
{ event: 'unsubscribed', subscriptions: {} }
2836+
```

node-bitvavo-api.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,12 @@ let api = function Bitvavo () {
919919
await this.checkSocket()
920920
doSendPublic(this.websocket, JSON.stringify({ 'action': 'getBook', 'market': market }))
921921
doSendPublic(this.websocket, JSON.stringify({ 'action': 'subscribe', 'channels': [{ 'name': 'book', 'markets': [market] }] }))
922+
},
923+
924+
unsubscribe: async function (market = '', name = undefined) {
925+
if (typeof name === 'undefined') errorToConsole('Specify which channel you want to unsubscribe from (such as: ticker, ticker24h, candles, trades, account and book.)');
926+
await this.checkSocket();
927+
doSendPrivate(this.websocket, JSON.stringify({ 'action': 'unsubscribe', 'channels': [{ 'name': name, 'markets': [market] }] }));
922928
}
923929
}
924930
}

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bitvavo",
3-
"version": "1.2.2",
3+
"version": "1.2.3",
44
"description": "This is the NodeJS wrapper for the Bitvavo API",
55
"main": "node-bitvavo-api.js",
66
"directories": {
@@ -25,5 +25,4 @@
2525
"url": "https://github.com/bitvavo/node-bitvavo-api/issues"
2626
},
2727
"homepage": "https://github.com/bitvavo/node-bitvavo-api#readme"
28-
}
29-
28+
}

0 commit comments

Comments
 (0)