Git Product home page Git Product logo

Comments (2)

Chavithra avatar Chavithra commented on July 28, 2024

Hello there,

I have split my answer in three parts :

  1. Type of series
  2. Issue id
  3. How to get data points timestamp ?

1. Type of series

@codecnotsupported
The README does contain a example how to get chart data.
But doesn't mention what types of series data there are.

Are you talking about the request to the API or the result ?

If you were talking about the request, you can find those in the documentation :

  • issueid
  • price
  • ohlc
  • volume

These are all the series types that I have found.

If you find more let me know.

2. Issue id

@codecnotsupported
Or for that matter what the number 360148977 means. ( Probably the product ID )

This number is not the product id : 360148977.

The number 360148977 is the vwd_id of the following stock :

  • name : Crédit agricole
  • product id : 64515
  • vwd_id / issueid : 360148977

3. How to get data points timestamp ?

@codecnotsupported
I took a guess how it works. Take the 'times' timestamp convert it to a integer and use it as a offset.

I think you are right on how to calculate the timestamp for each data point.

Here is some code that I have made to check if that works :

from datetime import datetime
from typing import List

def extract_times(serie: dict) -> str:
    times = serie['times']
    times = times.rsplit(sep='/', maxsplit=1)
    times = times[0]

    return times

def extract_resolution(serie: dict) -> str:
    times = serie['times']
    times = times.rsplit(sep='/', maxsplit=1)
    resolution = times[-1]

    return resolution

def resolution_in_seconds(resolution: str) -> int:
    unit = resolution[-1]
    units = int(resolution[2:-1])

    if unit == 'S':
        seconds_per_unit = 1
    elif unit == 'M':
        seconds_per_unit = 60
    elif unit == 'H':
        seconds_per_unit = 3600
    else:
        raise AttributeError('Unknown resolution')

    seconds = seconds_per_unit * units
    
    return seconds

def positions_to_timestamp(serie: dict) -> List[List[int]]:
    points = serie['data']
    points_timestamp = list()

    resolution = extract_resolution(serie=serie)
    resolution_s = resolution_in_seconds(resolution=resolution)

    times = extract_times(serie=serie)
    times_datetime = datetime.strptime(times, '%Y-%m-%dT%H:%M:%S')
    times_timestamp = times_datetime.timestamp()

    for (position, value) in points:
        time = position * resolution_s + times_timestamp
        points_timestamp.append([time, value])
    
    return points_timestamp

def positions_to_datetime(serie: dict) -> List[List]:
    points_timestamp = positions_to_timestamp(serie=serie)
    points_datetime = list()

    for (timestamp, value) in points_timestamp:
        dt = datetime.fromtimestamp(timestamp)
        points_datetime.append([dt, value])
    
    return points_datetime

# SELECT THE RIGHT SERIE HERE
serie = chart['series'][1] 

points_timestamp = positions_to_timestamp(serie=serie)
points_datetime = positions_to_datetime(serie=serie)

for (time, value) in points_datetime:
    print(time, value)

Here is what this code displays :

2021-03-12 09:00:00 12.24
2021-03-12 09:16:01.200000 12.22
2021-03-12 10:58:58.800000 12.31
2021-03-12 11:58:58.800000 12.35
2021-03-12 12:01:58.800000 12.375
2021-03-12 12:58:58.800000 12.365
2021-03-12 13:58:58.800000 12.335
2021-03-12 14:58:58.800000 12.315
2021-03-12 15:58:58.800000 12.355
2021-03-12 16:58:58.800000 12.335
2021-03-12 17:37:58.800000 12.32

I have used these parameters :

  • issueid = 360148977
  • resolution = PT1H (one hour)
  • period = P1D (one day)

from degiro-connector.

codecnotsupported avatar codecnotsupported commented on July 28, 2024
  1. Okay, I misunderstood and thought there were more series types that were present in the library.
  2. Yes, I found out not too long ago before I saw your answer, little note for anyone else reading: vwd_id is named 'vwdIdSecondary' in favorites (trading_api.get_favourites_list()).
  3. Seems to work OK.

Closing the issue, you might want to add the functionality to convert the chart's integer timestamp to datetime object.

from degiro-connector.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.