Workspace Python API takes a long time to complete

When using Workspace Python API under Windows 10, some simple queries take a long time to complete.


For example, the Python commands:


import refinitiv.data as rd

rd.open_session()

df=rd.get_data('4296477482', ['TR.OrganizationID','AVAIL(TR.CompanyName,TR.CommonName)','(TR.InvestorSharesHeld/1000000-TR.InvtrPrevSharesHeld)/TR.InvtrPrevSharesHeld', \
'TR.SecurityOwnedName','TR.SecurityOwnedRIC','TR.InvestorValueHeld','TR.InvestorValueHeld.currency','TR.InvestorSharesHeld/1000000','TR.InvtrPrevSharesHeld'], \
parameters={'Scale':6,'NULL':'Blank','Curn':'NATIVE'})

df=df.sort_values(by=['Investor Based Value Held'],ascending=False,na_position='last').head(25)

df.to_excel('PythonOutput.xlsx', sheet_name='PythonData', index=False)

rd.close_session()


, take about half a minute to complete.


As this needs to be scaled to running this script around 10 times (I prefer to do so instead of a bulk download for all 10 at once), is there any way to make the code run faster?


Best Answer

  • Jirapongse
    Answer ✓

    @IoannisG

    Please try this one:

    df=rd.get_data('4296477482', ['TR.OrganizationID',
                                  'AVAIL(TR.CompanyName,TR.CommonName)',
                                  '(TR.InvestorSharesHeld/1000000-TR.InvtrPrevSharesHeld)/TR.InvtrPrevSharesHeld', 
                                  'TR.InvestorSharesHeld',
                                  'TR.InvtrPrevSharesHeld',
                                  'TR.SecurityOwnedName',
                                  'TR.SecurityOwnedRIC',
                                  'TR.InvestorValueHeld',
                                  'TR.InvestorValueHeld.currency',
                                  'TR.InvestorSharesHeld/1000000',
                                  'TR.InvtrPrevSharesHeld'], 
                    parameters=
                    {'Scale':6,'NULL':'Blank','Curn':'NATIVE','StartNum':1,'EndNum':25,"SortOrder":"Descending"})

    Otherwise, please contact the helpdesk team via MyAccount for other supported parameters.

Answers

  • @IoannisG

    Thank you for reaching out to us.

    As far as I know, the problem is not in the code. The backend or server needs times to extract the requested data. I ran the code and found that the response contains 15447 rows.

    1719806887893.png

    On my maching, it took around 20-30 seconds to get the response. I think this is an expected behavior of Data Libary to extract this size of data.

    You may contact your LSEG account team for sales team for other solutions.

  • OK,thanks. So there is no way to sort the data (say, top 25) on the server, and just return this reduced set, but only to return the full set (of 15477 rows) and do the sorting later, is this right?

  • Thanks, is there also a way to specify in which field(s) (e.g. TR.InvestorValueHeld, TR.SecurityOwnedName) the sorting should be done?

  • @IoannisG

    You can specify the parameters to the field. For example:

    TR.PvtOwnInvestorName(SortOrder=Descending)

    However, I am unable to find those field in the Data Item Browser so I can't confirm which parameters can be used.

    Please contact the helpdesk team via MyAccount for more information.