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,
             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%",
             backend = NULL,
             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

A character vector: the names of the file (including the directory) that have been saved.

Author(s)

Enrico Schumann

See Also

reqHistoricalData

Examples

## Not run: 
require("IButils")

Symbol <- "ZQ   SEP 16"
Security_Type  <- "FUT"
Exchange <- "ECBOT"
Currency <- "USD"

id <- "zq201609"

download_dir <- "~/Trading/Data/IB_downloads/"

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

start <- structure(1423526400, class = c("POSIXct", "POSIXt"))
end <- start + 86400*20

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 = start+86400*40)

## End(Not run)

enricoschumann/IButils documentation built on March 13, 2024, 3:36 p.m.