|
| 1 | +# Exchange Rates API Module |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +### Description |
| 6 | + |
| 7 | +The Exchange Rates API Module provides comprehensive integration with Exchangeratesapi.io service for currency exchange rate data. |
| 8 | + |
| 9 | +This module enables: |
| 10 | +- Retrieving current exchange rates for any supported currency |
| 11 | +- Accessing historical exchange rates for specific dates |
| 12 | +- Listing all available currency symbols and their names |
| 13 | +- Automatic caching of responses to improve performance and reduce API calls |
| 14 | +- LangChain tool integration for AI agent usage |
| 15 | + |
| 16 | +### Requirements |
| 17 | + |
| 18 | +API Key Setup: |
| 19 | +1. Obtain an API key from [Exchangeratesapi.io](https://exchangeratesapi.io/) |
| 20 | +2. Configure your `EXCHANGERATESAPI_API_KEY` in your environment |
| 21 | + |
| 22 | +### TL;DR |
| 23 | + |
| 24 | +To get started with the Exchange Rates API module: |
| 25 | + |
| 26 | +1. Obtain an API key from [Exchangeratesapi.io](https://exchangeratesapi.io/) |
| 27 | +2. Configure your `EXCHANGERATESAPI_API_KEY` in your environment |
| 28 | + |
| 29 | +Test the integration using: |
| 30 | +```bash |
| 31 | +uv run python -m pytest src/marketplace/modules/applications/exchangeratesapi/integrations/ExchangeratesapiIntegration_test.py |
| 32 | +``` |
| 33 | + |
| 34 | +### Structure |
| 35 | + |
| 36 | +``` |
| 37 | +src/marketplace/modules/applications/exchangeratesapi/ |
| 38 | +├── integrations/ |
| 39 | +│ ├── ExchangeratesapiIntegration.py # Main integration class |
| 40 | +│ └── ExchangeratesapiIntegration_test.py # Integration tests |
| 41 | +├── __init__.py # Module requirements check |
| 42 | +└── README.md # This documentation |
| 43 | +``` |
| 44 | + |
| 45 | +## Core Components |
| 46 | + |
| 47 | +The module provides a single, focused integration for accessing exchange rate data from Exchangeratesapi.io. |
| 48 | + |
| 49 | +### Integrations |
| 50 | + |
| 51 | +#### Exchange Rates API Integration |
| 52 | + |
| 53 | +The `ExchangeratesapiIntegration` class provides methods to interact with the Exchangeratesapi.io API endpoints, handling authentication and request management. |
| 54 | + |
| 55 | +**Core Functions:** |
| 56 | +- `list_symbols()`: Get all available currency symbols and names |
| 57 | +- `get_exchange_rates()`: Get exchange rates for a specific date and base currency |
| 58 | + |
| 59 | +##### Configuration |
| 60 | + |
| 61 | +```python |
| 62 | +from src.marketplace.modules.applications.exchangeratesapi.integrations.ExchangeratesapiIntegration import ( |
| 63 | + ExchangeratesapiIntegration, |
| 64 | + ExchangeratesapiIntegrationConfiguration |
| 65 | +) |
| 66 | + |
| 67 | +# Create configuration |
| 68 | +config = ExchangeratesapiIntegrationConfiguration( |
| 69 | + api_key="your_api_key_here" |
| 70 | +) |
| 71 | + |
| 72 | +# Initialize integration |
| 73 | +integration = ExchangeratesapiIntegration(config) |
| 74 | +``` |
| 75 | + |
| 76 | +##### Usage Examples |
| 77 | + |
| 78 | +**Get Current Exchange Rates:** |
| 79 | +```python |
| 80 | +# Get latest rates with EUR as base currency |
| 81 | +rates = integration.get_exchange_rates(date="latest", base="EUR") |
| 82 | + |
| 83 | +# Get rates for specific currencies |
| 84 | +rates = integration.get_exchange_rates( |
| 85 | + date="latest", |
| 86 | + base="USD", |
| 87 | + symbols=["EUR", "GBP", "JPY"] |
| 88 | +) |
| 89 | + |
| 90 | +# Get historical rates |
| 91 | +rates = integration.get_exchange_rates( |
| 92 | + date="2024-01-15", |
| 93 | + base="EUR" |
| 94 | +) |
| 95 | +``` |
| 96 | + |
| 97 | +**List Available Currencies:** |
| 98 | +```python |
| 99 | +# Get all available currency symbols |
| 100 | +symbols = integration.list_symbols() |
| 101 | +print(symbols["symbols"]) # Dictionary of currency codes and names |
| 102 | +``` |
| 103 | + |
| 104 | +**Using with LangChain Tools:** |
| 105 | +```python |
| 106 | +from src.marketplace.modules.applications.exchangeratesapi.integrations.ExchangeratesapiIntegration import as_tools |
| 107 | + |
| 108 | +# Convert integration to LangChain tools |
| 109 | +tools = as_tools(config) |
| 110 | + |
| 111 | +# The tools will be available as: |
| 112 | +# - exchangeratesapi_get_exchange_rates |
| 113 | +# - exchangeratesapi_list_symbols |
| 114 | +``` |
| 115 | + |
| 116 | +#### Testing |
| 117 | + |
| 118 | +Run the integration tests to verify functionality: |
| 119 | +```bash |
| 120 | +uv run python -m pytest src/marketplace/modules/applications/exchangeratesapi/integrations/ExchangeratesapiIntegration_test.py |
| 121 | +``` |
| 122 | + |
| 123 | +**Test Coverage:** |
| 124 | +- `test_list_symbols`: Verifies currency symbol retrieval |
| 125 | +- `test_get_exchange_rates`: Tests exchange rate fetching with specific parameters |
| 126 | + |
| 127 | +## API Endpoints |
| 128 | + |
| 129 | +The module supports the following Exchangeratesapi.io endpoints: |
| 130 | + |
| 131 | +- **GET /symbols**: List all available currencies |
| 132 | +- **GET /{date}**: Get exchange rates for a specific date (use "latest" for current rates) |
| 133 | + |
| 134 | +### Supported Parameters |
| 135 | + |
| 136 | +**get_exchange_rates():** |
| 137 | +- `date` (str): Date in YYYY-MM-DD format or "latest" for current rates |
| 138 | +- `base` (str): Base currency code (default: "EUR") |
| 139 | +- `symbols` (list[str]): List of target currency codes (default: all symbols) |
| 140 | + |
| 141 | +**list_symbols():** |
| 142 | +- No parameters required |
| 143 | + |
| 144 | +## Caching |
| 145 | + |
| 146 | +The module implements intelligent caching using the ABI cache framework to: |
| 147 | +- Reduce API calls and improve performance |
| 148 | +- Cache responses based on request parameters |
| 149 | +- Store data in JSON format for easy access |
| 150 | + |
| 151 | +**Cache Keys:** |
| 152 | +- Exchange rates: `get_exchange_rates_{date}_{base}_{symbols}` |
| 153 | +- Symbols: `list_symbols` |
| 154 | + |
| 155 | +## Error Handling |
| 156 | + |
| 157 | +The module includes comprehensive error handling: |
| 158 | +- Network connection errors |
| 159 | +- API authentication failures |
| 160 | +- Invalid request parameters |
| 161 | +- Rate limiting responses |
| 162 | + |
| 163 | +All errors are wrapped in `IntegrationConnectionError` for consistent error handling across the application. |
| 164 | + |
| 165 | +## Rate Limits |
| 166 | + |
| 167 | +Please refer to your Exchangeratesapi.io subscription plan for rate limits: |
| 168 | +- **Free tier**: 100 requests per month |
| 169 | +- **Paid plans**: Higher limits and additional features |
| 170 | + |
| 171 | +The caching mechanism helps minimize API calls and stay within rate limits. |
| 172 | + |
| 173 | +## Dependencies |
| 174 | + |
| 175 | +### Python Libraries |
| 176 | +- `abi.integration`: Base integration framework |
| 177 | +- `abi.services.cache`: Caching functionality |
| 178 | +- `langchain_core`: Tool integration for AI agents |
| 179 | +- `pydantic`: Data validation and serialization |
| 180 | +- `requests`: HTTP client for API calls |
| 181 | + |
| 182 | +### External Services |
| 183 | +- **Exchangeratesapi.io**: Currency exchange rate data provider |
| 184 | + |
| 185 | +## Module Requirements |
| 186 | + |
| 187 | +The module includes a requirements check in `__init__.py` that verifies the presence of `EXCHANGERATESAPI_API_KEY` in the environment. This ensures proper configuration before the module can be used. |
0 commit comments