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.

## [2.1.0] - 2026-02-22

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

## [2.0.0] - 2026-02-19

### Added
Expand Down
26 changes: 14 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,33 @@ LOCAL_DOCKER_IMAGE=houseofapis/currencyapi-python
CONTAINER_NAME=currencyapi-python
WORKING_DIR=/app
PORT=7004
DOCKER_COMMAND=docker run --rm -v ${PWD}:${WORKING_DIR} -w ${WORKING_DIR} --name ${CONTAINER_NAME} -p ${PORT}:${PORT} ${LOCAL_DOCKER_IMAGE}
DOCKER_COMMAND_INTERACTIVE=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 ?= python:3.12-slim
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-image: ## Build docker image
docker build -t ${LOCAL_DOCKER_IMAGE} .

test: ## Run the tests
${DOCKER_COMMAND} python -m coverage run -m unittest discover
test: ## Run the tests (no build required)
${DOCKER_RUN} ${DOCKER_IMAGE} sh -c "pip install -q -e . coverage && python -m coverage run -m unittest discover"

run: ## Run the sample testing file
${DOCKER_COMMAND} python run.py
run: ## Run the run file (no build required)
${DOCKER_RUN} ${DOCKER_IMAGE} sh -c "pip install -q -e . && python run.py"

test-coverage: ## Show test coverage
${DOCKER_COMMAND} python -m coverage report
test-coverage: ## Show test coverage (no build required)
${DOCKER_RUN} ${DOCKER_IMAGE} sh -c "pip install -q -e . coverage && python -m coverage run -m unittest discover && python -m coverage report"

setup: ## Setup
${DOCKER_COMMAND} python setup.py install
${DOCKER_RUN} ${DOCKER_IMAGE} pip install -e .

exec: ## Run test file
${DOCKER_COMMAND_INTERACTIVE} sh
exec: ## Shell into container
${DOCKER_RUN_IT} ${DOCKER_IMAGE} sh

build-package: ## Build pip package
${DOCKER_COMMAND} python setup.py sdist bdist_wheel

upload-package: ## Upload pip package
upload-package: ## Upload pip package (requires build-image first)
docker run --rm -v ${PWD}:${WORKING_DIR} -v ${HOME}/.pypirc:/root/.pypirc -w ${WORKING_DIR} --name ${CONTAINER_NAME} -p ${PORT}:${PORT} ${LOCAL_DOCKER_IMAGE} python -m twine upload dist/*

help:
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,23 @@ Returns OHLC (Open, High, Low, Close) data for a currency pair on a specific dat

| Parameter | Required | Description |
|------------|----------|-------------|
| `currency` | Yes | Target currency code (e.g. `EUR`, `GBP`, `BTC`) |
| `quote` | Yes | Quote currency code (e.g. `EUR`, `GBP`, `BTC`) |
| `date` | Yes | Date in `YYYY-MM-DD` format (must be in the past) |
| `base` | No | Base currency code (defaults to `USD`) |
| `interval` | No | Time interval: `5m`, `15m`, `30m`, `1h`, `4h`, `12h`, `1d` (defaults to `1d`) |

```python
# Basic request (1-day interval)
result = currency.ohlc().currency('EUR').date('2023-12-25').get()
result = currency.ohlc().quote('EUR').date('2023-12-25').get()

# With custom interval
result = currency.ohlc().currency('GBP').date('2023-12-25').interval('1h').get()
result = currency.ohlc().quote('GBP').date('2023-12-25').interval('1h').get()

# With custom base currency and interval
result = currency.ohlc().currency('JPY').date('2023-12-25').base('EUR').interval('4h').get()
result = currency.ohlc().quote('JPY').date('2023-12-25').base('EUR').interval('4h').get()

# XML output
result = currency.ohlc().currency('EUR').date('2023-12-25').output('XML').get()
result = currency.ohlc().quote('EUR').date('2023-12-25').output('XML').get()
```

**Example response:**
Expand Down
4 changes: 2 additions & 2 deletions currencyapinet/endpoints/ohlc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class Ohlc(Endpoint):
def __init__(self, api_key: str):
super().__init__(api_key, OHLC_ENDPOINT)

def currency(self, currency: str):
self.add_param('currency', currency.upper())
def quote(self, quote: str):
self.add_param('quote', quote.upper())
return self

def date(self, date: str):
Expand Down
14 changes: 7 additions & 7 deletions tests/endpoints/test_ohlc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ class Test(TestCase):
def setUp(self):
self.class_under_test = Ohlc('fakekey')

def test_ohlc_currency(self):
self.class_under_test.currency('eUr')
self.assertEqual('EUR', self.class_under_test.param.get('currency'))
self.assertIsInstance(self.class_under_test.currency('EUR'), Ohlc)
def test_ohlc_quote(self):
self.class_under_test.quote('eUr')
self.assertEqual('EUR', self.class_under_test.param.get('quote'))
self.assertIsInstance(self.class_under_test.quote('EUR'), Ohlc)

def test_ohlc_date(self):
self.class_under_test.date('2023-12-25')
Expand All @@ -36,16 +36,16 @@ def test_ohlc__build_url_params(self):
{'key': 'fakekey', 'output': 'JSON'},
self.class_under_test._build_url_params()
)
self.class_under_test.currency('EUR')
self.class_under_test.quote('EUR')
self.class_under_test.date('2023-12-25')
self.assertDictEqual(
{'key': 'fakekey', 'output': 'JSON', 'currency': 'EUR', 'date': '2023-12-25'},
{'key': 'fakekey', 'output': 'JSON', 'quote': 'EUR', 'date': '2023-12-25'},
self.class_under_test._build_url_params()
)
self.class_under_test.base('gbP')
self.class_under_test.interval('1h')
self.assertDictEqual(
{'key': 'fakekey', 'output': 'JSON', 'currency': 'EUR', 'date': '2023-12-25', 'base': 'GBP', 'interval': '1h'},
{'key': 'fakekey', 'output': 'JSON', 'quote': 'EUR', 'date': '2023-12-25', 'base': 'GBP', 'interval': '1h'},
self.class_under_test._build_url_params()
)

Expand Down