/// <summary> /// 埋单提交(选中) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MaiDanHandle(object sender, RoutedEventArgs e) { List <TradeOrderData> selectedOrder = new List <TradeOrderData>(); foreach (var item in dgMaiConditionOrder.SelectedItems) { selectedOrder.Add((TradeOrderData)item); } foreach (var item in selectedOrder) { TradeOrderData o = (TradeOrderData)item; if (o != null) { //对o撤单 if (IsMaiDanHandlable(o)) { TradeDataClient.GetClientInstance().RequestOrder(o.InvestorID, BACKENDTYPE.CTP, new RequestContent("NewOrderSingle", new List <object>() { CodeSetManager.GetContractInfo(o.Code, CodeSetManager.ExNameToCtp(o.Exchange)), SIDETYPE.BUY, PosEffect.Close, 0, 0, 0, o.OrderID, CommonUtil.GetHedgeType(o.Hedge) })); } } } }
void grdRealData_SelectionChanged(object sender, SelectionChangedEventArgs e) { //将不需要的行情去除掉 if (dgRealData.SelectedItem != null) { DisplayRealData selectedRecord = dgRealData.SelectedItem as DisplayRealData; LvQuotesPanel.lblCode.Content = selectedRecord.Code; //RealData selectedData = new RealData(); string tempKey = selectedRecord.Code + "_" + CodeSetManager.ExNameToCtp(selectedRecord.Market); if (_BackupCodeDic.ContainsKey(tempKey)) { LvQuotesPanel.SetLevelsQuotesByRealData(_BackupCodeDic[tempKey]); } //List<DisplayRealData> uselessDatas = new List<DisplayRealData>(); //foreach (var item in mainWindow.RealDataCollection) //{ // if (!HQRealData.commObj.RequestingCodes.Contains(item.Code) // && item.Code != mainWindow.uscNewOrderPanel.txtCode.Text.Trim() // && item != selectedRecord) // { // uselessDatas.Add(item); // } //} //foreach (var item in uselessDatas) //{ // mainWindow.RealDataCollection.Remove(item); //} } }
private void txtCode_TextChanged(object sender, TextChangedEventArgs e) { //Util.Log("txtCode_TextChanged starts."); txtCode.SelectionStart = txtCode.Text.Length; int firstNumberIndiex = txtCode.Text.IndexOfAny("0123456789".ToCharArray()); string SpeciesName = txtCode.Text; string SpeciesDate = string.Empty; if (firstNumberIndiex >= 0) { SpeciesName = txtCode.Text.Substring(0, firstNumberIndiex); SpeciesDate = txtCode.Text.Substring(firstNumberIndiex, txtCode.Text.Length - firstNumberIndiex); //} //用户可能不区分大小写输入合约 string validSpeciesName = CodeSetManager.GetValidSpeciesName(SpeciesName); if (validSpeciesName != null && validSpeciesName != SpeciesName) { txtCode.Text = validSpeciesName + SpeciesDate; return; } } if (CommonUtil.IsValidCode(txtCode.Text.Trim())) { Contract newCode = CodeSetManager.GetContractInfo(txtCode.Text.Trim()); txtCodeName.Text = newCode.Name; //iudNum.Value = DefaultCodeHandInstance.GetDefaultCodeHand(txtCode.Text); } }
public void UpdateProperties(RealData realData) { if (realData.CodeInfo.Code == this.Code) { this.ChiCangLiang = realData.Position; this.StBuyCount = realData.BidHand[0]; this.StBuyPrice = realData.BidPrice[0]; this.StSellCount = realData.AskHand[0]; this.StSellPrice = realData.AskPrice[0]; this.DownStopPrice = realData.LowerLimitPrice; this.I64Sum = (UInt64)realData.Sum; //this.ICurrentSum = realData.ICurrentSum ; this.ISettlementPrice = realData.SettlmentPrice; this.PrevSettleMent = realData.PrevSettlementPrice; this.UpStopPrice = realData.UpperLimitPrice; this.CurrentHand = realData.Hand; //this.I64Outside = realData.I64Outside; this.IClose = realData.ClosePrice; //this.IDealNumber = realData.IDealNumber; this.IMaxPrice = realData.MaxPrice; this.IMinPrice = realData.MinPrice; this.INewPrice = realData.NewPrice; this.Open = realData.OpenPrice; //this.NTime = realData.NTime; this.PrevClose = realData.PrevClose; //this.UsUpdateNumber = realData.UsUpdateNumber; this.Volumn = realData.Volumn; this.Market = CodeSetManager.CtpToExName(realData.CodeInfo.ExchCode); this.PreChicang = realData.PrevPosition; this.PrevClose = realData.PrevClose; this.UpdateTime = realData.UpdateTime; } }
public Int32 ReadCodeSet() { Int32 Result = 0; CodeSetManager CodeSetManager = new CodeSetManager(); Result = CodeSetManager.ReadCodeSet(); return(Result); }
public Int32 AddCodeSet(string Code, string ShortValue, string LongValue, DateTime EffectiveFromDate, DateTime EffectiveToDate, string CategoryCode) { Int32 Result = 0; CodeSetManager CodeSetManager = new CodeSetManager(); Result = CodeSetManager.AddCodeSet(Code, ShortValue, LongValue, EffectiveFromDate, EffectiveToDate, CategoryCode); return(Result); }
public void AddSingleRealData(string strCode) { if (_CommObj.RequestingCodes.Contains(strCode)) { return; } Contract searchCodeInfo = CodeSetManager.GetContractInfo(strCode); this.AddContract(new Contract[] { searchCodeInfo }); this.GetRealData(); this.Request(); }
public void RefreshAutoPushMarketData() { foreach (string code in _CommObj.RequestingCodes) { Contract item = CodeSetManager.GetContractInfo(code); if (item != null) { _CodesList.Add(item); } } _CommObj.RequestingCodes.Clear(); Request(); }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value == null) { return(""); } string code = value.ToString(); if (CodeSetManager.GetContractInfo(code) != null) { return(CodeSetManager.GetContractInfo(code).Name); } return(""); }
/// <summary> /// 根据品种名得到其对应的合约 /// </summary> /// <param name="species"></param> private List <string> GetContractBySpeciesName(string species, out string ZLCode) { //先得到中文名 string chineseName = CodeSetManager.GetSpeciChineseName(species); string otherCode = ""; if (speciesNameDict.ContainsKey(chineseName)) { SpeciesItem si = speciesNameDict[chineseName]; if (species.Equals(si.code)) { otherCode = si.otherCode; } else if (species.Equals(si.otherCode)) { otherCode = si.code;; } } List <Contract> codeInfos = CodeSetManager.GetCodeListBySpecies(species); List <Contract> codeInfo2 = CodeSetManager.GetCodeListBySpecies(otherCode); if (codeInfo2 != null) { codeInfos.AddRange(codeInfo2); } //List<string> zhuliCodes = HQService.HQServ.GetZhuliCode(); ZLCode = ""; //foreach (String codeInfo in zhuliCodes) //{ // string name = GetValidSpeciesName(codeInfo); // if (name.Equals(species)) // { // ZLCode = codeInfo; // break; // } //} List <string> ret = new List <string>(); if (codeInfos != null) { foreach (Contract cif in codeInfos) { ret.Add(cif.Code); } } return(ret); }
private void bt_add_Click(object sender, RoutedEventArgs e) { if (CommonUtil.IsValidCode(txtCode.Text)) { Contract orderCodeIndo = CodeSetManager.GetContractInfo(txtCode.Text); if (!_ChooseSet.Contains(orderCodeIndo)) { _ChooseSet.Add(orderCodeIndo); } txtCode.Text = string.Empty; return; } AddContractFromChooseSet(); }
public bool UpdateRealProperties(DisplayRealData displayData) { try { this.CodeInfo.Code = displayData.Code; this.CodeInfo.Name = displayData.Name; this.Position = displayData.ChiCangLiang; this.BidHand[0] = displayData.StBuyCount; this.BidPrice[0] = displayData.StBuyPrice; this.AskHand[0] = displayData.StSellCount; this.AskPrice[0] = displayData.StSellPrice; this.LowerLimitPrice = displayData.DownStopPrice; this.Sum = displayData.I64Sum; this.SettlmentPrice = displayData.ISettlementPrice; this.PrevSettlementPrice = displayData.PrevSettleMent; this.UpperLimitPrice = displayData.UpStopPrice; this.Hand = displayData.CurrentHand; this.ClosePrice = displayData.IClose; this.MaxPrice = displayData.IMaxPrice; this.MinPrice = displayData.IMinPrice; this.NewPrice = displayData.INewPrice; this.OpenPrice = displayData.Open; this.PrevClose = displayData.PrevClose; this.Volumn = displayData.Volumn; this.CodeInfo.ExchCode = CodeSetManager.ExNameToCtp(displayData.Market); this.PrevPosition = displayData.PreChicang; this.PrevClose = displayData.PrevClose; this.UpdateTime = displayData.UpdateTime; return(true); } catch (Exception ex) { Util.Log_Error("exception: " + ex.Message); Util.Log_Error("exception: " + ex.StackTrace); return(false); } }
public RealData GetOptRealData_C() { RealData realData = new RealData(); realData.CodeInfo.Code = this.Code_C; realData.CodeInfo.Name = this.Name; realData.Position = this.ChiCangLiang_C; realData.BidHand[0] = this.StBuyCount_C; realData.BidPrice[0] = this.StBuyPrice_C; realData.AskHand[0] = this.StSellCount_C; realData.AskPrice[0] = this.StSellPrice_C; realData.LowerLimitPrice = this.DownStopPrice_C; //realData.HYCS = this.HYCS; realData.Sum = this.I64Sum_C; //realData.ICurrentSum = this.ICurrentSu_C; realData.SettlmentPrice = this.ISettlementPrice_C; realData.PrevSettlementPrice = this.PrevSettleMent_C; realData.UpperLimitPrice = this.UpStopPrice_C; realData.CodeInfo.Code = this.Code_C;//?? realData.Hand = this.CurrentHand_C; //realData.I64Outside = this.I64Outside_C; realData.ClosePrice = this.IClose_C; //realData.IDealNumber = this.IDealNumber_C; realData.MaxPrice = this.IMaxPrice_C; realData.MinPrice = this.IMinPrice_C; realData.NewPrice = this.INewPrice_C; //Todo //realData.LastINewPrice = this.LastINewPrice_C + r.Next(-2, 1); //realData.IsFirstData = this.IsFirstData; //realData.LogMessage = this.LogMessage; //realData.Name = this.Name; realData.OpenPrice = this.Open_C; //realData.NTime = this.NTime_C; realData.PrevClose = this.PrevClose_C; //realData.UiTime = this.UiTime; //realData.UsUpdateNumber = this.UsUpdateNumber_C; realData.Volumn = this.Volumn_C; realData.CodeInfo.ExchCode = CodeSetManager.ExNameToCtp(this.Market); realData.PrevPosition = this.PreChicang_C; realData.PrevClose = this.PrevClose_C; realData.UpdateTime = this.UpdateTime_C; return(realData); }
public static void SetRealDataToContainer(RealData realData) { Contract codeKey = CodeSetManager.GetContractInfo(realData.CodeInfo.Code, realData.CodeInfo.ExchCode); if (codeKey != null) { if (RealDataContainer.ContainsKey(codeKey)) { RealDataContainer[codeKey] = realData; } else { RealDataContainer.Add(codeKey, realData); } } else { Util.Log("Warning!: codeKey is NULL! "); } }
private void txtCode_TextChanged(object sender, TextChangedEventArgs e) { txtCode.SelectionStart = txtCode.Text.Length; int firstNumberIndiex = txtCode.Text.IndexOfAny("0123456789".ToCharArray()); string SpeciesName = txtCode.Text; string SpeciesDate = string.Empty; if (firstNumberIndiex >= 0) { SpeciesName = txtCode.Text.Substring(0, firstNumberIndiex); SpeciesDate = txtCode.Text.Substring(firstNumberIndiex, txtCode.Text.Length - firstNumberIndiex); //用户可能不区分大小写输入合约 string validSpeciesName = CodeSetManager.GetValidSpeciesName(SpeciesName); if (validSpeciesName != null && validSpeciesName != SpeciesName) { txtCode.Text = validSpeciesName + SpeciesDate; return; } } }
public void SetHandCount(string buySell) { tbHandCount.Text = "0"; //if (rbPingcang.IsChecked == true) //{ // foreach (var item in _MainWindow.PositionCollection_Total) // { // if (txtCode.Text == item.Code && item.BuySell.Contains(buySell)) // { // if (CodeSetManager.IsCloseTodaySupport(item.Code)) // { // tbHandCount.Text = item.YesterdayPosition.ToString(); //(item.YesterdayPosition - item.FreezeCount).ToString(); // } // else // { // tbHandCount.Text = item.TotalPosition.ToString(); //(item.TotalPosition - item.FreezeCount).ToString(); // } // } // } //} //else if (rbPingjin.IsChecked == true) { foreach (var item in _MainWindow.PositionCollection_Total) { if (txtCode.Text == item.Code && item.BuySell.Contains(buySell)) { if (CodeSetManager.IsCloseTodaySupport(item.Code)) { tbHandCount.Text = item.TodayPosition.ToString(); //(item.TodayPosition - item.FreezeCount).ToString(); } else { tbHandCount.Text = item.TotalPosition.ToString(); //(item.TotalPosition - item.FreezeCount).ToString(); } } } } }
public DisplayRealData UpdateDisplayProperties(RealData realData) { DisplayRealData displayData = new DisplayRealData(); try { displayData.Code = realData.CodeInfo.Code; if (realData.CodeInfo.ProductType != null && realData.CodeInfo.ProductType == "Combination" || displayData.Code.Contains("&")) { if (realData.CodeInfo.Code.Contains(" ")) { string[] tempType = realData.CodeInfo.Code.Split(' '); string[] tempGroup = tempType[1].Split('&'); displayData.Code1 = tempGroup[0]; displayData.Code2 = tempGroup[1]; } else { string[] tempGroup = realData.CodeInfo.Code.Split('&'); displayData.Code1 = tempGroup[0]; displayData.Code2 = tempGroup[1]; } } displayData.Name = realData.CodeInfo.Name; displayData.ChiCangLiang = realData.Position; displayData.StBuyCount = realData.BidHand[0]; displayData.StBuyPrice = realData.BidPrice[0]; displayData.StSellCount = realData.AskHand[0]; displayData.StSellPrice = realData.AskPrice[0]; displayData.DownStopPrice = realData.LowerLimitPrice; displayData.I64Sum = (UInt64)realData.Sum; //this.ICurrentSum = realData.ICurrentSum ; displayData.ISettlementPrice = realData.SettlmentPrice; displayData.PrevSettleMent = realData.PrevSettlementPrice; displayData.UpStopPrice = realData.UpperLimitPrice; displayData.CurrentHand = realData.Hand; //this.I64Outside = realData.I64Outside; displayData.IClose = realData.ClosePrice; //this.IDealNumber = realData.IDealNumber; displayData.IMaxPrice = realData.MaxPrice; displayData.IMinPrice = realData.MinPrice; displayData.INewPrice = realData.NewPrice; displayData.Open = realData.OpenPrice; //this.NTime = realData.NTime; displayData.PrevClose = realData.PrevClose; //this.UsUpdateNumber = realData.UsUpdateNumber; displayData.Volumn = realData.Volumn; displayData.Market = CodeSetManager.CtpToExName(realData.CodeInfo.ExchCode); displayData.PreChicang = realData.PrevPosition; displayData.PrevClose = realData.PrevClose; displayData.UpdateTime = realData.UpdateTime; } catch (Exception ex) { Util.Log_Error("exception: " + ex.Message); Util.Log_Error("exception: " + ex.StackTrace); } return(displayData); }
/// <summary> /// 得到所有的品种 /// </summary> /// <returns></returns> private List <SpeciesItem> GetAllSpecies() { List <SpeciesItem> ret = new List <SpeciesItem>(); SpeciesItem si = null; List <Species> speciesList = null; speciesList = CodeSetManager.GetAllInnerSpecies();// CodeSet.GetListSpeciesByMarket(HSMarketDataType.FUTURES_MARKET | HSMarketDataType.CFFEX_BOURSE); //foreach (Species s in speciesList) //{ // si = null; // string chnName=CodeGen.CodeSet.GetSpeciChineseName(s.speciesName); // if (speciesNameDict.ContainsKey(chnName)) // { // si = speciesNameDict[chnName]; // si.otherCode = s.speciesName; // } // else // { // si = new SpeciesItem(); // si.code = s.speciesName; // si.name = chnName; // ret.Add(si); // speciesNameDict[chnName] = si; // } //} //speciesList=CodeSet.GetListSpeciesByMarket(HSMarketDataType.FUTURES_MARKET | HSMarketDataType.SHANGHAI_BOURSE); //foreach (Species s in speciesList) //{ // si = null; // string chnName = CodeGen.CodeSet.GetSpeciChineseName(s.speciesName); // if (speciesNameDict.ContainsKey(chnName)) // { // si = speciesNameDict[chnName]; // si.otherCode = s.speciesName; // } // else // { // si = new SpeciesItem(); // si.name = chnName; // si.code = s.speciesName; // ret.Add(si); // speciesNameDict[chnName] = si; // } //} //speciesList = CodeSet.GetListSpeciesByMarket(HSMarketDataType.FUTURES_MARKET | HSMarketDataType.ZHENGZHOU_BOURSE); //foreach (Species s in speciesList) //{ // si = null; // string chnName = CodeGen.CodeSet.GetSpeciChineseName(s.speciesName); // if (speciesNameDict.ContainsKey(chnName)) // { // si = speciesNameDict[chnName]; // si.otherCode = s.speciesName; // } // else // { // si = new SpeciesItem(); // si.code = s.speciesName; // si.name = chnName; // ret.Add(si); // speciesNameDict[chnName] = si; // } //} //speciesList = CodeSet.GetListSpeciesByMarket(HSMarketDataType.FUTURES_MARKET | HSMarketDataType.DALIAN_BOURSE); foreach (Species s in speciesList) { //Todo: //if (s.SpeciesCode.Contains("SP") || s.SpeciesCode.Contains("efp") || s.SpeciesCode.Contains("_o")) if (s.SpeciesCode.Contains("efp") || s.SpeciesCode.StartsWith("sc") || s.ProductType == "Combination" || s.ProductType.Contains("Option") || s.SpeciesCode == "CVX") { continue; } si = null; string chnName = CodeSetManager.GetSpeciChineseName(s.SpeciesCode); if (speciesNameDict.ContainsKey(chnName)) { si = speciesNameDict[chnName]; si.otherCode = s.SpeciesCode; } else { si = new SpeciesItem(); si.code = s.SpeciesCode; si.name = chnName; ret.Add(si); speciesNameDict[chnName] = si; } } return(ret); }
private void RequestRealData(BackgroundDataServer hqRealData) { ObservableCollection <UserCodeSet> lstUserCodeSet = UserCodeSetInstance.GetUserCodeSetList(); //先删除合约 bool bChanged = false; _DelCodeList.Clear(); foreach (Contract temp in hqRealData.m_oldCodeArray) { if (!hqRealData.m_codeArray.Contains(temp)) { _DelCodeList.Add(temp); } } if (_DelCodeList.Count > 0) { bChanged = true; hqRealData.AddContract(_DelCodeList.ToArray()); hqRealData.UnRequest(); try { RealData tempData = null; foreach (Contract temp in _DelCodeList) { string tempKey = temp.Code + "_" + temp.ExchCode; if (_BackupCodeDic.ContainsKey(tempKey)) { tempData = _BackupCodeDic[tempKey]; if (tempData != null) { DisplayRealData tempDisplayData = UpdateDisplayProperties(tempData); if (hqRealData == HQRealData) { //Util.Log("<<:" + tempData.ToString()); _MainWindow.RealDataCollection.Remove(tempDisplayData); } else if (hqRealData == GroupHQRealData) { _MainWindow.RealDataArbitrageCollection.Remove(tempDisplayData); } _BackupCodeDic.Remove(tempKey); } } } } catch (Exception ex) { Util.Log_Error("exception: " + ex.Message); Util.Log_Error("exception: " + ex.StackTrace); } } //在请求新增的合约 _AddCodeList.Clear(); foreach (Contract temp in hqRealData.m_codeArray) { if (!hqRealData.m_oldCodeArray.Contains(temp)) { _AddCodeList.Add(temp); } } if (_AddCodeList.Count > 0) { foreach (Contract temp in _AddCodeList) { if (temp == null) { continue; } string tempKey = temp.Code + "_" + temp.ExchCode; if (_BackupCodeDic.ContainsKey(tempKey) == false) { RealData tempData2 = new RealData(); //Contract tempContract = CodeSetManager.GetContractInfo(temp.Code); tempData2.CodeInfo = CodeSetManager.GetContractInfo(temp.Code, temp.ExchCode); if (tempData2.CodeInfo == null) { tempData2.CodeInfo = new Contract(temp.Code); } //tempData2.Name = tempContract.Name; //decimal fluct = 0.00M; //CodeSetManager.GetHycsAndFluct(tempData2.codeInfo.Code, out (double)tempData2.m_hycs, out fluct); _BackupCodeDic.Add(tempKey, tempData2); } } bChanged = true; hqRealData.AddContract(_AddCodeList.ToArray()); hqRealData.GetRealData(); hqRealData.Request(); } DeepCopyInfo(hqRealData.m_codeArray, hqRealData.m_oldCodeArray); if (bChanged == false) { RealData tempData2 = null; _MainWindow.RealDataCollection.Clear(); _MainWindow.RealDataArbitrageCollection.Clear(); foreach (Contract temp in hqRealData.m_oldCodeArray) { //Util.Log(this.defaultButton.Content + " 添加内容 Old-----"); string tempKey = temp.Code + "_" + temp.ExchCode; if (_BackupCodeDic.ContainsKey(tempKey)) { tempData2 = _BackupCodeDic[tempKey]; if (tempData2 != null) { DisplayRealData tempDisplayData = UpdateDisplayProperties(tempData2); if (hqRealData == HQRealData) { //Util.Log(">>:" + tempData2.ToString()); _MainWindow.RealDataCollection.Add(tempDisplayData); } else if (hqRealData == GroupHQRealData) { if (tempData2.CodeInfo.Code.Contains("&")) { //string[] tempType = tempData2.codeInfo.Code.Split(' '); //string[] tempGroup = tempType[1].Split('&'); //tempData2.Code = tempGroup[0]; //tempData2.Code2 = tempGroup[1]; } _MainWindow.RealDataArbitrageCollection.Add(UpdateDisplayProperties(tempData2)); } } } } } else { RealData tempData2 = null; _MainWindow.RealDataCollection.Clear(); _MainWindow.RealDataArbitrageCollection.Clear(); if (hqRealData == HQRealData) { //Util.Log(this.defaultButton.Content + " 添加内容-----"); foreach (Contract temp in _CodeArray) { if (temp != null) { string tempKey = temp.Code + "_" + temp.ExchCode; if (_BackupCodeDic.ContainsKey(tempKey) == false) { tempData2 = new RealData(); //Contract tempContract = CodeSetManager.GetContractInfo(temp.Code); tempData2.CodeInfo = CodeSetManager.GetContractInfo(temp.Code, temp.ExchCode); if (tempData2.CodeInfo == null) { tempData2.CodeInfo = new Contract(temp.Code); } //tempData2.Name = tempContract.Name; //double fluct = 0; //CodeSetManager.GetHycsAndFluct(tempData2.Code, out tempData2.m_hycs, out fluct); _BackupCodeDic.Add(tempKey, tempData2); } else { tempData2 = _BackupCodeDic[tempKey]; } DisplayRealData tempDisplayData = UpdateDisplayProperties(tempData2); //Util.Log(">>:"+tempData2.ToString()); _MainWindow.RealDataCollection.Add(tempDisplayData); //Util.Log("mainWindow.RealDataCollection.count=" + mainWindow.RealDataCollection.Count); } } } else if (hqRealData == GroupHQRealData) { foreach (Contract temp in _GroupCodeArray) { if (temp != null) { string tempKey = temp.Code + "_" + temp.ExchCode; if (_BackupCodeDic.ContainsKey(tempKey) == false) { tempData2 = new RealData(); tempData2.CodeInfo = CodeSetManager.GetContractInfo(temp.Code, temp.ExchCode); if (tempData2.CodeInfo == null) { tempData2.CodeInfo = new Contract(tempKey); } //decimal fluct = 0; //CodeSetManager.GetHycsAndFluct(temp.Code, out tempData2.m_hycs, out fluct); _BackupCodeDic.Add(tempKey, tempData2); } else { tempData2 = _BackupCodeDic[tempKey]; } if (tempData2.CodeInfo.Code.Contains("&")) { //string[] tempType = tempData2.Code.Split(' '); //string[] tempGroup = tempType[1].Split('&'); //tempData2.Code1 = tempGroup[0]; //tempData2.Code2 = tempGroup[1]; } _MainWindow.RealDataArbitrageCollection.Add(UpdateDisplayProperties(tempData2)); } } } } hqRealData.UpdateRealDataList(); }
public CodeSetController(CodeSetManager manager) { //this.config = config; codesetManager = manager; }
/// <summary> /// 从配置文件中读取合约组信息 /// </summary> /// <returns></returns> public static ObservableCollection <UserCodeSet> GetUserCodeSetList() { if (_UserCodeSetList == null) { if (File.Exists(ConfigFilePath)) { try { //先从配置文件中读取合约组信息 _UserCodeSetList = (ObservableCollection <UserCodeSet>)(CommonUtil.RecoverObjectFromFile(typeof(ObservableCollection <UserCodeSet>), ConfigFilePath)); } catch (System.Exception ex) { Util.Log(ex.ToString()); } } if (_UserCodeSetList == null) { _UserCodeSetList = new ObservableCollection <UserCodeSet>(); UserCodeSet defaultSet = new UserCodeSet(); defaultSet.Name = "普通行情"; defaultSet.Id = Guid.NewGuid().ToString(); defaultSet.IsDefault = true; defaultSet.FileName = LASTCODEINFOPATH; defaultSet.IsArbitrage = false; _UserCodeSetList.Add(defaultSet); UserCodeSet GroupSet = new UserCodeSet(); GroupSet.Name = "组合行情"; GroupSet.Id = Guid.NewGuid().ToString(); GroupSet.IsDefault = true; GroupSet.FileName = LASTGROUPCODEINFOPATH; GroupSet.IsArbitrage = true; _UserCodeSetList.Add(GroupSet); } //再读取各合约组的合约情况 foreach (var item in _UserCodeSetList) { if (File.Exists(LASTCODEINFODIR + item.FileName)) { ObservableCollection <Contract> userCodes = new ObservableCollection <Contract>(); try { FileStream fs2 = new FileStream(LASTCODEINFODIR + item.FileName, FileMode.OpenOrCreate); BinaryFormatter formatter = new BinaryFormatter(); ObservableCollection <Contract> temp = (ObservableCollection <Contract>)formatter.Deserialize(fs2); foreach (Contract codeInfo in temp) { if (codeInfo != null && !CodeSetManager.IsOutOfDate(codeInfo.Code)) { userCodes.Add(codeInfo); } } fs2.Close(); } catch (System.Exception ex) { Util.Log_Error("exception: " + ex.Message); Util.Log_Error("exception: " + ex.StackTrace); } //要对userCodes进行处理,保证无重复的内容。 Dictionary <Contract, Boolean> codeDict = new Dictionary <Contract, bool>(); for (int i = 0; i < userCodes.Count; i++) { if (userCodes[i] != null) { if (codeDict.ContainsKey(userCodes[i])) { userCodes.RemoveAt(i); i -= 1; } else { codeDict.Add(userCodes[i], true); } } } while (userCodes.Count > USER_CODE_SET_MAX_CODES && item.IsZhuli == false) { userCodes.RemoveAt(userCodes.Count - 1); } if (item.IsZhuli) { Util.Log("添加UserCodes到主力合约: userCodes的个数为" + userCodes.Count.ToString()); foreach (Contract codeInfo in userCodes) { if (codeInfo != null) { //Util.Log("--CodeInfo为:" + codeInfo.ToString()); } else { //Util.Log("--CodeInfo为null"); } } } _DicUserCodeSetCodeInfo.Add(item.Id, userCodes); } else { _DicUserCodeSetCodeInfo.Add(item.Id, new ObservableCollection <Contract>()); } } } //AddZhuliCodeTemp(userCodeSetList); return(_UserCodeSetList); }
/// <summary> /// 买量 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Grid_MouseEnter_Close_Buy(object sender, MouseEventArgs e) { Grid grid = sender as Grid; if (grid == null) { return; } TextBlock tp = grid.ToolTip as TextBlock; DisplayRealData displayRealData = grid.DataContext as DisplayRealData; //卖出平仓 TradeDataClient jyDataServer = TradeDataClient.GetClientInstance(); int todayPosCount; int lastPosCount; string code = displayRealData.Code; //查找多头的单子 if (jyDataServer.GetPositionCount(code, true, out todayPosCount, out lastPosCount) == false) { grid.ToolTip = null; return; } if (todayPosCount == 0 && lastPosCount == 0) { grid.ToolTip = null; return; } if (tp == null) { grid.ToolTip = new TextBlock(); tp = grid.ToolTip as TextBlock; } tp.Inlines.Clear(); Run run = new Run(); run.Text = "双击 "; tp.Inlines.Add(run); run = new Run(); Binding binding1 = new Binding(); binding1.Source = grid.DataContext; binding1.Mode = BindingMode.OneWay; binding1.Path = new PropertyPath("StBuyPrice"); run.SetBinding(Run.TextProperty, binding1); tp.Inlines.Add(run); run = new Run(); run.Text = " 卖出"; run.Foreground = new SolidColorBrush(Color.FromRgb(0x13, 0xaf, 0x13)); tp.Inlines.Add(run); Boolean bHasComma = false; if (CodeSetManager.IsCloseTodaySupport(code) && todayPosCount != 0) { //如果支持平今 run = new Run(); run.Text = "平今"; run.FontSize = 13; run.Foreground = new SolidColorBrush(Color.FromRgb(0xff, 0x00, 0xff)); tp.Inlines.Add(run); run = new Run(); run.Text = " " + todayPosCount.ToString() + " "; run.Foreground = new SolidColorBrush(Color.FromRgb(0x13, 0xaf, 0x13)); tp.Inlines.Add(run); bHasComma = true; } else { lastPosCount += todayPosCount; } if (lastPosCount != 0) { if (bHasComma) { run = new Run(); run.Text = ","; tp.Inlines.Add(run); } run = new Run(); run.Text = " 平仓"; run.FontSize = 13; run.Foreground = new SolidColorBrush(Color.FromRgb(0xff, 0x00, 0xff)); tp.Inlines.Add(run); run = new Run(); run.Text = " " + lastPosCount.ToString() + " "; run.Foreground = new SolidColorBrush(Color.FromRgb(0x13, 0xaf, 0x13)); tp.Inlines.Add(run); } run = new Run(); run.Text = "手" + code; tp.FontWeight = FontWeights.Bold; tp.Inlines.Add(run); }
private void Exec_Click(object sender, RoutedEventArgs e) { string verifyMessage = execOrderDataVerification(); if (verifyMessage == string.Empty) { Contract optContract = CodeSetManager.GetContractInfo(txtCode.Text.Trim()); if (optContract == null) { Util.Log("Warning! Cannot find contract info for " + txtCode.Text.Trim()); return; } bool isExec = rbExec.IsChecked == true ? true : false; string order = rbExec.IsChecked == true ? "行权" : "弃权"; string strCode = optContract.Code; int handCount = CommonUtil.GetIntValue(iudNum.Value.Value); EnumThostOffsetFlagType openClose = EnumThostOffsetFlagType.Close; string kp = "平仓"; if (CodeSetManager.IsCloseTodaySupport(optContract.Code)) { if (rbPingjin.IsChecked == true) { openClose = EnumThostOffsetFlagType.CloseToday; kp = "平今"; } else if (rbPingcang.IsChecked == true) { openClose = EnumThostOffsetFlagType.CloseYesterday; kp = "平仓"; } } else if (rbPingcang.IsChecked == true) { openClose = EnumThostOffsetFlagType.Close; } if (TradingMaster.Properties.Settings.Default.ConfirmBeforeSendNewOrder == true) { CheckableMessageBox messageBox = new CheckableMessageBox(); messageBox.tbMessage.Text = string.Format("{0}:{1} {2} {3}手", order, kp, strCode, handCount); string windowTitle = string.Format("确认{0}:{1} {2} {3}手", order, kp, strCode, handCount); Window confirmWindow = CommonUtil.GetWindow(windowTitle, messageBox, _MainWindow); if (confirmWindow.ShowDialog() == true) { if (handCount > 0) { TradeDataClient.GetClientInstance().RequestOrder("", BACKENDTYPE.CTP, new RequestContent("NewExecOrder", new List <object>() { strCode, handCount, optContract.ExchName, isExec, openClose })); } } } else { if (!CodeSetManager.IsCloseTodaySupport(strCode) && openClose == EnumThostOffsetFlagType.CloseToday) { openClose = EnumThostOffsetFlagType.Close; } if (handCount > 0) { TradeDataClient.GetClientInstance().RequestOrder("", BACKENDTYPE.CTP, new RequestContent("NewExecOrder", new List <object>() { strCode, handCount, optContract.ExchName, isExec, openClose })); } } } }
/// <summary> /// 根据实时主推更新资金的盈亏数据和持仓的浮动盈亏数据 /// </summary> /// <param name="commRealTimeDatas"></param> private void UpdateFDYK(Dictionary <Contract, RealData> realDataDict) { MainWindow mainWindow = TradeDataClient.GetClientInstance().getMainWindow();//CtpDataServer.GetUserInstance().getMainWindow(); foreach (Contract contract in realDataDict.Keys) { RealData realData = realDataDict[contract]; double newPrice = realData.NewPrice; //最新价 double prevSettlementPrice = realData.PrevSettlementPrice; //昨结算 double settlementPrice = realData.SettlmentPrice; //现结算 double bidPrice = realData.BidPrice[0]; double askPrice = realData.AskPrice[0]; if (newPrice == 0 || realData.Volumn == 0) { if (prevSettlementPrice > 0) { newPrice = prevSettlementPrice; } else if (newPrice == 0) { newPrice = realData.PrevClose; } } if (bidPrice == 0) { bidPrice = newPrice; } if (askPrice == 0) { askPrice = newPrice; } double hycs = realData.CodeInfo.Hycs; decimal fluct = realData.CodeInfo.Fluct; if (mainWindow != null) { foreach (PosInfoDetail detail in mainWindow.PositionDetailCollection) { if (detail.Code == contract.Code) { detail.PrevSettleMent = prevSettlementPrice; if (newPrice == 0) { detail.Fdyk = detail.Ccyk = 0; } //更新Detail的数据 if (detail.BuySell.Contains("买")) { detail.INewPrice = bidPrice; if (CodeSetManager.GetContractInfo(detail.Code, CodeSetManager.ExNameToCtp(detail.Exchange)).ProductType != null && CodeSetManager.GetContractInfo(detail.Code, CodeSetManager.ExNameToCtp(detail.Exchange)).ProductType.Contains("Option")) { detail.OptionMarketCap = bidPrice * detail.TradeHandCount * hycs; if (detail.PositionType.Contains("今")) { detail.Premium = -detail.AvgPx * detail.TradeHandCount * hycs; //detail.OptionProfit = (newPrice - detail.AvgPx) * detail.TradeHandCount * hycs; } else { //detail.OptionProfit = (newPrice - detail.PrevSettleMent) * detail.TradeHandCount * hycs; } } if (detail.PositionType == "今仓") { detail.Ccyk = (bidPrice - detail.AvgPx) * detail.TradeHandCount * hycs; detail.Fdyk = detail.Ccyk; } else { detail.Ccyk = (bidPrice - prevSettlementPrice) * detail.TradeHandCount * hycs; detail.Fdyk = (bidPrice - detail.AvgPx) * detail.TradeHandCount * hycs; } } else { detail.INewPrice = askPrice; if (CodeSetManager.GetContractInfo(detail.Code, CodeSetManager.ExNameToCtp(detail.Exchange)).ProductType != null && CodeSetManager.GetContractInfo(detail.Code, CodeSetManager.ExNameToCtp(detail.Exchange)).ProductType.Contains("Option")) { detail.OptionMarketCap = -askPrice * detail.TradeHandCount * hycs; if (detail.PositionType.Contains("今")) { detail.Premium = detail.AvgPx * detail.TradeHandCount * hycs; //detail.OptionProfit = -(newPrice - detail.AvgPx) * detail.TradeHandCount * hycs; } else { //detail.OptionProfit = -(newPrice - detail.PrevSettleMent) * detail.TradeHandCount * hycs; } } if (detail.PositionType == "今仓") { detail.Ccyk = (detail.AvgPx - askPrice) * detail.TradeHandCount * hycs; detail.Fdyk = detail.Ccyk; } else { detail.Ccyk = (prevSettlementPrice - askPrice) * detail.TradeHandCount * hycs; detail.Fdyk = (detail.AvgPx - askPrice) * detail.TradeHandCount * hycs; } } } } foreach (PosInfoTotal posTotal in mainWindow.PositionCollection_Total) { if (posTotal.Code == realData.CodeInfo.Code) { double yesterdayDsyk = 0; double todayDsyk = 0; double yesterdayFdyk = 0; double todayFdyk = 0; double todayOpProfit = 0; double yesterdayOpProfit = 0; if (newPrice != 0) { if (CodeSetManager.GetContractInfo(posTotal.Code, CodeSetManager.ExNameToCtp(posTotal.Exchange)).ProductType != null && CodeSetManager.GetContractInfo(posTotal.Code, CodeSetManager.ExNameToCtp(posTotal.Exchange)).ProductType.Contains("Option")) { if (posTotal.BuySell.Contains("买")) { posTotal.OptionMarketCap = bidPrice * posTotal.TotalPosition * hycs; posTotal.Premium = -posTotal.TodayOpenAvgPx * posTotal.TodayPosition * hycs; //TODO: TradeHandCount //yesterdayOpProfit = (newPrice - posTotal.YesterdayOpenAvgPx) * posTotal.YesterdayPosition * hycs;//yesterdayOpProfit //todayOpProfit = (newPrice - posTotal.TodayOpenAvgPx) * posTotal.TodayPosition * hycs;//todayOpProfit } else { posTotal.OptionMarketCap = -askPrice * posTotal.TotalPosition * hycs; posTotal.Premium = posTotal.TodayOpenAvgPx * posTotal.TodayPosition * hycs; //TODO: TradeHandCount //yesterdayOpProfit = (posTotal.YesterdayOpenAvgPx - newPrice) * posTotal.YesterdayPosition * hycs;//yesterdayOpProfit //todayOpProfit = (posTotal.TodayOpenAvgPx - newPrice) * posTotal.TodayPosition * hycs;//todayOpProfit } } //更新Detail的数据 if (posTotal.BuySell.Contains("买")) { yesterdayDsyk = (bidPrice - prevSettlementPrice) * posTotal.YesterdayPosition * hycs; todayDsyk = (bidPrice - posTotal.TodayOpenAvgPx) * posTotal.TodayPosition * hycs; yesterdayFdyk = (bidPrice - posTotal.YesterdayOpenAvgPx) * posTotal.YesterdayPosition * hycs; todayFdyk = todayDsyk;//(newPrice - detail.OpenAvgPx) * detail.TodayOpen * hycs; } else { if (CodeSetManager.GetContractInfo(posTotal.Code, CodeSetManager.ExNameToCtp(posTotal.Exchange)).ProductType != null && CodeSetManager.GetContractInfo(posTotal.Code, CodeSetManager.ExNameToCtp(posTotal.Exchange)).ProductType.Contains("Option")) { posTotal.OptionMarketCap = -askPrice * posTotal.TotalPosition * hycs; posTotal.Premium = posTotal.TodayOpenAvgPx * posTotal.TodayPosition * hycs; //TODO: TradeHandCount } yesterdayDsyk = (prevSettlementPrice - askPrice) * posTotal.YesterdayPosition * hycs; todayDsyk = (posTotal.TodayOpenAvgPx - askPrice) * posTotal.TodayPosition * hycs; yesterdayFdyk = (posTotal.YesterdayOpenAvgPx - askPrice) * posTotal.YesterdayPosition * hycs; todayFdyk = todayDsyk;//((newPrice - detail.OpenAvgPx) * detail.TodayOpen * hycs); } } posTotal.Ccyk = yesterdayDsyk + todayDsyk; posTotal.Fdyk = yesterdayFdyk + todayFdyk; posTotal.OptionProfit = yesterdayOpProfit + todayOpProfit; posTotal.AvgPositionPrice = (posTotal.TodayPosition * posTotal.TodayOpenAvgPx + posTotal.YesterdayPosition * prevSettlementPrice) / posTotal.TotalPosition; } } //更新资金数据 double totalDSFY = 0; double totalFdyk = 0; double totalPremium = 0; double totalOptionCap = 0; double totalOptionProfit = 0; foreach (PosInfoTotal detail in mainWindow.PositionCollection_Total) { if (CodeSetManager.GetContractInfo(detail.Code, CodeSetManager.ExNameToCtp(detail.Exchange)).ProductType == "Futures") { totalDSFY += detail.Ccyk; totalFdyk += detail.Fdyk; } else if (CodeSetManager.GetContractInfo(detail.Code, CodeSetManager.ExNameToCtp(detail.Exchange)).ProductType != null && CodeSetManager.GetContractInfo(detail.Code, CodeSetManager.ExNameToCtp(detail.Exchange)).ProductType.Contains("Option")) { totalOptionProfit += detail.Ccyk; } totalPremium += detail.Premium; totalOptionCap += detail.OptionMarketCap; totalOptionProfit += detail.OptionProfit; } if (mainWindow.CapitalDataCollection != null) { mainWindow.CapitalDataCollection.Dsfy = totalDSFY; mainWindow.CapitalDataCollection.FloatProfit = totalFdyk; //mainWindow.CapitalDataCollection.Premium = totalPremium; mainWindow.CapitalDataCollection.OptionMarketCap = totalOptionCap; mainWindow.CapitalDataCollection.OptionProfit = totalOptionProfit; mainWindow.CapitalDataCollection.AccountCap = totalOptionCap + mainWindow.CapitalDataCollection.DynamicEquity; } } } }
public void RemoveUselessRequest() { //去除不必要的请求 List <Contract> lstDelCodes = new List <Contract>(); MainWindow mainWindow = TradeDataClient.GetClientInstance().getMainWindow();//CtpDataServer.GetUserInstance().getMainWindow(); if (mainWindow != null) { foreach (var item in _CommObj.RequestingCodes) { bool isUsed = false; foreach (var positionItem in mainWindow.PositionDetailCollection) { if (item == positionItem.Code) { isUsed = true; break; } } foreach (var quoteItem in mainWindow.RealDataCollection) { if (item == quoteItem.Code) { isUsed = true; break; } } foreach (var quoteItem in mainWindow.RealDataArbitrageCollection) { if (item == quoteItem.Code) { isUsed = true; break; } } if (item == mainWindow.uscNewOrderPanel.txtCode.Text) { isUsed = true; } string fCode = mainWindow.uscOptionHangqing.titleCode.Content.ToString(); if (fCode != null && fCode != String.Empty) { if (fCode == item) { isUsed = true; break; } if (mainWindow.uscOptionHangqing.OptionCodeDict.ContainsKey(fCode)) { foreach (string contract in mainWindow.uscOptionHangqing.OptionCodeDict[fCode]) { if (contract == item) { isUsed = true; break; } } } } if (!isUsed) { Contract cCode = CodeSetManager.GetContractInfo(item); //TODO :临时方案 if (cCode == null) { cCode = new Contract(item); } // lstDelCodes.Add(cCode); } } } if (lstDelCodes.Count > 0) { AddContract(lstDelCodes.ToArray()); UnRequest(); } }