API Support Forum
OEC API > API Support > Runtime 13 Type Mismatch error - cancel All
Author Topic: Runtime 13 Type Mismatch error - cancel All
(2 messages, Page 1 of 1)
Moderators: VPfau
ASykes4318
Posts: 18
Joined:


Posted: Dec 20, 2020 @ 09:59 AM             Msg. 1 of 2
We use VBA in MS Access and would like to cancel all orders for a single contact Based on the Orders' state. After it meets the criteria within the If statement, we used a DAO.recordset to retrieve the OderID, from our local table, which the table was filled with the orders data previously including their OrderID.

Problem is; the OrdersApi.CancelOrder fails with Runtime 13 Type Mismatch error. Our parameters have the correct data type for the criteria required. They are; Long for the OrderID and 0 (as "Manual") for the type, we left the "Location" blank since it's optional.



'Created MSansa 2020-1214
On Error GoTo Err_CancelWorkingOrders
Dim i As Integer
Dim Order As GF_Api_COM.Order
Dim cd As DAO.Database, rsc As Recordset
Dim cSQL As String

'refresh the list of active orders
Form_frmActiveOrders.UpdateStatus
'Set APIs
If (api Is Nothing) Then Set api = Glob.c
If (apiOrders Is Nothing) Then Set apiOrders = api.orders

'Stop 'Stops when "Suspend Trading" is checked on the Login window.
If Not apiOrders Is Nothing Then
For i = 0 To apiOrders.Get().Count - 1
Set Order = apiOrders.Get().GetAt(i)

If Order.Contract = aryCommodities(lPointer).Base_Contract Then
If Order.CurrentState = OrderState_Working _
Or Order.CurrentState = OrderState_Sent _
Or Order.CurrentState = OrderState_Held Then
'the Old API command that cancels an order,search for ActiveOrder
' Glob.c.CancelOrder Order
' or Glob.c.CancelOrder ActiveOrder

'Cancel all orders for the same Contract
cSQL = "Select clng([Order]) From tblActiveOrders_temp " _
& "Where Symbol='" & aryCommodities(lPointer).Base_Contract & "';"
Set cd = CurrentDb: Set rsc = cd.OpenRecordset(cSQL)
If rsc.EOF Then Exit Function
Do Until rsc.EOF
apiOrders.CancelOrder rsc(0), SubmissionType_Manual
Loop
End If 'Order state
End If 'Order contracts
Next
End If 'Order Api'


Exit_CancelWorkingOrders:
On Error Resume Next
Set rsc = Nothing: Set cd = Nothing
Set Order = Nothing: Set apiOrders = Nothing
Exit Function

Err_CancelWorkingOrders:
gParms = CStr(lPointer)
Call LogError(Err.Number, Err.Description, "NESClass", "CancelALLWorkingOrders()", gParms)
Resume Exit_CancelWorkingOrders
Resume Next

End Function
Anthony Sykes
SRuscak
Posts: 49
Joined: Aug 24, 2017


Posted: Jan 06, 2021 @ 08:07 AM             Msg. 2 of 2
Hello,

Probably you are getting a Type Mismatch error because you are passing a long instead of OrderID.
https://gainfutures.com/GFAPI/html/M_GF_Api_Orders_IOrdersApi_CancelOrder.htm

-Seth