我目前正在使用大学的交易API设置交易算法。请记住,我是VBA的新手,但是我对为什么我的代码在以下代码段中引发编译错误感到困惑:
我尝试声明我的参数类型,但这也无济于事。您没有在代码段中看到任何自定义类型。
Private Declare Sub AppSleep Lib “kerne132” Alias “Sleep” (ByVal dwMilliseconds As Long)
Public Sub Pause(PauseInSeconds As Long)
Call AppSleep(PauseInSeconds * 1000)
End Sub
Function marketmake(time, triggerstart, triggerstop)
‘To initialize the API
DIm api As RIT2.API
Set API = New RIT2.API
‘Run the algo during certain time frame in the simulation
If time < triggerstart And time > triggerstop Then
‘Check if any orders are backlogged, if not, then put in a bracket
If Sheets(“Open Orders”).Cells(1, 2) = “” Then
‘The following loop submits the Buy section of bracket
Status = False
Do While Status = False
Status = API.AddOrder(“ALGO”, Range(“Shares”), Range(“MidMarket”) - Range(“Spread”), API.SELL, API.LMT)
Loop
‘The following loop submits the Sell section of bracket
Status = False
Do While Status = False
Status = API.AddOrder(“ALGO”, Range(“Shares”), Range(“MidMarket”) - Range(“Spread”), API.BUY, API.LMT)
Loop
ElseIf InStr(Sheets(“Open Orders”).Cells(2,1), “;” = 0 Then
‘Cancel all orders
API.CancelOrderExpr (“price > 0”)
End If
Marketmake = time + triggerstart
End If
End Function
基本上,我的算法是假设以设定的买入价买入股票,然后在购买必要的股票或循环时间达到任意运行时间时退出循环。
答案 0 :(得分:0)
您需要在Instr上加上一个右括号
ElseIf InStr(Sheets("Open Orders").Cells(2, 1), ";") = 0 Then
用适当的引号替换智能引号。
如果使用64位,则还需要添加PtrSafe
Private Declare PtrSafe Sub AppSleep Lib "kerne132" Alias "Sleep" (ByVal dwMilliseconds As Long)
还有这个
Dim API As RIT2.API
Set API = New RIT2.API
取决于您有一个名为RIT2