-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-api.js
More file actions
100 lines (89 loc) · 3.24 KB
/
Copy pathtest-api.js
File metadata and controls
100 lines (89 loc) · 3.24 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
#!/usr/bin/env node
import KalshiApi from './src/api/kalshiApi.js';
import { config } from './src/config/config.js';
import logger from './src/utils/logger.js';
/**
* Simple API test script to discover Kalshi data
*/
async function testApi() {
console.log('🧪 Testing Kalshi API Connection...\n');
try {
const api = new KalshiApi();
// Test 1: Get Exchange Status (public endpoint - should work)
console.log('✅ Test 1: Exchange Status');
try {
const status = await api.getExchangeStatus();
console.log(' Exchange Status:', status.status);
console.log(' Message:', status.message || 'No message');
} catch (error) {
console.log(' ❌ Failed:', error.message);
}
console.log();
// Test 2: Get Events (public endpoint)
console.log('✅ Test 2: Get Events');
try {
const events = await api.getEvents(5);
console.log(` Found ${events.events?.length || 0} events`);
if (events.events && events.events.length > 0) {
events.events.slice(0, 3).forEach(event => {
console.log(` - ${event.title} (${event.id})`);
});
}
} catch (error) {
console.log(' ❌ Failed:', error.message);
}
console.log();
// Test 3: Get Markets (public endpoint)
console.log('✅ Test 3: Get Markets');
try {
const markets = await api.getMarkets(5);
console.log(` Found ${markets.markets?.length || 0} markets`);
if (markets.markets && markets.markets.length > 0) {
markets.markets.slice(0, 3).forEach(market => {
console.log(` - ${market.title} (${market.id})`);
console.log(` Status: ${market.status}, Type: ${market.type}`);
});
}
} catch (error) {
console.log(' ❌ Failed:', error.message);
}
console.log();
// Test 4: Get Series (public endpoint)
console.log('✅ Test 4: Get Series');
try {
const series = await api.getSeries(5);
console.log(` Found ${series.series?.length || 0} series`);
if (series.series && series.series.length > 0) {
series.series.slice(0, 3).forEach(s => {
console.log(` - ${s.title} (${s.id})`);
});
}
} catch (error) {
console.log(' ❌ Failed:', error.message);
}
console.log();
// Test 5: Portfolio Balance (requires authentication)
console.log('✅ Test 5: Portfolio Balance (Authenticated)');
try {
const balance = await api.getPortfolioBalance();
console.log(' Balance:', balance.balance?.balance);
console.log(' Currency:', balance.balance?.currency);
} catch (error) {
console.log(' ❌ Authentication failed:', error.message);
console.log(' This means your API key needs to be configured properly');
}
console.log();
console.log('🎉 API Test Complete!');
console.log('\n📝 To discover more data:');
console.log(' 1. Fix your API key configuration');
console.log(' 2. Use the bot CLI commands');
console.log(' 3. Check the logs for detailed information');
} catch (error) {
console.error('❌ Test failed:', error.message);
}
}
// Run the test
testApi().catch((error) => {
console.error('❌ Test execution failed:', error.message);
process.exit(1);
});