Unofficial DeGiro API
![DeGiro Logo](https://raw.githubusercontent.com/icastillejogomez/degiro-api/master/.assets/degiro.png)
This is an unofficial Node.js API client for DeGiro's trading platform. Using this module you can easily automate your orders (buy and sell) and get information about orders, funds or products.
DeGiro is Europe's fastest growing online stockbroker. DeGiro distinguishes itself by offering institutional fees to retail investors.
⚠️ DeGiro could change their API at any moment, if something is not working, please open an issue.
Install
npm install --save degiro-api
yarn add degiro-api
Basic examples
Create an instance of DeGiro
Basic log in DeGiro Platform. All endpoint needs a session key before those can be call.
const DeGiro = require('degiro-api')
const degiro = new DeGiro({
username: 'username',
pwd: '*****'
})
degiro.login()
.then(() => console.log('Log in success'))
.catch(console.error)
Get account details
Get account info using await
:
import DeGiro from 'degiro-api'
(async () => {
const degiro = new DeGiro({
username: 'username',
pwd: '*****'
})
await degiro.login()
const accountData = await degiro.getAccountData()
})()
Get portfolio
getPortfolio
params are:
Get all open positions:
import DeGiro, { DeGiroEnums, DeGiroTypes } from 'degiro-api'
const { PORTFOLIO_POSITIONS_TYPE_ENUM } = DeGiroEnums
(async () => {
const degiro: DeGiro = new DeGiro({
username: 'your_username_here',
pwd: '**********',
})
await degiro.login()
const portfolio = await degiro.getPortfolio({
type: PORTFOLIO_POSITIONS_TYPE_ENUM.ALL,
getProductDetails: true,
})
console.log(JSON.stringify(portfolio, null, 2))
})()
Also you can fetch your portfolio data this way:
import DeGiro, { DeGiroEnums, DeGiroTypes } from 'degiro-api'
const { PORTFOLIO_POSITIONS_TYPE_ENUM } = DeGiroEnums
(async () => {
const degiro: DeGiro = new DeGiro({
username: 'your_username_here',
pwd: '**********',
})
await degiro.login()
const portfolio = await degiro.getPortfolio({ type: PORTFOLIO_POSITIONS_TYPE_ENUM.ALL })
console.log(JSON.stringify(portfolio, null, 2))
})()
And getting product details too
import DeGiro, { DeGiroEnums, DeGiroTypes } from 'degiro-api'
const { PORTFOLIO_POSITIONS_TYPE_ENUM } = DeGiroEnums
(async () => {
const degiro: DeGiro = new DeGiro({
username: 'your_username_here',
pwd: '**********',
})
await degiro.login()
const portfolio = await degiro.getPortfolio({
type: PORTFOLIO_POSITIONS_TYPE_ENUM.ALL,
getProductDetails: true,
})
console.log(JSON.stringify(portfolio, null, 2))
})()
Search product, stock and much more in broker
degiro.searchProduct(options): Promise<SearchProductResultType[]>
- options:
- text: required string,
- type: optional DeGiroProducTypes
- limit: optional number default=10,
- offset: optional number default=0,
DeGiroProducTypes
- shares: 1
- bonds: 2
- futures: 7
- options: 8
- investmendFunds: 13
- leveragedProducts: 14
- etfs: 131
- cfds: 535
- warrants: 536
Search the text "AAPL" without any limitation
import DeGiro from 'degiro-api'
(async () => {
const degiro: DeGiro = new DeGiro({
username: 'your_username_here',
pwd: '***********',
})
await degiro.login()
const result = await degiro.searchProduct({ text: 'AAPL' })
console.log(JSON.stringify(result, null, 2))
})()
Search TSLA stock
import DeGiro, { DeGiroEnums, DeGiroTypes } from 'degiro-api'
const { DeGiroProducTypes } = DeGiroEnums
(async () => {
const degiro: DeGiro = new DeGiro({
username: 'your_username_here',
pwd: '***********',
})
await degiro.login()
const result = await degiro.searchProduct({
text: 'TSLA',
type: DeGiroProducTypes.shares,
limit: 1,
})
console.log(JSON.stringify(result, null, 2))
})()
DeGiro Orders
Create a new order
degiro.createOrder(order: OrderType): Promise<CreateOrderResultType>
-
OrderType
- buySell: DeGiroActions,
- orderType: DeGiroMarketOrderTypes,
- price: optional Number,
- productId: string,
- size: number,
- stopPrice: optional number,
- timeType: DeGiroTimeTypes,
-
DeGiroActions
-
DeGiroMarketOrderTypes
- LIMITED: 0,
- MARKET: 2,
- STOP_LOSS: 3,
- STOP_LOSS_LIMIT: 1,
-
DeGiroTimeTypes
-
CreateOrderResultType
- confirmationId: String,
- freeSpaceNew: Number,
- transactionFees: [TransactionFeeType],
-
TransactionFeeType
- amount: Number,
- currency: String,
- id: Number,
import DeGiro, { DeGiroEnums, DeGiroTypes } from 'degiro-api'
const { DeGiroActions, DeGiroMarketOrderTypes, DeGiroTimeTypes } = DeGiroEnums
const { OrderType } = DeGiroTypes
(async () => {
const degiro: DeGiro = new DeGiro({
username: 'your_username_here',
pwd: '************'
})
await degiro.login()
const order: OrderType = {
buySell: DeGiroActions.BUY,
orderType: DeGiroMarketOrderTypes.LIMITED,
productId: '331868',
size: 1,
timeType: DeGiroTimeTypes.DAY,
price: 272,
}
const { confirmationId, freeSpaceNew, transactionFees } = await degiro.createOrder(order)
console.log(JSON.stringify({ confirmationId, freeSpaceNew, transactionFees }, null, 2))
})()
Execute an order
import DeGiro, { DeGiroEnums, DeGiroTypes } from 'degiro-api'
const { DeGiroActions, DeGiroMarketOrderTypes, DeGiroTimeTypes } = DeGiroEnums
const { OrderType } = DeGiroTypes
(async () => {
try {
const degiro: DeGiro = new DeGiro({
username: 'nachoogoomezomg',
pwd: <string>process.env.DEGIRO_PWD,
})
await degiro.login()
const order: OrderType = {
buySell: DeGiroActions.BUY,
orderType: DeGiroMarketOrderTypes.LIMITED,
productId: '331868',
size: 1,
timeType: DeGiroTimeTypes.DAY,
price: 270,
}
const { confirmationId, freeSpaceNew, transactionFees } = await degiro.createOrder(order)
const orderId = await degiro.executeOrder(order, confirmationId)
console.log(`Order executed with id: ${orderId}`)
} catch (error) {
console.error(error)
}
})()
Remove an order
import DeGiro, { DeGiroEnums, DeGiroTypes } from 'degiro-api'
const { DeGiroActions, DeGiroMarketOrderTypes, DeGiroTimeTypes } = DeGiroEnums
const { OrderType } = DeGiroTypes
(async () => {
const degiro: DeGiro = new DeGiro({
username: 'nachoogoomezomg',
pwd: <string>process.env.DEGIRO_PWD,
})
await degiro.login()
const order: OrderType = {
buySell: DeGiroActions.BUY,
orderType: DeGiroMarketOrderTypes.LIMITED,
productId: '331868',
size: 1,
timeType: DeGiroTimeTypes.DAY,
price: 272,
}
const { confirmationId, freeSpaceNew, transactionFees } = await degiro.createOrder(order)
const orderId = await degiro.executeOrder(order, confirmationId)
console.log(`Order executed with id: ${orderId}`)
const TIMEOUT_SECONDS = 2 * 1000
const deleteOrderFunction = async () => {
try {
await degiro.deleteOrder(orderId)
console.log('Order removed')
} catch (error) {
console.error(error)
}
}
setTimeout(deleteOrderFunction, TIMEOUT_SECONDS)
})()
TO DO List
- Two factor
- Get prices
Degiro Command Line Interface (CLI)
See the repo degiro-cli.
License
MIT