diff --git a/README.md b/README.md index 5daecc7..631d086 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/FixerAPI/Rates.php b/src/FixerAPI/Rates.php index d54669f..f5b4ed6 100644 --- a/src/FixerAPI/Rates.php +++ b/src/FixerAPI/Rates.php @@ -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); } - }