哈哈
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)
|
||||
BIN
models/database.db
Normal file
BIN
models/database.db
Normal file
Binary file not shown.
47
models/eth_ai_strategy/feature_cols.json
Normal file
47
models/eth_ai_strategy/feature_cols.json
Normal file
@@ -0,0 +1,47 @@
|
||||
[
|
||||
"bb_pct",
|
||||
"bb_width",
|
||||
"keltner_pct",
|
||||
"keltner_width",
|
||||
"donchian_pct",
|
||||
"donchian_width",
|
||||
"stoch_k",
|
||||
"stoch_d",
|
||||
"cci",
|
||||
"willr",
|
||||
"rsi",
|
||||
"atr_band_pct",
|
||||
"atr_band_width",
|
||||
"zscore",
|
||||
"zscore_abs",
|
||||
"lr_pct",
|
||||
"lr_width",
|
||||
"price_vs_median",
|
||||
"median_band_pct",
|
||||
"pct_rank",
|
||||
"chandelier_pct",
|
||||
"chandelier_width",
|
||||
"std_band_pct",
|
||||
"std_band_width",
|
||||
"elder_bull",
|
||||
"elder_bear",
|
||||
"elder_dist",
|
||||
"ema_fast_slow",
|
||||
"price_vs_ema120",
|
||||
"ema8_slope",
|
||||
"macd",
|
||||
"macd_signal",
|
||||
"macd_hist",
|
||||
"atr_pct",
|
||||
"ret_1",
|
||||
"ret_3",
|
||||
"ret_5",
|
||||
"ret_10",
|
||||
"ret_20",
|
||||
"vol_5",
|
||||
"vol_20",
|
||||
"body_pct",
|
||||
"price_position_20",
|
||||
"hour_sin",
|
||||
"hour_cos"
|
||||
]
|
||||
14435
models/eth_ai_strategy/model.txt
Normal file
14435
models/eth_ai_strategy/model.txt
Normal file
File diff suppressed because it is too large
Load Diff
40
models/eth_ai_strategy/strategy_params.json
Normal file
40
models/eth_ai_strategy/strategy_params.json
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"bb_period": 20,
|
||||
"bb_std": 2.0,
|
||||
"keltner_period": 20,
|
||||
"keltner_atr_mult": 2.0,
|
||||
"donchian_period": 20,
|
||||
"stoch_k_period": 14,
|
||||
"stoch_d_period": 3,
|
||||
"cci_period": 20,
|
||||
"willr_period": 14,
|
||||
"rsi_period": 14,
|
||||
"atr_band_period": 20,
|
||||
"atr_band_mult": 2.0,
|
||||
"zscore_period": 20,
|
||||
"lr_period": 20,
|
||||
"lr_std_mult": 2.0,
|
||||
"median_band_period": 20,
|
||||
"pct_rank_period": 20,
|
||||
"chandelier_period": 22,
|
||||
"chandelier_mult": 3.0,
|
||||
"std_band_period": 14,
|
||||
"std_band_mult": 2.0,
|
||||
"elder_period": 13,
|
||||
"forward_bars": 10,
|
||||
"label_threshold": 0.002,
|
||||
"prob_threshold": 0.45,
|
||||
"sl_pct": 0.004,
|
||||
"tp_pct": 0.006,
|
||||
"min_hold_seconds": 180,
|
||||
"max_hold_seconds": 1800,
|
||||
"margin_per_trade": 100.0,
|
||||
"leverage": 100,
|
||||
"notional": 10000.0,
|
||||
"rebate_rate": 0.9,
|
||||
"train_period": "2020-01-01 ~ 2021-01-01",
|
||||
"test_period": "2021-01-01 ~ 2022-01-01",
|
||||
"kline_period": "5m",
|
||||
"initial_balance": 10000.0,
|
||||
"max_dd_target": 500.0
|
||||
}
|
||||
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