- 精华
- 0
- 在线时间
- 422 小时
- UID
- 68068
- 积分
- 6707
- 帖子
- 483
- 阅读权限
- 100
- 注册时间
- 2011-9-27
- 最后登录
- 2022-2-18
- 精华
- 0
- UID
- 68068
- 积分
- 6707
- 帖子
- 483
- 主题
- 31
- 阅读权限
- 100
- 注册时间
- 2011-9-27
- 最后登录
- 2022-2-18
|
本帖最后由 莫小漠 于 2012-9-21 17:06 编辑
代码功能就只是检查并同步持仓,代替人工
配合监控器30秒自动刷新
欢迎诸位debug和发展新功能。
关闭方式目前是右下角关闭,没有改消息模式
使用方法:安装AUTOIT后,右键>新建AutoIt V3脚本,然后右击新建的脚本文件,编辑该脚本,复制粘贴下方代码,F7编译。会在相同目录下出现同名exe文件,即该工具。
配合论坛已有的AUTOIT脚本即可进一步加强账户交易准确性、稳定性及安全性。
本方式适用于使用BUY/SELL方式开仓的。
对于自动换月,若是正常上班的朋友,白天肯定没有时间去对持仓品种进行换月,因新版TB已支持品种直接映射而无需加载新商品,一方面节省了资源加快了系统运行速度,另一方面对目前论坛现有的自动换月代码产生影响(如果你依旧叠加好几个合约的话,那对你毫无影响)。
这里提供一个思路:在有时间的时候,比如下班之后,对工作区中的合约映射更改至新的目标主力合约,第二天开盘后,自动核对持仓工具配合监控器会发现持仓不对,自动予以同步。就实现的开盘时间无人值守的自动换月。
例如:股指周五要从IF1209换到IF1210了,周四晚上可以将工作区的映射合约改到IF1210,第二天开盘系统自动发现我们策略中不应该有IF1209合约,应该有IF1210合约,于是通过同步,平老仓换新仓。
工具使用了简单的GUI界面,可设置自动刷新时间,这个时间要配合监控器中的时间来使用。监控器刷新时间应该比工具刷新时间要短。
工具界面
监控器时间:
持仓匹配时自动提示并关闭对话框
持仓不匹配时提示并关闭对话框且开始同步持仓
- #include <ButtonConstants.au3>
- #include <GUIConstantsEx.au3>
- #include <WindowsConstants.au3>
- #region ### START Koda GUI section ### Form=
- Dim $result, $lilunlots, $shijilots, $weizhi
- $Form1 = GUICreate("仓位监控器辅助", 200, 200, 200, 200)
- $Button1 = GUICtrlCreateButton("开始监控", 18, 56, 75, 25)
- $Input1 = GUICtrlCreateInput("30", 120, 40, 49, 21)
- $lable = GUICtrlCreateLabel("自动刷新时间(秒):", 20, 40, 100, 17)
- GUISetState(@SW_SHOW)
- #endregion ### END Koda GUI section ###
- While 1
- $nMsg = GUIGetMsg()
- Switch $nMsg
- Case $GUI_EVENT_CLOSE
- Exit
- Case $Button1
- While 1
- If WinExists("交易开拓者平台(旗舰版) - ", "") = 1 Then
- $result = 1
- WinActivate("交易开拓者平台(旗舰版) - ")
- Sleep(500)
- If WinExists("自动交易头寸监控器") = 0 Then
- $result = WinMenuSelectItem("交易开拓者平台(旗舰版) -", "", "交易(&T)", "监控器")
- EndIf
- Sleep(1000)
- WinActivate("自动交易头寸监控器")
- ;ControlFocus("自动交易头寸监控器", "", "Button13")
- ;ControlClick("自动交易头寸监控器","","Button13")
- $shijilots = ControlGetText("自动交易头寸监控器", "", "Button18") ;获得账户实际持仓汇总
- $weizhi = StringInStr($shijilots, "=多")
- $shijilots = StringLeft($shijilots, $weizhi - 1)
- $shijilots = StringMid($shijilots, 3, 10)
- $lilunlots = ControlGetText("自动交易头寸监控器", "", "Button19") ;获得账户理论持仓汇总
- $weizhi = StringInStr($lilunlots, "=多")
- $lilunlots = StringLeft($lilunlots, $weizhi - 1)
- $lilunlots = StringMid($lilunlots, 3, 10)
- If ($lilunlots <> $shijilots) Then
- ;将持仓数量输出到文本文件中
- ;WinActivate("新建 文本文档 -")
- ;ControlSetText("新建 文本文档 -", "", "Edit1",$shijilots&@CRLF&$lilunlots)
- MsgBox(0 + 16, "头寸不匹配警告:", "实际仓位状况:" & $shijilots & @CRLF & "理论仓位状况:" & $lilunlots,5)
- ControlFocus("自动交易头寸监控器", "", "Button12")
- ControlClick("自动交易头寸监控器", "", "Button12")
- Sleep(20)
- ControlFocus("确认", "", "Button1")
- ControlClick("确认", "", "Button1")
- Sleep(20)
- ControlFocus("委托确认[一键同步]", "", "Button2")
- ControlClick("委托确认[一键同步]", "", "Button2")
- Sleep(1000)
- ControlFocus("自动交易头寸监控器", "", "Button16")
- ControlClick("自动交易头寸监控器", "", "Button16")
- Else
- MsgBox(0, "头寸匹配:", "实际仓位状况:" & $shijilots & @CRLF & "理论仓位状况:" & $lilunlots, 2)
- ControlFocus("自动交易头寸监控器", "", "Button16")
- ControlClick("自动交易头寸监控器", "", "Button16")
- EndIf
- EndIf
- ;Sleep($Input1 * 1000)
- WEnd
- EndSwitch
- WEnd
复制代码 |
附件: 你需要登录才可以下载或查看附件。没有帐号?注册
|