Skip to content
This repository has been archived by the owner on Mar 21, 2021. It is now read-only.

getTransactions method #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
12 changes: 12 additions & 0 deletions examples/get-transactions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const DeGiro = require('..');

(async () => {
const degiro = DeGiro.create({
// username: 'your-username',
// password: 'your-password',
});

await degiro.login();

console.log(await degiro.getTransactions({year: 2019}));
})();
36 changes: 36 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,41 @@ const create = ({
});
};

/**
* Gets the transactions for a given year or between two dates
*
* @param {string} options.fromDate - JavaScript Date instance. Defaults to new Date()
* @param {string} options.toDate - JavaScript Date instance. Defaults to new Date()
* @param {string} options.year - When a year is provided options.fromDate and options.toDate
* will be set automatically to include all the transactions for the year.
* @param {number} options.groupTransactionsByOrder - Groups transactions by order. Defaults to false
* @return {Promise}
*/
const getTransactions = (options = {
fromDate: new Date(),
toDate: new Date(),
year: null,
groupTransactionsByOrder: false
}) => {
const formatDate = d =>
d.toISOString().slice(0, 10).split("-").reverse().join("/");
options.intAccount = session.account;
options.sessionId = session.id;
// Providing a year will set fromDate and toDate
if (options.year) {
options.fromDate = new Date(`${options.year}`);
options.toDate = new Date(
new Date(`${options.year + 1}`) - 3600001
);
}
options.fromDate = formatDate(options.fromDate);
options.toDate = formatDate(options.toDate);
const params = querystring.stringify(options);
log('getTransactions', params);
return fetch(`${urls.reportingUrl}/v4/transactions?${params}`)
.then(res => res.json());
};

/**
* Get client info
*
Expand Down Expand Up @@ -484,6 +519,7 @@ const create = ({
login,
searchProduct,
getData,
getTransactions,
getCashFunds,
getPortfolio,
getAskBidPrice,
Expand Down