valuecell icon indicating copy to clipboard operation
valuecell copied to clipboard

`RequestTimeout` on OKX due to missing `aiohttp_trust_env=True`

Open byronwang2005 opened this issue 1 year ago • 2 comments

Description:

When initializing ccxt.async_support.okx() via CCXTExecutionGateway, the exchange fails to load markets (e.g., fetch_ticker('BTC/USDT:USDT')) with ccxt.base.errors.RequestTimeout, even though the same requests succeed via curl under identical proxy setup (HTTPS_PROXY=http://127.0.0.1:10808).

Evidence:

  • ✅ curl -v "https://www.okx.com/api/v5/public/instruments?instType=FUTURES " succeeds.
  • ❌ Python runtime fails with:
    okx GET https://www.okx.com/api/v5/public/instruments?instType=SPOT  
    okx GET https://www.okx.com/api/v5/public/instruments?instType=FUTURES  
    
  • aiohttp attempts to connect to link-local 169.254.0.2:443, confirming proxy is not used.
  • Code inspection reveals:
    • Project loads .env (incl. HTTPS_PROXY) at startup (app.py:41–69).
    • But CCXTExecutionGateway only merges user config into options, not top-level keys like aiohttp_trust_env.
    • Thus, aiohttp never reads HTTPS_PROXY, and requests go bare → time out or get DNS-routed to unreachable IPs.

Root Causes:
aiohttp_trust_env=True is not passed at top level of ccxt.async_support config → proxy ignored.

Impact:

  • All async OKX calls fail (market data, execution, etc.).
  • Affects all instrument types (SPOT, FUTURES, SWAP).
  • Blocks local development & agent testing.

byronwang2005 avatar Dec 02 '25 03:12 byronwang2005

Hi @byronwang2005, thanks for the detailed report!

However, I would not recommend using the aiohttp_trust_env parameter to resolve this. We consider its invasiveness to be too high for a production-grade gateway.

Enabling trust_env=True forces aiohttp to implicitly read global system environment variables (like HTTP_PROXY / HTTPS_PROXY) for the session.

  • Global Scope: It makes the application behavior dependent on the shell environment, which can lead to "it works on my machine" issues or unintentional routing of internal traffic through external proxies.
  • Lack of Granularity: It applies to the session level, making it difficult to manage different proxy strategies for different exchanges or services within the same application.

vcfgv avatar Dec 02 '25 04:12 vcfgv

ACK

byronwang2005 avatar Dec 02 '25 04:12 byronwang2005