Combo orders IBcontroller

Hi,
is it possible to enter combo order IBController?
There are some inter-commodity spread for example which TWS allows to trade using the native spread of the exchange. How can these order be generated?
I think these are called combination order in TWS, and using API can be created by merging two legs in one combo order.

Thanks
Alpha

Here is documentation how to place all order types:
https://interactivebrokers.github.io/tws-api/basic_orders.html

These are just ordinary LMT or MKT or REL orders with extra information (OrderComboLegs)
Since IBController is open source, you can use this information to add OrderComboLegs to order structure.

1 Like

Hi Tomasz,
I know the API can do it. My questions was if the present implementation in AFL includes combo orders.
The answer seems to be negative, so only a modification of the plugin would allow it, but in that case programming everything directly in python or C could be easier.

The TWS excel sample applications allows it, so in principle it could be done from OLE.
Is there a way to use directly the Active X TWS objects of the API from AFL, with some worked out example?

With R I can do it, usind the Active X server, without the Amibroker pluging.

Thanks
AB

You don't understand how automated trading works in AmiBroker.

IBController is NOT part of AFL.

IBController is separate application that exposes OLE interface for automated trading that AmiBroker can use as any other OLE/ActiveX automation server.

By design all trading interfaces are external and not part of AmiBroker. AmiBroker just talks to them via generic OLE http://www.amibroker.com/guide/a_aflcom.html. IBController is open source software that can be modified.

Hi Tomasz,

I know what a ole server is, and I use one to run R code from AFL. I can run any command I want just from AFL by creating the OLE object, WITHOUT USING any plugin.

Are you saying the IB API does not include its native OLE server and IBcontroller is the only existing one?

I think there is an Excel sample on the IB website which is using ActiveX , see this page https://interactivebrokers.github.io/tws-api/activex.html#activex_sample.

So it seems another ActiveX server already exists, and is used in that Excel sample. So the same server could be used directly from AFL.

AB

I digged into the IB API a bit more, and found this dll TWSLib.dll, which is used in VB and activeX excel samples. From the link I gave above in fact we can read "The ActiveX API wraps the C#/.NET API and is provided as an open source project TWSLib", so all the latest API functionalities should be available.
There seems to be no com server though. Is there a way to use TWSLib activeX objects from AFL?
The source code of TWSLib is in C:\TWS API\source\CSharpClient\activex and can be compiled to create dlls, but infact they already exists, and are CshapApi.dll and TWSLib.dll. The latter should be the activex .

It is a bit confusing because TWSLib.dll does not appear in the list of available references in VB, and in fact the one used in the sample VB is CshapApi, but when exploring its objects I can see TWSLib, which is the activex object used to initiate connections etc.

I think there should be a way to use these active objects from Afl.
I checked IBcontroller, and it does not seem to use any activex; it is all c++, but the c++ api has been deprecated since api 9.72.

IBController does not use ActiveX because each release of new ActiveX from IB usually broke the compatibility with older versions. So it was a big no-no.

If you looked at the source you would find that the whole "C++ API" is not API. It is just a tiny wrapper that talks over TCP/IP socket to TWS. That is all what is done, that is whole mystery and that is how it works and it does not require any objects/com or whatever. All their "APIs" in the end talk over TCP/IP and the protocol is kept backward compatible that allows to work with ANY version of TWS and will never be deprecated as all their tools depend on it.

comboLegs are available in struct Contract in contract.h file. So all you need to do is to fill that member of struct inside CBrokerIBDlg::PlaceOrder function in BrokerIBDlg.cpp file.

Do you guys know if there is any way to request the placed combo positions through API. When I try reqPositions() function, I get them as individual positions. Lets say I entered a bull put spread, with one buy put and one sell put, I cannot see those as a bag position when fetching. How do I close the spread ?

You can try the python plugin AmiPy, and use IB python api, or ibinsync, which is a bit simpler.

1 Like