/* Navicat Premium Data Transfer Source Server : lz_mysql_host Source Server Type : MySQL Source Server Version : 50740 Source Host : localhost:3306 Source Schema : lz_app_test Target Server Type : MySQL Target Server Version : 50740 File Encoding : 65001 Date: 04/12/2025 21:57:38 */ SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- -- Table structure for deh_strategy_asset_new -- ---------------------------- DROP TABLE IF EXISTS `deh_strategy_asset_new`; CREATE TABLE `deh_strategy_asset_new` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id', `st_id` int(11) NOT NULL COMMENT '策略id', `asset` varchar(32) NOT NULL COMMENT '资产名称', `win_rate` decimal(11,8) NOT NULL DEFAULT '0.00000000' COMMENT '胜率', `aror` decimal(12,8) NOT NULL DEFAULT '0.00000000' COMMENT '年化收益', `networth` decimal(12,8) NOT NULL DEFAULT '1.00000000' COMMENT '净值', `max_down` decimal(12,8) NOT NULL DEFAULT '0.00000000' COMMENT '最大回撤', `profit` decimal(20,8) NOT NULL DEFAULT '0.00000000' COMMENT '总收益', `profit_rate` decimal(12,8) NOT NULL DEFAULT '0.00000000' COMMENT '总收益率', `current_num` decimal(20,8) NOT NULL DEFAULT '0.00000000' COMMENT '资产数量', `usd_num` decimal(20,8) NOT NULL DEFAULT '0.00000000' COMMENT '价值美元数', `deposit` decimal(20,8) NOT NULL DEFAULT '0.00000000' COMMENT '总充值', `withdrawal` decimal(20,8) NOT NULL DEFAULT '0.00000000' COMMENT '总提现', `other` decimal(20,8) NOT NULL DEFAULT '0.00000000' COMMENT '其他总变动', `time` int(11) NOT NULL COMMENT 'unix时间戳', PRIMARY KEY (`id`) USING BTREE, KEY `st_id` (`st_id`) USING BTREE, KEY `asset` (`asset`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='策略资产表'; -- ---------------------------- -- Table structure for deh_strategy_kx_new -- ---------------------------- DROP TABLE IF EXISTS `deh_strategy_kx_new`; CREATE TABLE `deh_strategy_kx_new` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id', `st_id` int(11) DEFAULT NULL COMMENT '策略id', `k_id` int(11) DEFAULT '0' COMMENT '对应strategy_key 的ID', `asset` varchar(32) DEFAULT NULL COMMENT '资产名', `balance` decimal(20,8) DEFAULT '0.00000000' COMMENT '当日账户金额', `withdrawal` decimal(20,8) DEFAULT '0.00000000' COMMENT '当日提现', `deposit` decimal(20,8) DEFAULT '0.00000000' COMMENT '当日充值', `other` decimal(20,8) DEFAULT '0.00000000' COMMENT '当日其他', `profit` decimal(20,8) DEFAULT '0.00000000' COMMENT '当日利润', `time` int(11) DEFAULT NULL COMMENT '时间', `up_time` datetime DEFAULT NULL COMMENT '最后更新时间', PRIMARY KEY (`id`) USING BTREE, KEY `kid_asset_time` (`k_id`,`asset`,`time`) USING BTREE, KEY `st_id_asset_time` (`st_id`,`asset`,`time`) USING BTREE ) ENGINE=InnoDB AUTO_INCREMENT=259 DEFAULT CHARSET=utf8; -- ---------------------------- -- Table structure for deh_strategy_networth -- ---------------------------- DROP TABLE IF EXISTS `deh_strategy_networth`; CREATE TABLE `deh_strategy_networth` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID', `st_id` int(11) DEFAULT '0' COMMENT '策略ID对应deh_strategy表的ID', `asset` varchar(32) CHARACTER SET utf8 DEFAULT NULL COMMENT '资产名', `share` decimal(20,8) DEFAULT '0.00000000' COMMENT '份额-净值算法', `net_worth` decimal(13,8) DEFAULT '0.00000000' COMMENT '净值-净值算法', `total_profit` decimal(20,8) DEFAULT NULL COMMENT '累计利润', `time` int(10) DEFAULT '0' COMMENT '日期', `up_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间', PRIMARY KEY (`id`), KEY `net_worth_index` (`st_id`,`asset`,`time`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- ---------------------------- -- Table structure for deh_strategy_order_new -- ---------------------------- DROP TABLE IF EXISTS `deh_strategy_order_new`; CREATE TABLE `deh_strategy_order_new` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `st_id` int(11) DEFAULT NULL COMMENT '策略id', `k_id` int(11) DEFAULT '0' COMMENT '对应strategy_key 的ID', `asset` varchar(32) DEFAULT NULL COMMENT '资产名称', `order_id` varchar(765) DEFAULT NULL COMMENT '订单id', `symbol` varchar(120) DEFAULT NULL COMMENT '交易对', `side` varchar(120) DEFAULT NULL COMMENT '订单方向', `price` float DEFAULT NULL COMMENT '订单价格', `time` int(11) DEFAULT NULL COMMENT '订单时间', `order_qty` float DEFAULT NULL COMMENT '订单挂单数量', `last_qty` float DEFAULT NULL COMMENT '订单成交数量', `avg_price` float DEFAULT NULL COMMENT '订单成交均价', `exchange_id` int(11) DEFAULT NULL COMMENT '交易所id', PRIMARY KEY (`id`), UNIQUE KEY `order_index` (`order_id`,`symbol`,`k_id`,`side`) USING BTREE ) ENGINE=InnoDB AUTO_INCREMENT=1269 DEFAULT CHARSET=utf8 COMMENT='订单表'; -- ---------------------------- -- Table structure for deh_strategy_position_new -- ---------------------------- DROP TABLE IF EXISTS `deh_strategy_position_new`; CREATE TABLE `deh_strategy_position_new` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增id', `st_id` int(11) NOT NULL COMMENT '策略id', `k_id` int(11) DEFAULT '0' COMMENT '对应strategy_key 的ID', `asset` varchar(32) DEFAULT '' COMMENT '使用资产名称,如BTC或USDT', `symbol` varchar(50) NOT NULL COMMENT '交易对', `price` float DEFAULT NULL COMMENT '持仓均价', `side` varchar(10) NOT NULL COMMENT '方向', `sum` float NOT NULL COMMENT '仓位(张数)', `asset_num` decimal(20,8) DEFAULT '0.00000000' COMMENT '资产数量', `asset_profit` decimal(20,8) DEFAULT NULL COMMENT '利润数量', `leverage` int(11) DEFAULT '0' COMMENT '杠杆倍数', `uptime` int(11) NOT NULL COMMENT '更新时间', `profit_price` decimal(20,8) DEFAULT '0.00000000' COMMENT '止盈价格', `stop_price` decimal(20,8) DEFAULT '0.00000000' COMMENT '止损价格', `liquidation_price` decimal(20,8) DEFAULT '0.00000000' COMMENT '强平价格', PRIMARY KEY (`id`) USING BTREE, UNIQUE KEY `st_id_asset_sum` (`k_id`,`st_id`,`symbol`,`side`) USING BTREE, KEY `k_id` (`k_id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='持仓表'; -- ---------------------------- -- Event structure for auto_del -- ---------------------------- DROP EVENT IF EXISTS `auto_del`; delimiter ;; CREATE EVENT `auto_del` ON SCHEDULE EVERY '1' MINUTE STARTS '2021-11-01 00:00:00' DO BEGIN DELETE FROM deh_strategy_kx_new WHERE CONCAT(k_id,asset,time) IN ( SELECT p_key FROM ( SELECT CONCAT(k_id,asset,time) AS p_key FROM deh_strategy_kx_new GROUP BY CONCAT(k_id,asset,time) HAVING count(CONCAT(k_id,asset,time)) > 1) AS tmp ) AND id NOT IN ( SELECT id FROM ( SELECT min(id) AS id FROM deh_strategy_kx_new GROUP BY CONCAT(k_id,asset,time) HAVING count(CONCAT(k_id,asset,time)) > 1) AS tmp1 ); DELETE FROM deh_strategy_networth WHERE CONCAT(st_id,asset,time) IN ( SELECT p_key FROM ( SELECT CONCAT(st_id,asset,time) AS p_key FROM deh_strategy_networth GROUP BY CONCAT(st_id,asset,time) HAVING count(CONCAT(st_id,asset,time)) > 1) AS tmp ) AND id NOT IN ( SELECT id FROM ( SELECT min(id) AS id FROM deh_strategy_networth GROUP BY CONCAT(st_id,asset,time) HAVING count(CONCAT(st_id,asset,time)) > 1) AS tmp1 ); DELETE FROM deh_strategy_asset_new WHERE CONCAT(st_id,asset) IN ( SELECT p_key FROM ( SELECT CONCAT(st_id,asset) AS p_key FROM deh_strategy_asset_new GROUP BY CONCAT(st_id,asset) HAVING count(CONCAT(st_id,asset)) > 1) AS tmp ) AND id NOT IN ( SELECT id FROM ( SELECT min(id) AS id FROM deh_strategy_asset_new GROUP BY CONCAT(st_id,asset) HAVING count(CONCAT(st_id,asset)) > 1) AS tmp1 ); END ;; delimiter ; -- ---------------------------- -- Event structure for auto_del_order -- ---------------------------- DROP EVENT IF EXISTS `auto_del_order`; delimiter ;; CREATE EVENT `auto_del_order` ON SCHEDULE EVERY '1' HOUR STARTS '2021-11-01 00:00:00' DO BEGIN -- DELETE FROM `deh_strategy_order_new` WHERE `time` < UNIX_TIMESTAMP(NOW() - INTERVAL 3 DAY); DELETE FROM `deh_strategy_order_new` WHERE `time` < UNIX_TIMESTAMP(NOW() - INTERVAL 3 DAY) AND st_id IN (SELECT st_id FROM `deh_strategy` WHERE is_ia=1); DELETE FROM `deh_strategy_order_new` WHERE `time` < UNIX_TIMESTAMP(NOW() - INTERVAL 30 DAY) AND st_id IN (SELECT st_id FROM `deh_strategy` WHERE is_ia=0); DELETE from `deh_strategy_order_new` where order_id in ( select order_id from ( SELECT order_id FROM `deh_strategy_order_new` GROUP BY order_id HAVING count(order_id) > 1) as tmp ) and id not in ( select id from ( SELECT min(id) as id FROM `deh_strategy_order_new` GROUP BY order_id HAVING count(order_id) > 1) as tmp1 ); END ;; delimiter ; SET FOREIGN_KEY_CHECKS = 1;