-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
73 lines (60 loc) · 2.28 KB
/
index.js
File metadata and controls
73 lines (60 loc) · 2.28 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
require('dotenv').config();
const config = require('./config');
const { getConnection } = require('./src/core/connection');
const { getWallet } = require('./src/core/wallet');
const { startScheduler } = require('./src/strategy/scheduler');
const { startDashboard, updateAgentStatus, addEquityHistory } = require('./src/monitoring/dashboard');
const { sendStartup } = require('./src/monitoring/telegram');
const logger = require('./src/monitoring/logger');
async function main() {
try {
logger.log('INFO', 'Starting Gtrade Agent...');
// Test koneksi
const connection = getConnection();
await connection.getSlot();
logger.log('INFO', 'RPC connection OK');
// Load wallet
const wallet = getWallet();
const walletAddress = wallet.publicKey.toBase58();
logger.log('INFO', `Wallet loaded: ${walletAddress}`);
// Hitung initial capital (default $40 = $20 SOL + $20 USDC)
// Ini bisa disesuaikan dengan membaca dari config nantinya
const initialCapital = config.trading.initial_capital || 40;
// Start dashboard with initial data
const dashboardPort = config.monitoring.dashboard_port || 3000;
startDashboard(dashboardPort, {
initialCapital: initialCapital,
status: 'RUNNING',
startTime: Date.now()
});
// Update agent status di dashboard
updateAgentStatus({
status: 'RUNNING',
startTime: Date.now(),
initialCapital: initialCapital,
currentBalance: initialCapital,
marketTrend: 'SIDEWAYS',
totalFeeCollected: 0,
lastUpdate: Date.now()
});
// Add initial equity history point
addEquityHistory(initialCapital);
// Start scheduler
await startScheduler();
// Kirim notifikasi startup
await sendStartup(walletAddress, 'Helius (primary)');
logger.log('INFO', 'Gtrade Agent is running...');
logger.log('INFO', `Dashboard available at http://localhost:${dashboardPort}`);
// Keep process alive
process.on('SIGINT', () => {
logger.log('INFO', 'Shutting down Gtrade Agent...');
updateAgentStatus({ status: 'STOPPED' });
process.exit(0);
});
} catch (error) {
logger.log('ERROR', `Fatal error: ${error.message}`);
updateAgentStatus({ status: 'STOPPED' });
process.exit(1);
}
}
main();