go-swap
go-swap copied to clipboard
💱 Currency exchange rates server - Golang "ƓØ"
Currency Exchange Server - Golang
Swap allows you to retrieve currency exchange rates from various services such as Google, Yahoo, Fixer, CurrencyLayer or 1Forge and optionally cache the results.
Playground


/GET Examples for single exchanger:
- 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
/POST Examples for single or multi exchanger:
- 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
-
QuickStart
# 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
Programmatically
$ 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())
}
Features
- 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
Screens

Documentation
The documentation for the current branch can be found here.
Services
Exchanger | type | # | $ |
---|---|---|---|
HTML / Regex | :heavy_check_mark: | Free | |
Yahoo | JSON / API | :heavy_check_mark: | Free |
Currency Layer | JSON / API | :heavy_check_mark: | Paid - ApiKey |
Fixer.io | JSON / API | :heavy_check_mark: | Paid - ApiKey |
1forge | API | :heavy_check_mark: | Freemium / Paid - ApiKey |
The Money Converter | HTML / Regex | :heavy_check_mark: | Free |
Open Exchange Rates | API | :heavy_check_mark: | Freemium / Paid - ApiKey |
Uptime Monitor

TODO LIST
- [ ] 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
Contributing
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
Credits
Inspired by florianv/swap
License
The code is available under the MIT license.