From 760d4f44af8204d5353c76269d6dae4d88825c26 Mon Sep 17 00:00:00 2001 From: Lu Ken Date: Tue, 31 Dec 2024 18:05:26 +0800 Subject: [PATCH] add proxy for ccxt Signed-off-by: Lu Ken --- src/gentrade/market_data/crypto.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/gentrade/market_data/crypto.py b/src/gentrade/market_data/crypto.py index a04fd1e..1116431 100644 --- a/src/gentrade/market_data/crypto.py +++ b/src/gentrade/market_data/crypto.py @@ -116,8 +116,15 @@ def __init__(self, cache_dir:str=None): assert self.api_secret is not None, \ "Please specify the Binance's API Secret via the environment" \ "variable BINANCE_API_SECRET" - self._ccxt_inst = ccxt.binance({'apiKey': self.api_key, - 'secret': self.api_secret}) + + params = {'apiKey': self.api_key, 'secret': self.api_secret} + if 'HTTP_PROXY' in os.environ: + params['proxies'] = { + 'http': os.environ['HTTP_PROXY'], + 'https': os.environ['HTTP_PROXY'] + } + + self._ccxt_inst = ccxt.binance(params) self._ready = False @property