Skip to content

data.currency #

currency handling

Allows us to get currencies from the internet

offline

if you need to work offline e.g. for development do

export OFFLINE=1

example

TODO:...

fn amount_get #

fn amount_get(amount_ string) !Amount

amount_get gets amount and currency from a string input ARGS:- amount_str string : a human-written string-decimals are done with US notation (.)- check in string for format e.g. 10.3usd or '10 usd' or '10 USD' or '10 usDC'allows £,$,€ to be used as special cases

fn default_set #

fn default_set(cur string, usdval f64)

fn defaults_set #

fn defaults_set()

can give actions string, if empty will just set TFT at 0.015

fn get #

fn get(name_ string) !Currency

get a currency object based on the name

fn rates_get #

fn rates_get(cur_array []string, crypto bool) !

// gets the latest currency exchange rates from an API on internet- an array of fiat codes e.g ['EUR', 'AED']

  • an array of crypto codes e.g ['TERRA']e.g.

fn refresh #

fn refresh()

struct Amount #

struct Amount {
pub mut:
	currency Currency
	val      f64
}

fn (Amount) exchange #

fn (mut a0 Amount) exchange(target_currency_ Currency) !Amount

exchagen the amount to requested target currency

fn (Amount) usd #

fn (a Amount) usd() f64

convert an Amount into usd ARGS:- Amount

Todo: hard code in exchange rates, later this struct can be filled in with an API or something

struct Currency #

struct Currency {
pub mut:
	name   string
	usdval f64
}