#WARNING: the Eikon terminal must be running in order to connect to the API #import packages import eikon as ek # the Eikon Python wrapper package import pandas as pd import numpy as np import datetime from datetime import timedelta, date, datetime from pandas.tseries.offsets import BDay #connects to Bill's Eikon terminal ek.set_app_key('XXXX') #retreive the RICs from Eikon df_rics,e = ek.get_data("lists('Inv Trust List')","TR.RIC") #convert that into a list and set as an object ric_list = df_rics['Instrument'].tolist() #Slice, loop and concatenate the retrieval request - must be done in order to avoid a backend request timeout which #happens when we use too many RICs. n can be toggled below. n = 25 df = pd.DataFrame() for ric_chunk in [ric_list[i:i + n] for i in range(0, len(ric_list), n)]: tmp_df, e = ek.get_data(ric_chunk, ['TR.RNSFilerName', 'TR.RNSAnnouncedDate', 'TR.RNSTransactionType', 'TR.RNSARNumShrsTransacted', 'TR.RNSARPctOSTransacted', 'TR.RNSARTransactionPrice', 'TR.RNSARMktValTransaction', 'TR.RNSARTotShrsPostTrans', 'TR.RNSARPctOSPostTrans']) df = tmp_df.append(df) #set boundary dates of the download end_date = date.today() start_date = end_date - BDay(2) #set those dates in the necessary string format end_date_str = datetime.strftime(end_date, "%Y-%m-%d") start_date_str = datetime.strftime(start_date, "%Y-%m-%d") #denote dates in datetime format df['RNS Announced Date'] = pd.to_datetime(df['RNS Announced Date']) #set the date constraints as an object mask = (df['RNS Announced Date'] >= start_date_str) & (df['RNS Announced Date'] < end_date_str) #set the dataframe as only those with values inside the boundary dates df = df.loc[mask] #rename some of columns headings, some for compatibility purposes - some programs don't like the '£' symbol df.rename(columns={'RNS Announced Date': 'Transaction Date','RNS AR Price (at Transaction) - £': 'RNS AR Price (at Transaction) GBP', 'RNS AR Market Value of Transaction - £': 'RNS AR Market Value of Transaction - GBP'}, inplace=True) #create file name and export as CSV todays_date = date.today() todays_date_str = datetime.strftime(todays_date, "%Y%m%d") df.to_csv('Daily API Download_' + todays_date_str + '.csv')