how to get date in dsws

Hi team, I've got a question regarding dsws. If retrieving single filed and startdate = -0D, then the result will not showing the actual date of the data.

e.g.

df = ds.get_data(tickers = '@:CNM1E1', fields = ['A12FE'], start = '-0D')

the result will be showing index, instrument, datatype, value and currency

1689564877355.png


However, if requesting multiple fileds, then it will return date automatically

e.g.

df = ds.get_data(tickers = '@:CNM1E1', fields = ['A12FE','A18GRO'], start = '-10D')

the result will be

1689564962889.png

If I need requesting single field while getting the Date, how should I modify the code? Thanks in advance for answering!

Best Answer

  • Jirapongse
    Answer ✓

    @Julian.Bai

    This could be a limitation in the API. It will not display the date field if there is only one date available in the response.

    You may raise this issue with the development team via GitHub.

    The retName parameter is not available anymore. You can use the following code to get the return name.

    df = ds.get_data(tickers = '@:CNM1E1|N', fields = ['A12FE'],start = '-0D',kind = 0)
    df

    1689581197976.png


Answers

  • Besides, when i try to use retName function and set to True, I got the following error message "get_data() got an unexpected keyword argument 'retName'", may I know why is that?

  • Hi @Julian.Bai ,

    Please try a call with the parameter 'kind' set to '0':


    test = ds.get_data(tickers='@:CNM1E1', fields=["A12FE"], kind=1)
    test


    And let us know if the output is what you were after:


    1689576931334.png

  • Hi Jonathan, tried

    df = ds.get_data(tickers = '@:CNM1E1', fields = ['A12FE'],kind = 0)

    df = ds.get_data(tickers = '@:CNM1E1', fields = ['A12FE'],start = '-0D',kind = 0)

    df = ds.get_data(tickers = '@:CNM1E1', fields = ['A12FE'],start = '-0D',kind = 1)


    and these three have the same results

    1689578253611.png

    if try

    df = ds.get_data(tickers = '@:CNM1E1', fields = ['A12FE'],kind = 1) then

    1689578287646.png


    The problem is I still want to get "Dates" when start = -0d. Is it doable? Thanks.


  • Hi @Julian.Bai ,

    Yes, you're right. Using the 'grammar' `start = '-0D'` will 'break' the time-series, unfortunutally.
    However, you can use 'date grammar':


    test = ds.get_data(
        tickers='@:CNM1E1', fields=["A12FE"], kind = 1,
        # freq = 'M',
        start = '2020-01-01',
        end = '2024-04-06')
    test


    1689583376542.png


    Does this work for you? You can use the native Python library 'datetime' to automatically pick dates (e.g.: last month).

  • Hi Jonathan, thank you very much for your help! I'd accept both answers if I could.