streaming_prices.open()

HI i have the following code:
def display_refreshed_fields(streaming_price, instrument_name, fields): current_time = datetime.datetime.now().time() print(current_time, "- Refresh received for", instrument_name, ":", fields) def display_updated_fields(streaming_price, instrument_name, fields): current_time = datetime.datetime.now().time() print(current_time, "- Update received for", instrument_name, ":", fields) def display_status(streaming_price, instrument_name, status): current_time = datetime.datetime.now().time() print(current_time, "- Status received for", instrument_name, ":", status) streaming_prices = ek.StreamingPrices( instruments = ['EUR=','GBP=','JPY=', 'CAD='], fields = ['SALTIM', 'CF_BID','CF_ASK','OPEN_PRC', 'CF_HIGH','CF_LOW', 'CF_CLOSE'], 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) ) streaming_prices.open()
I use Pycharm and running this code i get:
16:20:03.342917 - Status received for GBP= : {'status': <StreamState.Open: 3>, 'code': 'Open', 'message': 'All is well'} 16:20:03.343917 - Refresh received for GBP= : {'CF_BID': 1.2503, 'CF_ASK': 1.2507, 'OPEN_PRC': 1.2473, 'CF_HIGH': 1.2529, 'CF_LOW': 1.2462, 'CF_CLOSE': 1.247} 16:20:03.343917 - Status received for JPY= : {'status': <StreamState.Open: 3>, 'code': 'Open', 'message': 'All is well'} 16:20:03.343917 - Refresh received for JPY= : {'CF_BID': 107.5, 'CF_ASK': 107.53, 'OPEN_PRC': 107.45, 'CF_HIGH': 107.72, 'CF_LOW': 107.34, 'CF_CLOSE': 107.46} 16:20:03.343917 - Status received for CAD= : {'status': <StreamState.Open: 3>, 'code': 'Open', 'message': 'All is well'} 16:20:03.343917 - Refresh received for CAD= : {'CF_BID': 1.3576, 'CF_ASK': 1.358, 'OPEN_PRC': 1.3582, 'CF_HIGH': 1.3611, 'CF_LOW': 1.356, 'CF_CLOSE': 1.3585} 16:20:03.343917 - Status received for EUR= : {'status': <StreamState.Open: 3>, 'code': 'Open', 'message': 'All is well'} 16:20:03.343917 - Refresh received for EUR= : {'CF_BID': 1.1264, 'CF_ASK': 1.1268, 'OPEN_PRC': 1.125, 'CF_HIGH': 1.1302, 'CF_LOW': 1.1248, 'CF_CLOSE': 1.125} Process finished with exit code 0
As you can see, the program terminates almost immediatly, I would like the streaming prices to keep open and the updates getting handled when they come in.
What works is putting the streaming_prices.open() in a loop:
while True:
streaming_prices.open()
streaming_prices.open()while True: pass
this doesnt work either unfortunatly, then the program doesnt terminate, but the updates dont get handled by the function.
But I cant imagine this is the way to do it? Any help would be appreciated, thanks!
Jan
Best Answer
-
Hi,
streaming_prices.open() does just the streaming connection with the server.
It's up to you to keep it streaming the duration you want/need.
The solution you propose is correct but you should define the way to stop itwhile True:
...
if <condition is True>:
break...
You can also run your code in a Jupyter notebook because the stream will continue until you close your book.
0
Answers
-
somehow the readability got lost, here is the code again:
def display_refreshed_fields(streaming_price, instrument_name, fields):
current_time = datetime.datetime.now().time()
print(current_time, "- Refresh received for", instrument_name, ":", fields)
def display_updated_fields(streaming_price, instrument_name, fields):
current_time = datetime.datetime.now().time()
print(current_time, "- Update received for", instrument_name, ":", fields)
def display_status(streaming_price, instrument_name, status):
current_time = datetime.datetime.now().time()
print(current_time, "- Status received for", instrument_name, ":", status)
streaming_prices = ek.StreamingPrices(
instruments = ['EUR=','GBP=','JPY=', 'CAD='],
fields = ['SALTIM', 'CF_BID','CF_ASK','OPEN_PRC', 'CF_HIGH','CF_LOW', 'CF_CLOSE'],
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)
)
streaming_prices.open()0 -
that is clear then, thank you Pierre!
0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 685 Datastream
- 1.4K DSS
- 615 Eikon COM
- 5.2K Eikon Data APIs
- 10 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 252 ETA
- 556 WebSocket API
- 38 FX Venues
- 14 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 275 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 22 RDMS
- 1.9K Refinitiv Data Platform
- 652 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 27 DACS Station
- 121 Open DACS
- 1.1K RFA
- 104 UPA
- 193 TREP Infrastructure
- 228 TRKD
- 917 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 90 Workspace SDK
- 11 Element Framework
- 5 Grid
- 18 World-Check Data File
- 1 Yield Book Analytics
- 46 中文论坛