-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.js
80 lines (73 loc) · 1.94 KB
/
query.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
const axios = require('axios');
require("dotenv").config();
const query = `
query TopTrades {
swaps(first: 10, orderBy: amountUSD, orderDirection: desc) {
id
amountUSD
transaction {
id
}
pair {
token0 {
symbol
}
token1 {
symbol
}
}
}
}
`;
const fetchTopTrades = async () => {
const url = process.env.UNISWAP_SUBGRAPH_URL;
console.log("Constructed URL:", url);
try {
const response = await axios.post(
url,
{
query: query,
variables: {},
},
{
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.GRAPH_API_KEY}`, // Include if API key is needed
},
},
);
if (response.data.errors) {
console.error("GraphQL Errors:", response.data.errors);
return;
}
const trades = response.data.data.swaps;
trades.forEach((trade) => {
const token0Symbol =
trade.pair.token0.symbol === "unknown"
? "Unknown Token"
: trade.pair.token0.symbol;
const token1Symbol =
trade.pair.token1.symbol === "unknown"
? "Unknown Token"
: trade.pair.token1.symbol;
console.log(`Trade ID: ${trade.id}`);
console.log(` Transaction ID: ${trade.transaction.id}`);
console.log(
` Amount (USD): ${parseFloat(trade.amountUSD).toExponential()}`,
);
console.log(` Pair: ${token0Symbol} / ${token1Symbol}`);
console.log("---------------------------------------");
});
} catch (error) {
console.error("Error Details:", error);
if (error.response) {
console.error("Error Response:", error.response.data);
} else if (error.request) {
console.error("No Response:", error.request);
} else {
console.error("Axios Error:", error.message);
}
console.error("Error Config:", error.config);
}
};
fetchTopTrades();