以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  高级功能研发区  (http://weistock.com/bbs/list.asp?boardid=5)
----  [求助]如何将交易信号导入金字塔并实现程序化交易  (http://weistock.com/bbs/dispbbs.asp?boardid=5&id=4273)

--  作者:wangwatercup
--  发布时间:2010/12/3 15:01:28
--  [求助]如何将交易信号导入金字塔并实现程序化交易
  我用matlab编了交易系统,现在可以将交易信号输出到EXCEL(比如1是买,2是卖)。
现在想实现程序化交易,因此需要金字塔自动读取(每隔一秒钟执行一次)EXCEL文件,将信号传递给某一个变量,然后依据这个变量金字塔自动交易。

因为有点急,所以来不急慢慢学习,看了一堆论坛的帖子感觉还是有些迷茫,能否请高人指点一二。
--  作者:z7c9
--  发布时间:2010/12/3 20:21:40
--  
用vbs读excel,用order下单
--  作者:一亩三分地
--  发布时间:2010/12/4 13:27:14
--  
 Sub APPLICATION_VBAStart()
call Application.SetTimer(1,1000) \'1S触发一次
End Sub

Sub APPLICATION_Close()
call Application.KillTimer(1)
End Sub

Sub APPLICATION_Timer(ID)
call Operate()
End Sub

Sub Operate()
On Error Resume Next
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open _
    ("D:\\Scripts\\output.xls")
    
way = objExcel.Cells(1, 1).Value  \'取第一个单元格数据
If Err.Number=0 Then
Select Case way
    \'通过order执行操作,参数需要填充
   Case 1
        \'order.Buy(Type,Vol,Price,StoplmtPrice,Code,Market,AccountID,Valid)
   Case 2
        \'order.Sell(Type,Vol,Price,StoplmtPrice,Code,Market,AccountID,Valid)
   Case 3
        \'order.BuyShort(Type,Vol,Price,StoplmtPrice,Code,Market,AccountID,Valid)
   Case 4
        \'order.SellShort(Type,Vol,Price,StoplmtPrice,Code,Market,AccountID,Valid)
End Select
End If

objExcel.Quit
End Sub
--  作者:wangwatercup
--  发布时间:2010/12/4 20:58:13
--  
 谢谢了!
但是这一步

On Error Resume Next
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open _
    ("D:\\Scripts\\output.xls")

很慢,大约要用10秒的时间

--  作者:wangwatercup
--  发布时间:2010/12/4 21:02:53
--  
 还有,为什么在金字塔的函数列表里找不到order这个函数?

--  作者:夏小飞
--  发布时间:2010/12/8 11:06:45
--  

你不能输出到INI里吗 这样不是读的更快 ORDER是个对象


--  作者:wangwatercup
--  发布时间:2010/12/9 14:51:14
--  
我是把信号写入文本文件的,代码如下:
(1)在excel的vba里面:
                Set fs = CreateObject("Scripting.FileSystemObject")
                Set a = fs.CreateTextFile("c:\\out.txt", True)
                a.WriteLine (signal)
                a.Close
(2)在金字塔的vbs里面:
    On Error Resume Next
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set a = fs.OpenTextFile("c:\\out.txt", 1)
   
    signal = a.ReadLine
    a.Close
    \'msgbox "signal"&signal

不知道如果写入ini文件该怎么写,请指教。

--  作者:一亩三分地
--  发布时间:2010/12/9 21:55:24
--  
设计个INI文件,excel那头只能用一般写文本文件的方式写。金字塔这头提供专用访问ini文件的函数,访问很方便。
output.ini

[contract]
code=***
market=***

[operation]
tag=*
way=***
mode=***
vol=***
price=***

用tag标志是否有效,excel更新信息后置为有效,金字塔读取后置无效,防止重复执行
其它的诸如开平买卖,限价市价,手数,指定价格等

--  作者:Morgan
--  发布时间:2010/12/10 11:23:11
--  

Data = 1.2
CALL Document.WritePrivateProfileFloat("MyCpp", "Stock", Data, "C:\\Stock.ini")


--  作者:wangwatercup
--  发布时间:2010/12/14 16:06:27
--  
  终于搞定了 呵呵
(1)vba里面
Const IniFileName As String = "C:\\out.ini"
\' the path and filename to the file containing the information you want to read/write

Private Declare Function GetPrivateProfileStringA Lib "kernel32" (ByVal strSection As String, _
    ByVal strKey As String, ByVal strDefault As String, ByVal strReturnedString As String, ByVal lngSize As Long, ByVal strFileNameName As String) As Long
   
Private Declare Function WritePrivateProfileStringA Lib "kernel32" (ByVal strSection As String, _
    ByVal strKey As String, ByVal strString As String, ByVal strFileNameName As String) As Long
Public Function WritePrivateProfileString32(ByVal strFileName As String, _
    ByVal strSection As String, ByVal strKey As String, ByVal strValue As String) As Boolean
Dim lngValid As Long
    On Error Resume Next
    lngValid = WritePrivateProfileStringA(strSection, strKey, strValue, strFileName)
    If lngValid > 0 Then WritePrivateProfileString32 = True
    On Error GoTo 0
End Function
Public Function GetPrivateProfileString32(ByVal strFileName As String, ByVal strSection As String, ByVal strKey As String, Optional strDefault) As String
Dim strReturnString As String, lngSize As Long, lngValid As Long
    On Error Resume Next
    If IsMissing(strDefault) Then strDefault = ""
    strReturnString = Space(1024)
    lngSize = Len(strReturnString)
    lngValid = GetPrivateProfileStringA(strSection, strKey, strDefault, strReturnString, lngSize, strFileName)
    GetPrivateProfileString32 = Left(strReturnString, lngValid)
    On Error GoTo 0
End Function

Sub WriteUserInfo()
\' saves information in the file IniFileName
signal = 2
Tag = 0
    a1 = WritePrivateProfileString32(IniFileName, "operation", "tag", Tag)
    a2 = WritePrivateProfileString32(IniFileName, "operation", "signal", signal)
    If Not a1 Then
        MsgBox "Not able to save user info in " & IniFileName, vbExclamation, "Folder does not exist!"
        Exit Sub
    End If
   
End Sub

(2)金字塔里面
sub mtest3()
tag = cdbl(document.GetPrivateProfileFloat("operation", "tag", 0, "C:\\out1.ini"))
msgbox tag
end sub