From 0d8cb6b49197bc90d8c20a6b929b6db09b7d0898 Mon Sep 17 00:00:00 2001 From: Anders Back Date: Wed, 29 May 2019 16:23:37 +0200 Subject: [PATCH 1/4] Cancel Order --- src/index.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 93e53ff..92c36be 100644 --- a/src/index.js +++ b/src/index.js @@ -393,7 +393,7 @@ const create = ({ * @param {number} order.timeType - See TimeTypes * @param {number} order.price - Required for limited and stopLimited orders * @param {number} order.stopPrice - Required for stopLoss and stopLimited orders - * @return {Promise} Resolves to {order: Object, confirmationId: string} + * @return {Promise} Resolves to {order: Object, mOmationId: string} */ const checkOrder = order => { const {buySell, orderType, productId, size, timeType, price, stopPrice} = order; @@ -445,6 +445,25 @@ const create = ({ .then(checkSuccess) .then(json => ({orderId: json.orderId})); }; + + /** + * Cancel order + * + * @param {string} options.confirmationId - As returned by checkOrder() + * @return {Promise} Resolves to {} (empty object, response from Degiro) + */ + const cancelOrder = ({order, confirmationId}) => { + log('cancelOrder', {order, confirmationId}); + return fetch( + `${urls.tradingUrl}v5/order/${confirmationId};jsessionid=${session.id}?intAccount=${ + session.account + }&sessionId=${session.id}`, + { + method: 'DELETE', + headers: {'Content-Type': 'application/json;charset=UTF-8'} + } + ) + }; /** * Check and place Order From 3c649f2fab3d9c47791deb1e8ea35db98c12e06d Mon Sep 17 00:00:00 2001 From: Anders Back Date: Wed, 29 May 2019 16:24:37 +0200 Subject: [PATCH 2/4] Update index.js --- src/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 92c36be..2de10e7 100644 --- a/src/index.js +++ b/src/index.js @@ -449,11 +449,11 @@ const create = ({ /** * Cancel order * - * @param {string} options.confirmationId - As returned by checkOrder() + * @param {string} confirmationId - As returned by checkOrder() * @return {Promise} Resolves to {} (empty object, response from Degiro) */ - const cancelOrder = ({order, confirmationId}) => { - log('cancelOrder', {order, confirmationId}); + const cancelOrder = (confirmationId) => { + log('cancelOrder', confirmationId); return fetch( `${urls.tradingUrl}v5/order/${confirmationId};jsessionid=${session.id}?intAccount=${ session.account From 24a28b4897da45ce242ce194836a83cfb89cb6a8 Mon Sep 17 00:00:00 2001 From: Anders Back Date: Fri, 31 May 2019 08:31:10 +0200 Subject: [PATCH 3/4] added Cancel order --- src/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 2de10e7..e7c6faa 100644 --- a/src/index.js +++ b/src/index.js @@ -463,9 +463,10 @@ const create = ({ headers: {'Content-Type': 'application/json;charset=UTF-8'} } ) + .then(res => res.json()) }; - /** + /** * Check and place Order * * @param {number} options.buySell - See Actions @@ -507,6 +508,7 @@ const create = ({ getPortfolio, getAskBidPrice, setOrder, + cancelOrder, deleteOrder, getOrders, getProductsByIds, From 48d9e1acac89af996d9b7d4abd646858dcb7a435 Mon Sep 17 00:00:00 2001 From: andersback Date: Wed, 31 Jul 2019 17:19:32 +0200 Subject: [PATCH 4/4] Better api --- .flowconfig | 11 +++++++++++ src/index.js | 10 ++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 .flowconfig diff --git a/.flowconfig b/.flowconfig new file mode 100644 index 0000000..1fed445 --- /dev/null +++ b/.flowconfig @@ -0,0 +1,11 @@ +[ignore] + +[include] + +[libs] + +[lints] + +[options] + +[strict] diff --git a/src/index.js b/src/index.js index e7c6faa..24298dc 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,4 @@ +//@flow const fetch = require('node-fetch'); const querystring = require('querystring'); const parseCookies = require('cookie').parse; @@ -37,8 +38,8 @@ const create = ({ }; const checkSuccess = res => { - if (res.status !== 0) { - throw Error(res.message); + if (res.errors !== undefined && res.errors !== null) { + throw Error(res.message) } return res; }; @@ -419,7 +420,8 @@ const create = ({ ) .then(res => res.json()) .then(checkSuccess) - .then(json => ({order, confirmationId: json.confirmationId})); + .then(json => ({order, confirmationId: json.data.confirmationId})); + }; /** @@ -443,7 +445,7 @@ const create = ({ ) .then(res => res.json()) .then(checkSuccess) - .then(json => ({orderId: json.orderId})); + .then(json => ({orderId: json.data.orderId})); }; /**