Upgrade from Eikon -> Workspace. Learn about programming differences.

For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
5 0 1 3

streaming price service is printing just one update

I am registering a service to get live market data, but when I run following code it finishes after one update only

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)


def display_complete_snapshot(streaming_prices):
    current_time = datetime.datetime.now().time()
    print(current_time, "- StreamingPrice is complete. Full snapshot:")
    print(streaming_prices.get_snapshot())

streaming_prices = ek.StreamingPrices(
    instruments=["NIRc1", "NEUc1"],
    fields=["SALTIM_MS", "TRDPRC_1", "TRDVOL_1"],
    service='IDN_RDF',
    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),
    on_complete = lambda streaming_price :
        display_complete_snapshot(streaming_price)
)

streaming_prices.open()
streaming_prices.get_snapshot()


output is as follows : -


14:44:06.201053 - Status received for NEUc1 : {'status': <StreamState.Open: 3>, 'code': 'Open', 'message': 'All is well'}

14:44:06.201993 - Refresh received for NEUc1 : {'SALTIM_MS': 33223000, 'TRDPRC_1': 87.6225, 'TRDVOL_1': 5}

14:44:06.204055 - Status received for NIRc1 : {'status': <StreamState.Open: 3>, 'code': 'Open', 'message': 'All is well'}

14:44:06.205031 - Refresh received for NIRc1 : {'SALTIM_MS': 33244000, 'TRDPRC_1': 74.3925, 'TRDVOL_1': 1}

14:44:06.206042 - StreamingPrice is complete. Full snapshot:

Instrument SALTIM_MS TRDPRC_1 TRDVOL_1

0 NIRc1 33244000 74.3925 1

1 NEUc1 33223000 87.6225 5

eikoneikon-data-apirefinitiv-dataplatform-eikonworkspaceworkspace-data-api
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvote
Accepted
25.3k 87 12 25

Hi @birendra.bisht1

Is there anyother code after the

  1. streaming_prices.open()
  2. streaming_prices.get_snapshot()


to keep the script/code running? Otherwise, the script will terminate.

If not, then you should add something like:

asyncio.get_event_loop().run_until_complete(asyncio.sleep(60))

that will run for 60 seconds, you can add the above to a loop to run for longer...


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

HI @birendra.bisht1

I should point out that my reply above is assuming that you are running a .py file and NOT inside a Jupyter Notebook? If you are running in a Jupyter env, then you should continue to receive updates as Jupyter keeps things ticking over.

Upvotes
5 0 1 3

Hi @umer.nalla thanks for your answer.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.