I am building a Lightstreamer client for R. I managed to get the streaming data (tick data) directly into R console. To show how the download stream looks like in R, below you find a reconstruction. I need now to transform the streaming data into an xts object containing OHLC-data (Open, High, Low, Close). I am using sink to move stream to file. In the data-stream the OHLC data is presented as: [U,3,1,20:00:33|3.04|0.0|2.41|3.67|3.03|3.04|#|#|$], where the content is [timestamp, price, change, minimum, maximum, bid, ask, open, close, status].
Question: Is there a structured way/method to (within R environment) transform streaming data into OHLC-data?
counter <- 1 # Start position of counter
sink (file = '/lightstreamer_v3/a10.txt', append = TRUE, split = TRUE) # store data to file. Adjust to your path.
# Code to reproduce the Lightstreamer tick-data visible in R console:
repeat {
counter <- counter + 1 # Handle internal loop
cat ("<< Preamble: preparing push", "\n") # Printouts to R console.
cat ("<< Preamble: preparing push","\n")
cat ("<< Preamble: preparing push","\n")
cat ("<< Preamble: preparing push","\n")
cat ("<<","\n")
cat ("<<","\n")
cat ("<<","\n")
cat ("<< U,3,1,20:00:33|3.04|0.0|2.41|3.67|3.03|3.04|#|#|$","\n") # tick-data
cat ("<<","\n")
cat ("<< 7","\n")
cat (" PROBE","\n")
if (counter >= 10000) { # Counter break.
break
}
}
sink ()