For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
11 1 2 4

Syntax for screener

Hi Team,

I use this formula in screener, now I am trying to replace the "HK" here with a pre-defined items.

Economic_Sector,err = ek.get_data('SCREEN(U(IN(Equity(active,public,primary))/*UNV:Public*/), IN(TR.ExchangeCountryCode,"HK"), CURN=USD)',

'TR.TRBCEconomicSector',

{'Sdate':start_date,'Scale':scale,'Curn':curn})

For example:

I set country_code='HK'

and put the country_code into the formula, like this:

Economic_Sector,err = ek.get_data('SCREEN(U(IN(Equity(active,public,primary))/*UNV:Public*/), IN(TR.ExchangeCountryCode, country_code ), CURN=USD)',

'TR.TRBCEconomicSector',

{'Sdate':start_date,'Scale':scale,'Curn':curn})


Do you have idea why it doesnt work and how should I correct this.

Here is the error message:

KeyError                                  Traceback (most recent call last)
<ipython-input-24-b53aff9d8165> in <module>
      9 Economic_Sector,err = ek.get_data('SCREEN(U(IN(Equity(active,public,primary))/*UNV:Public*/), IN(TR.ExchangeCountryCode,"country_code"), CURN=USD)',
     10                     'TR.TRBCEconomicSector',
---> 11                    {'Sdate':start_date,'Scale':scale,'Curn':curn})
     12      13 Economic_Sector 
~\Anaconda3\lib\site-packages\refinitiv\dataplatform\legacy\data_grid.py in get_data(instruments, fields, parameters, field_name, raw_output, debug, raw_response)
    206         return result
    207 --> 208     return get_data_frame(result, field_name)
    209     210 
~\Anaconda3\lib\site-packages\refinitiv\dataplatform\legacy\data_grid.py in get_data_frame(data_dict, field_name)
    255         headers = [header.get('field', header.get('displayName')) for header in data_dict['headers'][0]]
    256     else:
--> 257         headers = [header['displayName'] for header in data_dict['headers'][0]]
    258     data = numpy.array([[get_data_value(value) for value in row] for row in data_dict['data']])
    259     if len(data):

KeyError: 'headers'


Thanks!


eikoneikon-data-apiworkspaceworkspace-data-apirefinitiv-dataplatform-eikonscreener
icon clock
10 |1500

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

1 Answer

Upvotes
Accepted
11.5k 16 7 10

Hello @Danni.Qiu

You cannot mix the string 'SCREEN(U(IN(Equity(active,public,primary))/*UNV:Public*/), IN(TR.ExchangeCountryCode, country_code ), CURN=USD)' with the variable country_code like that. You need to concatenate the string to the country_code variable first like the following:

country_code='HK'

syntax = 'SCREEN(U(IN(Equity(active,public,primary))/*UNV:Public*/), IN(TR.ExchangeCountryCode, %s ), CURN=USD)'%(country_code)

Economic_Sector,err = ek.get_data(syntax,'TR.TRBCEconomicSector')

There are many ways to concatenate string, please see more details in the following Python tutorial websites:

icon clock
10 |1500

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

Thank you so much!
Click below to post an Idea Post Idea