package exchange_test import ( "bytes" "fmt" "os" "time" "github.com/bojanz/currency" "git.samanthony.xyz/exchange" ) var btcDef = currency.Definition{ "1000", 8, "BTC", } func ExampleClient_Rate() { key, _ := readFile(".key") exc := exchange.NewClient(key, exchange.WithTTL(15*time.Minute)) cadPerBtc, _ := exc.Rate("BTC", "CAD") currency.Register("BTC", btcDef) btc, _ := currency.NewAmount("1.23", "BTC") cad, _ := btc.Convert("CAD", cadPerBtc.String()) fmt.Printf("%v = %v\n", btc.Round(), cad.Round()) } func readFile(path string) (string, error) { buf, err := os.ReadFile(path) return string(bytes.TrimSpace(buf)), err }