Hi, I am using , is this the correct use of forEach with a String List
import java.util.List
val List<String> stocks = newArrayList("BTC", "DGC", "ETC", "ETH", "GRC", "LTC") // crypto
rule "Get share prices"
when
System started or
Time cron "0 1/15 * ? * * *"
then
logInfo("org.openhab","Shares: Obtaining the latest prices.")
stocks.forEach[ stock , i |
val csv = sendHttpGetRequest("https://www.alphavantage.co/query?function=DIGITAL_CURRENCY_DAILY&symbol="+stock+"&market=GBP&datatype=csv&apikey=xxxxx").split("\n")
val firstLine = csv.get(1).split(",")
// 4th item (close price)
val price = firstLine.get(4).trim
sendCommand(stock +"_Current_Price", price)
logInfo("share.rules",stock +"_Current_Price "+price)
]
logInfo("org.openhab","Shares: Updated completed.")
end
the code is fetching the first value correct and populating the state, but not looping around and passes the error
2021-03-21 19:11:07.751 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Error during the execution of startup rule 'Get share prices': 4
this is with OH 2.5.12 ,
comments appreciated