local coins = {
"BTC", -- Bitcoin
"ETH", -- Ethereum
"BNB", -- Binance Coin
"DOGE", -- Dogecoin
"SOL", -- Solana
"TON", -- Toncoin
"LTC" -- Litecoin
}
local url_crypto = "https://min-api.cryptocompare.com/data/pricemulti?fsyms="
.. table.concat(coins, ",")
.. "&tsyms=USD"
local url_fx = "https://www.floatrates.com/daily/usd.json"
local function safe_json(resp)
local ok, data = pcall(json.parse, resp)
if not ok then
return nil, "невалидный JSON: "..tostring(resp)
end
return data
end
local tab = ui.create("Crypto","Rates")
local tab2 = ui.create("Crypto", "Update")
local labels = {}
for _, sym in ipairs(coins) do
labels[sym] = tab:label(string.format("%s → …", sym))
end
local lbl_usd = tab:label("USD → …")
local function update_rates()
network.get(url_crypto, nil, function(resp1)
local d1, err1 = safe_json(resp1)
if d1 then
for _, sym in ipairs(coins) do
local entry = d1[sym]
if entry and entry.USD then
labels[sym]:name(string.format("%s → $%.4f", sym, entry.USD))
else
print_error(sym.." API: no data or incorrect format")
end
end
else
print_error("Crypto API: "..tostring(err1 or resp1))
end
network.get(url_fx, nil, function(resp2)
local d2, err2 = safe_json(resp2)
if d2 and d2.rub and d2.rub.rate then
lbl_usd:name(string.format("USD → %.2f ₽", d2.rub.rate))
else
print_error("FX API: "..tostring(err2 or resp2))
end
end)
end)
end
tab2:button("Update pricing information", update_rates)
update_rates()