This commit is contained in:
zerone 2025-02-24 22:22:34 +08:00
parent c103fa700e
commit f4922bd7d8

View File

@ -1,5 +1,6 @@
import asyncio import asyncio
import platform import platform
import os
from typing import Any, Dict, List from typing import Any, Dict, List
import ccxt.async_support as ccxt import ccxt.async_support as ccxt
import mcp.types as types import mcp.types as types
@ -15,6 +16,12 @@ if platform.system() == 'Windows':
# 初始化服务器 # 初始化服务器
server = Server("crypto-server") server = Server("crypto-server")
# 代理配置
PROXY_CONFIG = {
'http': os.environ.get('HTTP_PROXY', ''),
'https': os.environ.get('HTTPS_PROXY', ''),
}
# 定义支持的交易所及其实例 # 定义支持的交易所及其实例
# 这里列出了所有支持的加密货币交易所使用ccxt库提供的接口 # 这里列出了所有支持的加密货币交易所使用ccxt库提供的接口
SUPPORTED_EXCHANGES = { SUPPORTED_EXCHANGES = {
@ -53,7 +60,19 @@ async def get_exchange(exchange_id: str) -> ccxt.Exchange:
if exchange_id not in exchange_instances: if exchange_id not in exchange_instances:
exchange_class = SUPPORTED_EXCHANGES[exchange_id] 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] return exchange_instances[exchange_id]