| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- //----------------------------------------------------------------
- //Module Name: $safeprojectname$
- //Purpose:
- //CopyRight: Muchinfo
- //History:
- //----------------------------------------------------------------
- //DateTime 2016/7/25 10:06:43
- //Author
- //Description Create
- //----------------------------------------------------------------
- using Muchinfo.MTPClient.Data;
- using Muchinfo.MTPClient.Data.Enums;
- 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.Resources;
- namespace Muchinfo.MTPClient.Trade.ViewModels
- {
- public class MixTradeViewModel : BidTradeViewModel
- {
- public MixTradeViewModel(QuoteGoods goods, Direction direction)
- : base(goods, direction)
- {
- SetEntrustPriceRange();
- }
- public MixTradeViewModel(QuoteGoods goods, OrderBase orderBase)
- : base(goods, orderBase)
- {
- SetEntrustPriceRange();
- }
- /// <summary>
- /// 设置默认价格模式[读取数据库配置--设置]
- /// </summary>
- protected override void setDefaultPriceMode()
- {
- PriceMode = ePriceMode.PRICEMODE_LIMIT;//【客户需求】若商品为竞价模式,则默认成交的价格类型为“限价”
- if (ApplicationParameter.XMarketDefaultPriceMode == 0 && IsMarketPriceVisibity)
- {
- PriceMode = ePriceMode.PRICEMODE_MARKET;
- }
- }
- public override void PostOrder( Action<OrderDetail> successAction, Action<ErrorEntity> errorAction)
- {
- var entrustOrder = BuildEntrustOrder();
- entrustOrder.SLPrice = StopLossChecked ? StopLoss : 0;
- entrustOrder.SPPrice = StopProfitChecked ? StopProfit : 0;
- entrustOrder.CurtQuotePrice = Direction == Direction.Ask ? _currentGoods.AskPrice : _currentGoods.BidPrice;
- //限价平时,如果关联单号不为0,就改单&& SelectOrder != null && (SelectOrder.StopLoss > 0||SelectOrder.StopProfit > 0
- #region 2.0 注销BY DK
- //if (entrustOrder.PriceMode == ePriceMode.PRICEMODE_LIMIT && this.OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSE && this.GoodsOrderMode == GoodsOrderMode.Order)
- //{
- // //entrustOrder.RelationTicket = SelectOrder.OrderID;
- // entrustOrder.BuildType = OpenCloseMode.BUILDTYPE_CLOSETHENOPEN;
- // entrustOrder.BuyOrSell = SelectOrder.Direction;
- //}
- //if (entrustOrder.BuildType == OpenCloseMode.BUILDTYPE_CLOSETHENOPEN)
- //{
- // _orderService.MixModifyEntrustOrder(entrustOrder, successAction, errorAction);
- //}
- //else
- //{
- // // _orderService.MixMarketEntrustOrder(entrustOrder, successAction, errorAction);
- // _orderService.MakeMarketEntrustOrder(entrustOrder, successAction, errorAction);
- //}
- #endregion
- }
- public override bool IsShowRaiseFall
- {
- get
- {
- if (this.CurrentGoods==null)
- {
- return false;
- }
- else
- {
- return !this.CurrentGoods.IsQuoteValid;
- }
- }
- }
- public override bool IsMarketPriceVisibity
- {
- get
- {
- var result= ApplicationParameter.XMarketShowMarketPrice == 1;
-
- return result;
- }
- }
- /// <summary>
- /// 是否可以修改数量-即期-限价-平仓-不支持部分平仓
- /// </summary>
- public override bool IsEnableChangeLot
- {
- get
- {
- if (PriceMode == ePriceMode.PRICEMODE_LIMIT && this.GoodsOrderMode == GoodsOrderMode.Order)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- }
- /// <summary>
- /// 是否可按商品平仓 (不可按商品平仓)
- /// </summary>
- //public override bool IsCanGoodsEdit
- //{
- // get
- // {
- // return this.PriceMode == ePriceMode.PRICEMODE_MARKET;
- // }
- //}
- /// <summary>
- /// 设置计算数量价格
- /// </summary>
- /// <returns></returns>
- protected override decimal OrderPriceSetting()
- {
- var price = ExecutePrice;
- if (IsShowRaiseFall)
- {
- price = base.OrderPriceSetting();
- }
- else
- {
- if (PriceMode == ePriceMode.PRICEMODE_MARKET)
- {
- #region 市价:买一价卖一价
- price = decimal.Zero;
- if (BidCommissions != null && Direction == Direction.Ask)
- {
- price = BidCommissions.Find(x => x.Index == 1).Price; //卖跌停价//买一价
- }
- if (AskCommissions != null && Direction == Direction.Bid)
- {
- price = AskCommissions.Find(x => x.Index == 1).Price; //卖跌停价//卖一价
- }
- #endregion
- if (price == decimal.Zero)
- {
- price = CurrentGoods.LastClose; ////取昨收价
- }
- }
- }
- return price;
- }
- public override bool IsStopPLVsb
- {
-
- get { return this.PriceMode == ePriceMode.PRICEMODE_LIMIT && (this.OpenCloseMode ==OpenCloseMode.BUILDTYPE_OPEN || this.OpenCloseMode==OpenCloseMode.BUILDTYPE_CLOSE && this.GoodsOrderMode == GoodsOrderMode.Order); }
- }
- /// <summary>
- /// 是否显示价格项
- /// </summary>
- public override bool IsExecutePriceVbs
- {
- get
- {
- if (PriceMode == ePriceMode.PRICEMODE_MARKET)
- {
- return false;
- }
- else
- {
- return !(OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSE && this.GoodsOrderMode == GoodsOrderMode.Order);
- }
- }
- }
- public override ePriceMode PriceMode
- {
- get
- {
- return _priceMode;
- }
- set
- {
- Set(() => PriceMode, ref _priceMode, value);
- DefautEntrustPrice();
- CheckedVisibleEnable();
- SetMinMaxQtyVaule(); //设置数量
- }
- }
- #region 止盈止损
- /// <summary>
- /// 建仓方向
- /// </summary>
- public bool IsBidDirection
- {
- get
- {
- if (OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSE) ////平仓的持仓方向
- {
- return Direction == Direction.Ask;
- }
- else
- {
- return Direction == Direction.Bid;
- }
- }
- }
- /// <summary>
- /// 止盈跟据买卖设置符号方向
- /// </summary>
- 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);
- }
- }
- }
- /// <summary>
- /// 止损跟据买卖设置符号方向
- /// </summary>
- public string LossChar
- {
- get
- {
- if (IsBidDirection)
- {
- return "≤";//"<";
- }
- else
- {
- return "≥";//">";
- }
- }
- }
- //private decimal _maxLoss;
- //private decimal _maxProfit;
- private decimal _stopLoss;
- /// <summary>
- /// StopLossChecked
- /// </summary>
- private bool _stopLossChecked;
- private decimal _stopProfit;
- /// <summary>
- /// StopProfitChecked
- /// </summary>
- private bool _stopProfitChecked;
- /// <summary>
- /// Sets and gets the StopLoss property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public decimal StopLoss
- {
- get
- {
- return _stopLoss;
- }
- set
- {
- Set(() => StopLoss, ref _stopLoss, value);
- RaisePropertyChanged(() => StopLossPips);
- }
- }
- /// <summary>
- /// 止损点数
- /// </summary>
- public string StopLossPips
- {
- get
- {
- if (_stopLoss == 0 || PipsPrice == 0)
- {
- return "-";
- }
- if (IsBidDirection)
- {
- return (int)((_stopLoss - PipsPrice) * GetBasePips()) + string.Empty;
- }
- else
- {
- return (int)((PipsPrice - _stopLoss) * GetBasePips()) + string.Empty;
- }
- }
- }
- /// <summary>
- /// Sets and gets the StopLossChecked property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- 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;
- }
- }
- /// <summary>
- /// Sets and gets the StopProfit property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public decimal StopProfit
- {
- get
- {
- return _stopProfit;
- }
- set
- {
- Set(() => StopProfit, ref _stopProfit, value);
- RaisePropertyChanged(() => StopProfitPips);
- }
- }
- /// <summary>
- /// 止盈点数
- /// </summary>
- public string StopProfitPips
- {
- get
- {
- if (_stopProfit == 0 || PipsPrice == 0)
- {
- return "-";
- }
- if (IsBidDirection)
- {
- return (int)((_stopProfit - PipsPrice) * GetBasePips()) + string.Empty;
- }
- else
- {
- return (int)((PipsPrice - _stopProfit) * GetBasePips()) + string.Empty;
- }
- }
- }
- /// <summary>
- /// Sets and gets the StopProfitChecked property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- 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));
- }
- }
- /// <summary>
- /// 以点数计算
- /// </summary>
- /// <returns></returns>
- private decimal GetBasePips()
- {
- int temp = 0;
- if (this._currentGoods != null && this._currentGoods.GoodsParameters != null)
- {
- temp = _currentGoods.GoodsParameters.HqExchFigures;
- }
- return Convert.ToDecimal(Math.Pow(10, temp));
- }
- /// 设置最大止损价
- /// </summary>
- public decimal MaxLoss
- {
- get;
- set;
- }
- /// <summary>
- /// 格式化最大止损价
- /// </summary>
- public string DisplayMaxLoss
- {
- get { return MaxLoss.ToString(_currentGoods.FormatPrice); }
- }
- /// <summary>
- /// 格式化最大止盈价
- /// </summary>
- public string DisplayMaxProfit
- {
- get { return MaxProfit.ToString(_currentGoods.FormatPrice); }
- }
- /// <summary>
- /// 设置最大止盈价
- /// </summary>
- public decimal MaxProfit
- {
- get;
- set;
- }
- private decimal _maxLimit;
- /// <summary>
- /// 限价最大值
- /// </summary>
- public decimal MaxLimit
- {
- get
- {
- return _maxLimit;
- }
- set
- {
- Set(() => MaxLimit, ref _maxLimit, value);
- RaisePropertyChanged(() => DisplayMaxLimit);
- }
- }
- /// <summary>
- /// 格式化 限价最大值
- /// </summary>
- public string DisplayMaxLimit
- {
- get
- {
- if (MaxLimit <= 0)
- {
- return "-";
- }
- return MaxLimit.ToString(_currentGoods.FormatPrice);
- }
- }
- private decimal _minLimit;
- /// <summary>
- /// 限价最小值
- /// </summary>
- public decimal MinLimit
- {
- get
- {
- return _minLimit;
- }
- set
- {
- Set(() => MinLimit, ref _minLimit, value);
- RaisePropertyChanged(() => DisplayMinLimit);
- }
- }
- /// <summary>
- /// 格式化 限价最小值
- /// </summary>
- public string DisplayMinLimit
- {
- get
- {
- if (MinLimit <= 0)
- {
- return "-";
- }
- return MinLimit.ToString(_currentGoods.FormatPrice);
- }
- }
- private decimal _pipsPrice;
- /// <summary>
- /// 计算点数价格
- /// </summary>
- public decimal PipsPrice
- {
- get
- {
- return _pipsPrice;
- }
- set
- {
- _pipsPrice = value;
- RaisePropertyChanged(() => StopLossPips);
- RaisePropertyChanged(() => StopProfitPips);
- }
- }
- public override decimal ExecutePrice
- {
- get
- {
- return _executePrice;
- }
- set
- {
- Set(() => ExecutePrice, ref _executePrice, value);
- SetProfitLoss();
- SetMinMaxQtyVaule();
- }
- }
- public override GoodsOrderMode GoodsOrderMode
- {
- get { return _goodsOrderMode; }
- set
- {
- if (value == GoodsOrderMode.unSet)
- {
- return;
- }
- // var needInit = value != _goodsOrderMode;
- Set(() => GoodsOrderMode, ref _goodsOrderMode, value);
- CheckedVisibleEnable();
- SetMinMaxQtyVaule(); //设置数量
-
- //if (needInit)
- //{
- // SetInitVaules();
- //}
- }
- }
- /// <summary>
- /// 是否可显示人价格范围 默认不显示
- /// </summary>
- public override bool IsPriceRangeVsb
- {
- get
- {
- if (_currentGoods == null || _currentGoods.AskPrice == 0 || _currentGoods.BidPrice == 0)
- {
- return false;
- }
- return this.PriceMode == ePriceMode.PRICEMODE_LIMIT &&
- (this.OpenCloseMode == OpenCloseMode.BUILDTYPE_OPEN ||
- (OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSE && GoodsOrderMode == GoodsOrderMode.Goods));//|| OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSETHENOPEN
- }
- }
- public void SetProfitLoss()
- {
- MaxProfit = GetProfit();
- MaxLoss = GetLoss();
- RaisePropertyChanged(() => ProfitChar);
- RaisePropertyChanged(() => LossChar);
- RaisePropertyChanged(() => DisplayMaxProfit);
- RaisePropertyChanged(() => DisplayMaxLoss);
- SetEntrustPriceRange();
- PipsPrice = this.OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSE && SelectOrder !=null? SelectOrder.HoldingPrice : ExecutePrice;
- }
- //下限价买建仓单时,止损价 < 委托价-(买点差-卖点差+止损卖点差) * 最小变动单位;
- //下限价卖建仓单时,止损价 > 限价 - (卖点差-买点差-止损买点差)* 最小变动单位。
- ///// <summary>
- ///// 限价止盈买点差
- ///// </summary>
- //TRADERULE_XLIMITSPBUYPT = 4705,
- ///// <summary>
- ///// 限价止盈卖点差
- ///// </summary>
- //TRADERULE_XLIMITSPSELLPT = 4706,
- /// <summary>
- /// 获取止盈价
- /// </summary>
- /// <returns></returns>
- private decimal GetProfit()
- {
- if (this.OpenCloseMode == OpenCloseMode.BUILDTYPE_OPEN )//|| this.OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSETHENOPEN)
- {
-
- #region 建仓
- if (this.Direction == Direction.Bid)
- {
- //止损价 < 限价-(买点差-卖点差+止损卖点差) * 最小变动单位
- // _currentGoods.GoodsParameters.GoodsStatus != GoodsStatusType.Open
- if (_currentGoods == null || _currentGoods.GoodsParameters == null) return 0;
-
- if (_currentGoods.GoodsParameters.HqExchFigures < 20 &&
- _currentGoods.GoodsParameters.HqExchFigures > -20)
- {
- // ||_orderQuoteGoods.GoodsParameters.GoodsStatus != GoodsStatusType.Open
- var ptSubObj = CacheManager.GetTradeRule((int)_currentGoods.GoodsId,
- (int)eTradeRule.TRADERULE_SPPT);
- var ptSub = ptSubObj == null ? 0 : ptSubObj.FeeValue;
-
- var value = ( ptSub) / (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;
- var ptSubObj = CacheManager.GetTradeRule((int)_currentGoods.GoodsId,
- (int)eTradeRule.TRADERULE_SPPT);
- var ptSub = ptSubObj == null ? 0 : ptSubObj.FeeValue;
- if (_currentGoods.GoodsParameters.HqExchFigures < 20 &&
- _currentGoods.GoodsParameters.HqExchFigures > -20)
- {
- var value = ( ptSub) / (decimal)
- Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures);
- return (_executePrice - value);
- }
- return _executePrice;
- }
- #endregion
- }
- else
- {
- //if (this.SelectOrder != null)
- //{
- // return this.SelectOrder.HoldingPrice;
- //}
- //return _currentGoods.CurrentPrice;
- bool flag = _currentGoods.GoodsParameters.HqExchFigures < 20 &&
- _currentGoods.GoodsParameters.HqExchFigures > -20;
- if (this.Direction == Direction.Ask)
- {
- //止盈价 > 买价 + (止盈点差 * 最小变动单位)
- //止盈价 >= 买价 + (止盈卖点差 * 最小变动单位)
- // ||_orderQuoteGoods.GoodsParameters.GoodsStatus != GoodsStatusType.Open
- var buyptSub = CacheManager.GetTradeRule((int)_currentGoods.GoodsId,
- (int)eTradeRule.TRADERULE_SPPT);
- var ptSub = buyptSub == null ? 0 : buyptSub.FeeValue;
- return _currentGoods.BidPrice +
- (flag
- ? ptSub /
- (decimal)Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures)
- : 0);
- }
- else
- {
- //止盈价 < 卖价 - (止盈点差 * 最小变动单位)
- //止盈价 <= 卖价 - (止盈买点差 * 最小变动单位)
- //||_orderQuoteGoods.GoodsParameters.GoodsStatus != GoodsStatusType.Open
- var sellptSub = CacheManager.GetTradeRule((int)_currentGoods.GoodsId,
- (int)eTradeRule.TRADERULE_SPPT);
- var ptSub = sellptSub == null ? 0 : sellptSub.FeeValue;
- return _currentGoods.AskPrice - (flag
- ? ptSub / (decimal)
- Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures)
- : 0);
- }
- }
- }
- // TRADERULE_XLIMITSLBUYPT = 4703,
- ///// <summary>
- ///// 限价止损卖点差
- ///// </summary>
- //TRADERULE_XLIMITSLSELLPT = 4704,
- /// <summary>
- /// 获取止损价
- /// </summary>
- /// <returns></returns>
- private decimal GetLoss()
- {
- if (this.OpenCloseMode == OpenCloseMode.BUILDTYPE_OPEN )//|| this.OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSETHENOPEN)
- {
-
- #region 建仓
- if (this.Direction == Direction.Bid)
- {
- //止损价 < 限价-(买点差-卖点差+止损卖点差) * 最小变动单位
- // _currentGoods.GoodsParameters.GoodsStatus != GoodsStatusType.Open
- if (_currentGoods == null || _currentGoods.GoodsParameters == null) return 0;
- if (_currentGoods.GoodsParameters.HqExchFigures < 20 &&
- _currentGoods.GoodsParameters.HqExchFigures > -20)
- {
- // ||_orderQuoteGoods.GoodsParameters.GoodsStatus != GoodsStatusType.Open
- var ptSubObj = CacheManager.GetTradeRule((int)_currentGoods.GoodsId,
- (int)eTradeRule.TRADERULE_SPPT);
- var ptSub = ptSubObj == null ? 0 : ptSubObj.FeeValue;
-
- var value = ( ptSub) / (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;
-
- var ptSubObj = CacheManager.GetTradeRule((int)_currentGoods.GoodsId,
- (int)eTradeRule.TRADERULE_SPPT);
- var ptSub = ptSubObj == null ? 0 : ptSubObj.FeeValue;
- if (_currentGoods.GoodsParameters.HqExchFigures < 20 &&
- _currentGoods.GoodsParameters.HqExchFigures > -20)
- {
- var value = ( ptSub) / (decimal)
- Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures);
- return (_executePrice + value);
- }
- return _executePrice;
- }
- #endregion
-
- }
- else
- {
- bool flag = _currentGoods.GoodsParameters.HqExchFigures < 20 &&
- _currentGoods.GoodsParameters.HqExchFigures > -20;
- if (this.Direction == Direction.Ask)
- {
- //止损价 < =卖价 - (止损卖点差 * 最小变动单位)
- //||_orderQuoteGoods.GoodsParameters.GoodsStatus != GoodsStatusType.Open
- var ptSubObj = CacheManager.GetTradeRule((int)_currentGoods.GoodsId,
- (int)eTradeRule.TRADERULE_SPPT);
- var ptSub = ptSubObj == null ? 0 : ptSubObj.FeeValue;
- return (_currentGoods.BidPrice - (flag ? ptSub / (decimal)Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures)
- : 0));
- }
- else
- {
- //止损价 > =买价 + (止损买点差 * 最小变动单位)
- //||_orderQuoteGoods.GoodsParameters.GoodsStatus != GoodsStatusType.Open
- var ptSubObj = CacheManager.GetTradeRule((int)_currentGoods.GoodsId,
- (int)eTradeRule.TRADERULE_SPPT);
- var ptSub = ptSubObj == null ? 0 : ptSubObj.FeeValue;
- return (_currentGoods.AskPrice +
- (flag ? ptSub /
- (decimal)Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures)
- : 0));
- }
- }
- }
- /// <summary>
- /// 设置限价的范围
- /// </summary>
- protected override void SetEntrustPriceRange()
- {
- if (_currentGoods != null && _currentGoods.GoodsParameters != null)
- {
- RaisePropertyChanged(()=>IsPriceRangeVsb);
- bool flag = _currentGoods.GoodsParameters.HqExchFigures < 20 &&
- _currentGoods.GoodsParameters.HqExchFigures > -20;
- GoodsFeeType foodsfeeType;
- if (this.OpenCloseMode == OpenCloseMode.BUILDTYPE_OPEN)// || this.OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSETHENOPEN)
- {
- foodsfeeType = CacheManager.GetTradeRule((int) _currentGoods.GoodsId,
- (int)(Direction==Direction.Ask? eTradeRule.TRADERULE_SLPT:eTradeRule.TRADERULE_SPPT));
- if (Direction == Direction.Ask)
- {
- //限价 》 限价上限(max(买价, 卖价) + 限价卖点差*最小变动单位)
- //限价 《 限价下限(min(买价, 卖价) - 限价卖点差*最小变动单位)
- var ptSub = foodsfeeType == null ? 0 : foodsfeeType.FeeValue;
- MinLimit = _currentGoods.BidPrice;
- //Math.Max(_currentGoods.BidPrice, _currentGoods.AskPrice);
- // MinLimit = Math.Min(_currentGoods.BidPrice, _currentGoods.AskPrice) - _currentGoods.GoodsParameters.LimitOpenSellptSub / (decimal)
- //EntructPriceRange = QuotePrice -
- // _currentGoods.GoodsParameters.LimitOpenSellptSub / (decimal)
- // Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures);
- MaxLimit = _currentGoods.BidPrice + (flag
- ? ptSub / (decimal)
- Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures)
- : 0);
- }
- else
- {
- // 限 价 >= 【卖一价】 或 =< 【卖一价 - (限价买入买点差*最小变动单位)】
- var ptSub = foodsfeeType == null ? 0 : foodsfeeType.FeeValue;
- MinLimit = _currentGoods.AskPrice-(flag
- ? ptSub / (decimal)
- Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures)
- : 0) ;
- MaxLimit = _currentGoods.AskPrice;
- }
- }
- else
- {
- foodsfeeType = CacheManager.GetTradeRule((int) _currentGoods.GoodsId,
- (Direction==Direction.Ask? 4708:4707));
- if (Direction == Direction.Bid)
- {
- //限价 》 限价上限(max(买价, 卖价) + 限价卖点差*最小变动单位)
- //限价 《 限价下限(min(买价, 卖价) - 限价卖点差*最小变动单位)
- var ptSub = foodsfeeType == null ? 0 : foodsfeeType.FeeValue;
- MaxLimit = _currentGoods.AskPrice;
- //Math.Max(_currentGoods.BidPrice, _currentGoods.AskPrice);
- // MinLimit = Math.Min(_currentGoods.BidPrice, _currentGoods.AskPrice) - _currentGoods.GoodsParameters.LimitOpenSellptSub / (decimal)
- //EntructPriceRange = QuotePrice -
- // _currentGoods.GoodsParameters.LimitOpenSellptSub / (decimal)
- // Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures);
- MinLimit = _currentGoods.AskPrice - (flag
- ? ptSub / (decimal)
- Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures)
- : 0);
- }
- else
- {
- //限价 》 限价上限(max(买价, 卖价) + 限价买点差 * 最小变动单位)
- //限价 《 限价下限(min(买价, 卖价) - 限价买点差 * 最小变动单位)
- var ptSub = foodsfeeType == null ? 0 : foodsfeeType.FeeValue;
- MaxLimit = (flag
- ? ptSub / (decimal)
- Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures)
- : 0) + _currentGoods.BidPrice;
- MinLimit = _currentGoods.BidPrice;
- }
- }
-
- }
-
- //if (flag)
- //{
- // PriceMinUnit = 1 / Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures);
- //}
- }
- public override void CheckedVisibleEnable()
- {
- base.CheckedVisibleEnable();
- if (_priceMode == ePriceMode.PRICEMODE_LIMIT && OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSE&&_goodsOrderMode==GoodsOrderMode.Order) //限价只能按单平
- {
-
- ////设置原止损止盈
- if (SelectOrder != null)
- {
- StopLossChecked = SelectOrder.StopLoss > 0;///设置了止损
- this.StopLoss = SelectOrder.StopLoss;
- StopProfitChecked = SelectOrder.StopProfit > 0;///设置了止损
- this.StopProfit = SelectOrder.StopProfit;
- }
- SetProfitLoss();
- }
- }
-
- /// <summary>
- /// 设置平仓最大最小数量
- /// </summary>
- protected override void SetCloseQty()
- {
- var minQty = _goodsService.GetGoodsParamerRule((int)_currentGoods.GoodsId, _currentGoods.TradeMode, GoodsTradeConts.MINOPENTRADEQTY);
- MinLot = minQty == null ? defaut_minLot : minQty.FeeValue;
- decimal tempMaxLot = CalcAvailCloseQty();
-
-
- //按单平仓
- if (this.GoodsOrderMode == GoodsOrderMode.Order)
- {
- MaxLot = SelectOrder == null || !SelectOrder.IsCanClose ? 0 : SelectOrder.AvailQty;
- if (this.PriceMode == ePriceMode.PRICEMODE_LIMIT)
- {
-
- MaxLot = Math.Min(tempMaxLot, MaxLot);
- Lot = MaxLot;
- //#23420 投资者下做市商品的持仓,P+X交割申报配对成功,冻结头寸成功,选择做市商品进行限制平仓,报错:3093[头寸不足]
-
- }
- //MaxLot = SelectOrder == null || !SelectOrder.IsCanClose ? 0 : SelectOrder.AvailQty; ////未达持仓天数,不可平
- //MaxLot = Math.Min(tempMaxLot, MaxLot);
- }
- else
- {
- //按寸头平仓
- MaxLot = tempMaxLot;
- }
- }
-
-
- #endregion
- public override bool Validated(ref string msg)
- {
- if (!base.Validated(ref msg))
- {
- return false;
- }
- bool isProfitLoss = false;
- if (PriceMode==ePriceMode.PRICEMODE_LIMIT)
- {
- if (OpenCloseMode != OpenCloseMode.BUILDTYPE_CLOSE)
- {
- if (IsShowRaiseFall&&(ExecutePrice > this.UpPrice || ExecutePrice < LowPrice))
- {
- msg = Client_Resource.ExecutePrice_IsNotInRaiseFallRange;
- return false;
- }
- isProfitLoss = true;
- if (ExecutePrice > MinLimit && ExecutePrice < MaxLimit)
- {
- msg = Client_Resource.ErrorEntrustPrice;
- return false;
- }
- }
- else
- {
- if (GoodsOrderMode == GoodsOrderMode.Order)
- {
- isProfitLoss = true;
- if (!StopProfitChecked && !StopLossChecked)
- {
- msg = Client_Resource.xmacth_stopProfitLossSetError;
- return false;
- }
- }
- else
- {
- if (ExecutePrice > MinLimit && ExecutePrice < MaxLimit)
- {
- msg = Client_Resource.ErrorEntrustPrice;
- return false;
- }
- }
- }
- if (isProfitLoss && StopProfitChecked) ////止盈
- {
- //止盈
- if (!this.IsBidDirection)
- {
- if (this.StopProfit > this.MaxProfit)
- {
- msg = Muchinfo.MTPClient.Resources.Client_Resource.Trade_ProfitIsOut;
- return false;
- }
- }
- else
- {
- if (this.StopProfit < this.MaxProfit)
- {
- msg = Muchinfo.MTPClient.Resources.Client_Resource.Trade_ProfitIsOut;
- return false;
- }
- }
- if (this.StopProfit <= 0)
- {
- msg = Muchinfo.MTPClient.Resources.Client_Resource.Trade_ProfitLessThanZero;
- return false;
- }
- if (IsShowRaiseFall && (StopProfit > this.UpPrice || StopProfit < LowPrice))
- {
- msg = Client_Resource.ProfitPrice_IsNotInRaiseFallRange;
- return false;
- }
- }
- if (isProfitLoss && StopLossChecked) ////止损
- {
- if (!this.IsBidDirection)
- {
- if (this.StopLoss < this.MaxLoss)
- {
- msg = Muchinfo.MTPClient.Resources.Client_Resource.Trade_StopIsOut;
- return false;
- }
- }
- else
- {
- if (this.StopLoss > this.MaxLoss)
- {
- msg = Muchinfo.MTPClient.Resources.Client_Resource.Trade_StopIsOut;
- return false;
- }
- }
- if (this.StopLoss <= 0)
- {
- msg = Muchinfo.MTPClient.Resources.Client_Resource.Trade_StopLessThanZero;
- return false;
- }
- if (IsShowRaiseFall && (StopLoss > this.UpPrice || StopLoss < LowPrice))
- {
- msg = Client_Resource.LossPrice_IsNotInRaiseFallRange;
- return false;
- }
- }
- }
- return true;
- }
- }
- }
|