refactor of data-service
This commit is contained in:
parent
6fb98c69f2
commit
09c97df1a8
49 changed files with 2394 additions and 112 deletions
160
test-ib-working.ts
Normal file
160
test-ib-working.ts
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
/**
|
||||
* Working Interactive Brokers test with verified network monitoring
|
||||
*/
|
||||
import { Browser } from '@stock-bot/browser';
|
||||
|
||||
async function testIBWithWorking() {
|
||||
console.log('🏦 Testing IB with working network monitoring and fixed proxy auth...');
|
||||
|
||||
try {
|
||||
await Browser.initialize({
|
||||
headless: true,
|
||||
timeout: 20000,
|
||||
blockResources: false, // Don't block resources initially
|
||||
});
|
||||
|
||||
// Test 1: Try a simple proxy detection service first
|
||||
console.log('🌐 Testing proxy connectivity...');
|
||||
const { page: proxyPage, contextId: proxyCtx } = await Browser.createPageWithProxy(
|
||||
'https://httpbin.org/ip',
|
||||
'http://doimvbnb-US-rotate:w5fpiwrb9895@p.webshare.io:80'
|
||||
);
|
||||
|
||||
let proxyEvents = 0;
|
||||
let myIP = null;
|
||||
proxyPage.onNetworkEvent(event => {
|
||||
proxyEvents++;
|
||||
if (event.type === 'response' && event.url.includes('/ip') && event.responseData) {
|
||||
try {
|
||||
const data = JSON.parse(event.responseData);
|
||||
myIP = data.origin;
|
||||
console.log(` 📍 Proxy IP: ${myIP}`);
|
||||
} catch (e) {
|
||||
console.log(` 📊 Raw response: ${event.responseData}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await proxyPage.waitForLoadState('domcontentloaded');
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
await Browser.closeContext(proxyCtx);
|
||||
|
||||
console.log(`📊 Proxy test events: ${proxyEvents}`);
|
||||
|
||||
// Test 2: Try IB API endpoint with fixed proxy auth
|
||||
console.log('🎯 Testing IB API endpoint...');
|
||||
const { page: apiPage, contextId: apiCtx } = await Browser.createPageWithProxy(
|
||||
'https://www.interactivebrokers.com/webrest/search/product-types/summary',
|
||||
'http://doimvbnb-US-rotate:w5fpiwrb9895@p.webshare.io:80'
|
||||
);
|
||||
|
||||
let apiEvents = 0;
|
||||
let summaryData = null;
|
||||
apiPage.onNetworkEvent(event => {
|
||||
apiEvents++;
|
||||
console.log(` 📡 API Event: ${event.type} ${event.method} ${event.url}`);
|
||||
|
||||
if (event.type === 'response' && event.url.includes('summary')) {
|
||||
console.log(` 🎯 Found summary response! Status: ${event.status}`);
|
||||
if (event.responseData) {
|
||||
summaryData = event.responseData;
|
||||
try {
|
||||
const data = JSON.parse(event.responseData);
|
||||
console.log(` 📊 Summary data: ${JSON.stringify(data, null, 2)}`);
|
||||
} catch (e) {
|
||||
console.log(` 📊 Raw summary: ${event.responseData.substring(0, 200)}...`);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await apiPage.waitForLoadState('domcontentloaded');
|
||||
await new Promise(resolve => setTimeout(resolve, 3000));
|
||||
await Browser.closeContext(apiCtx);
|
||||
|
||||
return {
|
||||
proxyEvents,
|
||||
apiEvents,
|
||||
summaryData,
|
||||
proxyIP: myIP,
|
||||
success: apiEvents > 0 || summaryData !== null,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('❌ IB test failed:', error);
|
||||
return {
|
||||
proxyEvents: 0,
|
||||
apiEvents: 0,
|
||||
summaryData: null,
|
||||
proxyIP: null,
|
||||
success: false,
|
||||
error: error.message,
|
||||
};
|
||||
} finally {
|
||||
await Browser.close();
|
||||
}
|
||||
}
|
||||
|
||||
async function testWithProxyFallback() {
|
||||
console.log('\n🔄 Testing with proxy fallback strategy...');
|
||||
|
||||
const proxiesToTest = [
|
||||
'http://doimvbnb-US-rotate:w5fpiwrb9895@p.webshare.io:80', // Your proxy
|
||||
];
|
||||
|
||||
for (const proxy of proxiesToTest) {
|
||||
console.log(`\n🌐 Testing with: ${proxy || 'No proxy'}`);
|
||||
|
||||
try {
|
||||
await Browser.initialize({
|
||||
headless: true,
|
||||
timeout: 15000,
|
||||
blockResources: false,
|
||||
});
|
||||
|
||||
const { page, contextId } = await Browser.createPageWithProxy(
|
||||
'https://httpbin.org/ip',
|
||||
proxy
|
||||
);
|
||||
|
||||
let ipResponse = null;
|
||||
page.onNetworkEvent(event => {
|
||||
if (event.type === 'response' && event.url.includes('/ip') && event.responseData) {
|
||||
ipResponse = event.responseData;
|
||||
console.log(` 📍 IP: ${JSON.parse(event.responseData).origin}`);
|
||||
}
|
||||
});
|
||||
|
||||
await page.waitForLoadState('domcontentloaded');
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
await Browser.closeContext(contextId);
|
||||
} catch (error) {
|
||||
console.log(` ❌ Failed: ${error.message}`);
|
||||
} finally {
|
||||
await Browser.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function runIBTests() {
|
||||
console.log('🚀 Interactive Brokers Network Monitoring Tests with Fixed Proxy Auth\n');
|
||||
|
||||
const result = await testIBWithWorking();
|
||||
await testWithProxyFallback();
|
||||
|
||||
console.log('\n🏁 Final Results:');
|
||||
console.log(` 🌐 Proxy events: ${result.proxyEvents || 0}`);
|
||||
console.log(` 📍 Proxy IP: ${result.proxyIP || 'Not captured'}`);
|
||||
console.log(` 🎯 API events: ${result.apiEvents || 0}`);
|
||||
console.log(` 📊 Summary data: ${result.summaryData ? 'Captured' : 'Not captured'}`);
|
||||
console.log(` ✅ Overall success: ${result.success}`);
|
||||
|
||||
if (result.error) {
|
||||
console.log(` ❌ Error: ${result.error}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (import.meta.main) {
|
||||
runIBTests().catch(console.error);
|
||||
}
|
||||
|
||||
export { testIBWithWorking, testWithProxyFallback };
|
||||
Loading…
Add table
Add a link
Reference in a new issue