excel - 如何修复 VBA 中的“编译错误:未定义用户定义的类型”
问题描述
我目前正在使用大学的交易 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
基本上我的算法是假设以设定的出价购买股票,然后在购买了必要的股票或循环持续时间达到任意运行时间时打破循环。
解决方案
你的 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
推荐阅读
- flutter - 如何缩小 ListTile 中的图像但不展开它?
- java - 如何在许多字节中找到特定字节?
- azure-api-management - 通过 AZURE API Gateway 公开的每个 API 的代码如何存储?
- c# - 从 csv 中删除 C# 中重复的数字组合
- visual-studio-code - 如何在保存特定文件时触发构建任务?
- python - 如何从 python 中的数据 url 显示和图像?
- excel - 如何通过 Perl 编写带有 VBA 宏的 excel 文件
- android-fragments - 如何从 recyclerview 中的 onclicklistener 替换 kotlin 中的片段
- python - 使用 pandas 将带有键:值的 json 转换为列名:行 df
- python - 大熊猫插值后剩余的 NaN