This is yet another library to access Degiro's API.
⭐️ Hopefully you have starred the project ⭐️
You can contribute to the project in two ways :
Code and documentation : pull requests are welcome !
Feedback : feel free to open an issue or send me a message if you have a feedback or question.
# INSTALL
pip install degiro-connector
# UPGRADE
pip install --no-cache-dir --upgrade degiro-connector
# UNINSTALL
pip uninstall degiro-connector
Here are the features you can access through this library :
Endpoint | Feature(s) |
---|---|
AccountCashReport | Export cash movements in a specific format : CSV, HTML, PDF or XLS. |
AccountInfo | Retrieve a table containing : "clientId" and Currencies. |
AccountOverview | Retrieve all the cash movements between two dates. |
Agenda | Crucial events regarding products : Dividend, Economic, Earnings, Holiday, IPO or Split. |
Bonds ETFs Funds Futures Leverageds Lookup Options Stocks Warrants |
Search list of products according their name, type and other criterias. For instance all the stocks from NASDAQ 100. |
Chart | Retrieve chart data. |
ClientDetails | Retrieve a table containing : "clientId", "intAccount" and other account information. |
CompanyProfile | Retrieve a company's profile using its ISIN code. |
CompanyRatios | Retrieve a company's ratios using its ISIN code. |
Config | Retrieve a table containing : "clientId" and URLs which are constitutive of Degiro's API. |
EstimatesSummaries | Retrieve a company's estimates summaries using its ISIN code. |
Favorites | Add/Delete/Prioritize/Retrieve favorites lists. |
FavoritesProducts | Add/Update products associated with a favorite list. |
FinancialStatements | Retrieve a company's financial statements using its ISIN code. |
LatestNews | Retrieve latest news about all the companies. |
LoginQuotecast | Establish a connection for quotecast operations. |
LoginTrading | Establish a connection for trading operations. |
LogoutTrading | Destroy previously established connection for trading operations. |
NewsByCompany | Retrieve news related to a specific company. |
Order | Create, update, delete an Order. |
OrderHistory | Retrieve all Orders created between two dates. |
Orders | List pending Orders. |
Portfolio | List products in your Portfolio. |
ProductsConfig | Retrieve a table containing : useful parameters to filter products. |
ProductsInfo | Search for products using their ids. |
Quotecasts | Fetch real-time data on financial products. For instance the real-time stock Price. |
TopNewsPreview | Retrieve some news preview about all the companies. |
TotalPorfolio | Retrieve aggregated information about your assets. |
TransactionsHistory | Retrieve all Transactions created between two dates. |
Underlyings | List Underlyings for Futures and Options. |
- 1. Degiro Connector
- 2. Real-time data
- 2.1. What are the workflows ?
- 2.2. How to find your
user_token
? - 2.3. How to get a Chart ?
- 2.4. How to format a chart.series ?
- 2.5. How to find a product
vwd_id
? - 2.6. What are the credentials ?
- 2.7. How to connect ?
- 2.8. Is there a timeout ?
- 2.9. How to subscribe to a data-stream ?
- 2.10. How to unsubscribe to a data-stream ?
- 2.11. How to fetch the data ?
- 2.12. How to use this data ?
- 2.13. Which are the available data types ?
- 2.14. What is a Ticker ?
- 2.15. What is inside the list[Metric] ?
- 2.16. What is inside the DataFrame ?
- 3. Trading connection
- 4. Order
- 5. Portfolio
- 6. Account
- 7. Products
- 7.1. How to get the table : ProductsConfig ?
- 7.2. How to lookup products (search by name) ?
- 7.3. How to search bonds ?
- 7.4. How to search etfs ?
- 7.5. How to search funds ?
- 7.6. How to search futures ?
- 7.7. How to search leverageds ?
- 7.8. How to search options ?
- 7.9. How to search stocks ?
- 7.10. How to search warrants ?
- 7.11. How to search products from ids ?
- 7.12. How to get my favorite products ?
- 7.13. How to create a favorite list ?
- 7.14. How to delete a favorite list ?
- 7.15. How to move a favorite list ?
- 7.16. How to put favorite list products ?
- 7.17. How to delete favorite list products ?
- 7.18. How to get futures/options underlyings ?
- 8. Companies
- 9. License
It is possible to fetch the following data from Degiro's API:
- Charts series data
- Streams of data in real-time
CHARTS
To consume charts series :
A. Fetch charts : directly with your "user_token".
B. Convert to a DataFrame.
REAL-TIME
To consume real-time data-stream :
A. Connect : with your "user_token".
B. Subscribe to metrics.
C. Fetch these metrics.
D. Convert to a DataFrame.
All the details of these steps are explained in the rest of this section.
You can find your "user_token" inside one of these tables :
- "Config" : attribute "clientId"
- "ClientDetails" : attribute "id"
See sections related to "Config" and "ClientDetails" tables.
You can fetch an object containing the same data than in Degiro's website graph.
For that you need to prepare a ChartRequest.
Here is a table with the available attributes for ChartRequest.
Parameter | Type | Description |
---|---|---|
requestid | str | It sends you back whatever string you put here, you can set it to : "1". |
resolution | Chart.Resolution | Resolution of the chart like : Chart.Resolution.PT1M. |
culture | str | Country code like : "en-US" or "fr-FR". |
period | Chart.Period | Period of the chart, like : Chart.Period.P1D. |
series | repeated string | Data to get like : ['issueid:36014897', 'price:issueid:360148977']. |
tz | str | Timezone like : "Europe/Paris" |
Example of code :
chart_fetcher = ChartFetcher(user_token=user_token)
chart_request = ChartRequest(
culture="fr-FR",
# override={
# "resolution": "P1D",
# "period": "P1W",
# },
period=Interval.P1D,
requestid="1",
resolution=Interval.PT60M,
series=[
"issueid:360148977",
"price:issueid:360148977",
"ohlc:issueid:360148977",
"volume:issueid:360148977",
# "vwdkey:AAPL.BATS,E",
# "price:vwdkey:AAPL.BATS,E",
# "ohlc:vwdkey:AAPL.BATS,E",
# "volume:vwdkey:AAPL.BATS,E",
],
tz="Europe/Paris",
)
chart = chart_fetcher.get_chart(
chart_request=chart_request,
raw=False,
)
The issueid
parameter is the vwd_id
of the product from which you want the Chart
data.
See the section related to vwd_id
for more information.
All the models are described in this module : chart.py
For a more comprehensive example :
A Chart object contains a list of series.
There is a SeriesFormatter to help you convertir a series into a polars.DataFrame
.
df = SeriesFormatter.format(series=chart.series)
print(df)
Here are the result for different series.id.
issueid:360148977
issueId | companyId | name | identifier | ... | windowPreviousClosePrice | windowEndPrice |
---|---|---|---|---|---|---|
i64 | i64 | str | str | ... | f64 | f64 |
360148977 | 9245 | Crédit | issueid:3 | ... | 12.858 | -0.00047 |
price:issueid:360148977
timestamp | price |
---|---|
datetime[μs] | f64 |
2023-12-29 09:00:00 | 12.858 |
2023-12-29 10:58:58.800 | 12.85 |
... | ... |
2023-12-29 17:28:58.800 | 12.83 |
2023-12-29 17:34:58.799999 | 12.852 |
volume:issueid:360148977
timestamp | volume |
---|---|
datetime[μs] | f64 |
2023-12-29 09:58:58.800 | 61627.0 |
2023-12-29 10:58:58.800 | 83854.0 |
2023-12-29 11:58:58.800 | 78240.0 |
2023-12-29 12:58:01.200 | 69263.0 |
2023-12-29 13:58:58.800 | 59040.0 |
2023-12-29 14:58:58.800 | 62831.0 |
2023-12-29 15:58:01.200 | 66681.0 |
2023-12-29 16:58:58.800 | 529315.0 |
2023-12-29 17:34:58.799999 | 1.317919e6 |
ohlc:issueid:360148977
timestamp | open | high | low | close |
---|---|---|---|---|
datetime[μs] | f64 | f64 | f64 | f64 |
2023-12-29 09:00:00 | 12.858 | 12.898 | 12.858 | 12.872 |
2023-12-29 10:00:00 | 12.872 | 12.876 | 12.84 | 12.85 |
2023-12-29 11:00:00 | 12.85 | 12.864 | 12.842 | 12.848 |
2023-12-29 12:00:00 | 12.844 | 12.884 | 12.844 | 12.87 |
2023-12-29 13:00:00 | 12.868 | 12.886 | 12.86 | 12.87 |
2023-12-29 14:00:00 | 12.872 | 12.902 | 12.868 | 12.886 |
2023-12-29 15:00:00 | 12.884 | 12.894 | 12.874 | 12.876 |
2023-12-29 16:00:00 | 12.876 | 12.882 | 12.854 | 12.858 |
2023-12-29 17:00:00 | 12.856 | 12.858 | 12.83 | 12.852 |
All the models are described in this module :
For a more comprehensive example :
In operations related to Quotecast
, Degiro uses the vwd_id
to identify a product.
Which means that if you want a Chart
or Real-time data
for a specific product : you first need to find this product's vwd_id
.
This two identifiers are not the same :
Identifier | API name(s) | Description |
---|---|---|
id | str | Id used identify a product in Trading related endpoints. |
vwd_id | issueid vwdId vwdIdSecondary |
Id used identify a product in Quotecast (Chart and Real-time data ) related endpoint. |
Here are some methods you can use to fetch a product's vwd_id
:
product_search
get_products_info
The method product_search
let you use the name or other attributes of a product to fetch it's vwd_id
.
The method get_products_info
let you use a product's id
to fetch it's vwd_id
.
The only credential you need in order to fetch real-time data and charts is the :
- user_token
Beware, these two identifiers are not the same thing :
- user_token : used to fetch real-time data and charts.
- int_account : used for some trading operations.
In order to fetch data you need to establish a connection.
You can use the following code to connect :
session_id = TickerFetcher.get_session_id(user_token=YOUR_USER_TOKEN)
Connection timeout is around 15 seconds.
Which means a connection will cease to work after this timeout.
This timeout is reset each time you use this connection to :
- Subscribe to a metric (for instance a stock Price)
- Fetch the data-stream
So if you use it nonstop (in a loop) you won't need to reconnect.
If one needs the following data from the "AAPL" stock :
- LastDate
- LastTime
- LastPrice
- LastVolume
You can use this library to retrieve updates like this :
product_id | LastPrice | LastVolume | LastDatetimeUTC | request_duration_s | response_datetime_utc |
---|---|---|---|---|---|
str | f64 | i64 | datetime[μs] | f64 | datetime[μs] |
360015751 | 34.6 | 1 | 2023-12-29 16:35:23 | 1.021337 | 2024-01-01 17:31:22.482618 |
AAPL.BATS,E | 192.55 | null | 2023-12-29 20:59:59 | 1.021337 | 2024-01-01 17:31:22.482618 |
To subscribe to a data-stream you need to setup a TickerRequest.
A Request has the following parameters :
Parameter | Type | Description |
---|---|---|
request_type | str | The value "subscription" or "unsubscription". |
request_map | dict | Map of products and metrics to subscribe/unsubscribe to. |
Here is an example of a request :
ticker_request = TickerRequest(
request_type="subscription",
request_map={
"360015751": [
'LastDate',
'LastTime',
'LastPrice',
'LastVolume',
'AskPrice',
'AskVolume',
'LowPrice',
'HighPrice',
'BidPrice',
'BidVolume'
],
"AAPL.BATS,E": [
'LastDate',
'LastTime',
'LastPrice',
'LastVolume',
'AskPrice',
'AskVolume',
'LowPrice',
'HighPrice',
'BidPrice',
'BidVolume'
],
},
)
In this example these are the vwd_id
of the products from which you want Real-time data
:
- 360015751
- AAPL.BATS,E
See the section related to vwd_id
for more information.
Once you have built this Request object you can send it to Degiro's API like this :
TickerFetcher.subscribe(
ticker_request=ticker_request,
session_id=session_id,
)
For more comprehensive examples : realtime_poller.py / realtime_one_shot.py
To remove metrics from the data-stream you need to setup a TickerRequest.
If you try to unsubscribe to a metric to which you didn't subscribed previously it will most likely have no impact.
A Request has the following parameters :
Parameter | Type | Description |
---|---|---|
request_type | str | The value "subscription" or "unsubscription". |
request_map | dict | Map of products and metrics to subscribe/unsubscribe to. |
Here is an example of a request :
ticker_request = TickerRequest(
request_type="unsubscription",
request_map={
"360015751": [
'LastDate',
'LastTime',
'LastPrice',
'LastVolume',
'AskPrice',
'AskVolume',
'LowPrice',
'HighPrice',
'BidPrice',
'BidVolume'
],
"AAPL.BATS,E": [
'LastDate',
'LastTime',
'LastPrice',
'LastVolume',
'AskPrice',
'AskVolume',
'LowPrice',
'HighPrice',
'BidPrice',
'BidVolume'
],
},
)
TickerFetcher.subscribe(
ticker_request=ticker_request,
session_id=session_id,
)
For more comprehensive examples : realtime_poller.py / realtime_one_shot.py
You can use the following code :
session_id = TickerFetcher.get_session_id(user_token=user_token)
logger = TickerFetcher.build_logger()
session = TickerFetcher.build_session()
ticker = TickerFetcher.fetch_ticker(
session_id=session_id,
session=session,
logger=logger,
)
For a more comprehensive example : realtime_poller.py
Received data is a Quotecast
object with the following properties :
Parameter | Type | Description |
---|---|---|
json_data | dict | Dictionary representation of what Degiro's API has sent. |
metadata | Metadata | Containing the "response_datetime" and "request_duration". |
Here is how to access these properties :
json_text = ticker.json_text
response_datetime = ticker.response_datetime
request_duration= ticker.request_duration
Notes:
- The API sometimes might return an empty Quotecast message.
- The API often returns a subset of the requested metrics, e.g. only
'LastPrice'
. This should be considered when appending consecutive data responses.
This library provides the tools to convert Degiro's JSON data into something more programmer-friendly.
Here is the list of available data types :
Type | Description |
---|---|
list[Metric] | List of Metric, which is a Pydantic BaseModel. |
polars.DataFrame | DataFrame from the library Polars. |
There are integrated method to turn polars.DataFrame
into Python dict
/list
or pandas.DataFrame
.
Here is how to build each type :
# BUILD `LIST[METRIC]`
ticker_to_metric_list = TickerToMetricList()
metric_list = ticker_to_metric_list.parse(ticker=ticker)
# BUILD `POLARS.DATAFRAME`
ticker_to_df = TickerToDF()
polars_df = ticker_to_df.parse(ticker=ticker)
# BUILD `LIST[DICT]`
python_list = polars_df.to_dicts()
# BUILD PANDAS.DATAFRAME
# YOU NEED PANDAS AND PYARROW INSTALLED
pandas_df = df.to_pandas()
The generated Ticker contains :
Parameter | Type | Description |
---|---|---|
json_text | str | The json message received |
response_datetime | datetime | Datetime of the response. |
request_duration | timedelta | Duration of the request. |
A Ticker is Pydantic BaseModel, it can serialize and deserialize into json.
Here is how to manipulate a Ticker object :
# GET TICKER PARAMETERS
json_text = ticker.json_text
response_datetime = ticker.response_datetime
request_duration= ticker.request_duration
# SERIALIZE/DESERIALIZE
ticker_json = Ticker.model_dump_json()
ticker_json = Ticker.model_validate_json(json_data=ticker_json)
The list[Metric]
is the parsed version of the json
message received from Degiro's API.
A Metric contains the following parameters :
Parameter | Type | Description |
---|---|---|
metric_type | MetricType | str |
product_id | str | The product identifier in the Quotecast API. |
value | str | float |
Example - list[Metric]
:
metric_list = [
Metric(
product_id=360114899,
metric_type="LastDate",
value="2020-11-06",
),
Metric(
product_id=360114899,
metric_type="LastTime",
value="17:36:17",
),
Metric(
product_id=360114899,
metric_type="LastPrice",
value=70.0,
),
Metric(
product_id=360114899,
metric_type="LastVolume",
value=100,
),
Metric(
product_id=360015751,
metric_type="LastDate",
value="2020-11-06",
),
Metric(
product_id=360015751,
metric_type="LastTime",
value="17:36:17",
),
Metric(
product_id=360015751,
metric_type="LastPrice",
value=22.99,
),
Metric(
product_id=360015751,
metric_type="LastVolume",
value=470,
),
}
In addition to whatever metrics you have chosen to subscribe to (see the example in section 2.6), the DataFrame will contain the following columns :
Column | Description |
---|---|
product_id | Product identifier, for instance "AAPL.BATS,E" for APPLE stock. |
response_datetime | Datetime at which the data was received. |
request_duration | Duration of the request used to fetch the data. |
Example - DataFrame :
product_id | LastPrice | LastVolume | LastDatetimeUTC | request_duration_s | response_datetime_utc |
---|---|---|---|---|---|
str | f64 | i64 | datetime[μs] | f64 | datetime[μs] |
360015751 | 34.6 | 1 | 2023-12-29 16:35:23 | 1.021337 | 2024-01-01 17:31:22.482618 |
AAPL.BATS,E | 192.55 | null | 2023-12-29 20:59:59 | 1.021337 | 2024-01-01 17:31:22.482618 |
This library is divided into two modules :
- quotecast : to consume real-time financial data.
- trading : to manage your Degiro's account.
The module quotecast is described in the section related to real-time data.
The rest of this document will only refer to the module : trading.
In order to use the module trading.api you need to establish a connection.
Check the section related to int_account to understand how to get yours.
Here is how to connect :
credentials = Credentials(
username = YOUR_USERNAME,
password = YOUR_PASSWORD,
int_account = YOUR_INT_ACCOUNT, # OPTIONAL FOR LOGIN
)
# SETUP TRADING API
trading_api = API(credentials=credentials)
# ESTABLISH CONNECTION
trading_api.connect()
For a more comprehensive example : connection.py
Once you no longer need to use the API you can destroy your connection.
You can use the following code to disconnect :
# DESTROY CONNECTION
trading_api.logout()
For a more comprehensive example : logout.py
Some credentials are required to use Degiro's trading API.
Here are these credentials :
Parameter | Type | Description |
---|---|---|
username | str | Username used to log into Degiro's website. |
password | str | Password used to log into Degiro's website. |
int_account | int | OPTIONAL : unique identifier of the account : used by Degiro's server. |
totp_secret_key | str | OPTIONAL : used for Two-factor Authentication (2FA). |
one_time_password | str | OPTIONAL : used for Two-factor Authentication (2FA). |
Check the section related to int_account to understand how to get yours.
Check the section related to 2FA if you want to know more about these two parameters :
- totp_secret_key
- one_time_password
To get your int_acccount you can run this example : client_details_table.py
See section related to ClientDetails table for more details.
This int_acccount is required to do most of the trading operations available in this connector.
Here are some operations for which your int_acccount is not required :
- Connection
- Fetch table : ClientDetails
- Fetch table : Config
Beware, these two identifiers are not the same thing :
- user_token : used to fetch real-time data and charts.
- int_account : used for some trading operations.
First I will briefly explain what is : Two-Factor Authentication (2FA).
I recommend to skip a few paragraphs if you already know what is 2FA.
In a standard connection you are providing two parameters:
- username
- password
If you use Two-Factor Authentication (2FA) you need an extra parameter:
- one_time_password
This one_time_password has a validity of 30 secondes and is generated using a totp_secret_key code.
Usually you use an app like Google Authenticator to store this totp_secret_key and generate the one_time_password.
The totp_secret_key is stored inside the QRCode which is displayed when you enable 2FA on Degiro's website
To use 2FA with this library you have two solutions.
SOLUTION 1
Provide your totp_secret_key : the library will use it to generate a new one_time_password at each connection.
So you won't have to type your one_time_password manually at each connection.
This is the proper way.
See the section about totp_secret_key to understand how to get yours.
Here is an example of connection with the totp_secret_key :
credentials = Credentials(
username=YOUR_USERNAME,
password=YOUR_PASSWORD,
int_account=YOUR_INT_ACCOUNT, # OPTIONAL FOR LOGIN
totp_secret_key=YOUR_2FA_SECRET_KEY, # ONLY IF 2FA IS ENABLED
)
# SETUP TRADING API
trading_api = API(credentials=credentials)
# ESTABLISH CONNECTION
trading_api.connect()
A complete example here : connection_2fa.py
SOLUTION 2
Provide a new one_time_password at each connection.
Here is an example of connection with the one_time_password :
credentials = Credentials(
username=YOUR_USERNAME,
password=YOUR_PASSWORD,
int_account=YOUR_INT_ACCOUNT, # OPTIONAL FOR LOGIN
one_time_password=YOUR_2FA_OTP, # ONLY IF 2FA IS ENABLED
)
# SETUP TRADING API
trading_api = API(credentials=credentials)
# ESTABLISH CONNECTION
trading_api.connect()
A complete example here : connection_otp.py
The parameter totp_secret_key is only required if you have enabled 2FA
on Degiro's website.
When you try to activate 2FA
on Degiro's website, it displays a QRCode
.
This QRCode
changes at each activation.
A QRCode
is a picture which can be converted into a text.
You can download this QRCode
and use a tool to extract the text from it.
This extracted text will look like this :
otpauth://totp/DEGIRO:YOUR_USERNAME?algorithm=SHA1&issuer=DEGIRO&secret=YOUR_TOPT_SECRET_KEY&digits=6&period=30
Has you can guess the "totp_secret_key" is in this part :
secret=YOUR_TOPT_SECRET_KEY
Here is an example of script that extracts the text from a QRCode
:
qrcode.py
The parameter one_time_password is the password you type when you log in the website using 2FA.
Usually you get it through an app like Google Authenticator.
It is preferable to use the parameter totp_secret_key instead of one_time_password.
A connection for trading operations has a timeout of 30 minutes.
It's defined in seconds as constant timeouts.TRADING_TIMEOUT
.
The timeout period is started when the TradingAPI.connect()
results successfully.
Every time an operation is made to this TradingAPI
connection, the timeout for this connection will be reset.
If a TradingAPI
connection is left unused during the timeout period, the connection will expire.
Every consecutive function call to the TraderAPI
will then throw a TimeoutError
exception.
A connection timeout might occur when your trading strategy only performs a few trades per day, e.g. once per hour.
So when finally a buy opportuntiy occurs, check_order()
:
# FETCH CHECKING_RESPONSE
checking_response = trading_api.check_order(order=order)
Will fail with TimeoutError
:
TimeoutError: Connection has probably expired.
HANDLE EXCEPTION
It's recommended to catch the TimeoutError
on every function call to the TradingAPI
.
When it's detected, it's sufficient to call connect()
again, followed by repeating the original call that threw the exception.
Example for the check_order()
call:
try:
checking_response = trading_api.check_order(order=order)
except TimeoutError:
logging.warning("TradingAPI session did timeout, reconnecting for new session ID...")
trading_api.connect()
checking_response = trading_api.check_order(order=order)
This shows the following in the log, while the order is checked successfully after a successful reconnect:
WARNING - TradingAPI session did timeout, reconnecting for new session ID...
INFO - get_session_id:response_dict: {'isPassCodeEnabled': False, 'locale': 'nl_NL', 'redirectUrl': 'https://trader.degiro.nl/trader/', 'sessionId': '2BADBBEF3****', 'status': 0, 'statusText': 'success'}
INFO - confirmation_id: "053df7cf-****"
response_datetime {
seconds: 1643801134
nanos: 715765000
}
REFRESH TIMEOUT
As mentioned before, the timeout will be reset after each call to the TradingAPI
. This provides the opportunity to make a periodic function call, for example every 10 minutes to get_update()
.
However, this might interfere with your other logic and might not be robust over time when DeGiro decides to decrease the timeout on their server.
Therefor it's strongly recommended to always incorporate the exception handling for TimeoutError
as indicated in the example above.
CHANGE PERIOD
It's possible to change the timeout period while creating the TradingAPI
. Just add a ModelConnection
object for parameter connection_storage
:
# SETUP TRADING API
trading_api = TradingAPI(
credentials=credentials,
connection_storage=ModelConnection(
timeout=600,
)
)
# Connect:
trading_api.connect()
The connection will now expire after 10 minutes (10 * 60 s).
Creating and updating of orders is done with an Order
object. Here are the parameters:
Parameter | Type | Description |
---|---|---|
id | str | Optional for update_order() . It's the order_id of the created Order as returned by confirm_order() . |
action | Order.Action |
Whether you want to : BUY or SELL . |
order_type | Order.OrderType |
Type of order : LIMIT , STOP_LIMIT , MARKET or STOP_LOSS . |
price | float | Limit price of the order. Optional for the following order_type : LIMIT and STOPLIMIT . |
product_id | int | Identifier of the product concerned by the order. |
size | float | Size of the order. |
stop_price | float | Stop price of the order. Optional for the following order_type : STOPLIMIT and STOPLOSS |
time_type | Order.TimeType |
Duration of the order : GOOD_TILL_DAY or GOOD_TILL_CANCELED |
The full description of an Order
is available here :
order.py
The order creation is done in two steps :
- Checking : send the
Order
to the API to check if it is valid. - Confirmation : confirm the creation of the
Order
.
Keeping these two steps (instead of reducing to one single "create" function) provides more options.
Use the check_order()
function of the Trading API:
Parameter | Type | Description |
---|---|---|
order | Order |
The order to create with all necessary parameters. |
On a succesfull request, a dict
with the following parameters is returned:
Parameter | Type | Description |
---|---|---|
confirmation_id | str | Id necessary to confirm the creation of the Order by the confirm_order() function. |
response_datetime | datetime | Datetime of the response. |
free_space_new | float | New free space (balance) if the Order is confirmed. |
transaction_fees | float | Transaction fees that will be applied to the Order. |
show_ex_ante_report_link | bool | ? |
When the request fails, None
is returned.
Use the confirm_order()
function of the Trading API:
Parameter | Type | Description |
---|---|---|
confirmation_id | str | The confirmtation id from the check_order() response. |
order | Order |
The same order from the check_order() request. |
On a succesfull request, a dict
with the following parameters is returned:
Parameter | Type | Description |
---|---|---|
order_id | str | A unique id of the accepted order. This id is required to update or delete the pending order. |
response_datetime | datetime | Datetime of the response. |
When the request fails, None
is returned.
order = Order(
buy_sell=Action.BUY,
order_type=OrderType.LIMIT,
price=12.1,
product_id=72160,
size=1,
time_type=TimeType.GOOD_TILL_DAY,
)
checking_response = trading_api.check_order(order=order)
confirmation_response = trading_api.confirm_order(
confirmation_id=checking_response.confirmation_id,
order=order,
)
For a more comprehensive example : order.py
To modify a specific Order, you need to set it up with the order_id
from the confirm_order()
response and use the update_order()
function of the Trading API:
Parameter | Type | Description |
---|---|---|
order | Order |
The order to update with all necessary parameters, including id as returned by confirm_order() . |
On a succesfull request, a bool
with the value True
is returned.
When the request fails, None
is returned. A valid reason is that the pending order has been already executed on the exchange, and this order_id
no longer exists.
Here is an example:
# ORDER SETUP
order = Order(
id=YOUR_ORDER_ID, # `order_id` from `confirm_order()` response
action=Order.Action.BUY,
order_type=Order.OrderType.LIMIT,
price=10.60,
product_id=71981,
size=1,
time_type=Order.TimeType.GOOD_TILL_DAY,
)
# UPDATE ORDER
succcess = trading_api.update_order(order=order)
To delete a specific Order you just need the order_id
from the confirm_order()
response and use the delete_order()
function of the Trading API:
Parameter | Type | Description |
---|---|---|
order_id | str | The unique id of the accepted order as returned by confirm_order() . |
On a succesfull request, a bool
with the value True
is returned.
When the request fails, None
is returned. A valid reason is that the pending order has been already executed on the exchange, and this order_id
no longer exists.
Here is an example:
# DELETE ORDER
succcess = trading_api.delete_order(order_id=YOUR_ORDER_ID) # `order_id` from `confirm_order()` response
This is how to get the list of Orders currently created but not yet executed or deleted :
account_update = trading_api.get_update(
request_list=[
UpdateRequest(
option=UpdateOption.ORDERS,
last_updated=0,
),
],
raw=True,
)
Example : Orders
product_id time_type price size id ... action order_type stop_price retained_order sent_to_exchange
0 0 GOOD_TILL_DAY 2 3 202cb962-ac59-075b-964b-07152d234b70 ... BUY LIMIT 16 17 18
For a more comprehensive example : update.py
This is how to list the stocks/products currently in the portfolio :
account_update = trading_api.get_update(
request_list=[
UpdateRequest(
option=UpdateOption.PORTFOLIO,
last_updated=0,
),
],
raw=True,
)
For a more comprehensive example : update.py
Note: In order to resolve product IDs to Human readable names, see 7.12. How to search products from ids ?
This is how to get aggregated data about the portfolio :
account_update = trading_api.get_update(
request_list=[
UpdateRequest(
option=UpdateOption.TOTALPORTFOLIO,
last_updated=0,
),
],
raw=True,
)
Example : DataFrame
degiroCash flatexCash totalCash totalDepositWithdrawal todayDepositWithdrawal ... reportNetliq reportOverallMargin reportTotalLongVal reportDeficit marginCallStatus
0 0 1 2 3 4 ... 16 17 18 19 NO_MARGIN_CALL
For a more comprehensive example : update.py
This method returns data about passed orders between two dates.
The result contains a list of "Orders" objects with the following attributes :
Parameter | Type | Description |
---|---|---|
created | str | RFC 3339 Datetime, example : "2020-10-06T20:07:18+02:00". |
orderId | str | MD5 HASH, example : "098f6bcd-4621-d373-cade-4e832627b4f6" |
productId | int | Id of the product example : 65156 |
size | float | Size of the order, example : 10.0000 |
price | float | Price of the order, example : 8.6800 |
buysell | str | "B" or "S" |
orderTypeId | int | see 3.Order |
orderTimeTypeId | int | see 3.Order |
stopPrice | float | Price like : 0.0000 |
totalTradedSize | int | - |
type | str | "CREATE", "DELETE" or "MODIFY" |
status | str | "CONFIRMED" |
last | str | RFC 3339 Datetime, example : "2020-10-06T20:07:18+02:00". |
isActive | bool | - |
Here is how to get this data :
# SETUP REQUEST
orders_history = trading_api.get_orders_history(
history_request=HistoryRequest(
from_date=date(year=date.today().year, month=1, day=1),
to_date=date.today(),
),
raw=True,
)
For a more comprehensive example : orders_history.py
Here is how to get this data :
# SETUP REQUEST
from_date = TransactionsHistory.Request.Date(year=2020,month=11,day=15)
to_date = TransactionsHistory.Request.Date(year=2020,month=10,day=15)
request = TransactionsHistory.Request(from_date=from_date, to_date=to_date)
# FETCH DATA
transactions_history = trading_api.get_transactions_history(request=request)
For a more comprehensive example : transactions_history.py
Here is how to get this data :
# FETCH DATA
upcoming_payments = trading_api.get_upcoming_payments()
For a more comprehensive example : upcoming_payments.py
The config table contains the following informations :
Parameter | Type | Description |
---|---|---|
sessionId | str | Current session id. |
clientId | int | Unique Degiro's Account identifier also called "userToken" |
tradingUrl | str | - |
paUrl | str | - |
reportingUrl | str | - |
paymentServiceUrl | str | - |
productSearchUrl | str | - |
dictionaryUrl | str | - |
productTypesUrl | str | - |
companiesServiceUrl | str | - |
i18nUrl | str | - |
vwdQuotecastServiceUrl | str | - |
vwdNewsUrl | str | - |
vwdGossipsUrl | str | - |
taskManagerUrl | str | - |
refinitivNewsUrl | str | - |
refinitivAgendaUrl | str | - |
refinitivCompanyProfileUrl | str | - |
refinitivCompanyRatiosUrl | str | - |
refinitivFinancialStatementsUrl | str | - |
refinitivClipsUrl | str | - |
landingPath | str | - |
betaLandingPath | str | - |
mobileLandingPath | str | - |
loginUrl | str | - |
Here is how to get this table :
# FETCH DATA
config_table = trading_api.get_config()
# EXTRACT SOME DATA
user_token = config_table['clientId']
session_id = config_table['sessionId']
For a more comprehensive example : config_table.py
The ClientDetails table contains information about the current Degiro Account.
Parameter | Type |
---|---|
id | int |
intAccount | int |
loggedInPersonId | int |
clientRole | str |
effectiveClientRole | str |
contractType | str |
username | str |
displayName | str |
str | |
firstContact.firstName | str |
firstContact.lastName | str |
firstContact.displayName | str |
firstContact.nationality | str |
firstContact.gender | str |
firstContact.dateOfBirth | str |
firstContact.placeOfBirth | str |
firstContact.countryOfBirth | str |
address.streetAddress | str |
address.streetAddressNumber | str |
address.zip | str |
address.city | str |
address.country | str |
cellphoneNumber | str |
locale | str |
language | str |
culture | str |
bankAccount.bankAccountId | int |
bankAccount.bic | str |
bankAccount.iban | str |
bankAccount.status | str |
flatexBankAccount.bic | str |
flatexBankAccount.iban | str |
memberCode | str |
isWithdrawalAvailable | bool |
isAllocationAvailable | bool |
isIskClient | bool |
isCollectivePortfolio | bool |
isAmClientActive | bool |
canUpgrade | bool |
Here is how to get this table :
# FETCH DATA
client_details_table = trading_api.get_client_details()
# EXTRACT SOME DATA
int_account = client_details_table['data']['intAccount']
user_token = client_details_table['data']['id']
For a more comprehensive example : client_details_table.py
The AccountInfo table contains the following information about currencies.
Parameter | Type |
---|---|
clientId | int |
baseCurrency | str |
currencyPairs | dict |
marginType | str |
cashFunds | dict |
compensationCapping | float |
Here is how to get this table :
account_info_table = trading_api.get_account_info()
For a more comprehensive example : account_info_table.py
It will provide a list of cash movements.
Here is how to get this data :
account_overview = trading_api.get_account_overview(
overview_request=OverviewRequest(
from_date=date(year=date.today().year-1, month=1, day=1),
to_date=date.today(),
),
raw=False,
)
For a more comprehensive example : account_overview.py
Each cash movement contains this kind of parameters :
Parameter | Type |
---|---|
date | str |
valueDate | str |
id | int |
orderId | str |
description | str |
productId | int |
currency | str |
change | float |
balance | dict |
unsettledCash | float |
total | float |
It will export a list of cash movements in a specific format.
Available formats :
- CSV
- HTML
- XLS
Here is how to get this content in CSV
format :
report = trading_api.get_account_report(
report_request=ReportRequest(
country="FR",
lang="fr",
format=Format.CSV,
from_date=date(year=date.today().year-1, month=1, day=1),
to_date=date.today(),
),
raw=False,
)
Here are the available parameters for CashAccountReport.Request
:
Parameter | Type | Description |
---|---|---|
format | CashAccountReport.Format | Wanted format : CSV HTML PDF XLS |
country | str | Country name, like : FR |
lang | int | Language, like : fr |
from_date | CashAccountReport.Request.Date | Events starting after this date. |
to_date | CashAccountReport.Request.Date | Events before this date. |
Models definitions are available are in this module : account.py
For a more comprehensive example : account_report.py
It will export a list of cash movements in a specific format.
Available formats :
- CSV
- HTML
- XLS
Here is how to get this content in CSV
format :
# SETUP REQUEST
report = trading_api.get_position_report(
report_request=ReportRequest(
country="FR",
lang="fr",
format=Format.XLS,
from_date=date(year=date.today().year-1, month=1, day=1),
to_date=date.today(),
),
raw=False,
)
Here are the available parameters for PositionReport.Request
:
Parameter | Type | Description |
---|---|---|
format | PositionReport.Format | Wanted format : CSV HTML PDF XLS |
country | str | Country name, like : FR |
lang | int | Language, like : fr |
to_date | PositionReport.Request.Date | Events before this date. |
Models definitions are available are in this module : account.py
For a more comprehensive example : position_report.py
This table contains useful parameters to filter products.
Here are the parameters which are inside this table :
Parameter | Type |
---|---|
stockCountries | list |
bondExchanges | list |
bondIssuerTypes | list |
eurexCountries | list |
futureExchanges | list |
optionExchanges | list |
combinationExchanges | list |
cfdExchanges | list |
exchanges | list |
indices | list |
regions | list |
countries | list |
productTypes | list |
etfFeeTypes | list |
investmentFundFeeTypes | list |
optionAggregateTypes | list |
leveragedAggregateTypes | list |
etfAggregateTypes | list |
investmentFundAggregateTypes | list |
lookupSortColumns | list |
stockSortColumns | list |
bondSortColumns | list |
cfdSortColumns | list |
etfSortColumns | list |
futureSortColumns | list |
Here is how to get this data :
# FETCH DATA
products_config = trading_api.get_products_config()
For a more comprehensive example : products_config.py
Text research on a financial product.
Here is how to get this data :
product_request = LookupRequest(
search_text='APPLE',
limit=10,
offset=0,
product_type_id=1,
)
products_lookup = trading_api.product_search(product_request=product_request)
For a more comprehensive example : product_lookup.py
Here is how to get this data :
# SETUP REQUEST
product_request = BondsRequest(
bond_issuer_type_id=0,
bond_exchange_id=710,
search_text='',
offset=0,
limit=100,
require_total=True,
sort_columns='name',
sort_types='asc',
)
# FETCH DATA
bond_list = trading_api.product_search(product_request=product_request)
For a more comprehensive example : product_search.py
Here is how to get this data :
# SETUP REQUEST
product_request = ETFsRequest(
popular_only=False,
input_aggregate_types='',
input_aggregate_values='',
search_text='',
offset=0,
limit=100,
require_total=True,
sort_columns='name',
sort_types='asc',
)
# FETCH DATA
etf_list = trading_api.product_search(product_request=product_request)
For a more comprehensive example : product_search.py
Here is how to get this data :
# SETUP REQUEST
product_request = FundsRequest(
search_text='',
offset=0,
limit=100,
require_total=True,
sort_columns='name',
sort_types='asc',
)
# FETCH DATA
fund_list = trading_api.product_search(product_request=product_request)
For a more comprehensive example : product_search.py
Here is how to get this data :
# SETUP REQUEST
product_request = FuturesRequest(
future_exchange_id=1,
underlying_isin='FR0003500008',
search_text='',
offset=0,
limit=100,
require_total=True,
sort_columns='name',
sort_types='asc',
)
# FETCH DATA
fund_list = trading_api.product_search(product_request=product_request)
For a more comprehensive example : product_search.py
Here is how to get this data :
# SETUP REQUEST
product_request = LeveragedsRequest(
popular_only=False,
input_aggregate_types='',
input_aggregate_values='',
search_text='',
offset=0,
limit=100,
require_total=True,
sort_columns='name',
sort_types='asc',
)
# FETCH DATA
etf_list = trading_api.product_search(product_request=product_request)
For a more comprehensive example : product_search.py
Here is how to get this data :
# SETUP REQUEST
product_request = OptionsRequest(
input_aggregate_types='',
input_aggregate_values='',
option_exchange_id=3,
underlying_isin='FR0003500008',
search_text='',
offset=0,
limit=100,
require_total=True,
sort_columns='expirationDate,strike',
sort_types='asc,asc',
)
# FETCH DATA
option_list = trading_api.product_search(product_request=product_request)
For a more comprehensive example : product_search.py
It contains information about available stocks.
Here is how to get this data :
# SETUP REQUEST
product_request = StocksRequest(
index_id=122001, # NASDAQ 100
# exchange_id=663, # NASDAQ
# You can either use `index_id` or `exchange id`
# See which one to use in the `ProductsConfig` table
is_in_us_green_list=True,
stock_country_id=846, # US
search_text='',
offset=0,
limit=100,
require_total=True,
sort_columns='name',
sort_types='asc',
)
# FETCH DATA
stock_list = trading_api.product_search(product_request=product_request)
For a more comprehensive example : product_search.py
Here is how to get this data :
# SETUP REQUEST
product_request = WarrantsRequest(
search_text='',
offset=0,
limit=100,
require_total=True,
sort_columns='name',
sort_types='asc',
)
# FETCH DATA
warrant_list = trading_api.product_search(product_request=product_request)
For a more comprehensive example : product_search.py
Here is how to get this data :
product_info = trading_api.get_products_info(
product_list=[96008, 1153605, 5462588],
raw=False,
)
For a more comprehensive example : products_info.py
Here is how to get this data :
favorites_batch = trading_api.get_favorite()
For a more comprehensive example : favorite_get.py
Example :
favorite_id = trading_api.create_favorite(name="SOME_NAME")
For a more comprehensive example : favorite_create.py
Example :
success = trading_api.delete_favorite(id=1234567)
For a more comprehensive example : favorite_delete.py
Example :
success = trading_api.move_favorite(
list_id=1234567,
position=1,
)
For a more comprehensive example : favorite_move.py
Example :
success = trading_api.put_favorite_product(
id=1234567,
product_id=1234567,
)
For a more comprehensive example : favorite_put_product.py
Example :
success = trading_api.delete_favorite_product(
id=1234567,
product_id=1234567,
)
For a more comprehensive example : [favorite_delete product.py](examples/trading/favorite_delete product.py)
Example :
underlying_list = trading_api.get_underlyings(
underlyings_request= UnderlyingsRequest(
future_exchange_id=1,
# option_exchange_id=3,
),
raw=False,
)
For a more comprehensive example : favorite_get_underlyings.py
Here is how to get this data :
# FETCH DATA
company_profile = trading_api.get_company_profile(
product_isin='FR0000131906',
)
For a more comprehensive example : company_profile.py
This table contains information about the company.
Here are the parameters which are inside this table :
Parameter | Type |
---|---|
totalFloat | str |
sharesOut | str |
consRecommendationTrend | dict |
forecastData | dict |
currentRatios | dict |
Here is how to get this data :
# FETCH DATA
company_ratios = trading_api.get_company_ratios(
product_isin='FR0000131906',
)
For a more comprehensive example : company_ratios.py
Here is how to get this data :
# FETCH DATA
financials_statements = trading_api.get_financials_statements(
product_isin='FR0000131906',
)
For a more comprehensive example : financial_statements.py
Here is how to get this data :
# SETUP REQUEST
request = LatestNews.Request(
offset=0,
languages='en,fr',
limit=20,
)
# FETCH DATA
latest_news = trading_api.get_latest_news(
request=request,
raw=True,
)
For a more comprehensive example : latest_news.py
Here is how to get this data :
# FETCH DATA
top_news_preview = trading_api.get_top_news_preview(raw=True)
For a more comprehensive example : top_news_preview.py
Here is how to get this data :
# SETUP REQUEST
request = NewsByCompany.Request(
isin='NL0000235190',
limit=10,
offset=0,
languages='en,fr',
)
# FETCH DATA
news_by_company = trading_api.get_news_by_company(
request=request,
raw=True,
)
For a more comprehensive example : news_by_company.py
Here is how to get this data :
agenda = trading_api.get_agenda(
agenda_request=AgendaRequest(
calendar_type=CalendarType.EARNINGS_CALENDAR,
end_date=datetime.now(),
start_date=datetime.now() - timedelta(days=1),
offset=0,
limit=25,
),
raw=True,
)
Here are the available parameters for Agenda.Request
:
Parameter | Type | Description |
---|---|---|
calendar_type | Agenda.CalendarType | Type of agenda : DIVIDEND_CALENDAR ECONOMIC_CALENDAR EARNINGS_CALENDAR HOLIDAY_CALENDAR IPO_CALENDAR SPLIT_CALENDAR |
offset | int | - |
limit | int | - |
order_by_desc | bool | - |
start_date | Timestamp | Events starting after this date. |
end_date | Timestamp | Events before this date. |
company_name | str | Filter used on the events description. |
countries | str | Comma separated list of countries like : FR,US |
classifications | str | Comma separated list of sectors like : GovernmentSector,ExternalSector |
units | str | Comma separated list of units like : Acre,Barrel |
Exact definitions of Agenda
and AgendaRequest
are in this module :
agenda.py
For a more comprehensive example : agenda.py
Here is how to get this data :
estimates_summaries = trading_api.get_estimates_summaries(
product_isin="FR0000131906",
raw=False,
)
Here are the available parameters for Agenda.Request
:
Parameter | Type | Description |
---|---|---|
annual | dict | Indicators by year. |
currency | str | currency, example EUR . |
interim | dict | Indicators by quarter. |
lastRetrieved | str | Last Retrieved, example : 2021-12-31T20:07:30.939Z . |
lastUpdated | str | Last updated,, example : 2021-02-18T01:30:00Z . |
preferredMeasure | str | Preferred measure, example : EPS . |
ric | str | Reuters Instrument Code, example : BOUY.PA . |
Exact definition of EstimatesSummaries
is in this file :
product.py
For a more comprehensive example : estimates_summaries.py