public void ExecuteTradeData(object para)
 {
     try
     {
         TodayTraderModel ttm = para as TodayTraderModel;
         if (TodayTraderViewModels.Instance().TodayTraderList.FirstOrDefault(x => x.TradeNumber == ttm.trade_id) != null)
         {
             return;
         }
         if (ttm.bLast)
         {
             Dictionary <string, TodayTraderModelViewModel> dicTTVM = new Dictionary <string, TodayTraderModelViewModel>();
             foreach (TodayTraderModelViewModel item in TodayTraderViewModels.Instance().TodayTraderList)
             {
                 if (!dicTTVM.ContainsKey(item.ContractCode + item.Direction + item.OpenOffset))
                 {
                     TodayTraderModelViewModel ttmvm = item.Clone(item);
                     ttmvm.AllPrice = item.TradePrice * item.TradeVolume;
                     dicTTVM.Add(item.ContractCode + item.Direction + item.OpenOffset, ttmvm);
                 }
                 else
                 {
                     dicTTVM[item.ContractCode + item.Direction + item.OpenOffset].AllPrice    = dicTTVM[item.ContractCode + item.Direction + item.OpenOffset].AllPrice + item.TradePrice * item.TradeVolume;
                     dicTTVM[item.ContractCode + item.Direction + item.OpenOffset].TradeVolume = dicTTVM[item.ContractCode + item.Direction + item.OpenOffset].TradeVolume + item.TradeVolume;
                     dicTTVM[item.ContractCode + item.Direction + item.OpenOffset].TradePrice  = dicTTVM[item.ContractCode + item.Direction + item.OpenOffset].AllPrice / dicTTVM[item.ContractCode + item.Direction + item.OpenOffset].TradeVolume;
                 }
             }
             foreach (TodayTraderModelViewModel item in dicTTVM.Values)
             {
                 TodayTraderViewModels.Instance().TodayTraderListALL.Add(item);
             }
             return;
         }
         VarietyModel vm     = null;
         string[]     values = ttm.contract_code.Split(' ');
         if (values.Length == 3)
         {
             string varietie = values[1];
             if (ContractVariety.Varieties.ContainsKey(varietie))
             {
                 vm = ContractVariety.Varieties[varietie];
             }
             if (vm != null)
             {
                 ttm.precision = vm.precision;
             }
         }
         //添加持仓集合
         TodayTraderViewModels.Instance().TodayTraderList.Add(new TodayTraderModelViewModel(ttm));
     }
     catch (Exception ex)
     {
         LogHelper.Info(ex.ToString());
     }
 }
Beispiel #2
0
        public TodayTraderModelViewModel Clone(TodayTraderModelViewModel tpm)
        {
            TodayTraderModelViewModel temp = new TodayTraderModelViewModel(new TodayTraderModel());

            temp.AllPrice      = tpm.AllPrice;
            temp.ContractCode  = tpm.ContractCode;
            temp.ContractId    = tpm.ContractId;
            temp.Direction     = tpm.Direction;
            temp.OpenOffset    = tpm.OpenOffset;
            temp.OrderOrderref = tpm.OrderOrderref;
            temp.PriceType     = tpm.PriceType;
            temp.ShadowTradeID = tpm.ShadowTradeID;
            temp.ShadowOrderID = tpm.ShadowOrderID;
            temp.TradeNumber   = tpm.TradeNumber;
            temp.TradePrice    = tpm.TradePrice;
            temp.TradeTime     = tpm.TradeTime;
            temp.TradeVolume   = tpm.TradeVolume;
            temp.Precision     = tpm.Precision;
            return(temp);
        }
        public void ExecuteTransactionInfoData(object para)
        {
            try
            {
                TransactionInfoModel tim = para as TransactionInfoModel;
                if (tim == null)
                {
                    return;
                }
                if (TodayTraderViewModels.Instance().TodayTraderList.FirstOrDefault(x => x.ShadowTradeID == tim.shadow_tradeID) != null)
                {
                    return;
                }
                TodayTraderModel ttm = new TodayTraderModel();
                ttm.contract_code  = tim.contract_code;
                ttm.direction      = tim.direction;
                ttm.open_offset    = tim.open_offset;
                ttm.order_id       = tim.order_id;
                ttm.price_type     = tim.price_type;
                ttm.shadow_orderID = tim.shadow_orderID;
                ttm.trade_id       = tim.trade_number;
                ttm.contract_id    = tim.contract_id;
                ttm.shadow_tradeID = tim.shadow_tradeID;
                ttm.trade_date     = tim.trade_date;
                ttm.trade_id       = tim.trade_id;
                ttm.trade_price    = tim.trade_price;
                ttm.trade_time     = tim.trade_time;
                ttm.trade_volume   = tim.trade_volume;
                VarietyModel vm     = null;
                string[]     values = ttm.contract_code.Split(' ');
                if (values.Length == 3)
                {
                    string varietie = values[1];
                    if (ContractVariety.Varieties.ContainsKey(varietie))
                    {
                        vm = ContractVariety.Varieties[varietie];
                    }
                    if (vm != null)
                    {
                        ttm.precision = vm.precision;
                    }
                }
                TodayTraderViewModels.Instance().TodayTraderList.Add(new TodayTraderModelViewModel(ttm));
                Dictionary <string, TodayTraderModelViewModel> dicTTVM = new Dictionary <string, TodayTraderModelViewModel>();
                foreach (TodayTraderModelViewModel item in TodayTraderViewModels.Instance().TodayTraderList)
                {
                    if (!dicTTVM.ContainsKey(item.ContractCode + item.Direction + item.OpenOffset))
                    {
                        TodayTraderModelViewModel ttmvm = item.Clone(item);
                        ttmvm.AllPrice = item.TradePrice * item.TradeVolume;
                        dicTTVM.Add(item.ContractCode + item.Direction + item.OpenOffset, ttmvm);
                    }
                    else
                    {
                        dicTTVM[item.ContractCode + item.Direction + item.OpenOffset].AllPrice    = dicTTVM[item.ContractCode + item.Direction + item.OpenOffset].AllPrice + item.TradePrice * item.TradeVolume;
                        dicTTVM[item.ContractCode + item.Direction + item.OpenOffset].TradeVolume = dicTTVM[item.ContractCode + item.Direction + item.OpenOffset].TradeVolume + item.TradeVolume;
                        dicTTVM[item.ContractCode + item.Direction + item.OpenOffset].TradePrice  = dicTTVM[item.ContractCode + item.Direction + item.OpenOffset].AllPrice / dicTTVM[item.ContractCode + item.Direction + item.OpenOffset].TradeVolume;
                    }
                }
                if (dicTTVM != null && dicTTVM.Values.Count > 0)
                {
                    TodayTraderViewModels.Instance().TodayTraderListALL.Clear();

                    foreach (TodayTraderModelViewModel item in dicTTVM.Values)
                    {
                        TodayTraderViewModels.Instance().TodayTraderListALL.Add(item);
                    }
                }
                if (CommParameterSetting.MessageAlert.TradeAlert == "窗口提示")
                {
                    // string msg = "\t合约已成交\t" + "\n\n" + ttm.contract_id + "\n\t" + "方向:" + (ttm.direction == "B" ? "买" : "卖") + "\n\t开平:" + (ttm.open_offset == 1 ? "开仓" : "平仓") + "\n\t成交数量:" + ttm.trade_volume + "\n\t成交价格" + ttm.trade_price;
                    string msg = "     " + ttm.contract_id + "\t" + "    方向:" + (ttm.direction == "B" ? "买" : "卖") + "\t\n     开平:" + (ttm.open_offset == 1 ? "开仓" : "平仓") + "\t    成交数量:" + ttm.trade_volume + "\t\n     成交价格" + ttm.trade_price + "\t" + "    已成交";
                    MessageBox.Show(msg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    LogHelper.Info(msg + "成交时间:");
                }
                else if (CommParameterSetting.MessageAlert.TradeAlert == "声音提示")
                {
                    SoundPlayerHelper.Play();
                }
            }
            catch (Exception ex)
            {
                LogHelper.Info(ex.ToString());
            }
        }