| | |
| | | #include <QJsonObject> |
| | | #include <QJsonArray> |
| | | #include <QLibrary> // 用于加载dll动态库的类 |
| | | #include <QDateTime> |
| | | |
| | | |
| | | #pragma execution_character_set("utf-8") |
| | | |
| | | GetStockList::GetStockList(QWidget *parent) : |
| | | QMainWindow(parent), |
| | |
| | | ui->pushButton_get->hide(); |
| | | ui->statusbar->hide(); |
| | | |
| | | // 注册元类型 |
| | | qRegisterMetaType<QVector<QVector<QString>>>("QVector<QVector<QString>> &"); |
| | | // 方案2: |
| | | // 如果https 访问的时候,还是爬取失败,可以代码加载动态库来支持 |
| | | // 前提条件是把2个dll动态库拷贝的生成目录中:libeay32.dll 和 ssleay32.dll |
| | | // 拷贝到生成目录,就可以直接加载 |
| | | // 若是msvc 64bit的编译器,需要下载对应位数的dll库来拷贝即可 -- openssl-1.0.2q-x64_86-win64.zip |
| | | |
| | | QLibrary lb("libeay32.dll"); |
| | | if(lb.load()){ |
| | | qDebug()<<"load libeay32.dll 成功"; |
| | |
| | | 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::MatchContains); // 前缀匹配、包含、后缀 |
| | | ui->lineEdit_search->setCompleter(m_completer); // 关联匹配的控件 |
| | | |
| | | } |
| | | |
| | | GetStockList::~GetStockList() |
| | |
| | | m_model->appendRow(rowItems); |
| | | } |
| | | } |
| | | |
| | | // 发射信号 |
| | | emit sendCodeNames(m_codeNames); |
| | | } |
| | | |
| | | |
| | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | |
| | | 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){ // 计算量能比 |
| | |
| | | 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); |
| | | emit sendInfoMess(info); |
| | | if(volume_rate > 4){ |
| | | QString info = QString("<font size=8 color=blue> %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); |
| | | }else{ |
| | | 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); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | |
| | | 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(); |
| | | |
| | |
| | | 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请求到的数据,进行分析 |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | 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() |
| | | { |
| | | ui->tableView->clearSelection(); |
| | | 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)); |
| | | ui->tableView->selectRow(i); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | void GetStockList::on_lineEdit_search_returnPressed() |
| | | { |
| | | on_pushButton_search_clicked(); |
| | | } |
| | | |
| | | void GetStockList::showHistoryModelData(QVector<QVector<QString>> &model) // 从历史那边将数据发过来 |
| | | { |
| | | qDebug()<<QDateTime::currentDateTime(); |
| | | m_model->setRowCount(0); |
| | | for(int i=0;i<model.size();++i){ |
| | | //qDebug()<<"i="<<i; |
| | | QList<QStandardItem*> items; |
| | | m_codeNames[model[i][1]] = model[i][0]; |
| | | for(int j=0;j<model.at(0).size();++j){ |
| | | items.append(new QStandardItem(model[i][j])); |
| | | |
| | | if(j==2){ |
| | | items.append(new QStandardItem(model[i][j])); |
| | | } |
| | | if(j==3){ |
| | | QStandardItem *percentItem = items.back(); |
| | | if(percentItem->text().toDouble() > 0){ |
| | | percentItem->setData(QColor("red"),Qt::DecorationRole); // 添加一个装饰的颜色为红色 |
| | | percentItem->setData(QColor("red"),Qt::TextColorRole); // 将字体颜色设置为红色 |
| | | items.at(0)->setData(QColor("red"),Qt::TextColorRole); // 将股票名字设置为红色 |
| | | } |
| | | else if(percentItem->text().toDouble() < 0){ |
| | | percentItem->setData(QColor("green"),Qt::BackgroundColorRole); |
| | | items.at(0)->setData(QColor("green"),Qt::TextColorRole); |
| | | } |
| | | } |
| | | |
| | | } |
| | | m_model->appendRow(items); |
| | | } |
| | | qDebug()<<"历史到信息赋值完成 行数:"<<m_model->rowCount(); |
| | | qDebug()<<QDateTime::currentDateTime(); |
| | | } |
| | | |
| | | void GetStockList::showHistoryModelData(QStandardItemModel *model) |
| | | { |
| | | |
| | | // qDebug()<<QDateTime::currentDateTime(); |
| | | // //ui->tableView->setModel(model); |
| | | // QVector<QVector<QString>> vec; |
| | | // for(int i=0;i<model->rowCount();++i){ |
| | | // //QString row; |
| | | // QVector<QString> tmp; |
| | | |
| | | // m_codeNames[model->item(i,1)->text()] = model->item(i,0)->text(); |
| | | |
| | | // for(int j=0;j<model->columnCount();++j){ |
| | | // //row+=model->item(i,j)->text()+" "; |
| | | // tmp.append(model->item(i,j)->text()); |
| | | // } |
| | | // //qDebug()<<i<<row; |
| | | // vec.append(tmp); |
| | | // } |
| | | // qDebug()<<"vec size:"<<vec.size(); |
| | | |
| | | qDebug()<<QDateTime::currentDateTime(); |
| | | m_model->setRowCount(0); |
| | | for(int i=0;i<model->rowCount();++i){ |
| | | QList<QStandardItem*> items; |
| | | m_codeNames[model->item(i,1)->text()] = model->item(i,0)->text(); |
| | | for(int j=0;j<model->columnCount();++j){ |
| | | items.append(new QStandardItem(model->item(i,j)->text())); |
| | | if(j==2){ |
| | | items.append(new QStandardItem(model->item(i,j)->text())); |
| | | } |
| | | if(j==3){ |
| | | QStandardItem *percentItem = items.back(); |
| | | if(percentItem->text().toDouble() > 0){ |
| | | percentItem->setData(QColor("red"),Qt::DecorationRole); // 添加一个装饰的颜色为红色 |
| | | percentItem->setData(QColor("red"),Qt::TextColorRole); // 将字体颜色设置为红色 |
| | | items.at(0)->setData(QColor("red"),Qt::TextColorRole); // 将股票名字设置为红色 |
| | | } |
| | | else if(percentItem->text().toDouble() < 0){ |
| | | percentItem->setData(QColor("green"),Qt::BackgroundColorRole); |
| | | items.at(0)->setData(QColor("green"),Qt::TextColorRole); |
| | | } |
| | | } |
| | | } |
| | | m_model->appendRow(items); |
| | | } |
| | | qDebug()<<"历史到信息赋值完成 条数:"<<m_model->rowCount(); |
| | | qDebug()<<QDateTime::currentDateTime(); |
| | | } |