lbilli / rib

An R implementation of Interactive Brokers API
GNU General Public License v3.0
34 stars 7 forks source link

Make contract specification more flexible #7

Closed enricoschumann closed 4 years ago

enricoschumann commented 4 years ago

It is really good to see an up-to-date pure R implementation of the IB API.

For creating a contract with IBContract, would you consider either adding localSymbol or replacing symbol with localSymbol? In my experience, you can unambiguously define any contract via the local symbol, instrument type, exchange and currency (plus possibly the includeExpired flag). (See https://github.com/enricoschumann/IButils#finding-the-contract-specification )

You could then easily define derivatives contracts. As an example, here would be the Euro Bund Future, expiry December 2019:

library("rib")
wrap <- IBWrapSimple$new()
ic   <- IBClient$new(wrap)
ic$connect(port = 7496, clientId = 1)

contract <- IBContract("FGBL DEC 19",
                       secType  = "FUT",
                       exchange = "DTB",
                       currency = "EUR")
ic$reqContractDetails(1, contract)
ic$checkMsg(2)
ic$disconnect()

I am aware that I can later on override contract$localSymbol. I'd just consider it more natural/convenient if the function supported the local symbol.

thank you.

lbilli commented 4 years ago

Thanks for the feedback.

Granted that IBContract() is rather a template that illustrates how to populate some common Contract fields and one which users can copy and customize to their needs, probably adding an extra localSymbol argument wouldn't hurt.

I'll work on it.