Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
34 lines (29 loc) · 1.62 KB
/
Copy pathscript.js
File metadata and controls
34 lines (29 loc) · 1.62 KB
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
import { CountUp } from "countup.js";
const trades = await fetch(`https://data-api.polymarket.com/trades?user=0xe9bcfe9e39e9e14b01920738009f050f8c229ec0&limit=10000&market=0xb0f15a2e601a224e803babc18f2cb93442921dc45930ec0ecef32e48d8cac352,0x0cfaa8fabad4d452be63950f47b07339ce192820df5d64569496fb91eb55b502&takerOnly=false`).then(response => response.json());
const positions = await fetch(`https://data-api.polymarket.com/positions?user=0xe9bcfe9e39e9e14b01920738009f050f8c229ec0&market=0xb0f15a2e601a224e803babc18f2cb93442921dc45930ec0ecef32e48d8cac352,0x0cfaa8fabad4d452be63950f47b07339ce192820df5d64569496fb91eb55b502`).then(response => response.json());
const markets = {
// burgas
"0xb0f15a2e601a224e803babc18f2cb93442921dc45930ec0ecef32e48d8cac352": {
netInvested: 0,
shares: 0
},
// sofia
"0x0cfaa8fabad4d452be63950f47b07339ce192820df5d64569496fb91eb55b502": {
netInvested: 0,
shares: 0
}
};
for (const trade of trades) {
const value = trade.size * trade.price;
if (trade.side === "BUY") markets[trade.conditionId].netInvested += value;
if (trade.side === "SELL") markets[trade.conditionId].netInvested -= value;
};
for (const position of positions) {
markets[position.conditionId].shares = position.size;
};
Object.values(markets).reduce(async (total, value) => {
document.body.classList.add("loaded");
new CountUp(document.querySelector("#total-bet h1"), total.netInvested + value.netInvested, { prefix: "$" }).start();
await new Promise(resolve => setTimeout(resolve, 3000));
new CountUp(document.querySelector("#win h1"), (total.shares - total.netInvested) + (value.shares - value.netInvested), { prefix: "$" }).start();
});