ib_hist_data: Download Historical Data

View source: R/ib_hist_data.R

ib_hist_dataR Documentation

Download Historical Data

Description

Download historical data from IB API and store them as text files.

Usage

ib_hist_data(Symbol, Security_Type, Exchange, Currency, id = NULL,
             directory, barSize, durationStr = NULL,
             whatToShow = "TRADES",
             start = as.POSIXct(Sys.Date() - 30), end = Sys.time(),
             useRTH = FALSE,
             skip.from, skip.until, skip.tz = "",
             verbose = TRUE, trim = TRUE, accumulate = FALSE,
             port = 7496, sep = ",",
             filename = "%id%__%start%__%end%",
             filename.datetime.fmt = identity,
             backend = "rib",
             clientId = NULL)

Arguments

Symbol

character

Security_Type

character

Exchange

character

Currency

character

id

character; optional: the prefix for text files. If NULL, Symbol etc. are pasted together

directory

character: the directory in which the files are stored

barSize

character

durationStr

character. If NULL, the function attempts to set a long duration. (This argument may be removed in the future since it rarely makes sense to set it explicitly.)

whatToShow

character: TRADES, MIDPOINT, BID or ASK

start

POSIXct

end

POSIXct

useRTH

logical

skip.from

character

skip.until

character

skip.tz

character

verbose

logical

accumulate

logical

trim

logical

sep

character: the column separator

port

the TWS port

clientId

either NULL or an integer. Specifying an integer is supported only for backend rib. If NULL, a random id is chosen.

filename

character: pattern for the filenames of the stored files. May include special patterns such as ‘%id%’.

backend

a lowercase string or NULL. Supported are ibrokers or rib. Default is NULL, which translates into ibrokers.

Details

See IB API documentation https://interactivebrokers.github.io/

The package uses functionality of either package IBrokers or rib, depending on the setting of backend.

Value

If accumulate is TRUE, a data.frame of the retrieved data. If accumulate is FALSE (the default), a character vector: the names of the file (including the directory) that have been saved. Files are written in tsdb format.

Author(s)

Enrico Schumann

See Also

combine_files for aggregating files

Examples

## Not run: 
contr <- rib::Contract
contr$secIdType <- "ISIN"
contr$secId <- isin <- "DE0005557508"
contr$exchange <- "IBIS"
contr <- contract_details(contr)[[1]]
contr <- contr$contract

download.dir <- "~/Trading/Data/IB_downloads/"

barSize <- "5 mins"
whatToShow <- "MIDPOINT"

start <- structure(Sys.time() - 86400 * 7,
                   class = c("POSIXct", "POSIXt"))

ib_hist_data(Symbol = Symbol,
             Security_Type = Security_Type,
             Exchange = Exchange,
             Currency = Currency,
             id = id,
             directory = download_dir,
             barSize = barSize,
             whatToShow = whatToShow,
             start = start,
             end = Sys.time())

## End(Not run)

enricoschumann/IButils documentation built on Dec. 11, 2024, 3:03 p.m.