import random
import pandas as pd
# 生成模拟的交易信号数据
def generate_trades(num_trades):
    trades = []
    for i in range(num_trades):
        timestamp = f"2024-02-22 {random.randint(9, 15)}:{random.randint(0, 59)}:{random.randint(0, 59)}"
        action = random.choice(["BUY", "SELL"])
        price = random.uniform(90, 110)
        volume = random.randint(1, 10)
        if action == "BUY":
            reason = random.choice(["新闻面利好", "技术指标交叉", "回调到支撑位"])
        else:
            reason = random.choice(["涨幅达到10%", "止损策略触发", "技术指标拐头"])
        trade = {"timestamp": timestamp, "action": action, "price": price, "volume": volume, "reason": reason}
        trades.append(trade)
    return trades
# 生成10条交易信号数据
trades_data = generate_trades(10)
# 创建DataFrame保存交易信号数据
df = pd.DataFrame(trades_data)
# 保存到Excel文件
df.to_excel("交易记录.xlsx", index=False)