Skip to content

Commit 0fb5602

Browse files
committed
✨ New account endpoint, stoploss example
1 parent 724fc9f commit 0fb5602

File tree

4 files changed

+159
-10
lines changed

4 files changed

+159
-10
lines changed

README.md

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ This is the Node.js wrapper for the Bitvavo API. This project can be used to bui
3131
* Cancel Orders [REST](#cancel-orders) [Websocket](#cancel-orders-1)
3232
* Orders Open [REST](#get-orders-open) [Websocket](#get-orders-open-1)
3333
* Trades [REST](#get-trades) [Websocket](#get-trades-1)
34+
* Account [REST](#get-account) [Websocket](#get-account-1)
3435
* Balance [REST](#get-balance) [Websocket](#get-balance-1)
3536
* Deposit Assets [REST](#deposit-assets) [Websocket](#deposit-assets-1)
3637
* Withdraw Assets [REST](#withdraw-assets) [Websocket](#withdraw-assets-1)
@@ -703,7 +704,9 @@ When placing an order, make sure that the correct optional parameters are set. F
703704
```javascript
704705
// Function with callback
705706
// Optional parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection),
706-
// both: timeInForce, selfTradePrevention, responseRequired
707+
// stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
708+
// stopLossLimit/takeProfitLimit:(amount, price, postOnly, triggerType, triggerReference, triggerAmount)
709+
// all orderTypes: timeInForce, selfTradePrevention, responseRequired
707710
bitvavo.placeOrder('BTC-EUR', 'sell', 'limit', { amount: '1', price: '3000' }, (error, response) => {
708711
if (error === null) {
709712
console.log(response)
@@ -714,7 +717,9 @@ bitvavo.placeOrder('BTC-EUR', 'sell', 'limit', { amount: '1', price: '3000' }, (
714717

715718
// Function with promise
716719
// Optional parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection),
717-
// both: timeInForce, selfTradePrevention, responseRequired
720+
// stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
721+
// stopLossLimit/takeProfitLimit:(amount, price, postOnly, triggerType, triggerReference, triggerAmount)
722+
// all orderTypes: timeInForce, selfTradePrevention, responseRequired
718723
try {
719724
let response = await bitvavo.placeOrder('BTC-EUR', 'sell', 'limit', { 'amount': '1', 'price': 3000 })
720725
console.log(response)
@@ -754,7 +759,9 @@ try {
754759
When updating an order make sure that at least one of the optional parameters has been set. Otherwise nothing can be updated.
755760
```javascript
756761
// Function with callback
757-
// Optional parameters: limit:(amount, price, timeInForce, selfTradePrevention, postOnly) (set at least 1)
762+
// Optional parameters: limit:(amount, amountRemaining, price, timeInForce, selfTradePrevention, postOnly)
763+
// untriggered stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
764+
// stopLossLimit/takeProfitLimit: (amount, price, postOnly, triggerType, triggerReference, triggerAmount)
758765
bitvavo.updateOrder('BTC-EUR', 'bb4076a3-d7b6-4bf6-aa35-b12f14fcb092', { price: 4500 }, (error, response) => {
759766
if (error === null) {
760767
console.log(response)
@@ -765,7 +772,8 @@ bitvavo.updateOrder('BTC-EUR', 'bb4076a3-d7b6-4bf6-aa35-b12f14fcb092', { price:
765772

766773
// Function with promise
767774
// Optional parameters: limit:(amount, amountRemaining, price, timeInForce, selfTradePrevention, postOnly)
768-
// (set at least 1) (responseRequired can be set as well, but does not update anything)
775+
// untriggered stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
776+
// stopLossLimit/takeProfitLimit: (amount, price, postOnly, triggerType, triggerReference, triggerAmount)
769777
try {
770778
let response = await bitvavo.updateOrder('BTC-EUR', 'bb4076a3-d7b6-4bf6-aa35-b12f14fcb092', { amount: 0.2 })
771779
console.log(response)
@@ -1175,6 +1183,40 @@ try {
11751183
```
11761184
</details>
11771185

1186+
#### Get account
1187+
Returns the fee tier for this account.
1188+
```javascript
1189+
// Function with callback
1190+
bitvavo.account((error, response) => {
1191+
if (error == null) {
1192+
console.log(response)
1193+
} else {
1194+
console.log(error)
1195+
}
1196+
})
1197+
1198+
// Function with promise
1199+
try {
1200+
let response = await bitvavo.account()
1201+
console.log(response)
1202+
} catch (error) {
1203+
console.log(error)
1204+
}
1205+
```
1206+
<details>
1207+
<summary>View Response</summary>
1208+
1209+
```javascript
1210+
{
1211+
fees: {
1212+
taker: '0.0025'
1213+
maker: '0.0015'
1214+
volume: '100.00'
1215+
}
1216+
}
1217+
```
1218+
</details>
1219+
11781220
#### Get balance
11791221
Returns the balance for this account.
11801222
```javascript
@@ -1913,7 +1955,9 @@ bitvavo.getEmitter().on('placeOrder', (response) => {
19131955
})
19141956

19151957
// Optional parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection),
1916-
// both: timeInForce, selfTradePrevention, responseRequired
1958+
// stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
1959+
// stopLossLimit/takeProfitLimit:(amount, price, postOnly, triggerType, triggerReference, triggerAmount)
1960+
// all orderTypes: timeInForce, selfTradePrevention, responseRequired
19171961
bitvavo.websocket.placeOrder('BTC-EUR', 'buy', 'limit', { amount: 0.1, price: 5000 })
19181962
```
19191963
<details>
@@ -1951,7 +1995,8 @@ bitvavo.getEmitter().on('updateOrder', (response) => {
19511995
})
19521996

19531997
// Optional parameters: limit:(amount, amountRemaining, price, timeInForce, selfTradePrevention, postOnly)
1954-
// (set at least 1) (responseRequired can be set as well, but does not update anything)
1998+
// untriggered stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
1999+
// stopLossLimit/takeProfitLimit: (amount, price, postOnly, triggerType, triggerReference, triggerAmount)
19552000
bitvavo.websocket.updateOrder('BTC-EUR', 'bb4076a3-d7b6-4bf6-aa35-b12f14fcb092', { amount: '0.2' })
19562001
```
19572002
<details>
@@ -2279,6 +2324,29 @@ bitvavo.websocket.trades('BTC-EUR', {})
22792324
```
22802325
</details>
22812326

2327+
#### Get account
2328+
Returns the fee tier for this account.
2329+
```javascript
2330+
bitvavo.getEmitter().on('account', (response) => {
2331+
console.log(response)
2332+
})
2333+
2334+
bitvavo.websocket.account()
2335+
```
2336+
<details>
2337+
<summary>View Response</summary>
2338+
2339+
```javascript
2340+
{
2341+
fees: {
2342+
taker: '0.0025'
2343+
maker: '0.0015'
2344+
volume: '100'
2345+
}
2346+
}
2347+
```
2348+
</details>
2349+
22822350
#### Get balance
22832351
Returns the balance for this account.
22842352
```javascript

example/testApi.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,15 @@ let testPlaceOrder = async () => {
211211
} catch (error) {
212212
console.log(error)
213213
}
214+
215+
// StopLoss
216+
bitvavo.placeOrder('BTC-EUR', 'sell', 'stopLoss', { amount: '0.1', triggerType: 'price', triggerReference: 'lastTrade', triggerAmount: '5000' }, (error, response) => {
217+
if (error === null) {
218+
console.log(response)
219+
} else {
220+
console.log(error)
221+
}
222+
})
214223
}
215224

216225
let testGetOrder = async () => {
@@ -348,6 +357,23 @@ let testTrades = async () => {
348357
}
349358
}
350359

360+
let testAccount = async () => {
361+
bitvavo.account((error, response) => {
362+
if (error == null) {
363+
console.log(response)
364+
} else {
365+
console.log(error)
366+
}
367+
})
368+
369+
try {
370+
let response = await bitvavo.account()
371+
console.log(response)
372+
} catch (error) {
373+
console.log(error)
374+
}
375+
}
376+
351377
let testBalance = async () => {
352378
bitvavo.balance({}, (error, response) => {
353379
if (error == null) {
@@ -468,6 +494,7 @@ let testRestApi = async () => {
468494

469495
// testTrades()
470496

497+
// testAccount()
471498
// testBalance()
472499
// testDepositAssets()
473500
// testWithdrawAssets()
@@ -529,6 +556,9 @@ let websocketSetListeners = async () => {
529556
emitter.on('trades', (response) => {
530557
console.log('TradesResponse', response)
531558
})
559+
emitter.on('account', (response) => {
560+
console.log('AccountResponse', response)
561+
})
532562
emitter.on('balance', (response) => {
533563
console.log('BalanceResponse', response)
534564
})
@@ -571,6 +601,7 @@ let testWebSockets = async () => {
571601
// bitvavo.websocket.ordersOpen({ market: 'BTC-EUR' })
572602
// bitvavo.websocket.trades('BTC-EUR', {})
573603

604+
// bitvavo.websocket.account()
574605
// bitvavo.websocket.balance({})
575606
// bitvavo.websocket.depositAssets('BTC')
576607
// bitvavo.websocket.withdrawAssets('BTC', '1', 'BitcoinAddress', {})

node-bitvavo-api.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ let api = function Bitvavo () {
247247
case 'privateGetTrades':
248248
emitter.emit('trades', response.response)
249249
break
250+
case 'privateGetAccount':
251+
emitter.emit('account', response.response)
252+
break
250253
case 'privateGetBalance':
251254
emitter.emit('balance', response.response)
252255
break
@@ -535,7 +538,10 @@ let api = function Bitvavo () {
535538
return publicRequest((base + '/ticker/24h' + postfix), callback)
536539
},
537540

538-
// Optional body parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection), both: timeInForce, selfTradePrevention, responseRequired
541+
// Optional body parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection)
542+
// stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
543+
// stopLossLimit/takeProfitLimit:(amount, price, postOnly, triggerType, triggerReference, triggerAmount)
544+
// all orderTypes: timeInForce, selfTradePrevention, responseRequired
539545
placeOrder: function (market = '', side = '', orderType = '', body = {}, callback = false) {
540546
body.market = market
541547
body.side = side
@@ -550,7 +556,8 @@ let api = function Bitvavo () {
550556
},
551557

552558
// Optional body parameters: limit:(amount, amountRemaining, price, timeInForce, selfTradePrevention, postOnly)
553-
// (set at least 1) (responseRequired can be set as well, but does not update anything)
559+
// untriggered stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
560+
// stopLossLimit/takeProfitLimit: (amount, price, postOnly, triggerType, triggerReference, triggerAmount)
554561
updateOrder: function (market = '', orderId = '', body = {}, callback = false) {
555562
body.market = market
556563
body.orderId = orderId
@@ -593,6 +600,10 @@ let api = function Bitvavo () {
593600
return privateRequest('/trades', postfix, callback)
594601
},
595602

603+
account: function (callback = false) {
604+
return privateRequest('/account', '', callback)
605+
},
606+
596607
// options: symbol
597608
balance: function (options = {}, callback = false) {
598609
let postfix = createPostfix(options)
@@ -726,7 +737,10 @@ let api = function Bitvavo () {
726737
doSendPublic(this.websocket, JSON.stringify(options))
727738
},
728739

729-
// Optional body parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection), both: timeInForce, selfTradePrevention, responseRequired
740+
// Optional body parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection)
741+
// stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
742+
// stopLossLimit/takeProfitLimit:(amount, price, postOnly, triggerType, triggerReference, triggerAmount)
743+
// all orderTypes: timeInForce, selfTradePrevention, responseRequired
730744
placeOrder: async function (market = '', side = '', orderType = '', body = {}) {
731745
await this.checkSocket()
732746
body.action = 'privateCreateOrder'
@@ -745,7 +759,8 @@ let api = function Bitvavo () {
745759
},
746760

747761
// Optional body parameters: limit:(amount, amountRemaining, price, timeInForce, selfTradePrevention, postOnly)
748-
// (set at least 1) (responseRequired can be set as well, but does not update anything)
762+
// untriggered stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
763+
// stopLossLimit/takeProfitLimit: (amount, price, postOnly, triggerType, triggerReference, triggerAmount)
749764
updateOrder: async function (market = '', orderId = '', body = {}) {
750765
await this.checkSocket()
751766
body.action = 'privateUpdateOrder'
@@ -792,6 +807,12 @@ let api = function Bitvavo () {
792807
doSendPrivate(this.websocket, JSON.stringify(options))
793808
},
794809

810+
account: async function () {
811+
await this.checkSocket()
812+
options = { action: 'privateGetAccount' }
813+
doSendPrivate(this.websocket, JSON.stringify(options))
814+
},
815+
795816
// options: symbol
796817
balance: async function (options = {}) {
797818
await this.checkSocket()

package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "bitvavo",
3+
"version": "1.2.0",
4+
"description": "This is the NodeJS wrapper for the Bitvavo API",
5+
"main": "node-bitvavo-api.js",
6+
"directories": {
7+
"example": "example"
8+
},
9+
"dependencies": {
10+
"events": "^3.0.0",
11+
"request": "^2.88.0",
12+
"ws": "^6.1.2"
13+
},
14+
"repository": {
15+
"type": "git",
16+
"url": "git+https://github.com/bitvavo/node-bitvavo-api.git"
17+
},
18+
"keywords": [
19+
"Node",
20+
"Bitvavo"
21+
],
22+
"author": "Bitvavo",
23+
"license": "ISC",
24+
"bugs": {
25+
"url": "https://github.com/bitvavo/node-bitvavo-api/issues"
26+
},
27+
"homepage": "https://github.com/bitvavo/node-bitvavo-api#readme"
28+
}
29+

0 commit comments

Comments
 (0)