1oscon commited on
Commit
f2700f2
·
verified ·
1 Parent(s): c601445

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -2
app.py CHANGED
@@ -116,6 +116,31 @@ class 轻量引擎:
116
  "alloc_mode": "fixed"
117
  }
118
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  def _记录(msg: str):
120
  with 状态锁:
121
  运行状态["日志"].append(f"[{datetime.now().strftime('%H:%M:%S')}] {msg}")
@@ -234,8 +259,12 @@ except Exception:
234
 
235
  # ========== Gradio 界面 ==========
236
  with gr.Blocks(title="模拟实盘(OKX 公共WS + 多策略引擎)", theme=theme, css=css) as demo:
237
- # 顶栏与提示:直接放在 Blocks 顶层,宽度与下方主内容一致
238
- gr.HTML('<div id="topbar"><h1>📈 模拟实盘控制台</h1><div class="right"><span class="badge">中文界面</span></div></div>')
 
 
 
 
239
  gr.Markdown("提示:点击“⚙️ 设置”进入配置页(上传CSV、参数加载/保存)。若后端模块缺失将自动进入演示引擎。")
240
 
241
  with gr.Row():
@@ -285,8 +314,14 @@ with gr.Blocks(title="模拟实盘(OKX 公共WS + 多策略引擎)", theme=t
285
  停止按钮.click(fn=停止模拟, outputs=状态显示)
286
  刷新按钮.click(fn=获取状态, outputs=[状态显示, 日志显示])
287
 
 
 
 
288
  # 初始和定时刷新
289
  demo.load(fn=获取状态, outputs=[状态显示, 日志显示])
 
 
 
290
  timer = gr.Timer(2)
291
  timer.tick(fn=获取状态, outputs=[状态显示, 日志显示])
292
 
 
116
  "alloc_mode": "fixed"
117
  }
118
 
119
+ def 从参数推断周期及选中(JSON文本: str):
120
+ try:
121
+ d = json.loads(JSON文本)
122
+ except Exception:
123
+ d = {}
124
+ tf = None
125
+ for k in ('tf', 'period', '周期', 'bar', 'bar_min', 'timeframe', 'k', 'k_min'):
126
+ v = d.get(k)
127
+ if isinstance(v, (int, float)) and int(v) > 0:
128
+ tf = int(v); break
129
+ if isinstance(v, str) and v.strip().isdigit():
130
+ tf = int(v.strip()); break
131
+ if not tf:
132
+ tf = 60
133
+ base = [30, 60, 120, 240]
134
+ if tf not in base:
135
+ base.append(tf)
136
+ base = sorted(set(base))
137
+ return [str(x) for x in base], str(tf)
138
+
139
+ def 参数变更更新周期(参数JSON文本: str):
140
+ choices, value = 从参数推断周期及选中(参数JSON文本)
141
+ import gradio as gr
142
+ return gr.update(choices=choices, value=value)
143
+
144
  def _记录(msg: str):
145
  with 状态锁:
146
  运行状态["日志"].append(f"[{datetime.now().strftime('%H:%M:%S')}] {msg}")
 
259
 
260
  # ========== Gradio 界面 ==========
261
  with gr.Blocks(title="模拟实盘(OKX 公共WS + 多策略引擎)", theme=theme, css=css) as demo:
262
+ # 顶栏外层添加 prose / gr-prose 类使其宽度与 Markdown 一致
263
+ gr.HTML(
264
+ '<div id="topbar"><h1>📈 模拟实盘控制台</h1><div class="right"><span class="badge">中文界面</span></div></div>',
265
+ elem_id="topbar_wrap",
266
+ elem_classes=["prose", "gr-prose"]
267
+ )
268
  gr.Markdown("提示:点击“⚙️ 设置”进入配置页(上传CSV、参数加载/保存)。若后端模块缺失将自动进入演示引擎。")
269
 
270
  with gr.Row():
 
314
  停止按钮.click(fn=停止模拟, outputs=状态显示)
315
  刷新按钮.click(fn=获取状态, outputs=[状态显示, 日志显示])
316
 
317
+ # 参数JSON变化时,自动更新周期选项与选中值
318
+ 参数输入.change(fn=参数变更更新周期, inputs=参数输入, outputs=周期选择)
319
+
320
  # 初始和定时刷新
321
  demo.load(fn=获取状态, outputs=[状态显示, 日志显示])
322
+ # 页面加载时按参数JSON回填周期
323
+ demo.load(fn=lambda s: 参数变更更新周期(s), inputs=参数输入, outputs=周期选择)
324
+
325
  timer = gr.Timer(2)
326
  timer.tick(fn=获取状态, outputs=[状态显示, 日志显示])
327