|
|
@@ -13,10 +13,10 @@ from plotly.utils import PlotlyJSONEncoder # 用于将Plotly图表序列化为J
|
|
|
|
|
|
# --- 配置部分 (与之前相同) ---
|
|
|
IN_TOKEN_ADDRESS_BSC = '0x55d398326f99059ff775485246999027b3197955'
|
|
|
-OUT_TOKEN_ADDRESS_BSC = '0x6894CDe390a3f51155ea41Ed24a33A4827d3063D' # CAT
|
|
|
+OUT_TOKEN_ADDRESS_BSC = '0x3AeE7602b612de36088F3ffEd8c8f10E86EbF2bF' # out token
|
|
|
AMOUNT_TO_QUERY_HUMAN = decimal.Decimal('1000')
|
|
|
-GATEIO_SPOT_PAIR = 'CAT_USDT'
|
|
|
-GATEIO_FUTURES_CONTRACT = 'CAT_USDT'
|
|
|
+GATEIO_SPOT_PAIR = 'BANK_USDT'
|
|
|
+GATEIO_FUTURES_CONTRACT = 'BANK_USDT'
|
|
|
proxies = None
|
|
|
decimal.getcontext().prec = 36
|
|
|
|
|
|
@@ -171,10 +171,10 @@ def update_data_for_plotly_and_table():
|
|
|
latest_values_for_table["last_updated"] = fetch_time_full
|
|
|
|
|
|
# Log a summary, not too verbose
|
|
|
- print(f"{fetch_time_chart} Update | "
|
|
|
- f"OO:{'OK' if oo_price else 'Fail'} "
|
|
|
- f"GS:{'OK' if spot_price else 'Fail'} "
|
|
|
- f"GF:{'OK' if futures_price else 'Fail'}")
|
|
|
+ # print(f"{fetch_time_chart} Update | "
|
|
|
+ # f"OO:{'OK' if oo_price else 'Fail'} "
|
|
|
+ # f"GS:{'OK' if spot_price else 'Fail'} "
|
|
|
+ # f"GF:{'OK' if futures_price else 'Fail'}")
|
|
|
|
|
|
time.sleep(REFRESH_INTERVAL_SECONDS)
|
|
|
|
|
|
@@ -210,13 +210,23 @@ def get_plotly_chart_data():
|
|
|
|
|
|
# --- 创建价格图 (主图) ---
|
|
|
fig_prices = go.Figure()
|
|
|
- fig_prices.add_trace(go.Scatter(x=times, y=[p['oo_price'] for p in points], mode='lines', name='OpenOcean',
|
|
|
- line=dict(color='rgb(75, 192, 192)')))
|
|
|
- fig_prices.add_trace(go.Scatter(x=times, y=[p['spot_price'] for p in points], mode='lines',
|
|
|
- name=f'Gate Spot ({GATEIO_SPOT_PAIR})', line=dict(color='rgb(255, 99, 132)')))
|
|
|
- fig_prices.add_trace(go.Scatter(x=times, y=[p['futures_price'] for p in points], mode='lines',
|
|
|
- name=f'Gate Futures ({GATEIO_FUTURES_CONTRACT})',
|
|
|
- line=dict(color='rgb(54, 162, 235)')))
|
|
|
+ # 在这里为每个 trace 添加 hovertemplate
|
|
|
+ fig_prices.add_trace(go.Scatter(
|
|
|
+ x=times, y=[p['oo_price'] for p in points], mode='lines', name='OpenOcean',
|
|
|
+ line=dict(color='rgb(75, 192, 192)'),
|
|
|
+ hovertemplate='<b>OpenOcean</b><br>Time: %{x}<br>Price: %{y:.6f}<extra></extra>' # .6f 表示6位小数
|
|
|
+ ))
|
|
|
+ fig_prices.add_trace(go.Scatter(
|
|
|
+ x=times, y=[p['spot_price'] for p in points], mode='lines', name=f'Gate Spot ({GATEIO_SPOT_PAIR})',
|
|
|
+ line=dict(color='rgb(255, 99, 132)'),
|
|
|
+ hovertemplate=f'<b>Gate Spot ({GATEIO_SPOT_PAIR})</b><br>Time: %{{x}}<br>Price: %{{y:.6f}}<extra></extra>'
|
|
|
+ ))
|
|
|
+ fig_prices.add_trace(go.Scatter(
|
|
|
+ x=times, y=[p['futures_price'] for p in points], mode='lines',
|
|
|
+ name=f'Gate Futures ({GATEIO_FUTURES_CONTRACT})',
|
|
|
+ line=dict(color='rgb(54, 162, 235)'),
|
|
|
+ hovertemplate=f'<b>Gate Futures ({GATEIO_FUTURES_CONTRACT})</b><br>Time: %{{x}}<br>Price: %{{y:.6f}}<extra></extra>'
|
|
|
+ ))
|
|
|
|
|
|
target_asset = GATEIO_SPOT_PAIR.split('_')[0]
|
|
|
fig_prices.update_layout(
|
|
|
@@ -224,27 +234,38 @@ def get_plotly_chart_data():
|
|
|
xaxis_title='时间',
|
|
|
yaxis_title=f'价格 ({target_asset}/USDT)',
|
|
|
legend_title_text='平台',
|
|
|
- # height=400 # 可以为每个子图设置高度
|
|
|
+ hovermode='x unified' # 或者 'x', 'closest'
|
|
|
)
|
|
|
|
|
|
# --- 创建价差图 (副图) ---
|
|
|
fig_diffs = go.Figure()
|
|
|
- fig_diffs.add_trace(go.Scatter(x=times, y=[p['diff_oo_spot'] for p in points], mode='lines',
|
|
|
- name=f'OO vs Spot ({GATEIO_SPOT_PAIR})', line=dict(color='rgb(255, 159, 64)')))
|
|
|
- fig_diffs.add_trace(go.Scatter(x=times, y=[p['diff_oo_futures'] for p in points], mode='lines',
|
|
|
- name=f'OO vs Futures ({GATEIO_FUTURES_CONTRACT})',
|
|
|
- line=dict(color='rgb(153, 102, 255)')))
|
|
|
- fig_diffs.add_trace(go.Scatter(x=times, y=[p['diff_spot_futures'] for p in points], mode='lines',
|
|
|
- name=f'Spot ({GATEIO_SPOT_PAIR}) vs Futures ({GATEIO_FUTURES_CONTRACT})',
|
|
|
- line=dict(color='rgb(75, 192, 75)')))
|
|
|
+ # 在这里为每个 trace 添加 hovertemplate
|
|
|
+ fig_diffs.add_trace(go.Scatter(
|
|
|
+ x=times, y=[p['diff_oo_spot'] for p in points], mode='lines', name=f'OO vs Spot ({GATEIO_SPOT_PAIR})',
|
|
|
+ line=dict(color='rgb(255, 159, 64)'),
|
|
|
+ hovertemplate=f'<b>OO vs Spot ({GATEIO_SPOT_PAIR})</b><br>Time: %{{x}}<br>Diff: %{{y:+.4f}}%<extra></extra>'
|
|
|
+ # :+.4f 表示带符号4位小数
|
|
|
+ ))
|
|
|
+ fig_diffs.add_trace(go.Scatter(
|
|
|
+ x=times, y=[p['diff_oo_futures'] for p in points], mode='lines',
|
|
|
+ name=f'OO vs Futures ({GATEIO_FUTURES_CONTRACT})',
|
|
|
+ line=dict(color='rgb(153, 102, 255)'),
|
|
|
+ hovertemplate=f'<b>OO vs Futures ({GATEIO_FUTURES_CONTRACT})</b><br>Time: %{{x}}<br>Diff: %{{y:+.4f}}%<extra></extra>'
|
|
|
+ ))
|
|
|
+ fig_diffs.add_trace(go.Scatter(
|
|
|
+ x=times, y=[p['diff_spot_futures'] for p in points], mode='lines',
|
|
|
+ name=f'Spot ({GATEIO_SPOT_PAIR}) vs Futures ({GATEIO_FUTURES_CONTRACT})',
|
|
|
+ line=dict(color='rgb(75, 192, 75)'),
|
|
|
+ hovertemplate=f'<b>Spot ({GATEIO_SPOT_PAIR}) vs Futures ({GATEIO_FUTURES_CONTRACT})</b><br>Time: %{{x}}<br>Diff: %{{y:+.4f}}%<extra></extra>'
|
|
|
+ ))
|
|
|
|
|
|
fig_diffs.update_layout(
|
|
|
title_text='价差百分比历史',
|
|
|
xaxis_title='时间',
|
|
|
yaxis_title='价差 (%)',
|
|
|
legend_title_text='对比',
|
|
|
- yaxis_zeroline=True, # 在y=0处画一条线
|
|
|
- # height=300
|
|
|
+ yaxis_zeroline=True,
|
|
|
+ hovermode='x unified' # 统一显示同一X轴下所有trace的值
|
|
|
)
|
|
|
|
|
|
# Plotly 不直接支持通过 fig.to_json() 合并具有完全独立Y轴的子图到一个figure中并保持良好交互性
|