You should not have to create all that code in order to use a contract object you received from reqContractDetails. And you should be able to use the entire object without having to copy individual fields. That defeats the purpose. Unfortunately, I don't have enough experience with Excel/VB (nor do we use MS/Office programs, LibreOffice/OpenOffice works much better for us) and I cannot give you additional pointers here.
Maybe, for now, you should create contracts from scratch again.
Using reqContractDetails to retrieve contract objects that IBKR creates for you with all fields they care about initialized is a "best practice" (but clearly not the only approach):
- It facilitates a code structure that "separates concerns". Meaning that you have a small specialized module that knows everything that needs to be known about instruments, trading hours, exchanges, and other contract object details. It knows the many things that can go wrong and what to do in case something does, and applies in a central location all validations and safety checks you care about. You don't want to realize during an urgent position close attempt that something has changed and the contract is no good for trading.
- You are correct that reqContractDetails also needs a contract object for the request, but it has a different function, is more human oriented, and you can provide fewer details than what you'd need for placing orders or other API requests (machine usable). You can specify the instrument in the most convenient way for you (local symbol, CUSIP/ISIN, conid, ...) and, if that makes sense, you can even ask for all contracts of a certain type (say all active futures of a certain type, or the contracts for all currencies of a stock, ...) and you get trade hour details for the current session and the next week or so. Are you really sure you know all rules for trading around holidays and other, possibly short notice, trade hour changes?
- take a look at Richard King's ContractInspector that you can get at . The ContractInspector allows to explore what reqContractDetails can do for you without having to create code first.
But again, this only makes sense if you can convince the Excel/VB environment that it should use the contract object from reqContractDetails without any extra coding or field copying.
闯ü谤驳别苍
On Mon, Aug 1, 2022 at 05:37 AM, Metrodus79 wrote:
toggle quoted message
Show quoted text
Hello joanmarcel119, hello 闯ü谤驳别苍
I'm not anymore sure if the the request for the is valuable for me. To make the request i need a contract object and fill this with all the information that also need to place an order. I'm not sure if the contract object need all the information that i put in.
Request for?
Sub M_REAL_ORDER_KONTRAKT_DETAILS_ANFORDERN()
Call M_GLOB_DEKLARATIONEN_EXCEC
?? ?
??? If Not (objTWSControl Is Nothing) Then
????? ?
??????? If objTWSControl.m_isConnected Then
?????? ?
??????????? 'Create object contract
??????????? Set contract = objTWSControl.contract
??????????? 'Fill this object it with contract information
??????????? With objTWSControl.contract
??????????????? .Symbol = UCase(wksRealImport.Cells(lngZ, flngFindeSpaltewksRealImport("SYMBOL")))
??????????????? .secType = UCase(wksRealImport.Cells(lngZ, flngFindeSpaltewksRealImport("SECTYP")))
??????????????? .lastTradeDateOrContractMonth = wksRealImport.Cells(lngZ, flngFindeSpaltewksRealImport("VERFALLSDATUM"))
??????????????? .multiplier = UCase(wksRealImport.Cells(lngZ, flngFindeSpaltewksRealImport("MULTIPLIKATOR")))
??????????????? .exchange = UCase(wksRealImport.Cells(lngZ, flngFindeSpaltewksRealImport("B?RSE")))
??????????????? .currency = UCase(wksRealImport.Cells(lngZ, flngFindeSpaltewksRealImport("W?HRUNG")))
??????????? ?
??????????? End With
?????????? ?
??????????? Dim lngreqId As Long
?????????? ?
??????????? lngreqId = 1
???????????
?????????? 'Call for detailed contract information.
??????????? Call objTWSControl.m_TWSControl.reqContractDetailsEx(lngreqId, objTWSControl.m_contractInfo)
?????? ?
??????? End If
??
?? End if
end Sub
Public Event send me the contract object in class modul
Public WithEvents m_TWSControl As Tws
Public contract As TWSLib.IContract
Private Sub m_TWSControl_contractDetailsEx(ByVal lngreqId As Long, ByVal contract As ComContractDetails)
Call M_REAL_ORDER_KONTRAKT_OBJEKT(lngreqId, contract)
End Sub
Do i get the same object back what i declared before? is This my problem here?
Thanks again but I'm struggling with this.