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