Skip to content
Currency exchange rates with GraphQL 🤑
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
fixtures
static
templates
.dockerignore
.gitignore
.travis.yml
Dockerfile
LICENSE Initial commit Apr 14, 2019
Makefile
README.md
env.go
generated.go
go.mod First commit Apr 14, 2019
go.sum First commit Apr 14, 2019
gqlgen.yml
main.go
models.go First commit Apr 14, 2019
models_test.go
resolver.go
schema.graphql First commit Apr 14, 2019
scrapper.go
scrapper_test.go

README.md

Exchange Rates GraphQL

Exchange Rates GraphQL is a free service for current and historical foreign exchange rates published by the European Central Bank. Inspired by exchangeratesapi, inlcuding this description.

Queries

To get the latest Exchange Rate:

query {
  latest {
    symbol
    value
  }
}

You can also ask for a specific base currency and which symbols to return. All Queries accept these parameters.

query {
  latest(base: "USD", symbols: ["EUR", "USD", "BRL"]) {
    symbol
    value
  }
}

Getting a specific date:

query {
  date(date: "2000-01-03") {
    symbol
    value
  }
}

Finally, asking for a date range:

query {
  history(startAt: "2019-01-01", endAt: "2019-01-10") {
    rates {
      symbol
      value
    }
  }
}

Developing

To run it locally you will need:

  • Go v1.11 or higher
  • PostgreSQL

First, set the following environment variables:

export DATABASE_URL='postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable'
export TEST_DATABASE_URL='postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable' # used only for tests!
export GIN_MODE='release'
export PORT=8000

Install the dependencies, build and run:

$ make build
$ make run

Go to your browser at http://localhost:8080/graphql/playground and have fun!

The currency data comes from the European Central Bank. The builtin scrapper will download the data from since 1999 in its first run, and subsequently download the latest 30 days and update accordingly. To run it, use:

$ make scrape

To run the tests, use the following command:

$ make test

FAQ

Q: Why am a specific date doesn't return any data?
R: The source data on the European Central bank if for every working day, except TARGET closing days. Also, the rates are updated every hour.

License

MIT

You can’t perform that action at this time.