gonbp

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2022 License: MIT Imports: 8 Imported by: 0

README

gonbp

This is a go wrapper over the NBP currency exchange rates API.

Narodowy Bank Polski (NBP) is the central bank of the Republic of Poland. Among other tasks it publishes the official exchange rate of Złoty (the Polish currency) against other currencies. NBP provides an API to access the exchange rates.

Use from CLI

Fetch current day CHF rate

❯ nbp CHF
Table No: 078/A/NBP/2022
     Day: 2022-04-22
    Rate: 4.493

Fetch previous day USD rate

❯ nbp -p USD
Table No: 077/A/NBP/2022
     Day: 2022-04-21
    Rate: 4.2596

Fetch EUR for a given day

❯ nbp EUR 2022-04-15
Table No: 074/A/NBP/2022
     Day: 2022-04-15
    Rate: 4.6378

Use as a library

See integration_test.go.

Documentation

Overview

Package gonbp is a go wrapper over NBP API

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Currency

type Currency string

Currency enumerates supported currencies

const (
	CHF Currency = "CHF"
	EUR Currency = "EUR"
	USD Currency = "USD"
)

type NBP

type NBP struct {
	// contains filtered or unexported fields
}

NBP is the NBP API client

func Default

func Default() (*NBP, error)

Default returns *NBP instance using http.DefaultClient and $HOME/.config/nbp

func Init

func Init(cacheDir string, client *http.Client) *NBP

Init returns *NBP instance with a given httpClient

func (*NBP) PreviousRate

func (n *NBP) PreviousRate(curr Currency, day time.Time) (*Rate, error)

PreviousRate returns the currency exchange rate for the last working day before the given day

func (*NBP) Rate

func (n *NBP) Rate(curr Currency, day time.Time) (*Rate, error)

Rate returns the currency exchange rate for a given date from NBP table A

type Rate

type Rate struct {
	TableNo string
	Day     time.Time
	Mid     decimal.Decimal
}

Rate represents the currency exchange rate for a given date

Directories

Path Synopsis
cmd
nbp
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL