-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSocketHandlerFrontend.mjs
131 lines (103 loc) · 3.92 KB
/
SocketHandlerFrontend.mjs
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
import { createRequire } from "module";
const require = createRequire(import.meta.url);
const io = require("socket.io-client");
console.clear();
const LANDING_SOCKET = io.connect("http://localhost:2424/");
// example for user input in search bar.
// LANDING_SOCKET.emit("search","frax")
// example for search_res: [{ '0xd632f22692FaC7611d2AA1C0D552930D43CAEd3B': 'FRAX/3Crv' },{...}]
LANDING_SOCKET.on("search_res", (data) => {
console.log("search_res", data);
});
// Ping-Pong:
setInterval(() => {
LANDING_SOCKET.emit("ping");
}, 2 * 1000); // pings every 2 seconds
LANDING_SOCKET.on("pong", () => {
// console.log("pong") // => server alive
});
// setting up the socket for sUSD
const WHITELISTED_POOL = "0xA5407eAE9Ba41422680e2e00537571bcC53efBfD";
const POOL_ADDRESS = WHITELISTED_POOL;
const POOL_SOCKET = io.connect("http://localhost:2424/" + POOL_ADDRESS);
POOL_SOCKET.on("token names inside pool", (data) => {
console.log("\ntoken names inside pool", data);
});
POOL_SOCKET.on("message", (data) => {
console.log(data);
});
/**
* sending out full data on init connect
*/
POOL_SOCKET.on("table_all", (data) => {
// handle JSON-data here
console.log("\n<table_all>", data.length, "entries send");
// console.log(data)
});
POOL_SOCKET.on("table_mev", (data) => {
// handle JSON-data here
console.log("<table_mev>", data.length, "entries send");
// console.log(data)
});
// example for price_chart_combination: [ 'sUSD', 'USDC' ] => price of sUSD in USDC (default)
POOL_SOCKET.on("price_chart_combination", (data) => {
console.log("\nprice_chart_combinations:", data);
});
// example for price_chart: [ { '1675078547': 1.00078609029431 },{ '1675081511': 1.0007863914931368 },{...} ]
POOL_SOCKET.on("price_chart", (data) => {
// handle JSON-data here
console.log("\n<price_chart>", data.length, "entries send");
});
// example for balances_chart: [ { '1672493903': [ 18636729, 18298801, 17929766, 16040727 ] },{ '1672494839': [ 18636729, 18298801, 17929766, 16040727 ] },{...} ]
POOL_SOCKET.on("balances_chart", (data) => {
// handle JSON-data here
console.log("\n<balances_chart>", data.length, "entries send");
});
// example for volume_chart: [ { '1675078547': 865 },{ '1675081511': 1216 },{...} ]
POOL_SOCKET.on("volume_chart", (data) => {
// handle JSON-data here
console.log("\n<volume_chart>", data.length, "entries send");
});
// example for tvl_chart: [ { '1675078547': 70906023 },{ '1675081511': 70904179 },{...} ]
POOL_SOCKET.on("tvl_chart", (data) => {
// handle JSON-data here
console.log("\n<tvl_chart>", data.length, "entries send");
});
POOL_SOCKET.on("bonding_curve", (data) => {
// handle JSON-data here
console.log("\n<bonding_curve>", data);
});
/**
* Updates, only latest entry, without history
*/
POOL_SOCKET.on("Update Table-ALL", (data) => {
// handle JSON-data here
console.log("Update Table-ALL", data);
});
POOL_SOCKET.on("Update Table-MEV", (data) => {
// handle JSON-data here
console.log("Update Table-MEV", data);
});
POOL_SOCKET.on("Update Price-Chart", (data) => {
// handle JSON-data here
console.log("Update Price-Chart", data);
});
POOL_SOCKET.on("Update Balance-Chart", (data) => {
// handle JSON-data here
console.log("Update Balance-Chart", data);
});
POOL_SOCKET.on("Update Volume-Chart", (data) => {
// handle JSON-data here
console.log("Update Volume-Chart", data);
});
POOL_SOCKET.on("Update TVL-Chart", (data) => {
// handle JSON-data here
console.log("Update TVL-Chart", data);
});
const timeFrame = "day";
// let timeFrame = "week"
// let timeFrame = "month"
// POOL_SOCKET.emit(timeFrame) not to be used on init connection (defaults to 1 month). Only used when a user starts changing time-spans
// POOL_SOCKET.emit(timeFrame)
// example for price-combination-request
POOL_SOCKET.emit("new combination", ["day", "sUSD", "USDC"]);