Skip to content

Commit

Permalink
Initial code commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jamieaitken committed Mar 16, 2022
1 parent b72b883 commit 2017a33
Show file tree
Hide file tree
Showing 17 changed files with 2,123 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@

# Go workspace file
go.work

.idea
.DS_Store
102 changes: 102 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
linters-settings:
funlen:
lines: 130
statements: 50
goconst:
min-len: 2
min-occurrences: 2
gocritic:
enabled-tags:
- diagnostic
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- wrapperFunc
gocyclo:
min-complexity: 15
godot:
# comments to be checked: `declarations`, `toplevel`, or `all`
scope: declarations
# list of regexps for excluding particular comment lines from check
exclude:
# example: exclude comments which contain numbers
# - '[0-9]+'
# check that each sentence starts with a capital letter
capital: false
govet:
check-shadowing: true
lll:
line-length: 200
maligned:
suggest-new: true
misspell:
locale: UK
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
staticcheck:
checks: ["all", -SA5001]
linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
#- deadcode
- depguard
- dogsled
#- errcheck
- exportloopref
- exhaustive
- funlen
- goconst
- gocritic
- gocyclo
- godot
- gofmt
- goimports
- goprintffuncname
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- noctx
- nolintlint
- rowserrcheck
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace

# don't enable:
# - asciicheck
# - bodyclose
# - scopelint
# - gochecknoglobals
# - gocognit
# - godox
# - goerr113
# - interfacer
# - maligned
# - nestif
# - prealloc
# - testpackage
# - revive
# - wsl

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
- gomnd
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.DEFAULT_GOAL := ci

ci: lint test

test:
@go test -race -failfast -covermode=atomic ./...

lint:
@golangci-lint run ./...
124 changes: 124 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# OXR 💹

## Install

```shell
go get github.com/jamieaitken/oxr
```

## How to use

### Initialise your client

```go
doer := http.DefaultClient
c := oxr.New(oxr.WithAppID("your_app_id"), oxr.WithDoer(doer))
```

### Latest Rates

Latest retrieves the latest exchange rates available from the Open Exchange
Rates [API](https://docs.openexchangerates.org/docs/latest-json)

```go
doer := http.DefaultClient
c := oxr.New(oxr.WithAppID("your_app_id"), oxr.WithDoer(doer))

latestRates, err := c.Latest(context.Background(), oxr.LatestForBaseCurrency("GBP"))
```

### Historical

Historical retrieves historical exchange rates for any date available from the Open Exchange Rates
[API](https://docs.openexchangerates.org/docs/historical-json), currently going back to 1st January 1999.

```go
doer := http.DefaultClient
c := oxr.New(oxr.WithAppID("your_app_id"), oxr.WithDoer(doer))

historicalRates, err := c.Historical(
context.Background(),
oxr.HistoricalForDate(time.Date(2022, 03, 10, 12, 00, 00, 00, time.UTC)),
oxr.HistoricalForBaseCurrency("USD"),
)
```

### Currencies

Currencies retrieves the list of all currency symbols available from the Open Exchange
Rates [API](https://docs.openexchangerates.org/docs/currencies-json), along with their full names.

```go
doer := http.DefaultClient
c := oxr.New(oxr.WithAppID("your_app_id"), oxr.WithDoer(doer))

currencies, err := c.Currencies(context.Background())
```

### Time Series

TimeSeries retrieves historical exchange rates for a given time period, where available, using the time series / bulk
download [API](https://docs.openexchangerates.org/docs/time-series-json) endpoint.

```go
doer := http.DefaultClient
c := oxr.New(oxr.WithAppID("your_app_id"), oxr.WithDoer(doer))

currencies, err := c.TimeSeries(
context.Background(),
oxr.TimeSeriesForStartDate(time.Date(2013, 01, 01, 00, 00, 00, 00, time.UTC)),
oxr.TimeSeriesForEndDate(time.Date(2013, 01, 31, 00, 00, 00, 00, time.UTC)),
oxr.TimeSeriesForBaseCurrency("AUD"),
oxr.TimeSeriesForDestinationCurrencies([]string{"BTC", "EUR", "HKD"}),
)
```

### Convert

Convert any money value from one currency to another at the
latest [API](https://docs.openexchangerates.org/docs/convert) rates.

```go
doer := http.DefaultClient
c := oxr.New(oxr.WithAppID("your_app_id"), oxr.WithDoer(doer))

currencies, err := c.Convert(
context.Background(),
oxr.ConvertWithValue(100.12),
oxr.ConvertForBaseCurrency("GBP"),
oxr.ConvertForDestinationCurrency("USD"),
)
```

### Open High Low Close (OHLC)

OpenHighLowClose [retrieves](https://docs.openexchangerates.org/docs/ohlc-json) historical Open, High Low, Close (OHLC)
and Average exchange rates for a given time period, ranging from 1 month to 1 minute, where available.

```go
doer := http.DefaultClient
c := oxr.New(oxr.WithAppID("your_app_id"), oxr.WithDoer(doer))

currencies, err := c.OpenHighLowClose(
context.Background(),
oxr.OHLCForBaseCurrency("USD"),
oxr.OHLCForPeriod(oxr.ThirtyMinute),
oxr.OHLCForDestinationCurrencies([]string{"GBP", "EUR"}),
oxr.OHLCForStartTime(time.Date(2022, 3, 15, 13, 00, 00, 00, time.UTC)),
)
```

### Usage

Usage [retrieves](https://docs.openexchangerates.org/docs/usage-json) basic plan information and usage statistics for an
Open Exchange Rates App ID.

```go
doer := http.DefaultClient
c := oxr.New(oxr.WithAppID("your_app_id"), oxr.WithDoer(doer))

currencies, err := c.Usage(context.Background())
```

## License
[MIT](https://choosealicense.com/licenses/mit/)
Loading

0 comments on commit 2017a33

Please sign in to comment.