using System; using System.Collections.Generic; using System.Linq; using System.Text; //---------------------------------------------------------------- //Module Name: $safeprojectname$ //Purpose: //CopyRight: Muchinfo //History: //---------------------------------------------------------------- //DateTime 2016/7/22 16:04:40 //Author //Description Create //---------------------------------------------------------------- using System.Windows; using System.Windows.Controls; using System.Windows.Input.StylusPlugIns; using System.Windows.Media; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Ioc; using Muchinfo.MTPClient.Data; using Muchinfo.MTPClient.Data.Enums; using Muchinfo.MTPClient.Data.Helper; using Muchinfo.MTPClient.Data.Model; using Muchinfo.MTPClient.Data.Model.Account; using Muchinfo.MTPClient.Data.Model.GoodRules; using Muchinfo.MTPClient.Infrastructure.Cache; using Muchinfo.MTPClient.Infrastructure.Utilities; using Muchinfo.MTPClient.IService; using Muchinfo.MTPClient.Infrastructure.Helpers; using Muchinfo.MTPClient.Infrastructure.MessageBox; using Muchinfo.MTPClient.Resources; namespace Muchinfo.MTPClient.Trade.ViewModels { public class TradeBaseViewModel : ViewModelBase { protected const int defaut_minLot = 1; protected const int defaut_maxLot = 88; protected IOrderService _orderService; protected IGoodsService _goodsService; private bool _isfristInit; //是否第一次初始化 protected QuoteGoods _currentGoods; //当前下单的商品 private Direction _direction; ////买卖方向 private OpenCloseMode _openCloseMode = OpenCloseMode.BUILDTYPE_OPEN; ////建仓平方式 private eListingSelectType _listingSelectModel = eListingSelectType.LISTINGSELECTTYPE_LISTING; ////挂牌点选类型 private eDelistingType _delistingModel = eDelistingType.DELISTINGTYPE_PRICE;//摘牌类型 protected GoodsOrderMode _goodsOrderMode = GoodsOrderMode.Goods; ///平仓时按单还是商品 private bool _isBusy; private ExpirationType _currentExpirationType = ExpirationType.Today; //有效期 private OrderMethods _orderFlag; ////下单方式【正常单、预埋单】 private OrderModel _orderModel = OrderModel.Normal; private string _channelBuyPrice = ""; private string _channelSellPrice = ""; private ICommonQueryService _commonQueryService; private List _spslOrders; public virtual bool ShowOpenCloseOrder { get { return ApplicationParameter.ShowOpenCloseOrder; } } private void Init() { if (_commonQueryService == null) { _commonQueryService = SimpleIoc.Default.GetInstance(); } } public TradeBaseViewModel(QuoteGoods goods, Direction direction) { _currentGoods = goods; _direction = direction; LockEditTextMaxMin(); _orderService = SimpleIoc.Default.GetInstance(); _goodsService = SimpleIoc.Default.GetInstance(); TriggerListingOrder(); GetHoldDetails(); SetInitVaules(); Init(); OpenCloseMode = (OpenCloseMode)ApplicationParameter.DefaultOpenMode; //所有商品默认为限价 //PriceMode = ePriceMode.PRICEMODE_LIMIT; setDefaultPriceMode(); //初始化多资金账号信息 CurrentUserFundsList = CacheManager.CacheTAAcountList.Select(x => x.FundsAccounts.AccountId.ToString()).ToList(); //UserManager.CurrentTradeAccount.FundsAccountId = 0; //单据成交时需重新计算委托数据 MessengerHelper.DefaultRegister(this, MessengerTokens.HolderRefresh, (e) => { GetHoldDetails(); SetMinMaxQtyVaule(); }); ////资金变化计算数量 MessengerHelper.DefaultRegister(this, MessengerTokens.MoneyNoticeToken, (e) => { GetHoldDetails(); SetMinMaxQtyVaule(); }); MessengerHelper.DefaultRegister(this, MessengerTokens.OrderChangeToRefeshTrade, (e) => { OpenCloseMode = (OpenCloseMode) ApplicationParameter.DefaultOpenMode; }); } /// /// 平仓ty /// /// /// public TradeBaseViewModel(QuoteGoods goods, OrderBase orderBase) : this(goods, orderBase.Direction == Direction.Ask ? Direction.Bid : Direction.Ask) { //初始化多资金账号信息 CurrentUserFundsList = CacheManager.CacheTAAcountList.Select(x => x.FundsAccounts.AccountId.ToString()).ToList(); RaisePropertyChanged(() => Direction); Init(); //TriggerListingOrder(); } /// /// 触发挂牌下单属性 /// private void TriggerListingOrder() { //挂牌下单 if (CacheManager.FromType == eOrderFormType.Listting) { FormType = eOrderFormType.Listting; } else { FormType = eOrderFormType.Commom; } } #region 是否忙 /// /// 是否忙 /// public bool IsBusy { get { return _isBusy; } set { Set(() => IsBusy, ref _isBusy, value); } } #endregion #region 是否是复杂下单 private bool _isComplex; /// /// 是否是复杂下单 /// public bool IsComplex { get { return _isComplex; } set { Set(() => IsComplex, ref _isComplex, value); } } #endregion #region 冻结头寸数量 /// /// 冻结头寸数量 /// private decimal _positionFzQty; /// /// 冻结头寸数量 /// public decimal PositionFzQty { get { return _positionFzQty; } set { _positionFzQty = value; } } #endregion #region 持仓汇总 /// /// 持仓汇总 /// private decimal _totalHoldDetails; /// /// 持仓汇总 /// /// The total hold details. public decimal TotalHoldDetails { get { return _totalHoldDetails; } set { Set(() => TotalHoldDetails, ref _totalHoldDetails, value); } } #endregion #region 可用持仓数量 private decimal _availHoldQty = decimal.Zero; /// /// 可用持仓数量 /// public decimal AvailHoldQty { get { return _availHoldQty; } set { Set(() => AvailHoldQty, ref _availHoldQty, value); } } #endregion #region 【10倍/20倍/30倍】保证金比例 private MarginRate _marginRate = MarginRate.Margin10; /// /// 保证金比例 /// public MarginRate MarginRate { get { return _marginRate; } set { Set(() => MarginRate, ref _marginRate, value); } } #endregion #region 【大于/小于/大于或等于/小于或等于】触发类型绑定 private Dictionary _dicTriggerType; /// /// 触发类型绑定 /// public Dictionary DicTriggerType { get { _dicTriggerType = new Dictionary(); _dicTriggerType.Add(eTriggerType.TRIGGERTYPE_GREATER_OR_EQUAL, TriggerPriceType.GreaterThanOrEqual.Discription()); _dicTriggerType.Add(eTriggerType.TRIGGERTYPE_LESS_OR_EQUAL, TriggerPriceType.LessThanOrEqual.Discription()); _dicTriggerType.Add(eTriggerType.TRIGGERTYPE_LESS, TriggerPriceType.LessThan.Discription()); _dicTriggerType.Add(eTriggerType.TRIGGERTYPE_GREATER, TriggerPriceType.GreaterThan.Discription()); return _dicTriggerType; } } #endregion #region 【买人/卖出】买卖方向 /// /// 买卖方向 /// public Direction Direction { get { return _direction; } set { if (value == Direction.unSet) { return; } Set(() => Direction, ref _direction, value); CheckedVisibleEnable(); SetMinMaxQtyVaule(); //设置数量 GetHoldDetails(); DefautEntrustPrice(this.CurrentChannelPriceMode != ChannelPriceMode.LimitPrice);//设置默认值 SetSellCloseBuyOpen(); } } #endregion #region 是否支持预埋单选项 //private bool _isEnableByPrePostOrder = false; ///// ///// Sets and gets the IsEnableByPrePostOrder property. ///// Changes to that property's value raise the PropertyChanged event. ///// //public bool IsEnableByPrePostOrder //{ // get // { // return _isEnableByPrePostOrder; // } // set // { // Set(() => IsEnableByPrePostOrder, ref _isEnableByPrePostOrder, value); // } //} public virtual bool IsEnableByPrePostOrder { get { return true; } } #endregion #region 【正常单/预埋单】下单方式 /// /// 下单方式 /// public OrderMethods OrderFlag { get { return _orderFlag; } set { if (value == OrderMethods.unSelect) { return; } Set(() => OrderFlag, ref _orderFlag, value); } } #endregion #region 正常下\SPSL下单 /// /// Gets or sets the order model. /// /// The order model. public OrderModel OrderModel { get { return _orderModel; } set { Set(() => OrderModel, ref _orderModel, value); RaisePropertyChanged(() => IsSPSLModel); RaisePropertyChanged(() => IsNormalModel); } } #endregion //===============挂牌下单属性↓======================= #region 挂牌点选类型 /// /// 挂牌点选类型 /// public eListingSelectType ListingSelectModel { get { return _listingSelectModel; } set { Set(() => ListingSelectModel, ref _listingSelectModel, value); RaisePropertyChanged(() => IsVisibility_DelistingModel); RaisePropertyChanged(() => IsExecutePriceVbs); RaisePropertyChanged(() => IsVisibility_ListingInfo); RaisePropertyChanged(() => IsExecutePrice); //RaisePropertyChanged(() => Lot); RaisePropertyChanged(() => IsEnableChangeLot); RaisePropertyChanged(() => IsVisibility_ListingSelect); ResetDelistingModel(); } } #endregion /// /// 重置摘牌类型 /// public void ResetDelistingModel() { if (ListingSelectModel != eListingSelectType.LISTINGSELECTTYPE_LISTING) { DelistingModel = eDelistingType.DELISTINGTYPE_PRICE; RaisePropertyChanged(() => DelistingModel); } } #region 摘牌类型 /// /// 摘牌类型 /// public eDelistingType DelistingModel { get { if (_delistingModel != eDelistingType.DELISTINGTYPE_SELECTED) { _delistingModel = eDelistingType.DELISTINGTYPE_PRICE; } return _delistingModel; } set { Set(() => DelistingModel, ref _delistingModel, value); RaisePropertyChanged(() => IsExecutePriceVbs); RaisePropertyChanged(() => IsVisibility_ListingInfo); RaisePropertyChanged(() => IsExecutePrice); RaisePropertyChanged(() => IsEnableChangeLot); // RaisePropertyChanged(() => Lot); } } #endregion #region 下单类型。普通下单/摘牌下单 private eOrderFormType _formType = eOrderFormType.Commom; /// /// 下单类型。普通下单/摘牌下单 /// public eOrderFormType FormType { get { return _formType; } set { Set(() => FormType, ref _formType, value); IsVisibility_Listing = Visibility.Collapsed; if (CurrentGoods.TradeMode == eTradeMode.TRADEMODE_LISTING_SELECT) { IsVisibility_Listing = Visibility.Visible; } else { IsVisibility_Listing = Visibility.Collapsed; } } } #endregion #region 摘牌下单是否可见 private Visibility _isVisibility_Listing = Visibility.Collapsed; /// /// 摘牌下单是否可见 /// public Visibility IsVisibility_Listing { get { return _isVisibility_Listing; } set { Set(() => IsVisibility_Listing, ref _isVisibility_Listing, value); } } #endregion #region 摘牌委托单号=》来自点选数据 private string _orderIdListing = CacheManager.OrderId_Listing.ToString(); /// /// 摘牌委托单号=》来自点选数据 /// public string OrderId_Listing { get { return _orderIdListing; } set { Set(() => OrderId_Listing, ref _orderIdListing, value); } } #endregion #region 摘牌委托价格=》来自点选数据 private string _orderPrice_Listing = CacheManager.OrderPrice_Listing.ToString(); /// /// 摘牌委托价格=》来自点选数据 /// public string OrderPrice_Listing { get { return _orderPrice_Listing; } set { Set(() => OrderPrice_Listing, ref _orderPrice_Listing, value); } } #endregion #region 是否显示摘牌单据信息 private Visibility _isVisibility_ListingInfo = Visibility.Collapsed; /// /// 是否显示摘牌单据信息 /// public Visibility IsVisibility_ListingInfo { get { if (CacheManager.FromType == eOrderFormType.Listting && CacheManager.OrderId_Listing != 0 && ListingSelectModel == eListingSelectType.LISTINGSELECTTYPE_DELISTING && DelistingModel == eDelistingType.DELISTINGTYPE_SELECTED) { return Visibility.Visible; } return _isVisibility_ListingInfo; } set { Set(() => IsVisibility_ListingInfo, ref _isVisibility_ListingInfo, value); } } #endregion //===============挂牌下单属性↑======================= #region 【建仓/平仓/先平后建/取消订单】建平仓方式 /// /// 建平仓方式 /// public OpenCloseMode OpenCloseMode { get { if (_openCloseMode != OpenCloseMode.BUILDTYPE_CLOSE && _openCloseMode != OpenCloseMode.BUILDTYPE_OPEN && _openCloseMode != OpenCloseMode.BUILDTYPE_CLOSETHENOPEN)// 完全不考虑拓展的吗?我现在加了一个BUILDTYPE_CLOSETHENOPEN,怎么办? { _openCloseMode = OpenCloseMode.BUILDTYPE_OPEN; } return _openCloseMode; } set { var needInit = value != _openCloseMode && (_openCloseMode == OpenCloseMode.BUILDTYPE_CLOSE || value == OpenCloseMode.BUILDTYPE_CLOSE); Set(() => OpenCloseMode, ref _openCloseMode, value); /* // 90663需求 if (_openCloseMode == OpenCloseMode.BUILDTYPE_CLOSETHENOPEN) // 如果现在选择的自动开平,那就存一个标志位 { ApplicationParameter.DefaultOpenMode = (int) OpenCloseMode.BUILDTYPE_CLOSETHENOPEN; } else { ApplicationParameter.DefaultOpenMode = (int)OpenCloseMode.BUILDTYPE_OPEN; } */ CheckedVisibleEnable(); SetMinMaxQtyVaule(); //设置数量 SetEntrustPriceRange(); if (needInit) { SetInitVaules(); } ChangeBuySellBackground(Direction.unSet); } } /// /// 点击openCloseradio Button按钮触发的事件,和枚举绑定不同的事件,必须是由手动点击触发的事件 /// public RelayCommand SelectOpenCloseCommand { get { return new RelayCommand(i => { if (i == 3) { ApplicationParameter.DefaultOpenMode = (int) OpenCloseMode.BUILDTYPE_CLOSETHENOPEN; } else { ApplicationParameter.DefaultOpenMode = (int)OpenCloseMode.BUILDTYPE_OPEN; } }); } } #endregion #region 【市价/限价】取价方式 protected ePriceMode _priceMode; /// /// 取价方式 /// public virtual ePriceMode PriceMode { get { return _priceMode; } set { if ((int)value == -1) return; Set(() => PriceMode, ref _priceMode, value); DefautEntrustPrice(); CheckedVisibleEnable(); SetMinMaxQtyVaule(); //设置数量 } } #endregion #region 【按商品/按单】平仓方式 /// /// 平仓方式 /// public virtual GoodsOrderMode GoodsOrderMode { get { return _goodsOrderMode; } set { if (value == GoodsOrderMode.unSet) { return; } var needInit = value != _goodsOrderMode; Set(() => GoodsOrderMode, ref _goodsOrderMode, value); SetMinMaxQtyVaule(); //设置数量 if (needInit) { SetInitVaules(); } } } #endregion #region 委托价格 protected decimal _executePrice; /// /// 委托价格 /// public virtual decimal ExecutePrice { get { return _executePrice; } set { Set(() => ExecutePrice, ref _executePrice, value); if(OrderModel == OrderModel.Normal) SetMinMaxQtyVaule(); ChannelBuyPrice = Convert.ToString(value); ChannelSellPrice = Convert.ToString(value); } } #endregion #region 当前选择触发价格类型 private eTriggerType _currentTriggerType = eTriggerType.TRIGGERTYPE_GREATER_OR_EQUAL; /// /// Sets and gets the 当前选择触发价格类型 property. /// Changes to that property's value raise the PropertyChanged event. /// public eTriggerType CurrentTirrgerType { get { return _currentTriggerType; } set { Set(() => CurrentTirrgerType, ref _currentTriggerType, value); } } #endregion #region 合约单位名称枚举 /// /// 合约单位名称枚举 /// public string AgreeUnitType { get { if (_currentGoods == null) { return string.Empty; } var goodsUnit = CacheManager.TradeGoodsUnit.FirstOrDefault((x) => x.UNITID == _currentGoods.GoodsParameters.AgreeUnitType); if (goodsUnit != null) { return goodsUnit.GOODSUNITNAME; } return string.Empty; } } #endregion #region 触发价格 private decimal _triggerPrice = 0; /// /// Sets and gets the 触发价格 property. /// Changes to that property's value raise the PropertyChanged event. /// public decimal TriggerPrice { get { return _triggerPrice; } set { Set(() => TriggerPrice, ref _triggerPrice, value); } } #endregion #region 【置灰】设置按键不可用 private bool _oKButtonEnabled = true; /// ///设置按键不可用IsBidAskVsb /// public bool OKButtonEnabled { get { return _oKButtonEnabled; } set { Set(() => OKButtonEnabled, ref _oKButtonEnabled, value); } } #endregion #region 【置灰】是否可平仓 /// /// 是否可平仓 /// public virtual bool IsCloseEnable { get { var buyOrSell = Direction == Direction.Ask ? Direction.Bid : Direction.Ask; //查询是否有反方向持仓 var hasHoldSummary = UserManager.HasGoodsHoldSummary(UserManager.CurrentTradeAccount.AccountId, buyOrSell, _currentGoods.GoodsId); //var holdersNum = CacheManager.GetGoodsPositionAvailableQty(dirction, _currentGoods.GoodsId, CurrentGoods.TradeProperty); //if (holdersNum > 0) //{ // _isCloseEnable = true; //} return hasHoldSummary && ApplicationParameter.ShowCloseOrder; //return true; } } #endregion #region 【当日有效/本周有效】过期类型 /// /// Sets and gets the 过期类型 property. /// Changes to that property's value raise the PropertyChanged event. /// public ExpirationType CurrentExpirationType { get { return _currentExpirationType; } set { Set(() => CurrentExpirationType, ref _currentExpirationType, value); } } #endregion #region 最大数量 private decimal _maxLot; /// /// 最大数量 /// public decimal MaxLot { get { return _maxLot; } set { Set(() => MaxLot, ref _maxLot, value); } } #endregion #region 最小数量 private decimal _minLot; /// /// 最小数量 /// public decimal MinLot { get { return _minLot; } set { Set(() => MinLot, ref _minLot, value); } } #endregion #region 最大限制数量 private decimal _limitMaxLot = Int32.MaxValue; /// /// 最大限制数量 /// public decimal LimitMaxLot { get { return _limitMaxLot; } set { Set(() => LimitMaxLot, ref _limitMaxLot, value); } } #endregion #region 最大预埋单数量 private decimal _maxPreOrderLot = decimal.Zero; /// /// 最大预埋单数量 /// public decimal MaxPreOrderLot { get { return _maxPreOrderLot; } set { Set(() => MaxPreOrderLot, ref _maxPreOrderLot, value); } } #endregion #region 最大买持仓量 private decimal _maxHolderBuyLot; /// /// 最大买持仓量 /// public decimal MaxHolderBuyLot { get { return _maxHolderBuyLot; } set { Set(() => MaxHolderBuyLot, ref _maxHolderBuyLot, value); } } #endregion #region 最大卖持仓量 private decimal _maxHolderSellLot; /// /// 最大卖持仓量 /// public decimal MaxHolderSellLot { get { return _maxHolderSellLot; } set { Set(() => MaxHolderSellLot, ref _maxHolderSellLot, value); } } #endregion #region 最大持仓量 private decimal _maxHolderLot; /// /// 最大卖仓量 /// public decimal MaxHolderLot { get { return _maxHolderLot; } set { Set(() => MaxHolderLot, ref _maxHolderLot, value); } } #endregion #region 数量 private decimal _lot = decimal.Zero; /// /// 数量 /// public decimal Lot { get { //#region 挂牌下单属性赋值=》数量 //if (CacheManager.FromType == eOrderFormType.Listting && CacheManager.OrderId_Listing != 0) //{ // if (ListingSelectModel == eListingSelectType.LISTINGSELECTTYPE_DELISTING && DelistingModel == eDelistingType.DELISTINGTYPE_SELECTED) // { // return CacheManager.OrderLot_Listing; // } //} //#endregion return _lot; } set { Set(() => Lot, ref _lot, value); RaisePropertyChanged(() => RelationNum); } } /// /// 单位 /// public string RelationNum { get { if (_currentGoods != null) { return (_currentGoods.GoodsParameters.AgreeUnit * _lot).ToString(); } else { return "-"; } } } #endregion #region 价格格式化 /// /// 价格格式化 /// public string PriceFormat { get { if (this._currentGoods != null) { return _currentGoods.FormatPrice; } else { return "F0"; } } } #endregion #region MyRegion小数位数据 /// /// /// public int DecimalCount { get { return _currentGoods.GoodsParameters.HqExchFigures; } } #endregion #region 可输入小数位数 /// /// 可输入小数位数 /// public decimal PriceMinUnit { get { int temp = 0; uint quoteMinUnit = 1; if (this._currentGoods != null && this._currentGoods.GoodsParameters != null) { //temp = _currentGoods.GoodsParameters.HqExchFigures; temp = _currentGoods.DecimalPlaces; quoteMinUnit = _currentGoods.QuoteMinUnit; } //return Convert.ToDecimal(1 / Math.Pow(10, temp)); return Convert.ToDecimal(quoteMinUnit / Math.Pow(10, temp)); } } #endregion #region 当前商品的持仓单 private List _holdDetails; /// /// 当前商品的持仓单 /// public List HoldDetails { get { return _holdDetails; } set { Set(() => HoldDetails, ref _holdDetails, value); CheckedVisibleEnable(); } } #endregion #region 当前持仓明细表 private HoldingOrder _selectOrder; /// /// 当前持仓明细表商品 /// public HoldingOrder SelectOrder { get { return _selectOrder; } set { Set(() => SelectOrder, ref _selectOrder, value); SetMinMaxQtyVaule(); CheckedVisibleEnable(); // SetInitVaules(); } } #endregion #region 最小偏移 private decimal _minUsedMargin; /// /// 最小偏移 /// public decimal MinUsedMargin { get { return _minUsedMargin; } set { Set(() => MinUsedMargin, ref _minUsedMargin, value); } } #endregion #region 标题 public virtual string SellTitle { get { return Muchinfo.MTPClient.Resources.Client_Resource.Order_OTC_Sell; } } public virtual string BuyTitle { get { return Muchinfo.MTPClient.Resources.Client_Resource.Order_OTC_Buy; } } private string _winTitle; /// /// 标题 /// public string WinTitle { get { if (OrderModel == OrderModel.SPSL) return "止盈止损"; return Muchinfo.MTPClient.Resources.Client_Resource.Order_Entruct_Titile + (Direction == Direction.Ask ? SellTitle : BuyTitle); } } #endregion #region 当前选择商品/所属市场【[混合]竞价/即期/竞价全额】 /// /// 当前选择商品 /// public QuoteGoods CurrentGoods { get { return _currentGoods; } } #endregion #region 界面项目是否显示控制 默认根据类型,如需修改刚重写 /// /// 是否显示价格类型可见 默认显示 /// public virtual bool IsPriceModeVisible { get { return true; } } /// /// 是否可显示允许点差 默认不显示 /// public virtual bool IsAllowPipsVsb { get { return false; } } private bool _isStopPLVsb; /// /// 是否显示止盈止损可见 默认不显示 /// public virtual bool IsStopPLVsb { get { return false; } } /// /// 是否有效期可见 默认不显示 /// public virtual bool IsExpirationVsb { get { return false; } } /// /// 触发类型是否可显示 默认不显示 /// public virtual bool IsTriggerTypeVsb { get { return false; } } /// /// 是否可显示人价格范围 默认不显示 /// public virtual bool IsPriceRangeVsb { get { return false; } } /// /// 是否显示买卖五档 /// public virtual bool IsBidQueueVsb { get { return false; } } /// /// 是否显示买卖价 /// public virtual bool IsBidAskVsb { get { return false; } } /// /// 是否可按单平 (不可按单平) /// public virtual bool IsCanOrderEdit { get { return true;// OpenCloseMode != OpenCloseMode.BUILDTYPE_CLOSETHENOPEN; } } /// /// 平仓是否可见 /// public virtual bool IsCloseTypeVsb { get { return OpenCloseMode != OpenCloseMode.BUILDTYPE_OPEN; } } /// /// 是否卖选项可见 /// public virtual bool IsSellVsb { get { return true; } } /// /// 是否可卖出 /// public virtual bool IsSellEnable { get { return true; } } /// /// 是否可买入 /// public virtual bool IsBuyEnable { get { return true; } } /// /// 是否最大可下单数量 /// public virtual bool IsLotMaxVsb { get { if (OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSE) { return true; } return false; } } /// /// 是否显示-建仓,平仓,先平后建 /// public virtual bool IsOpenCloseVisible { get { return true;//_currentGoods!=null&&_currentGoods.GoodsParameters.MoneyMode==eMoneyMode.MONEYMODE_MARGIN; } } public virtual string IsOpenCloseVisibleMargin { get { return IsOpenCloseVisible == true ? "0,0,0,0" : "0,25,0,0"; } } /// /// 多资金与单资金布局变化 /// public string ShowMultUserFundsMargin { get { return IsShowUserMultFundsList == Visibility.Visible ? "25,0,0,0" : "0,0,0,0"; } } /// /// 是否显示高级下单 /// public virtual bool IsOrderOptionVisible { get { return _currentGoods != null && _currentGoods.TradeMode != eTradeMode.TRADEMODE_SALE; } } #region 价格是否可编辑 /// /// 价格是否可编辑 /// public virtual bool IsExecutePrice { get { return this.PriceMode == ePriceMode.PRICEMODE_LIMIT && this.CurrentChannelPriceMode == ChannelPriceMode.LimitPrice; } } #endregion #region 渠道交易时候买入、卖出的价格 public virtual string ChannelBuyPrice { get { return (_channelBuyPrice.Equals("") || Convert.ToDouble(_channelBuyPrice) == 0) ? "--" : _channelBuyPrice; } set { Set(() => ChannelBuyPrice, ref _channelBuyPrice, value); } } public virtual string ChannelSellPrice { get { return (_channelSellPrice.Equals("") || Convert.ToDouble(_channelSellPrice) == 0) ? "--" : _channelSellPrice; } set { Set(() => ChannelSellPrice, ref _channelSellPrice, value); } } #endregion /// /// 是否可限价平 /// public virtual bool IsLimitPriceEnable { get { return true; } } /// /// 是否显示价格项 /// public virtual bool IsExecutePriceVbs { //this.OpenCloseMode != OpenCloseMode.BUILDTYPE_CLOSE; get { return PriceMode != ePriceMode.PRICEMODE_MARKET; } } public virtual string IsExecutePriceVbsMargin { get { return IsExecutePriceVbs == true ? "0,0,0,0" : "0,0,0,35"; } } /// /// 先平后建是否可用 /// public virtual bool IsOpenCloseEdit { //this.OpenCloseMode != OpenCloseMode.BUILDTYPE_CLOSE; get { return true; } } /// /// 是否可以选择建仓-默认可选 /// public virtual bool IsEnableSelectOpenMode { get { return true; } } /// /// 是否可以修改数量-默认可修改 /// public virtual bool IsEnableChangeLot { get { return true; } } /// /// 是否可按商品平仓 (不可按商品平仓) /// public virtual bool IsCanGoodsEdit { get { return true; } } /// /// 是否显示先平后建 /// public virtual bool IsCloseOpenVbs { get { return true; } } /// /// 建仓是否显示 /// public virtual bool IsOpenVbs { get { return true; } } /// /// 检查显示内容或可编辑 /// public virtual void CheckedVisibleEnable() { RaisePropertyChanged(() => IsPriceModeVisible); RaisePropertyChanged(() => IsExecutePrice); RaisePropertyChanged(() => IsBidAskVsb); RaisePropertyChanged(() => IsBidQueueVsb); RaisePropertyChanged(() => IsPriceRangeVsb); RaisePropertyChanged(() => IsTriggerTypeVsb); RaisePropertyChanged(() => IsExpirationVsb); RaisePropertyChanged(() => IsStopPLVsb); RaisePropertyChanged(() => IsAllowPipsVsb); RaisePropertyChanged(() => WinTitle); RaisePropertyChanged(() => IsCanOrderEdit); RaisePropertyChanged(() => IsCloseEnable); RaisePropertyChanged(() => IsBuyEnable); RaisePropertyChanged(() => IsSellEnable); RaisePropertyChanged(() => IsSellVsb); RaisePropertyChanged(() => IsOpenCloseVisible); RaisePropertyChanged(() => IsOpenCloseVisibleMargin); RaisePropertyChanged(() => IsOrderOptionVisible); RaisePropertyChanged(() => BuyTitle); RaisePropertyChanged(() => IsCloseTypeVsb); RaisePropertyChanged(() => IsEnableByPrePostOrder); RaisePropertyChanged(() => IsExecutePriceVbs); RaisePropertyChanged(() => IsExecutePriceVbsMargin); RaisePropertyChanged(() => IsCanGoodsEdit); RaisePropertyChanged(() => IsLimitPriceEnable); RaisePropertyChanged(() => IsEnableSelectOpenMode); RaisePropertyChanged(() => IsOpenCloseEdit); RaisePropertyChanged(() => IsEnableChangeLot); RaisePropertyChanged(() => IsCloseOpenVbs); RaisePropertyChanged(() => IsOpenVbs); RaisePropertyChanged(() => IsShowRaiseFall); RaisePropertyChanged(() => IsPrePostVisible); RaisePropertyChanged(() => IsMarketPriceVisibity); RaisePropertyChanged(() => IsVisibility_ListingSelect); RaisePropertyChanged(() => IsLotMaxVsb); RaisePropertyChanged(() => IsVisibility_DelistingModel); } #endregion #region 当前登录用户多资金信息列表 private List _currentUserFundsList = null; /// /// 当前登录用户多资金信息列表 /// public List CurrentUserFundsList { get { return _currentUserFundsList; } set { Set(() => CurrentUserFundsList, ref _currentUserFundsList, value); if (CurrentUserFundsList != null && CurrentUserFundsList.Count() > 1) { IsShowUserMultFundsList = Visibility.Visible;//显示多资金账号列表 _currentUserFundsList.Insert(0, "请选择资金账户"); UserManager.CurrentTradeAccount.FundsAccountId = 0; } else { _currentSelectedFunds = CurrentUserFundsList.First(); //单资金账号 默认选择第一个 if (!_currentSelectedFunds.Contains("请")) { UserManager.CurrentTradeAccount.FundsAccountId = ulong.Parse(_currentSelectedFunds); } } SetMinMaxQtyVaule(); } } #endregion #region 是否显示用户多资金信息列表 private Visibility _isShowUserMultFundsList = Visibility.Collapsed; /// /// 是否显示用户多资金信息列表 /// public Visibility IsShowUserMultFundsList { get { return _isShowUserMultFundsList; } set { Set(() => IsShowUserMultFundsList, ref _isShowUserMultFundsList, value); } } #endregion #region 当前选中的资金账号 private string _currentSelectedFunds = "请选择资金账户"; /// /// 当前选中的资金账号 /// public string CurrentSelectedFunds { get { return _currentSelectedFunds; } set { Set(() => CurrentSelectedFunds, ref _currentSelectedFunds, value); UserManager.CurrentTradeAccount.FundsAccountId = 0; if (!_currentSelectedFunds.Contains("请")) { UserManager.CurrentTradeAccount.FundsAccountId = ulong.Parse(CurrentSelectedFunds); } SetMinMaxQtyVaule(); } } #endregion /// /// 是否显示-点选成交 /// public virtual bool IsVisibility_ListingSelect { get { return false; } } /// /// 是否显示市价下单 /// public virtual bool IsMarketPriceVisibity { get { return true; } } /// /// 是否显示涨跌停 /// public virtual bool IsShowRaiseFall { get { return false; } } /// /// 是否显示预埋单功能 /// public bool IsPrePostVisible { get { return ApplicationParameter.IsPrePostVisible == 1; //// } } /// /// /// /// protected void GetHoldDetails() { if (this.CurrentGoods != null) { //var holdingOrders = (CurrentGoods.TradeMode == eTradeMode.Full_Transfer ? CacheManager.CacheRealGoodsPositionList : CacheManager.CacheGoodsPositionList);// UserManager.GetCacheOrders(); var holdingOrders = CacheManager.CacheGoodsPositionList;// UserManager.GetCacheOrders(); if (holdingOrders == null || !holdingOrders.Any()) { SetMinMaxQtyVaule(); return; } var direction = _direction == Direction.Ask ? Direction.Bid : Direction.Ask; HoldDetails = CacheManager.GetGoodsPositionList(direction, (uint)CurrentGoods.GoodsParameters.GoodsId, CurrentGoods.TradeMode);//holdingOrders.Where((item) => item.GoodsId == CurrentGoods.GoodsParameters.GoodsId && item.Direction == direction).ToList(); SelectOrder = HoldDetails.FirstOrDefault(); } } /// /// 提交表单 /// /// 成功回调 /// 错误返回 public virtual void PostOrder(Action successAction, Action errorAction) { } /// /// 创建基本单据 /// /// public virtual NewEntrustOrder BuildEntrustOrder() { var newOrder = new NewEntrustOrder() { BuyOrSell = Direction, GoodsCode = this.CurrentGoods.GoodsCode, OperaterId = UserManager.CurrentTradeAccount.LoginID, GoodsId = (uint)this.CurrentGoods.GoodsParameters.GoodsId, AccountType = UserManager.CurrentTradeAccount.AccountType, BuildType = OpenCloseMode, EntrurstTime = ApplicationParameter.ServerTimeNow, MemberAreaId = UserManager.CurrentTradeAccount.MemberAreaId, EntrustQuantity = Lot, PriceMode = this.PriceMode, ValidType = this.CurrentExpirationType, TriggerType = (uint)this._currentTriggerType, TriggerPrice = this.TriggerPrice, MarketId = this.CurrentGoods.MarketID, TradeMode = CurrentGoods.TradeMode, LoginID = UserManager.CurrentTradeAccount.LoginID, AccountId = UserManager.CurrentTradeAccount.FundsAccountId, OrderFlag = (uint)this.OrderFlag, OrderFormType = eOrderFormType.Commom, ChannelPriceMode = this.CurrentChannelPriceMode, CurrentGoods = this.CurrentGoods, Ip = ApplicationParameter.PublisgNetIp, }; ApplicationParameter.MakeSpsl(newOrder); // if (FormType == eOrderFormType.Listting) if (_currentGoods.TradeMode == eTradeMode.TRADEMODE_LISTING_SELECT) { newOrder.OrderFormType = eOrderFormType.Listting; newOrder.ListingSelectType = ListingSelectModel; if (ListingSelectModel != eListingSelectType.LISTINGSELECTTYPE_LISTING) { newOrder.DelistingType = DelistingModel; } if (ListingSelectModel == eListingSelectType.LISTINGSELECTTYPE_DELISTING && DelistingModel == eDelistingType.DELISTINGTYPE_SELECTED) { newOrder.RelationTicket = (ulong)CacheManager.OrderId_Listing; } } #region 注销BY DK //if (UserManager.CurrentTradeAccount.FundsAccounts.Any() && UserManager.CurrentTradeAccount.FundsAccounts[0] != null) //{ // newOrder.AccountId = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId; // if (newOrder.AccountId == 0) // { // newOrder.AccountId = UserManager.CurrentTradeAccount.AccountId; // } //} //else //{ // newOrder.AccountId = UserManager.CurrentTradeAccount.AccountId; //} #endregion // newOrder.EntrustPrice = ExecutePrice;// 买卖按钮变化了。所以不需要这样传值 // 点击界面上的买入卖出,会触犯买卖方向的变化。所以直接用买卖方向来判断,应该可以 if (ChannelBuyPrice.Equals("--")) { newOrder.EntrustPrice = 0; } else { if (newOrder.BuyOrSell == Direction.Bid) // 买入 { newOrder.EntrustPrice = Convert.ToDecimal(ChannelBuyPrice); } else if (newOrder.BuyOrSell == Direction.Ask)// 卖出 { newOrder.EntrustPrice = Convert.ToDecimal(ChannelSellPrice); } } //直接获取单据价格-挂牌单据 if (ListingSelectModel == eListingSelectType.LISTINGSELECTTYPE_DELISTING && DelistingModel == eDelistingType.DELISTINGTYPE_SELECTED) { newOrder.EntrustPrice = CacheManager.OrderPrice_Listing;//OrderPrice_Listing; } // newOrder.RelationTicket = 0; #region MTP2.0 注销 ////按单平 //if (OpenCloseMode != OpenCloseMode.BUILDTYPE_OPEN && GoodsOrderMode == GoodsOrderMode.Order) //{ // newOrder.RelationTicket = SelectOrder == null ? 0 : SelectOrder.OrderID; //} #endregion if (CurrentUserFundsList != null && CurrentUserFundsList.Count() == 1) { newOrder.AccountId = ulong.Parse(CurrentUserFundsList.FirstOrDefault()); } return newOrder; } /// /// 输入的价格是否有效 /// /// /// protected bool CheckExecutePrice(decimal price) { int temp = CurrentGoods.GoodsParameters.HqExchFigures; if (price >= 0 && price <= 1000000) { var pic = price % (1 / ((decimal)Math.Pow(10, temp))); return pic == 0; } else { return false; } } /// /// 设置价格范围 /// protected virtual void SetEntrustPriceRange() { } /// /// 验证数据 /// /// /// public virtual bool Validated(ref string msg) { #region if (CurrentUserFundsList != null && CurrentUserFundsList.Count() > 1 && CurrentSelectedFunds.Contains("请")) { msg = "请选择资金账户"; return false; } if (Lot > 9223372036854775807) { msg = "超出最大委托数量"; return false; } //var isclose = OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSE || // (CurrentGoods != null && CurrentGoods.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_PAY && // Direction == Direction.Ask); //if (!IsOpenCloseEdit && OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSETHENOPEN && CurrentGoods.GoodsParameters.MoneyMode != eMoneyMode.MONEYMODE_PAY) //{ // msg = Muchinfo.MTPClient.Resources.Client_Resource.OpenClose_IsNotAllow; // return false; //} //if (!IsEnableSelectOpenMode && OpenCloseMode == OpenCloseMode.BUILDTYPE_OPEN && CurrentGoods.GoodsParameters.MoneyMode != eMoneyMode.MONEYMODE_PAY) //{ // msg = Muchinfo.MTPClient.Resources.Client_Resource.Open_IsNotAllow; // return false; //} //if (!IsCloseEnable && OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSE && CurrentGoods.GoodsParameters.MoneyMode != eMoneyMode.MONEYMODE_PAY) //{ // msg = Muchinfo.MTPClient.Resources.Client_Resource.Close_IsNotAllow; // return false; //} //if (Lot <= 0 || Lot == decimal.Zero) //{ // //数量不在正确范围内 // msg = Muchinfo.MTPClient.Resources.Client_Resource.Lot_Vailed_MustUpOfZero; // return false; //} ////可用资金不足,最小交易数量为{0}! ////if (OpenCloseMode != OpenCloseMode.BUILDTYPE_CLOSE && MinLot > MaxLot) ////{ //// msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.EntrustOrderViewModel_MinLotLargeThanMaxLot, MinLot); ; //// return false; ////} ////可用资金不足,最小交易数量为{0}! ////if (!isclose && MinLot > MaxLot) ////{ //// msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.EntrustOrderViewModel_MinLotLargeThanMaxLot, MinLot); ; //// return false; ////} //if (Lot > MaxLot) //{ // //msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Lot_Open_DownOfMaxMinOpenLot, MaxLot, MinLot); // msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.EntrustOrderViewModel_OpenLotGreatThanMaxLot, MaxLot); ; // return false; //} //if (!isclose && Lot < MinLot) //{ // //单笔数量最小为:{0} // msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.EntrustOrderViewModel_MinInputNum, MinLot); // return false; //} //if (MinLot != 0 && (Lot % MinLot) != 0) //{ // // 1.将商品交易规则项“单笔最小建仓数量”更名为“单笔最小交易数量”,“单笔最大建仓数量”更名为“单笔最大交易数量”; // //2.服务端,客户端实现:平仓数量不是最小交易数量整数倍的,能且只能将剩余可用数量全部平仓, // // 即:平仓数量!=单笔最小交易数量*int(平仓数量/单笔最小交易数量), // //2.1若:平仓数量=剩余可平数量,平仓数量可平; // //2.2若:平仓数量!=剩余可平数量,平仓数量不可平,服务端或者客户端提示“平仓数量不是单笔最小交易数量{显示单笔最小交易数量}整数倍,只能将剩余可用数量全部平仓”,提示方式和校验时点按照之前逻辑; // if (!isclose) // { // //数量输入有误!应为{0}的倍数. // msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.EntrustOrderViewModel_InputNumShouldBeRight, MinLot); // return false; // } // else if (Lot != MaxLot) // { // msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.TradeClose_ErrorTips, MinLot); // return false; // } //} //if (this.PriceMode != ePriceMode.PRICEMODE_MARKET && !CheckExecutePrice(ExecutePrice)) //{ // //msg = "委托价格不在提示范围内"; // msg = Muchinfo.MTPClient.Resources.Client_Resource.ErrorEntrustPrice; // return false; //} //if (this.OrderFlag == OrderMethods.PreOrder && TriggerPrice <= 0) //{ // //msg = "触发价格需要大于0"; // msg = Muchinfo.MTPClient.Resources.Client_Resource.Error_TriggerPriceNeedGreaterThanZero; // return false; //} //if (this.OrderFlag == OrderMethods.PreOrder && ApplicationParameter.MaxPrePostOrderLot > 0 && MaxPreOrderLot >= ApplicationParameter.MaxPrePostOrderLot) //{ // //msg = "预埋单最多可保留{0}条,请撤销部分单据后进行提交"; // msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Error_MaxPrePostOrderLot, ApplicationParameter.MaxPrePostOrderLot); // return false; //} return true; #endregion } /// /// 设置更新下单数量 /// protected virtual void SetMinMaxQtyVaule() { } /// /// 是否显示摘牌类型 /// public virtual bool IsVisibility_DelistingModel { get { return false; } } /// /// 所有权商品,买建卖平显示 /// protected virtual void SetSellCloseBuyOpen() { } #region 计算可下单数量 /// /// 根据可用资金算出可下单的数量 /// /// protected decimal GetEnableNum(decimal price) { decimal enablenum = 0; decimal usableFunds = 0; decimal dividernum = 0; //可用资金[多资金账户] usableFunds = UserManager.GetCurrentUsableFundsByAccountId(UserManager.CurrentTradeAccount.FundsAccountId);//UserManager.CurrentAccountUsableFunds(); if (usableFunds > 0) { #region 计算可购买 dividernum = GetDivider(price); if (dividernum != 0) { var calcLot = usableFunds / dividernum; if (calcLot <= 0) { enablenum = 0; } else if (calcLot >= int.MaxValue) { enablenum = int.MaxValue; } else { enablenum = calcLot; //数量 } } else ////不收任何费用时显示最大值 { return int.MaxValue; } return enablenum > 0 ? enablenum : 0; #endregion } else { return 0;//没有资金不可以买 } } /// /// 每手下单所需资金 /// /// 价格 /// private decimal GetDivider(decimal price) { decimal dividernum = 0; decimal dividernumChange = 0; if (Direction == Direction.Bid) { //【买】建仓手续费 dividernumChange = GetTradeFeeBy(eTradeFeeType.TRADEFEETYPE_TRADECHARGE, price); } else { //【卖】建仓手续费 dividernumChange = GetTradeFeeBy(eTradeFeeType.TRADEFEETYPE_TRADECHARGE, price); } //竞价全额 if (_currentGoods != null)// && _currentGoods.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_PAY) { //dividernum = _currentGoods.CurrentPrice == 0 ? _currentGoods.LastClose : _currentGoods.CurrentPrice; dividernum = price * _currentGoods.AgreeUnit + dividernumChange; return dividernum; } return GetTradeFeeBy(eTradeFeeType.TRADEFEETYPE_TRADECHARGE, price) + dividernumChange; } /// /// 获取指定【交易费用类型】的费用 /// /// /// /// private decimal GetTradeFeeBy(eTradeFeeType tradeFeeType, decimal price) { decimal dividerTradeFee = 0; #region 类型:建仓保证金 //获取交易费用类型=建仓保证金 var eTradeFee = _goodsService.GetTradeFee(_currentGoods.TradeMode, tradeFeeType); GoodsFeeType goodsfee = null; GoodsFeeType accountfee = null; #endregion if (_currentGoods != null && CacheManager.TradeGoodsFeeRules != null && CacheManager.TradeGoodsFeeRules.ContainsKey((int)_currentGoods.GoodsId)) { #region 类型:建仓保证金 if (CacheManager.TradeGoodsFeeRules[(int)_currentGoods.GoodsId].GoodsFees.ContainsKey((int)eTradeFee)) { goodsfee = CacheManager.TradeGoodsFeeRules[(int)_currentGoods.GoodsId].GoodsFees[(int)eTradeFee]; } if (CacheManager.TradeGoodsFeeRules[(int)_currentGoods.GoodsId].AccountGoodsFees.ContainsKey((int)eTradeFee)) { accountfee = CacheManager.TradeGoodsFeeRules[(int)_currentGoods.GoodsId].AccountGoodsFees[(int)eTradeFee]; } #endregion } #region 类型:建仓保证金 //商品是总额百分比模式 if (goodsfee != null && (int)eCalMode.CALMODE_FIXEDRATIO == goodsfee.FeeMode) { //可用资金/合约单位*价格*占用百分比 或者可用资金/合约单位固定值 if (accountfee != null) { switch ((int)accountfee.FeeMode) { case (int)eCalMode.CALMODE_FIXEDRATIO: dividerTradeFee = (_currentGoods.GoodsParameters.AgreeUnit) * price * (accountfee.FeeValue + goodsfee.FeeValue); break; case (int)eCalMode.CALMODE_FIXEDNUMBER: dividerTradeFee = (_currentGoods.GoodsParameters.AgreeUnit) * price * goodsfee.FeeValue + accountfee.FeeValue; break; } } else { dividerTradeFee = (_currentGoods.GoodsParameters.AgreeUnit) * price * goodsfee.FeeValue; } } //商品是合约单位固定值的模式 else if (goodsfee != null && (int)eCalMode.CALMODE_FIXEDNUMBER == goodsfee.FeeMode) { //可用资金/合约单位*价格*占用百分比 或者可用资金/合约单位固定值 if (accountfee != null) { switch ((int)accountfee.FeeMode) { case (int)eCalMode.CALMODE_FIXEDRATIO: dividerTradeFee = (_currentGoods.GoodsParameters.AgreeUnit) * price * accountfee.FeeValue + goodsfee.FeeValue; break; case (int)eCalMode.CALMODE_FIXEDNUMBER: dividerTradeFee = accountfee.FeeValue + goodsfee.FeeValue; break; } } else { dividerTradeFee = goodsfee.FeeValue; } } #endregion return dividerTradeFee; } /// /// 设置 /// protected virtual void DefautEntrustPrice(bool isUpdateLimitePrice = true) { if (this._currentGoods == null) { return; } if (this.PriceMode == ePriceMode.PRICEMODE_LIMIT) { switch (this._currentGoods.TradeMode) { case eTradeMode.TRADEMODE_MARKETMAKE: ExecutePrice = _direction == Direction.Ask ? _currentGoods.AskPrice : _currentGoods.BidPrice; break; case eTradeMode.TRADEMODE_BIDDING: case eTradeMode.TRADEMODE_LISTING_SELECT: // 需求 #25835 竞价市场下点击下单类型为限价时,自动将买一卖一价带入价格框,若无买一卖一,则取昨收价。 ExecutePrice = _direction == Direction.Ask ? _currentGoods.BidPrice : _currentGoods.AskPrice; if (ExecutePrice <= 0) { //任务 #26769 //竞价市场-》-》限价-》默认价格 为昨收OR最新价 ExecutePrice = _currentGoods.CurrentPrice == 0 ? _currentGoods.LastClose : _currentGoods.CurrentPrice; } break; case eTradeMode.TRADEMODE_ENTRUST_HEDGE: switch (CurrentChannelPriceMode) { case ChannelPriceMode.MatchPrice: ExecutePrice = Direction == Direction.Ask ? _currentGoods.BidPrice : _currentGoods.AskPrice; ChannelBuyPrice = Convert.ToString(_currentGoods.AskPrice); ChannelSellPrice = Convert.ToString(_currentGoods.BidPrice); break; case ChannelPriceMode.MarketPrice: ChannelBuyPrice = "0"; ChannelSellPrice = "0"; ExecutePrice = 0; break; // 4、若价格选择为超价, // 买入按钮上价格取卖价(卖一价)+配置的超价点数*行情最小变动单位*10^行情小数位, // 卖出按钮上价格取买价(买一价)-配置的超价点数*行情最小变动单位*10^行情小数位,买卖价变动时价格需要跟着变动; case ChannelPriceMode.SuperPrice: double superPoint = SystemParamManager.getChannelSuperPoint; var changeValue = superPoint * _currentGoods.QuoteMinUnit / Math.Pow(10, _currentGoods.DecimalPlaces); ExecutePrice = Direction == Direction.Ask ? _currentGoods.BidPrice == 0 ? 0 : (_currentGoods.BidPrice - (decimal)changeValue) : _currentGoods.AskPrice == 0 ? 0 : (_currentGoods.AskPrice + (decimal)changeValue); ChannelBuyPrice = Convert.ToString(_currentGoods.AskPrice == 0 ? 0 : (_currentGoods.AskPrice + (decimal)changeValue)); ChannelSellPrice = Convert.ToString(_currentGoods.BidPrice == 0 ? 0 : (_currentGoods.BidPrice - (decimal)changeValue)); break; case ChannelPriceMode.LastestPrice: ExecutePrice = _currentGoods.CurrentPrice; ChannelBuyPrice = Convert.ToString(_currentGoods.CurrentPrice); ChannelSellPrice = Convert.ToString(_currentGoods.CurrentPrice); break; case ChannelPriceMode.LimitPrice: if (isUpdateLimitePrice) { ExecutePrice = Direction == Direction.Ask ? _currentGoods.BidPrice : _currentGoods.AskPrice; } ChannelBuyPrice = Convert.ToString(ExecutePrice); ChannelSellPrice = Convert.ToString(ExecutePrice); break; default: ExecutePrice = Direction == Direction.Ask ? CurrentGoods.BidPrice : CurrentGoods.AskPrice; ChannelBuyPrice = Convert.ToString(_currentGoods.BidPrice); ChannelSellPrice = Convert.ToString(_currentGoods.AskPrice); break; } break; default: break; } } else if (this.PriceMode == ePriceMode.PRICEMODE_MARKET) { switch (this._currentGoods.TradeMode) { case eTradeMode.TRADEMODE_MARKETMAKE: ExecutePrice = _direction == Direction.Ask ? _currentGoods.AskPrice : _currentGoods.BidPrice; break; case eTradeMode.TRADEMODE_BIDDING: case eTradeMode.TRADEMODE_BIDDINGMARKETMAKE: case eTradeMode.TRADEMODE_ENTRUST_HEDGE: //市价默认价格 ExecutePrice = 0; ChannelBuyPrice = "0"; ChannelSellPrice = "0"; break; } } } /// /// 设置默认下单数量,设置建仓平仓时使用 /// protected void SetInitVaules() { // 需求 #29897客户端下单平仓的时候,默认不要全部卖出,可以默认卖出0手,需要修改后才可以进行平仓;[建仓平仓都按这个规则] if ((OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSE || (_currentGoods.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_PAY && Direction == Direction.Ask))) ///全部平仓 { /*var currentAccount = UserManager.CurrentTradeAccount.FundsAccountId;// == 0 ? CacheManager.FundsAccountId : UserManager.CurrentTradeAccount.FundsAccountId; if (currentAccount == 0) return; TradePositionModel t = CacheManager.GetHoldingSummary(_currentGoods.GoodsId, currentAccount.ToString()); if (t == null) { Lot = MaxLot; return; } var qty = Direction == Direction.Ask ? t.AvailableBuyHolderQty() : t.AvailableSellHolderQty(); Lot = qty;*/ Lot = MaxLot; } else { if (ApplicationParameter.DefaultOrderLot == 0) { Lot = MinLot; } else { Lot = ApplicationParameter.DefaultOrderLot; ////默认下单数量 } } } #endregion /// /// 设置默认价格模式[读取数据库配置--设置] /// protected virtual void setDefaultPriceMode() { //所有商品默认为限价 PriceMode = ePriceMode.PRICEMODE_LIMIT; } public override void Cleanup() { base.Cleanup(); MessengerHelper.DefaultUnregister(this, MessengerTokens.HolderRefresh); MessengerHelper.DefaultUnregister(this, MessengerTokens.MoneyNoticeToken); MessengerHelper.QuoteUnregister>(this, MessengerTokens.ReceiveRealTimeQuote); } /// /// 获取预埋单-可下最最大数量 /// protected void GetPrePostOrderMaxQty() { ulong currentAccountId; if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any()) { currentAccountId = (uint)UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId; } else { currentAccountId = UserManager.CurrentTradeAccount.AccountId; } _goodsService.QueryPrePostDetailQty(currentAccountId, QueryPreOrderParameterSuccess, ErrorPreOrderParameterCallBack); } /// /// 委托单参数查询-成功返回 /// /// protected void QueryPreOrderParameterSuccess(List itemList) { if (itemList != null) { MaxPreOrderLot = itemList.FirstOrDefault().maxPreOrderLot; } } /// /// 委托单参数查询-失败返回 /// /// private void ErrorPreOrderParameterCallBack(ErrorEntity errorEntity) { IsBusy = false; } /// /// 设置订单委托价格 /// /// public void SetOrderPrice(decimal price) { if (PriceMode == ePriceMode.PRICEMODE_LIMIT) { if (price > 0) { ExecutePrice = price; } } } #region 通道交易相关属性及方法 /// /// 是否通道交易模式 /// public virtual bool IsVisibilityChannelTrade { get { return false; } } /// /// 通道交易价格方式字典 /// public Dictionary ChannelPriceModeList { get { var dic1 = new Dictionary { {ChannelPriceMode.LastestPrice, ChannelPriceMode.LastestPrice.Discription()}, {ChannelPriceMode.MatchPrice, ChannelPriceMode.MatchPrice.Discription()}, {ChannelPriceMode.MarketPrice, ChannelPriceMode.MarketPrice.Discription()}, {ChannelPriceMode.SuperPrice, ChannelPriceMode.SuperPrice.Discription()}, {ChannelPriceMode.LimitPrice, ChannelPriceMode.LimitPrice.Discription()}, }; var dic2 = new Dictionary // 不支持市价 { {ChannelPriceMode.LastestPrice, ChannelPriceMode.LastestPrice.Discription()}, {ChannelPriceMode.MatchPrice, ChannelPriceMode.MatchPrice.Discription()}, {ChannelPriceMode.SuperPrice, ChannelPriceMode.SuperPrice.Discription()}, {ChannelPriceMode.LimitPrice, ChannelPriceMode.LimitPrice.Discription()}, }; return ApplicationParameter.CanMarketPrice(CurrentGoods) ? dic1 : dic2; } } private ChannelPriceMode _currentChannelPriceMode; /// /// 当前通道交易价格方式 /// public ChannelPriceMode CurrentChannelPriceMode { get { return _currentChannelPriceMode; } set { Set(() => CurrentChannelPriceMode, ref _currentChannelPriceMode, value); var priceMode = value == ChannelPriceMode.MarketPrice ? ePriceMode.PRICEMODE_MARKET : ePriceMode.PRICEMODE_LIMIT; if ((int) priceMode == -1) return; PriceMode = priceMode; } } /// /// 止盈止损价格类型 /// /// The channel price mode list. public Dictionary ChannelSPSLPriceModeList { get { var dic = new Dictionary { {ChannelPriceMode.LastestPrice, ChannelPriceMode.LastestPrice.Discription()}, {ChannelPriceMode.MatchPrice, ChannelPriceMode.MatchPrice.Discription()}, {ChannelPriceMode.SuperPrice, ChannelPriceMode.SuperPrice.Discription()}, {ChannelPriceMode.MarketPrice, ChannelPriceMode.MarketPrice.Discription()} }; var dic1 = new Dictionary { {ChannelPriceMode.LastestPrice, ChannelPriceMode.LastestPrice.Discription()}, {ChannelPriceMode.MatchPrice, ChannelPriceMode.MatchPrice.Discription()}, {ChannelPriceMode.SuperPrice, ChannelPriceMode.SuperPrice.Discription()} }; return ApplicationParameter.CanMarketPrice(CurrentGoods) ? dic : dic1; } } /// /// 是否止盈止损 /// /// true if this instance is SPSL model; otherwise, false. public virtual bool IsSPSLModel { get { return OrderModel == OrderModel.SPSL; } } /// /// 是否正常下单 /// /// true if this instance is normal model; otherwise, false. public virtual bool IsNormalModel { get { return OrderModel == OrderModel.Normal; } } private SPSLOrderType _currentSPSLOrderType; /// /// 止盈止损类型【止损单/止盈单/撤单】 /// /// The type of the current SPSL order. public SPSLOrderType CurrentSPSLOrderType { get { return _currentSPSLOrderType; } set { Set(() => CurrentSPSLOrderType, ref _currentSPSLOrderType, value); RaisePropertyChanged(() => TriggerPriceMode); UpdateSPSLPriceRange(); } } private string _holdAvgPriceDisplay; /// /// 持仓均价 /// /// The hold average price display. public string HoldAvgPriceDisplay { get { return _holdAvgPriceDisplay; } set { Set(() => HoldAvgPriceDisplay, ref _holdAvgPriceDisplay, value); } } private string _directionDisplay; /// /// 止盈止损方向 /// /// The hold average price display. public string DirectionDisplay { get { return _directionDisplay; } set { Set(() => DirectionDisplay, ref _directionDisplay, value); } } private string _holdTotalQtyDisplay; /// /// 持仓数量 /// /// The hold total qty display. public string HoldTotalQtyDisplay { get { return _holdTotalQtyDisplay; } set { Set(() => HoldTotalQtyDisplay, ref _holdTotalQtyDisplay, value); } } /// /// Gets the trigger price mode. /// /// The trigger price mode. public string TriggerPriceMode { get { if (CurrentSPSLOrderType == SPSLOrderType.SPOrder) return "止盈价"; return "止损价"; } } protected decimal _spslTriggerPrice; /// /// 资管止盈止损触发价 /// public virtual decimal SPSLTriggerPrice { get { return _spslTriggerPrice; } set { Set(() => SPSLTriggerPrice, ref _spslTriggerPrice, value); } } protected decimal _spslTriggerMinPrice; /// /// 资管止盈止损触发价最小值 /// public virtual decimal SPSLTriggerMinPrice { get { return _spslTriggerMinPrice; } set { Set(() => SPSLTriggerMinPrice, ref _spslTriggerMinPrice, value); } } protected decimal _spslTriggerMaxPrice; /// /// 资管止盈止损触发价最小值 /// public virtual decimal SPSLTriggerMaxPrice { get { return _spslTriggerMaxPrice; } set { Set(() => SPSLTriggerMaxPrice, ref _spslTriggerMaxPrice, value); } } /// /// 更新止盈止损触发价范围 /// private void UpdateSPSLPriceRange() { //持仓单方向为买——止盈价格需大于最新价,止损价格需要小于最新价; if (this.Direction == Direction.Ask) { if (this.CurrentSPSLOrderType == SPSLOrderType.SPOrder) { SPSLTriggerMinPrice = CurrentGoods.CurrentPrice; SPSLTriggerMaxPrice = decimal.MaxValue; }else{ SPSLTriggerMinPrice = 0; SPSLTriggerMaxPrice = CurrentGoods.CurrentPrice; } } //持仓单方向为卖——止盈价格需小于最新价,止损价格需要大于最新价。 if (this.Direction == Direction.Bid) { if (this.CurrentSPSLOrderType == SPSLOrderType.SPOrder) { SPSLTriggerMinPrice = 0; SPSLTriggerMaxPrice = CurrentGoods.CurrentPrice; } else { SPSLTriggerMinPrice = CurrentGoods.CurrentPrice; SPSLTriggerMaxPrice = decimal.MaxValue; } } SPSLTriggerPrice = CurrentGoods.CurrentPrice; } #endregion #region 90705 因为止盈止损单由服务端触发,最好每次都取服务端的数据 /// /// 下面四个是用于设置止盈价止损价的最大最小值 /// private decimal _slMaxPrice; private decimal _slMinPrice; private decimal _spMaxPrice; private decimal _spMinPrice; /// /// 止损的最大值 /// public decimal SlMaxPrice { get { return _slMaxPrice; } set { Set(() => SlMaxPrice, ref _slMaxPrice, value); } } /// /// 止损的最小值 /// public decimal SlMinPrice { get { return _slMinPrice; } set { Set(() => SlMinPrice, ref _slMinPrice, value); } } /// /// 止盈的最大值 /// public decimal SpMaxPrice { get { return _spMaxPrice; } set { Set(() => SpMaxPrice, ref _spMaxPrice, value); } } /// /// 止盈的最小值 /// public decimal SpMinPrice { get { return _spMinPrice; } set { Set(() => SpMinPrice, ref _spMinPrice, value); } } /// /// 根据买卖方向来锁定输入框的输入最大值最小值 /// private void LockEditTextMaxMin() { //持仓单方向为买——止盈价格需大于最新价,止损价格需要小于最新价; if (this.Direction == Direction.Ask) // 买持仓 { SpMinPrice = /*CurrentGoods.CurrentPrice 别问我为什么不用这个了,因为没有办法做到,当设置成0的时候,控件自动设置为最小值,这样就影响到的判断*/0; SpMaxPrice = decimal.MaxValue; SlMinPrice = 0; SlMaxPrice = /*CurrentGoods.CurrentPrice*/decimal.MaxValue;// 最大值也会有这样的问题,当输入数字的大于最大值,失去焦点后,这个值会恢复到空间的最大值。 } //持仓单方向为卖——止盈价格需小于最新价,止损价格需要大于最新价。 if (this.Direction == Direction.Bid) // 卖持仓 { SpMinPrice = 0; SpMaxPrice = /*CurrentGoods.CurrentPrice*/decimal.MaxValue; SlMinPrice = /*CurrentGoods.CurrentPrice*/0; SlMaxPrice = decimal.MaxValue; } // 给输入框绑定默认值 SpPrice = (double)CurrentGoods.CurrentPrice; SlPrice = (double)CurrentGoods.CurrentPrice; } #region 做设置止盈止损价时候,止盈止损价超出了价格范围时的提示 /// /// 检测止盈价止损价输入是否合法 /// --此方法就有提示了,不需要再外面处理 /// /// true 合法 public bool CheckProfitLoss() { if (OrderModel == OrderModel.SPSL)// 止盈止损的下单模式下,我才会处理,其他的模式都放过 { if (!_canUseSpPrice && !_canUseSlPrice) { CheckTips(Client_Resource.Use_SpPrice_Or_SlPrice); return false; } //买方向持仓止盈价格设置小于最新价时,提示“止盈价格必须高于该合约最新价,请重新设置” //买方向持仓止损价格设置大于最新价时,提示“止损价格必须低于该合约最新价,请重新设置” if (this.Direction == Direction.Ask) // 买持仓 { if (_canUseSpPrice && SpPrice <= (double)CurrentGoods.CurrentPrice) // 买方向持仓止盈价格设置小于最新价时 { // 提示“止盈价格必须高于该合约最新价,请重新设置” CheckTips(Client_Resource.SpPrice_High_than_Last_Price); return false; } else if (_canUseSlPrice && SlPrice >= (double)CurrentGoods.CurrentPrice) // 买方向持仓止损价格设置大于最新价时 { // 提示“止损价格必须低于该合约最新价,请重新设置” CheckTips(Client_Resource.SlPrice_Low_than_Last_Price); return false; } } // 卖方向持仓止盈价格设置大于最新价时,提示“止盈价格必须低于该合约最新价,请重新设置” // 卖方向持仓止损价格设置小于最新价时,提示“止损价格必须高于该合约最新价,请重新设置” else if (this.Direction == Direction.Bid) // 卖持仓 { if (_canUseSpPrice && SpPrice >= (double)CurrentGoods.CurrentPrice) // 卖方向持仓止盈价格设置大于最新价时 { // 提示“止盈价格必须低于该合约最新价,请重新设置” CheckTips(Client_Resource.SpPrice_Low_than_Last_Price); return false; } else if (_canUseSlPrice && SlPrice <= (double)CurrentGoods.CurrentPrice) // 卖方向持仓止损价格设置小于最新价时 { //提示“止损价格必须高于该合约最新价,请重新设置” CheckTips(Client_Resource.SlPrice_High_than_Last_Price); return false; } } } return true; } /// /// just show Question tips message /// /// private void CheckTips(string tips) { Application.Current.Dispatcher.BeginInvoke(new Action(() => { MessageBoxHelper.ShowQuestion(tips, Client_Resource.DeliveryOrderView_WarningTipsTitle); })); } #endregion /// /// 止盈价 /// private double _spPrice; public double SpPrice { get { return _spPrice; } set { Set(() => SpPrice, ref _spPrice, value); } } private double _slPrice; public double SlPrice { get { return _slPrice; } set { Set(() => SlPrice, ref _slPrice, value); } } /// /// 查询止盈止损单 /// public void QuerySpslOrderByFundAccountId() { if (IsBusy) return; IsBusy = true; _commonQueryService.QuerySPSLOrder(UserManager.CurrentTradeAccount.FundsAccountId, (list => { IsBusy = false; _spslOrders = list; CountSpslSetNum(); }), CancelErrorCallBack); } /// /// 查询失败返回 /// /// private void CancelErrorCallBack(ErrorEntity errorEntity) { IsBusy = false; Application.Current.Dispatcher.BeginInvoke(new Action(() => { ErrorManager.ShowReturnError(errorEntity, Client_Resource.UI2014_Tips, true); })); } /// /// 计算已经设置的止盈止损数量 /// public void CountSpslSetNum() { decimal setNum = 0;// 已经设置的止盈止损的数量 if (_spslOrders != null) { Direction direction = Direction == Direction.Ask ? Direction.Bid : Direction.Ask; _spslOrders.ForEach((model => { //已经向需求确认过,如果止盈止损单中存在之前持仓未成交的单据时,得到的数量可能是大于当前的持仓数据,这个也没有关系。从数据上来说,该商品的相同方向上的待触发单据的数量确实是这么多。 if (model.GoodsId == _currentGoods.GoodsId && model.Status == SPSLOrderStatus.NotTrigger && direction == model.BuyOrSell)// 相同商品,待触发的状态,相同方向 { setNum += model.OrderQty; } })); } HadSetEntrustNum = setNum; } /// /// 已设止盈止损的数量-查询止盈止损单中现存的数量 #90705 /// 2. 增加显示已设置过多少数量(需要将已设置的止盈单、止损单、止盈止损单数量相加); /// private decimal _hadSetEntrustNum = 0; public decimal HadSetEntrustNum { get { return _hadSetEntrustNum; } set { Set(() => HadSetEntrustNum, ref _hadSetEntrustNum, value); } } /// /// 是否启用止盈价 /// private bool _canUseSpPrice; /// /// 是否启用止损价 /// private bool _canUseSlPrice; public bool CanUseSpPrice { get { return _canUseSpPrice; } set { Set(() => CanUseSpPrice, ref _canUseSpPrice, value); } } public bool CanUseSlPrice { get { return _canUseSlPrice; } set { Set(() => CanUseSlPrice, ref _canUseSlPrice, value); } } #endregion #region 买卖按钮的颜色控制 private SolidColorBrush _buyBackGroundBrush = Brushes.Red; public SolidColorBrush BuyBackGroundBrush { get { return _buyBackGroundBrush; } set { Set(() => BuyBackGroundBrush, ref _buyBackGroundBrush, value); } } private SolidColorBrush _sellBackGroundBrush = Brushes.Green; public SolidColorBrush SellBackGroundBrush { get { return _sellBackGroundBrush; } set { Set(() => SellBackGroundBrush, ref _sellBackGroundBrush, value); } } /// /// 在平仓时候,显示买卖方向就置灰,且不可以点击 /// /// public void ChangeBuySellBackground(Direction direction) { switch (direction) { case Direction.Ask:// 单据是卖方向的,那就将买方向的置灰, { SellBackGroundBrush = new SolidColorBrush(Color.FromRgb(100, 100, 100)); CanUseSell = false; BuyBackGroundBrush = Brushes.Red; CanUseBuy = true; break; } case Direction.Bid: { SellBackGroundBrush = Brushes.Green; CanUseSell = true; BuyBackGroundBrush = new SolidColorBrush(Color.FromRgb(100, 100, 100)); CanUseBuy = false; break; } default:// 买卖都可以用 { SellBackGroundBrush = Brushes.Green; CanUseSell = true; BuyBackGroundBrush = Brushes.Red; CanUseBuy = true; break; } } } private bool _canUseBuy; public bool CanUseBuy { get { return _canUseBuy; } set { Set(() => CanUseBuy, ref _canUseBuy, value); } } private bool _canUseSell; public bool CanUseSell { get { return _canUseSell; } set { Set(() => CanUseSell, ref _canUseSell, value); } } #endregion } }