Optimize configuration: remove unused parameters and fix dynaconf setup

This commit is contained in:
yhydev
2026-01-14 13:17:33 +08:00
parent b8c70ad448
commit 28d569bf1e
2 changed files with 58 additions and 20 deletions

View File

@@ -8,40 +8,44 @@ import logging
from datetime import datetime from datetime import datetime
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from download_unzip_csv import download_unzip_csv from download_unzip_csv import download_unzip_csv
from dynaconf import Dynaconf
# 配置日志 # 配置日志
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
# 初始化Dynaconf配置
settings = Dynaconf(
envvar_prefix="DYNACONF",
settings_files=["settings.toml"],
environments=True,
load_dotenv=False,
default_env="default",
env_switcher="BINANCE_ENV"
)
# 配置参数 # 配置参数
BASE_URL = "https://data.binance.vision/data/futures/um/monthly/klines/" BASE_URL = settings.BASE_URL
# 可以添加多个交易对,例如:["BOBUSDT", "BTCUSDT", "ETHUSDT"] SYMBOLS = settings.SYMBOLS
SYMBOLS = ["BOBUSDT", "BTCUSDT"] # BOBUSDT数据从2025-11开始可用 INTERVAL = settings.INTERVAL
INTERVAL = "1d"
START_DATE = "2021-01"
END_DATE = datetime.now().strftime("%Y-%m")
# 代理配置 # 代理配置
PROXIES = { PROXIES = {
'http': 'http://localhost:1080', 'http': settings.HTTP_PROXY,
'https': 'http://localhost:1080' 'https': settings.HTTPS_PROXY
} } if settings.PROXY_ENABLED else None
# PostgreSQL配置 # PostgreSQL配置
DB_CONFIG = { DB_CONFIG = {
"host": "localhost", "host": settings.DB_HOST,
"database": "your_database", "database": settings.DB_DATABASE,
"user": "your_username", "user": settings.DB_USER,
"password": "your_password", "password": settings.DB_PASSWORD,
"port": 5432 "port": settings.DB_PORT
} }
# K线数据列名 # K线数据列名
KLINE_COLUMNS = [ KLINE_COLUMNS = settings.KLINE_COLUMNS
"open_time", "open", "high", "low", "close", "volume",
"close_time", "quote_asset_volume", "number_of_trades",
"taker_buy_base_asset_volume", "taker_buy_quote_asset_volume", "ignore"
]
def download_kline_data(symbol, interval, year_month): def download_kline_data(symbol, interval, year_month):
"""下载指定月份的K线数据""" """下载指定月份的K线数据"""
@@ -209,7 +213,11 @@ def list_s3_files(url, timeout=10):
logger.info(f"Listing files from {url}") logger.info(f"Listing files from {url}")
try: try:
# 根据配置决定是否使用代理
if PROXIES:
response = requests.get(url, timeout=timeout, proxies=PROXIES) response = requests.get(url, timeout=timeout, proxies=PROXIES)
else:
response = requests.get(url, timeout=timeout)
response.raise_for_status() response.raise_for_status()
# 解析XML响应 # 解析XML响应

30
settings.toml Normal file
View File

@@ -0,0 +1,30 @@
# Binance K线数据下载配置
[default]
# 基础URL
BASE_URL = "https://data.binance.vision/data/futures/um/monthly/klines/"
# 默认交易对
SYMBOLS = ["BOBUSDT", "BTCUSDT"]
# 默认时间间隔
INTERVAL = "1d"
# K线数据列名
KLINE_COLUMNS = [
"open_time", "open", "high", "low", "close", "volume",
"close_time", "quote_asset_volume", "number_of_trades",
"taker_buy_base_asset_volume", "taker_buy_quote_asset_volume", "ignore"
]
# 代理配置
PROXY_ENABLED = true
HTTP_PROXY = "http://localhost:1080"
HTTPS_PROXY = "http://localhost:1080"
# PostgreSQL数据库配置
DB_HOST = "localhost"
DB_PORT = 5432
DB_DATABASE = "your_database"
DB_USER = "your_username"
DB_PASSWORD = "your_password"