question

Upvotes
Accepted
129 16 25 31

How do I set the ratio for one leg in VBA?

Hi,

I would like to set the ratio for one leg in VBA. The Quantity is for the whole structure.
How to do that? Do I need to add it as a third leg?
Could you please help me?

Here is my source code:

Dim hOrder As New COMPLEXORDER
  
  ' Complex options order header ---------------------------
  hOrder.Strategy = "Vertical"

  hOrder.SetSymbol 0, Symbol
  hOrder.SetExchange 0, Exch
  hOrder.SetPriceType 0, "Limit"
  hOrder.SetTIF 0, "Day"
  hOrder.SetQuantity 0, Qty
  hOrder.SetAccount 0, Acct

  ' Leg 1
  hOrder.SetSide 1, Side
  hOrder.SetPosition 1, "Open"
  hOrder.SetOptType 1, PC
  hOrder.SetMonth 1, Mat
  hOrder.SetStrike 1, Strike
    
   
  ' Leg 2
  If (Side = "Buy") Then
      hOrder.SetSide 2, "Sell"
  ElseIf (Side = "Sell") Then
      hOrder.SetSide 2, "Buy"    
  End If

  hOrder.SetPosition 2, "Open"
  hOrder.SetOptType 2, PC
  hOrder.SetMonth 2, Mat
  hOrder.SetStrike 2, Strike2
  
  hOrder.SetPrice 0, Px
  If (Live) Then
  rtnVal = hOrder.Submit(myerr)
  
  If Not rtnVal Then
    If myerr <> "" Then
      MsgBox myerr
                 MsgBox (Now() & "--" & str & "-- Error -- " & myerr)
    Else
      MsgBox "Failed - Please Contact REDI Support."
    End If
  Else
                  Debug.Print (Now() & "--" & str & "-- Order Submitted")
  End If
  Else
    MsgBox (str & " Not live order")
    End If
End Sub
redi-apivba
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
Accepted
136 1 3 3

You need to specify hOrder.Strategy = “Ratio Orders” and specify the header and leg quantities as per the below code snippet.

I just tried this on my machine and it worked (2:7 ratio).

hOrder.Strategy = "Ratio Orders"
hOrder.SetSymbol 0, "AAPL"
hOrder.SetExchange 0, "DEM2 DMA"
hOrder.SetPriceType 0, "Market"
hOrder.SetTIF 0, "Day"
hOrder.SetAccount 0, "DEMO2"
  ' Leg 1 of calendar spread hOrder.SetSide 1, "Buy"
hOrder.SetPosition 1, "Open"
hOrder.SetOptType 1, "Call"
hOrder.SetMonth 1, "Jun '18" hOrder.SetStrike 1, "175.00"
hOrder.SetQuantity 1, 2
  ' Leg 2 of calendar spread hOrder.SetSide 2, "Sell"
hOrder.SetPosition 2, "Open" hOrder.SetOptType 2, "Call"
hOrder.SetMonth 2, "Jun '18"
hOrder.SetStrike 2, "180.00"
hOrder.SetQuantity 2, 7hOrder.SetQuantity 0, 1

By the way, the Ratio Order strategy and other strategies like Butterfly, Delta Neutral, Ratio… are demonstrated in the "Order Entry - Complex Option (US Options).xlsm" example available on GitHub here: https://github.com/TR-API-Samples/Example.REDI.VB.ExcelExamples

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hi Dan,

I just tried it and it works perfectly well.

Thank you very much for you kind help and for the link to the examples on GitHub.

Akechi

Upvotes
136 1 3 3

Hi Akechi,

What do you mean ratio for one leg?

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
129 16 25 31

I want to change the quantity on the second leg, so 1 of one option and say 2x another

Something similar to what I do on this screenshot: screenshot.png


screenshot.png (299.4 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

I’ve done more testing:

When I set hOrder.Strategy = “Custom”, I get “Side is required”.

When I set hOrder.Strategy = “Calendar”, the order goes through in the custom ratio, but the side in Message Monitor says “Calendar”.

What do I have to specify in the API for Ratio orders to be submitted?
I tried hOrder.Strategy = “Custom”, but that didn’t work either.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.