Hi,
I have a task to retrieve intraday turnover for S&P500 stocks.
Only possibility which I can see now is to retrieve data and aggregate it via codebook.
Unfortunately I am not able to retrieve data for 500 stocks (price and volume) and aggregate it (after waiting over 30 mins every time, nothing happens).
Can you help in resolving it?
Example code:
import refinitiv.dataplatform as rdp
import datetime
import pandas as pd
rdp.open_desktop_session('DEFAULT_CODE_BOOK_APP_KEY')
sp_chain = rdp.StreamingChain(
session = rdp.get_default_session(),
name = '0#.SPX')
sp_chain.open(with_updates = False)
sp_constituents = sp_chain.get_constituents()
RICs = sp_constituents # the list of RICs
s_date = "2020-12-22 13:00" # start date
e_date = "2020-12-22 21:00" # end date
Field = "ACVOL_UNS" # the field of these RICs
data = pd.DataFrame() # define data is a DataFrame
for aRIC in RICs: # request turnover for each RIC
df = rdp.get_historical_price_summaries(
universe = aRIC,
start = s_date,
end = e_date,
interval = rdp.Intervals.ONE_HOUR, # Supported intervals: ONE_MINUTE, FIVE_MINUTES, TEN_MINUTES, THIRTY_MINUTES, ONE_HOUR
fields=[Field],
sessions = [
rdp.MarketSession.PRE,
rdp.MarketSession.NORMAL,
rdp.MarketSession.POST])
if df is None: # check if there is any error
print("Error for RIC " + aRIC + ":" + str(rdp.get_last_status()['error'])) # print the error
else:
df[Field] = df[Field].astype(float) # convert string type to float
data[aRIC] = df[Field] # create the RIC's last price column
data['S&P'] = data.sum(axis=1)
print(data['S&P'][-1])
data['S&P'].plot()