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?
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()
When posting a code sample, make sure to use the code block feature in the post editor: the button with </> icon. Code block helps preserve code formatting, indentation etc. The code you included lost all formatting, which means I have to guess for example where the for loop in the original code ends.
There's a bunch of issues I see here. One is a bug in RDP library, which ignores the value of "interval" kwarg for intraday intervals and always returns timeseries in default one minute summarization. Then there's default time zone, the availability of extended market trades for NYSE vs. NASDAQ stocks. But none of these issues would result in the code not returning, if that is indeed what you experienced. I suggest you include some print statements to help you trace the execution of your code, e.g. include "print(aRIC)" within the for loop to help you follow the progression of the code running through the loop.