#!/bin/sh

# --- BTC (USD) ---
btc_data=$(curl -s "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd")
btc_price=$(printf "%s" "$btc_data" | tr -d '\n' | grep -o '"usd":[0-9.]*' | cut -d: -f2)
btc_date=$(date +"%Y-%m-%d")
printf "%s %s\n" "$btc_date" "$btc_price" >> /mnt/sdb/www/mocus/code/stock/data/btc.dat

# --- XAU (Gold Ask USD) ---
xau_data=$(curl -s "https://forex-data-feed.swissquote.com/public-quotes/bboquotes/instrument/XAU/USD")
xau_price=$(printf "%s" "$xau_data" | tr -d '\n' | grep -o '"ask":[0-9.]*' | head -1 | cut -d: -f2)
xau_date=$(date +"%Y-%m-%d")
printf "%s %s\n" "$xau_date" "$xau_price" >> /mnt/sdb/www/mocus/code/stock/data/xau.dat

# --- WEBG (CHF) ---
webg_url="https://www.six-group.com/sheldon/market_data/v1/IE0009HF1MK9CHF4/historic.csv"
webg_price=$(
  curl -s "$webg_url" \
  | grep -E '^[0-9]{2}\.[0-9]{2}\.[0-9]{4};' \
  | head -1 \
  | cut -d';' -f2
)
webg_date=$(date +"%Y-%m-%d")
printf "%s %s\n" "$webg_date" "$webg_price" >> /mnt/sdb/www/mocus/code/stock/data/webg.dat
