因为Tushare的数据来源是
聚合数据 最重要免费的
接口这次换成聚合数据,
参考资料我从这里拿 的,https://www.juhe.cn/docs/api/id/21
不过由于没有C++ 的代码,我们先看C#的可以拿 过来改一下。
又一个WordPress站点
因为Tushare的数据来源是
接口这次换成聚合数据,
参考资料我从这里拿 的,https://www.juhe.cn/docs/api/id/21
不过由于没有C++ 的代码,我们先看C#的可以拿 过来改一下。
首先通过VC++ 建新一个项目,选择空项目,并且在项目中添加 testpython.c文件
如何实现 C/C++ 与 Python 的通信? – 编程 – 知乎
在Windows平台下,打开Visual Studio命令提示符,编译命令为
cl testpython.c -IC:\Python34\include C:\Python34\libs\python34.lib
编译成功,直接输入 testpython.exe 就可以运行,看到执行效果如图
Vc++ 调用python 是成功。
也算是一个抛砖引玉的过程,首先在CStkLibWnd中加入方法
int LoadCodetable( CStockContainer &container ); // 读取所有股票的信息 int LoadCodeTableByMarket(CStockContainer& container, DWORD dwMarket);
int CStkLibWnd::LoadCodetable( CStockContainer & container ) { if(!IsOK()) return 0; //上海指数 LoadCodeTableByMarket(container, CStock::marketSHSE); //深圳指数 LoadCodeTableByMarket(container, CStock::marketSZSE); return container.GetSize(); } int CStkLibWnd::LoadCodeTableByMarket(CStockContainer& container, DWORD dwMarket) int ncrow=0; CSPString strSql = ""; CSPString strStockCode = ""; CSPString strMarKet=GetMarket(dwMarket); strSql.Format( "select * from StockList where Market='%s' order by Market,Code",strMarKet); int nRow=0; try { _RecordsetPtr m_pRecordsetT; m_pRecordsetT.CreateInstance(__uuidof(Recordset)); m_pRecordsetT->Open(_variant_t(strSql), m_pCnn.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText); if(!m_pRecordsetT->adoEOF) { _variant_t var; while(!m_pRecordsetT->adoEOF) { CStockInfo info; var = m_pRecordsetT->GetCollect("Code"); if(var.vt != VT_NULL) { strStockCode=(LPCSTR)_bstr_t(var); info.SetStockCode(dwMarket,strStockCode); } var = m_pRecordsetT->GetCollect("ChineseName"); if(var.vt != VT_NULL) { CSPString sValue=(LPCSTR)_bstr_t(var); info.SetStockName(sValue); } var = m_pRecordsetT->GetCollect("ShortName"); if(var.vt != VT_NULL) { CSPString sValue=(LPCSTR)_bstr_t(var); info.SetStockShortName(sValue); } var = m_pRecordsetT->GetCollect("otherName"); if(var.vt != VT_NULL) { CSPString sValue=(LPCSTR)_bstr_t(var); info.SetStockNameEnu(sValue); } void * pArrayID = NULL; if (info.IsValidStock()) { container.Add(info); } m_pRecordsetT->MoveNext(); } } m_pRecordsetT->Close(); } catch(_com_error e) { return container.GetSize(); } ncrow = container.GetSize(); return container.GetSize(); }
打开 StkLib项目中Database.cpp 找到函数LoadCodetable( CStockContainer & container )
函数里面加入
int nSize = 0; int nSize2 = 0; if(AfxGetCStkLibWnd().IsOK()) { nSize2 = AfxGetCStkLibWnd().LoadCodetable(container); if(nSize2>0) return nSize2; }
确保首先执行。
看看调试的结果.
成功能了。
//编写了几个连接数据库的函数,由于是公共函数,可以独立编写在新的文件中,例如我自己建了一个StkFunction.h ,StkFunction.cpp上
在CStkLibWnd 中增加了数据库相关的变量及初始化的函数,
BOOL m_IsSqlDBConnect; //是否已经连接Sql Db
_ConnectionPtr m_pCnn; //连接数据库
CSPString m_szConnString;//连接字符串
DBInitTable() ; //数据库初始化
CnnExecuteSql(CSPString sSql, bool nErr); //执行Sql命令
////////用于执行Sql命令
int CStkLibWnd::CnnExecuteSql(CSPString sSql, bool nErr)
{
_variant_t vntRecs[100];
long lRecs=1;
if(nErr)
{
try
{
m_pCnn->Execute(_bstr_t(sSql),
vntRecs,
adCmdText);
}
catch(_com_error e)
{
lRecs=0;
}
}
else
{
m_pCnn->Execute(_bstr_t(sSql),
vntRecs,
adCmdText);
}
return lRecs;
}
// DBInitTable() 只需要运行一次即可,把test()的改一下并运行一次就好。
int CStkLibWnd::DBInitTable()
{
CSPString sSql = “”;
int nflase =0;
//1. 证券代码表
sSql= “CREATE TABLE STK_STOCK( \n”
“m_wMarket [varchar](8), \n”
“m_szLabel Varchar(10), \n”
“m_szName Varchar(32), \n”
“m_szPingYing [varchar](10), \n”
“m_nUnit numeric(4), \n”
“m_nDigit numeric(4), \n”
“m_fLastClose [numeric](18,6), \n”
“[m_time] [datetime] ) \n”;
nflase += CnnExecuteSql(sSql, true);
//2. 实行行情
sSql= “CREATE TABLE STK_REPORT( \n”
“[m_cbSize] [varchar](4), \n”
“[m_wMarket] [varchar](8), \n”
“[m_szLabel] [varchar](10) ,\n”
“[m_szName] [varchar](30), \n”
“[m_time] [datetime] , \n”
“[m_dwFlag] [varchar](4), \n”
“[m_fLast] [numeric](18,6), \n”
“[m_fOpen] [numeric](18,6), \n”
“[m_fHigh] [numeric](18,6), \n”
“[m_fLow] [numeric](18,6), \n”
“[m_fNew] [numeric](18,6), \n”
“[m_fVolume] [numeric](18,6), \n”
“[m_fAmount] [numeric](18,6), \n”
“[m_fBuyPrice1] [numeric](18,6), \n”
“[m_fBuyVolume1] [numeric](18,6), \n”
“[m_fSellPrice1] [numeric](18,6), \n”
“[m_fSellVolume1] [numeric](18,6), \n”
“[m_fBuyPrice2] [numeric](18,6), \n”
“[m_fBuyVolume2] [numeric](18,6), \n”
“[m_fSellPrice2] [numeric](18,6), \n”
“[m_fSellVolume2] [numeric](18,6), \n”
“[m_fBuyPrice3] [numeric](18,6), \n”
“[m_fBuyVolume3] [numeric](18,6), \n”
“[m_fSellPrice3] [numeric](18,6), \n”
“[m_fSellVolume3] [numeric](18,6), \n”
“[m_fBuyPrice4] [numeric](18,6), \n”
“[m_fBuyVolume4] [numeric](18,6), \n”
“[m_fSellPrice4] [numeric](18,6), \n”
“[m_fSellVolume4] [numeric](18,6), \n”
“[m_fBuyPrice5] [numeric](18,6), \n”
“[m_fBuyVolume5] [numeric](18,6), \n”
“[m_fSellPrice5] [numeric](18,6), \n”
“[m_fSellVolume5] [numeric](18,6), \n”
“[m_fAvgPrice] [numeric](18,6), \n”
“[m_dwTickAll] [varchar](4)) \n”;
nflase += CnnExecuteSql(sSql, true);
//3. 分笔数据(盘口) 主表
sSql= “CREATE TABLE STK_TICK_HDR ( \n”
“[m_wMarket] [varchar](8), \n”
“[m_szLabel] [varchar](10), \n”
“[m_lDate] DateTime, \n”
“[m_fLastClose] [numeric](18,6), \n”
“[m_fOpen] [numeric](18,6), \n”
“[m_nAllCount] [numeric](18,6), \n”
“[m_nCount] [numeric](18,6)) \n”;
nflase += CnnExecuteSql(sSql, true);
//4. 分笔数据(盘口) 从表
sSql= “CREATE TABLE STK_TICK( \n”
“[m_wMarket] [varchar](8), \n”
“[m_szLabel] [varchar](10) ,\n”
“[m_szName] [varchar](30), \n”
“[m_time] DateTime, \n”
“[m_lTime] DateTime, \n”
“[m_fHigh] [numeric](18,6), \n”
“[m_fLow] [numeric](18,6), \n”
“[m_fNewPrice] [numeric](18,6), \n”
“[m_fVolume] [numeric](18,6), \n”
“[m_fAmount] [numeric](18,6), \n”
“[m_lStroke] [numeric](18,6), \n”
“[m_fBuyPrice1] [numeric](18,6), \n”
“[m_fBuyVolume1] [numeric](18,6), \n”
“[m_fSellPrice1] [numeric](18,6), \n”
“[m_fSellVolume1] [numeric](18,6), \n”
“[m_fBuyPrice2] [numeric](18,6), \n”
“[m_fBuyVolume2] [numeric](18,6), \n”
“[m_fSellPrice2] [numeric](18,6), \n”
“[m_fSellVolume2] [numeric](18,6), \n”
“[m_fBuyPrice3] [numeric](18,6), \n”
“[m_fBuyVolume3] [numeric](18,6), \n”
“[m_fSellPrice3] [numeric](18,6), \n”
“[m_fSellVolume3] [numeric](18,6), \n”
“[m_fBuyPrice4] [numeric](18,6), \n”
“[m_fBuyVolume4] [numeric](18,6), \n”
“[m_fSellPrice4] [numeric](18,6), \n”
“[m_fSellVolume4] [numeric](18,6), \n”
“[m_fBuyPrice5] [numeric](18,6), \n”
“[m_fBuyVolume5] [numeric](18,6), \n”
“[m_fSellPrice5] [numeric](18,6), \n”
“[m_fSellVolume5] [numeric](18,6))\n”;
nflase += CnnExecuteSql(sSql, true);
//5. 补充除权数据
sSql= “CREATE TABLE STK_POWER ( \n”
“[m_dwHeadTag] [varchar](4), \n”
“[m_wMarket] [varchar](8), \n”
“[m_szLabel] [varchar](10), \n”
“[m_time] DateTime, \n”
“[m_fGive] [numeric](18,6), \n”
“[m_fPei] [numeric](18,6), \n”
“[m_fPeiPrice] [numeric](18,6), \n”
“[m_fProfit] [numeric](18,6), \n”
“[m_dwReserved] [varchar](4)) \n”;
nflase += CnnExecuteSql(sSql, true);
//6. 分时数据
sSql= “CREATE TABLE STK_KDATA_MIN (\n”
“[m_dwHeadTag] [varchar](4), \n”
“[m_wMarket] [varchar](8), \n”
“[m_szLabel] [varchar](10), \n”
“[m_date] DateTime, \n”
“[m_time] DateTime, \n”
“[m_fOpen] [numeric](18,6), \n”
“[m_fHigh] [numeric](18,6), \n”
“[m_fLow] [numeric](18,6), \n”
“[m_fClose] [numeric](18,6), \n”
“[m_fVolume] [numeric](18,6), \n”
“[m_fAmount] [numeric](18,6), \n”
“[m_dwAdvance] [varchar](4), \n”
“[m_dwDecline] [varchar](4), \n”
“[m_dwReserved] [varchar](4)) \n”;
nflase += CnnExecuteSql(sSql, true);
//7. 日线数据表
sSql= “CREATE TABLE STK_KDATA_DAY( \n”
“[m_dwHeadTag] [varchar](4), \n”
“[m_wMarket] [varchar](8), \n”
“[m_szLabel] [varchar](10), \n”
“[m_time] DateTime, \n”
“[m_fOpen] [numeric](18,6), \n”
“[m_fHigh] [numeric](18,6), \n”
“[m_fLow] [numeric](18,6), \n”
“[m_fClose] [numeric](18,6), \n”
“[m_fVolume] [numeric](18,6), \n”
“[m_fAmount] [numeric](18,6), \n”
“[m_wAdvance] [varchar](4), \n”
“[m_wDecline] [varchar](4)) \n”;
nflase += CnnExecuteSql(sSql, true);
//8. 1分钟数据线
sSql= “CREATE TABLE STK_KDATA_MIN1 (\n”
“[m_dwHeadTag] [varchar](4), \n”
“[m_wMarket] [varchar](8), \n”
“[m_szLabel] [varchar](10), \n”
“[m_date] DateTime, \n”
“[m_time] DateTime, \n”
“[m_fOpen] [numeric](18,6), \n”
“[m_fHigh] [numeric](18,6), \n”
“[m_fLow] [numeric](18,6), \n”
“[m_fClose] [numeric](18,6), \n”
“[m_fVolume] [numeric](18,6), \n”
“[m_fAmount] [numeric](18,6), \n”
“[m_dwAdvance] [varchar](4), \n”
“[m_dwDecline] [varchar](4), \n”
“[m_dwReserved] [varchar](4)) \n”;
nflase += CnnExecuteSql(sSql, true);
//9. 5分钟数据线
sSql= “CREATE TABLE STK_KDATA_MIN5 ( \n”
“[m_dwHeadTag] [varchar](4), \n”
“[m_wMarket] [varchar](8), \n”
“[m_szLabel] [varchar](10), \n”
“[m_date] DateTime, \n”
“[m_time] DateTime, \n”
“[m_fOpen] [numeric](18,6), \n”
“[m_fHigh] [numeric](18,6), \n”
“[m_fLow] [numeric](18,6), \n”
“[m_fClose] [numeric](18,6), \n”
“[m_fVolume] [numeric](18,6), \n”
“[m_fAmount] [numeric](18,6), \n”
“[m_dwAdvance] [varchar](4), \n”
“[m_dwDecline] [varchar](4), \n”
“[m_dwReserved] [varchar](4)) \n”;
nflase += CnnExecuteSql(sSql, true);
//10. 操作记录表
sSql= “CREATE TABLE STK_LOG ( \n”
” m_date DateTime, \n”
” m_Updated [varchar](10), \n”
” m_nCount [numeric](8), \n”
” m_wMarket [varchar](10), \n”
” m_szLabel [varchar](10), \n”
” m_Type [varchar](30)) \n”;
nflase += CnnExecuteSql(sSql, true);
//11. 基本信息表
sSql= “create table basedata( \n”
“m_dwMarket varchar(8),\n” // DWORD ; 证券市场类型,see CStock::StockMarket
“m_szCode varchar(8),\n” // char m_szCode[STKLIB_MAX_CODE2]; // 证券代码,以’\0’结尾
“m_szDomain varchar(20),\n” // char m_szDomain[STKLIB_MAX_DOMAIN]; // 板块
“m_szProvince varchar(20),\n” // char m_szProvince[STKLIB_MAX_PROVINCE]; // 省份
“m_time datetime,\n” // time_t m_time; // 日期,time_t
“m_date datetime,\n” // DWORD m_date; // 日期 Format is YYYYMMDD for base data
“m_reporttype numeric(18,6),\n” // LONG m_reporttype; // 报告类型:年报、中报、季报
“m_fErate_dollar numeric(18,6),\n” // float m_fErate_dollar; // 当期美元汇率
“m_fErate_hkdollar numeric(18,6),\n” //float m_fErate_hkdollar; // 当期港币汇率 –// ★偿债能力
“m_fRatio_liquidity numeric(18,6),\n” // float m_fRatio_liquidity; // 流动比率
“m_fRatio_quick numeric(18,6),\n” // float m_fRatio_quick; // 速动比率
“m_fVelocity_receivables numeric(18,6),\n” // float m_fVelocity_receivables; // 应收帐款周率–// ★经营能力
“m_fVelocity_merchandise numeric(18,6),\n” // float m_fVelocity_merchandise; // 存货周转率
“m_fMain_income numeric(18,6),\n” // float m_fMain_income; // 主营业务收入
“m_fCash_ps numeric(18,6),\n” // float m_fCash_ps; // 每股净现金流量–// ★盈利能力
“m_fProfit_margin numeric(18,6),\n” // float m_fProfit_margin; // 主营业务利润率 %
“m_fNetasset_yield numeric(18,6),\n” // float m_fNetasset_yield; // 净资产收益率 %
“m_datebegin datetime,\n” // DWORD m_datebegin; // 上市日期 Format is YYYYMMDD-// ★资本结构
“m_fShare_count_total varchar(20),\n” // float m_fShare_count_total; // 总股本
“m_fShare_count_a varchar(20),\n” // float m_fShare_count_a; // 流通A股
“m_fShare_count_b varchar(20),\n” //float m_fShare_count_b; // 流通B股
“m_fShare_count_h varchar(20),\n” //float m_fShare_count_h; // 流通H股
“m_fShare_count_national varchar(20),\n” //float m_fShare_count_national; // 国有股
“m_fShare_count_corp varchar(20),\n” //float m_fShare_count_corp; // 法人股
“m_fProfit_psud varchar(20),\n” //float m_fProfit_psud; // 每股未分配利润
“m_fAsset varchar(20),\n” //float m_fAsset; // 总资产
“m_fRatio_holderright varchar(20),\n” //float m_fRatio_holderright; // 股东权益比率
“m_fRatio_longdebt varchar(20),\n” //float m_fRatio_longdebt; // 长期负债率
“m_fRatio_debt varchar(20),\n” //float m_fRatio_debt; // 资产负债率–// ★投资收益能力
“m_fNetasset_ps varchar(20),\n” //float m_fNetasset_ps; // 每股净资产
“m_fNetasset_ps_regulate varchar(20),\n” //float m_fNetasset_ps_regulate; // 调整每股净资产
“m_fEps varchar(20),\n” //float m_fEps; // 每股收益
“m_fEps_deduct varchar(20),\n” //float m_fEps_deduct; // 扣除后每股收益
“m_fNet_profit varchar(20),\n” //float m_fNet_profit; // 净利润
“m_fMain_profit varchar(20),\n” //float m_fMain_profit; // 主营业务利润
“m_fTotal_profit varchar(20),\n” //float m_fTotal_profit; // 利润总额–// ★增长率
“m_fProfit_inc varchar(20),\n” //float m_fProfit_inc; // 主营利润增长率%
“m_fIncome_inc varchar(20),\n” //float m_fIncome_inc; // 主营收入增长率%
“m_fAsset_inc varchar(20),\n” //float m_fAsset_inc; // 总资产增长率%” –// ★技术数据统计值
“m_fYield_average varchar(20),\n” //float m_fYield_average; // 平均收益率%
“m_fYield_stddev varchar(20),\n” //float m_fYield_stddev; // 收益标准差%
“m_fBeite varchar(20),\n” //float m_fBeite; // β值
“m_dwReserved1 varchar(8),\n” // DWORD m_dwReserved[4];
“m_dwReserved2 varchar(8),\n” //
“m_dwReserved3 varchar(8),\n” //
“m_dwReserved4 varchar(8),\n” //
“) \n”; //
nflase += CnnExecuteSql(sSql, true);
sSql.Format(“insert into STK_LOG (m_date, m_Updated, m_nCount, m_wMarket, m_szLabel, m_Type)”
“select GETDATE(),’SYSTEM’, %d, ”,”,’连接,更新数据表'”,nflase);
nflase += CnnExecuteSql(sSql,true);
return nflase;
}