-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b72b883
commit 2017a33
Showing
17 changed files
with
2,123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,6 @@ | |
|
||
# Go workspace file | ||
go.work | ||
|
||
.idea | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/) |
Oops, something went wrong.