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 jaydoubleu79 · Jul 02, 2020 at 02:24 PM · pythonstreaming pricequestion

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


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.

3 Replies

  • Sort: 
avatar image
REFINITIV
Best Answer
Answer by pierre.faurel · Jul 02, 2020 at 05:49 PM

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 it

while 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.

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 jaydoubleu79 · Jul 02, 2020 at 02:35 PM

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()
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 jaydoubleu79 · Jul 02, 2020 at 06:03 PM

that is clear then, thank you Pierre!

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

StreamingPrices limits on Data API

Data fields for the Eikon streaming API

Why do TR.CurrEVEBITDALFY and TR.HistEnterpriseValueEBITDA differ?

Eikon Python API Query - How do you get the list of ASX listed stocks which have Company Guidance issued for Fiscal Year 2020?

How do I download Historical Data from Starmine?

  • 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