appended to the existing DataFrame object. The x and y coordinates of the rendering
object are updated and then stored to the current session:
In [ 67 ]: start = time.time()
# run for 60 seconds
while (time.time() - start) < 60 :
data = requests.get(url % instrument).json()
# connect and read data
data = dict(data[‘prices’][ 0 ])
# transform data to dict object
ticks = ticks.append(pd.DataFrame({‘bid’: data[‘bid’],
‘ask’: data[‘ask’],
‘instrument’: data[‘instrument’],
‘time’: pd.Timestamp(data[‘time’])},
index=[pd.Timestamp(data[‘time’]),]))
# append DataFrame object with new data to existing object
ds.data[‘x’] = ticks[‘time’]
# update x coordinates in rendering object
ds.data[‘y’] = ticks[‘bid’]
# update y coordinates in rendering object
bp.cursession().store_objects(ds)
# store data objects
time.sleep(0.1)
# wait for a bit
Figure 14-5 shows the output of the plotting exercise — i.e., a static snapshot of a real-
time plot. This approach and the underlying technology of course have many interesting
application areas, both in finance, with its focus today on real-time, high-frequency data,
and far beyond.