mirror of
https://github.com/aljazceru/satshkd-vercel.git
synced 2025-12-18 13:44:22 +01:00
- Created EUR calculation module (calculate-eur.js) for EUR-based satoshi calculations - Created btcpoll-eur.js to fetch and store EUR historical data from CoinGecko API - Added EUR historical data file structure (public/eur_historical) - Created locale files for 8 European languages (English, German, French, Spanish, Italian, Dutch, Portuguese, Polish) - Updated index.js with EUR routes for all language variants (/en-eur, /de, /fr, /es, /it, /nl, /pt, /pl) - Made template (sats.hbs) dynamic to support both HKD and EUR currencies with configurable exchange rates - Updated template to support up to 7 language links for EUR version - Added updaterate-eur.js for GitHub Actions to update EUR data daily - Updated GitHub Actions workflow to run both HKD and EUR data updates - Updated all locale files (HKD and EUR) with data_file, rate_field, and exchange_rate parameters This implementation allows the site to work with EUR currency and supports translations to all major European languages, preparing for deployment at eursat.eu domain.
59 lines
2.3 KiB
JavaScript
59 lines
2.3 KiB
JavaScript
const axios = require('axios')
|
|
const fs = require('fs');
|
|
|
|
module.exports = {
|
|
bfx: async function() {
|
|
const eurrate = 0.92 // approximate EUR/USD rate
|
|
const btcDataURL = "https://api-pub.bitfinex.com/v2/ticker/tBTCUSD"
|
|
const response = await axios.get(btcDataURL)
|
|
const data = response.data
|
|
//console.log(data[6])
|
|
|
|
const satDenominator = 100000000
|
|
// see docs : https://docs.bitfinex.com/reference#rest-public-ticker
|
|
btcLastPrice = data[6]
|
|
|
|
const sateur = Math.round((1 / btcLastPrice) * satDenominator * eurrate)
|
|
//console.log("bitfinex last price: ", btcLastPrice, "current satEUR: ", sateur)
|
|
return sateur
|
|
},
|
|
|
|
get10yr: async function() {
|
|
// console.log("get10yr")
|
|
try {
|
|
// const content = await fs.readFile('./public/eur_historical')
|
|
const content = fs.readFileSync('./public/eur_historical', { encoding: 'utf8' })
|
|
|
|
const historical = JSON.parse(content)
|
|
hist_entries = []
|
|
let datelist = []
|
|
|
|
// get all the years you need from 1 - 10
|
|
for (let i = 1; i < 11; i++) {
|
|
const y = new Date(new Date().setFullYear(new Date().getFullYear() - i)).toISOString().slice(0, 10)
|
|
datelist.push(y)
|
|
}
|
|
for (let j = 0; j < historical.length; j++) {
|
|
const hdate = historical[j]['date']
|
|
if (datelist.includes(hdate)) {
|
|
hist_entries.push(historical[j])
|
|
}
|
|
}
|
|
// console.log(hist_entries)
|
|
let final_list = []
|
|
let today_sats = await this.bfx()
|
|
for (var v = 0; v < hist_entries.length; v++) {
|
|
const date = new Date(hist_entries[v]['date'])
|
|
year = date.getFullYear();
|
|
rawsat = hist_entries[v]['sateur_rate']
|
|
percentage = (-100 * ((rawsat - today_sats) / rawsat)).toFixed(3)
|
|
final_list.push({ "year": date.toLocaleDateString(), "sats": rawsat.toLocaleString("en-US"), "percent": percentage });
|
|
}
|
|
return final_list.reverse()
|
|
} catch (error) {
|
|
console.error("Error trying to read file ", error)
|
|
}
|
|
}
|
|
|
|
}
|