moneyapi

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2022 License: LGPL-2.1 Imports: 13 Imported by: 0

README

 _   .-')                      .-') _     ('-.                   ('-.        _ (`-.            
( '.( OO )_                   ( OO ) )  _(  OO)                 ( OO ).-.   ( (OO  )           
 ,--.   ,--.) .-'),-----. ,--./ ,--,'  (,------.   ,--.   ,--.  / . --. /  _.`     \   ,-.-')  
 |   `.'   | ( OO'  .-.  '|   \ |  |\   |  .---'    \  `.'  /   | \-.  \  (__...--''   |  |OO) 
 |         | /   |  | |  ||    \|  | )  |  |      .-')     /  .-'-'  |  |  |  /  | |   |  |  \ 
 |  |'.'|  | \_) |  |\|  ||  .     |/  (|  '--.  (OO  \   /    \| |_.'  |  |  |_.' |   |  |(_/ 
 |  |   |  |   \ |  | |  ||  |\    |    |  .--'   |   /  /\_    |  .-.  |  |  .___.'  ,|  |_.' 
 |  |   |  |    `'  '-'  '|  | \   |    |  `---.  `-./  /.__)   |  | |  |  |  |      (_|  |    
 `--'   `--'      `-----' `--'  `--'    `------'    `--'        `--' `--'  `--'        `--'    
  

方便地MoneyAPI 金融相关


背景

封装现有API或者自己收集数据,为金融相关的的查询提供工具

特性

  • 🗂 货币实时汇率
  • 🗂 货币信息查询
  • 🗂 货币使用者查询

使用手册

import "github.com/wwqdrh/moneyapi"

func main() {
  // 币种转换
  api := NewMoneyAPI()
	target := []string{
		"CNY", "USD", "JPY", "BGN", "CZK", "DKK", "GBP",
		"HUF", "PLN", "RON", "SEK", "CHF", "ISK",
		"NOK", "HRK", "TRY", "AUD", "BRL", "CAD",
		"CNY", "HKD", "IDR", "INR", "KRW", "MXN",
		"MYR", "NZD", "PHP", "SGD", "THB", "ZAR",
	}
	for j := 0; j < len(target); j++ {
		for i := 0; i < j; i++ {
			fmt.Printf("%s -> %s: %.4f\n", target[i], target[j], api.Rate(target[i], target[j]))
		}
	}

  // 谁使用这个币
  target := []string{
		"USD", "JPY", "BGN", "CZK", "DKK", "GBP",
		"HUF", "PLN", "RON", "SEK", "CHF", "ISK",
		"NOK", "HRK", "TRY", "AUD", "BRL", "CAD",
		"CNY", "HKD", "IDR", "INR", "KRW", "MXN",
		"MYR", "NZD", "PHP", "SGD", "THB", "ZAR",
	}
	for _, item := range target {
		items, err := api.RelativeItem(item)
		if err != nil {
			t.Error(err)
		} else {
			fmt.Println(items)
		}
	}

  // ...
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ConvertInfo convertInfo
)

Functions

func Country2Currency

func Country2Currency(name string) string

func CountryEnName

func CountryEnName(name string) string

国家名转标识

func CountryName

func CountryName(name string) []string

标识转国家名

func Currency2Country

func Currency2Country(name string, flag uint) []string

获取使用币种的国家 0 中文 1 英文

func Currency2Flag

func Currency2Flag(name string) string

币种转为标识

func NewAmericaBankAPI

func NewAmericaBankAPI() (*americaBankAPI, error)

func NewCnBankAPI

func NewCnBankAPI() (*cnBankAPI, error)

func NewCurrencyInfo

func NewCurrencyInfo() (*xeInfoAPI, error)

func NewEuropeBankAPI

func NewEuropeBankAPI() (*europeBankAPI, error)

func NewxEAPI

func NewxEAPI(auth string) (*xeRateAPI, error)

func RelationCurrency

func RelationCurrency(name string) map[string]bool

处理中文可能存在同音字的问题

Types

type ICurrencyRate

type ICurrencyRate interface {
	CurrencyMap() map[string]float64
	Status() bool // 当前接口状态
	Rate(base string, target string) (float64, error)
	// contains filtered or unexported methods
}

type MoneyAPI

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

graph base on bank rate info

func NewMoneyAPI

func NewMoneyAPI() *MoneyAPI

func (*MoneyAPI) Rate

func (a *MoneyAPI) Rate(base, target string) float64

在graph中寻找从base到target的路径 bfs 寻找最短路径 1 base -> ? target

func (*MoneyAPI) Update

func (a *MoneyAPI) Update()

func (*MoneyAPI) Update2

func (a *MoneyAPI) Update2()

Jump to

Keyboard shortcuts

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