Failed return when pass the parameters to get_data

Hello,


I'm new to the TR API and have been using Python to perform API queries. My script has been running smoothly for about two years. However, when I attempted to run it this week, I encountered various errors.


After reviewing the code in my backup (codebk), it appears that the function get_data([list], 'Instrument') may be causing these errors. Could anyone share their experiences or suggest a solution?


Here are the details of my setup:


Platform: Windows 10 Pro

Python Version: 3.7

Integrated Development Environment (IDE): Spider

Firewall and Antivirus: Disabled

Additionally, I'm using Refinitiv Desktop Gateway 4.0.65 (version 4.0.65101).


Thank you for your assistance.

## Source ##
class TR():

def __init__(self):

ek.set_app_key('xxxxxxxxxxxx')

self.ek_con = ek

self.ds_con = DSWS.Datastream(username = 'xxxx', password = 'xxxx')



def get_ds_data(self, list_rics, field_name):

df_data = pd.DataFrame(columns=['Instrument', 'Datatype', 'Value', 'Currency'])

for i in range(0, len(list_rics), 50):

list_ric_tmp = list_rics[i:i+50]

ric_str = ','.join('<'+x+'>' for x in list_ric_tmp)



tmp_df_data = self.ds_con.get_data(tickers=ric_str, fields=[field_name], kind=0)

tmp_df_data['Instrument'] = tmp_df_data['Instrument'].str[1:-1]

tmp_df_data = tmp_df_data.iloc[:,0:4] # select columns ['Instrument', 'Datatype', 'Value', 'Currency']

df_data = pd.concat([df_data, tmp_df_data], axis=0)

return df_data



tr_instance = TR()

list_nisin_ric = [

'04I.SG^G24', 'ASHC.BO^B23', '8258.HK^B22',

]

if list_nisin_ric:

df_ds_isin = tr_instance.get_ds_data(list_nisin_ric, 'ISIN')

print(df_ds_isin)
## Error Message ##

get_data : Exception Occured

(<class 'TypeError'>, TypeError("argument of type 'NoneType' is not iterable"), <traceback object at 0x7f05af9a0100>)

None



Traceback (most recent call last):

File "/opt/conda/lib/python3.8/site-packages/DatastreamPy/DS_Response.py", line 159, in get_data

if 'DataResponse' in json_Response:

TypeError: argument of type 'NoneType' is not iterable

---------------------------------------------------------------------------

TypeError Traceback (most recent call last)

/tmp/ipykernel_84/2317672722.py in <module>

37 # Call get_ds_data on the instance of TR class

38 if list_nisin_ric:

---> 39 df_ds_isin = tr_instance.get_ds_data(list_nisin_ric, 'ISIN')

40

41 print(df_ds_isin)



/tmp/ipykernel_84/2317672722.py in get_ds_data(self, list_rics, field_name)

20

21 tmp_df_data = self.ds_con.get_data(tickers=ric_str, fields=[field_name], kind=0)

---> 22 tmp_df_data['Instrument'] = tmp_df_data['Instrument'].str[1:-1]

23 tmp_df_data = tmp_df_data.iloc[:,0:4] # select columns ['Instrument', 'Datatype', 'Value', 'Currency']

24 df_data = pd.concat([df_data, tmp_df_data], axis=0)



TypeError: 'NoneType' object is not subscriptable


Best Answer

  • Jirapongse
    Answer ✓

    @CTR DT

    Thank you for reaching out to us

    I tested the following code.

    ds.get_data(tickers="<04I.SG^G24>,<ASHC.BO^B23>,<8258.HK^B22>",
                fields=["ISIN"], kind=0)

    It returned the following data.

    1721880270353.png

    I assume that it may relate to the permission or limitations. You can check it via the Test REST Service.

    1721880399853.png

    Accoring to the Datastream source code, you are using the old version of the Datastream Webservice. The latest version is DatastreamPy 2.0.30. With the new version, you need to modify to code when passing credentials.

    ds = DSWS.DataClient(None, username = username, password = password)

Answers

  • @Jirapongse Thank you for your reply and skill transfer. I catch up the error details.

    By the way, may I inquire about extending the download limit through Customer Support? Additionally, could you inform me about the monthly download limit and where I can check this information?


    image



  • @CTR DT

    Please contact the Datastream Web Service support team via MyAccount to verify the limit.

    You can check the usage by using the following request.

    1721887811935.png


  • @Jirapongse Case solved in this morning. I hope so....

    It seems the quota issue in DataStream and they release the quota in this morning on 2024-08-01.

    Now we can run the script again. Thank you so much.