forked from anpigon/steem-keychain-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postprocess.js
141 lines (132 loc) · 4.49 KB
/
postprocess.js
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
import { readJSON, writeJSON } from "https://deno.land/x/flat/mod.ts";
/// bittrex
async function bittrex() {
const filename = Deno.args[0];
const data = await readJSON(filename);
function calculateValue(market, btc) {
const { Bid, PrevDay } = market;
const Daily = ((Bid - PrevDay) / PrevDay) * 100;
const PrevDayUsd = btc.PrevDay * PrevDay;
const Usd = Bid * btc.Bid;
const DailyUsd = ((Usd - PrevDayUsd) / PrevDayUsd) * 100;
return {
Bid,
PrevDay,
Daily: Daily.toFixed(2),
Usd: Usd.toFixed(2),
DailyUsd: DailyUsd.toFixed(2),
};
}
const btc = data.result.find((item) => item.MarketName === "USD-BTC");
const steem = data.result.find((item) => item.MarketName === "BTC-STEEM");
const sbd = data.result.find((item) => item.MarketName === "BTC-SBD");
const trx = data.result.find((item) => item.MarketName === "BTC-TRX");
const hive = data.result.find((item) => item.MarketName === "BTC-HIVE");
const hbd = data.result.find((item) => item.MarketName === "BTC-HBD");
const newData = {
btc: {
Bid: btc.Bid,
PrevDay: btc.PrevDay,
Daily: (((btc.Bid - btc.PrevDay) / btc.PrevDay) * 100).toFixed(2),
},
steem: calculateValue(steem, btc),
sbd: calculateValue(sbd, btc),
trx: calculateValue(trx, btc),
hive: calculateValue(hive, btc),
hbd: calculateValue(hbd, btc),
};
await writeJSON("flat/bittrex_price.json", newData);
}
await bittrex();
/// coinmarketcap
async function coinmarketcap() {
const response = await fetch(
"https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?symbol=STEEM,SBD,TRX,BTC,USDT",
{
headers: {
"X-CMC_PRO_API_KEY": Deno.env.get("COINMARKETCAP_API_KEY"),
},
}
);
const { data } = await response.json();
await writeJSON("flat/coinmarketcap_price.json", data);
const price = {
btc: {
Usd: data["BTC"]['quote']['USD']["price"],
DailyUsd: data["BTC"]['quote']['USD']["percent_change_24h"],
DailyVolume: data["BTC"]['quote']['USD']["volume_24h"],
},
steem: {
Usd: data["STEEM"]['quote']['USD']["price"],
DailyUsd: data["STEEM"]['quote']['USD']["percent_change_24h"],
DailyVolume: data["STEEM"]['quote']['USD']["volume_24h"],
},
sbd: {
Usd: data["SBD"]['quote']['USD']["price"],
DailyUsd: data["SBD"]['quote']['USD']["percent_change_24h"],
DailyVolume: data["SBD"]['quote']['USD']["volume_24h"],
},
trx: {
Usd: data["TRX"]['quote']['USD']["price"],
DailyUsd: data["TRX"]['quote']['USD']["percent_change_24h"],
DailyVolume: data["TRX"]['quote']['USD']["volume_24h"],
},
};
await writeJSON("flat/price.json", price);
}
await coinmarketcap();
/// steemAPINodeStatus
async function steemAPINodeStatus() {
const rpcList = [
"https://api.steemit.com",
"https://api.steemitdev.com",
"https://api.justyy.com",
"https://e51ewpb9dk.execute-api.us-east-1.amazonaws.com/release",
"https://api.steemyy.com",
"https://api.steemzzang.com",
"https://x68bp3mesd.execute-api.ap-northeast-1.amazonaws.com/release",
"https://cn.steems.top",
"https://justyy.azurewebsites.net/api/steem",
"https://steem.justyy.workers.dev",
"https://steem.ecosynthesizer.com",
"https://steem.61bts.com",
"https://api.steem.buzz",
"https://api.steem.fans",
];
const start = Date.now();
const response = await Promise.all(
rpcList.map((url) => {
return fetch(url)
.then((r) => r.json())
.then((r) => {
const ping = Date.now() - start;
return {
...r,
ping,
url,
};
})
.catch((e) => ({ status: "FAIL", message: e.message, url }));
})
);
const rpc_default = response.find(e => e.url === 'https://api.steemit.com');
const rpc_fastest = response
.filter((e) => e.status === "OK" && !e.url.includes("dev"))
.sort((a, b) => a.ping - b.ping)[0];
await writeJSON("flat/rpc_all.json", response);
await writeJSON("flat/rpc_default.json", rpc_default);
await writeJSON("flat/rpc_fastest.json", rpc_fastest);
}
await steemAPINodeStatus();
/// phishingAccounts
async function phishingAccounts() {
const response = await fetch(
"https://raw.githubusercontent.com/steemit/condenser/master/src/app/utils/BadActorList.js"
).then((r) => r.text());
const phishingAccounts = response
.split("`")[1]
.split("\n")
.filter((e) => e);
await writeJSON("flat/phishing_accounts.json", phishingAccounts);
}
await phishingAccounts();