4
4
from bokeh .io import curdoc
5
5
from bokeh .layouts import row , column , gridplot , layout
6
6
from bokeh .palettes import Spectral6
7
- from bokeh .models import ColumnDataSource , Range1d
7
+ from bokeh .models import ColumnDataSource , Range1d , LinearAxis
8
8
from bokeh .models .widgets import Select , Button
9
9
from bokeh .plotting import figure , output_file , show
10
10
@@ -55,8 +55,6 @@ def twin_plot(data, y_axis, x_axis='timestamp'):
55
55
"""
56
56
Create a bokeh plot with twin axes
57
57
"""
58
- from bokeh .plotting import figure
59
- from bokeh .models import LinearAxis , Range1d
60
58
61
59
TOOLTIPS = [
62
60
('datetime' , '@x{%F %H:%M}' ),
@@ -96,13 +94,16 @@ def twin_plot(data, y_axis, x_axis='timestamp'):
96
94
tooltips = [
97
95
('date' , '@date' ),
98
96
('value' , '$y{0 a}' )
99
- ])
97
+ ],
98
+ height = 250 )
100
99
cols , data = get_open_interest (df , 'NIFTY' )
101
100
data ['date' ] = data .timestamp .dt .date .astype (str )
102
101
colors = Spectral6 [:len (cols )]
103
102
source .data = source .from_df (data )
104
103
print (cols , colors )
105
104
p .vbar_stack (cols , width = 0.6 , x = 'index' , color = colors , source = source )
105
+ price_data = get_price_oi (df , 'NIFTY' )
106
+ price_chart = twin_plot (price_data , y_axis = ['close' , 'open_int' ])
106
107
107
108
# setup callbacks
108
109
def update ():
@@ -114,6 +115,8 @@ def update():
114
115
print (cols , symbol , max_val )
115
116
p .y_range = Range1d (100 , max_val )
116
117
p .title .text = 'Open interest chart for {} futures' .format (symbol )
118
+ pdata = get_price_data (df , symbol )
119
+ price_chart = twin_plot (pdata , y_axis = ['close' , 'open_int' ])
117
120
118
121
119
122
# set up event triggers
@@ -124,6 +127,7 @@ def update():
124
127
l = layout (
125
128
column (
126
129
row (select_symbol ,button ),
130
+ price_chart ,
127
131
p )
128
132
)
129
133
0 commit comments