Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 31 additions & 32 deletions example/testApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ let testTicker24h = async () => {
}

let testPlaceOrder = async () => {
bitvavo.placeOrder('BTC-EUR', 'sell', 'limit', { amount: '0.1', price: '2000' }, (error, response) => {
let operatorId = 1
bitvavo.placeOrder('BTC-EUR', 'sell', 'limit', operatorId, { amount: '0.1', price: '99000' }, (error, response) => {
if (error === null) {
console.log(response)
} else {
Expand All @@ -206,7 +207,7 @@ let testPlaceOrder = async () => {
})

try {
let response = await bitvavo.placeOrder('BTC-EUR', 'buy', 'market', { 'amount': '0.001' })
let response = await bitvavo.placeOrder('BTC-EUR', 'buy', 'market', operatorId, { 'amount': '0.0001' })
console.log(response)
} catch (error) {
console.log(error)
Expand All @@ -217,7 +218,8 @@ let testPlaceOrder = async () => {
'BTC-EUR',
'sell',
'stopLoss',
{ amount: '0.1', triggerType: 'price', triggerReference: 'lastTrade', triggerAmount: '5000' },
operatorId,
{ amount: '0.1', triggerType: 'price', triggerReference: 'lastTrade', triggerAmount: '85000' },
(error, response) => {
if (error === null) {
console.log(response)
Expand Down Expand Up @@ -246,23 +248,20 @@ let testGetOrder = async () => {
}

let testUpdateOrder = async () => {
bitvavo.updateOrder(
'BTC-EUR',
'aadbb500-835e-4ae9-b881-e2f18d1c1bff',
{ amount: '0.3', price: '6000' },
(error, response) => {
if (error === null) {
console.log(response)
} else {
console.log(error)
}
},
)
let orderId = 'aadbb500-835e-4ae9-b881-e2f18d1c1bff'
let operatorId = 1
bitvavo.updateOrder('BTC-EUR', orderId, operatorId, { amount: '0.0002', price: '86000' }, (error, response) => {
if (error === null) {
console.log(response)
} else {
console.log(error)
}
})

try {
let response = await bitvavo.updateOrder('BTC-EUR', 'aadbb500-835e-4ae9-b881-e2f18d1c1bff', {
amount: 0.2,
price: '7000',
let response = await bitvavo.updateOrder('BTC-EUR', orderId, operatorId, {
amount: '0.0001',
price: '85000',
})
console.log(response)
} catch (error) {
Expand All @@ -271,7 +270,9 @@ let testUpdateOrder = async () => {
}

let testCancelOrder = async () => {
bitvavo.cancelOrder('BTC-EUR', 'aadbb500-835e-4ae9-b881-e2f18d1c1bff', (error, response) => {
let orderId = 'aadbb500-835e-4ae9-b881-e2f18d1c1bff'
let operatorId = 1
bitvavo.cancelOrder('BTC-EUR', orderId, operatorId, (error, response) => {
if (error === null) {
console.log(response)
} else {
Expand All @@ -280,7 +281,7 @@ let testCancelOrder = async () => {
})

try {
let response = await bitvavo.cancelOrder('BTC-EUR', 'aadbb500-835e-4ae9-b881-e2f18d1c1bff')
let response = await bitvavo.cancelOrder('BTC-EUR', orderId, operatorId)
console.log(response)
} catch (error) {
console.log(error)
Expand All @@ -290,26 +291,23 @@ let testCancelOrder = async () => {
let testGetOrders = async () => {
bitvavo.getOrders('BTC-EUR', {}, (error, response) => {
if (error === null) {
for (let entry of response) {
console.log(entry)
}
console.log(response)
} else {
console.log(error)
}
})

try {
let response = await bitvavo.getOrders('BTC-EUR', {})
for (let entry of response) {
console.log(entry)
}
console.log(response)
} catch (error) {
console.log(error)
}
}

let testCancelOrders = async () => {
bitvavo.cancelOrders({ market: 'BTC-EUR' }, (error, response) => {
let operatorId = 1
bitvavo.cancelOrders({ market: 'BTC-EUR' }, operatorId, (error, response) => {
if (error === null) {
for (let entry of response) {
console.log(entry)
Expand All @@ -320,7 +318,7 @@ let testCancelOrders = async () => {
})

try {
let response = await bitvavo.cancelOrders({ market: 'BTC-EUR' })
let response = await bitvavo.cancelOrders({ market: 'BTC-EUR' }, operatorId)
for (let entry of response) {
console.log(entry)
}
Expand Down Expand Up @@ -627,12 +625,13 @@ let testWebSockets = async () => {
// bitvavo.websocket.tickerPrice({ market: 'BTC-EUR' })
// bitvavo.websocket.tickerBook({ market: 'BTC-EUR' })

// bitvavo.websocket.placeOrder('BTC-EUR', 'sell', 'limit', { amount: '1', price: '6000' })
let operatorId = 1
// bitvavo.websocket.placeOrder('BTC-EUR', 'sell', 'limit', operatorId, { amount: '0.01', price: '97000' })
// bitvavo.websocket.getOrder('BTC-EUR', '89c1a7f6-5fa1-4fa6-8a8d-aa2388798d4a')
// bitvavo.websocket.updateOrder('BTC-EUR', 'bc86d303-c199-404d-b742-f9b3a030916f', { amount: '0.5' })
// bitvavo.websocket.cancelOrder('BTC-EUR', 'bc86d303-c199-404d-b742-f9b3a030916f')
// bitvavo.websocket.updateOrder('BTC-EUR', 'bc86d303-c199-404d-b742-f9b3a030916f', operatorId,{ amount: '0.012' })
// bitvavo.websocket.cancelOrder('BTC-EUR', 'bc86d303-c199-404d-b742-f9b3a030916f', operatorId)
// bitvavo.websocket.getOrders('BTC-EUR', { limit: 10 })
// bitvavo.websocket.cancelOrders({ market: 'BTC-EUR' })
// bitvavo.websocket.cancelOrders({ market: 'BTC-EUR' }, operatorId)
// bitvavo.websocket.ordersOpen({ market: 'BTC-EUR' })
// bitvavo.websocket.trades('BTC-EUR', {})

Expand Down
25 changes: 16 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,11 @@ let api = function Bitvavo() {
// stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
// stopLossLimit/takeProfitLimit:(amount, price, postOnly, triggerType, triggerReference, triggerAmount)
// all orderTypes: timeInForce, selfTradePrevention, responseRequired
placeOrder: function (market = '', side = '', orderType = '', body = {}, callback = false) {
placeOrder: function (market = '', side = '', orderType = '', operatorId = 0, body = {}, callback = false) {
body.market = market
body.side = side
body.orderType = orderType
body.operatorId = operatorId
return request(callback, 'POST', '/order', {}, body)
},

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

cancelOrder: function (symbol = '', orderId = '', callback = false) {
const query = { 'market': symbol, 'orderId': orderId }
cancelOrder: function (symbol = '', orderId = '', operatorId = 0, callback = false) {
const query = { 'market': symbol, 'orderId': orderId, 'operatorId': operatorId }
return request(callback, 'DELETE', '/order', query, {})
},

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

// options: market
cancelOrders: function (options = {}, callback = false) {
cancelOrders: function (options = {}, operatorId = 0, callback = false) {
options.operatorId = operatorId
let query = options
if (typeof options === 'function') {
callback = options
Expand Down Expand Up @@ -766,12 +769,13 @@ let api = function Bitvavo() {
// stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
// stopLossLimit/takeProfitLimit:(amount, price, postOnly, triggerType, triggerReference, triggerAmount)
// all orderTypes: timeInForce, selfTradePrevention, responseRequired
placeOrder: async function (market = '', side = '', orderType = '', body = {}) {
placeOrder: async function (market = '', side = '', orderType = '', operatorId = 0, body = {}) {
await this.checkSocket()
body.action = 'privateCreateOrder'
body.market = market
body.side = side
body.orderType = orderType
body.operatorId = operatorId
doSendPrivate.call(this, JSON.stringify(body))
},

Expand All @@ -794,19 +798,21 @@ let api = function Bitvavo() {
// Optional body parameters: limit:(amount, amountRemaining, price, timeInForce, selfTradePrevention, postOnly)
// untriggered stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
// stopLossLimit/takeProfitLimit: (amount, price, postOnly, triggerType, triggerReference, triggerAmount)
updateOrder: async function (market = '', orderId = '', body = {}) {
updateOrder: async function (market = '', orderId = '', operatorId = 0, body = {}) {
await this.checkSocket()
body.action = 'privateUpdateOrder'
body.market = market
body.orderId = orderId
body.operatorId = operatorId
doSendPrivate.call(this, JSON.stringify(body))
},

cancelOrder: async function (market = '', orderId = '') {
cancelOrder: async function (market = '', orderId = '', operatorId = 0) {
await this.checkSocket()
let options = { 'action': 'privateCancelOrder' }
options.market = market
options.orderId = orderId
options.operatorId = operatorId
doSendPrivate.call(this, JSON.stringify(options))
},

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

// options: market
cancelOrders: async function (options = {}) {
cancelOrders: async function (options = {}, operatorId = 0) {
await this.checkSocket()
options.action = 'privateCancelOrders'
options.operatorId = operatorId
doSendPrivate.call(this, JSON.stringify(options))
},

Expand Down