public static LogOrder GetLogOrderEntity(OrderTask orderTask,OperationType operationType,string objectId)
        {
            LogOrder logEntity = new LogOrder();

            string hostname = Dns.GetHostName();
            IPHostEntry localhost = Dns.GetHostEntry(hostname);
            IPAddress localaddr = localhost.AddressList[0];
            logEntity.IP = localaddr.ToString();

            logEntity.UserId = ConsoleClient.Instance.User.UserId;
            logEntity.UserName = ConsoleClient.Instance.User.UserName;
            logEntity.Event = objectId;// "ExecuteOrder";
            logEntity.ExchangeCode = orderTask.ExchangeCode;
            logEntity.OperationType = operationType;
            logEntity.OrderId = orderTask.OrderId;
            logEntity.OrderCode = orderTask.Code;
            logEntity.AccountCode = orderTask.AccountCode;
            logEntity.InstrumentCode = orderTask.InstrumentCode;
            logEntity.IsBuy = orderTask.IsBuy == BuySell.Buy;
            logEntity.IsOpen = orderTask.IsOpen == OpenClose.Open;
            logEntity.Lot = orderTask.Lot.Value;
            logEntity.SetPrice = orderTask.SetPrice;
            logEntity.OrderType = orderTask.OrderType;
            logEntity.OrderRelation = null;
            logEntity.TransactionCode = orderTask.Transaction.Code;

            return logEntity;
        }
        public void AddLmtOrder(OrderTask orderTask)
        {
            bool isOK = OrderTaskManager.CheckExecuteOrder(orderTask);
            if (isOK)
            {
                this.OrderTasks.Insert(0,orderTask);
            }
            else
            {
                this.OrderTasks.Add(orderTask);
            }
            orderTask.SetCellDataDefine(orderTask.OrderStatus);

            if (this._LmtOrderForInstrument.Instrument.Id == Guid.Empty)
            {
                this.LmtOrderForInstrument.Update(orderTask);
            }
            else
            {
                bool isCurrentInstrument = orderTask.InstrumentId == this.LmtOrderForInstrument.Instrument.Id;
            }

            this.LmtOrderForInstrument.UpdateSumBuySellLot(true, orderTask);

            if (isOK && this.OnSettingFirstRowStyleEvent != null && this.SelectedInstrumentId != null && (orderTask.InstrumentId == this.SelectedInstrumentId))
            {
                this.OnSettingFirstRowStyleEvent();
            }
        }
 public void BackHitOrder(OrderTask orderTask,int rowIndex)
 {
     this._OrderTaskGrid.Rows[rowIndex].CellStyle = this._NormalStyle;
     this._App.ExchangeDataManager.OrderTaskModel.OrderTasks.Remove(orderTask);
     int index = this._App.ExchangeDataManager.OrderTaskModel.OrderTasks.Count - 1;
     this._App.ExchangeDataManager.OrderTaskModel.OrderTasks.Insert(index, orderTask);
     this._OrderTaskGrid.ItemsSource = this._App.ExchangeDataManager.OrderTaskModel.OrderTasks;
 }
 public static bool CheckDQOrder(OrderTask order, SystemParameter parameter, ConfigParameter configParameter)
 {
     bool isOK = false;
     if((order.OrderType == OrderType.SpotTrade) && (order.OrderStatus == OrderStatus.WaitOutPriceDQ || order.OrderStatus == OrderStatus.WaitOutLotDQ))
     {
         if (parameter.AutoConfirmOrder && ((IsNeedDQMaxMove(order) || (configParameter.AllowModifyOrderLot && parameter.CanDealerViewAccountInfo)) == false))
         {
             isOK = true;
         }
     }
     return isOK;
 }
 public static bool CheckExecuteOrder(OrderTask order)
 {
     bool isOK = false;
     if (order.OrderType == OrderType.Limit || order.OrderType == OrderType.Market)
     {
         if (order.OrderStatus == OrderStatus.WaitOutPriceLMT
             || order.OrderStatus == OrderStatus.WaitOutLotLMT
             || order.OrderStatus == OrderStatus.WaitOutLotLMTOrigin
             || order.Transaction.SubType == TransactionSubType.Mapping)
         {
             isOK = true;
         }
     }
     return isOK;
 }
        public static bool AllowAccept(OrderTask orderTask,QuotePolicyDetail quotePolicyDetail,string origin,int acceptDQVariation)
        {
            //Allow: (isNormal = IsBuy), SetPrice >= Calculated.Quotepolicy.Ask, SetPrice <= Calculated.Quotepolicy.Bid
            InstrumentClient instrument = orderTask.Transaction.Instrument;
            Price ask = null;
            Price bid = null;
            Price marketOriginPrice = new Price(origin, instrument.NumeratorUnit, instrument.Denominator);
            marketOriginPrice = marketOriginPrice + acceptDQVariation;
            if (quotePolicyDetail.PriceType == PriceType.WatchOnly)
            {
                int diffValue = instrument.GetSourceAskBidDiffValue();
                bid = marketOriginPrice;
                ask = bid + diffValue;
            }
            else if (quotePolicyDetail.PriceType == PriceType.OriginEnable)
            {
                bid = marketOriginPrice + quotePolicyDetail.AutoAdjustPoints + (0 - quotePolicyDetail.SpreadPoints);
                var diffValue = instrument.GetSourceAskBidDiffValue();
                ask = bid + (Math.Abs(diffValue)) + (quotePolicyDetail.SpreadPoints);
            }
            else
            {
                bid = marketOriginPrice + (quotePolicyDetail.AutoAdjustPoints);
                ask = bid + (quotePolicyDetail.SpreadPoints);
            }

            Price setPrice = new Price(orderTask.SetPrice, instrument.NumeratorUnit, instrument.Denominator);
            if(instrument.IsNormal == (orderTask.IsBuy == BuySell.Buy))
            {
                if (ask != null)
                {
                    return setPrice > ask;
                }
            }
            else
            {
                if (bid != null)
                {
                    return setPrice < bid;
                }
            }
            return false;
        }
        public void AddInstanceOrder(OrderTask orderTask)
        {
            this.OrderTasks.Add(orderTask);
            orderTask.SetCellDataDefine(orderTask.OrderStatus);

            if (this.InstantOrderForInstrument.Instrument.Id == Guid.Empty)
            {
                this.InstantOrderForInstrument.Update(orderTask);
            }
            else
            {
                bool isCurrentInstrument = orderTask.InstrumentId == this.InstantOrderForInstrument.Instrument.Id;
            }

            this.InstantOrderForInstrument.UpdateSumBuySellLot(true, orderTask);
            if (this.OnSettingFirstRowStyleEvent != null && this.SelectedInstrumentId != null && (orderTask.InstrumentId == this.SelectedInstrumentId))
            {
                this.OnSettingFirstRowStyleEvent();
            }
        }
        public void ShowDialogWin(AccountInfor accountInfor, string caption, OrderTask orderTask, UIElement uIElement, HandleAction action)
        {
            this.ShowDialogWin(accountInfor, caption, orderTask, action);

            var captionPanel = this._ConfirmOrderDialogWin.FindName("captionPanel") as StackPanel;
            if (captionPanel != null)
            {
                captionPanel.Children.Add(uIElement);

                this._ConfirmOptionElement = uIElement;
                this._OrderTask = orderTask;
                this._HandleAction = action;
            }
        }
        //Modify SetPrice
        public void ShowDialogWin(string caption, OrderTask orderTask,string origin, HandleAction action)
        {
            if (this._ModifyPriceDialogWin == null)
            {
                this._ModifyPriceDialogWin = new XamDialogWindow()
                {
                    Width = 250,
                    Height = 150,
                    Header = caption,
                    StartupPosition = Infragistics.Controls.Interactions.StartupPosition.Center,
                    IsModal = true,
                    CloseButtonVisibility = Visibility.Collapsed,
                    MinimizeButtonVisibility = Visibility.Collapsed,
                    MaximizeButtonVisibility = Visibility.Collapsed,
                };
            }
            this._HandleAction = action;
            this._OrderTask = orderTask;
            this._Origin = origin;
            TextBlock ModifyPriceLable = new TextBlock()
            {
                Name = "ModifyPriceLable",
                Foreground = new SolidColorBrush(Colors.Blue),
                Text = "Input new Price:",
                Margin = new Thickness(5),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left
            };

            TextBox NewPriceText = new TextBox()
            {
                Name = "NewPriceText",
                Width = 100,
                Foreground = new SolidColorBrush(Colors.Blue),
                Text = orderTask.SetPrice,
                Margin = new Thickness(5),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left,
                TextAlignment = TextAlignment.Right
            };
            this._NewPriceElement = NewPriceText;

            StackPanel ModifyPricePanle = new StackPanel() { Name = "captionPanel", Orientation = Orientation.Horizontal };
            ModifyPricePanle.Margin = new Thickness(15, 0, 0, 0);
            ModifyPricePanle.HorizontalAlignment = HorizontalAlignment.Left;
            ModifyPricePanle.VerticalAlignment = VerticalAlignment.Center;
            ModifyPricePanle.Children.Add(ModifyPriceLable);
            ModifyPricePanle.Children.Add(NewPriceText);

            Grid.SetRow(ModifyPricePanle, 0);

            //按钮
            Button ModifyPriceOk = new Button() { Name = "ModifyPriceOkBtn", Content = "OK", Width = 60, Height = 24, TabIndex = 1, Margin = new Thickness(25, 0, 0, 0) };
            Button ModifyPriceCancel = new Button() { Name = "ModifyPriceCancelBtn", Content = "Cancel", Width = 60, Height = 24, Margin = new Thickness(25, 0, 0, 0) };
            ModifyPriceOk.Click += new RoutedEventHandler(ModifyPriceOkBtn_Click);
            ModifyPriceCancel.Click += new RoutedEventHandler(ModifyPriceCancelBtn_Click);

            StackPanel panel = new StackPanel();
            panel.Orientation = Orientation.Horizontal;
            panel.Children.Add(ModifyPriceOk);
            panel.Children.Add(ModifyPriceCancel);
            panel.VerticalAlignment = VerticalAlignment.Bottom;
            panel.HorizontalAlignment = HorizontalAlignment.Center;
            panel.Margin = new Thickness(5);
            Grid.SetRow(panel, 1);

            Grid layoutGrid = new Grid();

            LinearGradientBrush brush = new LinearGradientBrush();
            brush.StartPoint = new Point(0.5, 0);
            brush.EndPoint = new Point(0.5, 1);
            GradientStop stop = new GradientStop();

            layoutGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(40) });
            layoutGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(40) });
            layoutGrid.Children.Add(ModifyPricePanle);
            layoutGrid.Children.Add(panel);

            this._ModifyPriceDialogWin.Content = layoutGrid;
            int columnSpan = this._LayoutContainer.ColumnDefinitions.Count;
            int rowSpan = this._LayoutContainer.RowDefinitions.Count;
            if (columnSpan > 0) Grid.SetColumnSpan(this._ModifyPriceDialogWin, columnSpan);
            if (rowSpan > 0) Grid.SetRowSpan(this._ModifyPriceDialogWin, rowSpan);

            if (!this._LayoutContainer.Children.Contains(this._ModifyPriceDialogWin))
            {
                this._LayoutContainer.Children.Add(this._ModifyPriceDialogWin);
            }

            this._ModifyPriceDialogWin.Show();
        }
        private void AddOrderTaskEntity(Order order)
        {
            if (order.Transaction.OrderType == iExchange.Common.OrderType.MarketOnOpen || order.Transaction.OrderType == iExchange.Common.OrderType.MarketOnClose)
            {
                OrderTask orderTask = new OrderTask(order);
                orderTask.BaseOrder = order;
                orderTask.OrderStatus = OrderStatus.TimeArrived;
                MooMocOrderForInstrument mooMocOrderForInstrument = null;
                mooMocOrderForInstrument = this._MooMocOrderForInstrumentModel.MooMocOrderForInstruments.SingleOrDefault(P => P.Instrument.Id == order.Transaction.Instrument.Id);
                if (mooMocOrderForInstrument == null)
                {
                    mooMocOrderForInstrument = new MooMocOrderForInstrument();
                    InstrumentClient instrument = order.Transaction.Instrument;
                    mooMocOrderForInstrument.Instrument = instrument;
                    mooMocOrderForInstrument.Origin = instrument.Origin;
                    mooMocOrderForInstrument.Variation = 0;

                    this._MooMocOrderForInstrumentModel.MooMocOrderForInstruments.Add(mooMocOrderForInstrument);
                }
                if (orderTask.IsBuy == BuySell.Buy)
                {
                    mooMocOrderForInstrument.SumBuyLot += orderTask.Lot.Value;
                }
                else
                {
                    mooMocOrderForInstrument.SumSellLot += orderTask.Lot.Value;
                }
                mooMocOrderForInstrument.OrderTasks.Add(orderTask);
            }
            else if(order.Transaction.OrderType == iExchange.Common.OrderType.SpotTrade)
            {
                OrderTask orderTask = new OrderTask(order);
                orderTask.BaseOrder = order;

                this._ProcessInstantOrder.AddInstanceOrder(orderTask);
            }
            else
            {
                OrderTask orderTask = new OrderTask(order);
                orderTask.BaseOrder = order;

                this._OrderTaskModel.OrderTasks.Add(orderTask);
                orderTask.SetCellDataDefine(orderTask.OrderStatus);
            }
        }
        //Move Hit Order To the First Row
        private void MoveHitOrder(Order newOrder)
        {
            List<OrderTask> hitOrders = new List<OrderTask>();
            IEnumerable<OrderTask> orders = this._OrderTaskModel.OrderTasks.Where(P => P.OrderId == newOrder.Id);

            foreach (OrderTask entity in orders)
            {
                hitOrders.Add(entity);
            }
            foreach (OrderTask entity in hitOrders)
            {
                this._OrderTaskModel.RemoveOrderTask(entity);
                OrderTask orderTask = new OrderTask(newOrder);
                orderTask.BaseOrder = newOrder;
                this._OrderTaskModel.OrderTasks.Insert(0, orderTask);

                if (this.OnOrderHitPriceNotifyEvent != null)
                {
                    this.OnOrderHitPriceNotifyEvent(orderTask);
                }
            }

            if (this.OnHitPriceReceivedRefreshUIEvent != null)
            {
                int hitOrdersCount = hitOrders.Count();
                this.OnHitPriceReceivedRefreshUIEvent(hitOrdersCount);
            }
        }
        public void SetOrderBottom(OrderTask orderTask, int rowIndex)
        {
            if (this.OrderTasks.Count <= 1) return;
            int index = this.OrderTasks.Count - 1;
            this.OrderTasks.Remove(orderTask);
            this.OrderTasks.Insert(index, orderTask);

            OrderTask firstOrder = this.OrderTasks[0];
            this.LmtOrderForInstrument.Update(firstOrder);
        }
 private void ChangeOrderStatus(OrderTask order,OrderStatus newStatus)
 {
     foreach (Order baseOrder in order.Transaction.Orders)
     {
         if (baseOrder.Id != order.OrderId)
         {
             baseOrder.ChangeStatus(newStatus);
         }
     }
 }
 private void ProcessPendingOrder(OrderTask orderTask, CellDataDefine currentCellData)
 {
     HandleAction actionType = currentCellData.Action;
     bool isEnabled;
     switch (actionType)
     {
         case HandleAction.None:
             break;
         case HandleAction.OnOrderAccept:
             isEnabled = currentCellData.IsEnable;
             if (isEnabled)
             {
                 this.OrderHandle.OnOrderAccept(orderTask); // DQ Order Accept
             }
             break;
         case HandleAction.OnOrderReject:
             isEnabled = currentCellData.IsEnable;
             if (isEnabled)
             {
                 this.OrderHandle.OnOrderReject(orderTask);
             }
             break;
     }
 }
 //Remove
 public void RemoveLmtOrderTask(OrderTask orderTask)
 {
     this.OrderTasks.Remove(orderTask);
     if (this._OrderTasks.Count == 0)
     {
         this.OnEmptyLmtOrderTask(this);
     }
 }
        //修改价格
        void ModifyPriceHandle(bool yesOrNo, string newPrice, OrderTask orderTask, HandleAction action)
        {
            if (yesOrNo)
            {
                if (action == HandleAction.OnOrderModify)
                {
                    //Check Modify Price DailyMaxMove
                    InstrumentClient instrument = orderTask.Transaction.Instrument;
                    if (OrderTaskManager.IsLimitedPriceByDailyMaxMove(newPrice, instrument))
                    {
                        string msg = "Out of daily max move,previous close price is " + instrument.PreviousClosePrice;
                        this._CommonDialogWin.ShowDialogWin(msg, "Alert");
                        return;
                    }
                    bool? isValidPrice = false;
                    isValidPrice = OrderTaskManager.IsValidPrice(instrument,decimal.Parse(newPrice));

                    if(isValidPrice.HasValue)
                    {
                        if (isValidPrice.Value)
                        {
                            orderTask.BestPrice = newPrice;
                            orderTask.SetPrice = newPrice;
                        }
                    }
                }
            }
        }
 private void ProcessOrder(OrderTask orderTask)
 {
     if (orderTask.OrderStatus == OrderStatus.WaitOutPriceLMT || orderTask.OrderStatus == OrderStatus.WaitOutLotLMT
     || orderTask.OrderStatus == OrderStatus.WaitOutLotLMTOrigin)
     {
         if (this.IsPriceExceedMaxMin(orderTask.BestPrice) == true && orderTask.OrderStatus == OrderStatus.WaitOutLotLMT)
         {
             //Waiting for Dealer Accept/Reject
             orderTask.ChangeStatus(OrderStatus.WaitOutPriceLMT);
             //this.mainWindow.oDealingConsole.PlaySound(SoundOption.LimitDealerIntervene);
         }
         else
         {
             if (orderTask.Transaction.OrderType == OrderType.Market)
             {
                 orderTask.SetPrice = orderTask.BestPrice;
             }
             //Commit Transaction
             //if (this.lotChanged) lot = this.lot.toString();
             this.Commit(orderTask,string.Empty,(decimal)orderTask.Lot);
         }
     }
 }
 private string GetRejectOrderMessage(OrderTask orderTask)
 {
     bool isBuy = orderTask.IsBuy == BuySell.Buy;
     Account account = orderTask.Transaction.Account;
     InstrumentClient instrument = orderTask.Instrument;
     return account.Code + (isBuy ? " buy " : " sell ") + orderTask.Lot + " " + instrument.Code + " at " + orderTask.SetPrice;
 }
 //成交单
 void ExecuteOrderHandle(bool yesOrNo, OrderTask orderTask, HandleAction action)
 {
     if (yesOrNo)
     {
         switch(action)
         {
             case HandleAction.None:
                 break;
             case HandleAction.OnOrderAccept:
                 this.Commit(orderTask, string.Empty, (decimal)orderTask.Lot);
                 break;
             case HandleAction.OnOrderExecute:
                 this.Commit(orderTask, string.Empty, (decimal)orderTask.Lot);
                 break;
         }
     }
 }
        private void Commit(OrderTask orderTask, string executePrice, decimal lot)
        {
            orderTask.ChangeStatus(OrderStatus.WaitServerResponse);
            orderTask.BaseOrder.ChangeStatus(OrderStatus.WaitServerResponse);

            string buyPrice = string.Empty;
            string sellPrice = string.Empty;
            executePrice = string.IsNullOrEmpty(executePrice) ? orderTask.SetPrice:executePrice;

            if(orderTask.IsBuy == BuySell.Buy)
            {
                buyPrice = executePrice;
            }
            else
            {
                sellPrice = executePrice;
            }

            switch(orderTask.Transaction.Type)
            {
                case TransactionType.Single:
                    foreach (Order order in orderTask.Transaction.Orders)
                    {
                        order.ChangeStatus(OrderStatus.WaitServerResponse);
                    }
                    break;
                case TransactionType.Pair:
                    foreach (Order orderTemp in orderTask.Transaction.Orders)
                    {
                        if (orderTemp.Id != orderTask.OrderId)
                        {
                            orderTemp.ChangeStatus(OrderStatus.WaitServerResponse);
                            executePrice = orderTemp.SetPrice;

                            if (orderTemp.BuySell == BuySell.Buy)
                                buyPrice = (executePrice == null) ? "" : executePrice.ToString();
                            else
                                sellPrice = (executePrice == null) ? "" : executePrice.ToString();
                            break;
                        }
                    }
                    break;
                case TransactionType.OneCancelOther:
                    foreach (Order orderTemp in orderTask.Transaction.Orders)
                    {
                        if (orderTemp.Id != orderTask.OrderId)
                        {
                            orderTemp.ChangeStatus(OrderStatus.Deleting);
                        }
                    }
                    break;
            }
            //if (!order.id) alert("The order is not valid!");
            LogOrder logEntity = LogEntityConvert.GetLogOrderEntity(orderTask, OperationType.OnOrderExecute, "ExecuteOrder");
            ConsoleClient.Instance.Execute(orderTask.Transaction, buyPrice, sellPrice, (decimal)orderTask.Lot, orderTask.OrderId, logEntity, ExecuteCallback);
        }
        //Account Information
        public void ShowDialogWin(AccountInfor accountInfor, string caption, OrderTask orderTask, HandleAction action)
        {
            if (this._ConfirmOrderDialogWin == null)
            {
                this._ConfirmOrderDialogWin = new XamDialogWindow()
                {
                    Width = 350,
                    Height = 450,
                    Header = caption,
                    StartupPosition = Infragistics.Controls.Interactions.StartupPosition.Center,
                    IsModal = true,
                    CloseButtonVisibility = Visibility.Collapsed,
                    MinimizeButtonVisibility = Visibility.Collapsed,
                    MaximizeButtonVisibility = Visibility.Collapsed,
                };
                this._OrderTask = orderTask;
                this._HandleAction = action;
            }
            else
            {
                this._ConfirmOrderDialogWin.Width = 350;
                this._ConfirmOrderDialogWin.Height = 450;
                this._ConfirmOrderDialogWin.Header = caption;
                this._ConfirmOrderDialogWin.Content = null;
            }
            TextBlock BLLable = new TextBlock()
            {
                Name = "BL",
                Foreground = new SolidColorBrush(Colors.White),
                Text = "BL",
                Margin = new Thickness(8),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left
            };
            TextBlock BalanceLable = new TextBlock()
            {
                Name = "Balance",
                Foreground = new SolidColorBrush(Colors.White),
                Text = "Balance",
                Margin = new Thickness(8),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left
            };
            TextBlock EquityLable = new TextBlock()
            {
                Name = "Equity",
                Foreground = new SolidColorBrush(Colors.White),
                Text = "Equity",
                Margin = new Thickness(8),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left
            };
            TextBlock NecessaryLable = new TextBlock()
            {
                Name = "Necessary",
                Foreground = new SolidColorBrush(Colors.White),
                Text = "Necessary",
                Margin = new Thickness(8),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left
            };
            TextBlock UsableLable = new TextBlock()
            {
                Name = "Usable",
                Foreground = new SolidColorBrush(Colors.White),
                Text = "Usable",
                Margin = new Thickness(8),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left
            };
            TextBlock TotalBuyLable = new TextBlock()
            {
                Name = "TotalBuy",
                Foreground = new SolidColorBrush(Colors.White),
                Text = "TotalBuy",
                Margin = new Thickness(8),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left
            };
            TextBlock TotalSellLable = new TextBlock()
            {
                Name = "TotalSell",
                Foreground = new SolidColorBrush(Colors.White),
                Text = "TotalSell",
                Margin = new Thickness(8),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left
            };
            TextBlock NetLable = new TextBlock()
            {
                Name = "Net",
                Foreground = new SolidColorBrush(Colors.Blue),
                Text = "Net",
                Margin = new Thickness(8),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left
            };
            TextBlock SetPriceLable = new TextBlock()
            {
                Name = "SetPrice",
                Foreground = new SolidColorBrush(Colors.White),
                Text = "SetPrice",
                Margin = new Thickness(8),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left
            };
            TextBlock ExecutePriceLable = new TextBlock()
            {
                Name = "ExecutePrice",
                Foreground = new SolidColorBrush(Colors.White),
                Text = "ExecutePrice",
                Margin = new Thickness(8),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left
            };
            TextBlock LotLable = new TextBlock()
            {
                Name = "Lot",
                Foreground = new SolidColorBrush(Colors.White),
                Text = "Lot",
                Margin = new Thickness(8),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left
            };

            StackPanel captionPanel = new StackPanel() { Name = "captionPanel", Orientation = Orientation.Vertical };
            captionPanel.Margin = new Thickness(0, 10, 0, 0);
            captionPanel.HorizontalAlignment = HorizontalAlignment.Center;
            captionPanel.VerticalAlignment = VerticalAlignment.Center;
            captionPanel.Children.Add(BLLable);
            captionPanel.Children.Add(BalanceLable);
            captionPanel.Children.Add(EquityLable);
            captionPanel.Children.Add(NecessaryLable);
            captionPanel.Children.Add(UsableLable);
            captionPanel.Children.Add(TotalBuyLable);
            captionPanel.Children.Add(TotalSellLable);
            captionPanel.Children.Add(NetLable);
            captionPanel.Children.Add(SetPriceLable);
            captionPanel.Children.Add(ExecutePriceLable);
            captionPanel.Children.Add(LotLable);

            Grid.SetRow(captionPanel, 0);
            Grid.SetColumn(captionPanel, 0);

            //Value Column
            CheckBox BLCheckBox = new CheckBox()
            {
                Name = "BLText",
                Foreground = new SolidColorBrush(Colors.White),
                IsChecked = true,
                Margin = new Thickness(8),
                IsEnabled = true,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Right
            };
            TextBlock BalanceText = new TextBlock()
            {
                Name = "BalanceText",
                Foreground = new SolidColorBrush(Colors.White),
                Text = accountInfor.Balance.ToString(),
                Margin = new Thickness(8),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Right
            };
            TextBlock EquityText = new TextBlock()
            {
                Name = "EquityText",
                Foreground = new SolidColorBrush(Colors.White),
                Text = accountInfor.Equity.ToString(),
                Margin = new Thickness(8),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Right
            };
            TextBlock NecessaryText = new TextBlock()
            {
                Name = "NecessaryText",
                Foreground = new SolidColorBrush(Colors.White),
                Text = accountInfor.Necessary.ToString(),
                Margin = new Thickness(8),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Right
            };
            TextBlock UsableText = new TextBlock()
            {
                Name = "UsableText",
                Foreground = new SolidColorBrush(Colors.White),
                Text = accountInfor.Usable.ToString(),
                Margin = new Thickness(8),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Right
            };
            TextBlock TotalBuyText = new TextBlock()
            {
                Name = "TotalBuyText",
                Foreground = new SolidColorBrush(Colors.White),
                Text = accountInfor.BuyLotBalanceSum.ToString(),
                Margin = new Thickness(8),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Right
            };
            TextBlock TotalSellText = new TextBlock()
            {
                Name = "TotalSellText",
                Foreground = new SolidColorBrush(Colors.White),
                Text = accountInfor.SellLotBalanceSum.ToString(),
                Margin = new Thickness(8),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Right
            };
            TextBlock NetText = new TextBlock()
            {
                Name = "NetText",
                Foreground = new SolidColorBrush(Colors.White),
                Text = (accountInfor.BuyLotBalanceSum - accountInfor.SellLotBalanceSum).ToString(),
                Margin = new Thickness(8),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Right
            };
            TextBlock SetPriceText = new TextBlock()
            {
                Name = "SetPriceText",
                Foreground = new SolidColorBrush(Colors.White),
                Text = orderTask.SetPrice,
                Margin = new Thickness(8),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Right
            };
            TextBlock ExecutePriceText = new TextBlock()
            {
                Name = "ExecutePriceText",
                Foreground = new SolidColorBrush(Colors.White),
                Text = orderTask.SetPrice,
                Margin = new Thickness(8),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Right
            };
            TextBox LotText = new TextBox()
            {
                Name = "LotText",
                Width = 100,
                Foreground = new SolidColorBrush(Colors.Blue),
                Text = orderTask.Lot.ToString(),
                Margin = new Thickness(8),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Right,
                TextAlignment = TextAlignment.Right
            };

            StackPanel valuePanel = new StackPanel() { Name = "valuePanel", Orientation = Orientation.Vertical };
            valuePanel.Margin = new Thickness(0, 10, 0, 0);
            valuePanel.HorizontalAlignment = HorizontalAlignment.Right;
            valuePanel.VerticalAlignment = VerticalAlignment.Center;
            valuePanel.Children.Add(BLCheckBox);
            valuePanel.Children.Add(BalanceText);
            valuePanel.Children.Add(EquityText);
            valuePanel.Children.Add(NecessaryText);
            valuePanel.Children.Add(UsableText);
            valuePanel.Children.Add(TotalBuyText);
            valuePanel.Children.Add(TotalSellText);
            valuePanel.Children.Add(NetText);
            valuePanel.Children.Add(SetPriceText);
            valuePanel.Children.Add(ExecutePriceText);
            valuePanel.Children.Add(LotText);

            Grid.SetRow(valuePanel, 0);
            Grid.SetColumn(valuePanel, 1);

            //按钮
            Button ok = new Button() { Name = "okBtn", Content = "Yes", Width = 60, Height = 25, TabIndex = 1, Margin = new Thickness(25, 0, 0, 0) };
            Button cancel = new Button() { Name = "cancelBtn", Content = "No", Width = 60, Height = 25, Margin = new Thickness(25, 0, 0, 0) };
            ok.Click += new RoutedEventHandler(ok_Click);
            cancel.Click += new RoutedEventHandler(cancel_Click);

            StackPanel panel = new StackPanel();
            panel.Orientation = Orientation.Horizontal;
            panel.Children.Add(ok);
            panel.Children.Add(cancel);
            panel.VerticalAlignment = VerticalAlignment.Bottom;
            panel.HorizontalAlignment = HorizontalAlignment.Center;
            panel.Margin = new Thickness(5);
            Grid.SetRow(panel, 1);
            Grid.SetColumnSpan(panel, 2);

            Grid layoutGrid = new Grid();

            LinearGradientBrush brush = new LinearGradientBrush();
            brush.StartPoint = new Point(0.5, 0);
            brush.EndPoint = new Point(0.5, 1);
            GradientStop stop = new GradientStop();

            stop = new GradientStop();
            stop.Color = Colors.LightGray;
            stop.Offset = 0.25;

            stop = new GradientStop();
            stop.Color = Color.FromArgb(0XFF, 0x4F, 0x4F, 0x4F);
            stop.Offset = 0.65;
            brush.GradientStops.Add(stop);

            layoutGrid.Background = brush;

            layoutGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(350) });
            layoutGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(50) });
            layoutGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(160) });
            layoutGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(160) });
            layoutGrid.Children.Add(captionPanel);
            //layoutGrid.Children.Add(scrollViewer2);
            layoutGrid.Children.Add(valuePanel);
            layoutGrid.Children.Add(panel);

            this._ConfirmOrderDialogWin.Content = layoutGrid;
            int columnSpan = this._LayoutContainer.ColumnDefinitions.Count;
            int rowSpan = this._LayoutContainer.RowDefinitions.Count;
            if (columnSpan > 0) Grid.SetColumnSpan(this._ConfirmOrderDialogWin, columnSpan);
            if (rowSpan > 0) Grid.SetRowSpan(this._ConfirmOrderDialogWin, rowSpan);

            if (!this._LayoutContainer.Children.Contains(this._ConfirmOrderDialogWin))
            {
                this._LayoutContainer.Children.Add(this._ConfirmOrderDialogWin);
            }

            this._ConfirmOrderDialogWin.Show();
        }
 //接受限价单下单
 private void AcceptLmtPlace(OrderTask orderTask)
 {
     LogOrder logEntity = LogEntityConvert.GetLogOrderEntity(orderTask, OperationType.OnOrderAcceptPlace, "ExecuteOrder");
     ConsoleClient.Instance.AcceptPlace(orderTask.Transaction, logEntity, AcceptPlaceCallback);
 }
        //Reject Order DialogWin
        public void ShowRejectOrderWin(string rejectMessage, OrderTask orderTask, HandleAction action)
        {
            if (this._RejectOrderDialogWin == null)
            {
                this._RejectOrderDialogWin = new XamDialogWindow()
                {
                    Width = 300,
                    Height = 140,
                    Header = "Confirm",
                    StartupPosition = Infragistics.Controls.Interactions.StartupPosition.Center,
                    IsModal = true,
                    CloseButtonVisibility = Visibility.Collapsed,
                    MinimizeButtonVisibility = Visibility.Collapsed,
                    MaximizeButtonVisibility = Visibility.Collapsed,
                };
            }
            this._OrderTask = orderTask;
            this._HandleAction = action;
            TextBlock alertLable = new TextBlock()
            {
                Name = "AlertLable",
                Foreground = new SolidColorBrush(Colors.Blue),
                Text = "Are you sure?",
                Margin = new Thickness(5),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center
            };

            TextBlock RejectOrderMessage = new TextBlock()
            {
                Name = "RejectOrderMessage",
                Foreground = new SolidColorBrush(Colors.Blue),
                Text = rejectMessage,
                Margin = new Thickness(5,15,0,0),
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center
            };

            StackPanel RejectOrderPanel = new StackPanel() { Name = "RejectOrderPanel", Orientation = Orientation.Vertical };
            RejectOrderPanel.Margin = new Thickness(15, 0, 0, 0);
            RejectOrderPanel.HorizontalAlignment = HorizontalAlignment.Left;
            RejectOrderPanel.VerticalAlignment = VerticalAlignment.Center;
            RejectOrderPanel.Children.Add(alertLable);
            RejectOrderPanel.Children.Add(RejectOrderMessage);

            Grid.SetRow(RejectOrderPanel, 0);

            //按钮
            Button RejectOrderOk = new Button() { Name = "RejectOrderOk", Content = "Yes", Width = 60, Height = 24, TabIndex = 1, Margin = new Thickness(25, 5, 0, 0) };
            Button RejectOrderCancel = new Button() { Name = "RejectOrderCancel", Content = "No", Width = 60, Height = 24, Margin = new Thickness(25, 5, 0, 0) };
            RejectOrderOk.Click += new RoutedEventHandler(RejectOrderOk_Click);
            RejectOrderCancel.Click += new RoutedEventHandler(RejectOrderCancel_Click);

            StackPanel panel = new StackPanel();
            panel.Orientation = Orientation.Horizontal;
            panel.Children.Add(RejectOrderOk);
            panel.Children.Add(RejectOrderCancel);
            panel.VerticalAlignment = VerticalAlignment.Bottom;
            panel.HorizontalAlignment = HorizontalAlignment.Center;
            panel.Margin = new Thickness(5);
            Grid.SetRow(panel, 1);

            Grid layoutGrid = new Grid();

            LinearGradientBrush brush = new LinearGradientBrush();
            brush.StartPoint = new Point(0.5, 0);
            brush.EndPoint = new Point(0.5, 1);
            GradientStop stop = new GradientStop();

            layoutGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(50) });
            layoutGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(50) });
            layoutGrid.Children.Add(RejectOrderPanel);
            layoutGrid.Children.Add(panel);

            this._RejectOrderDialogWin.Content = layoutGrid;
            int columnSpan = this._LayoutContainer.ColumnDefinitions.Count;
            int rowSpan = this._LayoutContainer.RowDefinitions.Count;
            if (columnSpan > 0) Grid.SetColumnSpan(this._RejectOrderDialogWin, columnSpan);
            if (rowSpan > 0) Grid.SetRowSpan(this._RejectOrderDialogWin, rowSpan);

            if (!this._LayoutContainer.Children.Contains(this._RejectOrderDialogWin))
            {
                this._LayoutContainer.Children.Add(this._RejectOrderDialogWin);
            }

            this._RejectOrderDialogWin.Show();
        }
 public void AddMooMocOrder(OrderTask orderTask)
 {
     this._OrderTasks.Add(orderTask);
     if (orderTask.IsBuy == BuySell.Buy)
     {
         this.SumBuyLot += orderTask.Lot.Value;
     }
     else
     {
         this.SumSellLot += orderTask.Lot.Value;
     }
 }
        public bool AllowAccept(OrderTask orderTask,QuotePolicyDetail quotePolicyDetail, bool isBuy, string marketPrice, int acceptDQVariation)
        {
            InstrumentClient instrument = orderTask.Transaction.Instrument;

            Price marketPricePrice = Price.CreateInstance(marketPrice, instrument.NumeratorUnit, instrument.Denominator);
            marketPricePrice = marketPricePrice + acceptDQVariation;

            if (quotePolicyDetail.PriceType == PriceType.OriginEnable)
            {
                marketPricePrice = marketPricePrice + quotePolicyDetail.AutoAdjustPoints + (0 - quotePolicyDetail.SpreadPoints);
            }
            else
            {
                marketPricePrice = marketPricePrice + (quotePolicyDetail.AutoAdjustPoints);
            }

            Price setPrice = new Price(orderTask.SetPrice, instrument.NumeratorUnit, instrument.Denominator);
            if (instrument.IsNormal == isBuy)
            {
                if (marketPricePrice != null)
                {
                    return setPrice > marketPricePrice;
                }
            }
            else
            {
                if (marketPricePrice != null)
                {
                    return setPrice < marketPricePrice;
                }
            }
            return false;
        }
        public void AddMooMocOrderForInstrument(OrderTask orderTask)
        {
            MooMocOrderForInstrument mooMocOrderForInstrument = null;
            mooMocOrderForInstrument = this.MooMocOrderForInstruments.SingleOrDefault(P => P.Instrument.Id == orderTask.Transaction.Instrument.Id);
            if (mooMocOrderForInstrument == null)
            {
                InstrumentClient instrument = orderTask.Transaction.Instrument;
                mooMocOrderForInstrument = new MooMocOrderForInstrument(instrument);
                this.MooMocOrderForInstruments.Add(mooMocOrderForInstrument);
            }

            mooMocOrderForInstrument.AddMooMocOrder(orderTask);
        }
 //取消单
 void RejectOrderHandle(bool yesOrNo, OrderTask orderTask, HandleAction action)
 {
     if (yesOrNo)
     {
         switch (action)
         {
             case HandleAction.OnOrderRejectPlace:
                 this.CancelTransaction(orderTask);
                 break;
             case HandleAction.OnOrderCancel:
                 this.CancelTransaction(orderTask);
                 break;
             case HandleAction.OnLMTExecute:
                 var s = "";
                 this.Commit(orderTask, string.Empty, (decimal)orderTask.Lot);
                 break;
         }
     }
 }
 private void CancelTransaction(OrderTask orderTask)
 {
     LogOrder logEntity = LogEntityConvert.GetLogOrderEntity(orderTask, OperationType.OnOrderCancel, "RejectOrder");
     ConsoleClient.Instance.Cancel(orderTask.Transaction, Manager.Common.CancelReason.DealerCanceled, logEntity, CancelTransactionCallback);
 }
 //Remove
 public void RemoveOrderTask(OrderTask orderTask)
 {
     this._OrderTasks.Remove(orderTask);
 }
 private void ShowConfirmOrderFrm(bool canDealerViewAccountInfo, OrderTask orderTask,HandleAction action)
 {
     string message = string.Empty;
     string title = string.Empty;
     this.GetAccountInforCaption(action,out message,out title);
     if (canDealerViewAccountInfo)
     {
         //just test data
         Manager.Common.AccountInformation accountInfor = ConsoleClient.Instance.GetAcountInfo(Guid.Empty);
         this._App._ConfirmOrderDialogWin.ShowDialogWin(accountInfor, title, orderTask, action);
     }
     else
     {
         if (MessageBox.Show(message, title, MessageBoxButton.YesNo) == MessageBoxResult.Yes)
         {
             this.Commit(orderTask, string.Empty, (decimal)orderTask.Lot);
         }
     }
 }