-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathwallets.ts
More file actions
107 lines (86 loc) · 3.42 KB
/
wallets.ts
File metadata and controls
107 lines (86 loc) · 3.42 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
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
import { Client } from '@solana-tracker/data-api'
import { handleError } from './utils';
const client = new Client({
apiKey: process.env.SOLANA_TRACKER_API_KEY || 'YOUR_API_KEY'
});
const EXAMPLE_WALLET = 'FbMxP3GVq8TQ36nbYgx4NP9iygMpwAwFWJwW81ioCiSF';
// Quick overview of a wallet
export async function getWalletBasicInfo(walletAddress: string = EXAMPLE_WALLET) {
try {
const wallet = await client.getWalletBasic(walletAddress);
console.log('\n💼 Wallet Overview:');
console.log('Total Value:', `$${wallet.total.toFixed(2)}`);
console.log('Holdings:', wallet.tokens.length, 'tokens');
const sorted = [...wallet.tokens].sort((a, b) => b.value - a.value);
console.log('\nTop 3:');
sorted.slice(0, 3).forEach((token, i) => {
console.log(`${i + 1}. $${token.value.toFixed(2)} - ${token.address.slice(0, 8)}...`);
});
return wallet;
} catch (error) {
handleError(error);
}
}
// Detailed portfolio view
export async function getWalletDetailedInfo(walletAddress: string = EXAMPLE_WALLET) {
try {
const wallet = await client.getWallet(walletAddress);
console.log('\n📊 Portfolio Details:');
console.log('Total:', `$${wallet.total.toFixed(2)}`);
console.log('SOL:', `${wallet.totalSol.toFixed(4)}`);
const sorted = [...wallet.tokens].sort((a, b) => b.value - a.value);
console.log('\nAll Holdings:');
sorted.slice(0, 10).forEach((token, i) => {
const symbol = token.token.symbol || 'Unknown';
console.log(`${i + 1}. ${symbol} - $${token.value.toFixed(2)} (${token.balance.toFixed(2)} tokens)`);
});
return wallet;
} catch (error) {
handleError(error);
}
}
// Paginated wallet view
export async function getWalletWithPagination(walletAddress: string = EXAMPLE_WALLET, page: number = 1) {
try {
const wallet = await client.getWalletPage(walletAddress, page);
console.log(`\n📄 Portfolio (page ${page}):`);
console.log(`${wallet.tokens.length} tokens shown`);
wallet.tokens.forEach((token, i) => {
const symbol = token.token.symbol || token.token.mint;
console.log(`${i + 1}. ${symbol}: $${token.value.toFixed(2)}`);
});
return wallet;
} catch (error) {
handleError(error);
}
}
// Trading activity
export async function getWalletTrades(walletAddress: string = EXAMPLE_WALLET) {
try {
const trades = await client.getWalletTrades(walletAddress, undefined, true, true);
console.log(`\n📈 Recent Trades (${trades.trades.length} found):`);
trades.trades.slice(0, 10).forEach((trade, i) => {
const date = new Date(trade.time).toLocaleTimeString();
const type = trade.type ? trade.type.toUpperCase() : 'SWAP';
console.log(`${i + 1}. [${date}] ${type} - Tx: ${trade.tx.slice(0, 8)}...`);
});
return trades;
} catch (error) {
handleError(error);
}
}
// Get wallet PnL chart
export async function getWalletChart(walletAddress: string = EXAMPLE_WALLET) {
try {
const chart = await client.getWalletChart(walletAddress);
console.log('\n📉 Portfolio Performance:');
if (chart.pnl) {
console.log('24h:', chart.pnl['24h'] ? `${chart.pnl['24h'].toFixed(2)}%` : 'N/A');
console.log('7d:', chart.pnl['7d'] ? `${chart.pnl['7d'].toFixed(2)}%` : 'N/A');
console.log('30d:', chart.pnl['30d'] ? `${chart.pnl['30d'].toFixed(2)}%` : 'N/A');
}
return chart;
} catch (error) {
handleError(error);
}
}