Skip to content
/ go-swap Public

πŸ’± Currency exchange rates server - Golang "Ζ“Γ˜"

License

Notifications You must be signed in to change notification settings

me-io/go-swap

Repository files navigation

Currency Exchange Server - Golang

Build Status Go Report Card Coverage Status GoDoc GitHub release

Blog URL COMMIT SIZE-LAYERS Pulls

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

Swagger UI heroku test instance @ https://go-swap-server.herokuapp.com

/GET Examples for single exchanger:

/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
  • Run in Postman

QuickStart

Deploy
# 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
    • Google
    • Yahoo
    • CurrencyLayer
    • Fixer.io
    • themoneyconverter.com
    • openexchangerates.org
    • 1forge.com
  • Rate Caching - 120s Default
    • Memory - Default
    • Redis
  • 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 # $
Google 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

Uptime Monitor

Deploy

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:

Credits

Inspired by florianv/swap

License

The code is available under the MIT license.