SV_HQ.C
上传用户:bjghjy
上传日期:2007-01-07
资源大小:379k
文件大小:54k
- #include <windows.h>
- #include <windowsx.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <io.h>
- #include <sysstat.h>
- #include <share.h>
- #include <fcntl.h>
- #include <time.h>
- #include "hq.h"
- #include "sv_hq.h"
- #include "sv_hqk.h"
- #include "data.h"
-
- HQ_DATA HqData[2]; //行情内存对象
- DP_DATA DpData[2]; //大盘内存对象
- MMP_DATA MmpData[2]; //买卖盘内存对象
- GRA_ALL GraphData[2]; //分时数据头部信息
- MAXMIN_DATA MaxMinData[2][2]; //排行榜内存对象
- HQ_TIME HqTime[2];
- DBF_DATA HqkData[2], GpkData[2], SzZskData, SzMmpkData;
- HQSEL_DATA HqSelData;
- ZX_DATA ZxData;
- extern void DelayMs(int ms);
- int SendHq(int jys);
- int GetShZsFirst(LPSTR lpbuf, int);
- int RefreshShZs(LPSTR lpbuf, int);
- int GetSzZqmc(int);
- long CalcCjzje(int jys);
- float CalcNpbl(int jys);
- long CalcCjss(int jys);
- BOOL IsTodayHq(int);
- BOOL ReadHqDat(int);
- int GetGraData(int jys, int i, LPHQ_REF_DATA lpLastHq);
- int GetDpGraData(int jys, int i);
- BOOL IsGuoZhai(int, int);
- int GetValidRecNum(int jys);
- extern BOOL WriteGraData(int,int);
- extern int ConnectHost(void);
- extern long zs_times[2][20];
- extern long tim_seconds;
- extern HWND ghWndMain;
- extern void MsgLocal(LPSTR msg);
- extern void DelSpaces(LPSTR);
- extern BOOL GetInitString(LPSTR, LPSTR, LPSTR);
- extern void PutInitString(LPSTR, LPSTR, LPSTR);
- extern int GetInitInt(LPSTR, LPSTR);
- extern BOOL ErrMsg(HWND, LPSTR);
- extern int UDPBlockingHook(void);
- extern BOOL run_cancelled;
- extern int UDP_SendBuff(int, LPSTR, int);
- extern int date_num,tim;
- LPSTR GetHqFldPos(int jys, int rec_num, int fld_num);
- int keys[600]; // must init first
- int HqAllocMem(int jys, int recCount);
- int SendMmp(int jys);
- int SendDp(int jys);
- int SendMaxMin(int jys, int type);
- int GetMaxMin10(int jys);
- void GetMaxZd10(int jys);
- void GetMinZd10(int jys);
- void GetMaxZdf10(int jys);
- void GetMinZdf10(int jys);
- void GetMaxCjss10(int jys);
- void GetMinCjss10(int jys);
- void GetMaxCjje10(int jys);
- void GetMinCjje10(int jys);
- int GetLongSort10(int jys, int fldNum, int type, int *);
- int GetFloatSort10(int jys, int fldNum, int type, int *);
- BOOL IsMaxMin(int jys, int rec_num);
- char *HqItems[] ={"HQK_SZ", "HQK_SH", "GPK_SZ", /*"GPK_SH",*/
- "ZSK_SZ", "MMPK_SZ", NULL};
- LPDBF_DATA lpDbfDatas[]={&HqkData[0], &HqkData[1],
- &GpkData[0],/* &GpkData[1],*/
- &SzZskData,
- &SzMmpkData,NULL};
- LPDBF_DATA lpDbfFile[2][5] ={
- {&HqkData[0],&GpkData[0],&SzZskData,&SzMmpkData,NULL},
- {&HqkData[1],NULL, NULL, NULL, NULL}
- };
-
- LPSTR HqTimeItems[] ={"SZ_AM_START", "SZ_AM_END", "SZ_PM_START", "SZ_PM_END",
- "SH_AM_START", "SH_AM_END", "SH_PM_START", "SH_PM_END",
- };
- LPSTR HqTimeDefs[] ={"9:30", "11:30", "13:00", "15:00",
- "9:30", "11:30", "13:00", "15:00",
- };
- int *lpHqTimes[] ={&HqTime[0].am_min_start, &HqTime[0].am_min_end,
- &HqTime[0].pm_min_start, &HqTime[0].pm_min_end,
- &HqTime[1].am_min_start, &HqTime[1].am_min_end,
- &HqTime[1].pm_min_start, &HqTime[1].pm_min_end
- };
- int zsRecNum[2][50];
- int zsRecCount[2] ={0,0};
- long oldDpCjss2[2][20];
- int gnHqRefreshTime =5;
- char HqDataPath[128], szDataPath[128];
- int *HqDataFile[] ={
- &hfHq[0], &hfHq[1], &hfMmp[0], &hfMmp[1], &hfDp,
- &hfMaxMin[0], &hfMaxMin[1], NULL
- };
- LPSTR HqDataFileName[] ={
- "SZHQ", "SHHQ", "SZMMP", "SHMMP", "DPDATA", "MAXMINSZ", "MAXMINSH", NULL
- };
-
-
- int Skip = -1,Idel;
-
- int HqInit(void)
- {
- int i, jys;
- char tmp[256], temp[256];
- OFSTRUCT os;
-
- memset(&oldDpCjss2, 0, sizeof(oldDpCjss2));
- memset(&zs_times, 0, sizeof(zs_times));
- for(i =0; i<2; i++)
- {
- memset(&HqData[i], 0, sizeof(HqData[i]));
- memset(&MmpData[i], 0, sizeof(MmpData[i]));
- memset(&HqTime[i], 0, sizeof(HqTime[i]));
- memset(&GraphData[i], 0, sizeof(GraphData[i]));
- memset(&DpData[i], 0, sizeof(DpData[i]));
- hfHq[i] =HFILE_ERROR;
- hfMmp[i] =HFILE_ERROR;
- hfMaxMin[i] =HFILE_ERROR;
- }
- hfDp =HFILE_ERROR;
- memset(&ZxData, 0, sizeof(ZxData));
- i=0;
- while(HqItems[i])
- {
- memset(lpDbfDatas[i], 0, sizeof(DBF_DATA));
- lpDbfDatas[i]->hf =-1;
- i++;
- }
- /*
- memset(tmp,0,sizeof(tmp));
- if(GetInitString("GLOBAL", "SKIP", tmp))
- {
- Skip= atoi(tmp);
- }
- else
- {
- PutInitString("GLOBAL", "SKIP", "0");
- Skip=0;
- }
- */
- memset(tmp,0,sizeof(tmp));
- if(GetInitString("GLOBAL", "IDEL", tmp))
- {
- Idel= atoi(tmp);
- }
- else
- {
- PutInitString("GLOBAL", "IDEL", "0");
- Idel=0;
- }
-
- //设置开闭市时间
- for(jys =0; jys <2; jys++)
- {
- for(i =0; i<4; i++)
- {
- if(!GetInitString("TIME", HqTimeItems[i+4*jys], tmp))
- {
- strcpy(tmp, HqTimeDefs[i+4*jys]);
- PutInitString("TIME", HqTimeItems[i+4*jys], tmp);
- }
- else
- {
- if(strlen(tmp) > 12 || strlen(tmp) <3)
- {
- ErrMsg(ghWndMain, "time set error!");
- return -1;
- }
- }
- *lpHqTimes[i+4*jys] =atoi(strtok(tmp, ":"))*60;
- *lpHqTimes[i+4*jys] +=atoi(strtok(NULL, ":"));
- }
-
- }
-
- //初始化DBF文件
- i =0;
- while(HqItems[i])
- {
- if(!GetInitString("DBF", HqItems[i], tmp))
- {
- wsprintf(temp, "can not find %s:n %s",
- (LPSTR)HqItems[i], (LPSTR)tmp);
- ErrMsg(ghWndMain, temp);
- PutInitString("DBF", HqItems[i], NULL);
- return -1;
- }
-
- if(access(tmp,_S_IREAD) <0)
- {
- wsprintf(temp, "can not read %s:n %s",
- (LPSTR)HqItems[i], (LPSTR)tmp);
- ErrMsg(ghWndMain, temp);
- return -1;
- }
- lpDbfDatas[i]->hf=OpenDbfBase(tmp,OF_READ);
- if (lpDbfDatas[i]->hf==-1)
- {
- wsprintf(temp, "can not open %s:n %s",
- (LPSTR)HqItems[i], (LPSTR)tmp);
- ErrMsg(ghWndMain, temp);
- return -1;
- }
- strcpy(lpDbfDatas[i]->file,tmp);
-
- if (InitBase(lpDbfDatas[i]->hf,&lpDbfDatas[i]->dbfStruct,
- &lpDbfDatas[i]->fldStruct,&lpDbfDatas[i]->fldCount)
- !=SUCCEED)
- {
- wsprintf(temp, "can not init %s:n %s",
- (LPSTR)HqItems[i], (LPSTR)tmp);
- ErrMsg(ghWndMain, temp);
- return -1;
- }
-
- i++;
- }
-
- //初始化分时数据结构
- if(!GetInitString("HQ", "DATAPATH", szDataPath))
- {
- ErrMsg(ghWndMain, "not set datapath in [graph]");
- PutInitString("HQ", "DATAPATH", NULL);
- return -1;
- }
- i =strlen(szDataPath);
- if(szDataPath[i] =='\')
- szDataPath[i] =0;
-
- wsprintf(HqDataPath, "%s\HQDATA", szDataPath);
- wsprintf(GraphData[0].szGraPath, "%s\SZDATA", szDataPath);
- wsprintf(GraphData[1].szGraPath, "%s\SHDATA", szDataPath);
-
- //初始化行情数据文件
- i =0;
- while(HqDataFileName[i])
- {
- wsprintf(tmp, "%s\%s.dat", HqDataPath, HqDataFileName[i]);
- if(access(tmp,_S_IREAD) <0)
- {
- *HqDataFile[i] =OpenFile(tmp,&os, OF_SHARE_DENY_NONE|OF_CREATE|OF_READWRITE);
- if(*HqDataFile[i] ==-1)
- {
- wsprintf(temp, "can not create hq_data_file %s:", tmp);
- ErrMsg(ghWndMain, temp);
- return -1;
- }
- }
- else *HqDataFile[i] =OpenFile(tmp, &os, OF_SHARE_DENY_NONE|OF_READWRITE);
- if (*HqDataFile[i] ==NULL)
- {
- wsprintf(temp, "can not open hq_data_file %s:", tmp);
- ErrMsg(ghWndMain, temp);
- return -1;
- }
- i++;
- }
- gnHqRefreshTime =GetInitInt("HQ", "REF_TIME");
- if(gnHqRefreshTime <5 || gnHqRefreshTime >60) gnHqRefreshTime =5;
-
-
- for(jys =0; jys <2; jys++)
- {
- CloseDbfFile(jys);
- }
-
- return 0;
- }
- void HqExit(void)
- {
- static BOOL fExit =FALSE;
- int jys, i;
-
- if(fExit ==TRUE) return;
- fExit =TRUE;
- for(jys =0; jys <2; jys++)
- {
- if(HqData[jys].lpPreData !=NULL) GlobalFreePtr(HqData[jys].lpPreData);
- if(HqData[jys].lpRefData !=NULL) GlobalFreePtr(HqData[jys].lpRefData);
- if(HqData[jys].lpbChanged !=NULL) GlobalFreePtr(HqData[jys].lpbChanged);
- if(MmpData[jys].lpMmp) GlobalFreePtr(MmpData[jys].lpMmp);
- if(GraphData[jys].lpGraData) GlobalFreePtr(GraphData[jys].lpGraData);
- if(GraphData[jys].lpGraHead) GlobalFreePtr(GraphData[jys].lpGraHead);
-
- if(hfHq[jys] !=HFILE_ERROR) _lclose(hfHq[jys]);
- if(hfMmp[jys] !=HFILE_ERROR) _lclose(hfMmp[jys]);
- if(hfMaxMin[jys] !=HFILE_ERROR) _lclose(hfMaxMin[jys]);
- }
- if(hfDp !=HFILE_ERROR) _lclose(hfDp);
- i =0;
- while(HqItems[i])
- {
- if(lpDbfDatas[i]->hf!=-1)
- {
- CloseDbf(lpDbfDatas[i]->hf);
- //if(lpDbfDatas[i]->fldStruct)
- // free(lpDbfDatas[i]->fldStruct);
- }
- if(lpDbfDatas[i]->fldStruct)
- free(lpDbfDatas[i]->fldStruct);
- i++;
- }
-
- if(ZxData.lpText) free(ZxData.lpText);
- }
- BOOL OpenDbfFile(int jys)
- {
- int i =0;
-
- while(lpDbfFile[jys][i]!=NULL)
- {
- if(lpDbfFile[jys][i]->hf==-1)
- lpDbfFile[jys][i]->hf =OpenDbfBase(lpDbfFile[jys][i]->file,OF_READ);
- if(lpDbfFile[jys][i]->hf == -1)
- return FALSE;
- i++;
- }
- return TRUE;
- }
- void CloseDbfFile(int jys)
- {
- int i=0;
-
- while(lpDbfFile[jys][i]!=NULL)
- {
- if(lpDbfFile[jys][i]->hf!=-1)
- {
- CloseDbf(lpDbfFile[jys][i]->hf);
- lpDbfFile[jys][i]->hf =-1;
- }
- i++;
- }
- }
- //zqdm,zrsp,jrkp,zgjg,zdjg,zgjm,zdjm,zjjg,zd,cjss,lc,npzl,wb,cjje
- int HqFldLens[HQ_FLDS_COUNT]=
- {
- MAX_ZQDM_SIZE, sizeof(float),sizeof(float), sizeof(float), sizeof(float),
- sizeof(float), sizeof(float), sizeof(float), sizeof(float),sizeof(long),
- sizeof(long), sizeof(long), sizeof(float), sizeof(long)
- };
- int HqFldTypes[HQ_FLDS_COUNT]=
- {
- FLD_TYPE_STRING, FLD_TYPE_FLOAT, FLD_TYPE_FLOAT, FLD_TYPE_FLOAT,
- FLD_TYPE_FLOAT, FLD_TYPE_FLOAT, FLD_TYPE_FLOAT, FLD_TYPE_FLOAT,
- FLD_TYPE_FLOAT, FLD_TYPE_LONG, FLD_TYPE_LONG, FLD_TYPE_LONG,
- FLD_TYPE_FLOAT, FLD_TYPE_LONG
- };
- int HqFldPoss[2][HQ_FLDS_COUNT] =
- {
- //0zqdm,1zrsp,2jrkp,3zgjg,4zdjg,5zgjm,6zdjm,7zjjg,8zd,9cjss,0lc,11npzl,
- //12wb,13cjje
- //{0, 2, 3, 5, 6, 8, 9, 7, -1, 4, -1,-1, -1, 15},
- {0, 1, 2, 4, 5, 7, 8, 6, -1, 3, -1,-1, -1, 14},
- {0, 2, 3, 5, 6, 8, 9, 7, -1, 10, -1, -1, -1, 4},
- };
- BOOL IsTodayHq(int jys)
- {
- struct _stat buff;
- char tmp[10];
-
- _strdate(tmp);
- _fstat(HqkData[jys].hf,&buff);
-
- return TRUE;
- }
- //if(_hread(HqkData[jys].hf, buffer, recCount*reclen) !=recCount*reclen)
- #define _hread hRead
- #define PER_READ_LEN 1024L
- long hRead(HFILE hf,char huge * buff,long len)
- {
- long rlen=0;
- UINT ret,plen ;
-
- if(len<=PER_READ_LEN)
- {
- ret =_lread(hf,buff,(UINT)(len));
- rlen =(long)(ret);
- }
- else
- {
- rlen =0;
- do
- {
- if(len -rlen>= PER_READ_LEN)
- {
- plen =(UINT)(PER_READ_LEN);
- }
- else
- {
- plen =(UINT)(len -rlen);
- }
-
- ret =_lread(hf,buff,plen);
- if(ret!=HFILE_ERROR)
- {
- buff+=ret;
- rlen +=ret;
- }
- else
- {
- return -1;
- }
- }while(rlen<len&&ret!=HFILE_ERROR);
- }
-
- return rlen;
- }
- //////////////////////////////////////////////////////////////////
- //功能 :初始化内存行情数据对象、内存买卖盘对象、内存分时数据头部信息 ,
- // 同时,填充相应的内存行情数据的股票名称字段, 三个内存对象与填充
- // 操作以内存行情数据的记录号为主索引 ,所以当行情数据的记录数有变化
- // 时,一定要更新其余的内存对象,并重作名称填充。该例程同时初始化大盘
- // 内存对象和排行榜内存对象
- //参数 :
- // jys---交易所编码
- //返回码 :
- // TRUE---成功
- // FALSE--失败
- //修改日期 :1997/10/15
- //修改建议 :可将内存行情数据放入BTREE,BTREE内包含其余的两内存数据对象,以股票
- // 代码作索引
- int ReadHqFirst(int jys)
- {
- int i, j, reclen, headlen;
- long recCount,bytes;
- char huge*buffer;
- char huge *lpTmp;
- LPSTR lpFld;
- char tmp[100];
- static BOOL fFirst[2] ={TRUE, TRUE};
-
- if(HqkData[jys].hf <0)
- {
- ErrMsg(ghWndMain, "ReadHqFirst 不能打开行情库句柄!");
- return FALSE;
- }
- if(jys ==0) MsgLocal("读取深圳行情");
- else MsgLocal("读取上海行情");
-
- reclen=*(int *)HqkData[jys].dbfStruct.rlen;
- headlen=*(int *)HqkData[jys].dbfStruct.hlen;
-
- recCount =GetDbfRecCount(HqkData[jys].hf,headlen,reclen);
- //计算行情库有效记录
- //recCount =GetValidRecNum(jys);
- if(jys ==1)
- {
- recCount --;
- }
- if(recCount <=0)
- {
- ErrMsg(ghWndMain, "ReadHqFirst 行情库记录数为零!");
- return FALSE;
- }
- // 分配内存,同时将分时数据结构等清零及初始化
- if(HqAllocMem(jys, (int)recCount) <0)
- {
- ErrMsg(ghWndMain, "ReadHqFirst:HqAllocMem错!");
- return FALSE;
- }
- //读交易所行情文件
- //reclen=*(int *)HqkData[jys].dbfStruct.rlen;
- //headlen=*(int *)HqkData[jys].dbfStruct.hlen;
- buffer =(char huge*)GlobalAllocPtr(GHND, recCount*reclen+1);
- if (buffer==NULL)
- {
- ErrMsg(ghWndMain, "ReadHqFirst:alloc buffer 错!");
- return FALSE;
- }
- _llseek(HqkData[jys].hf,(long)headlen,SEEK_SET);
- if(jys ==1)
- _llseek(HqkData[jys].hf, reclen, SEEK_CUR);
-
- bytes =hRead(HqkData[jys].hf, buffer, recCount*reclen);
-
- if(bytes == -1)
- {
- ErrMsg(ghWndMain,"ReadHqFirst:hRead bytes =-1错");
- GlobalFreePtr(buffer);
- return FALSE;
- }
-
- if(bytes !=recCount*reclen)
- {
- ErrMsg(ghWndMain, "ReadHqFirst:bytes !=recCount*reclen");
- GlobalFreePtr(buffer);
- return FALSE;
- }
-
- //初始化行情数据结构
- lpTmp =buffer;
- for (i=0;i<recCount;i++)
- {
- for(j =0; j<HQ_FLDS_COUNT; j++)
- {
- lpFld =GetHqFldPos(jys, i, j);
- if(HqFldPoss[jys][j] >=0)
- {
- FldToString(lpTmp,
- (FieldStruct *)&HqkData[jys].fldStruct[HqFldPoss[jys][j]],
- tmp);
- switch(HqFldTypes[j])
- {
- case FLD_TYPE_STRING:
- strcpy(lpFld, tmp);
- break;
- case FLD_TYPE_FLOAT:
- *(float *)lpFld =(float)atof(tmp);
- break;
- case FLD_TYPE_LONG:
- *(long *)lpFld =(long)atol(tmp);
- break;
- }
- }
- }
-
- if(IsGuoZhai(jys, i))
- HqData[jys].lpRefData[i].cjss /=10; //单位:手
- else
- HqData[jys].lpRefData[i].cjss /=100; //单位:手
- HqData[jys].lpRefData[i].cjje /=1000; //单位:万
-
- HqData[jys].lpRefData[i].lc =0;
-
- if(HqData[jys].lpPreData[i].zrsp ==0
- ||HqData[jys].lpRefData[i].zjjg ==0)
- HqData[jys].lpRefData[i].zdf =0;
- else
- HqData[jys].lpRefData[i].zdf =
- (HqData[jys].lpRefData[i].zjjg
- - HqData[jys].lpPreData[i].zrsp)
- /HqData[jys].lpPreData[i].zrsp*100;
-
- if(IsZsRec(jys, i))
- {
- if(jys ==1)
- {
- GetShZsFirst(lpTmp, DpData[jys].recCount);
- DpData[jys].recCount++;
- }
- }
-
- if(jys ==1)
- {
- FldToString(lpTmp,(FieldStruct *)&HqkData[jys].fldStruct[1],
- HqData[jys].lpPreData[i].zqmc);
- GetShMmp(TRUE, i, lpTmp);
- }
- lpTmp +=reclen;
- }
-
- GlobalFreePtr(buffer);
- CheckGraHead(jys);
-
- if(jys ==0)
- {
- if(!GetSzZqmc(jys))
- {
- ErrMsg(ghWndMain,"ReadHqFirst:GetSzZqmc(jys)错");
- return FALSE;
- }
- if(!ReadSzZsFirst())
- {
- ErrMsg(ghWndMain,"ReadHqFirst:ReadSzZsFirst()错");
- return FALSE;
- }
- if(!ReadSzMmp(TRUE))
- {
- ErrMsg(ghWndMain,"ReadHqFirst:ReadSzZsFirst()错");
- return FALSE;
- }
- }
- i =GetMaxMin10(jys);
- if(i >0) SendMaxMin(jys, i);
-
- GetDpData(jys, TRUE);
- MsgLocal("OK.");
- fFirst[jys] =FALSE;
-
- return TRUE;
- }
- ////////////////////////////////////////////////////////
- //功能 :根据股票代码、记录号获取股票名称,该功能只支持深股
- //参数 :
- // jys---交易所编号
- // rec---记录标号(0-->记录数-1)
- // gpdm--股票代码
- // gpmc--股票名称
- //返回码 :
- // 0 --成功
- // -1 --失败
- //修改日期 :1997/10/15
- int GetZqmc(int jys,int rec,char *gpdm,char *gpmc)
- {
- int i, reclen, headlen, fldnum, rec_count;
- char *buffer;
- char tmp[40];
-
- if(GpkData[jys].hf ==-1)
- return -1;
- if(jys==1)
- return -1;
-
- reclen=*(int *)GpkData[jys].dbfStruct.rlen;
- headlen=*(int *)GpkData[jys].dbfStruct.hlen;
-
- rec_count =(int)GetDbfRecCount(GpkData[jys].hf,headlen,reclen);
- if(rec_count <=0) return -1;
- fldnum =GpkData[jys].fldCount;
- //reclen=*(int *)GpkData[jys].dbfStruct.rlen;
- //headlen=*(int *)GpkData[jys].dbfStruct.hlen;
-
- buffer =(char *)malloc(reclen+1);
- if (buffer==NULL)
- {
- ErrMsg(ghWndMain, "GetZqmc:alloc buffer failed!");
- return -1;
- }
- //用记录数定位
- if(rec<rec_count)
- {
- _llseek(GpkData[jys].hf,(long)(headlen+reclen*rec),SEEK_SET);
- if(_lread(GpkData[jys].hf,buffer,reclen) ==(UINT)reclen)
- {
- FldToString(buffer,(FieldStruct *)&GpkData[jys].fldStruct[0], tmp);
- if(!strcmp(tmp, gpdm))
- {
- FldToString(buffer,(FieldStruct *)&GpkData[jys].fldStruct[1],gpmc);
- free(buffer);
- return 0;
- }
- }
- }
- //线性搜索
- _llseek(GpkData[jys].hf,(long)headlen,SEEK_SET);
- for (i=0;i<rec_count;i++)
- {
- if(_lread(GpkData[jys].hf,buffer,reclen) !=(UINT)reclen) break;
-
- FldToString(buffer,(FieldStruct *)&GpkData[jys].fldStruct[0], tmp);
- if(!strcmp(tmp, gpdm))
- {
- FldToString(buffer,(FieldStruct *)&GpkData[jys].fldStruct[1],gpmc);
- free(buffer);
- return 0;
- }
- }
- free(buffer);
- return -1;
- }
- /////////////////////////////////////////////////
- //功能 :刷新行情数据
- //参数 :
- // jys---交易所编码
- //返回码 :
- // 0---成功
- // -1--失败
- //修改日期 :1997/10/15
- int HqRefresh(int jys)
- {
- int i, j, reclen, headlen, zs_num[2] ={0, 0};
- char huge *buffer;
- char huge *lpTmp;
- LPSTR lpFld;
- char tmp[50];
- long l,bytes;
- HQ_REF_DATA LastHq;
- char LastZqdm[MAX_ZQDM_SIZE];
-
- int recCount;
-
- if(HqkData[jys].hf ==-1)
- {
- ErrMsg(ghWndMain, "HqRefresh:不能打开行情库文件句柄");
- return FALSE;
- }
- if(jys ==0) MsgLocal("刷新深圳行情");
- else MsgLocal("刷新上海行情");
-
- reclen=*(int *)HqkData[jys].dbfStruct.rlen;
- headlen=*(int *)HqkData[jys].dbfStruct.hlen;
-
- recCount =(int)GetDbfRecCount(HqkData[jys].hf,headlen,reclen);
-
- //检查行情库记录数有无增减,如有效记录数发生变化,则应从新调整内存 ,
- //recCount =GetValidRecNum(jys);
- if(recCount ==0)
- {
- ErrMsg(ghWndMain,"HqRefresh:GetDbfRecCount =0");
- return FALSE;
- }
-
- //上海行情库少采集一条记录
- if(jys ==1) recCount --;
-
- if(recCount <=0)
- {
- ErrMsg(ghWndMain,"HqRefresh:调整recCount <=0");
- return FALSE;
- }
-
- if(recCount!=HqData[jys].recCount)
- {
- MsgLocal("HqRefresh:记录数不匹配,重新初始化");
- return FALSE;
- }
- if(HqData[jys].recCount <=0)
- {
- ErrMsg(ghWndMain, "HqRefresh:行情库记录数错");
- return FALSE;
- }
- l =HqData[jys].recCount;
- if ((buffer=(char huge*)GlobalAllocPtr(GHND, l*reclen+1))==NULL)
- {
- ErrMsg(ghWndMain, "HqRefresh:行情采集分配缓冲区错!");
- return FALSE;
- }
-
- _llseek(HqkData[jys].hf,(long)headlen,SEEK_SET);
-
- //上海行情库第一条记录不能采集
- if(jys ==1)
- _llseek(HqkData[jys].hf, reclen, SEEK_CUR);
-
- bytes =hRead(HqkData[jys].hf, buffer, l*reclen);
-
- if(bytes == -1)
- {
- ErrMsg(ghWndMain,"HqRefresh:bytes == -1");
- GlobalFreePtr(buffer);
- return FALSE;
- }
-
- if(bytes!=l*reclen)
- {
- ErrMsg(ghWndMain, "HqRefresh:bytes!=l*reclen");
- GlobalFreePtr(buffer);
- return FALSE;
- }
- else
- {
- lpTmp =buffer;
- for (i=0;i<HqData[jys].recCount;i++)
- {
- while(UDPBlockingHook());
- if(run_cancelled) break;
- //拷贝行情老数据,作增量判断
- memcpy(&LastHq,&HqData[jys].lpRefData[i],
- sizeof(HQ_REF_DATA));
- //拷贝股票代码,以下用于股票数量加减判断
- strcpy(LastZqdm,HqData[jys].lpPreData[i].zqdm);
-
- for(j =0; j<HQ_FLDS_COUNT; j++)
- {
- lpFld =GetHqFldPos(jys, i, j);
- if(HqFldPoss[jys][j] >=0)
- {
- FldToString(lpTmp,(FieldStruct *)&HqkData[jys].fldStruct[HqFldPoss[jys][j]],
- tmp);
- switch(HqFldTypes[j])
- {
- case FLD_TYPE_STRING:
- strcpy(lpFld, tmp);
- break;
- case FLD_TYPE_FLOAT:
- *(float *)lpFld =(float)atof(tmp);
- break;
- case FLD_TYPE_LONG:
- *(long *)lpFld =atol(tmp);
- break;
- }
- }
- }
- //判断股票代码有无改变,如改变,则应获取正确的行情老数据
- //如股票代码有改变,则相应的名称也应改变
- if(strcmp(HqData[jys].lpPreData[i].zqdm,LastZqdm)!=0)
- {
- //重读股票名称
- if(jys==0)
- {
- if(GetZqmc(jys,i,HqData[jys].lpPreData[i].zqdm,
- HqData[jys].lpPreData[i].zqmc)!=0)
- {
- strcpy(HqData[jys].lpPreData[i].zqmc,
- HqData[jys].lpPreData[i].zqdm);
- }
- }
- if(jys==1)
- {
- FldToString(lpTmp,(FieldStruct *)&HqkData[jys].fldStruct[1],
- HqData[jys].lpPreData[i].zqmc);
- }
- //放弃该次采集,处理下一条
- lpTmp +=reclen;
- continue;
- }
- if(IsGuoZhai(jys, i))
- HqData[jys].lpRefData[i].cjss /=10; //单位:手
- else
- HqData[jys].lpRefData[i].cjss /=100; //单位:手
- HqData[jys].lpRefData[i].cjje /=1000; //单位:万
- if(jys ==1)
- {
- //FldToString(lpTmp,(FieldStruct *)&HqkData[jys].fldStruct[1],
- // HqData[jys].lpPreData[i].zqmc);
-
- if(IsZsRec(jys, i))
- {
- RefreshShZs(lpTmp, zs_num[1]);
- zs_num[1] ++;
- }
- else GetShMmp(FALSE, i, lpTmp);
- }
- HqData[jys].lpRefData[i].lc =
- HqData[jys].lpRefData[i].cjss -LastHq.cjss;
- //没有成交 ,处理下一条
- if(HqData[jys].lpRefData[i].lc <=0)
- {
- lpTmp +=reclen;
- continue;
- }
- //有成交,计算涨跌
- if(HqData[jys].lpPreData[i].zrsp ==0
- ||HqData[jys].lpRefData[i].zjjg ==0)
- HqData[jys].lpRefData[i].zdf =0;
- else
- HqData[jys].lpRefData[i].zdf =
- (HqData[jys].lpRefData[i].zjjg
- - HqData[jys].lpPreData[i].zrsp)
- /HqData[jys].lpPreData[i].zrsp*100;
-
- //如果是指数,则不处理
- if(!IsZsRec(jys, i))
- {
- GetGraData(jys, i, &LastHq);
- if(HqData[jys].lpRefData[i].lc >0)
- WriteGraData(jys, i);
- }
-
- lpTmp +=reclen;
- }
- }
- GlobalFreePtr(buffer);
- MsgLocal("OK.");
-
- if(jys ==0)
- {
- ReadSzMmp(FALSE);
- RefreshSzZs();
- //if((int)*(long *)SzZskData.dbfStruct.recnum!=HqData[jys].recCount)
- //GetSzZqmc(jys);
- }
-
- GetMaxMin10(jys);
- GetDpData(jys, FALSE);
-
- //if(Skip!=-1)
- //{
- // SendDp(jys);
- // SendHq(jys);
- //}
-
- return TRUE;
- }
- int ReadSzZsFirst(void)
- {
- int i, reclen, headlen;
- char *buffer;
- char tmp[100];
-
- if(SzZskData.hf <0)
- {
- ErrMsg(ghWndMain, "ReadSzZsFirst:SzZskData.hf <0!");
- return FALSE;
- }
- DpData[0].recCount =(int)*(long *)SzZskData.dbfStruct.recnum;
- if(DpData[0].recCount >15) DpData[0].recCount =15;
-
- reclen=*(int *)SzZskData.dbfStruct.rlen;
- headlen=*(int *)SzZskData.dbfStruct.hlen;
-
- if(DpData[0].recCount <=0)
- {
- ErrMsg(ghWndMain, "ReadSzZsFirst:DpData[0].recCount <=0!");
- return FALSE;
- }
-
- buffer =(char *)malloc(reclen*DpData[0].recCount+1);
- if (buffer==NULL)
- {
- ErrMsg(ghWndMain, "ReadSzZsFirst:alloc buffer failed!");
- return FALSE;
- }
- memset(buffer, 0, reclen*DpData[0].recCount+1);
-
- _llseek(SzZskData.hf,(long)headlen,SEEK_SET);
- _lread(SzZskData.hf,buffer, reclen*DpData[0].recCount);
- for (i=0;i<DpData[0].recCount;i++)
- {
- FldToString(buffer+i*reclen,
- (FieldStruct *)&SzZskData.fldStruct[2],tmp);
- DpData[0].sp[i] =(float)atof(tmp);
- FldToString(buffer+i*reclen,
- (FieldStruct *)&SzZskData.fldStruct[6],
- tmp);
- DpData[0].zs[i] =(float)atof(tmp);
- DpData[0].zd[i] =DpData[0].zs[i] -DpData[0].sp[i];
- }
- free(buffer);
- return TRUE;
- }
- int GetShZsFirst(LPSTR lpbuf, int zsnum)
- {
- char tmp[100];
-
- if(zsnum >15) return 0;
- FldToString(lpbuf,(FieldStruct *)&HqkData[1].fldStruct[7],
- tmp);
- DpData[1].zs[zsnum] =(float)atof(tmp);
- FldToString(lpbuf,(FieldStruct *)&HqkData[1].fldStruct[2],
- tmp);
- DpData[1].sp[zsnum] =(float)atof(tmp);
- //FldToString(lpbuf,(FieldStruct *)&HqkData[1].fldStruct[3],
- // tmp);
- //if((float)atof(tmp)!=0.00)
- // DpData[1].zd[zsnum] =(float)atof(tmp)-DpData[1].sp[zsnum];
- //else
- DpData[1].zd[zsnum] =DpData[1].zs[zsnum]-DpData[1].sp[zsnum];
- return 0;
- }
- int GetShMmp(BOOL fFirst, int rec_num, LPSTR buffer)
- {
- int i;
- char tmp[100];
- double f1, f2;
- MMP LastMmp;
- long tmpl;
- float tmpf;
-
- memcpy(&LastMmp, &MmpData[1].lpMmp[rec_num], sizeof(MMP));
- MmpData[1].lpMmp[rec_num].jwBuy[0]
- =HqData[1].lpRefData[rec_num].zgjm;
- MmpData[1].lpMmp[rec_num].jwSell[0]
- =HqData[1].lpRefData[rec_num].zdjm;
- f1 =f2 =0;
- for(i =0; i<3; i++)
- {
- FldToString(buffer,(FieldStruct *)&HqkData[1].fldStruct[12+i*2],
- tmp);
- MmpData[1].lpMmp[rec_num].slBuy[i] =atol(tmp)/100;
- if(i !=2)
- {
- FldToString(buffer,(FieldStruct *)&HqkData[1].fldStruct[12+i*2+1],
- tmp);
- MmpData[1].lpMmp[rec_num].jwBuy[i+1] =(float)atof(tmp);
- }
- f2+=MmpData[1].lpMmp[rec_num].slBuy[i];
- }
- for(i =0; i<3; i++)
- {
- FldToString(buffer,(FieldStruct *)&HqkData[1].fldStruct[17+i*2],
- tmp);
- MmpData[1].lpMmp[rec_num].slSell[i] =atol(tmp)/100;
- if(i !=2)
- {
- FldToString(buffer,(FieldStruct *)&HqkData[1].fldStruct[17+i*2+1],
- tmp);
- MmpData[1].lpMmp[rec_num].jwSell[i+1] =(float)atof(tmp);
- }
- f1+=MmpData[1].lpMmp[rec_num].slSell[i];
- }
-
- tmpl=MmpData[1].lpMmp[rec_num].slSell[0];
- tmpf=MmpData[1].lpMmp[rec_num].jwSell[0];
- MmpData[1].lpMmp[rec_num].slSell[0]=
- MmpData[1].lpMmp[rec_num].slSell[2];
- MmpData[1].lpMmp[rec_num].jwSell[0]=
- MmpData[1].lpMmp[rec_num].jwSell[2];
- MmpData[1].lpMmp[rec_num].slSell[2]=tmpl;
- MmpData[1].lpMmp[rec_num].jwSell[2]=tmpf;
-
- if(f1+f2 ==0)
- HqData[1].lpRefData[rec_num].wb =0;
- else
- HqData[1].lpRefData[rec_num].wb =(float)((f2-f1)/(f2+f1));
-
- if(memcmp(&LastMmp, &MmpData[1].lpMmp[rec_num], sizeof(MMP)))
- MmpData[1].lpChanged[rec_num] =TRUE;
- else MmpData[1].lpChanged[rec_num] =FALSE;
- return 0;
- }
- int ReadSzMmp(BOOL fFirst)
- {
- int i, j, reclen, headlen;
- char huge*buffer;
- char huge *lpTmp;
- char tmp[100];
- double f1, f2;
- int rec_count;
- MMP LastMmp;
- long bytes;
-
- if(SzMmpkData.hf <0)
- {
- ErrMsg(ghWndMain, "ReadSzMmp:SzMmpkData.hf <0!");
- return FALSE;
- }
-
- MsgLocal("read Sz_Mmp...");
-
- rec_count =HqData[0].recCount*6;
-
- reclen=*(int *)SzMmpkData.dbfStruct.rlen;
- headlen=*(int *)SzMmpkData.dbfStruct.hlen;
-
- //加入以下代码处理买卖盘库尚未传完的情况
- i=(int)GetDbfRecCount(SzMmpkData.hf,headlen,reclen);
- if(rec_count>i) rec_count =i;
-
- //reclen=*(int *)SzMmpkData.dbfStruct.rlen;
- //headlen=*(int *)SzMmpkData.dbfStruct.hlen;
-
- buffer =(char *)GlobalAllocPtr(GHND, (long)rec_count*reclen+1);
- if (buffer==NULL)
- {
- ErrMsg(ghWndMain, "ReadSzMmp:alloc buffer failed!");
- return FALSE;
- }
- //memset(buffer, 0, reclen*MmpData[0].recCount+1);
-
- _llseek(SzMmpkData.hf,(long)headlen,SEEK_SET);
-
- bytes =hRead(SzMmpkData.hf, buffer, (long)rec_count*reclen);
-
- if(bytes ==-1)
- {
- MsgLocal("HqRefresh:重新初化szmmpk");
- GlobalFreePtr(buffer);
- return FALSE;
- }
-
- if(bytes !=(long)rec_count*reclen)
- {
- ErrMsg(ghWndMain, "error read sz_mmpk");
- }
- else
- {
- lpTmp =buffer;
- for(i =0; i<rec_count/6; i++)
- {
- while(UDPBlockingHook());
- if(run_cancelled) break;
-
- if(IsZsRec(0, i)) continue;
- memcpy(&LastMmp, &MmpData[0].lpMmp[i], sizeof(MMP));
- f1 =f2 =0;
- //应加入股票代码检查
- for(j =0; j<3; j++)
- {
- //if(_lread(SzMmpkData.hf,buffer, reclen) !=(UINT)reclen) break;
- //if(fFirst && j==0)
- // FldToString(lpTmp,
- // (FieldStruct *)&SzMmpkData.fldStruct[0],
- // MmpData[0].lpMmp[i].zqdm);
- FldToString(lpTmp,(FieldStruct *)&SzMmpkData.fldStruct[2],
- tmp);
- MmpData[0].lpMmp[i].jwSell[j] =(float)atof(tmp);
- FldToString(lpTmp,(FieldStruct *)&SzMmpkData.fldStruct[4],
- tmp);
- MmpData[0].lpMmp[i].slSell[j] =atol(tmp)/100;
- f1+=(double)MmpData[0].lpMmp[i].slSell[j];
- lpTmp +=reclen;
- }
- if(j !=3) break;
- for(j =0; j<3; j++)
- {
- //if(_lread(SzMmpkData.hf,buffer, reclen) !=(UINT)reclen) break;;
- FldToString(lpTmp,(FieldStruct *)&SzMmpkData.fldStruct[2],
- tmp);
- MmpData[0].lpMmp[i].jwBuy[j] =(float)atof(tmp);
- FldToString(lpTmp,(FieldStruct *)&SzMmpkData.fldStruct[3],
- tmp);
- MmpData[0].lpMmp[i].slBuy[j] =atol(tmp)/100;
- f2+=(double)MmpData[0].lpMmp[i].slBuy[j];
- lpTmp +=reclen;
- }
- if(j !=3) break;
- if(f1+f2 !=0)
- HqData[0].lpRefData[i].wb
- =(float)((f2-f1)/(f1+f2));
- else HqData[0].lpRefData[i].wb =0;
- if(memcmp(&LastMmp, &MmpData[0].lpMmp[i], sizeof(MMP)))
- MmpData[0].lpChanged[i] =TRUE;
- else MmpData[0].lpChanged[i] =FALSE;
- //rec_num++;
- }
- }
- //没有初始化的买卖盘数据
- if(rec_count/6<HqData[0].recCount)
- {
- memset(&MmpData[0].lpMmp[rec_count/6],0,
- sizeof(MMP)*(HqData[0].recCount -rec_count/6));
- }
- GlobalFreePtr(buffer);
- MsgLocal("OK.");
- return TRUE;
- }
- int RefreshSzZs(void)
- {
- int i, reclen, headlen;
- char *buffer;
- char tmp[100];
- static int times =0;
- if(SzZskData.hf <0)
- return 0;
-
- reclen=*(int *)SzZskData.dbfStruct.rlen;
- headlen=*(int *)SzZskData.dbfStruct.hlen;
-
- buffer =(char *)malloc(reclen*DpData[0].recCount+1);
- if (buffer==NULL)
- {
- ErrMsg(ghWndMain, "RefreshSzZs:alloc buffer failed!");
- return -1;
- }
- memset(buffer, 0, reclen*DpData[0].recCount+1);
-
- _llseek(SzZskData.hf,(long)headlen,SEEK_SET);
- _lread(SzZskData.hf,buffer, reclen*DpData[0].recCount);
- for (i=0;i<DpData[0].recCount;i++)
- {
- FldToString(buffer+i*reclen,
- (FieldStruct *)&SzZskData.fldStruct[6],
- tmp);
- DpData[0].zs[i] =(float)atof(tmp);
- DpData[0].zd[i] =DpData[0].zs[i]-DpData[0].sp[i];
- }
- free(buffer);
- return 0;
- }
- int RefreshShZs(LPSTR lpbuf, int zsnum)
- {
- char tmp[100];
-
- if(zsnum >15) return 0;
- FldToString((char huge*)lpbuf,(FieldStruct *)&HqkData[1].fldStruct[7],
- tmp);
- DpData[1].zs[zsnum] =(float)atof(tmp);
-
- FldToString((char huge*)lpbuf,(FieldStruct *)&HqkData[1].fldStruct[2],
- tmp);
- DpData[1].sp[zsnum] =(float)atof(tmp);
-
- DpData[1].zd[zsnum] =DpData[1].zs[zsnum]-DpData[1].sp[zsnum];
- return 0;
- }
- int GetSzZqmc(int jys)
- {
- int i, j, reclen, headlen, fldnum, rec_count;
- char *buffer;
- char tmp[40];
-
- if(GpkData[jys].hf ==-1)
- {
- ErrMsg(ghWndMain, "GetSzZqmc:GpkData[jys].hf ==-1!");
- return FALSE;
- }
- //rec_count =(int)*(long *)SzZskData.dbfStruct.recnum;
- rec_count =(int)*(long *)GpkData[jys].dbfStruct.recnum;
- if(rec_count <HqData[jys].recCount) rec_count =HqData[jys].recCount;
-
- fldnum =GpkData[jys].fldCount;
- reclen=*(int *)GpkData[jys].dbfStruct.rlen;
- headlen=*(int *)GpkData[jys].dbfStruct.hlen;
- if(rec_count <=0)
- {
- ErrMsg(ghWndMain, "GetSzZqmc:rec_count <=0!");
- return FALSE;
- }
- buffer =(char *)malloc(reclen+1);
- if (buffer==NULL)
- {
- ErrMsg(ghWndMain, "GetSzZqmc:alloc buffer failed!");
- return FALSE;
- }
-
- _llseek(GpkData[jys].hf,(long)headlen,SEEK_SET);
- for (i=0;i<rec_count;i++)
- {
- if(_lread(GpkData[jys].hf,buffer,reclen) !=(UINT)reclen) break;
-
- // get zqdm
- FldToString(buffer,(FieldStruct *)&GpkData[jys].fldStruct[0], tmp);
- for(j =0; j<HqData[jys].recCount; j++)
- if(!strcmp(tmp, HqData[jys].lpPreData[j].zqdm))
- break;
- if(j <HqData[jys].recCount)
- FldToString(buffer,(FieldStruct *)&GpkData[jys].fldStruct[1],
- HqData[jys].lpPreData[j].zqmc);
- }
- if(i <rec_count)
- {
- for(; i<HqData[jys].recCount; i++)
- {
- strcpy(HqData[jys].lpPreData[i].zqmc,
- HqData[jys].lpPreData[i].zqdm);
- }
- }
- free(buffer);
-
- return TRUE;
- }
- int CheckZqdm(LPSTR lpzqdm)
- {
- return 0;
- }
- extern long tim_seconds;
- //取大盘数据
- int GetDpData(int jys, BOOL fFirst)
- {
- int i;
- //int jys;
- float oldjg;
- long b_lc =0L, s_lc =0L;
- HQ_REF_DATA LastHq;
- DP_DATA LastDp;
- int rec_num;
-
- memcpy(&LastDp, &DpData[jys], sizeof(DP_DATA));
- DpData[jys].cjzje =CalcCjzje(jys);
- DpData[jys].npbl =CalcNpbl(jys);
- DpData[jys].cjss =CalcCjss(jys);
- DpData[jys].upCount =DpData[jys].downCount =DpData[jys].equalCount =0;
-
- for(i =0; i<HqData[jys].recCount; i++)
- {
- oldjg =HqData[jys].lpRefData[i].zjjg;
- //如果不是指数,则计算升跌家数
- if(!IsZsRec(jys, i))
- {
- if(HqData[jys].lpRefData[i].zdf >0)
- DpData[jys].upCount ++;
- else if(HqData[jys].lpRefData[i].zdf <0)
- DpData[jys].downCount ++;
- else DpData[jys].equalCount ++;
- }
- else
- {
- memcpy(&LastHq, &HqData[jys].lpRefData[i], sizeof(HQ_REF_DATA));
-
- HqData[jys].lpRefData[i].cjss =DpData[jys].cjss;
- HqData[jys].lpRefData[i].cjje =DpData[jys].cjzje;
- HqData[jys].lpRefData[i].npzl
- =(long)((double)DpData[jys].npbl*(double)DpData[jys].cjss);
- HqData[jys].lpRefData[i].wb =0;
- HqData[jys].lpRefData[i].lc =DpData[jys].cjss-LastDp.cjss;
- if(HqData[jys].lpRefData[i].lc <0)
- HqData[jys].lpRefData[i].lc =0L;
-
-
- if(jys ==0) rec_num =HqData[jys].recCount-i;
- else rec_num =i;
- if(!fFirst)
- {
- if(tim_seconds -zs_times[jys][rec_num] >gnHqRefreshTime)
- {
- GraphData[jys].lpGraData[i].lc =
- DpData[jys].cjss-oldDpCjss2[jys][rec_num];
- GetDpGraData(jys, i);
- if(GraphData[jys].lpGraData[i].lc)
- WriteGraData(jys, i);
- zs_times[jys][rec_num] =tim_seconds;
- oldDpCjss2[jys][rec_num] =DpData[jys].cjss;
- }
- }
- else
- {
- zs_times[jys][rec_num] =tim_seconds;
- oldDpCjss2[jys][rec_num] =DpData[jys].cjss;
- }
- }
- }
-
- if(memcmp(&LastDp, &DpData[jys], sizeof(DP_DATA))) return 1;
-
- return 0;
- }
- int GetMaxMin10(int jys)
- {
- int ret =0;
- MAXMIN_DATA LastMaxMin[2];
-
- memcpy(&LastMaxMin[0], &MaxMinData[jys][0], sizeof(MAXMIN_DATA));
- memcpy(&LastMaxMin[1], &MaxMinData[jys][1], sizeof(MAXMIN_DATA));
- GetMaxZd10(jys);
- GetMaxZdf10(jys);
- GetMaxCjss10(jys);
- GetMaxCjje10(jys);
- if(memcmp(&MaxMinData[jys][0], &LastMaxMin[0], sizeof(MAXMIN_DATA)))
- ret++;
- GetMinZd10(jys);
- GetMinZdf10(jys);
- GetMinCjss10(jys);
- GetMinCjje10(jys);
- if(memcmp(&MaxMinData[jys][1], &LastMaxMin[1], sizeof(MAXMIN_DATA)))
- ret+=2;
-
- return ret;
- }
- void GetMaxZdf10(int jys)
- {
- GetFloatSort10(jys, 8, SORT_UP, &MaxMinData[jys][0].recNum[0][0]);
- }
- void GetMinZdf10(int jys)
- {
- GetFloatSort10(jys, 8, SORT_DOWN, &MaxMinData[jys][1].recNum[0][0]);
- }
- void GetMaxCjss10(int jys)
- {
- GetLongSort10(jys, 9, SORT_UP, &MaxMinData[jys][0].recNum[2][0]);
- }
- void GetMinCjss10(int jys)
- {
- GetLongSort10(jys, 9, SORT_DOWN, &MaxMinData[jys][1].recNum[2][0]);
- }
- void GetMaxCjje10(int jys)
- {
- GetLongSort10(jys, 13, SORT_UP, &MaxMinData[jys][0].recNum[3][0]);
- }
- void GetMinCjje10(int jys)
- {
- GetLongSort10(jys, 13, SORT_DOWN, &MaxMinData[jys][1].recNum[3][0]);
- }
- void GetMaxZd10(int jys)
- {
- int key, i, j, n;
- float fval, f1, f;
- int count =0;
- int fldNum =8;
-
- for(i =0; i<10; i++)
- MaxMinData[jys][0].recNum[1][i] =i;
-
- for(i =0; i<HqData[jys].recCount; i++)
- keys[i] =i;
-
- for(i =0; i<HqData[jys].recCount; i++)
- {
- if(!IsMaxMin(jys, keys[i])) continue;
- if(HqData[jys].lpRefData[keys[i]].zjjg ==0) continue;
- key =i;
- if(HqData[jys].lpPreData[keys[key]].zrsp)
- fval =HqData[jys].lpRefData[keys[key]].zjjg
- -HqData[jys].lpPreData[keys[key]].zrsp;
- else fval =-100;
- for(j =i+1; j<HqData[jys].recCount; j++)
- {
- if(!IsMaxMin(jys, keys[j])) continue;
- if(HqData[jys].lpRefData[keys[j]].zjjg ==0) continue;
- if(HqData[jys].lpPreData[keys[j]].zrsp)
- f1 =HqData[jys].lpRefData[keys[j]].zjjg
- -HqData[jys].lpPreData[keys[j]].zrsp;
- else f1 =-100;
- f =f1-fval;
- if(f1>fval)
- {
- key =j;
- fval =f1;
- }
- }
- if(key >i)
- {
- //fval =*(float *)GetHqFldPos(jys, keys[key], fldNum);
- n =keys[i];
- keys[i] =keys[key];
- keys[key] =n;
- }
- MaxMinData[jys][0].recNum[1][count] =key;
- if(++count >=10) break;
- }
- }
- void GetMinZd10(int jys)
- {
- int key, i, j, n;
- float fval, f1, f;
- int count =0;
- int fldNum =8;
-
- for(i =0; i<10; i++)
- MaxMinData[jys][1].recNum[1][i] =i;
-
- for(i =0; i<HqData[jys].recCount; i++)
- keys[i] =i;
-
- for(i =0; i<HqData[jys].recCount; i++)
- {
- if(!IsMaxMin(jys, keys[i])) continue;
- if(HqData[jys].lpRefData[keys[i]].zjjg ==0) continue;
- key =i;
- if(HqData[jys].lpPreData[keys[key]].zrsp)
- fval =HqData[jys].lpRefData[keys[key]].zjjg
- -HqData[jys].lpPreData[keys[key]].zrsp;
- else fval =100;
- for(j =i+1; j<HqData[jys].recCount; j++)
- {
- if(!IsMaxMin(jys, keys[j])) continue;
- if(HqData[jys].lpRefData[keys[j]].zjjg ==0) continue;
- if(HqData[jys].lpPreData[keys[j]].zrsp)
- f1 =HqData[jys].lpRefData[keys[j]].zjjg
- -HqData[jys].lpPreData[keys[j]].zrsp;
- else f1 =100;
- f =f1-fval;
- if(f1<fval)
- {
- key =j;
- fval =f1;
- }
- }
- if(key >i)
- {
- //fval =*(float *)GetHqFldPos(jys, keys[key], fldNum);
- n =keys[i];
- keys[i] =keys[key];
- keys[key] =n;
- }
- MaxMinData[jys][1].recNum[1][count] =key;
- if(++count >=10) break;
- }
- }
- BOOL CheckTpbz(int jys, LPSTR buffer)
- {
- return FALSE;
- }
- BOOL IsZsRec(int jys, int rec_num)
- {
- if(jys ==0)
- {
- if(!strncmp(HqData[jys].lpPreData[rec_num].zqdm, "99", 2))
- return TRUE;
- }
- else
- if(!strncmp(HqData[jys].lpPreData[rec_num].zqdm, "0000", 4)
- && (HqData[jys].lpPreData[rec_num].zqdm[4] =='0'
- ||HqData[jys].lpPreData[rec_num].zqdm[4] =='1'))
- return TRUE;
-
- return FALSE;
- }
- LPSTR GetHqFldPos(int jys, int rec_num, int fld_num)
- {
- switch(fld_num)
- {
- case 0:
- return (LPSTR)&HqData[jys].lpPreData[rec_num].zqdm[0];
- case 1:
- return (LPSTR)&HqData[jys].lpPreData[rec_num].zrsp;
- case 2:
- return (LPSTR)&HqData[jys].lpPreData[rec_num].jrkp;
- case 3:
- return (LPSTR)&HqData[jys].lpRefData[rec_num].zgjg;
- case 4:
- return (LPSTR)&HqData[jys].lpRefData[rec_num].zdjg;
- case 5:
- return (LPSTR)&HqData[jys].lpRefData[rec_num].zgjm;
- case 6:
- return (LPSTR)&HqData[jys].lpRefData[rec_num].zdjm;
- case 7:
- return (LPSTR)&HqData[jys].lpRefData[rec_num].zjjg;
- case 8:
- return (LPSTR)&HqData[jys].lpRefData[rec_num].zdf;
- case 9:
- return (LPSTR)&HqData[jys].lpRefData[rec_num].cjss;
- case 10:
- return (LPSTR)&HqData[jys].lpRefData[rec_num].lc;
- case 11:
- return (LPSTR)&HqData[jys].lpRefData[rec_num].npzl;
- case 12:
- return (LPSTR)&HqData[jys].lpRefData[rec_num].wb;
- case 13:
- return (LPSTR)&HqData[jys].lpRefData[rec_num].cjje;
- }
- }
- int GetFloatSort10(int jys, int fldNum, int type, int *lpKeys)
- {
- int key, i, j, n;
- float fval, f1, f;
- int count =0;
-
- for(i =0; i<10; i++)
- lpKeys[i] =i;
-
- for(i =0; i<HqData[jys].recCount; i++)
- keys[i] =i;
-
- for(i =0; i<HqData[jys].recCount; i++)
- {
- if(!IsMaxMin(jys, keys[i])) continue;
- if(HqData[jys].lpRefData[keys[i]].zjjg ==0) continue;
- key =i;
- fval =*(float*)GetHqFldPos(jys, keys[key], fldNum);
- for(j =i+1; j<HqData[jys].recCount; j++)
- {
- if(!IsMaxMin(jys, keys[j])) continue;
- if(HqData[jys].lpRefData[keys[j]].zjjg ==0) continue;
- f1 =*(float *)GetHqFldPos(jys, keys[j], fldNum);
- f =f1-fval;
- if(type ==SORT_UP && f>.0)
- {
- key =j;
- fval =f1;
- }
- else if(type ==SORT_DOWN && f<.0)
- {
- key =j;
- fval =f1;
- }
- }
- if(key >i)
- {
- //fval =*(float *)GetHqFldPos(jys, keys[key], fldNum);
- n =keys[i];
- keys[i] =keys[key];
- keys[key] =n;
- }
- lpKeys[count] =key;
- if(++count >=10) break;
- }
- return 0;
- }
- int GetLongSort10(int jys, int fldNum, int type, int *lpKeys)
- {
- int key, i, j, n;
- long lval, l1, l;
- int count =0;
-
- for(i =0; i<10; i++)
- lpKeys[i] =i;
-
- for(i =0; i<HqData[jys].recCount; i++)
- keys[i] =i;
-
- for(i =0; i<HqData[jys].recCount; i++)
- {
- if(!IsMaxMin(jys, keys[i])) continue;
- if(HqData[jys].lpRefData[keys[i]].zjjg ==0) continue;
- key =i;
- lval =*(long*)GetHqFldPos(jys, keys[key], fldNum);
- for(j =i+1; j<HqData[jys].recCount; j++)
- {
- if(!IsMaxMin(jys, keys[j])) continue;
- if(HqData[jys].lpRefData[keys[j]].zjjg ==0) continue;
- l1 =*(long *)GetHqFldPos(jys, keys[j], fldNum);
- l =l1-lval;
- if(type ==SORT_UP && l>.0)
- {
- key =j;
- lval =l1;
- }
- else if(type ==SORT_DOWN && l<.0)
- {
- key =j;
- lval =l1;
- }
- }
- if(key >i)
- {
- //lval =*(long *)GetHqFldPos(jys, keys[key], fldNum);
- n =keys[i];
- keys[i] =keys[key];
- keys[key] =n;
- }
- lpKeys[count] =key;
- if(++count >=10) break;
- }
- return 0;
- }
- long CalcCjzje(int jys)
- {
- int i;
- long l =0;
-
- for(i =0; i<HqData[jys].recCount; i++)
- {
- if(jys==0)
- {
- if(HqData[jys].lpPreData[i].zqdm[0]=='1'||HqData[jys].lpPreData[i].zqdm[0]=='9')
- continue;
- if(HqData[jys].lpPreData[i].zqdm[0]=='3'||HqData[jys].lpPreData[i].zqdm[0]=='8')
- continue;
- }
- if(jys==1)
- {
- //if(strncmp(HqData[jys].lpPreData[i].zqdm,"70",2)!=0&&strncmp(HqData[jys].lpPreData[i].zqdm,"71",2)!=0)
- {
- if(HqData[jys].lpPreData[i].zqdm[0]=='0'||HqData[jys].lpPreData[i].zqdm[0]=='1'||
- HqData[jys].lpPreData[i].zqdm[0]=='2'||HqData[jys].lpPreData[i].zqdm[0]=='7')
- continue;
- }
- }
- if(!IsZsRec(jys, i))
- l +=HqData[jys].lpRefData[i].cjje;
- }
-
- return l;
- }
- float CalcNpbl(int jys)
- {
- int i;
- long double lfbuy =0, lftotal =0;
- float lf;
-
- for(i =0; i<HqData[jys].recCount; i++)
- {
- if(jys==0)
- {
- if(HqData[jys].lpPreData[i].zqdm[0]=='1'||HqData[jys].lpPreData[i].zqdm[0]=='9')
- continue;
- if(HqData[jys].lpPreData[i].zqdm[0]=='3'||HqData[jys].lpPreData[i].zqdm[0]=='8')
- continue;
- }
- if(jys==1)
- {
- //if(strncmp(HqData[jys].lpPreData[i].zqdm,"70",2)!=0&&strncmp(HqData[jys].lpPreData[i].zqdm,"71",2)!=0)
- {
- if(HqData[jys].lpPreData[i].zqdm[0]=='0'||HqData[jys].lpPreData[i].zqdm[0]=='1'||
- HqData[jys].lpPreData[i].zqdm[0]=='2'||HqData[jys].lpPreData[i].zqdm[0]=='7')
- continue;
- }
- }
- if(!IsZsRec(jys, i))
- {
- lfbuy +=(long double)HqData[jys].lpRefData[i].npzl;
- lftotal +=(long double)HqData[jys].lpRefData[i].cjss;
- }
- }
- if(lftotal ==0) return (float)0;
-
- lf =(float)(lfbuy/lftotal);
- return lf;
- }
- long CalcCjss(int jys)
- {
- int i;
- long l =0;
-
- for(i =0; i<HqData[jys].recCount; i++)
- {
- if(jys==0)
- {
- if(HqData[jys].lpPreData[i].zqdm[0]=='1'||HqData[jys].lpPreData[i].zqdm[0]=='9')
- continue;
- if(HqData[jys].lpPreData[i].zqdm[0]=='3'||HqData[jys].lpPreData[i].zqdm[0]=='8')
- continue;
- }
- if(jys==1)
- {
- //if(strncmp(HqData[jys].lpPreData[i].zqdm,"70",2)!=0&&strncmp(HqData[jys].lpPreData[i].zqdm,"71",2)!=0)
- {
- if(HqData[jys].lpPreData[i].zqdm[0]=='0'||HqData[jys].lpPreData[i].zqdm[0]=='1'||
- HqData[jys].lpPreData[i].zqdm[0]=='2'||HqData[jys].lpPreData[i].zqdm[0]=='7')
- continue;
- }
- }
- if(!IsZsRec(jys, i))
- l +=HqData[jys].lpRefData[i].cjss;
- }
- return l;
- }
- int UDPBlockingHook(void)
- {
- MSG msg;
- if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
- {
- if(!ghWndMain || !IsDialogMessage(ghWndMain, &msg))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- if(msg.message ==WM_QUIT)
- {
- PostQuitMessage(0);
- run_cancelled =TRUE;
- return FALSE;
- }
- }
- return TRUE;
- }
- return FALSE;
- }
- int HqAllocMem(int jys, int recCount)
- {
- if(HqData[jys].recCount ==0)
- {
- HqData[jys].recCount =recCount;
- HqData[jys].lpPreData =(LPHQ_PRE_DATA)GlobalAllocPtr(GHND,
- HqData[jys].recCount*sizeof(HQ_PRE_DATA));
- HqData[jys].lpRefData =(LPHQ_REF_DATA)GlobalAllocPtr(GHND,
- HqData[jys].recCount*sizeof(HQ_REF_DATA));
- HqData[jys].lpbChanged =(BYTE *)GlobalAllocPtr(GHND,
- HqData[jys].recCount*HQ_REF_ITEM_COUNT);
- GraphData[jys].lpGraData =(LPGRA_DATA)GlobalAllocPtr(GHND,
- HqData[jys].recCount*sizeof(GRA_DATA));
- GraphData[jys].lpGraHead =(LPGRA_HEAD)GlobalAllocPtr(GHND,
- HqData[jys].recCount*sizeof(GRA_HEAD));
- MmpData[jys].lpMmp =(LPMMP)GlobalAllocPtr(GHND,
- HqData[jys].recCount*sizeof(MMP));
- MmpData[jys].lpChanged =(BYTE *)GlobalAllocPtr(GHND,
- HqData[jys].recCount);
- }
- else if(HqData[jys].recCount !=recCount)
- {
- HqData[jys].recCount =recCount;
- HqData[jys].lpPreData =(LPHQ_PRE_DATA)GlobalReAllocPtr(HqData[jys].lpPreData,
- HqData[jys].recCount*sizeof(HQ_PRE_DATA), GMEM_MOVEABLE);
- HqData[jys].lpRefData =(LPHQ_REF_DATA)GlobalReAllocPtr(HqData[jys].lpRefData,
- HqData[jys].recCount*sizeof(HQ_REF_DATA), GMEM_MOVEABLE);
- HqData[jys].lpbChanged =(BYTE *)GlobalReAllocPtr(HqData[jys].lpbChanged,
- HqData[jys].recCount*HQ_REF_ITEM_COUNT, GMEM_MOVEABLE);
- GraphData[jys].lpGraHead =(LPGRA_HEAD)GlobalReAllocPtr(GraphData[jys].lpGraHead,
- HqData[jys].recCount*sizeof(GRA_HEAD),GMEM_MOVEABLE);
- GraphData[jys].lpGraData =(LPGRA_DATA)GlobalReAllocPtr(GraphData[jys].lpGraData,
- HqData[jys].recCount*sizeof(GRA_DATA),GMEM_MOVEABLE);
- MmpData[jys].lpMmp =(LPMMP)GlobalReAllocPtr(MmpData[jys].lpMmp,
- HqData[jys].recCount*sizeof(MMP), GMEM_MOVEABLE);
- MmpData[jys].lpChanged =(BYTE *)GlobalReAllocPtr(MmpData[jys].lpChanged,
- HqData[jys].recCount, GHND);
- }
-
- if(HqData[jys].lpPreData ==NULL)
- {
- ErrMsg(ghWndMain, "alloc mem pre data failed!");
- return -1;
- }
-
- if(HqData[jys].lpRefData ==NULL)
- {
- ErrMsg(ghWndMain, "alloc mem ref data failed!");
- return -1;
- }
- if(HqData[jys].lpbChanged ==NULL)
- {
- ErrMsg(ghWndMain, "alloc mem chg data failed!");
- return -1;
- }
- if(GraphData[jys].lpGraData ==NULL || GraphData[jys].lpGraHead ==NULL)
- {
- ErrMsg(ghWndMain, "alloc mem graph data failed!");
- return -1;
- }
- if(MmpData[jys].lpMmp ==NULL)
- {
- ErrMsg(ghWndMain, "alloc mem mmp failed!");
- return -1;
- }
- if(MmpData[jys].lpChanged ==NULL)
- {
- ErrMsg(ghWndMain, "alloc mem mmp changed failed!");
- return -1;
- }
- return 0;
- }
- BOOL IsMaxMin(int jys, int rec_num)
- {
- char c;
- c =HqData[jys].lpPreData[rec_num].zqdm[0];
-
- if(IsZsRec(jys, rec_num)) return FALSE;
- if(jys ==0)
- {
- if(c =='0' || c =='4') return TRUE;
- }
- else if((c =='0' && !IsZsRec(jys, rec_num))
- || c =='5' || c=='6')
- return TRUE;
-
- return FALSE;
- }
- BOOL IsB(int jys, int rec_num)
- {
- if((jys ==0 && HqData[jys].lpPreData[rec_num].zqdm[0] =='2')
- || (jys ==1 && HqData[jys].lpPreData[rec_num].zqdm[0] =='2'))
- return TRUE;
- return FALSE;
- }
- BOOL IsGuoZhai(int jys, int rec_num)
- {
- return FALSE;
- }
- int GetGraData(int jys, int i, LPHQ_REF_DATA lpLastHq)
- {
- float jg1, jg2;
-
- if(HqData[jys].lpRefData[i].lc>0)
- {
- //计算内盘
- //GraphData[jys].lpGraHead[i].dateNum==date_num;
- GraphData[jys].lpGraData[i].tim=tim;
- if(GraphData[jys].lpGraHead[i].minCount==0)
- {
- //第一次有正量差,开市初始化
- //HqData[jys].lpPreData[i].jrkp=lpLastHq->zjjg;
- //初始化分时数据