chore: initial commit with config ignores
This commit is contained in:
58
models/__init__.py
Normal file
58
models/__init__.py
Normal file
@@ -0,0 +1,58 @@
|
||||
from pathlib import Path
|
||||
|
||||
from peewee import *
|
||||
|
||||
# 连接到 SQLite 数据库,如果文件不存在会自动创建
|
||||
db = SqliteDatabase(fr'{Path(__file__).parent}/database.db')
|
||||
|
||||
import pymysql
|
||||
|
||||
from peewee import *
|
||||
from playhouse.pool import PooledMySQLDatabase
|
||||
|
||||
pymysql.install_as_MySQLdb()
|
||||
|
||||
# 数据库配置
|
||||
db_config = {
|
||||
'database': 'lm',
|
||||
'user': 'lm',
|
||||
'password': 'HhyAsGbrrbsJfpyy',
|
||||
'host': '192.168.1.87',
|
||||
'port': 3306
|
||||
}
|
||||
|
||||
# 全局数据库实例
|
||||
db1 = MySQLDatabase(
|
||||
db_config['database'],
|
||||
user=db_config['user'],
|
||||
password=db_config['password'],
|
||||
host=db_config['host'],
|
||||
port=db_config['port']
|
||||
)
|
||||
|
||||
# class BaseModel(Model):
|
||||
# class Meta:
|
||||
# database = db1
|
||||
#
|
||||
# def save(self, *args, **kwargs):
|
||||
# """在调用 save 时自动连接和关闭(若无事务)"""
|
||||
# db.connect(reuse_if_open=True)
|
||||
# try:
|
||||
# result = super().save(*args, **kwargs)
|
||||
# finally:
|
||||
# # 若当前没有事务且连接仍然打开,则关闭连接
|
||||
# if not db.in_transaction() and not db.is_closed():
|
||||
# db.close()
|
||||
# return result
|
||||
#
|
||||
# @classmethod
|
||||
# def get_or_create(cls, defaults=None, **kwargs):
|
||||
# """在调用 get_or_create 时自动连接和关闭(若无事务)"""
|
||||
# db.connect(reuse_if_open=True)
|
||||
# try:
|
||||
# obj, created = super().get_or_create(defaults=defaults, **kwargs)
|
||||
# finally:
|
||||
# # 若当前没有事务且连接仍然打开,则关闭连接
|
||||
# if not db.in_transaction() and not db.is_closed():
|
||||
# db.close()
|
||||
# return obj, created
|
||||
21
models/bitmart.py
Normal file
21
models/bitmart.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from peewee import *
|
||||
|
||||
from models import db
|
||||
|
||||
|
||||
class BitMart30(Model):
|
||||
id = IntegerField(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_30'
|
||||
|
||||
|
||||
# 连接到数据库
|
||||
db.connect()
|
||||
# 创建表(如果表不存在)
|
||||
db.create_tables([BitMart30])
|
||||
21
models/bitmart_15.py
Normal file
21
models/bitmart_15.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from peewee import *
|
||||
|
||||
from models import db
|
||||
|
||||
|
||||
class BitMart15(Model):
|
||||
id = IntegerField(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_15'
|
||||
|
||||
|
||||
# 连接到数据库
|
||||
db.connect()
|
||||
# 创建表(如果表不存在)
|
||||
db.create_tables([BitMart15])
|
||||
97
models/bitmart_klines.py
Normal file
97
models/bitmart_klines.py
Normal file
@@ -0,0 +1,97 @@
|
||||
"""
|
||||
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)
|
||||
21
models/ips.py
Normal file
21
models/ips.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from peewee import *
|
||||
|
||||
from models import db1
|
||||
|
||||
|
||||
class Ips(Model):
|
||||
id = IntegerField(primary_key=True)
|
||||
host = CharField(null=True)
|
||||
port = CharField(null=True)
|
||||
username = CharField(null=True)
|
||||
password = CharField(null=True)
|
||||
start = IntegerField(null=True)
|
||||
country = CharField(null=True)
|
||||
|
||||
class Meta:
|
||||
database = db1
|
||||
table_name = 'ips'
|
||||
|
||||
|
||||
# if __name__ == '__main__':
|
||||
# Ips.create_table()
|
||||
57
models/mexc.py
Normal file
57
models/mexc.py
Normal file
@@ -0,0 +1,57 @@
|
||||
from peewee import *
|
||||
|
||||
from models import db
|
||||
|
||||
|
||||
class Mexc1(Model):
|
||||
id = IntegerField(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 = 'mexc_1'
|
||||
|
||||
|
||||
class Mexc15(Model):
|
||||
id = IntegerField(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 = 'mexc_15'
|
||||
|
||||
|
||||
class Mexc30(Model):
|
||||
id = IntegerField(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 = 'mexc_30'
|
||||
|
||||
|
||||
class Mexc1Hour(Model):
|
||||
id = IntegerField(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 = 'mexc_1_hour'
|
||||
|
||||
|
||||
# 连接到数据库
|
||||
db.connect()
|
||||
# 创建表(如果表不存在)
|
||||
db.create_tables([Mexc1, Mexc15, Mexc30, Mexc1Hour])
|
||||
71
models/weex.py
Normal file
71
models/weex.py
Normal file
@@ -0,0 +1,71 @@
|
||||
from peewee import *
|
||||
|
||||
from models import db
|
||||
|
||||
|
||||
class Weex15(Model):
|
||||
id = IntegerField(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 = 'weex_15'
|
||||
|
||||
|
||||
class Weex1(Model):
|
||||
id = IntegerField(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 = 'weex_1'
|
||||
|
||||
|
||||
class Weex1Hour(Model):
|
||||
id = IntegerField(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 = 'weex_1_hour'
|
||||
|
||||
class Weex30(Model):
|
||||
id = IntegerField(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 = 'weex_30'
|
||||
|
||||
class Weex30Copy(Model):
|
||||
id = IntegerField(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 = 'weex_30_copy1'
|
||||
|
||||
|
||||
# 连接到数据库
|
||||
db.connect()
|
||||
#
|
||||
# # 创建表(如果表不存在)
|
||||
# db.create_tables([Weex15])
|
||||
db.create_tables([Weex30])
|
||||
|
||||
|
||||
22
models/xstart.py
Normal file
22
models/xstart.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from peewee import *
|
||||
|
||||
from models import db1
|
||||
from models.ips import Ips
|
||||
|
||||
|
||||
class Xstart(Model):
|
||||
id = AutoField(primary_key=True) # 自增主键
|
||||
bit_id = CharField(null=True)
|
||||
start = IntegerField(null=True)
|
||||
x_id = IntegerField(null=True)
|
||||
ip_id = IntegerField(null=True)
|
||||
url_id = CharField(null=True)
|
||||
|
||||
class Meta:
|
||||
database = db1 # 所属数据库
|
||||
table_name = 'xstart'
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Xstart.create_table()
|
||||
24
models/xtoken.py
Normal file
24
models/xtoken.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from peewee import *
|
||||
# 假设 db 已经在其他地方定义并连接到数据库
|
||||
from models import db1
|
||||
|
||||
|
||||
class XToken(Model):
|
||||
id = AutoField(primary_key=True) # 自增主键
|
||||
hub_id = IntegerField(null=True) # hub_id 字段,整型,可为空
|
||||
start = IntegerField(null=True) # start 字段,整型,可为空
|
||||
account_start = IntegerField(null=True) # account_start 字段,整型,可为空
|
||||
user_name = CharField(max_length=255, null=True) # user_name 字段,最大长度 255,可为空
|
||||
password = CharField(max_length=255, null=True) # password 字段,最大长度 255,可为空
|
||||
email = CharField(max_length=255, null=True) # email 字段,最大长度 255,可为空
|
||||
two_fa = CharField(max_length=255, null=True) # 2fa 字段,由于 2fa 是 Python 中的无效标识符,这里使用 two_fa 替代,最大长度 255,可为空
|
||||
token = CharField(max_length=255, null=True) # token 字段,最大长度 255,可为空
|
||||
email_pwd = CharField(max_length=255, null=True) # token 字段,最大长度 255,可为空
|
||||
|
||||
class Meta:
|
||||
database = db1 # 所属数据库
|
||||
table_name = 'x_token' # 表名
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
XToken.create_table()
|
||||
Reference in New Issue
Block a user