A股api交易接口是在股票量化交易中常用到的一种量化工具,对于它的用法,小编针对性的以文档的例子说明:
交易接口API 功能概述:
名称 | 功能 | |
基本函数 | Init | API 初始化 |
Deinit | API 反初始化 | |
Logon | 登录交易账户 | |
Logoff | 登出交易账户 | |
QueryData | 查询各类交易数据 | |
QueryHistoryData | 查询各类历史数据 | |
SendOrder | 委托下单 | |
CancelOrder | 委托撤单 | |
GetQuote | 获取五档报价 | |
Repay | 融资融券账户直接还款 | |
GetExpireDate | 查询 API 授权到期日期 | |
单账户批量函数 | QueryDatas | 单账户批量查询各类交易数据 |
SendOrders | 单账户批量下单 | |
CancelOrders | 单账户批量撤单 | |
GetQuotes | 单账户批量获取五档报价 | |
多账户批量函数 | QueryMultiAccountsDatas | 多账户批量查询各类交易数据 |
SendMultiAccountsOrders | 多账户批量下单 | |
CancelMultiAccountsOrders | 多账户批量撤单 | |
GetMultiAccountsQuotes | 多账户批量获取五档报价 | |
也就是说,A股api交易接口API文档接口其实是一些预先定义的函数,或指软件系统不同组成部分衔接的约定。开发人员可以使用这些API股票自动交易接口接口进行编程开发,而又无需访问源码,或理解内部工作机制的细节。比较常见的现实场景是在开发安卓应用时需要使用到安卓系统提供的API,在进行Windows桌面应用开发时需要用到微软系统提供的API,在进行微信小程序开发时可使用微信开放A股api交易接口试用,能够提供了交易者的开发和使用。
A股api交易接口常见的接口开发A股股票代码的程序如下:
void stockDialog::on_refreshStock_clicked()
{
stockNumList.clear();
QTime startTime = QTime::currentTime();
ui->refreshStatus->setText("正在更新股票数量...");
QSqlQuery query;
QString sel = QString("select stockNum from stocklist");
bool result = query.exec(sel);
if(result){
while(query.next()){
QString stockNum = query.value(0).toString();
stockNumList<<stockNum;//获取所有股票代码
}
}
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager,SIGNAL(finished(QNetworkReply*)),this, SLOT(writeData(QNetworkReply*)));
for(int i=600000;i<604000;i++){//上证范围
if(stockNumList.contains(QString::number(i,10)))
continue;
QNetworkRequest request(stockSource1.arg(i).arg(ui->lastTime->text()).arg(ui->thisTime->text()));
request.setHeader(QNetworkRequest::ContentTypeHeader,
"application/x-www-form-urlencoded");
manager->get(request);
sleep(20);
}
for(int i=300000;i<300999;i++){//创业板范围,后续可能需要加大
if(stockNumList.contains(QString::number(i,10)))
continue;
QNetworkRequest request(stockSource1.arg(i).arg(ui->lastTime->text()).arg(ui->thisTime->text()));
request.setHeader(QNetworkRequest::ContentTypeHeader,
"application/x-www-form-urlencoded");
manager->get(request);
sleep(20);
}
for(int i=1600;i<2999;i++){
QString ii = "00"+QString::number(i, 10);
if(stockNumList.contains(ii))
continue;
QNetworkRequest request(stockSource1.arg(ii).arg(ui->lastTime->text()).arg(ui->thisTime->text()));
request.setHeader(QNetworkRequest::ContentTypeHeader,
"application/x-www-form-urlencoded");
manager->get(request);
sleep(20);
}
for(int i=100;i<1000;i++){
QString ii = "000"+QString::number(i, 10);
if(stockNumList.contains(ii))
continue;
QNetworkRequest request(stockSource1.arg(ii).arg(ui->lastTime->text()).arg(ui->thisTime->text()));
request.setHeader(QNetworkRequest::ContentTypeHeader,
"application/x-www-form-urlencoded");
manager->get(request);
sleep(20);
}
for(int i=10;i<100;i++){
QString ii = "0000"+QString::number(i, 10);
if(stockNumList.contains(ii))
continue;
QNetworkRequest request(stockSource1.arg(ii).arg(ui->lastTime->text()).arg(ui->thisTime->text()));
request.setHeader(QNetworkRequest::ContentTypeHeader,
"application/x-www-form-urlencoded");
manager->get(request);
sleep(20);
}
for(int i=1;i<10;i++){
QString ii = "00000"+QString::number(i, 10);
if(stockNumList.contains(ii))
continue;
QNetworkRequest request(stockSource1.arg(ii).arg(ui->lastTime->text()).arg(ui->thisTime->text()));
request.setHeader(QNetworkRequest::ContentTypeHeader,
"application/x-www-form-urlencoded");
manager->get(request);
sleep(20);
}
QTime stopTime = QTime::currentTime();
int elapsed = startTime.msecsTo(stopTime)/1000;
QString str = "更新股票数量结束,用时"+QString::number(elapsed, 10)+"秒";
ui->refreshStatus->setText(str);
stockNumList.clear();
result = query.exec(sel);
if(result){
while(query.next()){
QString stockNum = query.value(0).toString();
stockNumList<<stockNum;//a股数据接口获取所有股票代码
}
}
执行示例: