Package: intriniorealtime
intrinio realtime python sdkSDK for working with Intrinio's realtime Multi-Exchange prices feed.  Intrinio’s Multi-Exchange feed bridges the gap by merging real-time equity pricing from the IEX and MEMX exchanges. Get a comprehensive view with increased market volume and enjoy no exchange fees, no per-user requirements, no permissions or authorizations, and little to no paperwork.Intrinioprovides real-time stock prices via a two-way WebSocket connection. To get started,subscribe to a real-time data feedand follow the instructions below.Documentation for our legacy realtime clientRequirementsPython 3.10You needhttps://pypi.org/project/websocket-client/, nothttps://pypi.org/project/websocket/.DockerAdd your API key to the example_app.py file, thendocker compose build
docker compose run clientFeaturesReceive streaming, real-time price quotes (last trade, bid, ask)Subscribe to updates from individual securitiesSubscribe to updates for all securitiesMultiple sources of data - REALTIME or DELAYED_SIP or NASDAQ_BASICInstallationpip install intriniorealtimeExample UsageimportthreadingimporttimefromthreadingimportTimer,Thread,Eventfromintriniorealtime.clientimportIntrinioRealtimeClienttrade_count=0ask_count=0bid_count=0backlog_count=0defon_quote(quote,backlog):globalask_countglobalbid_countglobalbacklog_countbacklog_count=backlogif'type'inquote.__dict__:ifquote.type=="ask":ask_count+=1else:bid_count+=1defon_trade(trade,backlog):globaltrade_countglobalbacklog_countbacklog_count=backlogtrade_count+=1classSummarize(threading.Thread):def__init__(self,event):threading.Thread.__init__(self,args=(),kwargs=None)self.daemon=Trueself.stopped=eventdefrun(self):globaltrade_countglobalbid_countglobalask_countglobalbacklog_countwhilenotself.stopped.wait(5):print("trades: "+str(trade_count)+"; asks: "+str(ask_count)+"; bids: "+str(bid_count)+"; backlog: "+str(backlog_count))options={'api_key':'API_KEY_HERE','provider':'REALTIME'# REALTIME or DELAYED_SIP or NASDAQ_BASIC}client=IntrinioRealtimeClient(options,on_trade,on_quote)client.join(['AAPL','GE','MSFT'])#client.join(['lobby'])client.connect()stopFlag=Event()summarize_thread=Summarize(stopFlag)summarize_thread.start()time.sleep(10)client.disconnect()# this will stop the summarize threadstopFlag.set()Handling Quotes and the QueueThere are thousands of securities, each with their own feed of activity.  We highly encourage you to make your trade and quote handlers has short as possible and follow a queue pattern so your app can handle the volume of activity.Quote Data FormatQuote Message{'symbol':'AAPL','type':'ask','price':'102.3','size':100,'timestamp':1636395583000000000,'subprovider':'UTP','market_center':'','condition':''}symbol- the ticker of the securitytype- the quote typeask- represents the top-of-book ask pricebid- represents the top-of-book bid priceprice- the price in USDsize- the size of thelasttrade, or total volume of orders at the top-of-bookbidoraskpricetimestamp- a Unix timestamp (nanoseconds since unix epoch)subprovider- Denotes the detailed source within grouped sources.NO_SUBPROVIDER- No subtype specified.CTA_A- CTA_A in the DELAYED_SIP provider.CTA_B- CTA_B in the DELAYED_SIP provider.UTP- UTP in the DELAYED_SIP provider.OTC- OTC in the DELAYED_SIP provider.NASDAQ_BASIC- NASDAQ Basic in the NASDAQ_BASIC provider.IEX- From the IEX exchange in the REALTIME provider.market_center- Provides the market centercondition- Provides the conditionTrade Message{'symbol':'AAPL','total_volume':'106812','price':'102.3','size':100,'timestamp':1636395583000000000,'subprovider':'IEX','market_center':'','condition':''}symbol- the ticker of the securitytotal_volume- the total volume of trades for the security so far today.price- the price in USDsize- the size of thelasttrade, or total volume of orders at the top-of-bookbidoraskpricetimestamp- a Unix timestamp (nanoseconds since unix epoch)subprovider- Denotes the detailed source within grouped sources.NO_SUBPROVIDER- No subtype specified.CTA_A- CTA_A in the DELAYED_SIP provider.CTA_B- CTA_B in the DELAYED_SIP provider.UTP- UTP in the DELAYED_SIP provider.OTC- OTC in the DELAYED_SIP provider.NASDAQ_BASIC- NASDAQ Basic in the NASDAQ_BASIC provider.IEX- From the IEX exchange in the REALTIME provider.market_center- Provides the market centercondition- Provides the conditionAPI KeysYou will receive your Intrinio API Key aftercreating an account. You will need a subscription to arealtime data feedas well.DocumentationMethodsclient = IntrinioRealtimeClient(options)- Creates an Intrinio Realtime clientParameteroptions.api_key: Your Intrinio API KeyParameteroptions.provider: The real-time data provider to use ("REALTIME" or "DELAYED_SIP" or "NASDAQ_BASIC")Parameteroptions.on_quote(quote, backlog): A function that handles received quotes.backlogis an integer representing the approximate size of the queue of unhandled quote/trade events.Parameteroptions.on_trade(quote, backlog): A function that handles received trades.backlogis an integer representing the approximate size of the queue of unhandled quote/trade events.Parameteroptions.logger: (optional) A Python Logger instance to use for loggingdefon_quote(quote,backlog):print("QUOTE: ",quote,"BACKLOG LENGTH: ",backlog)defon_trade(trade,backlog):print("TRADE: ",trade,"BACKLOG LENGTH: ",backlog)options={'api_key':'','provider':'REALTIME',# REALTIME or DELAYED_SIP or NASDAQ_BASIC'on_quote':on_quote,'on_trade':on_trade}client=IntrinioRealtimeClient(options)client.join(channels)- Joins the given channels. This can be called at any time. The client will automatically register joined channels and establish the proper subscriptions with the WebSocket connection.Parameterchannels- A single channel or list of channels. You can also use the special symbol, "lobby" to join the firehose channel and recieved updates for all ticker symbols (you must have a valid "firehose" subscription).client.join(["AAPL","MSFT","GE"])client.join("GOOG")client.join("lobby")client.connect()- Retrieves an auth token, opens the WebSocket connection, starts the self-healing and heartbeat intervals, joins requested channels.client.keep_alive()- Runs an infinite loop to keep the thread alive, so that the client continues to receive prices. You may call this function afterconnect()or use your own timing logic (for example: connect, listen for quotes for x minutes, disconnect).client.disconnect()- Closes the WebSocket, stops the self-healing and heartbeat intervals. Youmustcall this to dispose of the client.client.on_quote(quote, backlog)- Changes the quote handler functiondefon_quote(quote,backlog):print("QUOTE: ",quote,"BACKLOG LENGTH: ",backlog)client.on_quote=on_quoteclient.leave(channels)- Leaves the given channels.Parameterchannels- A single channel or list of channelsclient.leave(["AAPL","MSFT","GE"])client.leave("GOOG")client.leave_all()- Leaves all channels.Example Replay Client Usagedefon_quote(quote,backlog):print("QUOTE: ",quote,"BACKLOG LENGTH: ",backlog)defon_trade(trade,backlog):print("TRADE: ",trade,"BACKLOG LENGTH: ",backlog)options={'api_key':'','provider':'REALTIME',# REALTIME or DELAYED_SIP or NASDAQ_BASIC'replay_date':datetime.date.today(),'with_simulated_delay':False,# This plays back the events at the same rate they happened in market.'delete_file_when_done':True}client=IntrinioReplayClient(options,on_trade,on_quote)