|
| 1 | +# forexrateapi |
| 2 | + |
| 3 | +forexrateapi is the official Java wrapper for ForexRateAPI.com. This allows you to quickly integrate our foreign exchange rate API and currency conversion API into your application. Check https://forexrateapi.com documentation for more information. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +### Maven |
| 8 | + |
| 9 | +Add the following dependency to your `pom.xml`: |
| 10 | + |
| 11 | +```xml |
| 12 | +<dependency> |
| 13 | + <groupId>io.github.forexrateapi</groupId> |
| 14 | + <artifactId>forexrateapi</artifactId> |
| 15 | + <version>1.3.0</version> |
| 16 | +</dependency> |
| 17 | +``` |
| 18 | + |
| 19 | +### Gradle |
| 20 | + |
| 21 | +Add the following to your `build.gradle`: |
| 22 | + |
| 23 | +```groovy |
| 24 | +implementation 'io.github.forexrateapi:forexrateapi:1.3.0' |
| 25 | +``` |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```java |
| 30 | +import io.github.forexrateapi.client.ForexRateApiClient; |
| 31 | + |
| 32 | +String apiKey = "SET_YOUR_API_KEY_HERE"; |
| 33 | +ForexRateApiClient client = new ForexRateApiClient(apiKey); |
| 34 | + |
| 35 | +// Or use EU server: |
| 36 | +// ForexRateApiClient client = new ForexRateApiClient(apiKey, "eu"); |
| 37 | +``` |
| 38 | +--- |
| 39 | +## Server Regions |
| 40 | + |
| 41 | +ForexRateAPI provides two regional endpoints. Choose the one closest to your servers for optimal performance. |
| 42 | + |
| 43 | +| Region | Base URL | |
| 44 | +|--------|----------| |
| 45 | +| United States (default) | `https://api.forexrateapi.com/v1` | |
| 46 | +| Europe | `https://api-eu.forexrateapi.com/v1` | |
| 47 | + |
| 48 | +```java |
| 49 | +import io.github.forexrateapi.client.ForexRateApiClient; |
| 50 | + |
| 51 | +// Default (US) |
| 52 | +ForexRateApiClient client = new ForexRateApiClient("SET_YOUR_API_KEY_HERE"); |
| 53 | + |
| 54 | +// Europe |
| 55 | +ForexRateApiClient client = new ForexRateApiClient("SET_YOUR_API_KEY_HERE", "eu"); |
| 56 | +``` |
| 57 | + |
| 58 | +--- |
| 59 | +## Documentation |
| 60 | + |
| 61 | +#### fetchSymbols() |
| 62 | +```java |
| 63 | +client.fetchSymbols(); |
| 64 | +``` |
| 65 | + |
| 66 | +[Link](https://forexrateapi.com/documentation#api_symbol) |
| 67 | + |
| 68 | +--- |
| 69 | +#### setServer(server) |
| 70 | + |
| 71 | +- `server` <[string]> Pass `"eu"` to use the EU server (`api-eu.forexrateapi.com`), or `"us"` for the US server. Defaults to US if not specified. |
| 72 | + |
| 73 | +```java |
| 74 | +client.setServer("eu"); |
| 75 | +``` |
| 76 | + |
| 77 | +--- |
| 78 | +#### fetchLive(base, currencies, math) |
| 79 | + |
| 80 | +- `base` <[string]> Optional. Pass in a base currency, defaults to USD. |
| 81 | +- `currencies` <[List]<[string]>> Optional. Pass in a list of currencies to return values for. |
| 82 | +- `math` <[string]> Optional. Pass in a math expression to apply to the rates. |
| 83 | + |
| 84 | +```java |
| 85 | +client.fetchLive("USD", List.of("AUD", "CAD", "GBP", "JPY"), ""); |
| 86 | +``` |
| 87 | + |
| 88 | +[Link](https://forexrateapi.com/documentation#api_realtime) |
| 89 | + |
| 90 | +--- |
| 91 | +#### fetchHistorical(date, base, currencies) |
| 92 | + |
| 93 | +- `date` <[string]> Required. Pass in a string with format `YYYY-MM-DD` |
| 94 | +- `base` <[string]> Optional. Pass in a base currency, defaults to USD. |
| 95 | +- `currencies` <[List]<[string]>> Optional. Pass in a list of currencies to return values for. |
| 96 | + |
| 97 | +```java |
| 98 | +client.fetchHistorical("2024-02-05", "USD", List.of("AUD", "CAD", "GBP", "JPY")); |
| 99 | +``` |
| 100 | + |
| 101 | +[Link](https://forexrateapi.com/documentation#api_historical) |
| 102 | + |
| 103 | +--- |
| 104 | +#### hourly(base, currency, startDate, endDate, math, dateType) |
| 105 | + |
| 106 | +- `base` <[string]> Optional. Pass in a base currency, defaults to USD. |
| 107 | +- `currency` <[string]> Required. Specify currency you would like to get hourly rates for. |
| 108 | +- `startDate` <[string]> Required. Specify the start date using the format `YYYY-MM-DD`. |
| 109 | +- `endDate` <[string]> Required. Specify the end date using the format `YYYY-MM-DD`. |
| 110 | +- `math` <[string]> Optional. Pass in a math expression to apply to the rates. |
| 111 | +- `dateType` <[string]> Optional. Pass in a date type, overrides date parameters if passed in. |
| 112 | + |
| 113 | +```java |
| 114 | +client.hourly("USD", "EUR", "2024-02-05", "2024-02-05", "", ""); |
| 115 | +``` |
| 116 | + |
| 117 | +[Link](https://forexrateapi.com/documentation#api_hourly) |
| 118 | + |
| 119 | +--- |
| 120 | +#### fetchOHLC(base, currency, date, dateType) |
| 121 | + |
| 122 | +- `base` <[string]> Optional. Pass in a base currency, defaults to USD. |
| 123 | +- `currency` <[string]> Required. Specify currency you would like to get OHLC for. |
| 124 | +- `date` <[string]> Required. Specify date to get OHLC for specific date using format `YYYY-MM-DD`. |
| 125 | +- `dateType` <[string]> Optional. Pass in a date type, overrides date parameter if passed in. |
| 126 | + |
| 127 | +```java |
| 128 | +client.fetchOHLC("USD", "EUR", "2024-02-05", ""); |
| 129 | +``` |
| 130 | + |
| 131 | +[Link](https://forexrateapi.com/documentation#api_ohlc) |
| 132 | + |
| 133 | +--- |
| 134 | +#### convert(fromCurrency, toCurrency, amount, date) |
| 135 | + |
| 136 | +- `fromCurrency` <[string]> Optional. Pass in a base currency, defaults to USD. |
| 137 | +- `toCurrency` <[string]> Required. Specify currency you would like to convert to. |
| 138 | +- `amount` <[number]> Required. The amount to convert. |
| 139 | +- `date` <[string]> Optional. Specify date to use historical midpoint value for conversion with format `YYYY-MM-DD`. Otherwise, it will use live exchange rate date if value not passed in. |
| 140 | + |
| 141 | +```java |
| 142 | +client.convert("USD", "EUR", 100, "2024-02-05"); |
| 143 | +``` |
| 144 | + |
| 145 | +[Link](https://forexrateapi.com/documentation#api_convert) |
| 146 | + |
| 147 | +--- |
| 148 | +#### timeframe(startDate, endDate, base, currencies) |
| 149 | + |
| 150 | +- `startDate` <[string]> Required. Specify the start date of your timeframe using the format `YYYY-MM-DD`. |
| 151 | +- `endDate` <[string]> Required. Specify the end date of your timeframe using the format `YYYY-MM-DD`. |
| 152 | +- `base` <[string]> Optional. Pass in a base currency, defaults to USD. |
| 153 | +- `currencies` <[List]<[string]>> Optional. Pass in a list of currencies to return values for. |
| 154 | + |
| 155 | +```java |
| 156 | +client.timeframe("2024-02-05", "2024-02-06", "USD", List.of("AUD", "CAD", "GBP", "JPY")); |
| 157 | +``` |
| 158 | + |
| 159 | +[Link](https://forexrateapi.com/documentation#api_timeframe) |
| 160 | + |
| 161 | +--- |
| 162 | +#### change(startDate, endDate, base, currencies, dateType) |
| 163 | + |
| 164 | +- `startDate` <[string]> Required. Specify the start date of your timeframe using the format `YYYY-MM-DD`. |
| 165 | +- `endDate` <[string]> Required. Specify the end date of your timeframe using the format `YYYY-MM-DD`. |
| 166 | +- `base` <[string]> Optional. Pass in a base currency, defaults to USD. |
| 167 | +- `currencies` <[List]<[string]>> Optional. Pass in a list of currencies to return values for. |
| 168 | +- `dateType` <[string]> Optional. Pass in a date type, overrides date parameters if passed in. |
| 169 | + |
| 170 | +```java |
| 171 | +client.change("2024-02-05", "2024-02-06", "USD", List.of("AUD", "CAD", "GBP", "JPY"), ""); |
| 172 | +``` |
| 173 | + |
| 174 | +[Link](https://forexrateapi.com/documentation#api_change) |
| 175 | + |
| 176 | +--- |
| 177 | +#### usage() |
| 178 | +```java |
| 179 | +client.usage(); |
| 180 | +``` |
| 181 | + |
| 182 | +[Link](https://forexrateapi.com/documentation#api_usage) |
| 183 | + |
| 184 | +--- |
| 185 | +**[Official documentation](https://forexrateapi.com/documentation)** |
| 186 | + |
| 187 | +--- |
| 188 | +## FAQ |
| 189 | + |
| 190 | +- How do I get an API Key? |
| 191 | + |
| 192 | + Free API Keys are available [here](https://forexrateapi.com). |
| 193 | + |
| 194 | +- I want more information |
| 195 | + |
| 196 | + Checkout our FAQs [here](https://forexrateapi.com/faq). |
| 197 | + |
| 198 | + |
| 199 | +## Support |
| 200 | + |
| 201 | +For support, get in touch using [this form](https://forexrateapi.com/contact). |
| 202 | + |
| 203 | + |
| 204 | +[List]: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html 'List' |
| 205 | +[number]: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Number.html 'Number' |
| 206 | +[string]: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html 'String' |
0 commit comments