GetHistory: Download data from Bloomberg using the gethistory program.

Description Usage Arguments Value See Also Examples

View source: R/HighLevelFunctions.R

Description

By default, this methods blocks call, until the file is available (which can be several minutes) (see sync parameter for details)

Usage

1
2
GetHistory(con, fields, tickers, fromDate, toDate = Sys.Date(), sync = TRUE,
  parser = GetHistoryParser, verbose = FALSE, useSystemUudecode = FALSE)

Arguments

con

The BdlConnection object containing the Bloomberg credentials

fields

A vector of fields, e.g. c('PX_LAST', 'NAME')

tickers

A vector of Bloomberg tickers to be downloaded, e.g. c('SPX Index', 'IBM US Equity')

fromDate

The start date in your request

toDate

The end date in your request. Per default, this is today.

sync

If TRUE, then the call will not return until the file is available, or until it times out

parser

The parser used to convert the file into an R object. The default parser is the GetHistoryParser. Another parser you might prefer is the GetHistoryListParser.

verbose

Prints output if TRUE

useSystemUudecode

workaround for a bug with long filenames on some linux systems. Requires installation of sharutils on your system (sudo apt-get install sharutils). This parameter will be removed as soon as we fix the bug.

Value

A list containing the downloaded data. If you use the default parser, then an xts object is returned. More precisely, the list contains the following items:

connection

The BdlConnection object used to connect ot Bloomberg (R). This contains the credentials necessary.

requestTime

The time at which the request was sent to Bloomberg (R)

requestFileName

The name of the file that was uploaded to Bloomberg (R)

replyTime

The time at which the reply was downloaded from Bloomberg (R). Applies only if sync == TRUE

replyFileName

The name of the file that was uploaded to Bloomberg (R)

GetReply(parser., verbose.)

A callback function to download the reply file. The paramaeters are optional and allow you to overwrite their counterparts given in the GetSnapshot call.

success

TRUE if the method call was successful. In case of sync == TRUE, this means that a reply file was successfully downloaded and parsed. Otherwise, it means that the request file was successfully uploaded.

See Also

GetData, GetSnapshot

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
## Not run: 

con <- BdlConnection(user = 'dl111111', 
                     pw = 'XvH,gE2A', 
                     key = '3xzZl0yA')


#######################
#Sync call

history <- GetHistory(con, 
                      fields = c('PX_OPEN', 'PX_HIGH', 'PX_LOW'), 
                      tickers = c('SPX Index', 'SMI Index', 'IBM US Equity', '120421Q FP Equity'),
                      fromDate = "2015-05-01", toDate = "2015-05-08",
                      verbose = TRUE)
                      
#the call blocks, and after 5 minutes or so, you get the reply
if(history$success) {
  history$reply
  #or extract single column:
  history$reply$SPX_Index.PX_HIGH
}

#To see the downloaded file content:
cat(history$response)

#Or, if you prefer a list with one xts object per security:
history <- GetHistory(con, 
                      fields = c('PX_OPEN', 'PX_HIGH', 'PX_LOW'), 
                      tickers = c('SPX Index', 'SMI Index', 'IBM US Equity', '120421Q FP Equity'),
                      fromDate = "2015-05-01", toDate = "2015-05-08",
                      parser = GetHistoryListParser,
                      verbose = TRUE)
                      

#######################
#Async call

history <- GetHistory(con, 
                      fields = c('PX_OPEN', 'PX_HIGH', 'PX_LOW'), 
                      tickers = c('SPX Index', 'SMI Index', 'IBM US Equity', '120421Q FP Equity'),
                      fromDate = "2015-05-01", toDate = "2015-05-08",
                      sync = FALSE,
                      verbose = TRUE)

#the method returns after uploading. 5 minutes later, you can request to download
#the reply using the callback:
reply <- history$GetReply()
if(!is.null(reply)) {
  #do something with the data
}




######################
#Re-download an existing file

TryGetBdlData(con, history$replyFileName)


## End(Not run)

gluc/datalicenseR documentation built on Aug. 5, 2021, 10:50 p.m.