degiroasync.api’s documentation

High-level API for DEGIRO platform.

This module provides an interface that is higher level than the webapi module (or the direct HTTP API). It provides various data structures with guaranteed fields, and functions to build or act on those data structures.

Users should only import directly from degiroasync.api, its submodules should be considered implementation details.

Data Structures

Details on data structures are available for each data structure.

Core structures to be aware off when dealing with degiroasync are:

  • Session It is necessary with almost every call in this module. Session contains session identifier, as well as basic mapping information between identifiers and objects.

  • Product A product per DEGIRO API. This can be a Shares, ETF or any other product available on the platform.

  • Order An order per DEGIRO API. As in the web trader, an order can be active or not, and different order types exist (BUY, SELL, LIMITED …).

  • Transaction A transaction per DEGIRO API. This reflects cash impacts on the account. There can be zero to many transactions per Order. As of 2022.03, DEGIRO API does not seem to provide relationship between transactions and orders.

Other data structures are available, but more situational. They can be found in the module members documentation.

Functions

Several functions reflecting the API calls are implemented in this module, An overview of some of the essential ones is listed below. Details can be found with each function documentation:

  • login Builds a Session instance, this supports login with or without 2FA.

  • get_portfolio and get_portfolio_total Provide data on products currently held on the account.

  • search_product Find and instantiate DEGIRO products from various search options (text, ISIN, symbol, exchange …).

  • get_price_series Get price data on a Product.

  • get_orders and check_order Get orders on the account, start placing an order. Note: webapi module must currently be used to confirm an order.

class degiroasync.api.Country
class degiroasync.api.Credentials(username: str, password: str, totp_secret: str | None = None, one_time_password: str | None = None)

Holds credentials for Web API.

If 2FA is enabled on the account, either totp_secret or one_time_password must be provided for the login to be successful.

totp_secret can be obtained in a 2FA editor/app (e.g. andOTP) in the ‘Secret’ field.

If use of one_time_password is chosen instead, be mindful that login must be called promptly as one_time_password expires frequently.

class degiroasync.api.Exchange
class degiroasync.api.ExchangeDictionary(session: SessionCore)

Usage:

exchangedict = await ExchangeDictionary(session)
exchangedict.exchange_by(hiqAbbr='EPA')
exchange_by(*, name: str | None = None, id: int | None = None, hiq_abbr: str | None = None, mic_code: str | None = None) CustomJSONWrapper

Get Exchange by either name, hiqAbbr (e.g. EPA), micCode (e.g. XPAR).

async populate_indices_info(session: Session)

Populate info attribute for all indices.

class degiroasync.api.Index
class degiroasync.api.Order
class degiroasync.api.PriceSeries(*, start: datetime, end: datetime, currency: str, resolution: RESOLUTION, series: Dict[str, List[List[int | float]]])
items() Iterable[Tuple[str, List[float | datetime]]]
iterrows() Iterable[Dict[str, datetime | float]]

Provide data by columns, can be fed directly to instantiate a pandas.DataFrame

With pandas.DataFrame:

>>> pricedata = PriceData(
        start=datetime.datetime(2023, 6, 29),
        end=datetime.datetime(2023, 7, 5),
        resolution=PRICE.RESOLUTION.OHLC
        currency='EUR',
        data={
            'data': [
                [0, 1., 4., 0., 2.],
                [1, 2., 4., 0., 2.]
                ],
            'type': 'ohlc',
            'times': '2023-06-29/P1D',
            'expires': '2023-07-05T17:54:21.7030064+02:00',
            }
        )
>>> import pandas as pd
>>> df = pd.DataFrame(pricedata.iterrows())
>>> df.columns
Index(['date', 'open', 'high', 'low', 'close'], dtype='object')
>>> df.iloc[0]['date']
Timestamp('2023-06-29 00:00:00')
>>> df['open']
0    1.
1    2.
Name: open, dtype: float64
class degiroasync.api.Region
class degiroasync.api.Session(session_core: SessionCore, dictionary: ExchangeDictionary)
class degiroasync.api.TotalPortfolio
class degiroasync.api.Transaction
async degiroasync.api.check_order(session: SessionCore, *, product: ProductBase, buy_sell: ACTION, time_type: TIME, order_type: TYPE, size: int, price: float | None = None) Dict[str, Any]

This must be called to obtain a confirmation_id prior to confirming an order.

This can also be used to get an order fees before confirming the order.

# Get your products through search_product
check_order(
    product=product,
    buy_sell=ORDER.ACTION.SELL,
    time_type=ORDER.TIME,
    order_type=ORDER.TYPE,
    size=1,
    price=100
)

WARNING: This call is rate limited at the end-point level, tests would show the call to be rate limited at 1 per second. Users should throttle their calls to this function.

Example return:

{
    'confirmation_id': '0f404158-3628-414b-87fc-91e2ab2ba1ee',
    'free_space_new': 62283.1,
    'transaction_fee': 0.5,
    'show_ex_ante_report_link': True
}

In the case of a SELL order, the parameter ‘transaction_opposite_fee’ has also been observed. It does not seem to serve a differente purpose than transaction_fee.

async degiroasync.api.get_dictionary(session: Session) ExchangeDictionary

Return a new ExchangeDictionary from Session.

async degiroasync.api.get_orders(session: SessionCore, from_date: datetime | None = None, to_date: datetime | None = None) CustomJSONWrapper]]

Get current orders and history.

to_date

Request orders history up to to_date. Defaults to today.

from_date

Request orders history from from_date. Defaults to today - 7 days.

Return current_orders, historical_orders.

async degiroasync.api.get_portfolio(session: SessionCore) CustomJSONWrapper]

Returns Products in portfolio. Refer to Products classes for minimum available attributes.

async degiroasync.api.get_portfolio_total(session: SessionCore) CustomJSONWrapper

Returns (TotalPortfolio, Products). Refer to TotalPortfolio and Products classes for attributes available.

async degiroasync.api.get_price_data(*args, **kwargs)

DEPRECATED: Please use get_price_series instead.

async degiroasync.api.get_price_series(session: SessionCore, product: Stock, resolution: RESOLUTION = RESOLUTION.PT1D, period: PERIOD = PERIOD.P1MONTH, timezone: str = 'Europe/Paris', culture: str = 'fr-FR', data_type: TYPE = TYPE.PRICE) PriceSeries

Get price data for product.

Parameters:
  • product – Product to look for the data.

  • resolution

    How often do we want data points.

    See RESOLUTION for available values.

  • period

    Period between now and data starting point.

    See PERIOD for available values.

  • data_type

    Specify if we want raw price, or ‘ohlc’ (open, high, low, close) information. The latter might be useful for long periods where high resolution is not available.

    See TYPE for available values.

Returns:

Contains price data and time information.

Return type:

PriceSeriesTime

async degiroasync.api.get_transactions(session: SessionCore, from_date: datetime | None = None, to_date: datetime | None = None) CustomJSONWrapper]

Get transactions for session.

from_date

Request transactions from from_date. Defaults to to_date - 7 days.

to_date

Request transactions to to_date. Defaults to today.

async degiroasync.api.login(credentials: Credentials, session: Session | None = None, /, safeguard_incorrect_credentials: bool = True) Session

Authentify with Degiro API and populate basic information that’ll be needed for further calls.

session will be updated with required data for further connections.

Roughly equivalent to:

session = await degiroasync.webapi.login(credentials)
await webapi.get_config(session)
await webapi.get_client_info(session)

If no session is provided, create one.

Parameters:
  • credentials – Credentials with which we attempt login.

  • session – If provided, populate with API config. If not a new Session will be created.

  • safeguard_incorrect_credentials – Defaults to True. If True, store credentials hash in case of failure and do not allow new login attempts with same hash. This allows to avoid blocking account in case of inaccurate credentials.

Raises:
  • BadCredentialsError: – If login with those credentials returned a bad credentials response.

  • ResponseError: – Other response errors.

async degiroasync.api.search_product(session: ~degiroasync.api.session.Session, *, by_text: str | None = None, by_isin: str | None = None, by_symbol: str | None = None, by_country: str | None = None, by_exchange: str | ~jsonloader.jsonloader.JSONclass.<locals>.decorator.<locals>.CustomJSONWrapper | None = None, by_index: str | ~jsonloader.jsonloader.JSONclass.<locals>.decorator.<locals>.CustomJSONWrapper | None = None, product_type_id: ~degiroasync.core.constants.PRODUCT.TYPEID | None = TYPEID.STOCK, max_iter: int | None = 1000) List[ProductBase]

Access product_search endpoint.

Exactly one of by_text, by_isin, by_symbol be set. Note: API endpoint doesn’t return expected results with both text and ISIN search.

Parameters:
  • by_text – As a search text in Degiro search field website.

  • by_isin – Will look-up products with provided ISIN identifier.

  • by_symbol – Product outputs will be filtered on their ‘symbol’.

  • by_country – Products matching this argument, string must be ISO 3166-1 alpha-2 2 letters code.

  • product_type_id – Restricts search to one type of products. See TYPEID

  • by_exchange – Restricts results to products in an exchange. Can be either an Exchange instance or an hiq_abbr str (e.g. EPA for Paris, AEX for Amsterdam)

  • by_index – Restricts results to products in an index. Can be either an Index instance or an index name str.

  • product_type_id – Restricts search to one type of products.

  • max_iter – Pull max_iter pages of results. If None, don’t stop until end is reached. Default value: 1000.

Returns:

  • Return a list of ProductBase objects returned by Degiro for

  • search_txt attribute.