Skip to content

Commit

Permalink
Add Fluctuation Endpoint support
Browse files Browse the repository at this point in the history
  • Loading branch information
infiniweb committed Jun 3, 2018
1 parent 3bc635d commit daa1bb7
Showing 2 changed files with 75 additions and 4 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -108,6 +108,36 @@ You can get daily rates from a starting end an end date, using:
...


### Fluctuations

The parameters to retrieve the fluctuations are exactly the same then the time-series rates.

$return = $fixer->rates->getDailyFluctuation("2018-05-01", "2018-05-03", $baseCurrency, $symbols);

You will then get the daily flactuations for each currencies from the start to end date:

Array
(
[base] => EUR
[rates] => Array
(
[USD] => stdClass Object
(
[start_rate] => 1.199468
[end_rate] => 1.199326
[change] => -0.0001
[change_pct] => -0.0118
)
[GBP] => stdClass Object
(
[start_rate] => 0.881297
[end_rate] => 0.883748
[change] => 0.0025
[change_pct] => 0.2781
)
)
)

### Convert

You can request the conversion from a currency to another. If you provide a date, it will return an historical rate.
49 changes: 45 additions & 4 deletions src/FixerAPI/Rates.php
Original file line number Diff line number Diff line change
@@ -37,7 +37,15 @@ public function get($baseCurrency = null, $symbols = [], $date = null)
return array('timestamp' => $response->timestamp, 'base' => $response->base, 'rates' => (array)$response->rates);
}

public function prepareData($baseCurrency = null, $symbols = [], $startDate = null, $endDate = null)
/**
* Prepare rates options
* @param string|null $baseCurrency the three-letter currency code of the base currency.
* @param array $symbols list of comma-separated currency codes to limit output currencies.
* @param string|null $startDate the series start date
* @param string|null $endDate the series end date
* @return array
*/
private function prepareData($baseCurrency, $symbols, $startDate = null, $endDate = null)
{
$data = array();

@@ -60,11 +68,45 @@ public function prepareData($baseCurrency = null, $symbols = [], $startDate = nu
return $data;
}

/**
* Get Time-series daily rates
* @param string $startDate the series start date
* @param string $endDate the series end date
* @param string|null $baseCurrency the three-letter currency code of the base currency.
* @param array $symbols list of comma-separated currency codes to limit output currencies.
* @return array
*/
public function getDailyRates($startDate, $endDate, $baseCurrency = null, $symbols = [])
{
$data = $this->prepareData($baseCurrency, $symbols, $startDate, $endDate);

$endPoint = "timeseries";
return $this->getSeries($endPoint, $startDate, $endDate, $baseCurrency, $symbols);
}

/**
* Get daily fluctuation rates
* @param string $startDate the series start date
* @param string $endDate the series end date
* @param string|null $baseCurrency the three-letter currency code of the base currency.
* @param array $symbols list of comma-separated currency codes to limit output currencies.
* @return array
*/
public function getDailyFluctuation($startDate, $endDate, $baseCurrency = null, $symbols = [])
{
$endPoint = "fluctuation";
return $this->getSeries($endPoint, $startDate, $endDate, $baseCurrency, $symbols);
}

/**
* Prepare and get series request
* @param string $startDate the series start date
* @param string $endDate the series end date
* @param string|null $baseCurrency the three-letter currency code of the base currency.
* @param array $symbols list of comma-separated currency codes to limit output currencies.
* @return array
*/
private function getSeries($endPoint, $startDate, $endDate, $baseCurrency, $symbols)
{
$data = $this->prepareData($baseCurrency, $symbols, $startDate, $endDate);

$response = $this->fixer->getResponse($endPoint, $data);

@@ -74,5 +116,4 @@ public function getDailyRates($startDate, $endDate, $baseCurrency = null, $symbo

return array('base' => $response->base, 'rates' => (array)$response->rates);
}

}

0 comments on commit daa1bb7

Please sign in to comment.