Skip to content

Commit bb91a38

Browse files
committed
chore: make graceful exit in data_visualization example
1 parent b9f5747 commit bb91a38

File tree

1 file changed

+4
-0
lines changed
  • binding/python/example/data_visualization

1 file changed

+4
-0
lines changed

binding/python/example/data_visualization/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from ccapi import EventHandler, SessionOptions, SessionConfigs, Session, Subscription, Event
33
import matplotlib.pyplot as plt
44
import seaborn as sns
5+
import time
56

67
if __name__ == "__main__":
78
option = SessionOptions()
@@ -12,6 +13,7 @@
1213
subscription = Subscription(exchange, instrument, "MARKET_DEPTH", "MARKET_DEPTH_MAX=400&CONFLATE_INTERVAL_MILLISECONDS=100")
1314
session.subscribe(subscription)
1415
fig, ax = plt.subplots()
16+
startTime = time.time()
1517
while True:
1618
bids = {"price": [], "size": []}
1719
asks = {"price": [], "size": []}
@@ -47,5 +49,7 @@
4749
)
4850
sns.ecdfplot(x="price", weights="size", legend=False, stat="count", data={"price": asks["price"], "size": asks["size"]}, ax=ax, color="r")
4951
plt.pause(0.1)
52+
if time.time() - startTime > 10:
53+
break
5054
session.stop()
5155
print("Bye")

0 commit comments

Comments
 (0)