一、增加挂单增加、减少的变量
1.增加变量
G:\stock\TskingVS2019\src\Client\StkLib\Include\Stock.h
/***
单个股票信息类 CStock::dataInfo
*/
class STKLIB_API CStockInfo
{
public:
CStockInfo( );
CStockInfo( const CStockInfo &src );
// Operation
void Clear( );
CStockInfo & operator = ( const CStockInfo & si );
...
public:
DWORD m_datetech; //日期 Format is XXMMDDHHMM for 5min, Format is YYYYMMDD for day
float m_fLast; // 昨收(元)
float m_fOpen; // 开盘(元)
float m_fHigh; // 最高价(元)
float m_fLow; // 最低价(元)
float m_fClose; // 收盘(元)
float m_fVolume; // 成交量(股)
float m_fAmount; // 成交额(元)
DWORD m_dwAdvance; // 仅指数有效,上涨家数 by freeman
DWORD m_dwDecline; // 仅指数有效,下跌家数 by freeman
float m_fBuyPrice[5];
float m_fBuyVolume[5];
float m_fSellPrice[5];
float m_fSellVolume[5];
/*****custom extend by freeman*****/
float m_fBuyVolumeChanged[5];
float m_fSellVolumeChanged[5];
/*********************************/
....
}
2.变量初始化
G:\stock\TskingVS2019\src\Client\StkLib\Src\Stock.cpp
oid CStockInfo::Clear()
{
m_dwMarket = CStock::marketUnknown;
memset(m_szCode, 0, sizeof(m_szCode));
....
/********custom extend 获取回车选择的历史K线日期、笔数变化;*********************/
//挂单增、减笔数变化
memcpy(m_fBuyVolumeChanged, 0, sizeof(m_fBuyVolumeChanged));
memcpy(m_fSellVolumeChanged, 0, sizeof(m_fSellVolumeChanged));
m_dateHistoryReport = 0;
/********end*******************/
}
3.变量赋值
CStockInfo& CStockInfo::operator = (const CStockInfo& si)
{
m_dwMarket = si.m_dwMarket;
memcpy(m_szCode, si.m_szCode, sizeof(m_szCode));
.....
/********custom extend 获取回车选择的历史K线日期、笔数变化;*********************/
m_dateHistoryReport = si.m_dateHistoryReport;
//挂单增、减笔数变化
memcpy(m_fBuyVolumeChanged, si.m_fBuyVolumeChanged, sizeof(m_fBuyVolumeChanged));
memcpy(m_fSellVolumeChanged, si.m_fSellVolumeChanged, sizeof(m_fSellVolumeChanged));
/********end*******************/
return *this;
}
二、增加挂单增加、减少的变量计算函数
增加函数声明
src\Client\StkLib\Include\Stock.h
/*custom extend 挂单变化 by freeman */
BOOL CalBuySellVolumeChanged();
/*custom end 挂单变化 by freeman */
实现函数
src\Client\StkLib\Src\Report.cpp
*custom extend 挂单变化 by freeman */
BOOL CReport::CalBuySellVolumeChanged()
{
if (GetSize() <= 0)
return 0;
//Map中的元素是自动按key升序排序, 所以不能对map用sort函数
map<float, float > mapBuyPriceVolume;
map<float, float>::iterator iterBuyPriceVolume;
map<float, float > mapSellPriceVolume;
map<float, float>::iterator iterSellPriceVolume;
for (int i = 0; i < GetSize(); i++)
{
REPORT& rpt = ElementAt(i);
//第一笔,map初始化
if (i == 0)
{
for (int k = 0; k < sizeof(rpt.m_fBuyVolume) / sizeof(rpt.m_fBuyVolume[0]); k++)
{
mapBuyPriceVolume.insert(pair <float, float>(rpt.m_fBuyPrice[k], rpt.m_fBuyVolume[k]));
}
for (int k = 0; k < sizeof(rpt.m_fSellVolume) / sizeof(rpt.m_fSellVolume[0]); k++)
{
mapSellPriceVolume.insert(pair <float, float>(rpt.m_fSellPrice[k], rpt.m_fSellVolume[k]));
}
continue;
}
//买 5笔
for (int k = 0; k < sizeof(rpt.m_fBuyVolume) / sizeof(rpt.m_fBuyVolume[0]); k++)
{
//使用Find()和Count()方法来发现一个键是否存在
iterBuyPriceVolume = mapBuyPriceVolume.find(rpt.m_fBuyPrice[k]); //要查找的Key
if (iterBuyPriceVolume == mapBuyPriceVolume.end())
{
//没找到
//修改挂单变化
ElementAt(i).m_fBuyVolumeChanged[k] = rpt.m_fBuyVolume[k];
//map插入新值
mapBuyPriceVolume.insert(pair <float, float>(rpt.m_fBuyPrice[k], rpt.m_fBuyVolume[k]));
}
else
{
//修改挂单变化
ElementAt(i).m_fBuyVolumeChanged[k] = rpt.m_fBuyVolume[k] - iterBuyPriceVolume->second;
//map删除老值
mapBuyPriceVolume.erase(iterBuyPriceVolume);//列表移除
//map插入新值
mapBuyPriceVolume.insert(pair <float, float>(rpt.m_fBuyPrice[k], rpt.m_fBuyVolume[k]));
}
}
//卖5笔
for (int k = 0; k < sizeof(rpt.m_fSellVolume) / sizeof(rpt.m_fSellVolume[0]); k++)
{
//使用Find()和Count()方法来发现一个键是否存在
iterSellPriceVolume = mapSellPriceVolume.find(rpt.m_fSellPrice[k]); //要查找的Key
if (iterSellPriceVolume == mapSellPriceVolume.end())
{
//没找到
//修改挂单变化
ElementAt(i).m_fSellVolumeChanged[k] = rpt.m_fSellVolume[k];
//map插入新值
mapSellPriceVolume.insert(pair <float, float>(rpt.m_fSellPrice[k], rpt.m_fSellVolume[k]));
}
else
{
//修改挂单变化
ElementAt(i).m_fSellVolumeChanged[k] = rpt.m_fSellVolume[k] - iterSellPriceVolume->second;
//map删除老值
mapSellPriceVolume.erase(iterSellPriceVolume);//列表移除
//map插入新值
mapSellPriceVolume.insert(pair <float, float>(rpt.m_fSellPrice[k], rpt.m_fSellVolume[k]));
}
}
}
return TRUE;
}
/*custom end 挂单变化 by freeman */
src/Client/StkUI/View/HistoryRealTime.cpp
CReport& aReport = m_CurStock.GetReport();
aReport.CalBuySellVolumeChanged();
StkUI:realtime.cpp stock.cpp增加挂单笔数增、减少计算CReport::CalBuySellVolumeChan…
三、修改五档行情挂单增加、减少的显示部分
//实时行情,画右上角信息
int CHistoryRealTime::DrawBuySell(CDC* pDC, int xStart, int yStart, int nWidth)
四、修改成交笔数显示
void CHistoryRealTime::DrawReportColumn(CDC* pDC, CStockInfo& info, CReport& aReport, int nStartPos, int nMaxCount, CRect rect)