|
| 1 | +## Currency API Java Client |
| 2 | + |
| 3 | +[](https://github.com/moatsystem/currensees-java/actions/workflows/ci.yml) |
| 4 | + |
| 5 | +A Java client for interacting with [Currency API](https://moatsystems.com/currency-api/). |
| 6 | + |
| 7 | +[Moat Systems](https://moatsystems.com) provides customers with accurate and up-to-date currency data for making informed decisions in the global financial market, including Gold, Silver and Special Drawing Rights. Our reliable exchange rate data assist businesses in confidently managing foreign transactions, investments and risks. Accounting, E-commerce, CRM, and ERP software companies will find it helpful to integrate with us instead of developing a custom in-house solution. |
| 8 | + |
| 9 | +### Requirements |
| 10 | + |
| 11 | +This library is tested with Java versions 11, 14, 15, 16 and 17. |
| 12 | + |
| 13 | +### Installation |
| 14 | + |
| 15 | +#### Maven |
| 16 | + |
| 17 | +Add this dependency to your project's POM: |
| 18 | + |
| 19 | +```java |
| 20 | +<dependency> |
| 21 | + <groupId>com.currensees</groupId> |
| 22 | + <artifactId>currensees-java</artifactId> |
| 23 | + <version>X.X.X</version> |
| 24 | +</dependency> |
| 25 | +``` |
| 26 | + |
| 27 | +#### Gradle |
| 28 | + |
| 29 | +Add this dependency to your `build.gradle` file: |
| 30 | + |
| 31 | +``` |
| 32 | +compile 'com.currensees:currensees-java:X.X.X' |
| 33 | +``` |
| 34 | + |
| 35 | +### Usage Example |
| 36 | + |
| 37 | +This library is a Java client you can use to interact with the [Currency API](https://moatsystems.com/currency-api/). |
| 38 | + |
| 39 | +```java |
| 40 | +package myapp; |
| 41 | + |
| 42 | +import com.currensees; |
| 43 | +import com.google.gson.Gson; |
| 44 | +import com.google.gson.JsonObject; |
| 45 | +import java.util.Optional; |
| 46 | + |
| 47 | +public class MyApp { |
| 48 | + |
| 49 | + public static void main(String[] args) { |
| 50 | + String username = "your_username"; |
| 51 | + String password = "your_password"; |
| 52 | + |
| 53 | + Optional<String> loginResponse = Auth.loginAndGetUsername(username, password); |
| 54 | + |
| 55 | + if (loginResponse.isPresent()) { |
| 56 | + // Convert |
| 57 | + Optional<String> conversionResult = Convert.convert(username, "2023_04_19", "GBP", "EUR", "500"); |
| 58 | + if (conversionResult.isPresent()) { |
| 59 | + System.out.println("Conversion result: " + conversionResult.get()); |
| 60 | + } else { |
| 61 | + System.out.println("Conversion failed."); |
| 62 | + } |
| 63 | + |
| 64 | + // ConvertAll |
| 65 | + Optional<String> conversionAllResult = ConvertAll.convertAll(username, "2023_04_02", "GBP", "120"); |
| 66 | + if (conversionAllResult.isPresent()) { |
| 67 | + System.out.println("Conversion all result: " + conversionAllResult.get()); |
| 68 | + } else { |
| 69 | + System.out.println("Conversion all failed."); |
| 70 | + } |
| 71 | + |
| 72 | + // DailyAverage |
| 73 | + Optional<String> dailyAverageResult = DailyAverage.getDailyAverage(username, "2023_04_02"); |
| 74 | + if (dailyAverageResult.isPresent()) { |
| 75 | + System.out.println("Daily average result: " + dailyAverageResult.get()); |
| 76 | + } else { |
| 77 | + System.out.println("Fetching daily average failed."); |
| 78 | + } |
| 79 | + |
| 80 | + // WeeklyAverage |
| 81 | + Optional<String> weeklyAverageResult = WeeklyAverage.getWeeklyAverage(username, "2023_04_03", "2023_04_07"); |
| 82 | + if (weeklyAverageResult.isPresent()) { |
| 83 | + System.out.println("Weekly average result: " + weeklyAverageResult.get()); |
| 84 | + } else { |
| 85 | + System.out.println("Fetching weekly average failed."); |
| 86 | + } |
| 87 | + |
| 88 | + // Currencies |
| 89 | + Optional<String> currenciesResult = Currencies.getAllCurrencies(username, 19, 4, 2024); |
| 90 | + if (currenciesResult.isPresent()) { |
| 91 | + System.out.println("All currencies result: " + currenciesResult.get()); |
| 92 | + } else { |
| 93 | + System.out.println("Fetching all currencies failed."); |
| 94 | + } |
| 95 | + |
| 96 | + // Currencies - getCurrencyById |
| 97 | + Optional<String> currencyByIdResult = Currencies.getCurrencyById(username, "594bffc4-d095-11ed-9e30-acde48001122", 19, 4, 2023); |
| 98 | + if (currencyByIdResult.isPresent()) { |
| 99 | + System.out.println("Currency by ID result: " + currencyByIdResult.get()); |
| 100 | + } else { |
| 101 | + System.out.println("Fetching currency by ID failed."); |
| 102 | + } |
| 103 | + |
| 104 | + // Historical |
| 105 | + Optional<String> allHistoricalDataResult = Historical.getAllHistoricalData(username, "2023_04_02", 19, 4, 2023); |
| 106 | + if (allHistoricalDataResult.isPresent()) { |
| 107 | + System.out.println("All historical data result: " + allHistoricalDataResult.get()); |
| 108 | + } else { |
| 109 | + System.out.println("Fetching all historical data failed."); |
| 110 | + } |
| 111 | + |
| 112 | + // Historical - getHistoricalById |
| 113 | + Optional<String> historicalDataByIdResult = Historical.getHistoricalDataById(username, "fe1ee1c4-d162-11ed-a2dc-acde48001122", "2023_04_02", 19, 4, 2023); |
| 114 | + if (historicalDataByIdResult.isPresent()) { |
| 115 | + System.out.println("Historical data by ID result: " + historicalDataByIdResult.get()); |
| 116 | + } else { |
| 117 | + System.out.println("Fetching historical data by ID failed."); |
| 118 | + } |
| 119 | + |
| 120 | + // MarginsSpreads - getAllMarginsSpreads |
| 121 | + Optional<String> marginsSpreadsAllResult = MarginsSpreads.getAllMarginsSpreads(username, 19, 4, 2023); |
| 122 | + if (marginsSpreadsAllResult.isPresent()) { |
| 123 | + System.out.println("All Margins Spreads result: " + marginsSpreadsAllResult.get()); |
| 124 | + } else { |
| 125 | + System.out.println("Fetching all Margins Spreads failed."); |
| 126 | + } |
| 127 | + |
| 128 | + // MarginsSpreads - getMarginsSpreadsById |
| 129 | + Optional<String> marginsSpreadsByIdResult = MarginsSpreads.getMarginsSpreadsById(username, "8e694000-e3c2-11ed-b5bd-acde48001122", 19, 4, 2023); |
| 130 | + if (marginsSpreadsByIdResult.isPresent()) { |
| 131 | + System.out.println("Margins Spreads by ID result: " + marginsSpreadsByIdResult.get()); |
| 132 | + } else { |
| 133 | + System.out.println("Fetching Margins Spreads by ID failed."); |
| 134 | + } |
| 135 | + |
| 136 | + // Performances |
| 137 | + Optional<String> performancesResult = Performances.getAllPerformances(username); |
| 138 | + if (performancesResult.isPresent()) { |
| 139 | + System.out.println("Performances result: " + performancesResult.get()); |
| 140 | + } else { |
| 141 | + System.out.println("Fetching performances failed."); |
| 142 | + } |
| 143 | + |
| 144 | + // Performances - getPerformanceById |
| 145 | + Optional<String> performanceByIdResult = Performances.getPerformanceById(username, "8edd9b12-e3c2-11ed-b5bd-acde48001122"); |
| 146 | + if (performanceByIdResult.isPresent()) { |
| 147 | + System.out.println("Performance by ID result: " + performanceByIdResult.get()); |
| 148 | + } else { |
| 149 | + System.out.println("Fetching Performance by ID failed."); |
| 150 | + } |
| 151 | + |
| 152 | + // Signals |
| 153 | + Optional<String> signalsResult = Signals.getAllSignals(username); |
| 154 | + if (signalsResult.isPresent()) { |
| 155 | + System.out.println("Signals result: " + signalsResult.get()); |
| 156 | + } else { |
| 157 | + System.out.println("Fetching signals failed."); |
| 158 | + } |
| 159 | + |
| 160 | + // Signals - getSignalById |
| 161 | + Optional<String> signalByIdResult = Signals.getSignalById(username, "8e694050-e3c2-11ed-b5bd-acde48001122"); |
| 162 | + if (signalByIdResult.isPresent()) { |
| 163 | + System.out.println("Signal by ID result: " + signalByIdResult.get()); |
| 164 | + } else { |
| 165 | + System.out.println("Fetching Signal by ID failed."); |
| 166 | + } |
| 167 | + |
| 168 | + } else { |
| 169 | + System.out.println("Login failed."); |
| 170 | + } |
| 171 | + } |
| 172 | +} |
| 173 | +``` |
| 174 | + |
| 175 | +### Setting up Currency API Account |
| 176 | + |
| 177 | +Subscribe [here](https://moatsystems.com/currency-api/) for a user account. |
| 178 | + |
| 179 | +### Using the Currency API |
| 180 | + |
| 181 | +You can read the [API documentation](https://docs.currensees.com/) to understand what's possible with the Currency API. If you need further assistance, don't hesitate to [contact us](https://moatsystems.com/contact/). |
| 182 | + |
| 183 | +### License |
| 184 | + |
| 185 | +This project is licensed under the [BSD 3-Clause License](./LICENSE). |
| 186 | + |
| 187 | +### Copyright |
| 188 | + |
| 189 | +(c) 2020 - 2023 [Moat Systems Limited](https://moatsystems.com). |
0 commit comments