| | |
| | | m_poolModel = new QStandardItemModel(1,9,this); |
| | | |
| | | QStringList poolLabel; |
| | | poolLabel<<"id"<<"股票名字"<<"股票代号"<<"监控记录时间"<<"监控买入价格"<<"当前价格"<<"盈亏百分比"<<"监控卖出价格"<<"监控卖出时间"; |
| | | poolLabel<<"id"<<"股票名字"<<"股票代号"<<"监控买入价格"<<"监控记录时间"<<"当前价格"<<"盈亏百分比"<<"监控卖出价格"<<"监控卖出时间"<<"策略周期"; |
| | | m_poolModel->setHorizontalHeaderLabels(poolLabel); |
| | | ui->tableView_2->setModel(m_poolModel); |
| | | |
| | |
| | | m_poolTimer = new QTimer(this); |
| | | connect(m_poolTimer,SIGNAL(timeout()),this,SLOT(poolTimerSlot())); |
| | | m_poolTimer->start(10*1000); |
| | | |
| | | m_getPoolCloseTimer = new QTimer(this); // 刷新股票池最新价格 |
| | | connect(m_getPoolCloseTimer,SIGNAL(timeout()),this,SLOT(getLastCloseSlot())); |
| | | |
| | | } |
| | | |
| | | HistoryData::~HistoryData() |
| | |
| | | qDebug()<<"查看个股情况:"; |
| | | getOneStock(buffer); |
| | | |
| | | }else if(reply->url().toString().indexOf("https://hqm.stock.sohu.com/getqjson") != -1){ |
| | | qDebug()<<"获取股票池个股价格"; |
| | | getPoolStock(buffer); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | /* |
| | | * {"cn_000032":["cn_000032","深桑达A","26.33","-9.98%","-2.92","1102599","3473","306282","17.10%","2.38","29.87","26.33","0.00","29.25","29.25","\/cn\/000032\/index.shtml","169.77","2025-02-28 15:00:54","\/t\/cn\/032\/000032.html"], |
| | | * "cn_603729":["cn_603729","龙韵股份","15.50","-4.79%","-0.78","52294","1220","8268","5.60%","0.57","16.27","15.46","407.89","16.28","16.20","\/cn\/603729\/index.shtml","14.47","2025-02-28 15:00:57","\/t\/cn\/729\/603729.html"], |
| | | * "cn_300253":["cn_300253","卫宁健康","11.03","-7.08%","-0.84","1667417","11","189099","8.96%","3.64","11.86","10.97","116.11","11.87","11.70","\/cn\/300253\/index.shtml","205.36","2025-02-28 15:30:57","\/t\/cn\/253\/300253.html"], |
| | | * "cn_300454":["cn_300454","深信服 ","102.06","-7.13%","-7.84","173684","1","181338","6.29%","2.29","109.90","101.00","0.00","109.90","107.14","\/cn\/300454\/index.shtml","281.95","2025-02-28 15:30:57","\/t\/cn\/454\/300454.html"], |
| | | * "cn_688055":["cn_688055","龙腾光电","3.88","-4.67%","-0.19","98688","1418","3898","0.30%","1.01","4.08","3.87","0.00","4.07","4.07","\/cn\/688055\/index.shtml","129.33","2025-02-28 15:30:56","\/t\/cn\/055\/688055.html"], |
| | | * "cn_000818":["cn_000818","航锦科技","31.45","-3.82%","-1.25","982520","16510","316446","14.50%","5.41","33.40","30.98","393.13","32.70","32.30","\/cn\/000818\/index.shtml","213.03","2025-02-28 15:00:54","\/t\/cn\/818\/000818.html"]} |
| | | * |
| | | */ |
| | | void HistoryData::getPoolStock(QByteArray &buffer){ |
| | | // 通过搜狐股票行情中心来批量获取价格情况,https://hqm.stock.sohu.com/getqjson?code=cn_603729,cn_688055,cn_000032,cn_000818,cn_300454,cn_300253 |
| | | qDebug()<<buffer; |
| | | qDebug()<<buffer.left(buffer.size()-1); |
| | | QJsonDocument jd = QJsonDocument::fromJson(buffer.left(buffer.size()-1)); |
| | | qDebug()<<jd.isObject()<<jd.toJson(); |
| | | |
| | | if(jd.isObject()){ |
| | | QJsonObject jObject = jd.object(); |
| | | //QJsonArray jArr = jObject.keys(); // 通过键值对取值 |
| | | int cnt = jObject.keys().size(); |
| | | qDebug()<<"数组size:"<<cnt; |
| | | for(auto it = jObject.begin();it != jObject.end();++it){ |
| | | qDebug()<<it.key()<<it.value().toArray().at(1)<<it.value().toArray().at(2); |
| | | } |
| | | }else{ |
| | | // 当字符串处理 |
| | | QList<QByteArray> tmp = buffer.split('['); |
| | | //qDebug()<<"[ tmp size:"<<tmp.size(); |
| | | for(int i=0;i<tmp.size();++i){ |
| | | //qDebug()<<i<<tmp.at(i); |
| | | QList<QByteArray> row = tmp.at(i).split(','); |
| | | if(row.size() > 2){ |
| | | QString code = QString::fromLocal8Bit(row.at(0).mid(1,row.at(0).size()-2)).trimmed().split('_').at(1); |
| | | QString name = QString::fromLocal8Bit(row.at(1).mid(1,row.at(1).size()-2)).trimmed(); |
| | | double close = row.at(2).mid(1,row.at(2).size()-2).toDouble(); |
| | | //qDebug()<<name<<close<<code; |
| | | QString sql = QString("update stock_pool set cur_price=%1 where code like '%%2%' and state=1").arg(close).arg(code); |
| | | qDebug()<<sql; |
| | | QSqlQuery que(db); |
| | | if(que.exec(sql)){ |
| | | qDebug()<<"sql update ok"; |
| | | }else{ |
| | | qDebug()<<"sql update fail"; |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | // 最后更新一下表格的百分比情况 |
| | | QString sql = "update stock_pool set percent = (cur_price/in_price - 1)*100 where cur_price > 0 and in_price > 0 and state=1"; |
| | | QSqlQuery que(db); |
| | | if(que.exec(sql)){ |
| | | qDebug()<<"sql update percent ok"; |
| | | }else{ |
| | | qDebug()<<"sql update percent fail"; |
| | | } |
| | | } |
| | | } |
| | | |
| | | void HistoryData::on_pushButton_search_clicked() |
| | |
| | | QString code = ui->lineEdit_2->text(); |
| | | QString price = ui->lineEdit_3->text(); |
| | | QString in_date = ui->dateEdit_2->text(); |
| | | qDebug()<<name<<code<<price<<in_date; |
| | | QString type = ui->comboBox->currentText(); |
| | | qDebug()<<name<<code<<price<<in_date<<type; |
| | | |
| | | QString sql = QString("insert into stock_pool (name,code,in_price,in_time) values('%1','%2',%3,'%4')").arg(name).arg(code).arg(price).arg(in_date); |
| | | QString sql = QString("insert into stock_pool (name,code,in_price,in_time,type) values('%1','%2',%3,'%4','%5')").arg(name).arg(code).arg(price).arg(in_date).arg(type); |
| | | qDebug()<<"sql:"<<sql; |
| | | |
| | | QSqlQuery que(db); |
| | |
| | | m_poolModel->setRowCount(0); |
| | | while (que.next()) { |
| | | QList<QStandardItem*> items; |
| | | for(int i=0;i<9;++i){ |
| | | for(int i=0;i<10;++i){ |
| | | QString item = que.value(i).toString(); |
| | | QStandardItem *it = new QStandardItem(item); |
| | | if(i==6){ |
| | |
| | | qDebug()<<"days:"<<days; |
| | | m_days = days; // 刷新时间 |
| | | |
| | | getLastCloseSlot(); |
| | | |
| | | } |
| | | |
| | | void HistoryData::getLastCloseSlot() |
| | | { |
| | | // 获取股票池每只股票最新价格 |
| | | QString url = "https://hqm.stock.sohu.com/getqjson?code="; |
| | | for(int i=0;i<m_poolModel->rowCount();++i){ |
| | | if(m_poolModel->item(i,2)){ |
| | | QString code="cn_"; |
| | | if(i > 0) code = ",cn_"; |
| | | code += m_poolModel->item(i,2)->text().mid(2); |
| | | // qDebug()<<"code:"<<code; |
| | | url+=code; |
| | | //qDebug()<<"url:"<<url; |
| | | } |
| | | |
| | | |
| | | } |
| | | qDebug()<<QDateTime::currentDateTime()<<"url:"<<url; |
| | | |
| | | m_request.setUrl(QUrl(url)); |
| | | m_manager.get(m_request); |
| | | |
| | | |
| | | } |
| | | |
| | | void HistoryData::on_checkBox_updatePoolClose_clicked() |
| | | { |
| | | if(ui->checkBox_updatePoolClose->isChecked()){ |
| | | m_getPoolCloseTimer->start(3*60*1000); // 3分钟更新一次 |
| | | }else{ |
| | | m_getPoolCloseTimer->stop(); |
| | | } |
| | | } |
| | |
| | | |
| | | void initMySQL(); |
| | | |
| | | void getPoolStock(QByteArray &buffer); |
| | | signals: |
| | | void sendHistoryModel(QVector<QVector<QString>> &); // 将模型发给信息展示 |
| | | void sendHistoryModel(QStandardItemModel *); // 将模型发给信息展示 |
| | |
| | | |
| | | void on_checkBox_clicked(); |
| | | |
| | | void getLastCloseSlot(); |
| | | |
| | | void on_checkBox_updatePoolClose_clicked(); |
| | | |
| | | private: |
| | | Ui::HistoryData *ui; |
| | | |
| | |
| | | QVector<QVector<QString>> m_modelDatas; // 行列存储 |
| | | |
| | | QTimer *m_poolTimer; // 刷新股票池的定时器 |
| | | QTimer *m_getPoolCloseTimer; // 获取股票池最新价格的定时器 |
| | | |
| | | int m_days=0; // 上次更新到现在经过的天数 |
| | | }; |
| | |
| | | </property> |
| | | </widget> |
| | | </item> |
| | | <item> |
| | | <widget class="QCheckBox" name="checkBox_updatePoolClose"> |
| | | <property name="text"> |
| | | <string>更新股票池价格</string> |
| | | </property> |
| | | </widget> |
| | | </item> |
| | | </layout> |
| | | </item> |
| | | <item row="1" column="0"> |
| | |
| | | </widget> |
| | | </item> |
| | | <item> |
| | | <widget class="QComboBox" name="comboBox"> |
| | | <item> |
| | | <property name="text"> |
| | | <string>week</string> |
| | | </property> |
| | | </item> |
| | | <item> |
| | | <property name="text"> |
| | | <string>month</string> |
| | | </property> |
| | | </item> |
| | | <item> |
| | | <property name="text"> |
| | | <string>day</string> |
| | | </property> |
| | | </item> |
| | | <item> |
| | | <property name="text"> |
| | | <string>quarter</string> |
| | | </property> |
| | | </item> |
| | | <item> |
| | | <property name="text"> |
| | | <string>year</string> |
| | | </property> |
| | | </item> |
| | | </widget> |
| | | </item> |
| | | <item> |
| | | <widget class="QPushButton" name="pushButton_addStock"> |
| | | <property name="text"> |
| | | <string>添加</string> |
New file |
| | |
| | | -- -------------------------------------------------------- |
| | | -- 主机: 127.0.0.1 |
| | | -- 服务器版本: 5.6.35-log - MySQL Community Server (GPL) |
| | | -- 服务器操作系统: Win64 |
| | | -- HeidiSQL 版本: 9.5.0.5196 |
| | | -- -------------------------------------------------------- |
| | | |
| | | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; |
| | | /*!40101 SET NAMES utf8 */; |
| | | /*!50503 SET NAMES utf8mb4 */; |
| | | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; |
| | | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; |
| | | |
| | | |
| | | -- 导出 stock_plan 的数据库结构 |
| | | CREATE DATABASE IF NOT EXISTS `stock_plan` /*!40100 DEFAULT CHARACTER SET utf8 */; |
| | | USE `stock_plan`; |
| | | |
| | | -- 导出 表 stock_plan.days_info 结构 |
| | | CREATE TABLE IF NOT EXISTS `days_info` ( |
| | | `id` int(11) NOT NULL AUTO_INCREMENT, |
| | | `log_time` varchar(50) DEFAULT NULL, |
| | | PRIMARY KEY (`id`) |
| | | ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COMMENT='记录每次更新的时间节点,主要是为了方便后续的节点'; |
| | | |
| | | -- 正在导出表 stock_plan.days_info 的数据:~6 rows (大约) |
| | | /*!40000 ALTER TABLE `days_info` DISABLE KEYS */; |
| | | INSERT INTO `days_info` (`id`, `log_time`) VALUES |
| | | (1, '2025-02-12'), |
| | | (2, '2025-02-10'), |
| | | (3, '2025-02-09'), |
| | | (4, '2025-02-08'), |
| | | (5, '2025-02-11'), |
| | | (6, '2025-02-26'), |
| | | (7, '2025-02-27'), |
| | | (8, '2025-02-28'); |
| | | /*!40000 ALTER TABLE `days_info` ENABLE KEYS */; |
| | | |
| | | -- 导出 表 stock_plan.stock_pool 结构 |
| | | CREATE TABLE IF NOT EXISTS `stock_pool` ( |
| | | `id` int(11) NOT NULL AUTO_INCREMENT, |
| | | `name` varchar(50) DEFAULT NULL COMMENT '股票名', |
| | | `code` varchar(50) DEFAULT NULL COMMENT '股票代号', |
| | | `in_price` double DEFAULT NULL COMMENT '列入监控的价格', |
| | | `in_time` varchar(50) DEFAULT NULL COMMENT '列入监控的时间', |
| | | `cur_price` double DEFAULT NULL COMMENT '当前收盘价', |
| | | `percent` double DEFAULT NULL COMMENT '盈亏百分比', |
| | | `out_price` double DEFAULT NULL COMMENT '卖出的价格', |
| | | `out_time` varchar(50) DEFAULT NULL COMMENT '卖出的时间', |
| | | `type` varchar(50) NOT NULL DEFAULT 'week' COMMENT '周期类型,day,week,month,quarter,year', |
| | | `state` int(11) NOT NULL DEFAULT '1' COMMENT '状态 1=监测中,2=监测结束', |
| | | PRIMARY KEY (`id`) |
| | | ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COMMENT='股票池,用于监听'; |
| | | |
| | | -- 正在导出表 stock_plan.stock_pool 的数据:~6 rows (大约) |
| | | /*!40000 ALTER TABLE `stock_pool` DISABLE KEYS */; |
| | | INSERT INTO `stock_pool` (`id`, `name`, `code`, `in_price`, `in_time`, `cur_price`, `percent`, `out_price`, `out_time`, `type`, `state`) VALUES |
| | | (1, '龙韵股份', 'SH603729', 15.91, '2000-01-01', 15.5, -2.5769956002514194, NULL, NULL, 'week', 1), |
| | | (2, '龙腾光电', 'SH688055', 3.78, '2025-02-26', 3.88, 2.645502645502651, 3.88, '2025-02-26', 'month', 1), |
| | | (3, '深桑达A', 'SZ000032', 29.25, '2025-02-27', 26.33, -9.982905982905987, NULL, NULL, 'month', 1), |
| | | (4, '航锦科技', 'SZ000818', 32.7, '2025-02-27', 31.45, -3.822629969418967, NULL, NULL, 'month', 1), |
| | | (5, '深信服', 'SZ300454', 109.9, '2025-02-27', 102.06, -7.133757961783438, NULL, NULL, 'month', 1), |
| | | (6, '卫宁健康', 'SZ300253', 11.87, '2025-02-27', 11.03, -7.076663858466725, NULL, NULL, 'month', 1); |
| | | /*!40000 ALTER TABLE `stock_pool` ENABLE KEYS */; |
| | | |
| | | /*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */; |
| | | /*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */; |
| | | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; |
New file |
| | |
| | | -- -------------------------------------------------------- |
| | | -- 主机: 127.0.0.1 |
| | | -- 服务器版本: 5.6.35-log - MySQL Community Server (GPL) |
| | | -- 服务器操作系统: Win64 |
| | | -- HeidiSQL 版本: 9.5.0.5196 |
| | | -- -------------------------------------------------------- |
| | | |
| | | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; |
| | | /*!40101 SET NAMES utf8 */; |
| | | /*!50503 SET NAMES utf8mb4 */; |
| | | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; |
| | | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; |
| | | |
| | | |
| | | -- 导出 stock_plan 的数据库结构 |
| | | CREATE DATABASE IF NOT EXISTS `stock_plan` /*!40100 DEFAULT CHARACTER SET utf8 */; |
| | | USE `stock_plan`; |
| | | |
| | | -- 导出 表 stock_plan.days_info 结构 |
| | | CREATE TABLE IF NOT EXISTS `days_info` ( |
| | | `id` int(11) NOT NULL AUTO_INCREMENT, |
| | | `log_time` varchar(50) DEFAULT NULL, |
| | | PRIMARY KEY (`id`) |
| | | ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COMMENT='记录每次更新的时间节点,主要是为了方便后续的节点'; |
| | | |
| | | -- 数据导出被取消选择。 |
| | | -- 导出 表 stock_plan.stock_day_info 结构 |
| | | CREATE TABLE IF NOT EXISTS `stock_day_info` ( |
| | | `id` int(11) NOT NULL AUTO_INCREMENT, |
| | | `name` varchar(50) DEFAULT NULL COMMENT '股票名字', |
| | | `code` varchar(50) DEFAULT NULL COMMENT '股票代号', |
| | | `market_capital` double DEFAULT NULL COMMENT '总市值', |
| | | `market_capital_float` double DEFAULT NULL COMMENT '流通市值', |
| | | `percent` double DEFAULT NULL COMMENT '涨跌幅', |
| | | `open` double DEFAULT NULL COMMENT '开盘价', |
| | | `high` double DEFAULT NULL COMMENT '最高价', |
| | | `low` double DEFAULT NULL COMMENT '最低价', |
| | | `close` double DEFAULT NULL COMMENT '收盘价', |
| | | `amount` bigint(20) DEFAULT NULL COMMENT '成交额', |
| | | `volume` bigint(20) DEFAULT NULL COMMENT '成交量', |
| | | `turnover_rate` double DEFAULT NULL COMMENT '换手率', |
| | | `pe_ttm` double DEFAULT NULL COMMENT '市盈率', |
| | | `time_trade` varchar(50) DEFAULT NULL COMMENT '交易时间', |
| | | PRIMARY KEY (`id`) |
| | | ) ENGINE=InnoDB AUTO_INCREMENT=10368475 DEFAULT CHARSET=utf8 COMMENT='每日行情信息,用于处理每天交易排名的'; |
| | | |
| | | -- 数据导出被取消选择。 |
| | | -- 导出 表 stock_plan.stock_pool 结构 |
| | | CREATE TABLE IF NOT EXISTS `stock_pool` ( |
| | | `id` int(11) NOT NULL AUTO_INCREMENT, |
| | | `name` varchar(50) DEFAULT NULL COMMENT '股票名', |
| | | `code` varchar(50) DEFAULT NULL COMMENT '股票代号', |
| | | `in_price` double DEFAULT NULL COMMENT '列入监控的价格', |
| | | `in_time` varchar(50) DEFAULT NULL COMMENT '列入监控的时间', |
| | | `cur_price` double DEFAULT NULL COMMENT '当前收盘价', |
| | | `percent` double DEFAULT NULL COMMENT '盈亏百分比', |
| | | `out_price` double DEFAULT NULL COMMENT '卖出的价格', |
| | | `out_time` varchar(50) DEFAULT NULL COMMENT '卖出的时间', |
| | | `type` varchar(50) NOT NULL DEFAULT 'week' COMMENT '周期类型,day,week,month,quarter,year', |
| | | `state` int(11) NOT NULL DEFAULT '1' COMMENT '状态 1=监测中,2=监测结束', |
| | | PRIMARY KEY (`id`) |
| | | ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COMMENT='股票池,用于监听'; |
| | | |
| | | -- 数据导出被取消选择。 |
| | | /*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */; |
| | | /*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */; |
| | | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; |