getBAT: download Bid Ask Trade data and merge into BAT object

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

Description

getBAT downloads and merges data for Bid, Ask, and Trade. reqTBBO is an alias for getBAT.

Usage

1
2
3
4
5
getBAT(Symbols, endDateTime, tws = NULL, barSize = "1 min",
  duration = "5 D", useRTH = "1", auto.assign = TRUE, env = .GlobalEnv)

reqTBBO(Symbols, endDateTime, tws = NULL, barSize = "1 min",
  duration = "5 D", useRTH = "1", auto.assign = TRUE, env = .GlobalEnv)

Arguments

Symbols

can be a twsInstrument, a twsContract, an instrumnet or the name of an instrument. (you can give it a character vector to get multiple Symbols)

endDateTime

end date/time for request. See details.

tws

a twsConnection object. optional.

barSize

bar size to retrieve. default='1 min'

duration

time span the request will cover. default='5 D'

useRTH

only include regular trading hours?

auto.assign

if TRUE, data will be assigned to symbols in the env or .GlobalEnv if no env given.

env

environment in which to save results

Details

reqTBBO is an alias for getBAT.

Symbol can be one of: an instrument, the name of an instrument, the name of an undefined stock, or a twsContract object.

Before making a request for historical data, Symbol will be passed through Contr_From_Instr (which is a wrapper for buildIBcontract) which will convert Symbol into an updated, complete twsContract.

If you want to get data for something other than a stock, then Symbol should be an instrument object, a twsContract object or the name of a previosly defined instrument

Unlike reqHistoricalData, The endDateTime argument must be of the form 'CCYY-MM-DD HH:MM:SS'

If the contract is expired, the minimum (i.e. oldest) of endDateTime, if given, and 1 minute before midnight on the expiration date, will be used for endDateTime in the call to reqHistoricalData.

Below is copied from the help page for reqHistoricalData

If endDateTime is not specified the current time as returned from the TWS server will be used. This is the preferred method for backfilling data. The ‘TZ’ portion of the string is optional.

Legal barSize settings are technically ‘1 secs’,‘5 secs’,‘15 secs’, ‘30 mins’,‘1 min’,‘2 mins’, ‘3 mins’,‘5 mins’,‘15 mins’, ‘30 mins’,‘1 hour’,‘1 day’, ‘1 week’,‘1 month’,‘3 months’, and ‘1 year’. They must be specified exactly and there is no guarantee from the API that all will work for all securities or durations.

The duration string must be of the form ‘n S’ where the last character may be any one of ‘S’ (seconds), ‘D’ (days), ‘W’ (weeks), ‘M’ (months), and ‘Y’ (year). At present the limit for years is 1.

Value

Returns (or assigns) an xts object containing Bid.Price, Ask.Price, Trade.Price, Mid.Price, along with additional information stored in the objects xtsAttributes,

Author(s)

Garrett See

References

InteractiveBrokers www.interactivebrokers.com

IB API http://interactivebrokers.com/php/apiUsersGuide/apiguide.htm

IB Historic Data Limitations http://individuals.interactivebrokers.com/php/apiUsersGuide/apiguide/api/historical_data_limitations.htm#XREF_93621_Historical_Data

See Also

reqTBBOhistory, Contr_From_Instr, reqHistoricalData, reqHistory, getIBequities

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## Not run: 
#If no instrument is defined for symbol,
#it will assume you are trying to get a stock
getBAT("XOM")

#Alternatively, pass a twsContract
contract <- twsSTK("XOM","SMART","NYSE")
getBAT(contract)

#or, if you use FinancialInstrument, add an IB slot to hold
#the twsContract object
currency('USD')
stock('XOM', 'USD', 1, IB=twsSTK('XOM'))
getBAT('XOM') #gets contract from .instrument

## End(Not run)

gsee/twsInstrument documentation built on May 17, 2019, 8:55 a.m.