GetSnapshot: Download data from Bloomberg using the getsnap program.

Description Usage Arguments Value See Also Examples

View source: R/HighLevelFunctions.R

Description

The program getsnap returns two files: one response file containing some errorcodes and masterdate. It can be used to check if the request was OK. Some time after the snaptime, the reply file is made available. It contains the actual prices. By default, this methods blocks call, until the file is available (which can be several hours, depending on your snaptime) (see sync parameter for details)

Usage

1
2
3
GetSnapshot(con, tickers, snaptime, delayLimit = 3, sync = TRUE,
  responseParser = GetSnapshotResponseParser,
  replyParser = GetSnapshotReplyParser, timeoutMin = 120, verbose = FALSE)

Arguments

con

The BdlConnection object containing the Bloomberg credentials

tickers

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

snaptime

A character string, containing the snapshot time, in the format HHMM, and only half-hours are allowed (e.g. 0900 or 0930, but not 0915). Also, the timezone of the snapshot is your Bloomberg region (either NY, LONDON, or TOKYO), e.g. 0930

delayLimit

An integer, representing the maximum time Bloomberg should wait on the next price after the snaptime. This is useful if you have delayed prices on some of the markets requested.

sync

If TRUE, the call does not return until the response file is available, or if a timeout occurs

responseParser

The parser used to convert the response file into an R object

replyParser

The parser used to convert the reply file into an R object

timeoutMin

The timeout of the replyFile. This only applies if sync == TRUE.

verbose

Prints output if TRUE

Value

A list containing the response file, as well as a callback to fetch the reply. 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)

responseTime

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

responseFileName

The name of the response file containing the error codes.

GetResponse(responseParser., verbose.)

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

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(replyParser., 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, GetHistory

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
## Not run: 

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

#######################
# Sync call
   
#this blocks, and waits until the files are available, or until a timeout occurs.
#Remember that the snaptime is in the timezone of your Bloomberg region (London, NY, Tokyo),
#and that only full and have hours are allowed (e.g. 0900 or 0930)
snapshot <- GetSnapshot(con,
                        tickers = c('SPX Index', 'SMI Index'),
                        snaptime = "0930",
                        delayLimit = 15,
                        sync = TRUE)
                       
#after long time waiting                        
if(snapshot$success) {
  snapshot$reply
  reply['SPX Index', 'OPEN_PRICE']
}

#You can re-download both the reply and the response file:
snapshot$GetResponse()

if you have problems with the download, you can overwrite the verbose parameter:
snapshot$GetResponse(verbose. = TRUE)

#or you might use a different parser, to see the file in raw text:
cat(snapshot$GetResponse(responseParser. = function(x) x))


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

#this returns immediately after uploading the request. You 
#can then use the callback handles for downloading the results.
snapshot <- GetSnapshot(con, 
                        tickers = c('SPX Index', 'SMI Index'),
                        snaptime = "0930",
                        delayLimit = 15)
                        
#after 3 minutes or so, you can check if your request was ok:
response <- snapshot$GetResponse()

#check if there were any errors in the response:
any(response$ERROR_CODE != 0)

#get the error message to identify the problem:
GetSnapshotErrorMessage(response$ERROR_CODE)

#when you expect the reply to be available:
reply <- snapshot$GetReply()
if(!is.null(reply)) reply['SPX Index', 'OPEN_PRICE']


## End(Not run)

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