icastillejogomez / degiro-api

Unofficial DeGiro stock broker API. See your portfolio and set up orders in the market like wall street
MIT License
201 stars 30 forks source link

Feature: prices #19

Closed danielvandenberg95 closed 1 year ago

danielvandenberg95 commented 3 years ago

I need to be able to get prices, so I figured I'd make an issue with my findings. I'm hoping to be able to submit a PR in a couple days, but if not I'll have all the information I've found documented here.

The URL DEGIRO requests it's data from (on page load) is https://charting.vwdservices.com/hchart/v1/deGiro/data.js?requestid=1&resolution=PT1M&culture=nl-NL&period=P1D&series=issueid%3A198401&series=price%3Aissueid%3A198401&format=json&callback=vwd.hchart.seriesRequestManager.sync_response&userToken=${usertoken}&tz=Europe%2FAmsterdam.

I redacted the user token for now, as I'm not sure if this one is personal or if it's the "user token" for DEGIO at vwdservices. It's a 7-digit number, ending with 821. If someone else runs into this issue, could you let me know if it's the same for you? Then we know it's common to everyone and not variable.

This is a get-request, so all required information is in this URL. I'm assuming there is no cookies involved, as the data is loaded from a 3rd party service.

The two "series" arguments are issueid:${product.vwdId} and price:issueid:${product.vwdId}. Although I'm not certain both are required for our (initial) use-case, I'd recommend leaving both in to make the request indistinguishable from what DEGIRO does.

What's interesting though, is that for this request, it doesn't seem like you have to be logged in. This means easier unit testing, also in CI.

To-Do:

My suggestions for implementing this:

Notes: Callback should be omitted, as that will wrap the result in a function call (to be used with eval). Omitting it returns the raw JSON response.

icastillejogomez commented 3 years ago

I've been looking how to do it, but it was confuse. How can I help you? I want to develop this feature too.

icastillejogomez commented 3 years ago

I just sent to you a collaboration invite. Maybe we have to defined a correct develop flow to ensure all people can use this awesome module without any troubles. Here I'am for all you could need.

Chavithra commented 3 years ago

First of all, thanks for sharing that's great !

For the rest of my response : beware that this is just my experience feedback.

Since at this point, there is no official and public documentation for Degiro's API.

I will split my answer in 3 parts :

  1. What is this "user_token" ?
  2. Is there an example for this endpoint ?
  3. Is there another endpoint to get prices ?

1. What is this user_token ?

1.1. What is it ?

From what I understood it's a unique identifier.

To answer to your question : we don't have the same "user_token".

It seems to be unique to each Degiro's account.

1.1. How can I get it ?

It's inside the response of these endpoints and it's called "clientId" or "id" :

There might be other endpoints.

For more details about "user_token", you can take a look at the documentation of this repository :

https://github.com/Chavithra/degiro-connector

2. Is there an example for this endpoint ?

I can see you have already started to build methods to consume this endpoint. https://charting.vwdservices.com/hchart/v1/deGiro/data.js

There are other projects on github which consume this endpoint.

Here are some examples : A. https://github.com/Chavithra/degiro-connector B. https://github.com/lolokraus/DegiroAPI C. https://github.com/pcmind/degiro-java-client D. https://github.com/SlashGordon/autotrader

A : method "get_graph" B : method "real_time_price" C : methods "getPriceHistory" & "getGraph" D : methods "get_series" & "get_last_price"

Maybe you can take inspiration from these repositories.

For instance, to get the available options for each parameter, like "resolution" or "period".

Although most options are already listed directly in Degiro's website JavaScript code.

3. Is there another endpoint to get prices ?

For a real-time usage I think this endpoint is more suitable :

https://degiro.quotecast.vwdservices.com/CORS

Some examples of projects consuming this endpoint : A. https://github.com/Chavithra/degiro-connector B. https://github.com/llehouerou/go-degiro C. https://github.com/pcmind/degiro-java-client D. https://github.com/pladaria/degiro

A : method "fetch_data" B : methods "SubscribeQuotes" and "GetQuote" C : method "getPricePoller" D : methods "getAskBidPrice"

I hope that will help you in your quest.

icastillejogomez commented 3 years ago

This days I'm bit offline for christmas. Tomorrow Monday 4 I'm going to resumo all my tasks & jobs. I think we need to read carefully Chavithra comment and study all this stuff. I think with a little more effort we're going to have a awesome DeGiro JS lib.

I had saw this VWD endpoint but I didn't had time to implemented.

ianwensink commented 3 years ago

I would love this to be implemented directly as well.

Below is my implementation to get the real time pricing. It's not perfect and does some assumptions, but it might help with a kick start.

The product from degiro contains the ID you need for VWD.

export async function getRealtimePrice(degiro: DeGiro, tickerId: number) {
  // Get the product id's based on the ticker id you want to get the price for.
  const productIds = await degiro.getProductsByIds([ tickerId.toString() ]);

  // It returns an object, so we use the same ticker id to get it from the object. "VWD" is the endpoint name.
  const vwdId = productIds[tickerId].vwdId;

  // Get the user's account ID from degiro.
  const accountId = (await degiro.getAccountData()).data.id;

 // Format the endpoint for VWD.
  const requestRealtimePrice = `https://charting.vwdservices.com/hchart/v1/deGiro/data.js?resolution=PT5M&period=P1D&series=issueid%3A${vwdId}&series=price%3Aissueid%3A3${vwdId}&format=json&userToken=${accountId}`;

  // Request he information.
  const response = await fetch(requestRealtimePrice);
  const result = await response.json();

  // The data structure without assertions and without respect for other series. Works fine for me.
  return result.series[0].data.lastPrice as number;
}
wexert commented 3 years ago

Really a great job! Awesome project! But the result that i get from requestRealtimePrice are from 15 min ago... is there any way to solve this ?

Chavithra commented 3 years ago

wexert: Really a great job! Awesome project! But the result that i get from requestRealtimePrice are from 15 min ago... is there any way to solve this ?

Hi,

this is part of Degiro's terms.

From what I understood to access to PRICE FEEDS in real time, depending on the market you want it's either :

More informations about PRICE FEEDS in the document called :

Here is the current English version of this document :

Hope that helps you

bdoubleu86 commented 3 years ago

Really a great job! Awesome project! But the result that i get from requestRealtimePrice are from 15 min ago... is there any way to solve this ?

I am paying for realtime price feed e.g. for German Xetra which is then displayed in Degiro's dashboard and updated automatically. However, seems like the value from https://charting.vwdservices.com/hchart/v1/deGiro/data.js is delayed. That's also what Degiro confirmed to me by email in German language:

Die Realtime-Kurse funktionieren nur auf der Handelsplattform von DEGIRO. Wenn Sie auf den Interaktiven Chart gehen, werden Sie allerdings auf die Seite von VWD geleitet. Dort sind die Kurse 15 Minuten verzögert.

Any chance to "listen" to the realtime prices like Degiro does it in it's portfolio dashboard? I tried looking into their JS, but I still didn't find it.

faerietree commented 3 years ago

save your time not required. or do you really want to download all the data every time? that is not stealthy at all. even with cache. realtime suffices (store it). pladaria already solved it luckily. good work all.

but degiro has its eyes and fraud detection algorithms wide open be warned (only wall street is allowed automated gains using arbitrage and whatnot, remember you play on big money's property ;)

wexert commented 3 years ago

Really thank you for everything! i'll work for a bit with the delayed data, if i manage to generate something i'll pay the fees !

Il giorno dom 28 feb 2021 alle ore 01:17 J.R.I. notifications@github.com ha scritto:

save your time not required or do you want to download all the data every time? that is hilarious and not stealthy at all

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/icastillejogomez/degiro-api/issues/19#issuecomment-787208533, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKO3WKWZKIM4BZCPYX3LFNLTBGDTNANCNFSM4VQ5P7OA .

faerietree commented 3 years ago

I once was as enthusiastic as you all. And just when I finished everything after a year of coding ... DeGiro cracked down on me. Happened to Oscar too.

Save your time. Do something useful. Try make this world a better, more fair, just, honest and lovely world. Have a nice time all

wexert commented 3 years ago

How can Degiro crack you?

Il dom 28 feb 2021, 13:19 J.R.I. notifications@github.com ha scritto:

I once was as enthusiastic as you all. And just when I finished everything after a year of coding ... DeGiro cracked down on me. Happened to Oscar too.

Save your time. Do something useful. Try make this world a better, more fair, just, honest and lovely world. Have a nice time all

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/icastillejogomez/degiro-api/issues/19#issuecomment-787443443, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKO3WKWEIV6DDT2CG6GWZYTTBIYEJANCNFSM4VQ5P7OA .

faerietree commented 3 years ago

I used all the stealth from reusing session and many many more measures. Point is they won't believe you because they are smart. As long as your bot is not profitable, danger is low. But if significant. Then well.

Edit: They can remove all profits from your account. Legal basis is the contract we agreed to on register. Just be careful.

wexert commented 3 years ago

I understeand... Is not legal for degiro if se create bot? Cause Etoro per you do that... But getting the api is a pain too

Il dom 28 feb 2021, 13:21 J.R.I. notifications@github.com ha scritto:

I used all the stealth from reusing session and many many more measures. Point is they won't believe you because they are smart. As long as your bot is not profitable, danger is low. But if significant. Then well

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/icastillejogomez/degiro-api/issues/19#issuecomment-787443705, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKO3WKXC3WN3LEONHFUTGULTBIYNHANCNFSM4VQ5P7OA .

icastillejogomez commented 1 year ago

This repository won't handle real-time prices. If someone want to get real time prices must use an external prices provider