Skip to content
This repository was archived by the owner on Mar 21, 2021. It is now read-only.
Open
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
11 changes: 11 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[ignore]

[include]

[libs]

[lints]

[options]

[strict]
35 changes: 29 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@flow
const fetch = require('node-fetch');
const querystring = require('querystring');
const parseCookies = require('cookie').parse;
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -393,7 +394,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;
Expand All @@ -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}));

};

/**
Expand All @@ -443,10 +445,30 @@ const create = ({
)
.then(res => res.json())
.then(checkSuccess)
.then(json => ({orderId: json.orderId}));
.then(json => ({orderId: json.data.orderId}));
};

/**
* Cancel order
*
* @param {string} confirmationId - As returned by checkOrder()
* @return {Promise} Resolves to {} (empty object, response from Degiro)
*/
const cancelOrder = (confirmationId) => {
log('cancelOrder', 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'}
}
)
.then(res => res.json())
};

/**
/**
* Check and place Order
*
* @param {number} options.buySell - See Actions
Expand Down Expand Up @@ -488,6 +510,7 @@ const create = ({
getPortfolio,
getAskBidPrice,
setOrder,
cancelOrder,
deleteOrder,
getOrders,
getProductsByIds,
Expand Down