Install degiro-api via npm or yarn
masterInstall the degiro-api package as a dependency in your project using your preferred package manager.
# using npm
npm install --save degiro-api
# using yarn
yarn add degiro-apirepository·master·Indexed 42 days ago
https://github.com/icastillejogomez/degiro-apiAn unofficial TypeScript backend client for the DeGiro trading platform. Version 1.0.6 provides functionality for automated order management, fund tracking, product searches, and portfolio monitoring. It supports One-Time Passwords (OTP), session reuse via JSESSIONID, and includes a separate CLI tool for terminal-based interaction.
Install the degiro-api package as a dependency in your project using your preferred package manager.
# using npm
npm install --save degiro-api
# using yarn
yarn add degiro-apiTo avoid frequent login/logout requests (which can be flagged by DeGiro), you can extract the jsessionId from an active session and reuse it in a new instance.
await degiro.login(), use degiro.getJSESSIONID() (note: this is a synchronous method, not a promise).jsessionId into the DeGiro constructor along with your credentials. You must then call await degiro.login() to re-hydrate the account configuration data.import DeGiro from 'degiro-api'
// 1. Extracting the session ID
(async () => {
const degiro = new DeGiro({}) // Uses ENV variables
await degiro.login()
const jsessionId = degiro.getJSESSIONID()
})()
// 2. Reusing the session ID
(async () => {
const degiro = new DeGiro({
username: '<your_username_here>',
pwd: '<your_password_here>',
oneTimePassword: '<your_one_time_password_here>',
jsessionId: '<your_jsessionId_here>',
})
// Re-hydrate the account config
await degiro.login()
// Do your stuff here...
})()To interact with the DeGiro API, you must first create an instance of the DeGiro class. You can provide credentials directly in the constructor, use the static create method, or rely on environment variables.
Note: This is a backend-only library. It cannot be used in a frontend environment due to DeGiro's CORS policy.
// Using constructor with credentials
const DeGiro = require('degiro-api').default
const degiro = new DeGiro({
username: '<your_username_here>',
pwd: '*****'
})
// OR using the static create method
const degiro = DeGiro.create({ username: '*****', pwd: '*****' })
// OR using environment variables (DEGIRO_USER & DEGIRO_PWD)
const degiro = new DeGiro()You can enable detailed logging for debugging purposes by setting the DEGIRO_DEBUG environment variable to any truthy value.
$ export DEGIRO_DEBUG=1
$ yarn startYou can initialize the DeGiro client using the constructor or the static create method. The client accepts a DeGiroSettupType object. If credentials are not provided in the object, the client will attempt to read them from the following environment variables:
DEGIRO_USER: Your usernameDEGIRO_PWD: Your passwordDEGIRO_OTP: Your one-time password (if applicable)DEGIRO_JSESSIONID: An existing session ID to bypass loginNote: If neither a username nor a jsessionId is provided, the client will throw an error.
import { DeGiro } from './DeGiro';
// Using the static create method
const degiro = DeGiro.create({
username: 'my_username',
pwd: 'my_password',
oneTimePassword: '123456'
});
// Or using environment variables implicitly
// process.env.DEGIRO_USER = '...';
// const degiro = new DeGiro();Access various aspects of your DeGiro account using the following methods:
getAccountConfig(): Returns AccountConfigType.getAccountData(): Returns AccountDataType (note: login() also returns this).getAccountState(options: GetAccountStateOptionsType): Returns an array of account state data.getAccountReports(): Returns AccountReportsType.getAccountInfo(): Returns AccountInfoType.import DeGiro from 'degiro-api'
const degiro = new DeGiro({ username: '...', pwd: '...' })
await degiro.login()
const config = await degiro.getAccountConfig()
const data = await degiro.getAccountData()
const state = await degiro.getAccountState()
const reports = await degiro.getAccountReports()
const info = await degiro.getAccountInfo()Search for financial products using searchProduct(options: SearchProductOptionsType).
Options:
text (required): The search string (e.g., 'AAPL').type (optional): A DeGiroProducTypes enum value.limit (optional): Number of results (default: 10).offset (optional): Pagination offset (default: 0).DeGiroProducTypes:
shares: 1bonds: 2futures: 7options: 8investmendFunds: 13leveragedProducts: 14etfs: 131cfds: 535warrants: 536import DeGiro, { DeGiroEnums } from 'degiro-api'
const { DeGiroProducTypes } = DeGiroEnums
const degiro = new DeGiro({ username: '...', pwd: '...' })
await degiro.login()
// Search for TSLA shares with a limit of 1
const result = await degiro.searchProduct({
text: 'TSLA',
type: DeGiroProducTypes.shares,
limit: 1,
})Fetch your portfolio using getPortfolio(config: GetPorfolioConfigType).
Config Options:
type: Filter positions using PORTFOLIO_POSITIONS_TYPE_ENUM:ALL: All positions.ALL_POSITIONS: Only product positions (excludes 'CASH').OPEN: Only opened positions.CLOSED: Only closed positions.getProductDetails (boolean): If true, results include a productData field with full product details.import DeGiro, { DeGiroEnums } from 'degiro-api'
const { PORTFOLIO_POSITIONS_TYPE_ENUM } = DeGiroEnums
const degiro = new DeGiro({ username: '...', pwd: '...' })
await degiro.login()
// Get all open positions with full product details
const portfolio = await degiro.getPortfolio({
type: PORTFOLIO_POSITIONS_TYPE_ENUM.ALL,
getProductDetails: true,
})Use the session endpoints to handle authentication and session state. You must instantiate DeGiro with your credentials before calling login().
login(): Authenticates and returns AccountDataType.logout(): Ends the current session.isLogin(options?: IsLoginOptionsType): Checks if the user is currently authenticated. Can be used with { secure: true }.getJSESSIONID(): Returns the current JSESSIONID string if logged in, otherwise undefined.import DeGiro from 'degiro-api'
const degiro = new DeGiro({
username: 'your_username',
pwd: 'your_password',
})
// Login
const accountData = await degiro.login()
// Check status
const isLogin = await degiro.isLogin({ secure: true })
// Get session ID
const sessionId = degiro.getJSESSIONID()
// Logout
await degiro.logout()The API allows for a two-step order process: creating an order and then executing it.
Use createOrder(order: OrderType).
OrderType properties:
buySell: DeGiroActions (BUY or SELL).orderType: DeGiroMarketOrderTypes (LIMITED: 0, MARKET: 2, STOP_LOSS: 3, STOP_LOSS_LIMIT: 1).price (optional): Limit price.productId: The product ID string.size: Number of units.stopPrice (optional): Stop price.timeType: DeGiroTimeTypes (DAY: 1, PERMANENT: 3).Use executeOrder(order: OrderType, executeId: string) where executeId is the confirmationId returned from createOrder.
Use deleteOrder(orderId: string) to remove an order. Note: It is recommended to wait a few seconds after execution before attempting to delete to avoid rate limit errors.
import DeGiro, { DeGiroEnums, DeGiroTypes } from 'degiro-api'
const { DeGiroActions, DeGiroMarketOrderTypes, DeGiroTimeTypes } = DeGiroEnums
const { OrderType } = DeGiroTypes
const degiro = new DeGiro({ username: '...', pwd: '...' })
await degiro.login()
const order: OrderType = {
buySell: DeGiroActions.BUY,
orderType: DeGiroMarketOrderTypes.LIMITED,
productId: '331868',
size: 1,
timeType: DeGiroTimeTypes.DAY,
price: 272,
}
// Step 1: Create
const { confirmationId } = await degiro.createOrder(order)
// Step 2: Execute
const orderId = await degiro.executeOrder(order, confirmationId)
// Step 3: Delete (after a delay to avoid rate limits)
setTimeout(async () => {
await degiro.deleteOrder(orderId)
}, 2000)The isLogin() method checks if the instance has account configuration data.
degiro.isLogin() returns a boolean immediately based on local state. This does not verify if the session is still active on DeGiro's servers.await degiro.isLogin({ secure: true }) returns a Promise. It performs a real API request (typically getAccountConfig) to verify that the session is still valid. If it returns false, you should call await degiro.login().import DeGiro from 'degiro-api'
(async () => {
const degiro = new DeGiro({}) // Uses ENV variables
// Force a network request to verify the session is actually alive
if(! await degiro.isLogin({ secure: true })) {
await degiro.login()
}
})()The following enums and types are available via the DeGiroEnums and DeGiroTypes exports to ensure type safety when constructing orders and searches.
DeGiroActions
BUY: 'BUY'SELL: 'SELL'DeGiroMarketOrderTypes
LIMITED: 0MARKET: 2STOP_LOSS: 3STOP_LOSS_LIMIT: 1DeGiroTimeTypes
DAY: 1PERMANENT: 3DeGiroProducTypes
shares: 1bonds: 2futures: 7options: 8investmendFunds: 13leveragedProducts: 14etfs: 131cfds: 535warrants: 536