// 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_pOpCode = NULL; //m_pOpMst = NULL; m_pOpJpBid = NULL; m_pOpCurOnly = NULL; m_pTrader = 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); //g_pTdUtil.CreateInstance(CLSID_CpTdUtil); //try { // HRESULT hr = g_pTdUtil.CreateInstance(__uuidof(CpTdUtil)); // if (FAILED(hr)) // _com_raise_error(hr); // g_pTdUtil->TradeInit(0); // variant_t vArray = g_pTdUtil->GetAccountNumber(); // //CComSafeArray sa; // //sa.Attach(vArray.Detach().parray); // //for (LONG nlb = sa.GetLowerBound(), nub = sa.GetUpperBound(); nlb <= nub; nlb++) // //{ // // vItem = sa.GetAt(nlb); // // _tprintf(_T("%s\n"), (LPCTSTR)(bstr_t)vItem); // //} //} //catch (_com_error e) //{ // AfxMessageBox(e.ErrorMessage()); //} //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_pOpCode.CreateInstance(CLSID_CpOptionCode); //m_pOpMst.CreateInstance(CLSID_OptionMst); m_pOpJpBid.CreateInstance(CLSID_OptionJpBid); m_pOpCurOnly.CreateInstance(CLSID_OptionCurOnly); m_EventHandler.DispEventAdvise(m_pOpCurOnly); m_EventHandler.SetIEventHandler(this); m_pTrader = new CTrader(); return 0; } void CCPRobotDlg::OnDestroy() { CDialog::OnDestroy(); // TODO: Add your message handler code here m_pOpCurOnly.Release(); m_pOpJpBid.Release(); //m_pOpMst.Release(); m_pOpCode.Release(); SAFE_DELETE(m_pDataMgr); SAFE_DELETE(m_pTrader); m_EventHandler.DispEventUnadvise(m_pOpCurOnly); } BOOL CCPRobotDlg::DestroyWindow() { // TODO: Add your specialized code here and/or call the base class g_pTdUtil.Release(); CoUninitialize(); return CDialog::DestroyWindow(); } // 대화 상자에 최소화 단추를 추가할 경우 아이콘을 그리려면 // 아래 코드가 필요합니다. 문서/뷰 모델을 사용하는 MFC 응용 프로그램의 경우에는 // 프레임워크에서 이 작업을 자동으로 수행합니다. void CCPRobotDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // 그리기를 위한 디바이스 컨텍스트 SendMessage(WM_ICONERASEBKGND, reinterpret_cast(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(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. short iCodeCnt = m_pOpCode->GetCount(); //CString Code; float afSellingPrice[5] = {0, }; float afBuyingPrice[5] = {0, }; CString Msg; std::string Code; m_PutDataList.clear(); OPTION_DATA NewData; for(int i=0; iGetData(0, i); if(Code[0] == '2') m_pDataMgr->m_CallCodeList.push_back(Code); else if(Code[0] == '3') m_pDataMgr->m_PutCodeList.push_back(Code); else TRACE1("알수 없는 코드 : ", Code); NewData.m_Code = Code; //ISysDibPtr pOpCurOnly; //pOpCurOnly.CreateInstance(CLSID_OptionCurOnly); if(i == 0) { m_pOpCurOnly->SetInputValue(0, Code.data()); m_pOpCurOnly->SubscribeLatest(); if(m_pOpCurOnly->GetDibStatus() != 0) { CString strErrorMsg; strErrorMsg += (LPCTSTR)m_pOpCurOnly->GetDibMsg1(); strErrorMsg += (LPCTSTR)m_pOpCurOnly->GetDibMsg2(); strErrorMsg.TrimRight(); AfxMessageBox(strErrorMsg); } //m_pOpCurOnly-> afSellingPrice[0] = m_pOpCurOnly->GetHeaderValue(17); afBuyingPrice[0] = m_pOpCurOnly->GetHeaderValue(18); //m_pOpJpBid->SetInputValue(0, Code.data()); //m_pOpJpBid->Subscribe(); //if(m_pOpJpBid->GetDibStatus() != 0) //{ // CString strErrorMsg; // strErrorMsg += (LPCTSTR)m_pOpJpBid->GetDibMsg1(); // strErrorMsg += (LPCTSTR)m_pOpJpBid->GetDibMsg2(); // strErrorMsg.TrimRight(); // AfxMessageBox(strErrorMsg); //} } //m_pOpMst->SetInputValue(0, (LPCSTR)Code); //m_pOpMst->BlockRequest(); //afSellingPrice[0] = m_pOpMst->GetHeaderValue(58); //afBuyingPrice[0] = m_pOpMst->GetHeaderValue(59); Msg.Format("%s/%d/%d", Code.data(), afSellingPrice[0], afBuyingPrice[0]); m_ResultList.AddString(Msg); } } 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() { 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()); }