127 lines
3.7 KiB
Python
127 lines
3.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
修复时间戳问题的诊断和解决方案
|
|
"""
|
|
import os
|
|
import json
|
|
import pandas as pd
|
|
from datetime import datetime, timezone
|
|
|
|
def check_config_timestamp(config_path="config.json"):
|
|
"""检查配置文件中的时间戳配置"""
|
|
try:
|
|
with open(config_path, 'r') as f:
|
|
config = json.load(f)
|
|
|
|
print("🔍 检查配置文件时间设置...")
|
|
|
|
# 检查交易所配置
|
|
if 'exchange' in config:
|
|
exchange = config['exchange']
|
|
print(f"✅ 交易所配置: {exchange.get('name', 'unknown')}")
|
|
|
|
# 检查时区设置
|
|
if 'timezone' in exchange:
|
|
print(f"🕐 交易所时区: {exchange['timezone']}")
|
|
else:
|
|
print("⚠️ 未设置交易所时区")
|
|
|
|
# 检查时间范围配置
|
|
if 'timerange' in config:
|
|
print(f"📅 时间范围: {config['timerange']}")
|
|
|
|
# 检查时间框架
|
|
if 'timeframe' in config:
|
|
print(f"⏱️ 时间框架: {config['timeframe']}")
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ 配置文件检查失败: {e}")
|
|
return False
|
|
|
|
def test_dataframe_index():
|
|
"""测试DataFrame索引类型"""
|
|
try:
|
|
# 创建测试数据
|
|
dates = pd.date_range('2024-08-17', periods=10, freq='3min')
|
|
df = pd.DataFrame({
|
|
'open': [100.0] * 10,
|
|
'high': [101.0] * 10,
|
|
'low': [99.0] * 10,
|
|
'close': [100.5] * 10,
|
|
'volume': [1000.0] * 10
|
|
}, index=dates)
|
|
|
|
print("\n🔍 测试DataFrame索引类型...")
|
|
print(f"索引类型: {type(df.index[0])}")
|
|
print(f"索引值示例: {df.index[0]}")
|
|
|
|
# 测试时间戳转换
|
|
timestamp = int(df.index[0].timestamp())
|
|
print(f"时间戳转换: {timestamp}")
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ DataFrame测试失败: {e}")
|
|
return False
|
|
|
|
def create_debug_config():
|
|
"""创建调试配置"""
|
|
debug_config = {
|
|
"exchange": {
|
|
"name": "binance",
|
|
"key": "your_api_key",
|
|
"secret": "your_api_secret",
|
|
"ccxt_config": {"enableRateLimit": True},
|
|
"ccxt_async_config": {"enableRateLimit": True},
|
|
"markets_refresh_interval": 60
|
|
},
|
|
"timeframe": "3m",
|
|
"stake_currency": "USDT",
|
|
"stake_amount": 10,
|
|
"tradable_balance_ratio": 0.99,
|
|
"fiat_display_currency": "USD",
|
|
"dry_run": True,
|
|
"cancel_open_orders_on_exit": False,
|
|
"trading_mode": "spot",
|
|
"margin_mode": "",
|
|
"unfilledtimeout": {"entry": 10, "exit": 10},
|
|
"entry_pricing": {
|
|
"price_side": "same",
|
|
"use_order_book": True,
|
|
"order_book_top": 1,
|
|
"price_last_balance": 0.0
|
|
},
|
|
"exit_pricing": {
|
|
"price_side": "same",
|
|
"use_order_book": True,
|
|
"order_book_top": 1,
|
|
"price_last_balance": 0.0
|
|
}
|
|
}
|
|
|
|
with open('debug_config.json', 'w') as f:
|
|
json.dump(debug_config, f, indent=2)
|
|
|
|
print("✅ 已创建调试配置: debug_config.json")
|
|
return True
|
|
|
|
if __name__ == "__main__":
|
|
print("🚀 开始时间戳问题诊断...")
|
|
|
|
# 检查配置文件
|
|
check_config_timestamp()
|
|
|
|
# 测试DataFrame索引
|
|
test_dataframe_index()
|
|
|
|
# 创建调试配置
|
|
create_debug_config()
|
|
|
|
print("\n📋 诊断完成!")
|
|
print("建议操作:")
|
|
print("1. 重启Freqtrade服务")
|
|
print("2. 检查config.json中的时间配置")
|
|
print("3. 清理缓存数据") |