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
-
streaming_prices.open()
while True:
passthis doesnt work either unfortunatly, then the program doesnt terminate, but the updates dont get handled by the function.
0 -
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
- 6 AHS
- 39 Alpha
- 162 App Studio
- 4 Block Chain
- 5 Bot Platform
- 17 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 370 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 60 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛