|
|
@@ -0,0 +1,35 @@
|
|
|
+import pandas as pd
|
|
|
+import numpy as np
|
|
|
+import matplotlib.pyplot as plt
|
|
|
+import seaborn as sns
|
|
|
+from datetime import datetime, timedelta
|
|
|
+
|
|
|
+# 创建示例订单簿数据
|
|
|
+times = [datetime.now() - timedelta(seconds=i) for i in range(10)]
|
|
|
+prices = np.linspace(10000, 10100, 10)
|
|
|
+bid_qtys = np.random.rand(10, 10) * 100 # 随机生成挂单数量
|
|
|
+
|
|
|
+# 创建一个DataFrame来表示订单簿数据
|
|
|
+order_book_df = pd.DataFrame(
|
|
|
+ {
|
|
|
+ 'time': np.repeat(times, 10),
|
|
|
+ 'price': np.tile(prices, 10),
|
|
|
+ 'bid_qty': bid_qtys.flatten()
|
|
|
+ }
|
|
|
+)
|
|
|
+
|
|
|
+# 设置索引为时间和价格
|
|
|
+order_book_df.set_index(['time', 'price'], inplace=True)
|
|
|
+
|
|
|
+# 选择 bid_qty 列来绘制热力图
|
|
|
+heatmap_data = order_book_df['bid_qty'].unstack().T
|
|
|
+
|
|
|
+# 创建热力图
|
|
|
+plt.figure(figsize=(12, 8))
|
|
|
+sns.heatmap(heatmap_data, cmap="Blues", cbar=True, cbar_kws={'label': 'Order Quantity'})
|
|
|
+plt.title('Order Book Heatmap')
|
|
|
+plt.xlabel('Time')
|
|
|
+plt.ylabel('Price')
|
|
|
+plt.xticks(rotation=45)
|
|
|
+plt.tight_layout()
|
|
|
+plt.show()
|