degiro-api
Version:
Unofficial DeGiro API for Javascript. Buy and sell in the stock market. See your portfolio and much more
38 lines (33 loc) • 1.18 kB
text/typescript
// Import types
import { AccountConfigType, AccountDataType, ConfigDictionaryType } from '../types'
// Import debug console log
import { debug, fetch } from '../utils'
export function getConfigDictionaryRequest(accountData: AccountDataType, accountConfig: AccountConfigType): Promise<ConfigDictionaryType> {
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
const uri = `${accountConfig.data.dictionaryUrl}?intAccount=${accountData.data.intAccount}&sessionId=${accountConfig.data.sessionId}`
debug(`Making request to ${uri}`)
fetch(uri, requestOptions)
.then(res => res.json())
.then((res: ConfigDictionaryType) => {
debug('Response:\n', JSON.stringify(res, null, 2))
resolve(res)
})
.catch(reject)
})
}