finance

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

README

go-finance

Go Report Card Documentation license GitHub version GitHub issues

This is a Golang library which contains finance related functions.

Exchange Rates

The following example explains how to use this package to retrieve the exchange rates from ECB:

package main

import (
	"fmt"
	"os"

	"github.com/pieterclaerhout/go-finance"
)

func main() {

	rates, err := finance.ExchangeRates()
	if err != nil {
		fmt.Println("ERROR:", err.Error())
		os.Exit(1)
	}

	for currency, rate := range rates {
		fmt.Println(currency, "-> €1 =", rate)
	}

}

Checking VAT Numbers

You can also VAT numbers via the VIES service. The following sample code shows how to do this:

package main

import (
	"fmt"
	"os"

	"github.com/pieterclaerhout/go-finance"
)

func main() {

	info, err := finance.CheckVAT("BE0836157420")
	if err != nil {
		fmt.Println("ERROR:", err.Error())
		os.Exit(1)
	}

	fmt.Println(info)

}

IBAN & BIC

There is also a function which converts a regular Belgian Bank Account Number to it's IBAN / BIC equivalent:

package main

import (
	"fmt"
	"os"

	"github.com/pieterclaerhout/go-finance"
)

func main() {

	info, err := finance.CheckIBAN("738120256174")
	if err != nil {
		fmt.Println("ERROR:", err.Error())
		os.Exit(1)
	}

	fmt.Println(info)

}

Documentation

Index

Constants

View Source
const DefaultIBANBICServiceURL = "https://www.ibanbic.be/IBANBIC.asmx"

DefaultIBANBICServiceURL is the default IBANBIC service URL to use

View Source
const DefaultIBANBICTimeout = 5 * time.Second

DefaultIBANBICTimeout is the default timeout to use when checking the bank account number

View Source
const DefaultRatesURL = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"

DefaultRatesURL defines the default URL to fetch the exchange rates from

View Source
const DefaultVATServiceURL = "http://ec.europa.eu/taxation_customs/vies/services/checkVatService"

DefaultVATServiceURL is the default VAT service URL to use

View Source
const DefaultVATTimeout = 5 * time.Second

DefaultVATTimeout is the default timeout to use when checking the VAT service

Variables

View Source
var (
	// ErrIBANBICServiceUnreachable is the error returned when the IBANBIC service is unreachable
	ErrIBANBICServiceUnreachable = errors.New("IBANBIC service is unreachable")

	// ErrIBANBICInvalidInput is the error returned when the bank account number is invalid
	ErrIBANBICInvalidInput = errors.New("Number is not a valid bank account number")

	// ErrIBANBICServiceError is the error returned when we get a non-standard error from the IBANBIC service
	ErrIBANBICServiceError = "IBANBIC service returns an error: "
)
View Source
var (
	// ErrVATnumberNotValid is the error returned when the VAT number is invalid
	ErrVATnumberNotValid = errors.New("VAT number is not valid")

	// ErrVATserviceUnreachable is the error returned when the VIES service is unreachable
	ErrVATserviceUnreachable = errors.New("VAT number validation service is unreachable")

	// ErrVATNumberTooShort is the error returned when the VAT number is too short
	ErrVATNumberTooShort = errors.New("VAT number is too short")

	// ErrVATserviceError is the error returned when we get a non-standard error from the VAT service
	ErrVATserviceError = "VAT number validation service returns an error: "
)
View Source
var DefaultTimeout = 5 * time.Second

DefaultTimeout is the default tiemout for the HTTP client

View Source
var IBANBICServiceURL = DefaultIBANBICServiceURL

IBANBICServiceURL is the SOAP URL to be used when checking a bank account number

View Source
var IBANBICTimeout = DefaultIBANBICTimeout

IBANBICTimeout is the timeout to use when checking the bank account number

View Source
var RatesURL = DefaultRatesURL

RatesURL is the URL where to fetch the rates from

View Source
var VATServiceURL = DefaultVATServiceURL

VATServiceURL is the SOAP URL to be used when checking a VAT number

View Source
var VATTimeout = DefaultVATTimeout

VATTimeout is the timeout to use when checking the VAT service

Functions

func ConvertRate added in v1.0.4

func ConvertRate(value float64, from string, to string) (float64, error)

ConvertRate converts a value from once exchange rate to another

func ExchangeRates

func ExchangeRates() (map[string]float64, error)

ExchangeRates returs the list exchange rates

Types

type IBANBICInfo added in v1.0.3

type IBANBICInfo struct {
	BBAN     string // The Belgian Bank Account Number
	BankName string // The name of the bank which issues the account
	IBAN     string // The IBAN number of the bank account
	BIC      string // The Bank Identification Code of the bank
}

IBANBICInfo contains the info about a Belgian Bank Account number

func CheckIBAN added in v1.0.3

func CheckIBAN(number string) (*IBANBICInfo, error)

CheckIBAN checks the Bank Account Number and returns the IBAN and BIC information

type VATInfo

type VATInfo struct {
	CountryCode string // The country code
	VATNumber   string // The VAT number
	IsValid     bool   // A boolean indicating if the VAT number is valid
	Name        string // The name linked to the VAT number
	Address     string // The address linked to the VAT number
}

VATInfo is the info returned about a VAT number

func CheckVAT

func CheckVAT(vatNumber string) (*VATInfo, error)

CheckVAT checks the VAT number and returns the data

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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