BOOL CStrategyApp::InitInstance() { // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif CStrategyDlg dlg; m_pMainWnd = &dlg; int nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; }
void CStrategyInfoDlg::OnEditStrategy() { CMainFrame * pMainFrame = gpMainFrame; char szname[64]; memset(szname, 0, sizeof(szname)); if(m_nRSelItem == -1) return; m_listStrategyInfo.GetItemText(m_nRSelItem, 0 ,szname , 64); CString strName = szname; int pos = strName.Find("_"); if (pos <= 0) return; strName = strName.Mid(0, pos); IPInfoMap::iterator iter = pMainFrame->m_IPInfoMap.find(strName.GetBuffer(strName.GetLength())); assert( iter != pMainFrame->m_IPInfoMap.end()); TIPInfo *pIPInfo = iter->second; list<TStrategyInfo*> ::iterator it ; CStrategyDlg strategyDlg; DayTradingStrategy * dts = NULL; for(it = pIPInfo->strategyInfoList.begin(); it != pIPInfo->strategyInfoList.end(); ++it)// list { if(strcmp((*it)->tStrategyUI.sName ,szname) == 0) { CopyStructStrategyUI(&(strategyDlg.m_tStrategyUI), (*it)->tStrategyUI); dts = (*it)->dts; break; } } if (dts == NULL) { TRACE_LOG("找不到%s对应的TwoLegStrategy指针",szname); return; } TwoLegStrategy *ts1 = dts->getStrategyA(); TwoLegStrategy *ts2 = dts->getStrategyB(); strategyDlg.m_buttonstate = 2; //modify strategyDlg.m_strName = strName; strategyDlg.m_strContractOversea = pIPInfo->firstname.c_str(); strategyDlg.m_strContractDomestic = pIPInfo->secondname.c_str(); strategyDlg.m_nVolumeOversea = strategyDlg.m_nVolumeOversea2 = pIPInfo->firstVol; strategyDlg.m_nVolumeDomestic = strategyDlg.m_nVolumeDomestic2 = pIPInfo->secondVol; if(IDOK == strategyDlg.DoModal()) { //TODO add for modify strategy strcpy_s(strategyDlg.m_tStrategyUI.sName, 32, szname); if(strategyDlg.m_nOP == 1) strategyDlg.m_tStrategyUI.sgstate = WORK; else strategyDlg.m_tStrategyUI.sgstate = STOP; strategyDlg.m_tStrategyUI.firstLeg = strategyDlg.m_bRadio; if(strategyDlg.m_tStrategyUI.type == 1 || strategyDlg.m_tStrategyUI.type == 3) { if (strategyDlg.m_bRadio == 1) { ts1->setLegA(new Leg("default", strategyDlg.m_tStrategyUI.tStrategyPrarm[0].overseaBuySell, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].overseaType, strategyDlg.m_tStrategyUI.fistname, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].overseaVolume, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].overseaAdd)); ts1->setLegB(new Leg("default", strategyDlg.m_tStrategyUI.tStrategyPrarm[0].domesticBuySell, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].domesticType, strategyDlg.m_tStrategyUI.secondname, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].domesticVolume, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].domesticAdd)); string sdiffExp = strategyDlg.m_tStrategyUI.fistname + " . ask - " + strategyDlg.m_tStrategyUI.secondname + " . bid"; ts1->setCondition(new Condition(sdiffExp, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].compare, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].diff)); ts1->setHoldingLimit(0, strategyDlg.m_tStrategyUI.maxPostions); ts1->setHoldingOperation(INCREASE); if(strategyDlg.m_tStrategyUI.tStrategyPrarm[0].fishflag == 1) ts1->setFish(true); else ts1->setFish(false); ASSERT(ts1 != NULL) ; if (strategyDlg.m_tStrategyUI.type == 3) { if(ts2 == NULL) ts2 = dts->createStrategyB(); ts2->setLegA(new Leg("default", strategyDlg.m_tStrategyUI.tStrategyPrarm[1].overseaBuySell, strategyDlg.m_tStrategyUI.tStrategyPrarm[1].overseaType, strategyDlg.m_tStrategyUI.fistname, strategyDlg.m_tStrategyUI.tStrategyPrarm[1].overseaVolume, strategyDlg.m_tStrategyUI.tStrategyPrarm[1].overseaAdd)); ts2->setLegB(new Leg("default", strategyDlg.m_tStrategyUI.tStrategyPrarm[1].domesticBuySell, strategyDlg.m_tStrategyUI.tStrategyPrarm[1].domesticType, strategyDlg.m_tStrategyUI.secondname, strategyDlg.m_tStrategyUI.tStrategyPrarm[1].domesticVolume, strategyDlg.m_tStrategyUI.tStrategyPrarm[1].domesticAdd)); string sdiffExp = strategyDlg.m_tStrategyUI.fistname + " . ask - " + strategyDlg.m_tStrategyUI.secondname + " . bid"; ts2->setCondition(new Condition(sdiffExp, strategyDlg.m_tStrategyUI.tStrategyPrarm[1].compare, strategyDlg.m_tStrategyUI.tStrategyPrarm[1].diff)); ts2->setHoldingLimit(0, strategyDlg.m_tStrategyUI.maxPostions); ts2->setHoldingOperation(DECREASE); } else dts->setStrategyBNull(); } if (strategyDlg.m_bRadio == 2) { ts1->setLegB(new Leg("default", strategyDlg.m_tStrategyUI.tStrategyPrarm[0].overseaBuySell, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].overseaType, strategyDlg.m_tStrategyUI.fistname, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].overseaVolume, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].overseaAdd)); ts1->setLegA(new Leg("default", strategyDlg.m_tStrategyUI.tStrategyPrarm[0].domesticBuySell, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].domesticType, strategyDlg.m_tStrategyUI.secondname, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].domesticVolume, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].domesticAdd)); string sdiffExp = strategyDlg.m_tStrategyUI.fistname + " . ask - " + strategyDlg.m_tStrategyUI.secondname + " . bid"; ts1->setCondition(new Condition(sdiffExp, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].compare, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].diff)); ts1->setHoldingLimit(0, strategyDlg.m_tStrategyUI.maxPostions); ts1->setHoldingOperation(INCREASE); if(strategyDlg.m_tStrategyUI.tStrategyPrarm[0].fishflag == 1) ts1->setFish(true); else ts1->setFish(false); if (strategyDlg.m_tStrategyUI.type == 3) { if(ts2 == NULL) ts2 = dts->createStrategyB(); ts2->setLegB(new Leg("default", strategyDlg.m_tStrategyUI.tStrategyPrarm[1].overseaBuySell, strategyDlg.m_tStrategyUI.tStrategyPrarm[1].overseaType, strategyDlg.m_tStrategyUI.fistname, strategyDlg.m_tStrategyUI.tStrategyPrarm[1].overseaVolume, strategyDlg.m_tStrategyUI.tStrategyPrarm[1].overseaAdd)); ts2->setLegA(new Leg("default", strategyDlg.m_tStrategyUI.tStrategyPrarm[1].domesticBuySell, strategyDlg.m_tStrategyUI.tStrategyPrarm[1].domesticType, strategyDlg.m_tStrategyUI.secondname, strategyDlg.m_tStrategyUI.tStrategyPrarm[1].domesticVolume, strategyDlg.m_tStrategyUI.tStrategyPrarm[1].domesticAdd)); string sdiffExp = strategyDlg.m_tStrategyUI.fistname + " . ask - " + strategyDlg.m_tStrategyUI.secondname + " . bid"; ts2->setCondition(new Condition(sdiffExp, strategyDlg.m_tStrategyUI.tStrategyPrarm[1].compare, strategyDlg.m_tStrategyUI.tStrategyPrarm[1].diff)); ts2->setHoldingLimit(0, strategyDlg.m_tStrategyUI.maxPostions); ts2->setHoldingOperation(DECREASE); if(strategyDlg.m_tStrategyUI.tStrategyPrarm[1].fishflag == 1) ts2->setFish(true); else ts2->setFish(false); } else{ dts->setStrategyBNull(); } } } if(strategyDlg.m_tStrategyUI.type == 2) { if (strategyDlg.m_bRadio == 1) { ts1->setLegA(new Leg("default", strategyDlg.m_tStrategyUI.tStrategyPrarm[0].overseaBuySell, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].overseaType, strategyDlg.m_tStrategyUI.fistname, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].overseaVolume, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].overseaAdd)); ts1->setLegB(new Leg("default", strategyDlg.m_tStrategyUI.tStrategyPrarm[0].domesticBuySell, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].domesticType, strategyDlg.m_tStrategyUI.secondname, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].domesticVolume, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].domesticAdd)); } if (strategyDlg.m_bRadio == 2) { ts1->setLegB(new Leg("default", strategyDlg.m_tStrategyUI.tStrategyPrarm[0].overseaBuySell, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].overseaType, strategyDlg.m_tStrategyUI.fistname, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].overseaVolume, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].overseaAdd)); ts1->setLegA(new Leg("default", strategyDlg.m_tStrategyUI.tStrategyPrarm[0].domesticBuySell, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].domesticType, strategyDlg.m_tStrategyUI.secondname, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].domesticVolume, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].domesticAdd)); } string sdiffExp = strategyDlg.m_tStrategyUI.fistname + " . ask - " + strategyDlg.m_tStrategyUI.secondname + " . bid"; ts1->setCondition(new Condition(sdiffExp, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].compare, strategyDlg.m_tStrategyUI.tStrategyPrarm[0].diff)); ts1->setHoldingLimit(0, strategyDlg.m_tStrategyUI.maxPostions); ts1->setHoldingOperation(INCREASE); if(strategyDlg.m_tStrategyUI.tStrategyPrarm[0].fishflag == 1) ts1->setFish(true); else ts1->setFish(false); } dts->save(); TStrategyInfo *ptStrategyInfo = FindSGstatemap(szname); ptStrategyInfo->dts = dts; strategyDlg.m_tStrategyUI.sStrategy = dts->toDesc();//dts->toString(); CopyStructStrategyUI(&(ptStrategyInfo->tStrategyUI), (strategyDlg.m_tStrategyUI)); if(strategyDlg.m_nOP == 1) { if (dts != NULL) dts->start(); }else{ if (dts != NULL) dts->stop(); } list<TStrategyInfo*> ::iterator it ; m_listStrategyInfo.DeleteAllItems(); for(it = pIPInfo->strategyInfoList.begin(); it != pIPInfo->strategyInfoList.end(); ++it)// list { int count = m_listStrategyInfo.GetItemCount(); int index = m_listStrategyInfo.InsertItem(count, (*it)->tStrategyUI.sName ); m_listStrategyInfo.SetItem(index,2,LVIF_TEXT,(*it)->tStrategyUI.sStrategy.c_str(), 0, 0, 0,0); if((*it)->tStrategyUI.sgstate == WORK) m_listStrategyInfo.SetItem(index,1,LVIF_TEXT,"已启动", 0, 0, 0,0); //pMainFrame->m_pStrategyInfoDlg->m_listStrategyInfo.SetItemTextColor(1,index,RGB(255,0,0)); else m_listStrategyInfo.SetItem(index,1,LVIF_TEXT,"已停止", 0, 0, 0,0); //pMainFrame->m_pStrategyInfoDlg->m_listStrategyInfo.SetItemTextColor(1,index,RGB(255,255,255)); } m_listStrategyInfo.SetSelectionMark(m_nRSelItem); m_listStrategyInfo.SetItemState(m_nRSelItem, LVIS_SELECTED, LVIS_SELECTED); } return; }