# Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

# Exchange Rates

#### Joe Caverly

Do you need to know what the current exchange rate is?

If I want to make a purchase of an item being sold in USD, I need to find out approx. how much that is in CAD.

This function will find the current exchange rate;
Code:
`` function usd2can=`%@execstr[type "http://finance.yahoo.com/d/quotes.csv?f=l1&s=USDCAD=X"]```

Now, if the item that I want to purchase is \$89.10 USD;
Code:
``@echo The answer is: %((%@usd2can[]*89.1))``

For GBP,
Code:
``function gbp2can=`%@execstr[type "http://finance.yahoo.com/d/quotes.csv?f=l1&s=GBPCAD=X"]```

Now, if the item that I want to purchase is \$70.00 GBP;
Code:
``@echo The answer is: %((%@gbp2can[]*70.00))``

Joe

Nice! I like the techniques you used to extract data from the WWW. Very usable.

PS: without modifications this specific function will only have accurate results in countries where the "." is the decimal seperator.
Here in the Netherlands (and most of Europe) 70 * 1.165 will cause your item to have an unexpected pricetag :-)

Using "," as decimal separator (and converted to an alias):

Code:
``````alias 2EURO=`echo %1 %2 = %@eval[%1 * %@replace[.,^^,,%@execstr[type "http://finance.yahoo.com/d/quotes.csv?f=l1&s=%2EUR=X"]] ] EUR`

Output:
[C:\Temp]2euro 10 GBP
10 GBP = 11,581 EUR

EDIT: Needs some improvement: for example 2euro 10,5 USD will give a "Divide by zero" error message. Problem is the " , " in 10,5. How ironic :-)
Will try to fix it later tonight.

Last edited:
"," is regarded as a parameter separator, which caused "10,5 USD" to be split in 3 parameters.
A "workaround" is to get all the parameters with %\$ and split these on spaces, like %@word[" ",0,%\$]

With that, the new and shiny alias is now:

Code:
``````alias 2EURO=`echo %\$ = %@eval[ %@word[" ",0,%\$] * %@replace[.,^^,,%@execstr[type "http://finance.yahoo.com/d/quotes.csv?f=l1&s=%@word[" ",1,%\$]EUR=X"]] ] EUR`

Output:
[C:\Temp]2euro 10,5 USD
10,5 USD = 9,78915 EUR``````

I know ... a little bit ugly. I consider moving to Canada to get rid of this ;-)

@Joe Caverly 's original function was written for systems where the "." was the decimal separator and "," the thousands separator.
The alias converted this to a European version, where "," is the decimal sparator and "."the thousands separator.
It also had to compensate for a "," being regarded as a parameter separator.

Why go through all this trouble trying to convert the latter one to decimal separator "." instead of using the techniques of the original function?

Last edited:
I didn't understand the problem. Here in Australia 1,234.00 format is used but I just read [title] so I've now been enlightened.

I did create another batch file using the xe.com site. I found their rates more accurate or real world. But I couldn't work out how to present the results at the command prompt.

====================================
setdos /c~
iff "%1" EQ "" then
text

amount first currency1 currency2
for example
xe 1 usd aud
will open up the www site
[title]

endtext
quit
endiff
%@execstr[[title]]
setdos /c&

=====================================

It has come to our attention that this service is being used in violation of the Yahoo Terms of Service. As such, the service is being discontinued. For all future markets and equities data research, please refer to finance.yahoo.com

It has come to our attention that this service is being used in violation of the Yahoo Terms of Service. As such, the service is being discontinued. For all future markets and equities data research, please refer to finance.yahoo.com

Yeah, I noticed that last month, around the beginning of November. My solution;
Code:
``````::
:: Get the current exchange rate
::
setdos /X-5
setdos /X0
set LastLine=%@lines[clip:]
set USD2CAN=%@clip[%LastLine]
set USD=%@word[0,%USD2CAN]
set CAN=%@word[3,%USD2CAN]``````

This is part of a .BTM that I wrote, but can be used elsewhere.

Note that lynx is part of Cygwin.

Joe

You can use any flavor of lynx.
The important note is that this script destroys clipboard.

Yeah, I noticed that last month, around the beginning of November. My solution;
Code:
``````setdos /X-5
setdos /X0``````

Or without using lynx:
Code:
``type https://finance.google.com/finance/converter^?a=usd^&from=USD^&to=CAD | tpipe /simple=16 | tpipe /simple=10 > clip:``

@AnrDaemon: replace clip: with "%temp\randomfilename" if you want your clipboard preserved.

A (very) slight improvement, I think: combine the two filters in TPIPE and capture only the last line:
Code:
``type https://finance.google.com/finance/converter^?a=usd^&from=USD^&to=CAD | tpipe /simple=16 /simple=10 | tail /n1 > clip:``

This was caused by an outbound firewall rule. I'm surprised that it makes its way all the way back to TCC.
Code:
``````v:\> type https://finance.google.com
TCC: (Sys) An attempt was made to access a socket in a way forbidden by its access permissions.

I treid in FF going to the finance.google.com/.... site and got a 404 error. Seems one thing is to remove the "^" chars.....

I don't see 'already running' at all. Try it with in-process pipes ( |! instead of | ) and see what happens. If you don't see the 'already running' using in-process pipes, then it's probably the result of something in your TCSTART.BTM .
Code:
``````type https://finance.google.com/finance/converter^?a=aud^&from=AUD^&to=USD |! tpipe /simple=16 /simple=10 |! tail /n1
1 AUD = 0.7565 USD``````

Yes that's better.

That's better. Is there any way to read the results so I can do some calculations on them.

That's better. Is there any way to read the results so I can do some calculations on them.
For example:
Code:
``alias CONVERT2AUD=`type https://finance.google.com/finance/converter^^?a=aud^^&from=%2^^&to=AUD |! tpipe /simple=16 /simple=10 /tail=0,0,1 |! echo %1 %2 = %@eval[%@word[3,%@line[con:,0]] * %1=.2] AUD```

Last edited:

Many thanks. I get an idea what you did. I added it to my batch file.

Cheers
Phil
Code:
``````type https://finance.google.com/finance/converter^?a=aud^&from=%2^&to=%3 |! tpipe /simple=16 /simple=10 |! tail /n1
type https://finance.google.com/finance/converter^?a=aud^&from=%3^&to=%2 |! tpipe /simple=16 /simple=10 |! tail /n1

type https://finance.google.com/finance/converter^?a=aud^&from=%2^&to=%3 |! tpipe /simple=16 /simple=10 |! tail /n1   |! echo %1 %2 = %@eval[%@word[3,%@line[con:,0]] * %1] %3

pause .

setdos /c~

%@execstr[http://www.xe.com/currencyconverter/convert/?Amount=%1&From=%2&To=%3]
setdos /c&``````