Hello everyone,
I currently collect share price data using the following rules. As you can see I’m just repeating the same rule with a small change. Is there room for improvement or maybe in a more programmable way? Nothing broken with what I have in place, I just want to make sure there isn’t a better way to do things. The API I’m using is free, so limits the number of requests per day. This means I need to limit the number of times I run the rules.
Thanks in advanced, all comments are welcome.
rule "Get TW Share Price From CSV Data"
when
Time cron "0 15 * ? * * *"
then
val csv = sendHttpGetRequest("https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=LON:TW&interval=15min&outputsize=compact&datatype=csv&apikey=MYAPIKEY").split("\n")
val firstLine = csv.get(2).split(",")
val Price = firstLine.get(2).trim
logInfo("org.openhab", "Share Price Update: TW; " + Price)
TW_Current_Price.sendCommand(Price)
end
rule "Get TCG Share Price From CSV Data"
when
Time cron "0 16 * ? * * *"
then
val csv = sendHttpGetRequest("https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=LON:TCG&interval=15min&outputsize=compact&datatype=csv&apikey=MYAPIKEY").split("\n")
val firstLine = csv.get(2).split(",")
val Price = firstLine.get(2).trim
logInfo("org.openhab", "Share Price Update: TCG; " + Price)
TC_Current_Price.sendCommand(Price)
end
rule "Get SLA Share Price From CSV Data"
when
Time cron "0 17 * ? * * *"
then
val csv = sendHttpGetRequest("https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=LON:SLA&interval=15min&outputsize=compact&datatype=csv&apikey=MYAPIKEY").split("\n")
val firstLine = csv.get(2).split(",")
val Price = firstLine.get(2).trim
logInfo("org.openhab", "Share Price Update: SLA; " + Price)
SL_Current_Price.sendCommand(Price)
end