Swap allows you to retrieve currency exchange rates from various services such as Google, Yahoo, Fixer, CurrencyLayer or 1Forge and optionally cache the results.
- GET /convert?from=USD&to=AED&amount=2&exchanger=yahoo
- GET /convert?from=EUR&to=GBP&amount=1&exchanger=google&cacheTime=300s
- GET /convert?from=USD&to=SAR&amount=1&exchanger=themoneyconverter
- CURL examples:
curl -X POST \ https://go-swap-server.herokuapp.com/convert \ -H 'Content-Type: application/json' \ -d '{ "amount": 2.5, "from": "USD", "to": "AED", "decimalPoints": 4, "cacheTime": "120s", "exchanger": [ { "name": "yahoo" }, { "name": "google" }, { "name": "themoneyconverter", "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:21.0) Gecko/20100101 Firefox/21.0" } ] }' # Response example # { # "to": "AED", # "from": "USD", # "exchangerName": "yahoo", # "exchangeValue": 3.6721, # "originalAmount": 2.5, # "convertedAmount": 9.1802, # "convertedText": "2.5 USD is worth 9.1802 AED", # "rateDateTime": "2018-09-30T07:45:45Z", # "rateFromCache": false # }
- Run in SwaggerUI
# Or using docker
$ docker pull meio/go-swap-server:latest && \
docker run --rm --name go-swap-server -p 5000:5000 -it meio/go-swap-server:latest
$ go get github.com/me-io/go-swap
package main
import (
"fmt"
ex "github.com/me-io/go-swap/pkg/exchanger"
"github.com/me-io/go-swap/pkg/swap"
)
func main() {
SwapTest := swap.NewSwap()
SwapTest.
AddExchanger(ex.NewGoogleApi(nil)).
Build()
euroToUsdRate := SwapTest.Latest("EUR/USD")
fmt.Println(euroToUsdRate.GetRateValue())
}
- Convert with Single exchange source
/GET
- Convert with Multi exchange sources with fallback mechanism
/POST
- Yahoo
- CurrencyLayer
- Fixer.io
- themoneyconverter.com
- openexchangerates.org
- 1forge.com
- Rate Caching -
120s Default
- Memory -
Default
- Redis
- Memory -
- Rate decimal points rounding
4 Default
- Swagger UI
- Clear API Request and Response
- Docker image, Binary release and Heroku Demo
- Clear documentation and 90%+ code coverage
- Unit tested on live and mock data
The documentation for the current branch can be found here.
Exchanger | type | # | $ |
---|---|---|---|
HTML / Regex | βοΈ | Free | |
Yahoo | JSON / API | βοΈ | Free |
Currency Layer | JSON / API | βοΈ | Paid - ApiKey |
Fixer.io | JSON / API | βοΈ | Paid - ApiKey |
1forge | API | βοΈ | Freemium / Paid - ApiKey |
The Money Converter | HTML / Regex | βοΈ | Free |
Open Exchange Rates | API | βοΈ | Freemium / Paid - ApiKey |
- error structure for empty json or regex not matched
- convert panic to api json error
- increase tests
- verbose logging
- godoc
- static bundle public folder
./cmd/server/public
- v 1.0.0 release ( docker / binary github / homebrew mac )
- support historical rates if possible
- benchmark & performance optimization
memory leak
- contributors list
Anyone is welcome to contribute, however, if you decide to get involved, please take a moment to review the guidelines:
- Only one feature or change per pull request
- Write meaningful commit messages
- Follow the existing coding standards
Inspired by florianv/swap
The code is available under the MIT license.