Optimize configuration: remove unused parameters and fix dynaconf setup
This commit is contained in:
@@ -8,40 +8,44 @@ import logging
|
||||
from datetime import datetime
|
||||
import xml.etree.ElementTree as ET
|
||||
from download_unzip_csv import download_unzip_csv
|
||||
from dynaconf import Dynaconf
|
||||
|
||||
# 配置日志
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
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/"
|
||||
# 可以添加多个交易对,例如:["BOBUSDT", "BTCUSDT", "ETHUSDT"]
|
||||
SYMBOLS = ["BOBUSDT", "BTCUSDT"] # BOBUSDT数据从2025-11开始可用
|
||||
INTERVAL = "1d"
|
||||
START_DATE = "2021-01"
|
||||
END_DATE = datetime.now().strftime("%Y-%m")
|
||||
BASE_URL = settings.BASE_URL
|
||||
SYMBOLS = settings.SYMBOLS
|
||||
INTERVAL = settings.INTERVAL
|
||||
|
||||
# 代理配置
|
||||
PROXIES = {
|
||||
'http': 'http://localhost:1080',
|
||||
'https': 'http://localhost:1080'
|
||||
}
|
||||
'http': settings.HTTP_PROXY,
|
||||
'https': settings.HTTPS_PROXY
|
||||
} if settings.PROXY_ENABLED else None
|
||||
|
||||
# PostgreSQL配置
|
||||
DB_CONFIG = {
|
||||
"host": "localhost",
|
||||
"database": "your_database",
|
||||
"user": "your_username",
|
||||
"password": "your_password",
|
||||
"port": 5432
|
||||
"host": settings.DB_HOST,
|
||||
"database": settings.DB_DATABASE,
|
||||
"user": settings.DB_USER,
|
||||
"password": settings.DB_PASSWORD,
|
||||
"port": settings.DB_PORT
|
||||
}
|
||||
|
||||
# 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"
|
||||
]
|
||||
KLINE_COLUMNS = settings.KLINE_COLUMNS
|
||||
|
||||
def download_kline_data(symbol, interval, year_month):
|
||||
"""下载指定月份的K线数据"""
|
||||
@@ -209,7 +213,11 @@ def list_s3_files(url, timeout=10):
|
||||
logger.info(f"Listing files from {url}")
|
||||
|
||||
try:
|
||||
response = requests.get(url, timeout=timeout, proxies=PROXIES)
|
||||
# 根据配置决定是否使用代理
|
||||
if PROXIES:
|
||||
response = requests.get(url, timeout=timeout, proxies=PROXIES)
|
||||
else:
|
||||
response = requests.get(url, timeout=timeout)
|
||||
response.raise_for_status()
|
||||
|
||||
# 解析XML响应
|
||||
|
||||
30
settings.toml
Normal file
30
settings.toml
Normal 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"
|
||||
Reference in New Issue
Block a user