fix: ensure proxy is used by @polymarket/clob-client
Add proxy-patch.cjs that patches https.request BEFORE axios is loaded. This forces all Polymarket API calls through the proxy, including internal axios instances used by @polymarket/clob-client. Import patch as very first thing in sniper.js and sniper-tui.js. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,9 @@
|
||||
* npm run sniper-tui-sim (simulation)
|
||||
*/
|
||||
|
||||
// Load proxy patch BEFORE any other imports (must patch https before axios is loaded)
|
||||
import './utils/proxy-patch.cjs';
|
||||
|
||||
import { validateMMConfig } from './config/index.js';
|
||||
import config from './config/index.js';
|
||||
import logger from './utils/logger.js';
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
* For the TUI dashboard version, use: npm run sniper-tui
|
||||
*/
|
||||
|
||||
// Load proxy patch BEFORE any other imports (must patch https before axios is loaded)
|
||||
import './utils/proxy-patch.cjs';
|
||||
|
||||
import { validateMMConfig } from './config/index.js';
|
||||
import config from './config/index.js';
|
||||
import logger from './utils/logger.js';
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* proxy-patch.cjs
|
||||
* CommonJS module to patch https.request BEFORE any axios imports.
|
||||
* This ensures @polymarket/clob-client uses the proxy.
|
||||
*
|
||||
* Must be imported as very first thing in the app.
|
||||
* In ES modules: import './proxy-patch.cjs'
|
||||
*/
|
||||
const https = require('https');
|
||||
const http = require('http');
|
||||
const { HttpsProxyAgent } = require('https-proxy-agent');
|
||||
|
||||
const PROXY_URL = process.env.PROXY_URL || '';
|
||||
|
||||
if (PROXY_URL) {
|
||||
const agent = new HttpsProxyAgent(PROXY_URL);
|
||||
const originalHttpsRequest = https.request.bind(https);
|
||||
|
||||
// Polymarket domains that must go through proxy
|
||||
const POLY_DOMAINS = [
|
||||
'polymarket.com',
|
||||
'clob.polymarket.com',
|
||||
'gamma-api.polymarket.com',
|
||||
'data-api.polymarket.com',
|
||||
];
|
||||
|
||||
function shouldProxy(url) {
|
||||
try {
|
||||
const hostname = new URL(url).hostname;
|
||||
return POLY_DOMAINS.some(domain => hostname === domain || hostname.endsWith(`.${domain}`));
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Patch https.request
|
||||
https.request = function(...args) {
|
||||
const url = args[0];
|
||||
if (typeof url === 'string' && shouldProxy(url)) {
|
||||
const options = args[1] || {};
|
||||
options.agent = agent;
|
||||
return originalHttpsRequest(url, options);
|
||||
}
|
||||
return originalHttpsRequest(...args);
|
||||
};
|
||||
|
||||
console.log(`[proxy-patch] HTTPS patched for Polymarket routing via proxy`);
|
||||
}
|
||||
Reference in New Issue
Block a user