合并UI
This commit is contained in:
+4
-2
@@ -1,6 +1,8 @@
|
|||||||
[config]
|
[config]
|
||||||
miniqmtpath = /Users/gao/Workspace/quant
|
; miniqmtpath = /Users/gao/Workspace/quant
|
||||||
grid_price = 10.9,10.0,9.1,8.2,7.3,6.4,5.5,4.6,3.7,2.8,1.9,1.0
|
miniQMTPath=D:\\Programs\\DTQMT\\userdata_mini
|
||||||
|
; grid_price = 10.9,10.0,9.1,8.2,7.3,6.4,5.5,4.6,3.7,2.8,1.9,1.0
|
||||||
|
grid_price=1.665,1.660,1.655,1.650,1.645,1.640,1.635,1.630,1.625,1.620,1.615,1.610
|
||||||
grid_volume = 200
|
grid_volume = 200
|
||||||
account_no = 99082560
|
account_no = 99082560
|
||||||
max_enabled_targets = 10
|
max_enabled_targets = 10
|
||||||
|
|||||||
@@ -66,8 +66,8 @@ class SFGridStrategy:
|
|||||||
print(f'|- 市价更新[{self.tradeTarget.stock_code}-{self.tradeTarget.stock_name}] - LOCKED')
|
print(f'|- 市价更新[{self.tradeTarget.stock_code}-{self.tradeTarget.stock_name}] - LOCKED')
|
||||||
try:
|
try:
|
||||||
index = self.tradeTarget.grid_index
|
index = self.tradeTarget.grid_index
|
||||||
price = sfgrid_constants.grid_price[int(index)] # pyright: ignore[reportArgumentType]
|
price = -1 if index>=len(sfgrid_constants.grid_price) else sfgrid_constants.grid_price[int(index)] # pyright: ignore[reportArgumentType]
|
||||||
lowPrice = sfgrid_constants.grid_price[int(index) + 1] if len(sfgrid_constants.grid_price)>int(index) + 1 else -1.0 # pyright: ignore[reportArgumentType]
|
lowPrice = -1 if index+1>=len(sfgrid_constants.grid_price) else sfgrid_constants.grid_price[int(index) + 1] # pyright: ignore[reportArgumentType]
|
||||||
highPrice = sfgrid_constants.grid_price[int(index) - 1] # pyright: ignore[reportArgumentType]
|
highPrice = sfgrid_constants.grid_price[int(index) - 1] # pyright: ignore[reportArgumentType]
|
||||||
|
|
||||||
lastPrice = float("{:.3f}".format(data[self.tradeTarget.stock_code]['lastPrice']))
|
lastPrice = float("{:.3f}".format(data[self.tradeTarget.stock_code]['lastPrice']))
|
||||||
|
|||||||
+9
-70
@@ -1,82 +1,21 @@
|
|||||||
# coding:utf-8
|
# coding:utf-8
|
||||||
from mimetypes import init
|
|
||||||
import sys
|
import sys
|
||||||
sys.stdout.reconfigure(encoding='utf-8') # 设置标准输出编码为UTF-8 # type: ignore
|
sys.stdout.reconfigure(encoding='utf-8') # 设置标准输出编码为UTF-8 # type: ignore
|
||||||
from core import strategy_db
|
from core import strategy_db
|
||||||
# from core.main_controller import SFGridController
|
from core.main_controller import SFGridController
|
||||||
# import core.util as util
|
|
||||||
import sfgrid_constants as sdConstants
|
import sfgrid_constants as sdConstants
|
||||||
# from xtquant import xtdata
|
|
||||||
import ui
|
import ui
|
||||||
|
|
||||||
def interact():
|
|
||||||
"""执行后进入repl模式"""
|
|
||||||
import code
|
|
||||||
code.InteractiveConsole(locals=globals()).interact()
|
|
||||||
|
|
||||||
# def startMarketData():
|
|
||||||
# ctrl.startMarketData()
|
|
||||||
|
|
||||||
# def stopMarketData():
|
|
||||||
# ctrl.stopMarketData()
|
|
||||||
|
|
||||||
# def pool():
|
|
||||||
# ctrl.print_pool()
|
|
||||||
|
|
||||||
# def addTarget(stock_code):
|
|
||||||
# ctrl.add_trade_target(stock_code)
|
|
||||||
|
|
||||||
# def delTarget(index:int):
|
|
||||||
# ctrl.del_trade_target(index)
|
|
||||||
|
|
||||||
# def accountInfo():
|
|
||||||
# ctrl.print_account_info()
|
|
||||||
|
|
||||||
# def positionInfo():
|
|
||||||
# ctrl.print_position_info()
|
|
||||||
|
|
||||||
# def startTrade(index:int):
|
|
||||||
# ctrl.start_stock_trade(index)
|
|
||||||
|
|
||||||
# def pauseTrade(index:int):
|
|
||||||
# ctrl.pause_stock_trade(index)
|
|
||||||
|
|
||||||
# def stockTradeCtrl(index: int):
|
|
||||||
# return ctrl.stock_trade_ctrl[ctrl.instrument_pool[index].stock_code]
|
|
||||||
|
|
||||||
def help():
|
|
||||||
print("基础指令:")
|
|
||||||
print(" ===================================================")
|
|
||||||
print(" startMarketData() - 启动市场数据接收")
|
|
||||||
print(" stopMarketData() - 停止市场数据接收\n")
|
|
||||||
print(" pool() - 打印标的池信息")
|
|
||||||
print(" addTarget(stock_code) - 添加交易标的")
|
|
||||||
print(" delTarget(index) - 删除交易标的\n")
|
|
||||||
print(" accountInfo() - 打印账户信息")
|
|
||||||
print(" positionInfo() - 打印持仓信息\n")
|
|
||||||
print(" startTrade(index) - 启动标的交易")
|
|
||||||
print(" pauseTrade(index) - 暂停标的交易")
|
|
||||||
print(" ===================================================")
|
|
||||||
print("内部指令:")
|
|
||||||
print(" stockTradeCtrl(index) - 获取标的交易控制器")
|
|
||||||
print(" ctrl - 访问控制器实例")
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
sdConstants.initConfig()
|
||||||
strategy_db.db.connect()
|
strategy_db.db.connect()
|
||||||
strategy_db.db.create_tables([strategy_db.TradeTarget])
|
strategy_db.db.create_tables([strategy_db.TradeTarget])
|
||||||
print('- [成功]数据库模块初始化')
|
print('- [成功]数据库模块初始化')
|
||||||
|
|
||||||
targets = strategy_db.TradeTarget.select()
|
|
||||||
|
|
||||||
|
|
||||||
app = ui.TradeTargetUI(trade_targets=targets)
|
|
||||||
app.run()
|
|
||||||
|
|
||||||
# sdConstants.initConfig()
|
targets = strategy_db.TradeTarget.select()
|
||||||
# print(f'{sdConstants.account_no} : {sdConstants.miniQMTPath}')
|
appUi = ui.TradeTargetUI(trade_targets=targets)
|
||||||
# ctrl: SFGridController = SFGridController(sdConstants.account_no, sdConstants.miniQMTPath)
|
|
||||||
# if ctrl.inited:
|
print(f'{sdConstants.account_no} : {sdConstants.miniQMTPath}')
|
||||||
# interact()
|
ctrl: SFGridController = SFGridController(sdConstants.account_no, sdConstants.miniQMTPath)
|
||||||
# else:
|
|
||||||
# print("控制器初始化失败")
|
appUi.run()
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ import configparser
|
|||||||
import sfgrid_constants
|
import sfgrid_constants
|
||||||
|
|
||||||
class TradeTargetUI:
|
class TradeTargetUI:
|
||||||
def __init__(self, trade_targets: Optional[List[TradeTarget]] = None):
|
def __init__(self, trade_targets: List[TradeTarget]):
|
||||||
if trade_targets is not None:
|
self.data:dict[str, TradeTarget] = {}
|
||||||
self.trade_targets = trade_targets
|
for temp in trade_targets:
|
||||||
else:
|
target:TradeTarget = temp
|
||||||
self.trade_targets = []
|
self.data[str(target.get_id())] = target
|
||||||
|
|
||||||
self.root = tk.Tk()
|
self.root = tk.Tk()
|
||||||
self.root.title("三疯交易系统")
|
self.root.title("三疯交易系统")
|
||||||
@@ -43,7 +43,7 @@ class TradeTargetUI:
|
|||||||
menubar.add_cascade(label="系统", menu=system_menu)
|
menubar.add_cascade(label="系统", menu=system_menu)
|
||||||
system_menu.add_command(label="系统设置", command=self.system_settings)
|
system_menu.add_command(label="系统设置", command=self.system_settings)
|
||||||
system_menu.add_separator()
|
system_menu.add_separator()
|
||||||
system_menu.add_command(label="退出", command=self.root.quit)
|
system_menu.add_command(label="退出", command=self.root.destroy)
|
||||||
|
|
||||||
def create_tables_area(self, parent):
|
def create_tables_area(self, parent):
|
||||||
"""创建表格区域"""
|
"""创建表格区域"""
|
||||||
@@ -152,8 +152,8 @@ class TradeTargetUI:
|
|||||||
|
|
||||||
def populate_trade_table(self):
|
def populate_trade_table(self):
|
||||||
"""填充交易标的表格数据"""
|
"""填充交易标的表格数据"""
|
||||||
for temp in self.trade_targets:
|
for temp in self.data:
|
||||||
target: TradeTarget = temp
|
target: TradeTarget = self.data[temp]
|
||||||
values = [
|
values = [
|
||||||
target.id, # type: ignore
|
target.id, # type: ignore
|
||||||
target.stock_code,
|
target.stock_code,
|
||||||
@@ -238,9 +238,9 @@ class TradeTargetUI:
|
|||||||
target_id = values[0]
|
target_id = values[0]
|
||||||
|
|
||||||
# 从列表中找到对应的target对象
|
# 从列表中找到对应的target对象
|
||||||
for target in self.trade_targets:
|
for id in self.data:
|
||||||
if target.id == target_id: # type: ignore
|
if target_id == id: # type: ignore
|
||||||
return target
|
return self.data[id]
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -307,7 +307,7 @@ class TradeTargetUI:
|
|||||||
|
|
||||||
if result:
|
if result:
|
||||||
try:
|
try:
|
||||||
self.trade_targets.remove(target)
|
del self.data[target.get_id()]
|
||||||
self.add_log("WARNING", f"已删除交易标的: {target.stock_code} - {target.stock_name}")
|
self.add_log("WARNING", f"已删除交易标的: {target.stock_code} - {target.stock_name}")
|
||||||
self.refresh_table()
|
self.refresh_table()
|
||||||
messagebox.showinfo("删除成功", f"已删除 {target.stock_code} ({target.stock_name})")
|
messagebox.showinfo("删除成功", f"已删除 {target.stock_code} ({target.stock_name})")
|
||||||
@@ -653,15 +653,3 @@ class TradeTargetUI:
|
|||||||
"""运行程序"""
|
"""运行程序"""
|
||||||
self.root.mainloop()
|
self.root.mainloop()
|
||||||
|
|
||||||
|
|
||||||
# 使用示例
|
|
||||||
if __name__ == "__main__":
|
|
||||||
print("交易标的监控系统启动...")
|
|
||||||
print("功能说明:")
|
|
||||||
print(" - 左侧表格显示所有交易标的详细信息")
|
|
||||||
print(" - 右侧表格显示操作日志")
|
|
||||||
print(" - 底部五个功能按钮提供操作")
|
|
||||||
|
|
||||||
# 创建并运行界面
|
|
||||||
app = TradeTargetUI()
|
|
||||||
app.run()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user