My code, which is intended to append new data daily to an already existing csv file named 'Daily API Download Master.csv:
#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 data fields from the Eikon API using dynamic dates for a list of RICs
df,e = ek.get_data("lists('Inv Trust List')","TR.RIC")
ric_list = df['Instrument'].tolist()
df, e = ek.get_data(ric_list,
['TR.RNSFilerName',
'TR.RNSAnnouncedDate',
'TR.RNSTransactionType',
'TR.RNSARNumShrsTransacted',
'TR.RNSARPctOSTransacted',
'TR.RNSARTransactionPrice',
'TR.RNSARMktValTransaction',
'TR.RNSARTotShrsPostTrans',
'TR.RNSARPctOSPostTrans'])
end_date = date.today()
start_date = end_date - BDay(1)
end_date_str = datetime.strftime(end_date, "%Y-%m-%d")
start_date_str = datetime.strftime(start_date, "%Y-%m-%d")
df['RNS Announced Date'] = pd.to_datetime(df['RNS Announced Date'])
mask = (df['RNS Announced Date'] > start_date_str) & (df['RNS Announced Date'] <= end_date_str)
df = df.loc[mask]
df.rename(columns={'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)
#append new csv to Master
df.to_csv('Daily API Download Master.csv', mode='a', header=False)
Backend error. 400 Bad Request
---------------------------------------------------------------------------
EikonError Traceback (most recent call last)
<ipython-input-16-f4c48e9e9e88> in <module>()
22 'TR.RNSARMktValTransaction',
23 'TR.RNSARTotShrsPostTrans',
---> 24 'TR.RNSARPctOSPostTrans'])
25 26 end_date = date.today()
~\AppData\Local\Continuum\anaconda3\lib\site-packages\eikon\data_grid.py in get_data(instruments, fields, parameters, field_name, raw_output, debug)
184 payload = {'requests': [payload]}
185 --> 186 result = eikon.json_requests.send_json_request(_endpoint, payload, debug=debug)
187 188 if result.get('responses'):
~\AppData\Local\Continuum\anaconda3\lib\site-packages\eikon\json_requests.py in send_json_request(entity, payload, debug)
116 ticket = _check_ticket_async(result)
117 --> 118 _check_server_error(result)
119 return result
120 else:
~\AppData\Local\Continuum\anaconda3\lib\site-packages\eikon\json_requests.py in _check_server_error(server_response)
192 status, reason_phrase, version, content, headers = error_message.split(',')[:5]
193 logger.error(error_message)
--> 194 raise EikonError(int(server_response['ErrorCode']), error_message)
195 196 # check DataGrid response (server response is JSON and it can contain error + transactionId keys)
EikonError: Error code 400 | Backend error. 400 Bad Request