From f4922bd7d8c0389e6b7fe006eac4d802f5a1210e Mon Sep 17 00:00:00 2001 From: zerone Date: Mon, 24 Feb 2025 22:22:34 +0800 Subject: [PATCH] add --- src/server.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/server.py b/src/server.py index 09a2c27..d383a71 100644 --- a/src/server.py +++ b/src/server.py @@ -1,5 +1,6 @@ import asyncio import platform +import os from typing import Any, Dict, List import ccxt.async_support as ccxt import mcp.types as types @@ -15,6 +16,12 @@ if platform.system() == 'Windows': # 初始化服务器 server = Server("crypto-server") +# 代理配置 +PROXY_CONFIG = { + 'http': os.environ.get('HTTP_PROXY', ''), + 'https': os.environ.get('HTTPS_PROXY', ''), +} + # 定义支持的交易所及其实例 # 这里列出了所有支持的加密货币交易所,使用ccxt库提供的接口 SUPPORTED_EXCHANGES = { @@ -53,7 +60,19 @@ async def get_exchange(exchange_id: str) -> ccxt.Exchange: if exchange_id not in exchange_instances: exchange_class = SUPPORTED_EXCHANGES[exchange_id] - exchange_instances[exchange_id] = exchange_class() + # 创建交易所实例时配置代理 + proxy = PROXY_CONFIG['http'] or PROXY_CONFIG['https'] + exchange_options = {} + + if proxy: + exchange_options.update({ + 'proxies': { + 'http': proxy, + 'https': proxy + } + }) + + exchange_instances[exchange_id] = exchange_class(exchange_options) return exchange_instances[exchange_id]