"""
BitMart 多周期K线数据模型
包含 1分钟、3分钟、5分钟、15分钟、30分钟、1小时 K线数据表
"""

from peewee import *
from models import db


# ==================== 1分钟 K线 ====================
class BitMartETH1M(Model):
    id = BigIntegerField(primary_key=True)  # 时间戳（毫秒级）
    open = FloatField(null=True)
    high = FloatField(null=True)
    low = FloatField(null=True)
    close = FloatField(null=True)

    class Meta:
        database = db
        table_name = 'bitmart_eth_1m'


# ==================== 3分钟 K线 ====================
class BitMartETH3M(Model):
    id = BigIntegerField(primary_key=True)
    open = FloatField(null=True)
    high = FloatField(null=True)
    low = FloatField(null=True)
    close = FloatField(null=True)

    class Meta:
        database = db
        table_name = 'bitmart_eth_3m'


# ==================== 5分钟 K线 ====================
class BitMartETH5M(Model):
    id = BigIntegerField(primary_key=True)
    open = FloatField(null=True)
    high = FloatField(null=True)
    low = FloatField(null=True)
    close = FloatField(null=True)

    class Meta:
        database = db
        table_name = 'bitmart_eth_5m'


# ==================== 15分钟 K线 ====================
class BitMartETH15M(Model):
    id = BigIntegerField(primary_key=True)
    open = FloatField(null=True)
    high = FloatField(null=True)
    low = FloatField(null=True)
    close = FloatField(null=True)

    class Meta:
        database = db
        table_name = 'bitmart_eth_15m'


# ==================== 30分钟 K线 ====================
class BitMartETH30M(Model):
    id = BigIntegerField(primary_key=True)
    open = FloatField(null=True)
    high = FloatField(null=True)
    low = FloatField(null=True)
    close = FloatField(null=True)

    class Meta:
        database = db
        table_name = 'bitmart_eth_30m'


# ==================== 1小时 K线 ====================
class BitMartETH1H(Model):
    id = BigIntegerField(primary_key=True)
    open = FloatField(null=True)
    high = FloatField(null=True)
    low = FloatField(null=True)
    close = FloatField(null=True)

    class Meta:
        database = db
        table_name = 'bitmart_eth_1h'


# 连接数据库并创建表
db.connect(reuse_if_open=True)
db.create_tables([
    BitMartETH1M,
    BitMartETH3M,
    BitMartETH5M,
    BitMartETH15M,
    BitMartETH30M,
    BitMartETH1H,
], safe=True)
