Hello there,
I use sample code your tutorial provide to run python eikon api streaming prices function. It works well on jupyter as I separate my code in different cells for streaming_prices.open() & streaming_prices.close() function. It keeps receiving newly updated data during the time I run these two cells.
But, if I run same code in the same script in pycharm, it doesn't work that well. It can only runs for the first refresh function and then the program go into end. I tried some different approach such as adding time.sleep or systems.("pause") while still remains the problem. Do you have any advice on this? thanks!
import eikon as ek
import os
ek.set_app_key('key')
def display_fields_refresh(streaming_prices, instrument_name, fields):
print("Fields refresh received for", instrument_name, ":", fields)
print(streaming_prices)
def display_fields_update(streaming_prices, instrument_name, fields):
print("Fields updated received for", instrument_name, ":", fields)
if __name__ == '__main__':
streaming_prices = ek.StreamingPrices(
instruments=['CNH='],
fields=['SALTIM', 'CF_BID', 'CF_ASK', 'OPEN_PRC', 'CF_HIGH', 'CF_LOW', 'CF_CLOSE', 'VALUE_TS1'],
on_refresh_refresh=lambda streaming_prices, instrument_name, fields:
display_fields(streaming_prices, instrument_name, fields),
on_update=lambda streaming_prices, instrument_name, fields:
display_fields_update(streaming_prices, instrument_name, fields)
)
print("start streaming.......")
streaming_prices.open()
#time.sleep(5)
#os.system('pause')
#streaming_prices.close()
print("stop streaming.......")