This topic is locked

Help needed to pull given dates foreign exchange rates

9/27/2017 12:09:20 AM
PHPRunner General questions
A
Abhijeet author

Dear Team,
Greetings !
I have a requirement to pull foreign exchange rate from the potential site. I managed to get a php code which is as belows.



<?php

/**

* Live currency exchange script.

* This script allows you to retrieve the current currency exchanges, live, from the internet.

*

* This script is developed by Tim Visee, for educational purposes.

* The Yahoo currency exchange API is used to retrieve the live exchange rates.

*

* ---

*

* Script usage:

* To retrieve the current currency exchange rates for two currencies, simply make a request to this script with the

* parameters that are described bellow.

*

* Script parameters:

* - from: Three letter code for base currency.

* - to: Three letter code for target currency.

*

* For example, to get the exchange rate for EUR to USD, use the following parameters:

* index.php?from=EUR&to=USD

* The currency exchange rate is returned as a numerical value, with a dot as decimal delimiter.

*

* The string 'ERROR' is returned if an error occurred. For example, if the current exchange rate couldn't be retrieved,

* or if the three letter currency code is invalid.

*

* ---

*

* @author Tim Visee

* @website http://timvisee.com/

* @copyright Copyright (c) Tim Visee 2015. All rights reserved.

*/

// Disable all PHP errors

error_reporting(0);

ini_set('display_errors', 0);

/**

* Show an error, and stop the script.

*/

function showError() {

die('ERROR');

}

// Make sure the currencies are set

if(!isset($_GET['from']) || !isset($_GET['from']))

showError();

// Get the currencies to convert

$from = trim(strtoupper($_GET['from']));

$to = trim(strtoupper($_GET['to']));

// Make sure both currency identifiers are three characters long

if(strlen($from) != 3 || strlen($to) != 3)

showError();

// Create the conversion string

$conversionString = $from . $to;

// Do the whole exchange rate retrieval process in a try-catch block to handle possible errors

try {

// Get the current exchange

$url = "http://query.yahooapis.com/v1/public/yql?env=store://datatables.org/alltableswithkeys&q=SELECT%20*%20FROM%20yahoo.finance.xchange%20WHERE%20pair%20IN%20%28%22"; . $conversionString . "%22%29";

$ch = curl_init();

curl_setopt($ch,CURLOPT_URL, $url);

curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 4);

$xml = curl_exec($ch);

// Parse the XML data

$xmlData = new SimpleXMLElement($xml);

// Make sure the rate is set

if(!isset($xmlData->results->rate->Rate))

showError();

// Get and parse the exchange rate as a float

$exchangeRate = floatval($xmlData->results->rate->Rate);

// Echo the actual exchange rate

echo $exchangeRate;

} catch(Exception $e) {

// Show an error page

showError();

}


I am on phprunner 9.7 on windows 7 sp1 with xampp control panel v3.2.2 php version 5.6.30.
I have 2 questions:-

  1. when I put a date in first column and select currency pair, I need to fetch the exchange rate from internet into initial exchange rate column based on the date given in this first column, I believe above code is one of the means to retrieve rate, I am not yet sure, if that is the code required, if otherwise, please suggest.
  2. The third column is of system date in phprunner, the phprunner should retrieve the system date exchange rate based on the date given and pair already selected in the fourth column named todays foreign exchange rate column, the system date column will be read only. So the system will have initial foreign exchange rate and todays foreign exchange rate in a single record with 2 dates.
    I am also licensed holder of phprunner 9.8.
    Team, please help me achieve this scenario, I am a complete noob in php, if any changes or procedure is required, please let me know the detailed procedure and column names required. I will appreciate if the exchange rate comes automatically after putting date and exchange rate pair in the 2 dates columns.
    Your knowledge/ support/ patience is highly appreciated.
    Kind Regards.

A
Abhijeet author 10/1/2017



Dear Team,
Greetings !
I have a requirement to pull foreign exchange rate from the potential site. I managed to get a php code which is as belows.



<?php

/**

* Live currency exchange script.

* This script allows you to retrieve the current currency exchanges, live, from the internet.

*

* This script is developed by Tim Visee, for educational purposes.

* The Yahoo currency exchange API is used to retrieve the live exchange rates.

*

* ---

*

* Script usage:

* To retrieve the current currency exchange rates for two currencies, simply make a request to this script with the

* parameters that are described bellow.

*

* Script parameters:

* - from: Three letter code for base currency.

* - to: Three letter code for target currency.

*

* For example, to get the exchange rate for EUR to USD, use the following parameters:

* index.php?from=EUR&to=USD

* The currency exchange rate is returned as a numerical value, with a dot as decimal delimiter.

*

* The string 'ERROR' is returned if an error occurred. For example, if the current exchange rate couldn't be retrieved,

* or if the three letter currency code is invalid.

*

* ---

*

* @author Tim Visee

* @website http://timvisee.com/

* @copyright Copyright (c) Tim Visee 2015. All rights reserved.

*/

// Disable all PHP errors

error_reporting(0);

ini_set('display_errors', 0);

/**

* Show an error, and stop the script.

*/

function showError() {

die('ERROR');

}

// Make sure the currencies are set

if(!isset($_GET['from']) || !isset($_GET['from']))

showError();

// Get the currencies to convert

$from = trim(strtoupper($_GET['from']));

$to = trim(strtoupper($_GET['to']));

// Make sure both currency identifiers are three characters long

if(strlen($from) != 3 || strlen($to) != 3)

showError();

// Create the conversion string

$conversionString = $from . $to;

// Do the whole exchange rate retrieval process in a try-catch block to handle possible errors

try {

// Get the current exchange

$url = "http://query.yahooapis.com/v1/public/yql?env=store://datatables.org/alltableswithkeys&q=SELECT%20*%20FROM%20yahoo.finance.xchange%20WHERE%20pair%20IN%20%28%22"; . $conversionString . "%22%29";

$ch = curl_init();

curl_setopt($ch,CURLOPT_URL, $url);

curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 4);

$xml = curl_exec($ch);

// Parse the XML data

$xmlData = new SimpleXMLElement($xml);

// Make sure the rate is set

if(!isset($xmlData->results->rate->Rate))

showError();

// Get and parse the exchange rate as a float

$exchangeRate = floatval($xmlData->results->rate->Rate);

// Echo the actual exchange rate

echo $exchangeRate;

} catch(Exception $e) {

// Show an error page

showError();

}


I am on phprunner 9.7 on windows 7 sp1 with xampp control panel v3.2.2 php version 5.6.30.
I have 2 questions:-

  1. when I put a date in first column and select currency pair, I need to fetch the exchange rate from internet into initial exchange rate column based on the date given in this first column, I believe above code is one of the means to retrieve rate, I am not yet sure, if that is the code required, if otherwise, please suggest.
  2. The third column is of system date in phprunner, the phprunner should retrieve the system date exchange rate based on the date given and pair already selected in the fourth column named todays foreign exchange rate column, the system date column will be read only. So the system will have initial foreign exchange rate and todays foreign exchange rate in a single record with 2 dates.
    I am also licensed holder of phprunner 9.8.
    Team, please help me achieve this scenario, I am a complete noob in php, if any changes or procedure is required, please let me know the detailed procedure and column names required. I will appreciate if the exchange rate comes automatically after putting date and exchange rate pair in the 2 dates columns.
    Your knowledge/ support/ patience is highly appreciated.
    Kind Regards.


I appeal to the experts, please help me in this post. Thank you in advance.

HJB 10/1/2017

https://stackoverflow.com/questions/28918968/how-to-get-historical-data-for-currency-exchange-rates-via-yahoo-finance
... for inspiration purposes only ..., CURL method as per your example won't help as you want to see TWO results of different dates in a record.

A
Abhijeet author 10/1/2017



https://stackoverflow.com/questions/28918968/how-to-get-historical-data-for-currency-exchange-rates-via-yahoo-finance
... for inspiration purposes only ..., CURL method as per your example won't help as you want to see TWO results of different dates in a record.


Hi Walk2Fly,
Thank you for your response, but these are 2 different methods, when I insert the record then the FX rate should come in first rate column based on the inserted FX pair, and the second rate column is live and only applicable for view page and will come from todays system date column i.e may be now(), I hope I have made it easy.

HJB 10/2/2017



Hi Walk2Fly,
Thank you for your response, but these are 2 different methods, when I insert the record then the FX rate should come in first rate column based on the inserted FX pair, and the second rate column is live and only applicable for view page and will come from todays system date column i.e may be now(), I hope I have made it easy.


https://xlinesoft.com/phprunner/docs/choose_fields.htm
...it's definitely up to you to set the fields (date, currency abbreviation, decimal value) first the way you wish to see them. After it you need to "inject" data, either manually or by Yahoo code snippet as rendered. If then, once all is done, you need fields to only appear within VIEW page, you simply use "columns devices" table to click per field of what is going to be seen as per URL specified (out of the manual). I fear, there is definitely no ready-made code snippet available on the web which solves your individual task.