-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtest_ccxt_loader_proxy.py
More file actions
48 lines (33 loc) · 1.21 KB
/
test_ccxt_loader_proxy.py
File metadata and controls
48 lines (33 loc) · 1.21 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
"""Regression tests for CCXT proxy environment handling."""
from __future__ import annotations
import ccxt
from backtest.loaders.ccxt_loader import DataLoader
class _FakeExchange:
def __init__(self, config):
self.config = config
def _clear_proxy_env(monkeypatch):
for name in (
"HTTP_PROXY",
"HTTPS_PROXY",
"ALL_PROXY",
"http_proxy",
"https_proxy",
"all_proxy",
):
monkeypatch.delenv(name, raising=False)
def test_get_exchange_passes_all_proxy_to_ccxt(monkeypatch):
_clear_proxy_env(monkeypatch)
monkeypatch.setenv("CCXT_EXCHANGE", "binance")
monkeypatch.setenv("ALL_PROXY", "socks5h://127.0.0.1:1088")
monkeypatch.setattr(ccxt, "binance", _FakeExchange)
exchange = DataLoader()._get_exchange()
assert exchange.config["proxies"] == {
"http": "socks5h://127.0.0.1:1088",
"https": "socks5h://127.0.0.1:1088",
}
def test_get_exchange_omits_proxy_config_when_env_absent(monkeypatch):
_clear_proxy_env(monkeypatch)
monkeypatch.setenv("CCXT_EXCHANGE", "binance")
monkeypatch.setattr(ccxt, "binance", _FakeExchange)
exchange = DataLoader()._get_exchange()
assert "proxies" not in exchange.config