[HELP] My rule works but errors each time

I have the rule below that collects the current available share prices for me. It does the job, however I get an error each time the rule runs. Does anyone have any ideas why?

2019-08-19 12:46:00.003 [INFO ] [e.smarthome.model.script.org.openhab] - Shares: Obtaining the latest prices.
2019-08-19 12:46:01.376 [INFO ] [e.smarthome.model.script.org.openhab] - Shares: Updating TW.
2019-08-19 12:46:02.533 [INFO ] [e.smarthome.model.script.org.openhab] - Shares: Updating TCG.
2019-08-19 12:46:03.900 [INFO ] [e.smarthome.model.script.org.openhab] - Shares: Updating SLA.
2019-08-19 12:46:05.456 [INFO ] [e.smarthome.model.script.org.openhab] - Shares: Updating RMG.
2019-08-19 12:46:07.126 [INFO ] [e.smarthome.model.script.org.openhab] - Shares: Updating BARC.
2019-08-19 12:46:08.546 [INFO ] [e.smarthome.model.script.org.openhab] - Shares: Updating VOD.
2019-08-19 12:46:08.807 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Get The Latest Share Prices': 2

import java.util.List
val List<String> vShares = newArrayList("TW", "TCG", "SLA", "RMG", "BARC", "VOD", "LLOY") // Each share symbol

rule "Get The Latest Share Prices"
when
    Time cron "0 1/15 * ? * * *"
then
if(now.getHourOfDay < 8 || now.getHourOfDay > 17 || Weekend.state == ON) return;
    logInfo("org.openhab","Shares: Obtaining the latest prices.")
    vShares.forEach[ vShare, i |
        val csv = sendHttpGetRequest("https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=LON:"+vShare+"&interval=15min&outputsize=compact&datatype=csv&apikey=MYAPIKEYGOESHERE").split("\n")
        val firstLine = csv.get(2).split(",")
        val price = firstLine.get(2).trim
        sendCommand(vShare+"_Current_Price", price)
        logInfo("org.openhab","Shares: Updating {}.",vShare)
        Thread::sleep(150)
    ]
logInfo("org.openhab","Shares: Updated completed.")
end

Add a logInfo to display vshare before using it in sendCommand.
I’ll guess you have one beginning with a digit, not allowed in Item names.

Fromthe structure of the list there is something wron with the LLOY shares. As @rossko57 wrote, just add log lines to see the data at each step. And show us your items maybe there is a problem.

Thanks for your help.

Nothing unusual about the LLOY share by the looks of it, however I moved the order and now VOD doesn’t update. I also removed LLOY from the list and don’t get an error. Another ideas?

2019-08-19 16:01:00.144 [INFO ] [e.smarthome.model.script.org.openhab] - Shares: Obtaining the latest prices.
2019-08-19 16:01:01.781 [INFO ] [e.smarthome.model.script.org.openhab] - Shares: TW has a price of 145.5500p
2019-08-19 16:01:01.783 [INFO ] [e.smarthome.model.script.org.openhab] - Shares: Updating TW.
2019-08-19 16:01:03.306 [INFO ] [e.smarthome.model.script.org.openhab] - Shares: TCG has a price of 8.9780p
2019-08-19 16:01:03.307 [INFO ] [e.smarthome.model.script.org.openhab] - Shares: Updating TCG.
2019-08-19 16:01:05.810 [INFO ] [e.smarthome.model.script.org.openhab] - Shares: SLA has a price of 243.4000p
2019-08-19 16:01:05.811 [INFO ] [e.smarthome.model.script.org.openhab] - Shares: Updating SLA.
2019-08-19 16:01:08.689 [INFO ] [e.smarthome.model.script.org.openhab] - Shares: RMG has a price of 199.3000p
2019-08-19 16:01:08.690 [INFO ] [e.smarthome.model.script.org.openhab] - Shares: Updating RMG.
2019-08-19 16:01:10.327 [INFO ] [e.smarthome.model.script.org.openhab] - Shares: BARC has a price of 141.2200p
2019-08-19 16:01:10.329 [INFO ] [e.smarthome.model.script.org.openhab] - Shares: Updating BARC.
2019-08-19 16:01:11.609 [INFO ] [e.smarthome.model.script.org.openhab] - Shares: LLOY has a price of 49.9650p
2019-08-19 16:01:11.610 [INFO ] [e.smarthome.model.script.org.openhab] - Shares: Updating LLOY.
2019-08-19 16:01:11.890 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Get The Latest Share Prices': 2

You still don’t know what csv is at time of failure, or it has an element (2).

Sounds like the remote service only lets you fire so many quick http requests.

You’ve hit the nail on the head there @rossko57. Searched the documentation and found it, with the free key your limited to 5 calls per minute. So I’ve now added a small delay between calls to ensure I only ever make 5 calls per minute.

Thanks for the suggestions.

Now that my issue has been solved, there an additional aspect I’d like to cover. I’m not expecting much, but hopefully this information will be of use to others and may even help someone create a binding.

Alpha Avantage also have a GitHub repository, here.

With in the java section I found this example. Is there a way to convert this so that it works with OH? This is in the repository names; patriques82/ alphavantage4j

public class App {
  public static void main(String[] args) {
    String apiKey = "50M3AP1K3Y";
    int timeout = 3000;
    AlphaVantageConnector apiConnector = new AlphaVantageConnector(apiKey, timeout);
    TimeSeries stockTimeSeries = new TimeSeries(apiConnector);
    
    try {
      IntraDay response = stockTimeSeries.intraDay("MSFT", Interval.ONE_MIN, OutputSize.COMPACT);
      Map<String, String> metaData = response.getMetaData();
      System.out.println("Information: " + metaData.get("1. Information"));
      System.out.println("Stock: " + metaData.get("2. Symbol"));
      
      List<StockData> stockData = response.getStockData();
      stockData.forEach(stock -> {
        System.out.println("date:   " + stock.getDateTime());
        System.out.println("open:   " + stock.getOpen());
        System.out.println("high:   " + stock.getHigh());
        System.out.println("low:    " + stock.getLow());
        System.out.println("close:  " + stock.getClose());
        System.out.println("volume: " + stock.getVolume());
      });
    } catch (AlphaVantageException e) {
      System.out.println("something went wrong");
    }
  }
}

Someone could use that library to build a new binding. I don’t think there is a way to get access to third party libraries from Rules DSL Rules.