getContract: get a twsContract object

Description Usage Arguments Details Value Note Author(s) See Also Examples

View source: R/getContract.R

Description

get a twsContract object

Usage

1
getContract(x, verbose = TRUE, silent = FALSE, ...)

Arguments

x

can be an instrument, twsInstrument, name of an instrument or twsInstrument, or a numeric or character ‘conId’

verbose

be verbose?

silent

silence warnings?

...

any additional arguments to pass to Contr_From_Instr

Details

If x is a twsInstrument, or if there is a twsInstrument with the same name as x in the .instrument environment, it will return the twsContract found in the $IB field of that object. If not, then if x is the name of a Symbol defined in the Symbol Lookup table (see setSymbolLookup) that has an "IBrokers" src, and a twsContract object stored under "Contract", that twsContract will be returned. Otherwise, x will be passed to Contr_From_Instr which will use what information it can to create a twsContract shell that can/will be updated with reqContractDetails

If you want to force a request for contract details from IB (and ensure you are not getting a local copy of the twsContract), use Contr_From_Instr which will return the twsContract that reqContractDetails returns without altering any local copies. Alternatively, if you call rmContract before calling getContract, it will be forced to look it up (by calling Contr_From_Instr for you).

Value

an object of class twsContract

Note

To ensure you get the contract you're after, you should define your instruments before using this function.

Author(s)

Garrett See

See Also

conId, rmContract, define_stocks, define_options, define_futures, Contr_From_Instr, twsInstrument, getInstrument

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Not run: 
getContract("4082282") #uses reqContractDetails
getContract(4082282) #same
twsInstrument('SEE')
getContract("SEE") # == .instrument$SEE$IB
getContract("DIA") # will use reqContractDetails if "DIA" is not already defined
instr <- getInstrument("SEE")
getContract(instr)
getContract(instr$conId) # will connect to IB and reqContractDetails

## End(Not run)

twsInstrument documentation built on May 2, 2019, 5:24 p.m.