332 lines
17 KiB
C++
332 lines
17 KiB
C++
// CPRobotDlg.cpp : 구현 파일
|
||
//
|
||
|
||
#include "stdafx.h"
|
||
#include "CPRobot.h"
|
||
#include "CPRobotDlg.h"
|
||
|
||
#ifdef _DEBUG
|
||
#define new DEBUG_NEW
|
||
#endif
|
||
|
||
|
||
ICpTdUtilPtr g_pTdUtil = NULL;
|
||
|
||
|
||
CCPRobotDlg::CCPRobotDlg(CWnd* pParent /*=NULL*/)
|
||
: CDialog(CCPRobotDlg::IDD, pParent)
|
||
{
|
||
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
|
||
|
||
m_pDataMgr = NULL;
|
||
m_pOpJpBid = NULL;
|
||
}
|
||
|
||
void CCPRobotDlg::DoDataExchange(CDataExchange* pDX)
|
||
{
|
||
CDialog::DoDataExchange(pDX);
|
||
DDX_Control(pDX, IDC_LIST_ITEMS, m_ResultList);
|
||
}
|
||
|
||
BEGIN_MESSAGE_MAP(CCPRobotDlg, CDialog)
|
||
ON_WM_PAINT()
|
||
ON_WM_QUERYDRAGICON()
|
||
//}}AFX_MSG_MAP
|
||
ON_BN_CLICKED(IDC_BUTTON_REFRESH_BALANCE, &CCPRobotDlg::OnBnClickedButtonRefreshBalance)
|
||
ON_WM_CREATE()
|
||
ON_WM_DESTROY()
|
||
ON_BN_CLICKED(IDC_BUTTON_START_DEAL, &CCPRobotDlg::OnBnClickedButtonStartDeal)
|
||
ON_BN_CLICKED(IDC_BUTTON_SEARCH, &CCPRobotDlg::OnBnClickedButtonSearch)
|
||
ON_BN_CLICKED(IDC_RADIO_BID, &CCPRobotDlg::OnBnClickedRadioBid)
|
||
ON_BN_CLICKED(IDC_RADIO_ASK, &CCPRobotDlg::OnBnClickedRadioAsk)
|
||
ON_EN_CHANGE(IDC_EDIT_ORDERINGPRICE, &CCPRobotDlg::OnEnChangeEditOrderingprice)
|
||
END_MESSAGE_MAP()
|
||
|
||
|
||
// CCPRobotDlg 메시지 처리기
|
||
BOOL CCPRobotDlg::OnInitDialog()
|
||
{
|
||
CDialog::OnInitDialog();
|
||
|
||
// 이 대화 상자의 아이콘을 설정합니다. 응용 프로그램의 주 창이 대화 상자가 아닐 경우에는
|
||
// 프레임워크가 이 작업을 자동으로 수행합니다.
|
||
SetIcon(m_hIcon, TRUE); // 큰 아이콘을 설정합니다.
|
||
SetIcon(m_hIcon, FALSE); // 작은 아이콘을 설정합니다.
|
||
|
||
// TODO: 여기에 추가 초기화 작업을 추가합니다.
|
||
|
||
return TRUE; // 포커스를 컨트롤에 설정하지 않으면 TRUE를 반환합니다.
|
||
}
|
||
|
||
int CCPRobotDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
|
||
{
|
||
if (CDialog::OnCreate(lpCreateStruct) == -1)
|
||
return -1;
|
||
|
||
// TODO: Add your specialized creation code here
|
||
CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
||
|
||
// 모의투자 mjjo53
|
||
// 계좌번호 335190813
|
||
//g_pTdUtil.CreateInstance(CLSID_CpTdUtil);
|
||
//const short iInitResult = g_pTdUtil->TradeInit(0);
|
||
//switch(iInitResult)
|
||
//{
|
||
//case -1:
|
||
// MessageBox("TradeInit 오류");
|
||
// return -2;
|
||
// break;
|
||
|
||
//case 1:
|
||
// MessageBox("업무 키 잘못 입력됨");
|
||
// return -2;
|
||
// break;
|
||
|
||
//case 2:
|
||
// MessageBox("계좌 비밀번호 잘못 입력됨");
|
||
// return -2;
|
||
// break;
|
||
|
||
//case 3:
|
||
// MessageBox("취소됨");
|
||
// return -2;
|
||
// break;
|
||
//}
|
||
|
||
|
||
|
||
|
||
//OnBnClickedButtonRefreshBalance();
|
||
|
||
m_pDataMgr = new CDataMgr();
|
||
m_pDataMgr->LoadFromFile();
|
||
|
||
m_pOpJpBid.CreateInstance(CLSID_OptionJpBid);
|
||
|
||
m_EventHandler.DispEventAdvise(m_pOpJpBid);
|
||
m_EventHandler.SetIEventHandler(this);
|
||
|
||
|
||
|
||
ICpOptionCodePtr pOpCode;
|
||
pOpCode.CreateInstance(CLSID_CpOptionCode);
|
||
short iCodeCnt = pOpCode->GetCount();
|
||
|
||
std::string Code;
|
||
|
||
for(int i=0; i<iCodeCnt; i++)
|
||
{
|
||
Code = (_bstr_t)pOpCode->GetData(0, i);
|
||
m_OpCodeList.push_back(Code);
|
||
}
|
||
pOpCode.Release();
|
||
|
||
return 0;
|
||
}
|
||
|
||
void CCPRobotDlg::OnDestroy()
|
||
{
|
||
CDialog::OnDestroy();
|
||
|
||
// TODO: Add your message handler code here
|
||
m_pOpJpBid.Release();
|
||
SAFE_DELETE(m_pDataMgr);
|
||
|
||
m_EventHandler.DispEventUnadvise(m_pOpJpBid);
|
||
}
|
||
|
||
BOOL CCPRobotDlg::DestroyWindow()
|
||
{
|
||
// TODO: Add your specialized code here and/or call the base class
|
||
//g_pTdUtil.Release();
|
||
|
||
return CDialog::DestroyWindow();
|
||
}
|
||
|
||
// 대화 상자에 최소화 단추를 추가할 경우 아이콘을 그리려면
|
||
// 아래 코드가 필요합니다. 문서/뷰 모델을 사용하는 MFC 응용 프로그램의 경우에는
|
||
// 프레임워크에서 이 작업을 자동으로 수행합니다.
|
||
|
||
void CCPRobotDlg::OnPaint()
|
||
{
|
||
if (IsIconic())
|
||
{
|
||
CPaintDC dc(this); // 그리기를 위한 디바이스 컨텍스트
|
||
|
||
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
|
||
|
||
// 클라이언트 사각형에서 아이콘을 가운데에 맞춥니다.
|
||
int cxIcon = GetSystemMetrics(SM_CXICON);
|
||
int cyIcon = GetSystemMetrics(SM_CYICON);
|
||
CRect rect;
|
||
GetClientRect(&rect);
|
||
int x = (rect.Width() - cxIcon + 1) / 2;
|
||
int y = (rect.Height() - cyIcon + 1) / 2;
|
||
|
||
// 아이콘을 그립니다.
|
||
dc.DrawIcon(x, y, m_hIcon);
|
||
}
|
||
else
|
||
{
|
||
CDialog::OnPaint();
|
||
}
|
||
}
|
||
|
||
// 사용자가 최소화된 창을 끄는 동안에 커서가 표시되도록 시스템에서 이 함수를 호출합니다.
|
||
HCURSOR CCPRobotDlg::OnQueryDragIcon()
|
||
{
|
||
return static_cast<HCURSOR>(m_hIcon);
|
||
}
|
||
|
||
void CCPRobotDlg::UpdateDataCustom(const BOOL bWndToVariable)
|
||
{
|
||
if(bWndToVariable == TRUE)
|
||
{
|
||
m_pDataMgr->m_bSell = (((CButton*)GetDlgItem(IDC_RADIO_BID))->GetCheck() == 1);
|
||
m_pDataMgr->m_iAmountSet = GetDlgItemInt(IDC_EDIT_ORDERINGPRICE);
|
||
m_pDataMgr->m_iMinPriceSet = GetDlgItemInt(IDC_EDIT_ORDERING_TICK_MIN);
|
||
m_pDataMgr->m_iMaxPriceSet = GetDlgItemInt(IDC_EDIT_ORDERING_TICK_MAX);
|
||
m_pDataMgr->m_iSellTick = GetDlgItemInt(IDC_EDIT_SELL_TICK);
|
||
m_pDataMgr->m_iLossCutTick = GetDlgItemInt(IDC_EDIT_LOSS_CUT_TICK);
|
||
m_pDataMgr->m_iTrailingTick = GetDlgItemInt(IDC_EDIT_TRAING_TICK);
|
||
m_pDataMgr->m_iCancelDelay = GetDlgItemInt(IDC_EDIT_CANCEL_DELAY);
|
||
m_pDataMgr->m_bCallOption = (((CButton*)GetDlgItem(IDC_RADIO_CALLOP))->GetCheck() == 1);
|
||
}
|
||
else
|
||
{
|
||
((CButton*)GetDlgItem(IDC_RADIO_BID))->SetCheck(m_pDataMgr->m_bSell);
|
||
SetDlgItemInt(IDC_EDIT_ORDERINGPRICE, m_pDataMgr->m_iAmountSet);
|
||
SetDlgItemInt(IDC_EDIT_ORDERING_TICK_MIN, m_pDataMgr->m_iMinPriceSet);
|
||
SetDlgItemInt(IDC_EDIT_ORDERING_TICK_MAX, m_pDataMgr->m_iMaxPriceSet);
|
||
SetDlgItemInt(IDC_EDIT_SELL_TICK, m_pDataMgr->m_iSellTick);
|
||
SetDlgItemInt(IDC_EDIT_LOSS_CUT_TICK, m_pDataMgr->m_iLossCutTick);
|
||
SetDlgItemInt(IDC_EDIT_TRAING_TICK, m_pDataMgr->m_iTrailingTick);
|
||
SetDlgItemInt(IDC_EDIT_CANCEL_DELAY, m_pDataMgr->m_iCancelDelay);
|
||
((CButton*)GetDlgItem(IDC_RADIO_CALLOP))->SetCheck(m_pDataMgr->m_bCallOption);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
void CCPRobotDlg::OnBnClickedButtonRefreshBalance()
|
||
{
|
||
// TODO: Add your control notification handler code here
|
||
UpdateDataCustom(TRUE);
|
||
|
||
|
||
//ICpTdDibPtr pTd0721 = NULL;
|
||
//pTd0721.CreateInstance(CLSID_CpTd0721F);
|
||
//pTd0721->SetInputValue(0, "117126165");
|
||
////pTd0721->SetInputValue(0, "412120700");
|
||
//pTd0721->SetInputValue(1, "50");
|
||
//pTd0721->SetInputValue(2, "50");
|
||
//pTd0721->SetInputValue(3, "10");
|
||
|
||
//CString Message;
|
||
//do
|
||
//{
|
||
// pTd0721->BlockRequest();
|
||
// m_pDataMgr->m_iBalance = pTd0721->GetHeaderValue(9);
|
||
|
||
// Message.Format("현금주문가능액 : %d", m_pDataMgr->m_iBalance);
|
||
// SetDlgItemText(IDC_STATIC_BALANCE, Message.GetString());
|
||
//} while (pTd0721->Continue);
|
||
|
||
//pTd0721.Release();
|
||
}
|
||
|
||
void CCPRobotDlg::OnBnClickedButtonSearch()
|
||
{
|
||
// TODO: Add your control notification handler code here
|
||
//m_ResultList.
|
||
|
||
|
||
|
||
|
||
|
||
try
|
||
{
|
||
const int iCodeCnt = m_OpCodeList.size();
|
||
for(int i=0; i<iCodeCnt; i++)
|
||
{
|
||
m_pOpJpBid->SetInputValue(0, m_OpCodeList[i].data());
|
||
m_pOpJpBid->SubscribeLatest();
|
||
|
||
TRACE1("Subscribe[%s]\n", m_OpCodeList[i].data());
|
||
|
||
if(m_pOpJpBid->GetDibStatus() != 0)
|
||
{
|
||
CString strErrorMsg;
|
||
strErrorMsg += (LPCTSTR)m_pOpJpBid->GetDibMsg1();
|
||
strErrorMsg += (LPCTSTR)m_pOpJpBid->GetDibMsg2();
|
||
strErrorMsg.TrimRight();
|
||
AfxMessageBox(strErrorMsg);
|
||
}
|
||
}
|
||
}
|
||
catch(_com_error e)
|
||
{
|
||
AfxMessageBox("Subscribe Error");
|
||
}
|
||
}
|
||
|
||
|
||
void CCPRobotDlg::OnBnClickedButtonStartDeal()
|
||
{
|
||
// TODO: Add your control notification handler code here
|
||
}
|
||
|
||
|
||
void CCPRobotDlg::OnBnClickedRadioBid()
|
||
{
|
||
// TODO: Add your control notification handler code here
|
||
m_pDataMgr->m_bSell = (((CButton*)GetDlgItem(IDC_RADIO_BID))->GetCheck() == 1);
|
||
}
|
||
|
||
void CCPRobotDlg::OnBnClickedRadioAsk()
|
||
{
|
||
// TODO: Add your control notification handler code here
|
||
m_pDataMgr->m_bSell = (((CButton*)GetDlgItem(IDC_RADIO_BID))->GetCheck() == 1);
|
||
}
|
||
|
||
void CCPRobotDlg::OnEnChangeEditOrderingprice()
|
||
{
|
||
// TODO: If this is a RICHEDIT control, the control will not
|
||
// send this notification unless you override the CDialog::OnInitDialog()
|
||
// function and call CRichEditCtrl().SetEventMask()
|
||
// with the ENM_CHANGE flag ORed into the mask.
|
||
|
||
// TODO: Add your control notification handler code here
|
||
}
|
||
|
||
void CCPRobotDlg::Received()
|
||
{
|
||
if(m_pOpJpBid->GetDibStatus() != 0)
|
||
{
|
||
CString strErrorMsg;
|
||
strErrorMsg += (LPCTSTR)m_pOpJpBid->GetDibMsg1();
|
||
strErrorMsg += (LPCTSTR)m_pOpJpBid->GetDibMsg2();
|
||
strErrorMsg.TrimRight();
|
||
AfxMessageBox(strErrorMsg);
|
||
return;
|
||
}
|
||
|
||
std::string Code = (_bstr_t)m_pOpJpBid->GetHeaderValue(0);
|
||
float fOffer1Price = m_pOpJpBid->GetHeaderValue(2);
|
||
float fBid1Price = m_pOpJpBid->GetHeaderValue(19);
|
||
|
||
TRACE3("received [%s] %f / %f\n", Code.data(), fOffer1Price, fBid1Price);
|
||
|
||
|
||
//const char* pszCode = (char*)(bstr_t)m_pOpJpBid->GetHeaderValue(0);
|
||
//int iTime = m_pOpJpBid->GetHeaderValue(1);
|
||
//float fOffer1Price = m_pOpJpBid->GetHeaderValue(2);
|
||
//float fOffer1Cnt = m_pOpJpBid->GetHeaderValue(7);
|
||
//float fBid1Price = m_pOpJpBid->GetHeaderValue(19);
|
||
//float fBid1Cnt = m_pOpJpBid->GetHeaderValue(24);
|
||
|
||
//CString Msg;
|
||
//Msg.Format("[%s] (%d) : %d(%d), %d(%d)", pszCode, iTime, fOffer1Price, fOffer1Cnt, fBid1Price, fBid1Cnt);
|
||
//TRACE(Msg.GetString());
|
||
}
|