price-widget

5 min read Original article ↗

A simple widget desktop that shows prices of several asset types: cryptocurrency, fiat currency, gold, silver, stocks

A simple desktop widget that shows prices of several asset types:

  • Cryptocurrencies (in USD)
  • Gold and silver (in USD, by troy ounce and kilogram)
  • National/fiat currency exchange rates using floatrates, tgju
  • Stocks using stooq.com

Build

If you have Go, and are using Linux or Mac, either:

  • Run CGO_ENABLED=1 go install codeberg.org/ilius/price-widget@latest to build and install
  • Clone the repo then run CGO_ENABLED=1 go build

On Mac, you will need to install brew and some dependencies first:

brew install gcc cmake ninja openssl@3 zlib pkg-config qt@6

Maybe I can build and upload static binaries for Mac or even Windows in the future.

Example configuration

Here is a small example comfiguration file:

refresh_interval_seconds = 900  # 15min
text_size = 25
spacing = 20
inner_spacing = 5
window_width = 200
window_height = 300
background_color = "#000000"  # default: "black"
text_color = "#ffffff"  # default: "white"
bypass_window_manager = false
# log_level = "debug"  # default: "info"
# show_fetch_time = ["coingecko"]

[[assets]]
name = "Bitcoin"
id = "bitcoin"
digits = -1
humanize_format = "###,###."
# prefix = "$"
# suffix = ""

[[assets]]
row = 2
name = "Gold (oz)"
id = "gold_oz"
type = "gold"

[[assets]]
row = 3
type = "floatrates"
name = "MYR/USD"
id = "MYR/USD"
digits = 2

Which produces this window:

btc-gold-myr-vertical

Note: name = parameter is only for display and you can change it any way you want. While id = is to actually specify what asset it is.

Configuration

If you right-click on the window, you will see a menu with "Quit", "Config" and "About". When you click on "Config" the configuration file is opened in your default editor for TOML files (file will be created if it does not exist), so you can change the config quickly. Then you need to restart the program.

But here is the config file path:

  • Linux: ~/.config/price-widget/config.toml

    • If $XDG_CONFIG_HOME is set: $XDG_CONFIG_HOME/price-widget/config.toml
  • Windows: C:\Users\USERNAME\AppData\Roaming\PriceWidget\config.toml

    • More accurately: %APPDATA%\PriceWidget\config.toml
  • Mac: ~/Library/Preferences/PriceWidget/config.toml

Asset types

Here are all supported asset types (as seen in example above):

Label / text: type = "label"

Just shows name parameter with no number/price.

Cryptocurrency: type = "coingecko"

This is the default asset type, so you can omit it for cryptocurrencies.

Alias types: "coin", "crypto"

Gold and silver: type = "precious-metals"

Use two different data sources:

Alias types: "preciousmetals", "metals", "metal", "gold", "goldprice", "silver"

These are supported asset IDs (id = as seen in example above).

  • id = "gold_oz" and id = "gold" for troy ounce of gold in USD
  • id = "gold_kg" for kilogram of gold in USD
    • Can change it to grams using unit = 1000 parameter
  • id = "silver_oz" and id = "silver" for troy ounce of silver in USD
  • id = "silver_kg" for kilogram of silver in USD
  • id = "gsr": Gold to Silver Ratio (calculated)
  • id = "shanghai_silver_oz": Shanghai's silver price in USD per troy ounce
  • id = "shanghai_silver_kg": Shanghai's silver price in USD per kilogram
  • id = "shanghai_gold_oz": Shanghai's gold price in USD per troy ounce
  • id = "shanghai_gold_kg": Shanghai's gold price in USD per kilogram
  • id = "shanghai_gsr": Shanghai's Gold to Silver Ratio (calculated)

Global currency rates: type = "floatrates"

As seen in example above, you specify the pair in this way for example:

[[assets]]
type = "floatrates"
name = "EUR/USD"
id = "EUR/USD"
digits = 2

Global stock prices: type = "stooq"

Example:


[[assets]]
row = 4
type = "stooq"
name = "Grab: close"
id = "grab.us_close"
digits = 2

[[assets]]
row = 4
type = "stooq"
name = "open"
id = "grab.us_open"
digits = 2

[[assets]]
row = 4
type = "stooq"
name = "high"
id = "grab.us_high"
digits = 2

[[assets]]
row = 4
type = "stooq"
name = "low"
id = "grab.us_low"
digits = 2

Iran's rates: type = "tgju"

Free market prices/rates of fiat currencies and precious metals.

Example:

[[assets]]
type = "tgju"
name = "EUR/Toman"
id = "EUR"
digits = 1
unit = 10000
suffix = " k"

Supported currencies (valid id = values):

USD, EUR, AED, GBP, TRY, CHF, CNY, JPY, KRW, CAD, NZD, SGD, INR, PKR, IQD, SYP, AFN, DKK, SEK, NOK, SAR, QAR, OMR, KWD, BHD, MYR, THB, HKD, RUB, AZN, AMD, GEL, KGS, TJS, TMT

Supported precious metals (valid id = values):

  • id = "ir_gold_oz": troy ounce of gold in Rials
  • id = "ir_gold_kg": kilogram of gold in Rials
  • id = "ir_silver_oz": troy ounce of silver in Rials
  • id = "ir_silver_kg": kilogram of silver in Rials
  • id = "ir_gold_oz_usd": troy ounce of gold in USD (calculated)
  • id = "ir_gold_kg_usd": kilogram of gold in USD (calculated)
  • id = "ir_silver_oz_usd": troy ounce of silver in USD (calculated)
  • id = "ir_silver_kg_usd": kilogram of silver in USD (calculated)
  • id = "ir_gsr" Iran's Gold to Silver Ratio (calculated)