Tinderbox Forum

Drawing upon data from eg openexchangerates.org

Apologies if this has been discussed elsewhere, or if I’m missing something basic, but is there a way to draw into Tinderbox updated FX rates, crypto prices etc? I have noticed quite a lot of apps offer quite extensive features (Excel are back doing it, Numbers do it, and other apps like numi rely on it).

Look up AutoFetch.

I took a look at that, and RawData, but as I understand it, services like openexchangerates.org are APIs, delivering in JSON, so I am assuming this would not be a simple grab from a URL.

I think that’s the operative word here. I don’t think the design concept is for that sort of thing. I’d suggest emailing support as that will bypass our collective assumptions.

But, at present AutoFetch is how you read such feeds. You can always post process the data once pulled. I’m reflecting on the difference between can I if I really need to, and I’d be kinda neat if I could.

But, what is the use case for pulling a currency tracker in Tinderbox? Pulling data on historical rates I get if you’re analysing them, but live feeds seem something better served by a different type of app. Sorry if I’m understanding.

I’m not talking about live feeds, but where a piece of data is periodically updated. Use cases in a spreadsheet could be a list of holdings, so when the file is opened the latest price of several currencies or other instruments is updated. In the calculator app numi, for example, calculations can include currencies and other instruments, and the app pulls the latest price as part of that. Type the currency, stock or token code, and the latest rate appears instantly.
These are not feeds or historical rates,I agree TB would not be the best app for that, but in the same way that Agents are running errands in the background, watched folders are being watched, and AutoFetch is fetching, I was looking to be able to access discrete slices of data rather than having to look them up manually.
I can imagine lots of possible uses, but for my purposes, I would be interested in being able to draw on some forex rates, some crypto prices etc as attributes which could then automatically update reports etc. But the data could be weather, transport, COVID etc.

Thanks for that useful clarification. Tinderbox doesn’t have a ‘wizard’ for calculating data. But it talks to the shell, has AppleScript support and can pull API feeds. So there’s no shortage of access means. Whether there’s an ROI for yet another interface isn’t clear.

Looking at OpenExchangeRates docs it uses JSON, so you don’t need to do much in Tinderbox. Rather, you simply construct your API call to return the info you need, in the format you want. At the same time, there are moves afoot to improve Tinderbox’s parsing of API data) so that too may help (but too early stage to speak about that here).

1 Like

I’ve got some good news on this front!

First, @mwra is right: AutoFetch is the core idea. AutoFetch goes out to a URL, receives some data, and puts it in the $Text of a note. So, the first step is you’d ask the service, OpenExchangeRates.org, to send you information about (say) Australian dollars.

Now, this particular service replies with JSON. Others might reply with XML, or YAML, or HTML, or something else. They send you a reply like this:

{
    disclaimer: "https://openexchangerates.org/terms/",
    license: "https://openexchangerates.org/license/",
    timestamp: 1449877801,
    base: "USD",
    rates: {
        AED: 3.672538,
        AFN: 66.809999,
        ALL: 125.716501,
        AMD: 484.902502,
        ANG: 1.788575,
        AOA: 135.295998,
        ARS: 9.750101,
        AUD: 1.390866,
        /* ... */
    }
}

This says that the $1 is 3.672638 Arab Emirates Dirham (AED), and proceeds from there.

Today, you’d use a a regular expression to extract the number you want. For example, if you’re chasing Australian Dollars (AUD), you might look for “AUD: (.+),”. This can be translated into English as:

Look for the letters "AUD: ". When you find them, start remembering what comes next, all the way up to a comma. Save the stuff that comes next: we’ll call it $1. Thanks!

That’s not too bad, and you can do tons with just this. Regular Expressions are just a concise way of describing flexible search patterns, and you can learn all about them in aTbRef.

Tomorrow: Coming up in Tinderbox 9.1 (soon), we’ve got a ton of fresh support for this. For example, you will be able to say:

$Text.skipTo("AUD: ").extractNumber("Australian")

This is a lot easier on the eyes, and it’s also a little more flexible than regular expressions.

But there’s an even better way, as it happens, also coming in the next major release:

$Australian=$Text.json["rates"]["AUD"]

This says: "Get the JSON object from the text. In that object, you’ll find a object under “rates”; look up what the rate is for “AUD”.

I don’t want to get sidetracked too much on coming features. There’s a rule about discussing backstage stuff outside backstage; I get to break it, but it’s not a good thing as a rule. (Backstage is a good thing: Tinderbox: Tinderbox Backstage)

But there’s some very nice, state-of-the-art stuff coming soon. I’ll talk more about this at this weekend’s meetup.

3 Likes

Thanks for this, Mark @eastgate, that really helps, and 9.1 sounds fabulous! I really look forward to this.

1 Like