# There's an issue in \refinitiv\dataplatform\pricing\pricing_.py:8: FutureWarning # that I don't feel like seeing. Ignore it. from warnings import simplefilter simplefilter(action='ignore', category=FutureWarning) #import sys #print(sys.version) import asyncio import pandas as pd import datetime import pytz import sys import time import refinitiv.dataplatform as rdp app_id = "*****" # Yeah, yeah, I know: don't embed credentials in a program file. RDP_LOGIN = "*****" RDP_PASSWORD = "*****" default_session = rdp.open_platform_session(app_id, rdp.GrantPassword( username = RDP_LOGIN, password = RDP_PASSWORD ) ) # Length of tick-gathering window (in seconds) WINDOW_LENGTH = 10 # Destination current_time = datetime.datetime.now() output_file = "C:\\Temp\\StreamingFile_" + current_time.strftime("%Y-%m-%d") + ".csv" f = open(output_file, 'a') # SONIA # universe = "['SON3H0','SON3MO','SON3U0','SON3Z0','SON3H1']" # fields = "['QUOTIM','QUOTIM_MS','QUOTIM_NS','TIMACT','EXCHTIM','BID','BIDSIZE','ASK','ASKSIZE']" # Testing: FX universe = "['EUR=', 'GBP=', 'JPY=', 'CAD=']" fields = "['BID', 'ASK', 'OPEN_PRC', 'HST_CLOSE']" # Streaming Price support functions def display_refreshed_fields(streaming_price, instrument_name, fields): current_time = datetime.datetime.now() timestampStr = current_time.strftime("%Y-%m-%d %H:%M:%S.%f") output_string = timestampStr + ",REFRESH," + instrument_name + ",\"" + str(fields) + "\"\n" global output_file f.write(output_string) def display_updated_fields(streaming_price, instrument_name, fields): current_time = datetime.datetime.now() timestampStr = current_time.strftime("%Y-%m-%d %H:%M:%S.%f") output_string = timestampStr + ",UPDATE," + instrument_name + ",\"" + str(fields) + "\"\n" f.write(output_string) def display_status(streaming_price, instrument_name, status): current_time = datetime.datetime.now() timestampStr = current_time.strftime("%Y-%m-%d %H:%M:%S.%f") output_string = timestampStr + ",STATUS," + instrument_name + ",\"" + str(status) + "\"\n" f.write(output_string) streaming_prices = rdp.StreamingPrices( # service = 'ELEKTRON_EDGE', universe = universe, fields = fields, on_refresh = lambda streaming_price, instrument_name, fields : display_refreshed_fields(streaming_price, instrument_name, fields), on_update = lambda streaming_price, instrument_name, fields : display_updated_fields(streaming_price, instrument_name, fields), on_status = lambda streaming_price, instrument_name, status : display_status(streaming_price, instrument_name, status), ) print("About to open!\n",file=sys.stdout) foo = streaming_prices.open() print("Opened!\n",file=sys.stdout) print(foo,file=sys.stdout) # Wait n seconds, then close off the stream, save the results, and exit time.sleep(WINDOW_LENGTH) streaming_prices.close() f.flush() f.close() rdp.close_session()