Discover Refinitiv
MyRefinitiv Refinitiv Perspectives Careers
Created with Sketch.
All APIs Questions & Answers  Register |  Login
Ask a question
  • Questions
  • Tags
  • Badges
  • Unanswered
Search:
  • Home /
  • Eikon Data APIs /
avatar image
Question by lawrence.chiang · Dec 18, 2020 at 02:34 PM · streaming price

python api streaming price can't work on pycharm?

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.......")

People who like this

0 Show 0
Comment
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

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

2 Replies

  • Sort: 
avatar image
REFINITIV
Best Answer
Answer by umer.nalla · Dec 18, 2020 at 03:16 PM

Hi @lawrence.chiang

Can you please try replacing your time.sleep() / adding the following after the streaming_prices open()

streaming_prices.open() 
asyncio.get_event_loop().run_until_complete(asyncio.sleep(120))

OR something like

streaming_prices.open()
asyncio.get_event_loop().run_forever()

You will need to import asyncio off course


Comment

People who like this

0 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

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

avatar image
Answer by lawrence.chiang · Dec 18, 2020 at 02:41 PM

sorry, correct some code and provide you with the running result as below. thanks

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=lambda streaming_prices, instrument_name, fields:
        display_fields_refresh(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.......")


start streaming.......

Fields refresh received for CNH= : {'CF_BID': 6.5174, 'CF_ASK': 6.518, 'OPEN_PRC': 6.516, 'CF_HIGH': 6.5327, 'CF_LOW': 6.5116, 'CF_CLOSE': 6.5165, 'VALUE_TS1': '11:05:25'}

<eikon.streaming_session.streamingprices.StreamingPrices object at 0x0000015B722631C8>

stop streaming.......


Process finished with exit code 0

Comment

People who like this

0 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

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

Watch this question

Add to watch list
Add to your watch list to receive emailed updates for this question. Too many emails? Change your settings >
11 People are following this question.

Related Questions

Defining Color output StreamingPrices

problems with StreamingPrices object's "open()" method

Customised functions on streamed data

Getting currency code for a security

What is a "universe" in the rdp.steamingPrices API for news headlines

  • Feedback
  • Copyright
  • Cookie Policy
  • Privacy Statement
  • Terms of Use
  • Careers
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Alpha
  • App Studio
  • Block Chain
  • Bot Platform
  • Calais
  • Connected Risk APIs
  • DSS
  • Data Fusion
  • Data Model Discovery
  • Datastream
  • Eikon COM
  • Eikon Data APIs
  • Elektron
    • EMA
    • ETA
    • WebSocket API
  • Legal One
  • Messenger Bot
  • Messenger Side by Side
  • ONESOURCE
    • Indirect Tax
  • Open PermID
    • Entity Search
  • Org ID
  • PAM
    • PAM - Logging
  • ProView
  • ProView Internal
  • Product Insight
  • Project Tracking
  • Refinitiv Data Platform
    • Refinitiv Data Platform Libraries
  • Rose's Space
  • Screening
    • Qual-ID API
    • Screening Deployed
    • Screening Online
    • World-Check One
    • World-Check One Zero Footprint
  • Side by Side Integration API
  • TR Knowledge Graph
  • TREP APIs
    • CAT
    • DACS Station
    • Open DACS
    • RFA
    • UPA
  • TREP Infrastructure
  • TRIT
  • TRKD
  • TRTH
  • Thomson One Smart
  • Transactions
    • REDI API
  • Velocity Analytics
  • Wealth Management Web Services
  • World-Check Data File
  • Explore
  • Tags
  • Questions
  • Badges