#!/usr/bin/env python # coding: utf-8 # # Eikon Data API - How to use StreamingPrice with events to get News # ## Imports # # Imports the 'eikon' library and other usefull libraries needed by this notebook # In[ ]: import eikon as ek from IPython.display import display, clear_output, HTML import asyncio # ## Set App Key # Set the AppKey of this application and connect to Eikon. # In[ ]: ek.set_app_key('my app key') # ### Define a callback to receive incoming events # In[ ]: def display_news_story(streaming_price, instrument_name, fields): clear_output(wait=True) print('********** Headline **********') display(fields) print('********** Story **********') html_story = ek.get_news_story(fields['PNAC']) display(html_story) # ## Create a StreamingPrice and register event callbacks # In[ ]: streaming_price = ek.StreamingPrices( instruments = ['NFCP_UBMS'], on_update = lambda streaming_price, instrument_name, fields : display_news_story(streaming_price, instrument_name, fields) ) # ## Open the StreamingPrice and wait for events # In[ ]: streaming_price.open() # ## Close the StreamingPrice when done # In[ ]: asyncio.get_event_loop().run_until_complete(asyncio.sleep(60)) streaming_price.close() # In[ ]: