getstocklist.cpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
getstocklist.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
getstocklist.ui | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
regularinvestment.cpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
regularinvestment.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
regularinvestment.ui | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
getstocklist.cpp
@@ -172,6 +172,14 @@ m_getCodeTimer = new QTimer(this); connect(m_getCodeTimer,SIGNAL(timeout()),this,SLOT(getCodeSlot())); // 支持编辑框的模糊匹配 m_completer = new QCompleter(this); m_completer->setModel(m_customModel); m_completer->setCaseSensitivity(Qt::CaseInsensitive); // 不区分大小写 m_completer->setCompletionMode(QCompleter::PopupCompletion); // 自动显示下拉框 m_completer->setFilterMode(Qt::MatchStartsWith); // 前缀匹配 ui->lineEdit_search->setCompleter(m_completer); // 关联匹配的控件 } GetStockList::~GetStockList() @@ -395,6 +403,8 @@ double volume_rate = volume_cur / volume_old; if(volume_rate > 2){ qDebug()<<"底部反转策略:量能比"<<volume_rate<<code <<curDateTime<<"价格:" <<close; QString info = QString("<font size=8 color=red> %4 底部反转策略:量能 时间:%1 价格:%2 量能比值=%3 </font>").arg(curDateTime).arg(close).arg(volume_rate).arg(code); emit sendInfoMess(info); } } @@ -503,6 +513,7 @@ double ma30 = jArr.at(i).toArray().at(15).toVariant().toDouble(); double open = jArr.at(i).toArray().at(2).toVariant().toDouble(); long long market_cap = jArr.at(i).toArray().at(22).toVariant().toLongLong(); double volume_rate = 0; if(i > 0){ // 计算量能比 @@ -514,7 +525,8 @@ if(ma5 >= open && ma10 >= open && ma20 >= open && ma30 >= open && ma5 <= close && ma10 <= close && ma20 <= close && ma30 <= close){ qDebug()<<"一阳穿四线:"<< code <<curDateTime<<" 价格:"<<close << "量能比:"<<volume_rate; QString info = QString("<font size=8 color=red> %3 %4 一阳穿四线:%1 价格:%2 量能比:%5 周期:%6 </font>").arg(curDateTime).arg(close).arg(code).arg(m_codeNames[code]).arg(volume_rate).arg(m_dateType); QString info = QString("<font size=8 color=red> %3 %4 一阳穿四线:%1 价格:%2 量能比:%5 周期:%6 市值:%7亿</font>").arg(curDateTime).arg(close).arg(code).arg(m_codeNames[code]).arg(volume_rate) .arg(m_dateType).arg(market_cap/100000000.0); emit sendInfoMess(info); } } @@ -810,7 +822,7 @@ */ qDebug()<<"执行底部反转策略"; emit sendInfoMess("<font size=12 color=pink>执行MACD策略 </font>"); emit sendInfoMess("<font size=12 color=pink>执行底部反转策略 </font>"); int curRow = ui->tableView->currentIndex().row(); // QString symbol = m_model->item(curRow,1)->text(); @@ -865,7 +877,7 @@ QString symbol = m_customModel->data(m_customModel->index(curRow,1)).toString(); qint64 begin = QDateTime::currentMSecsSinceEpoch(); // 取当前时间戳 int numsCnt = 200; QString urlStr = QString("https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol=%1&begin=%2&period=%4&type=before&count=-%3&indicator=kline,macd,ma,boll").arg(symbol).arg(begin).arg(numsCnt).arg(m_dateType); QString urlStr = QString("https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol=%1&begin=%2&period=%4&type=before&count=-%3&indicator=kline,macd,ma,boll,market_capital").arg(symbol).arg(begin).arg(numsCnt).arg(m_dateType); qDebug()<<urlStr; qDebug()<<"当前股票:"<<symbol<<m_customModel->data(m_customModel->index(curRow,0)).toString(); // 下一步就是根据url请求到的数据,进行分析 @@ -925,3 +937,34 @@ } } } void GetStockList::on_pushButton_filterCap_clicked() { double begin = ui->lineEdit_beginCap->text().toDouble(); double end = ui->lineEdit_endCap->text().toDouble(); int rows = m_customModel->rowCount(); for(int i=rows - 1;i > 0;--i){ double allCap = m_customModel->data(m_customModel->index(i,2)).toDouble(); if( allCap < begin || allCap > end){ m_customModel->removeRow(i); } } } void GetStockList::on_pushButton_search_clicked() { QString condition = ui->lineEdit_search->text(); for(int i =0;i<m_customModel->rowCount();++i){ if(m_customModel->data(m_customModel->index(i,0)).toString() == condition || m_customModel->data(m_customModel->index(i,1)).toString() == condition) { ui->tableView->setCurrentIndex(m_customModel->index(i,0)); break; } } } void GetStockList::on_lineEdit_search_returnPressed() { on_pushButton_search_clicked(); } getstocklist.h
@@ -11,6 +11,7 @@ #include <QLineSeries> // 折线类 #include <QSplineSeries> // 曲线类 #include <QTimer> #include <QCompleter> // 用于模糊匹配 #include "customitem.h" #include "customsortproxymodel.h" @@ -69,6 +70,12 @@ void getLastClosePrice(QString name); // 通过名字获取股票价格槽 void on_pushButton_filterCap_clicked(); void on_pushButton_search_clicked(); void on_lineEdit_search_returnPressed(); private: Ui::GetStockList *ui; // 这2个用于爬取数据的 @@ -95,6 +102,9 @@ QTimer *m_pollMultiTimer; // 轮询多策略定时器 QCompleter *m_completer; // 支持模糊匹配 }; #endif // GETSTOCKLIST_H getstocklist.ui
@@ -25,6 +25,47 @@ </widget> </item> <item> <widget class="QLineEdit" name="lineEdit_search"> <property name="placeholderText"> <string>请输入股票名字</string> </property> </widget> </item> <item> <widget class="QPushButton" name="pushButton_search"> <property name="text"> <string>查找</string> </property> </widget> </item> <item> <widget class="QLabel" name="label"> <property name="text"> <string>市值(亿):</string> </property> </widget> </item> <item> <widget class="QLineEdit" name="lineEdit_beginCap"/> </item> <item> <widget class="QLabel" name="label_2"> <property name="text"> <string>到</string> </property> </widget> </item> <item> <widget class="QLineEdit" name="lineEdit_endCap"/> </item> <item> <widget class="QPushButton" name="pushButton_filterCap"> <property name="text"> <string>过滤市值</string> </property> </widget> </item> <item> <widget class="QPushButton" name="pushButton_industry"> <property name="text"> <string>获取行业对应股票</string> regularinvestment.cpp
@@ -21,6 +21,7 @@ m_nameCodes["中国神华"]= "SH601088"; m_nameCodes["中国电信"]= "SH601728"; m_nameCodes["中国移动"]= "SH600941"; m_nameCodes["工商银行"]= "SH601398"; // 处理数据爬取的操作 @@ -48,12 +49,19 @@ // 去请求首页 m_manager.get(m_request); // 处理模型 // 处理模型 回测 m_model = new QStandardItemModel(0,7,this); ui->tableView->setModel(m_model); QStringList labels; labels<<"时间"<<"买入价格"<<"数量(手)"<<"所需金额(元)"<<"最新价格"<<"盈亏比"<<"盈亏金额"; m_model->setHorizontalHeaderLabels(labels); // 定投买入 m_modelBuy = new QStandardItemModel(0,9,this); ui->tableView_buyRecord->setModel(m_modelBuy); QStringList buyLabels; buyLabels<<"申请时间"<<"申请价格(元)"<<"成交时间"<<"成交价格(元)"<<"购买数量(手)"<<"所需金额(元)"<<"最新价格(元)"<<"盈亏比"<<"盈亏金额(元)"; m_modelBuy->setHorizontalHeaderLabels(buyLabels); } @@ -66,9 +74,14 @@ void RegularInvestment::showClosePrice(QString name, QString closePrice) { qDebug()<<name<<closePrice; if(ui->comboBox->currentText() == name){ ui->label_closePrice->setText(closePrice); on_lineEdit_2_returnPressed(); // 刷新总价 }else if(ui->comboBox_3->currentText() == name){ ui->label_closePrice_2->setText(closePrice); on_lineEdit_buyNum_returnPressed(); // 刷新总价 } } void RegularInvestment::on_comboBox_currentIndexChanged(const QString &arg1) @@ -203,3 +216,35 @@ ui->label_winAll->setText(QString::number(allWin)); ui->label_allRate->setText(QString::number((allWin/allBuy)*100)); } void RegularInvestment::on_comboBox_3_currentIndexChanged(const QString &arg1) { qDebug()<<"开始定投当前股票为:"<<arg1; emit getClosePriceSignal(arg1); } void RegularInvestment::on_lineEdit_buyNum_returnPressed() { qDebug()<<ui->lineEdit_buyNum->text(); double price = ui->lineEdit_buyNum->text().toInt()* 100 * ui->label_closePrice_2->text().toDouble(); ui->lineEdit_money->setText(QString::number(price)); } void RegularInvestment::on_pushButton_buy_clicked() { QString applyTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); QString name = ui->comboBox_3->currentText(); QString code = m_nameCodes[name]; QString numStr = ui->lineEdit_buyNum->text(); QString applyPrice = ui->label_closePrice_2->text(); double needMoney = numStr.toInt() * applyPrice.toDouble()*100; int rowCnt = m_modelBuy->rowCount(); m_modelBuy->setRowCount(rowCnt+1); m_modelBuy->setItem(rowCnt,0,new QStandardItem(applyTime)); m_modelBuy->setItem(rowCnt,1,new QStandardItem(applyPrice)); m_modelBuy->setItem(rowCnt,4,new QStandardItem(numStr)); m_modelBuy->setItem(rowCnt,5,new QStandardItem(QString::number(needMoney))); } regularinvestment.h
@@ -36,10 +36,17 @@ void on_pushButton_sum_clicked(); void on_comboBox_3_currentIndexChanged(const QString &arg1); void on_lineEdit_buyNum_returnPressed(); void on_pushButton_buy_clicked(); private: Ui::RegularInvestment *ui; QStandardItemModel *m_model; QStandardItemModel *m_modelBuy; QMap<QString,QString> m_nameCodes; // 股票名字及代号 regularinvestment.ui
@@ -18,7 +18,7 @@ <item row="0" column="0"> <widget class="QTabWidget" name="tabWidget"> <property name="currentIndex"> <number>0</number> <number>1</number> </property> <widget class="QWidget" name="tab"> <attribute name="title"> @@ -63,6 +63,11 @@ <item> <property name="text"> <string>中国移动</string> </property> </item> <item> <property name="text"> <string>工商银行</string> </property> </item> </widget> @@ -231,29 +236,142 @@ <attribute name="title"> <string>开始定投</string> </attribute> <layout class="QGridLayout" name="gridLayout_5"> <item row="0" column="0"> <widget class="QGroupBox" name="groupBox_2"> <property name="geometry"> <rect> <x>20</x> <y>30</y> <width>801</width> <height>111</height> </rect> </property> <property name="title"> <string>定投买入</string> </property> </widget> <widget class="QTableView" name="tableView_2"> <property name="geometry"> <rect> <x>20</x> <y>160</y> <width>801</width> <height>391</height> </rect> <layout class="QGridLayout" name="gridLayout_4"> <item row="0" column="0"> <layout class="QHBoxLayout" name="horizontalLayout_4"> <item> <widget class="QLabel" name="label_8"> <property name="text"> <string>个股</string> </property> </widget> </item> <item> <widget class="QComboBox" name="comboBox_3"> <property name="editable"> <bool>true</bool> </property> <item> <property name="text"> <string>长江电力</string> </property> </item> <item> <property name="text"> <string>中国神华</string> </property> </item> <item> <property name="text"> <string>中国电信</string> </property> </item> <item> <property name="text"> <string>中国移动</string> </property> </item> <item> <property name="text"> <string>工商银行</string> </property> </item> </widget> </item> <item> <spacer name="horizontalSpacer_2"> <property name="orientation"> <enum>Qt::Horizontal</enum> </property> <property name="sizeHint" stdset="0"> <size> <width>40</width> <height>20</height> </size> </property> </spacer> </item> <item> <widget class="QLabel" name="label_13"> <property name="text"> <string>最新价(元)</string> </property> </widget> </item> <item> <widget class="QLabel" name="label_closePrice_2"> <property name="text"> <string>0</string> </property> </widget> </item> <item> <spacer name="horizontalSpacer_3"> <property name="orientation"> <enum>Qt::Horizontal</enum> </property> <property name="sizeHint" stdset="0"> <size> <width>40</width> <height>20</height> </size> </property> </spacer> </item> </layout> </item> <item row="0" column="1"> <widget class="QPushButton" name="pushButton_buy"> <property name="text"> <string>申请买入</string> </property> </widget> </item> <item row="1" column="0"> <layout class="QHBoxLayout" name="horizontalLayout_5"> <item> <widget class="QLabel" name="label_11"> <property name="text"> <string>定投金额[元]</string> </property> </widget> </item> <item> <widget class="QLineEdit" name="lineEdit_money"/> </item> </layout> </item> <item row="2" column="0"> <layout class="QHBoxLayout" name="horizontalLayout_6"> <item> <widget class="QLabel" name="label_12"> <property name="text"> <string>定投份数[手]</string> </property> </widget> </item> <item> <widget class="QLineEdit" name="lineEdit_buyNum"> <property name="text"> <string>1</string> </property> </widget> </item> </layout> </item> </layout> </widget> </item> <item row="1" column="0"> <widget class="QTableView" name="tableView_buyRecord"/> </item> </layout> </widget> </widget> </item>