Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to this project will be documented in this file.

## [3.1.0] - 2026-02-22

### Changed
- OHLC endpoint: renamed `setCurrency()` to `setQuote()` and request parameter from `currency` to `quote` to align with API response field names.

## [3.0.0] - 2026-02-19

### Added
Expand Down
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ RUN apk --no-cache add pcre-dev linux-headers ${PHPIZE_DEPS} \
&& apk del pcre-dev linux-headers ${PHPIZE_DEPS}

COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
COPY composer.json $APP_DIR/
COPY composer.json composer.lock $APP_DIR/
RUN composer install --no-interaction

RUN composer install
COPY . $APP_DIR/

CMD ["./vendor/bin/phpunit"]
17 changes: 10 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@
.PHONY: help
LOCAL_DOCKER_IMAGE=houseofapis/currencyapi-php
CONTAINER_NAME=currencyapi-php
WORKING_DIR=/application
WORKING_DIR=/app
PORT=7005
DOCKER_COMMAND=docker run --rm -v ${PWD}:${WORKING_DIR} -w ${WORKING_DIR} --name ${CONTAINER_NAME} -p ${PORT}:${PORT} -it ${LOCAL_DOCKER_IMAGE}
# Use official image so test/run work without building
DOCKER_IMAGE ?= composer:2
DOCKER_RUN = docker run --rm -v ${PWD}:${WORKING_DIR} -w ${WORKING_DIR} --name ${CONTAINER_NAME} -p ${PORT}:${PORT}
DOCKER_RUN_IT = docker run --rm -v ${PWD}:${WORKING_DIR} -w ${WORKING_DIR} --name ${CONTAINER_NAME} -p ${PORT}:${PORT} -it

build: ## Build docker image
docker build -t ${LOCAL_DOCKER_IMAGE} . --no-cache

test: ## Run the tests
${DOCKER_COMMAND} php -d xdebug.mode=coverage ./vendor/bin/phpunit --coverage-html build/logs/coverage.html
test: ## Run the tests (no build required)
${DOCKER_RUN} ${DOCKER_IMAGE} sh -c "composer install --no-interaction && ./vendor/bin/phpunit"

install: ## Composer install
${DOCKER_COMMAND} composer install
${DOCKER_RUN} ${DOCKER_IMAGE} composer install --no-interaction

run: ## Run test file
${DOCKER_COMMAND} php run.php
run: ## Run the run file (no build required)
${DOCKER_RUN_IT} ${DOCKER_IMAGE} sh -c "composer install --no-interaction && php run.php"

help:
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ Returns candlestick data for a currency pair on a given date, useful for chartin

```php
$result = $currencyApi
->setCurrency('EUR')
->setQuote('EUR')
->setDate('2023-12-25')
->ohlc();
```
Expand All @@ -205,7 +205,7 @@ Example with all available methods:

```php
$result = $currencyApi
->setCurrency('EUR')
->setQuote('EUR')
->setDate('2023-12-25')
->setBase('GBP')
->setInterval('1h')
Expand All @@ -216,7 +216,7 @@ $result = $currencyApi

| Methods | Description |
| --- | --- |
| `setCurrency()` | The currency to retrieve OHLC data for. Three letter ISO 4217 currency code. **Required**. |
| `setQuote()` | The quote currency to retrieve OHLC data for. Three letter ISO 4217 currency code. **Required**. |
| `setDate()` | The date to retrieve OHLC data for. This should be formatted as YYYY-MM-DD. **Required**. |
| `setBase()` | The base currency for the rates. **Default: USD**. |
| `setInterval()` | The interval for the OHLC candles. One of: `5m`, `15m`, `30m`, `1h`, `4h`, `12h`, `1d`. **Default: 1d**. |
Expand Down
16 changes: 8 additions & 8 deletions src/CurrencyApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ class CurrencyApi
protected $end_date = '';

/**
* The currency to retrieve OHLC data for.
* The quote currency to retrieve OHLC data for.
* This will be a three letter ISO 4217 currency code.
*
* @var string
*/
protected $currency = '';
protected $quote = '';

/**
* The interval for OHLC data.
Expand Down Expand Up @@ -231,15 +231,15 @@ public function setEndDate(string $end_date) : CurrencyApi
}

/**
* Sets the currency for the OHLC endpoint
* See currency property for description ^
* Sets the quote currency for the OHLC endpoint
* See quote property for description ^
*
* @param string $currency
* @param string $quote
* @return CurrencyApi
*/
public function setCurrency(string $currency) : CurrencyApi
public function setQuote(string $quote) : CurrencyApi
{
$this->currency = strtoupper($currency);
$this->quote = strtoupper($quote);
return $this;
}

Expand Down Expand Up @@ -374,7 +374,7 @@ protected function getTimeFrameParams() : array
protected function getOhlcParams() : array
{
$params = [
'currency' => $this->currency,
'quote' => $this->quote,
'date' => $this->date,
];
if ($this->base !== self::DEFAULT_BASE) {
Expand Down
20 changes: 10 additions & 10 deletions tests/CurrencyApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ public function testSetEndDate()
$this->assertEquals($date, $this->getProtectedProperty($this->currencyApi, 'end_date'));
}

public function testSetCurrency()
public function testSetQuote()
{
$currency = 'eur';
$this->assertEquals($this->currencyApi, $this->currencyApi->setCurrency($currency));
$this->assertEquals('EUR', $this->getProtectedProperty($this->currencyApi, 'currency'));
$quote = 'eur';
$this->assertEquals($this->currencyApi, $this->currencyApi->setQuote($quote));
$this->assertEquals('EUR', $this->getProtectedProperty($this->currencyApi, 'quote'));
}

public function testSetInterval()
Expand Down Expand Up @@ -186,30 +186,30 @@ public function testGetTimeFrameParams()

public function testGetOhlcParams()
{
$currency = 'EUR';
$quote = 'EUR';
$date = '2023-12-25';
$this->currencyApi->setCurrency($currency);
$this->currencyApi->setQuote($quote);
$this->currencyApi->setDate($date);
$invokedMethod = $this->invokeMethod($this->currencyApi, 'getOhlcParams');
$this->assertEquals([
'currency' => $currency,
'quote' => $quote,
'date' => $date,
], $invokedMethod);
}

public function testGetOhlcParamsWithBaseAndInterval()
{
$currency = 'EUR';
$quote = 'EUR';
$date = '2023-12-25';
$base = 'GBP';
$interval = '1h';
$this->currencyApi->setCurrency($currency);
$this->currencyApi->setQuote($quote);
$this->currencyApi->setDate($date);
$this->currencyApi->setBase($base);
$this->currencyApi->setInterval($interval);
$invokedMethod = $this->invokeMethod($this->currencyApi, 'getOhlcParams');
$this->assertEquals([
'currency' => $currency,
'quote' => $quote,
'date' => $date,
'base' => $base,
'interval' => $interval,
Expand Down