https://github.com/softwareengineerchris/monetaryexchange
💱 Provides exchange rates between currencies and converts monetary amounts - Swift Micro Package
https://github.com/softwareengineerchris/monetaryexchange
cross-rates currency exchange-rates fixer fixer-client fixerio micropackage monetary money swift
Last synced: 3 months ago
JSON representation
💱 Provides exchange rates between currencies and converts monetary amounts - Swift Micro Package
- Host: GitHub
- URL: https://github.com/softwareengineerchris/monetaryexchange
- Owner: SoftwareEngineerChris
- License: mit
- Created: 2019-10-02T18:07:42.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-21T14:04:29.000Z (over 5 years ago)
- Last Synced: 2025-03-01T01:45:18.605Z (3 months ago)
- Topics: cross-rates, currency, exchange-rates, fixer, fixer-client, fixerio, micropackage, monetary, money, swift
- Language: Swift
- Homepage: https://softwareengineerchris.github.io/MonetaryExchange/
- Size: 254 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MonetaryExchange
[](https://app.bitrise.io/app/57e424b934229804)
[](https://softwareengineerchris.github.io/MonetaryExchange)
[](#)
[](#)`Exchange` provides exchange rates between currencies. It can also convert `MonetaryAmount` values into
those of different `Currency` values.## Installation
### Swift Package Manager
```swift
dependencies: [
.package(url: "https://github.com/SoftwareEngineerChris/MonetaryExchange.git", from: "1.0.0")
]
```## Decoding a Fixer.io JSON response
An `Exchange` can be decoded directly from a the [Fixer.io](https://fixer.io/) Latest Rates JSON response.
See [Fixer API Documentation](https://fixer.io/documentation#latestrates) for more information about its API usage.### Example using the Fixer Extension
```swift
Exchange.Fixer.exchange(accessKey: "YourFixerAccessKey") { result in
switch result {
case let .success(exchange):
// We have an Exchange valuecase let .failure(error):
// Something went wrong. Dig into the error.
}
}
```
See the documentation for `Exchange.Fixer` for more information.### Example using JSONDecoder Directly
```swift
let exchange = try? JSONDecoder().decode(Exchange.self, from: fixerResponseData)
```Alternatively, an `Exchange` can be constructed with a base currency and a dictionary of currency-rate pairs.
## Cross-rates
If converting between two currencies which neither are the base currency, but each have a rate against the base currency,
then a cross-rate will be produced.For example, if the base currency is _EUR_ but a rate for _GBP to USD_ is requested, a cross-rate will be used. i.e. _GBP to EUR to USD_.
See the Collins Dictionary definition of [Cross-Rate](https://www.collinsdictionary.com/dictionary/english/cross-rate)
for more information.