简体   繁体   中英

How to fix “Compile Error: User defined type not defined” in VBA

I am currently setting a trading algorithm using a University's trading API. Keep in mind I am fairly new to VBA, but I am just confused as to why my code is throwing a compile error in the following snippet:

I've tried declaring my parameters type but this doesn't help either. I haven't made any custom types as you can see in the snippet.


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



basically my algorithm is suppose to buy shares up to a set bid price, then break out of the loop when either the necessary shares were bought or loop duration has reached some arbitrary runtime.

You need a closing bracket on your Instr

ElseIf InStr(Sheets("Open Orders").Cells(2, 1), ";") = 0 Then

Replace smart quotes with proper quotes.

If using 64 bit you need to add PtrSafe as well

Private Declare PtrSafe Sub AppSleep Lib "kerne132" Alias "Sleep" (ByVal dwMilliseconds As Long)

And this

Dim API As RIT2.API
Set API = New RIT2.API

relies on you have a class called RIT2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM