Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | 57x 57x 57x 2x 2x 2x 2x 2x 2x 2x 57x 57x | import { sdk } from "../../index.client"
import axios from 'axios'
export async function updateChaintracksFiatExchangeRates(targetCurrencies: string[], options: sdk.WalletServicesOptions): Promise<sdk.FiatExchangeRates> {
const url = options.chaintracksFiatExchangeRatesUrl
Iif (!url)
throw new sdk.WERR_MISSING_PARAMETER('options.chaintracksFiatExchangeRatesUrl')
const r = await axios.get(url)
Iif (r.status !== 200 || !r.data || r.data.status != "success") {
throw new sdk.WERR_BAD_REQUEST(`${url} returned status ${r.status}`)
}
const rates = <sdk.FiatExchangeRates>r.data.value
rates.timestamp = new Date(rates.timestamp)
return rates
}
export async function updateExchangeratesapi(targetCurrencies: string[], options: sdk.WalletServicesOptions): Promise<sdk.FiatExchangeRates> {
Iif (!options.exchangeratesapiKey)
throw new sdk.WERR_MISSING_PARAMETER('options.exchangeratesapiKey')
const iorates = await getExchangeRatesIo(options.exchangeratesapiKey)
Iif (!iorates.success)
throw new sdk.WERR_BAD_REQUEST(`getExchangeRatesIo returned success ${iorates.success}`)
Iif (!iorates.rates["USD"] || !iorates.rates[iorates.base])
throw new sdk.WERR_BAD_REQUEST(`getExchangeRatesIo missing rates for 'USD' or base`)
const r: sdk.FiatExchangeRates = {
timestamp: new Date(iorates.timestamp * 1000),
base: 'USD',
rates: {}
}
const basePerUsd = iorates.rates[iorates.base] / iorates.rates["USD"]
let updates = 0
for (const [key, value] of Object.entries(iorates.rates)) {
Iif (targetCurrencies.indexOf(key) > -1) {
r.rates[key] = value * basePerUsd
updates++
}
}
Iif (updates !== targetCurrencies.length)
throw new sdk.WERR_BAD_REQUEST(`getExchangeRatesIo failed to update all target currencies`)
//console.log(`new fiat rates=${JSON.stringify(r)}`)
return r
}
export interface ExchangeRatesIoApi {
success: boolean,
timestamp: number,
base: "EUR" | "USD"
date: string
rates: Record<string, number>
}
export async function getExchangeRatesIo(key: string): Promise<ExchangeRatesIoApi> {
const url = `http://api.exchangeratesapi.io/v1/latest?access_key=${key}`
const r = await axios.get(url)
Iif (r.status !== 200 || !r.data) {
throw new sdk.WERR_BAD_REQUEST(`getExchangeRatesIo returned status ${r.status}`)
}
const rates = <ExchangeRatesIoApi>r.data
return rates
}
/*
{
"success": true,
"timestamp": 1702405384,
"base": "EUR",
"date": "2023-12-12",
"rates": {
"AED": 3.96261,
"AFN": 74.453362,
"ALL": 101.807155,
"AMD": 435.489459,
"ANG": 1.944069,
"AOA": 897.226337,
"ARS": 395.468082,
"AUD": 1.646886,
"AWG": 1.942271,
"AZN": 1.832044,
"BAM": 1.95407,
"BBD": 2.177971,
"BDT": 118.654929,
"BGN": 1.956827,
"BHD": 0.406753,
"BIF": 3078.499675,
"BMD": 1.079039,
"BND": 1.446102,
"BOB": 7.4534,
"BRL": 5.35741,
"BSD": 1.07874,
"BTC": 0.000026145469,
"BTN": 89.916078,
"BWP": 14.715901,
"BYN": 3.553337,
"BYR": 21149.174075,
"BZD": 2.174364,
"CAD": 1.468287,
"CDF": 2875.640503,
"CHF": 0.945353,
"CLF": 0.034313,
"CLP": 948.09775,
"CNY": 7.743512,
"COP": 4307.525658,
"CRC": 569.093422,
"CUC": 1.079039,
"CUP": 28.594547,
"CVE": 110.978933,
"CZK": 24.507795,
"DJF": 191.766554,
"DKK": 7.457544,
"DOP": 61.505535,
"DZD": 145.236415,
"EGP": 33.367028,
"ERN": 16.185592,
"ETB": 60.199033,
"EUR": 1,
"FJD": 2.416779,
"FKP": 0.859886,
"GBP": 0.859574,
"GEL": 2.880527,
"GGP": 0.859886,
"GHS": 12.980915,
"GIP": 0.859886,
"GMD": 72.726644,
"GNF": 9285.134874,
"GTQ": 8.443457,
"GYD": 225.859997,
"HKD": 8.426031,
"HNL": 26.685156,
"HRK": 7.598132,
"HTG": 142.513142,
"HUF": 382.707793,
"IDR": 16801.292339,
"ILS": 4.007585,
"IMP": 0.859886,
"INR": 89.987955,
"IQD": 1414.081256,
"IRR": 45602.907562,
"ISK": 151.109018,
"JEP": 0.859886,
"JMD": 167.700721,
"JOD": 0.765366,
"JPY": 157.115675,
"KES": 165.523229,
"KGS": 96.379362,
"KHR": 4440.24707,
"KMF": 493.571281,
"KPW": 971.097551,
"KRW": 1417.685123,
"KWD": 0.332733,
"KYD": 0.8989,
"KZT": 493.04112,
"LAK": 22368.488843,
"LBP": 16154.243871,
"LKR": 352.747636,
"LRD": 203.02122,
"LSL": 20.582684,
"LTL": 3.186123,
"LVL": 0.6527,
"LYD": 5.211954,
"MAD": 10.976529,
"MDL": 19.340873,
"MGA": 4939.301335,
"MKD": 61.507276,
"MMK": 2265.283559,
"MNT": 3705.780074,
"MOP": 8.676817,
"MRU": 42.727878,
"MUR": 47.690625,
"MVR": 16.584924,
"MWK": 1816.023037,
"MXN": 18.69803,
"MYR": 5.052606,
"MZN": 68.249194,
"NAD": 20.588506,
"NGN": 865.924709,
"NIO": 39.6024,
"NOK": 11.848426,
"NPR": 143.865605,
"NZD": 1.761931,
"OMR": 0.415394,
"PAB": 1.07864,
"PEN": 4.073376,
"PGK": 4.025102,
"PHP": 59.974075,
"PKR": 306.446851,
"PLN": 4.334063,
"PYG": 7963.910929,
"QAR": 3.928776,
"RON": 4.973399,
"RSD": 117.196649,
"RUB": 97.248412,
"RWF": 1351.496966,
"SAR": 4.047186,
"SBD": 9.12268,
"SCR": 14.561036,
"SDG": 648.5028,
"SEK": 11.285032,
"SGD": 1.449037,
"SHP": 1.312921,
"SLE": 24.488188,
"SLL": 21311.029931,
"SOS": 616.131981,
"SRD": 40.655509,
"STD": 22333.938945,
"SYP": 14029.21897,
"SZL": 20.587826,
"THB": 38.597298,
"TJS": 11.757734,
"TMT": 3.776638,
"TND": 3.377493,
"TOP": 2.551714,
"TRY": 31.312865,
"TTD": 7.321483,
"TWD": 34.012943,
"TZS": 2697.598652,
"UAH": 39.917867,
"UGX": 4102.367289,
"USD": 1.079039,
"UYU": 42.422631,
"UZS": 13299.161683,
"VEF": 3838024.202021,
"VES": 38.392542,
"VND": 26188.28851,
"VUV": 129.693288,
"WST": 2.964402,
"XAF": 655.37362,
"XAG": 0.047456,
"XAU": 0.000545,
"XCD": 2.916158,
"XDR": 0.811478,
"XOF": 657.134976,
"XPF": 119.331742,
"YER": 270.110528,
"ZAR": 20.470755,
"ZMK": 9712.646776,
"ZMW": 26.319693,
"ZWL": 347.450277
}
}
*/ |