注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

且行且记录

点滴记录,行的更远!

 
 
 

日志

 
 

又再三更新了华泰买股卖股程序  

2015-11-18 08:12:38|  分类: 一些练习 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
因为平时喜欢追涨、也喜欢抄底,所以如果没有快捷输入价格数量的话,就要花时间查价。
所以为了方便,加了zt表涨停价,dt表跌停价,all表所有。这样便于立即成交,不用为几分钱
而买不上,卖不掉等。也便于清仓!
C:\TEMP\huatai>buy
华泰证券(专业版Ⅱ交易) 买入股票测试!
帮助: buy code [price] [num]
[注] price用zt表示涨停价, dt表示跌停价, num用all表示可买股数!
查当前价格可买股数: buy 601010
查输入价格可买股数: buy 601010 7.28
按输入价格数量买股: buy 601010 7.28 100

C:\TEMP\huatai>sell
华泰证券(专业版Ⅱ交易) 卖出股票测试!
帮助: sell code [price num]
[注] price用zt表示涨停价, dt表示跌停价, num用all表示可卖股数!
查可卖股数: sell 601010
按输入卖股: sell 601010 7.28 100

C:\TEMP\huatai>list
华泰证券(专业版Ⅱ交易) 列出股票价格测试!
帮助: list code1 code2 ... codeN
举例: list 601010 002100 002181

1、买股
// cl buy.cpp user32.lib
// hcper @ 2015.10.19创建v0.1
// hcper @ 2015.11.17修改v0.3
#include <windows.h>
#include <stdio.h>

typedef struct _WNDSTR
{
HWND hwnd;
LPSTR lpStr;
DWORD atom;
} WS,*LPWS;

BOOL CALLBACK EnumWindowsName(HWND hwnd, LPARAM lParam)
{
LPWS lpws = (LPWS)lParam;
char Buff[256];
if (GetWindowText(hwnd, Buff, 256) > 0)
{

if (strcmp(Buff, lpws->lpStr) == 0) // 匹配窗口名
{
//printf("hwnd = 0x%08x, title = %s\n", hwnd, Buff);
lpws->hwnd = hwnd;
return FALSE;
}
}
return TRUE;
}

BOOL CALLBACK EnumName(HWND hwnd, LPARAM lParam)
{
LPWS lpws = (LPWS)lParam;
char Buff[256];

if (GetClassName(hwnd, Buff, 256) > 0 && strcmp(Buff, "#32770") == 0)
{
if (GetClassLong(hwnd, GCW_ATOM) == lpws->atom)
{
hwnd = GetDlgItem(hwnd, (int)lpws->hwnd);
GetWindowText(hwnd, Buff, 256);

if (strcmp(Buff, lpws->lpStr) == 0) // 匹配窗口名
{
//printf("hwnd = 0x%08x, title = %s\n", hwnd, Buff);
lpws->hwnd = hwnd;
return FALSE;
}
}
}

return TRUE;
}

int main(int argc, char *argv[])
{
WS ws;
char Buff[256];

HWND hWnd = NULL;
HWND hFrm = NULL;
HWND hBtn = NULL;
HWND hDlg = NULL;
HWND hPan = NULL;
HWND hTmp = NULL;
double zt = 0.0; // 涨停价
double dt = 0.0; //跌停价
long num = 100; //股数
double k = 1.0; //比例

printf("华泰证券(专业版Ⅱ交易) 买入股票测试!\n");
if (argc < 2 || argc > 4)
{
printf("帮助: buy code [price] [num]\n");
printf("[注] price用zt表示涨停价, dt表示跌停价, num用all表示可买股数!\n");
printf("查当前价格可买股数: buy 601010\n");
printf("查输入价格可买股数: buy 601010 7.28\n");
printf("按输入价格数量买股: buy 601010 7.28 100\n");
return 0;
}
ws.lpStr = "网上股票交易系统5.0";
EnumWindows(EnumWindowsName, (LPARAM)&ws);
hWnd = ws.hwnd;
if (hWnd == NULL) return 0;
PostMessage(hWnd, WM_KEYDOWN, VK_F1, 0); // 按F1进入买入股票界面
Sleep(500);
PostMessage(hWnd, WM_KEYUP, VK_F1, 0);
Sleep(500);

ws.lpStr = "买入股票";
EnumChildWindows(hWnd, EnumWindowsName, (LPARAM)&ws); // 查找买入股票
hFrm = ws.hwnd ? GetParent(ws.hwnd) : NULL;
if (hFrm == NULL) return 0;

hTmp = GetDlgItem(hFrm, 0x408);
if (hTmp != NULL )
{
SendMessage(hTmp, WM_CLEAR, 0, 0); // 先清除残留
SendMessage(hTmp, WM_SETTEXT, 0, (LPARAM)argv[1]); // 输入股票代码
Sleep(1000); // 网络延迟等更新界面
}

if (GetDlgItemText(hFrm, 0x40c, Buff, 255) > 0)
printf("\n证券代码: %s\t证券名称: %s\n", argv[1], Buff);

ws.lpStr = "最新";
EnumChildWindows(hFrm, EnumWindowsName, (LPARAM)&ws); // 通过最新找到盘口句柄
hPan = ws.hwnd ? GetParent(ws.hwnd) : NULL;

hTmp = GetDlgItem(hPan, 0x400);
if (hTmp != NULL )
{
SendMessage(hTmp, WM_GETTEXT, 256, (LPARAM)Buff);
printf("最新: %s\t", Buff);
}

hTmp = GetDlgItem(hPan, 0x403);
if (hTmp != NULL )
{
SendMessage(hTmp, WM_GETTEXT, 256, (LPARAM)Buff);
printf("涨幅: %s\t", Buff);
}

hTmp = GetDlgItem(hPan, 0x404);
if (hTmp != NULL )
{
SendMessage(hTmp, WM_GETTEXT, 256, (LPARAM)Buff);
printf("涨停: %s\t", Buff);
zt = atof(Buff);
}

hTmp = GetDlgItem(hPan, 0x405);
if (hTmp != NULL )
{
SendMessage(hTmp, WM_GETTEXT, 256, (LPARAM)Buff);
printf("跌停: %s\n", Buff);
dt = atof(Buff);
}

if (argc > 2)
{
if (strcmp(argv[2], "zt") == 0)
sprintf(Buff, "%.2f", zt);
else if (strcmp(argv[2], "dt") == 0)
sprintf(Buff, "%.2f", dt);
else
strcpy(Buff, argv[2]);

SendDlgItemMessage(hFrm, 0x409, WM_SETTEXT, 0, (LPARAM)Buff); // 输入股票价格
}

hTmp = GetDlgItem(hFrm, 0x409);
if (hTmp != NULL )
{
SendMessage(hTmp, WM_GETTEXT, 256, (LPARAM)Buff);
printf("当前价格: %s\t", Buff);
}

hTmp = GetDlgItem(hFrm, 0x3fa);
if (hTmp != NULL )
{
SendMessage(hTmp, WM_GETTEXT, 256, (LPARAM)Buff);
printf("可买(股): %s\n", Buff);
num = atol(Buff);
}

if (argc != 4) return 0; // 只有价格数量齐全才往后执行

if (strcmp(argv[3], "all") == 0)
sprintf(Buff, "%d", num);
else
strcpy(Buff, argv[3]);

SendDlgItemMessage(hFrm, 0x40a, WM_SETTEXT, 0, (LPARAM)Buff); // 输入股票数量

hBtn = GetDlgItem(hFrm, 0x3ee);
if (hBtn == NULL) return 0;

PostMessage(hBtn, BM_CLICK, 0, 0); // 点击买入
Sleep(500);

ws.hwnd = (HWND)0x555; // ID
ws.lpStr = "委托确认";
ws.atom = 0x8002; // ATOM
EnumWindows(EnumName, (LPARAM)&ws);

hDlg = ws.hwnd ? GetParent(ws.hwnd) : NULL;

hBtn = GetDlgItem(hDlg, 6);
if (hBtn == NULL) return 0;

PostMessage(hBtn, BM_CLICK, 0, 0); // 点击确认
Sleep(500);

ws.hwnd = (HWND)0x555; // ID
ws.lpStr = "提示";
ws.atom = 0x8002; // ATOM
EnumWindows(EnumName, (LPARAM)&ws);

hDlg = ws.hwnd ? GetParent(ws.hwnd) : NULL;

hBtn = GetDlgItem(hDlg, 2);
if (hBtn == NULL) return 0;

PostMessage(hBtn, BM_CLICK, 0, 0); // 点击确认
Sleep(500);

return 0;
}

2、卖股
// cl sell.cpp user32.lib
// hcper @ 2015.10.19创建v0.1
// hcper @ 2015.11.17修改v0.3
#include <windows.h>
#include <stdio.h>

typedef struct _WNDSTR
{
HWND hwnd;
LPSTR lpStr;
DWORD atom;
} WS,*LPWS;

BOOL CALLBACK EnumWindowsName(HWND hwnd, LPARAM lParam)
{
LPWS lpws = (LPWS)lParam;
char Buff[256];
if (GetWindowText(hwnd, Buff, 256) > 0)
{

if (strcmp(Buff, lpws->lpStr) == 0) // 匹配窗口名
{
//printf("hwnd = 0x%08x, title = %s\n", hwnd, Buff);
lpws->hwnd = hwnd;
return FALSE;
}
}
return TRUE;
}

BOOL CALLBACK EnumName(HWND hwnd, LPARAM lParam)
{
LPWS lpws = (LPWS)lParam;
char Buff[256];

if (GetClassName(hwnd, Buff, 256) > 0 && strcmp(Buff, "#32770") == 0)
{
if (GetClassLong(hwnd, GCW_ATOM) == lpws->atom)
{
hwnd = GetDlgItem(hwnd, (int)lpws->hwnd);
GetWindowText(hwnd, Buff, 256);

if (strcmp(Buff, lpws->lpStr) == 0) // 匹配窗口名
{
//printf("hwnd = 0x%08x, title = %s\n", hwnd, Buff);
lpws->hwnd = hwnd;
return FALSE;
}
}
}

return TRUE;
}

int main(int argc, char *argv[])
{
WS ws;
char Buff[256];

HWND hWnd = NULL;
HWND hFrm = NULL;
HWND hBtn = NULL;
HWND hDlg = NULL;
HWND hPan = NULL;
HWND hTmp = NULL;
double zt = 0.0; // 涨停价
double dt = 0.0; //跌停价
long num = 100; //股数
double k = 1.0; //比例

printf("华泰证券(专业版Ⅱ交易) 卖出股票测试!\n");
if (argc != 2 && argc != 4)
{
printf("帮助: sell code [price num]\n");
printf("[注] price用zt表示涨停价, dt表示跌停价, num用all表示可卖股数!\n");
printf("查可卖股数: sell 601010\n");
printf("按输入卖股: sell 601010 7.28 100\n");
return 0;
}
ws.lpStr = "网上股票交易系统5.0";
EnumWindows(EnumWindowsName, (LPARAM)&ws);
hWnd = ws.hwnd;
if (hWnd == NULL) return 0;
PostMessage(hWnd, WM_KEYDOWN, VK_F2, 0); // 按F2进入卖出股票界面
Sleep(500);
PostMessage(hWnd, WM_KEYUP, VK_F2, 0);
Sleep(500);

ws.lpStr = "卖出股票";
EnumChildWindows(hWnd, EnumWindowsName, (LPARAM)&ws); // 查找卖出股票
hFrm = ws.hwnd ? GetParent(ws.hwnd) : NULL;
if (hFrm == NULL) return 0;

hTmp = GetDlgItem(hFrm, 0x408);
if (hTmp != NULL )
{
SendMessage(hTmp, WM_CLEAR, 0, 0); // 先清除残留
SendMessage(hTmp, WM_SETTEXT, 0, (LPARAM)argv[1]); // 输入股票代码
Sleep(1000); // 网络延迟等更新界面
}

if (GetDlgItemText(hFrm, 0x40c, Buff, 255) > 0)
printf("\n证券代码: %s\t证券名称: %s\n", argv[1], Buff);

ws.lpStr = "最新";
EnumChildWindows(hFrm, EnumWindowsName, (LPARAM)&ws); // 通过最新找到盘口句柄
hPan = ws.hwnd ? GetParent(ws.hwnd) : NULL;

hTmp = GetDlgItem(hPan, 0x400);
if (hTmp != NULL )
{
SendMessage(hTmp, WM_GETTEXT, 256, (LPARAM)Buff);
printf("最新: %s\t", Buff);
}

hTmp = GetDlgItem(hPan, 0x403);
if (hTmp != NULL )
{
SendMessage(hTmp, WM_GETTEXT, 256, (LPARAM)Buff);
printf("涨幅: %s\t", Buff);
}

hTmp = GetDlgItem(hPan, 0x404);
if (hTmp != NULL )
{
SendMessage(hTmp, WM_GETTEXT, 256, (LPARAM)Buff);
printf("涨停: %s\t", Buff);
zt = atof(Buff);
}

hTmp = GetDlgItem(hPan, 0x405);
if (hTmp != NULL )
{
SendMessage(hTmp, WM_GETTEXT, 256, (LPARAM)Buff);
printf("跌停: %s\n", Buff);
dt = atof(Buff);
}

hTmp = GetDlgItem(hFrm, 0x409);
if (hTmp != NULL )
{
SendMessage(hTmp, WM_GETTEXT, 256, (LPARAM)Buff);
printf("当前价格: %s\t", Buff);
}

hTmp = GetDlgItem(hFrm, 0x40e);
if (hTmp != NULL )
{
SendMessage(hTmp, WM_GETTEXT, 256, (LPARAM)Buff);
printf("可用数量: %s\n", Buff);
num = atol(Buff);
}

if (argc != 4) return 0; // 只有价格数量齐全才往后执行

if (strcmp(argv[2], "zt") == 0)
sprintf(Buff, "%.2f", zt);
else if (strcmp(argv[2], "dt") == 0)
sprintf(Buff, "%.2f", dt);
else
strcpy(Buff, argv[2]);

SendDlgItemMessage(hFrm, 0x409, WM_SETTEXT, 0, (LPARAM)Buff); // 输入股票价格

if (strcmp(argv[3], "all") == 0)
sprintf(Buff, "%d", num);
else
strcpy(Buff, argv[3]);

SendDlgItemMessage(hFrm, 0x40a, WM_SETTEXT, 0, (LPARAM)Buff); // 输入股票数量

hBtn = GetDlgItem(hFrm, 0x3ee);
if (hBtn == NULL) return 0;

PostMessage(hBtn, BM_CLICK, 0, 0); // 点击卖出
Sleep(500);

ws.hwnd = (HWND)0x555; // ID
ws.lpStr = "委托确认";
ws.atom = 0x8002; // ATOM
EnumWindows(EnumName, (LPARAM)&ws);

hDlg = ws.hwnd ? GetParent(ws.hwnd) : NULL;

hBtn = GetDlgItem(hDlg, 6);
if (hBtn == NULL) return 0;

PostMessage(hBtn, BM_CLICK, 0, 0); // 点击确认
Sleep(500);

ws.hwnd = (HWND)0x555; // ID
ws.lpStr = "提示";
ws.atom = 0x8002; // ATOM
EnumWindows(EnumName, (LPARAM)&ws);

hDlg = ws.hwnd ? GetParent(ws.hwnd) : NULL;

hBtn = GetDlgItem(hDlg, 2);
if (hBtn == NULL) return 0;

PostMessage(hBtn, BM_CLICK, 0, 0); // 点击确认
Sleep(500);

return 0;
}

3、列价格
// cl list.cpp user32.lib
#include <windows.h>
#include <stdio.h>

typedef struct _WNDSTR
{
HWND hwnd;
LPSTR lpStr;
DWORD atom;
} WS,*LPWS;

BOOL CALLBACK EnumWindowsName(HWND hwnd, LPARAM lParam)
{
LPWS lpws = (LPWS)lParam;
char Buff[256];
if (GetWindowText(hwnd, Buff, 256) > 0)
{

if (strcmp(Buff, lpws->lpStr) == 0) // 匹配窗口名
{
//printf("hwnd = 0x%08x, title = %s\n", hwnd, Buff);
lpws->hwnd = hwnd;
return FALSE;
}
}
return TRUE;
}

BOOL CALLBACK EnumName(HWND hwnd, LPARAM lParam)
{
LPWS lpws = (LPWS)lParam;
char Buff[256];

if (GetClassName(hwnd, Buff, 256) > 0 && strcmp(Buff, "#32770") == 0)
{
if (GetClassLong(hwnd, GCW_ATOM) == lpws->atom)
{
hwnd = GetDlgItem(hwnd, (int)lpws->hwnd);
GetWindowText(hwnd, Buff, 256);

if (strcmp(Buff, lpws->lpStr) == 0) // 匹配窗口名
{
//printf("hwnd = 0x%08x, title = %s\n", hwnd, Buff);
lpws->hwnd = hwnd;
return FALSE;
}
}
}

return TRUE;
}

int main(int argc, char *argv[])
{
WS ws;
char Buff[256];

HWND hWnd = NULL;
HWND hFrm = NULL;
HWND hBtn = NULL;
HWND hDlg = NULL;
HWND hPan = NULL;
HWND hTmp = NULL;

printf("华泰证券(专业版Ⅱ交易) 列出股票价格测试!\n");
if (argc < 2)
{
printf("帮助: list code1 code2 ... codeN\n");
printf("举例: list 601010 002100 002181\n");
return 0;
}
ws.lpStr = "网上股票交易系统5.0";
EnumWindows(EnumWindowsName, (LPARAM)&ws);
hWnd = ws.hwnd;
if (hWnd == NULL) return 0;
PostMessage(hWnd, WM_KEYDOWN, VK_F1, 0); // 按F1进入买入股票界面
Sleep(500);
PostMessage(hWnd, WM_KEYUP, VK_F1, 0);
Sleep(500);

ws.lpStr = "买入股票";
EnumChildWindows(hWnd, EnumWindowsName, (LPARAM)&ws); // 查找买入股票
hFrm = ws.hwnd ? GetParent(ws.hwnd) : NULL;
if (hFrm == NULL) return 0;

for (int i = 1; i < argc; i++)
{
hTmp = GetDlgItem(hFrm, 0x408);
if (hTmp != NULL )
{
SendMessage(hTmp, WM_CLEAR, 0, 0); // 先清除残留
SendMessage(hTmp, WM_SETTEXT, 0, (LPARAM)argv[i]); // 输入股票代码
Sleep(1000); // 网络延迟等更新界面
}

hTmp = GetDlgItem(hFrm, 0x40c);
if (hTmp != NULL )
{
SendMessage(hTmp, WM_GETTEXT, 256, (LPARAM)Buff);
printf("\n证券代码: %s\t证券名称: %s\t", argv[i], Buff);
}

hTmp = GetDlgItem(hFrm, 0x3fa);
if (hTmp != NULL )
{
SendMessage(hTmp, WM_GETTEXT, 256, (LPARAM)Buff);
printf("可买(股): %s\n", Buff);
}

ws.lpStr = "最新";
EnumChildWindows(hFrm, EnumWindowsName, (LPARAM)&ws); // 通过最新找到盘口句柄
hPan = ws.hwnd ? GetParent(ws.hwnd) : NULL;

hTmp = GetDlgItem(hPan, 0x400);
if (hTmp != NULL )
{
SendMessage(hTmp, WM_GETTEXT, 256, (LPARAM)Buff);
printf("最新: %s\t", Buff);
}

hTmp = GetDlgItem(hPan, 0x403);
if (hTmp != NULL )
{
SendMessage(hTmp, WM_GETTEXT, 256, (LPARAM)Buff);
printf("涨幅: %s\t", Buff);
}

hTmp = GetDlgItem(hPan, 0x404);
if (hTmp != NULL )
{
SendMessage(hTmp, WM_GETTEXT, 256, (LPARAM)Buff);
printf("涨停: %s\t", Buff);
}

hTmp = GetDlgItem(hPan, 0x405);
if (hTmp != NULL )
{
SendMessage(hTmp, WM_GETTEXT, 256, (LPARAM)Buff);
printf("跌停: %s\n", Buff);
}
}

return 0;
}
  评论这张
 
阅读(92)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017