How to process an array of items

Hello,

I’m trying to create a macro that runs periodically, that checks the current price of a list of securities, and alerts me when a change of 10% has happened since the last time I was alerted. The logic would look something like this:

  1. Define a list of securities, SECURITY_X
  2. For each security, curl and grep for the current price, SECURITY_X_Current
  3. Compare with the price at which the security was the last time I was alerted, SECURITY_X_Last
  4. If the absolute relative difference between Current and Last is more than 10%, email me an alert, and update Last to the Current value.

My current implementation involves defining separate variables for _X, _X_Current and _X_Last for every security I want to follow. This is cumbersome, since I frequently update the list of securities I track.

So I would like to find an implementation such that I simply define a list of securities, and everything else happens automatically. I imagine that would require some array handling, and I have no idea how to do that (other than most basic use of For Each operating over a list of items.

Any suggestion would really be appreciated. Also I’d be happy to consider offers to pay someone for the implementation.

I really need to get 8.0 out.

The Set Variable action can take tokens in the variable field, so you can do an indirection when setting the value. And you can use the Filter Variable: Value of Named Variable to read a variable indirectly.

So something like:

  • For Each variable “Security” in substrings matching [^,]+ of Security List
    • Curl for %Variable%Security% to get current value in to variable Security Current.
    • Set variable Security Last to “Security Last %Variable%Security%”
    • Filter Variable Value of Named Variable on Security Last.
    • If is empty Security Last or calculation Security Current < 0.9 * Security Last or Security Current > 1.1 * Security Last
      • Notify about %Variable%Security%
      • Set variable “Security Last %Variable%Security%” to %Variable%Security Current%

Something along those lines.

1 Like

That sounds great, Peter!

In the meantime, I actually had an idea of how to implement my macro using only a list of securities, and reading/writing some files in TMP/

  1. For Each “Security” in “Securities”
  2. Curl and grep to get CurrentPrice
  3. Read file %Security%_Last.txt into LastPrice
  4. Compare CurrentPrice and LastPrice
  5. If Alert, email and write CurrentPrice into %Security%_Last.txt

This seems to work very well!

1 Like