File size: 1,173 Bytes
976166f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import panel as pn
import pandas as pd
import numpy as np
from streamz import Stream
from pipeline import stock_price_stream
stream = Stream()
stock_price_stream
pn.extension('tabulator')
pn.extension('vega')

stream_df = pd.DataFrame(columns=['time', 'ticker', 'open', 'close', 'high', 'low',
                                  'volume', 'money', 'in_portfolio', 'in_benchmark', 'aggregate_sector', 'display_name'])

stream_table = pn.widgets.Tabulator(
    stream_df, layout='fit_columns', width=1200, height=1200)
# stream_table


def stream_data(stream_df):
    print('updating stream!!!')
    # stream_df = pd.DataFrame(np.random.randn(5, 5), columns=list('ABCDE'))
    stream_table.stream(stream_df, follow=True)


def create_new_stream():
    stream_df = pd.DataFrame(np.random.randn(5, 5), columns=list('ABCDE'))
    stock_price_stream.emit(stream_df)
# pn.state.add_periodic_callback(create_new_stream, period=1000, count=100)


stock_price_stream.sink(stream_data)
template = pn.template.FastListTemplate(
    title='api monitor')
# stock_price_stream.sink(print)
template.main.extend(
    [stream_table]
)
# )
# stock_price_stream.sink(print)
template.servable()