Skip to content

Instantly share code, notes, and snippets.



Last active Sep 19, 2020
What would you like to do?
Simple Real-Time Stock Streaming with Bokeh
To run:
python -m bokeh serve
import io
import requests
import pandas as pd
import pyEX
from bokeh.models import ColumnDataSource, HoverTool
from bokeh.models.widgets import TextInput, Button
from bokeh.plotting import figure, curdoc
from bokeh.layouts import row, widgetbox
base = ""
data = ColumnDataSource(dict(time=[], display_time=[], price=[]))
def get_last_price(symbol):
# endpoint = "tops/last"
return pd.DataFrame([pyEX.delayedQuote(symbol)])
def update_ticker():
global TICKER
TICKER = ticker_textbox.value
price_plot.title.text = "IEX Real-Time Price: " + ticker_textbox.value = dict(time=[], display_time=[], price=[])
def update_price():
new_price = get_last_price(symbol=TICKER)["delayedPriceTime"],
price=new_price["delayedPrice"]), 10000)
hover = HoverTool(tooltips=[
("Time", "@display_time"),
("IEX Real-Time Price", "@price")
price_plot = figure(plot_width=800,
title="Real-Time Price Plot")
price_plot.line(source=data, x='time', y='price')
price_plot.xaxis.axis_label = "Time"
price_plot.yaxis.axis_label = "IEX Real-Time Price"
price_plot.title.text = "IEX Real Time Price: " + TICKER
ticker_textbox = TextInput(placeholder="Ticker")
update = Button(label="Update")
inputs = widgetbox([ticker_textbox, update], width=200)
curdoc().add_root(row(inputs, price_plot, width=1600))
curdoc().title = "Real-Time Price Plot from IEX"
curdoc().add_periodic_callback(update_price, 1000)

This comment has been minimized.

Copy link

@treatmesubj treatmesubj commented May 27, 2018

tried bokeh serve from cmd and got the error that I didn't have the "PIL" module. I tried a pip install and couldn't find it. Must be referring to Python Imaging Library. There's no version for python 3 yet :/ Update: Never mind I pip installed Pillow instead


This comment has been minimized.

Copy link

@bkasaeer bkasaeer commented Jul 10, 2019

Hi Tim,

I have been trying to run your app using both the python shells or Spyder and windows command line, but none of them work. I wonder if you can give me an advice on how to proceed.

In Spyder shell, I run "bokeh serve --show" and it shows this error:

"bokeh serve --show File "", line 1 bokeh serve --show ^ SyntaxError: invalid syntax"

When I run it on the cmd as "bokeh serve --show", it shows this error:

'bokeh' is not recognized as an internal or external command, operable program or batch file.

When I run it through cmd as "python -m bokeh serve" it shows a long error ending as follows:

"ImportError: DLL load failed: The specified module could not be found."


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment