degiro-api
Version:
Unofficial DeGiro API for Javascript. Buy and sell in the stock market. See your portfolio and much more
36 lines (32 loc) • 1.1 kB
text/typescript
// Import types
import { AccountDataType, AccountConfigType } from '../types'
// Import debug console log
import { debug } from '../utils'
export function getAccountDataRequest(accountConfig: AccountConfigType): Promise<AccountDataType> {
return new Promise((resolve, reject) => {
const requestOptions: {
method?: string,
body?: string,
headers: {
[key: string]: string,
},
credentials: 'include',
referer: string,
} = {
headers: {
Cookie: `JSESSIONID=${accountConfig.data.sessionId};`,
},
credentials: 'include',
referer: 'https://trader.degiro.nl/trader/',
}
// Do the request to get a account config data
debug(`Making request to ${accountConfig.data.paUrl}client?sessionId=${accountConfig.data.sessionId}`)
fetch(`${accountConfig.data.paUrl}client?sessionId=${accountConfig.data.sessionId}`, requestOptions)
.then(res => res.json())
.then((res: AccountDataType) => {
debug('Response:\n', JSON.stringify(res, null, 2))
resolve(res)
})
.catch(reject)
})
}