API Support Forum
OEC API > API Support > Excel DOM example not working
Author Topic: Excel DOM example not working
(2 messages, Page 1 of 1)
Moderators: VPfau
ASykes4318
Posts: 18
Joined:


Posted: Dec 29, 2020 @ 09:25 PM             Msg. 1 of 2
The following statement is giving us the following error from the excel DOM Code:
• Object doesn't support this property or method
Is there an update code procedure that works with the new GF API??
We would like to also send maindraft and draftTP only also is this possible??

orders.SendLinkedOrders mainDraft, OSOGroupingMethod_ByPrice, linked

Sub SendOrder(side As OrderSide, row As Integer, qty As Integer)
On Error GoTo Err
'Stop
Dim account As account
Set account = CurrentAccount
If account Is Nothing Then
MsgBox "Invalid account"
Else
Dim Price As Double
Price = CurrentTop - (row - TopRow) * CurrentContract.tickSize
If qty < 0 Then
DecreaseQty side, Price, -qty, account
Else
Dim Builder As OrderDraftBuilder
Set Builder = New OrderDraftBuilder
Builder.WithSide side
Builder.WithPrice Price
Builder.WithQuantity qty
Builder.WithContractID CurrentContract.ID
Builder.WithComments "DOM"
Builder.WithAccountID account.ID

If (side = OrderSide_Buy) And (Price CurrentContract.CurrentPrice.LastPrice) Then
Builder.WithOrderType (OrderType_Limit)
Else
Builder.WithOrderType (OrderType_Stop)
End If
Dim sl As Integer, tp As Integer
sl = Range("K6")
tp = Range("K7")
Dim mainDraft As OrderDraft
Dim draftSL As OrderDraft
Dim draftTP As OrderDraft
Set mainDraft = Builder.Build
If (sl = 0) And (tp = 0) Then
Stop
orders.SendOrder mainDraft
Else
If sl 0 Then
If mainDraft.side = OrderSide_Buy Then
Builder.WithSide OrderSide_Sell
Builder.WithPrice mainDraft.Price - sl * CurrentContract.tickSize
Else
Builder.WithSide OrderSide_Buy
Builder.WithPrice mainDraft.Price + sl * CurrentContract.tickSize
End If
Builder.WithOrderType OrderType_Stop
Set draftSL = Builder.Build
End If
If tp 0 Then
If mainDraft.side = OrderSide_Buy Then
Builder.WithSide OrderSide_Sell
Builder.WithPrice mainDraft.Price + tp * CurrentContract.tickSize
Else
Builder.WithSide OrderSide_Buy
Builder.WithPrice mainDraft.Price - tp * CurrentContract.tickSize
End If
Builder.WithOrderType OrderType_Limit
Set draftTP = Builder.Build
End If
Dim linked As OrderDraftList
Set linked = New OrderDraftList
If (tp 0) Then
linked.Add draftTP
End If
If sl 0 Then
linked.Add draftSL
End If
orders.SendLinkedOrders mainDraft, OSOGroupingMethod_ByPrice, linked
End If
End If
End If
Exit Sub
Err:
MsgBox Err.Description
End Sub
Anthony Sykes
SRuscak
Posts: 50
Joined: Aug 24, 2017


Posted: Jan 07, 2021 @ 03:30 PM             Msg. 2 of 2
Hello,

Yes, this code is pretty old. I improved the area around this function and it will be released in the next COM package.

SendLinkedOrders is no longer valid. You are looking for SendOSOOrders, and can see this in the C# documentation.
https://gainfutures.com/GFAPI/html/T_GF_Api_Orders_IOrdersApi.htm

Here is an improved VBA subroutine:

Sub SendOrder(side As OrderSide, row As Integer, qty As Integer)
On Error GoTo Err
Dim account As account
Set account = CurrentAccount
If account Is Nothing Then
MsgBox "Invalid account"
Else
Dim Price As Double
Price = CurrentTop - (row - TopRow) * CurrentContract.tickSize
If qty < 0 Then
DecreaseQty side, Price, -qty, account
Else
Dim Builder As OrderDraftBuilder
Set Builder = New OrderDraftBuilder
Builder.WithSide side
Builder.WithPrice Price
Builder.WithQuantity qty
Builder.WithContractID CurrentContract.id
Builder.WithComments "DOM"
Builder.WithAccountID account.id

If (side = OrderSide_Buy) And (Price CurrentContract.CurrentPrice.LastPrice) Then
Builder.WithOrderType (OrderType_Limit)
Else
Builder.WithOrderType (OrderType_Stop)
End If

Dim stopLoss As Integer
Dim takeProfit As Integer
Dim mainDraft As OrderDraft
Dim draftStopLoss As OrderDraft
Dim draftTakeProfit As OrderDraft

stopLoss = range("K6")
takeProfit = range("K7")
Set mainDraft = Builder.Build

If (stopLoss = 0) And (takeProfit = 0) Then
orders.SendOrder mainDraft
Else
If stopLoss 0 Then
If mainDraft.side = OrderSide_Buy Then
Builder.WithSide OrderSide_Sell
Builder.WithPrice mainDraft.Price - stopLoss * CurrentContract.tickSize
Else
Builder.WithSide OrderSide_Buy
Builder.WithPrice mainDraft.Price + stopLoss * CurrentContract.tickSize
End If
Builder.WithOrderType OrderType_Stop
Set draftStopLoss = Builder.Build
End If

If takeProfit 0 Then
If mainDraft.side = OrderSide_Buy Then
Builder.WithSide OrderSide_Sell
Builder.WithPrice mainDraft.Price + takeProfit * CurrentContract.tickSize
Else
Builder.WithSide OrderSide_Buy
Builder.WithPrice mainDraft.Price - takeProfit * CurrentContract.tickSize
End If
Builder.WithOrderType OrderType_Limit
Set draftTakeProfit = Builder.Build
End If

If (takeProfit 0) Then
If stopLoss 0 Then
orders.SendOSOOrders mainDraft, draftTakeProfit, draftStopLoss, OSOGroupingMethod_ByPrice
Else
orders.SendOSOOrders mainDraft, draftTakeProfit, Nothing, OSOGroupingMethod_ByPrice
End If
ElseIf stopLoss 0 Then
orders.SendOSOOrders mainDraft, draftStopLoss, Nothing, OSOGroupingMethod_ByPrice
End If
End If
End If
End If
Exit Sub
Err:
MsgBox Err.Description
End Sub