mirror of
https://github.com/aljazceru/satshkd-vercel.git
synced 2025-12-17 05:04:24 +01:00
- Removed all HKD routes (/en, /zh-cn, /zh-hk) from index.js - Removed HKD locale files (en.json, zh-cn.json, zh-hk.json) - Removed HKD calculation files (calculate.js, btcpoll.js, updaterate.js from old version) - Removed HKD historical data files (hkd_historical, hkd_historical_dedup) - Renamed EUR-specific files to standard names: - calculate-eur.js -> calculate.js - btcpoll-eur.js -> btcpoll.js - updaterate-eur.js -> updaterate.js - eur_historical -> historical - Updated all locale files to reference 'historical' instead of 'eur_historical' - Updated default route to redirect to /en-eur instead of /en - Updated GitHub Actions workflow to only run EUR data updates - Updated all references in code to use renamed files This creates a clean EUR-only implementation ready for deployment at eursat.eu
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/historical')
|
|
const content = fs.readFileSync('./public/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)
|
|
}
|
|
}
|
|
|
|
}
|