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
9 changes: 9 additions & 0 deletions src/fetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// fetch.js
//via https://github.com/node-fetch/node-fetch/issues/591#issuecomment-474457866
const fetch = require('node-fetch')

module.exports = (url, args = {}) => {
args.headers = args.headers || {}
args.headers['user-agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:75.0) Gecko/20100101 Firefox/75.0'
return fetch(url, args)
}
26 changes: 13 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fetch = require('node-fetch');
const fetch = require('./fetch.js');
const querystring = require('querystring');
const parseCookies = require('cookie').parse;
const {Actions, OrderTypes, TimeTypes, ProductTypes, Sort} = require('./constants');
Expand Down Expand Up @@ -37,8 +37,8 @@ const create = ({
};

const checkSuccess = res => {
if (res.status !== 0) {
throw Error(res.message);
if (res.errors !== undefined && res.errors !== null) {
throw Error(res.errors[0].text);
}
return res;
};
Expand Down Expand Up @@ -153,7 +153,7 @@ const create = ({
method: 'POST',
headers: {Origin: 'https://trader.degiro.nl'},
body: JSON.stringify({
controlData: `req(${issueId}.BidPrice);req(${issueId}.AskPrice);req(${issueId}.LastPrice);req(${issueId}.LastTime);`,
controlData: `req(${issueId}.BidPrice);req(${issueId}.AskPrice);req(${issueId}.LastPrice);req(${issueId}.LastTime);req(${issueId}.OpenPrice);req(${issueId}.HighPrice);req(${issueId}.LowPrice);req(${issueId}.RelativeDifference);req(${issueId}.AbsoluteDifference);`,
}),
})
.then(() => fetch(`https://degiro.quotecast.vwdservices.com/CORS/${vwdSession.sessionId}`))
Expand Down Expand Up @@ -268,12 +268,12 @@ const create = ({
})
.then(res => res.json())
.then(res => {
urls.paUrl = res.paUrl;
urls.productSearchUrl = res.productSearchUrl;
urls.productTypesUrl = res.productTypesUrl;
urls.reportingUrl = res.reportingUrl;
urls.tradingUrl = res.tradingUrl;
urls.vwdQuotecastServiceUrl = res.vwdQuotecastServiceUrl;
urls.paUrl = res.data.paUrl;
urls.productSearchUrl = res.data.productSearchUrl;
urls.productTypesUrl = res.data.productTypesUrl;
urls.reportingUrl = res.data.reportingUrl;
urls.tradingUrl = res.data.tradingUrl;
urls.vwdQuotecastServiceUrl = res.data.vwdQuotecastServiceUrl;
});

/**
Expand All @@ -287,8 +287,8 @@ const create = ({
let loginParams = {
username,
password,
isPassCodeReset: false,
isRedirectToMobile: false,
loginButtonUniversal: '',
queryParams: {reason: 'session_expired'},
};

Expand Down Expand Up @@ -419,7 +419,7 @@ const create = ({
)
.then(res => res.json())
.then(checkSuccess)
.then(json => ({order, confirmationId: json.confirmationId}));
.then(json => ({order, confirmationId: json.data.confirmationId}));
};

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

/**
Expand Down