using Muchinfo.MTPClient.Data.Enums; using Muchinfo.MTPClient.Data.Model; using Muchinfo.MTPClient.Data.Model.Account; using Muchinfo.MTPClient.Infrastructure.Utilities; using System; using System.Collections.Generic; //---------------------------------------------------------------- //Module Name: $safeprojectname$ //Purpose: //CopyRight: Muchinfo //History: //---------------------------------------------------------------- //DateTime 2016/1/16 10:45:32 //Author //Description Create //---------------------------------------------------------------- using System.Windows; namespace Muchinfo.MTPClient.Trade.ViewModels { public class MakeOrderViewModel : TradeOrderBase { private List _specMemberCodes; /// /// 转单的特别会员 /// public List SpecMemberCodes { get { return _specMemberCodes; } set { Set(() => SpecMemberCodes, ref _specMemberCodes, value); } } private SpecialMember _currentSpecCode; /// /// 当前选择 特别会员代码 /// public SpecialMember CurrentSpecCode { get { return _currentSpecCode; } set { Set(() => CurrentSpecCode, ref _currentSpecCode, value); // RaisePropertyChanged(() => ProfitLossPipsSpecCodeVailed); } } private bool _relateSpecMemFlag; /// /// 是否可选择对冲的特别会员 /// public bool RelateSpecMemFlag { get { return _relateSpecMemFlag; } set { Set(() => RelateSpecMemFlag, ref _relateSpecMemFlag, value); } } private bool _isInvestorAccount = true; /// /// 是否是会员交易员 /// public bool IsInvestorAccount { get { return _isInvestorAccount; } set { Set(() => IsInvestorAccount, ref _isInvestorAccount, value); } } public Visibility PriceTipsVisibility { get; set; } public MakeOrderViewModel(QuoteGoods goods, OrderType orderType) : base(goods, orderType) { IsBidMarket = false; if (UserManager.CurrentTradeAccount.AccountType == eAccountType.ACCOUNTTYPE_TRADER) { IsInvestorAccount = false; this.CurrentOrderType = OrderType.MarketOpenOrder; ////会员交易员只有市价建仓 } PriceTipsVisibility = Visibility.Collapsed; ////注册实时行情消息 ApplicationParameter.QuotationMessenger.Register>(this, MessengerTokens.ReceiveRealTimeQuote, (quoteList) => { if (CurrentGoods != null) { QuotePrice = (IsBidDirection ? CurrentGoods.BidPrice : CurrentGoods.AskPrice); } }); } #region 止盈止损 /// /// 止盈跟据买卖设置符号方向 /// public string ProfitChar { get { if (IsBidDirection) { // StopProfit = (decimal)(MaxProfit - (decimal)PriceMinUnit); // StopLoss = (decimal)(MaxLoss + (decimal)PriceMinUnit); return "<"; } else { return ">"; // StopProfit = (decimal)(MaxProfit + (decimal)PriceMinUnit); // StopLoss = (decimal)(MaxLoss - (decimal)PriceMinUnit); } } } /// /// 止损跟据买卖设置符号方向 /// public string LossChar { get { if (IsBidDirection) { return ">"; } else { return "<"; } } } //private decimal _maxLoss; //private decimal _maxProfit; private decimal _stopLoss; /// /// StopLossChecked /// private bool _stopLossChecked; private decimal _stopProfit; /// /// StopProfitChecked /// private bool _stopProfitChecked; /// /// Sets and gets the StopLoss property. /// Changes to that property's value raise the PropertyChanged event. /// public decimal StopLoss { get { return _stopLoss; } set { Set(() => StopLoss, ref _stopLoss, value); // RaisePropertyChanged(() => ProfitLossPipsSpecCodeVailed); } } /// /// Sets and gets the StopLossChecked property. /// Changes to that property's value raise the PropertyChanged event. /// public bool StopLossChecked { get { return _stopLossChecked; } set { Set(() => StopLossChecked, ref _stopLossChecked, value); // StopLoss = _stopLossChecked ? ExecutePrice : 0; //StopLoss = _stopProfitChecked ? 0 : 0; if (IsBidDirection) { StopLoss = (decimal)(MaxLoss - MinUint); } else { StopLoss = (decimal)(MaxLoss + MinUint); } //StopLoss = _stopProfitChecked ? 0 : 0; } } /// /// Sets and gets the StopProfit property. /// Changes to that property's value raise the PropertyChanged event. /// public decimal StopProfit { get { return _stopProfit; } set { Set(() => StopProfit, ref _stopProfit, value); } } /// /// Sets and gets the StopProfitChecked property. /// Changes to that property's value raise the PropertyChanged event. /// public bool StopProfitChecked { get { return _stopProfitChecked; } set { Set(() => StopProfitChecked, ref _stopProfitChecked, value); // StopProfit = _stopProfitChecked ? ExecutePrice : 0; if (IsBidDirection) { StopProfit = (decimal)(MaxProfit + MinUint); } else { StopProfit = (decimal)(MaxProfit - MinUint); } } } public decimal MinUint { get { int temp = 0; if (this.CurrentGoods != null && this.CurrentGoods.GoodsParameters != null) { temp = CurrentGoods.GoodsParameters.HqExchFigures; } return Convert.ToDecimal(1 / Math.Pow(10, temp)); } } /// 设置最大止损价 /// public decimal MaxLoss { get { if (IsBidDirection) { //止损价 < 限价-(买点差-卖点差+止损点差) * 最小变动单位 // _currentGoods.GoodsParameters.GoodsStatus != GoodsStatusType.Open if (CurrentGoods == null || CurrentGoods.GoodsParameters == null) return 0; if (CurrentGoods.GoodsParameters.HqExchFigures < 20 && CurrentGoods.GoodsParameters.HqExchFigures > -20) { var value = (CurrentGoods.GoodsParameters.BuyptSub - CurrentGoods.GoodsParameters.SellptSub + CurrentGoods.GoodsParameters.LimitslBuyptSub) / (decimal) Math.Pow(10, CurrentGoods.GoodsParameters.HqExchFigures); return (ExecutePrice - value); } return ExecutePrice; } else { //止损价 > 限价 -(卖点差-买点差-止损点差)* 最小变动单位 //_currentGoods.GoodsParameters.GoodsStatus != GoodsStatusType.Open if (CurrentGoods == null || CurrentGoods.GoodsParameters == null) return 0; if (CurrentGoods.GoodsParameters.HqExchFigures < 20 && CurrentGoods.GoodsParameters.HqExchFigures > -20) { var value = (CurrentGoods.GoodsParameters.SellptSub - CurrentGoods.GoodsParameters.BuyptSub - CurrentGoods.GoodsParameters.LimitslSellptSub) / (decimal) Math.Pow(10, CurrentGoods.GoodsParameters.HqExchFigures); return (ExecutePrice - value); } return ExecutePrice; } } } /// /// 格式化最大止损价 /// public string DisplayMaxLoss { get { return MaxLoss.ToString(PriceFormat); } } /// /// 格式化最大止盈价 /// public string DisplayMaxProfit { get { return MaxProfit.ToString(PriceFormat); } } /// /// 设置最大止盈价 /// public decimal MaxProfit { get { if (IsBidDirection) { //限价 + (止盈点差* 最小变动单位) //止盈价 > 委托价 + (止盈点差 * 最小单位) if (CurrentGoods == null || CurrentGoods.GoodsParameters == null) return 0; if (CurrentGoods.GoodsParameters.HqExchFigures < 20 && CurrentGoods.GoodsParameters.HqExchFigures > -20) return ExecutePrice + CurrentGoods.GoodsParameters.LimittpBuyptSub / (decimal)Math.Pow(10, CurrentGoods.GoodsParameters.HqExchFigures); return ExecutePrice; } else { //止盈价 < 委托价 - (止盈点差*最小单位) if (CurrentGoods == null || CurrentGoods.GoodsParameters == null) return 0; if (CurrentGoods.GoodsParameters.HqExchFigures < 20 && CurrentGoods.GoodsParameters.HqExchFigures > -20) { var value = CurrentGoods.GoodsParameters.LimittpSellptSub / (decimal)Math.Pow(10, CurrentGoods.GoodsParameters.HqExchFigures); return ExecutePrice - value; } return ExecutePrice; } } } #endregion public override NewEntrustOrder BuildEntrustOrder() { var order = base.BuildEntrustOrder(); if (CurrentOrderType == OrderType.MarketOpenOrder && IsAllowPips) { //点差只能设置整数 order.AllowTradeSub = (int)Pips; } order.EntrustPrice = CurrentOrderType == OrderType.MarketOpenOrder ? QuotePrice : ExecutePrice; order.CurtQuotePrice = QuotePrice; // : (OrderDirection == Direction.Ask ? CurrentGoods.AskPrice : CurrentGoods.BidPrice); order.PriceMode = OrderPriceMode.MarketPrice; if (CurrentOrderType == OrderType.LimitOpenOrder) { order.SLPrice = StopLossChecked ? StopLoss : 0; order.SPPrice = StopProfitChecked ? StopProfit : 0; order.PriceMode = OrderPriceMode.LimitPrice; } //var goodsPips = UserManager.GetTraderGoodsPips( // UserManager.CurrentTradeAccount.TradeCode, // CurrentGoods.GoodsCode); //if (OrderDirection == Direction.Ask) //{ // ////委托单点差=商品点差+商品增量点差 // entrustOrder.PtSub = goodsPips.AskPips + CurrentGoods.GoodsParameters.SellptSub; // entrustOrder.CurtQuotePrice = CurrentGoods.AskPrice; //} //else //{ // ////委托单点差=商品点差+商品增量点差 // entrustOrder.PtSub = goodsPips.BidPips + CurrentGoods.GoodsParameters.BuyptSub; // entrustOrder.CurtQuotePrice = CurrentGoods.BidPrice; //} //if (UserManager.CurrentTradeAccount.AccountType == ClientAccountType.MemberTradeAccount ) //{ // order.SpecialAccount = CurrentSpecCode.TradeCode; //} return order; } public override void PostOrder(Action successAction, Action errorAction) { var entrustOrder = BuildEntrustOrder(); _orderService.MakeMarketEntrustOrder(entrustOrder, successAction, errorAction); } } }