question

Upvotes
Accepted
29 1 4 12

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!

#technology#contentdatastream-apidsws-apidatastream
1689564877355.png (5.8 KiB)
1689564962889.png (9.0 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

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?

Upvotes
Accepted
78.6k 248 52 74

@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



1689581197976.png (11.6 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
5.7k 21 2 6

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


1689576931334.png (32.7 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

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.


Upvotes
5.7k 21 2 6

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).


1689583376542.png (37.7 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

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

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.