1

I need Yahoo API, which will return exchange rates of all country on country based I pass.

For example I will pass USD as a base, then Yahoo API should return me exchange rates of all other countries.

I have search on google I find following Yahoo API

http://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange
       where pair in ( "USDEUR", "USDJPY", "USDBGN", "USDCZK",
                       "USDDKK", "USDGBP", "USDHUF", "USDLTL",
                       "USDLVL", "USDPLN", "USDRON", "USDSEK",
                       "USDCHF", "USDNOK", "USDHRK", "USDRUB",
                       "USDTRY", "USDAUD", "USDBRL", "USDCAD",
                       "USDCNY", "USDHKD", "USDIDR", "USDILS",
                       "USDINR", "USDKRW", "USDMXN", "USDMYR",
                       "USDNZD", "USDPHP", "USDSGD", "USDTHB",
                       "USDZAR", "USDISK"
                       )&env=store://datatables.org/alltableswithkeys

In this API I have to write one by one currency pairs for each country.

I don't want to write currency pairs one by one.

I want to pass USD and return me all the exchange rates for all the other countries.

Please send me Yahoo API Querystring which fit my requirement.

user3666197
  • 1
  • 6
  • 50
  • 92
Kirti Zare
  • 719
  • 1
  • 12
  • 35
  • Possible duplicate of [How do I get currency exchange rates via an API such as Google Finance?](http://stackoverflow.com/q/3139879/10263) – Brian Rogers Apr 11 '17 at 22:38

1 Answers1

0

The simplest way is to prepare a static convertor, responsible for returning the pre-assembled list, that will return ( send you ) the Yahoo API Querystring.

A trivial mock-up example is:

string sendMeTheYahooApiQuerySTRING(  const string aCurrency1 = "USD",
                                            bool  &ErrorFLAG  = True
                                      ){
       switch( aCurrency1 ){
         case "USD":   ErrorFLAG = False; return( "https://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange where pair in ( "USDEUR", "USDJPY", "USDBGN", "USDCZK", "USDDKK", "USDGBP", "USDHUF", "USDLTL", "USDLVL", "USDPLN", "USDRON", "USDSEK", "USDCHF", "USDNOK", "USDHRK", "USDRUB", "USDTRY", "USDAUD", "USDBRL", "USDCAD", "USDCNY", "USDHKD", "USDIDR", "USDILS", "USDINR", "USDKRW", "USDMXN", "USDMYR", "USDNZD", "USDPHP", "USDSGD", "USDTHB", "USDZAR", "USDISK" )&env=store://datatables.org/alltableswithkeys" );
         case "GBP":   ErrorFLAG = False; return( "https://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange where pair in ( "GBPEUR", "GBPJPY", "GBPBGN", "GBPCZK", "GBPDKK", "USDGBP", ...  )&env=store://datatables.org/alltableswithkeys" );
         case "JPY":   ErrorFLAG = False; return( "https://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange where pair in ( "GBPJPY", "JPYBGN", ...  )&env=store://datatables.org/alltableswithkeys" );
         case  ... :   ErrorFLAG = False; return( ... );
         case default:                    return( "" );
       }

designed so as to use it later in:

 bool   anErrorFLAG  = False;
 ...
 string aQuerySTRING = sendMeTheYahooApiQuerySTRING( "DKK", anErrorFLAG );
 assert( !anErrorFLAG );
 ...

This approach relies on Y! side processing, as detailed in API specification:

       <execute>
                var pairs = [];

                for each (var p in pair.toString().replace(/\s+/g,'').split(','))
                    pairs.push(p.toUpperCase() + '=X');

                var q = "select * from csv where url='http://download.finance.yahoo.com/d/quotes.csv?s="+ pairs.join(',') +
                    "&f=snl1d1t1ab'" + " and columns='Symbol,Name,Rate,Date,Time,Ask,Bid'",
                    results = y.query(q),
                    rates = <rates/>,
                    rows=results.results.row;

                for each (var row in rows) {
                    for each (var item in row.*) 
                        row[item.localName()]=item.text().toString().replace(/"/g, '');

                    var tag = row.Symbol.text().toString().substr(0,6);
                    delete row.Symbol;
                    rates.rate += <rate id={tag}>{row.*}</rate>;
                }
                response.object = rates;
                </execute>

Another way would be to build a set of direct access-iterators that re-use Y! direct access query syntax for returning a single csv-record for each respective currency pair, without Y! side aggregation of results into a common container:

 http://download.finance.yahoo.com/d/quotes.csv?s=GBPJPY=X&f=snl1

which retuns as simple data as:

 "GBPJPY=X","GBP/JPY",146.7220

without the Y! side re-packaging of the individual exchange rates.

user3666197
  • 1
  • 6
  • 50
  • 92