Skip to content

Commit ee3dca4

Browse files
[EXCH-4240] operatorId support (#43)
1 parent 81e1834 commit ee3dca4

File tree

2 files changed

+47
-41
lines changed

2 files changed

+47
-41
lines changed

example/testApi.js

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ let testTicker24h = async () => {
197197
}
198198

199199
let testPlaceOrder = async () => {
200-
bitvavo.placeOrder('BTC-EUR', 'sell', 'limit', { amount: '0.1', price: '2000' }, (error, response) => {
200+
let operatorId = 1
201+
bitvavo.placeOrder('BTC-EUR', 'sell', 'limit', operatorId, { amount: '0.1', price: '99000' }, (error, response) => {
201202
if (error === null) {
202203
console.log(response)
203204
} else {
@@ -206,7 +207,7 @@ let testPlaceOrder = async () => {
206207
})
207208

208209
try {
209-
let response = await bitvavo.placeOrder('BTC-EUR', 'buy', 'market', { 'amount': '0.001' })
210+
let response = await bitvavo.placeOrder('BTC-EUR', 'buy', 'market', operatorId, { 'amount': '0.0001' })
210211
console.log(response)
211212
} catch (error) {
212213
console.log(error)
@@ -217,7 +218,8 @@ let testPlaceOrder = async () => {
217218
'BTC-EUR',
218219
'sell',
219220
'stopLoss',
220-
{ amount: '0.1', triggerType: 'price', triggerReference: 'lastTrade', triggerAmount: '5000' },
221+
operatorId,
222+
{ amount: '0.1', triggerType: 'price', triggerReference: 'lastTrade', triggerAmount: '85000' },
221223
(error, response) => {
222224
if (error === null) {
223225
console.log(response)
@@ -246,23 +248,20 @@ let testGetOrder = async () => {
246248
}
247249

248250
let testUpdateOrder = async () => {
249-
bitvavo.updateOrder(
250-
'BTC-EUR',
251-
'aadbb500-835e-4ae9-b881-e2f18d1c1bff',
252-
{ amount: '0.3', price: '6000' },
253-
(error, response) => {
254-
if (error === null) {
255-
console.log(response)
256-
} else {
257-
console.log(error)
258-
}
259-
},
260-
)
251+
let orderId = 'aadbb500-835e-4ae9-b881-e2f18d1c1bff'
252+
let operatorId = 1
253+
bitvavo.updateOrder('BTC-EUR', orderId, operatorId, { amount: '0.0002', price: '86000' }, (error, response) => {
254+
if (error === null) {
255+
console.log(response)
256+
} else {
257+
console.log(error)
258+
}
259+
})
261260

262261
try {
263-
let response = await bitvavo.updateOrder('BTC-EUR', 'aadbb500-835e-4ae9-b881-e2f18d1c1bff', {
264-
amount: 0.2,
265-
price: '7000',
262+
let response = await bitvavo.updateOrder('BTC-EUR', orderId, operatorId, {
263+
amount: '0.0001',
264+
price: '85000',
266265
})
267266
console.log(response)
268267
} catch (error) {
@@ -271,7 +270,9 @@ let testUpdateOrder = async () => {
271270
}
272271

273272
let testCancelOrder = async () => {
274-
bitvavo.cancelOrder('BTC-EUR', 'aadbb500-835e-4ae9-b881-e2f18d1c1bff', (error, response) => {
273+
let orderId = 'aadbb500-835e-4ae9-b881-e2f18d1c1bff'
274+
let operatorId = 1
275+
bitvavo.cancelOrder('BTC-EUR', orderId, operatorId, (error, response) => {
275276
if (error === null) {
276277
console.log(response)
277278
} else {
@@ -280,7 +281,7 @@ let testCancelOrder = async () => {
280281
})
281282

282283
try {
283-
let response = await bitvavo.cancelOrder('BTC-EUR', 'aadbb500-835e-4ae9-b881-e2f18d1c1bff')
284+
let response = await bitvavo.cancelOrder('BTC-EUR', orderId, operatorId)
284285
console.log(response)
285286
} catch (error) {
286287
console.log(error)
@@ -290,26 +291,23 @@ let testCancelOrder = async () => {
290291
let testGetOrders = async () => {
291292
bitvavo.getOrders('BTC-EUR', {}, (error, response) => {
292293
if (error === null) {
293-
for (let entry of response) {
294-
console.log(entry)
295-
}
294+
console.log(response)
296295
} else {
297296
console.log(error)
298297
}
299298
})
300299

301300
try {
302301
let response = await bitvavo.getOrders('BTC-EUR', {})
303-
for (let entry of response) {
304-
console.log(entry)
305-
}
302+
console.log(response)
306303
} catch (error) {
307304
console.log(error)
308305
}
309306
}
310307

311308
let testCancelOrders = async () => {
312-
bitvavo.cancelOrders({ market: 'BTC-EUR' }, (error, response) => {
309+
let operatorId = 1
310+
bitvavo.cancelOrders({ market: 'BTC-EUR' }, operatorId, (error, response) => {
313311
if (error === null) {
314312
for (let entry of response) {
315313
console.log(entry)
@@ -320,7 +318,7 @@ let testCancelOrders = async () => {
320318
})
321319

322320
try {
323-
let response = await bitvavo.cancelOrders({ market: 'BTC-EUR' })
321+
let response = await bitvavo.cancelOrders({ market: 'BTC-EUR' }, operatorId)
324322
for (let entry of response) {
325323
console.log(entry)
326324
}
@@ -627,12 +625,13 @@ let testWebSockets = async () => {
627625
// bitvavo.websocket.tickerPrice({ market: 'BTC-EUR' })
628626
// bitvavo.websocket.tickerBook({ market: 'BTC-EUR' })
629627

630-
// bitvavo.websocket.placeOrder('BTC-EUR', 'sell', 'limit', { amount: '1', price: '6000' })
628+
let operatorId = 1
629+
// bitvavo.websocket.placeOrder('BTC-EUR', 'sell', 'limit', operatorId, { amount: '0.01', price: '97000' })
631630
// bitvavo.websocket.getOrder('BTC-EUR', '89c1a7f6-5fa1-4fa6-8a8d-aa2388798d4a')
632-
// bitvavo.websocket.updateOrder('BTC-EUR', 'bc86d303-c199-404d-b742-f9b3a030916f', { amount: '0.5' })
633-
// bitvavo.websocket.cancelOrder('BTC-EUR', 'bc86d303-c199-404d-b742-f9b3a030916f')
631+
// bitvavo.websocket.updateOrder('BTC-EUR', 'bc86d303-c199-404d-b742-f9b3a030916f', operatorId,{ amount: '0.012' })
632+
// bitvavo.websocket.cancelOrder('BTC-EUR', 'bc86d303-c199-404d-b742-f9b3a030916f', operatorId)
634633
// bitvavo.websocket.getOrders('BTC-EUR', { limit: 10 })
635-
// bitvavo.websocket.cancelOrders({ market: 'BTC-EUR' })
634+
// bitvavo.websocket.cancelOrders({ market: 'BTC-EUR' }, operatorId)
636635
// bitvavo.websocket.ordersOpen({ market: 'BTC-EUR' })
637636
// bitvavo.websocket.trades('BTC-EUR', {})
638637

lib/index.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -546,10 +546,11 @@ let api = function Bitvavo() {
546546
// stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
547547
// stopLossLimit/takeProfitLimit:(amount, price, postOnly, triggerType, triggerReference, triggerAmount)
548548
// all orderTypes: timeInForce, selfTradePrevention, responseRequired
549-
placeOrder: function (market = '', side = '', orderType = '', body = {}, callback = false) {
549+
placeOrder: function (market = '', side = '', orderType = '', operatorId = 0, body = {}, callback = false) {
550550
body.market = market
551551
body.side = side
552552
body.orderType = orderType
553+
body.operatorId = operatorId
553554
return request(callback, 'POST', '/order', {}, body)
554555
},
555556

@@ -566,14 +567,15 @@ let api = function Bitvavo() {
566567
// Optional body parameters: limit:(amount, amountRemaining, price, timeInForce, selfTradePrevention, postOnly)
567568
// untriggered stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
568569
// stopLossLimit/takeProfitLimit: (amount, price, postOnly, triggerType, triggerReference, triggerAmount)
569-
updateOrder: function (market = '', orderId = '', body = {}, callback = false) {
570+
updateOrder: function (market = '', orderId = '', operatorId = 0, body = {}, callback = false) {
570571
body.market = market
571572
body.orderId = orderId
573+
body.operatorId = operatorId
572574
return request(callback, 'PUT', '/order', {}, body)
573575
},
574576

575-
cancelOrder: function (symbol = '', orderId = '', callback = false) {
576-
const query = { 'market': symbol, 'orderId': orderId }
577+
cancelOrder: function (symbol = '', orderId = '', operatorId = 0, callback = false) {
578+
const query = { 'market': symbol, 'orderId': orderId, 'operatorId': operatorId }
577579
return request(callback, 'DELETE', '/order', query, {})
578580
},
579581

@@ -585,7 +587,8 @@ let api = function Bitvavo() {
585587
},
586588

587589
// options: market
588-
cancelOrders: function (options = {}, callback = false) {
590+
cancelOrders: function (options = {}, operatorId = 0, callback = false) {
591+
options.operatorId = operatorId
589592
let query = options
590593
if (typeof options === 'function') {
591594
callback = options
@@ -766,12 +769,13 @@ let api = function Bitvavo() {
766769
// stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
767770
// stopLossLimit/takeProfitLimit:(amount, price, postOnly, triggerType, triggerReference, triggerAmount)
768771
// all orderTypes: timeInForce, selfTradePrevention, responseRequired
769-
placeOrder: async function (market = '', side = '', orderType = '', body = {}) {
772+
placeOrder: async function (market = '', side = '', orderType = '', operatorId = 0, body = {}) {
770773
await this.checkSocket()
771774
body.action = 'privateCreateOrder'
772775
body.market = market
773776
body.side = side
774777
body.orderType = orderType
778+
body.operatorId = operatorId
775779
doSendPrivate.call(this, JSON.stringify(body))
776780
},
777781

@@ -794,19 +798,21 @@ let api = function Bitvavo() {
794798
// Optional body parameters: limit:(amount, amountRemaining, price, timeInForce, selfTradePrevention, postOnly)
795799
// untriggered stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
796800
// stopLossLimit/takeProfitLimit: (amount, price, postOnly, triggerType, triggerReference, triggerAmount)
797-
updateOrder: async function (market = '', orderId = '', body = {}) {
801+
updateOrder: async function (market = '', orderId = '', operatorId = 0, body = {}) {
798802
await this.checkSocket()
799803
body.action = 'privateUpdateOrder'
800804
body.market = market
801805
body.orderId = orderId
806+
body.operatorId = operatorId
802807
doSendPrivate.call(this, JSON.stringify(body))
803808
},
804809

805-
cancelOrder: async function (market = '', orderId = '') {
810+
cancelOrder: async function (market = '', orderId = '', operatorId = 0) {
806811
await this.checkSocket()
807812
let options = { 'action': 'privateCancelOrder' }
808813
options.market = market
809814
options.orderId = orderId
815+
options.operatorId = operatorId
810816
doSendPrivate.call(this, JSON.stringify(options))
811817
},
812818

@@ -819,9 +825,10 @@ let api = function Bitvavo() {
819825
},
820826

821827
// options: market
822-
cancelOrders: async function (options = {}) {
828+
cancelOrders: async function (options = {}, operatorId = 0) {
823829
await this.checkSocket()
824830
options.action = 'privateCancelOrders'
831+
options.operatorId = operatorId
825832
doSendPrivate.call(this, JSON.stringify(options))
826833
},
827834

0 commit comments

Comments
 (0)