MixTradeViewModel.cs 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. //----------------------------------------------------------------
  6. //Module Name: $safeprojectname$
  7. //Purpose:
  8. //CopyRight: Muchinfo
  9. //History:
  10. //----------------------------------------------------------------
  11. //DateTime 2016/7/25 10:06:43
  12. //Author
  13. //Description Create
  14. //----------------------------------------------------------------
  15. using Muchinfo.MTPClient.Data;
  16. using Muchinfo.MTPClient.Data.Enums;
  17. using Muchinfo.MTPClient.Data.Model;
  18. using Muchinfo.MTPClient.Data.Model.Account;
  19. using Muchinfo.MTPClient.Data.Model.GoodRules;
  20. using Muchinfo.MTPClient.Infrastructure.Cache;
  21. using Muchinfo.MTPClient.Infrastructure.Utilities;
  22. using Muchinfo.MTPClient.Resources;
  23. namespace Muchinfo.MTPClient.Trade.ViewModels
  24. {
  25. public class MixTradeViewModel : BidTradeViewModel
  26. {
  27. public MixTradeViewModel(QuoteGoods goods, Direction direction)
  28. : base(goods, direction)
  29. {
  30. SetEntrustPriceRange();
  31. }
  32. public MixTradeViewModel(QuoteGoods goods, OrderBase orderBase)
  33. : base(goods, orderBase)
  34. {
  35. SetEntrustPriceRange();
  36. }
  37. /// <summary>
  38. /// 设置默认价格模式[读取数据库配置--设置]
  39. /// </summary>
  40. protected override void setDefaultPriceMode()
  41. {
  42. PriceMode = ePriceMode.PRICEMODE_LIMIT;//【客户需求】若商品为竞价模式,则默认成交的价格类型为“限价”
  43. if (ApplicationParameter.XMarketDefaultPriceMode == 0 && IsMarketPriceVisibity)
  44. {
  45. PriceMode = ePriceMode.PRICEMODE_MARKET;
  46. }
  47. }
  48. public override void PostOrder( Action<OrderDetail> successAction, Action<ErrorEntity> errorAction)
  49. {
  50. var entrustOrder = BuildEntrustOrder();
  51. entrustOrder.SLPrice = StopLossChecked ? StopLoss : 0;
  52. entrustOrder.SPPrice = StopProfitChecked ? StopProfit : 0;
  53. entrustOrder.CurtQuotePrice = Direction == Direction.Ask ? _currentGoods.AskPrice : _currentGoods.BidPrice;
  54. //限价平时,如果关联单号不为0,就改单&& SelectOrder != null && (SelectOrder.StopLoss > 0||SelectOrder.StopProfit > 0
  55. #region 2.0 注销BY DK
  56. //if (entrustOrder.PriceMode == ePriceMode.PRICEMODE_LIMIT && this.OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSE && this.GoodsOrderMode == GoodsOrderMode.Order)
  57. //{
  58. // //entrustOrder.RelationTicket = SelectOrder.OrderID;
  59. // entrustOrder.BuildType = OpenCloseMode.BUILDTYPE_CLOSETHENOPEN;
  60. // entrustOrder.BuyOrSell = SelectOrder.Direction;
  61. //}
  62. //if (entrustOrder.BuildType == OpenCloseMode.BUILDTYPE_CLOSETHENOPEN)
  63. //{
  64. // _orderService.MixModifyEntrustOrder(entrustOrder, successAction, errorAction);
  65. //}
  66. //else
  67. //{
  68. // // _orderService.MixMarketEntrustOrder(entrustOrder, successAction, errorAction);
  69. // _orderService.MakeMarketEntrustOrder(entrustOrder, successAction, errorAction);
  70. //}
  71. #endregion
  72. }
  73. public override bool IsShowRaiseFall
  74. {
  75. get
  76. {
  77. if (this.CurrentGoods==null)
  78. {
  79. return false;
  80. }
  81. else
  82. {
  83. return !this.CurrentGoods.IsQuoteValid;
  84. }
  85. }
  86. }
  87. public override bool IsMarketPriceVisibity
  88. {
  89. get
  90. {
  91. var result= ApplicationParameter.XMarketShowMarketPrice == 1;
  92. return result;
  93. }
  94. }
  95. /// <summary>
  96. /// 是否可以修改数量-即期-限价-平仓-不支持部分平仓
  97. /// </summary>
  98. public override bool IsEnableChangeLot
  99. {
  100. get
  101. {
  102. if (PriceMode == ePriceMode.PRICEMODE_LIMIT && this.GoodsOrderMode == GoodsOrderMode.Order)
  103. {
  104. return false;
  105. }
  106. else
  107. {
  108. return true;
  109. }
  110. }
  111. }
  112. /// <summary>
  113. /// 是否可按商品平仓 (不可按商品平仓)
  114. /// </summary>
  115. //public override bool IsCanGoodsEdit
  116. //{
  117. // get
  118. // {
  119. // return this.PriceMode == ePriceMode.PRICEMODE_MARKET;
  120. // }
  121. //}
  122. /// <summary>
  123. /// 设置计算数量价格
  124. /// </summary>
  125. /// <returns></returns>
  126. protected override decimal OrderPriceSetting()
  127. {
  128. var price = ExecutePrice;
  129. if (IsShowRaiseFall)
  130. {
  131. price = base.OrderPriceSetting();
  132. }
  133. else
  134. {
  135. if (PriceMode == ePriceMode.PRICEMODE_MARKET)
  136. {
  137. #region 市价:买一价卖一价
  138. price = decimal.Zero;
  139. if (BidCommissions != null && Direction == Direction.Ask)
  140. {
  141. price = BidCommissions.Find(x => x.Index == 1).Price; //卖跌停价//买一价
  142. }
  143. if (AskCommissions != null && Direction == Direction.Bid)
  144. {
  145. price = AskCommissions.Find(x => x.Index == 1).Price; //卖跌停价//卖一价
  146. }
  147. #endregion
  148. if (price == decimal.Zero)
  149. {
  150. price = CurrentGoods.LastClose; ////取昨收价
  151. }
  152. }
  153. }
  154. return price;
  155. }
  156. public override bool IsStopPLVsb
  157. {
  158. get { return this.PriceMode == ePriceMode.PRICEMODE_LIMIT && (this.OpenCloseMode ==OpenCloseMode.BUILDTYPE_OPEN || this.OpenCloseMode==OpenCloseMode.BUILDTYPE_CLOSE && this.GoodsOrderMode == GoodsOrderMode.Order); }
  159. }
  160. /// <summary>
  161. /// 是否显示价格项
  162. /// </summary>
  163. public override bool IsExecutePriceVbs
  164. {
  165. get
  166. {
  167. if (PriceMode == ePriceMode.PRICEMODE_MARKET)
  168. {
  169. return false;
  170. }
  171. else
  172. {
  173. return !(OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSE && this.GoodsOrderMode == GoodsOrderMode.Order);
  174. }
  175. }
  176. }
  177. public override ePriceMode PriceMode
  178. {
  179. get
  180. {
  181. return _priceMode;
  182. }
  183. set
  184. {
  185. Set(() => PriceMode, ref _priceMode, value);
  186. DefautEntrustPrice();
  187. CheckedVisibleEnable();
  188. SetMinMaxQtyVaule(); //设置数量
  189. }
  190. }
  191. #region 止盈止损
  192. /// <summary>
  193. /// 建仓方向
  194. /// </summary>
  195. public bool IsBidDirection
  196. {
  197. get
  198. {
  199. if (OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSE) ////平仓的持仓方向
  200. {
  201. return Direction == Direction.Ask;
  202. }
  203. else
  204. {
  205. return Direction == Direction.Bid;
  206. }
  207. }
  208. }
  209. /// <summary>
  210. /// 止盈跟据买卖设置符号方向
  211. /// </summary>
  212. public string ProfitChar
  213. {
  214. get
  215. {
  216. if (IsBidDirection)
  217. {
  218. // StopProfit = (decimal)(MaxProfit - (decimal)PriceMinUnit);
  219. // StopLoss = (decimal)(MaxLoss + (decimal)PriceMinUnit);
  220. return "≥";//">";
  221. }
  222. else
  223. {
  224. return "≤";//"<";
  225. // StopProfit = (decimal)(MaxProfit + (decimal)PriceMinUnit);
  226. // StopLoss = (decimal)(MaxLoss - (decimal)PriceMinUnit);
  227. }
  228. }
  229. }
  230. /// <summary>
  231. /// 止损跟据买卖设置符号方向
  232. /// </summary>
  233. public string LossChar
  234. {
  235. get
  236. {
  237. if (IsBidDirection)
  238. {
  239. return "≤";//"<";
  240. }
  241. else
  242. {
  243. return "≥";//">";
  244. }
  245. }
  246. }
  247. //private decimal _maxLoss;
  248. //private decimal _maxProfit;
  249. private decimal _stopLoss;
  250. /// <summary>
  251. /// StopLossChecked
  252. /// </summary>
  253. private bool _stopLossChecked;
  254. private decimal _stopProfit;
  255. /// <summary>
  256. /// StopProfitChecked
  257. /// </summary>
  258. private bool _stopProfitChecked;
  259. /// <summary>
  260. /// Sets and gets the StopLoss property.
  261. /// Changes to that property's value raise the PropertyChanged event.
  262. /// </summary>
  263. public decimal StopLoss
  264. {
  265. get
  266. {
  267. return _stopLoss;
  268. }
  269. set
  270. {
  271. Set(() => StopLoss, ref _stopLoss, value);
  272. RaisePropertyChanged(() => StopLossPips);
  273. }
  274. }
  275. /// <summary>
  276. /// 止损点数
  277. /// </summary>
  278. public string StopLossPips
  279. {
  280. get
  281. {
  282. if (_stopLoss == 0 || PipsPrice == 0)
  283. {
  284. return "-";
  285. }
  286. if (IsBidDirection)
  287. {
  288. return (int)((_stopLoss - PipsPrice) * GetBasePips()) + string.Empty;
  289. }
  290. else
  291. {
  292. return (int)((PipsPrice - _stopLoss) * GetBasePips()) + string.Empty;
  293. }
  294. }
  295. }
  296. /// <summary>
  297. /// Sets and gets the StopLossChecked property.
  298. /// Changes to that property's value raise the PropertyChanged event.
  299. /// </summary>
  300. public bool StopLossChecked
  301. {
  302. get
  303. {
  304. return _stopLossChecked;
  305. }
  306. set
  307. {
  308. Set(() => StopLossChecked, ref _stopLossChecked, value);
  309. // StopLoss = _stopLossChecked ? ExecutePrice : 0;
  310. //StopLoss = _stopProfitChecked ? 0 : 0;
  311. if (IsBidDirection)
  312. {
  313. StopLoss = (decimal)(MaxLoss - MinUint);
  314. }
  315. else
  316. {
  317. StopLoss = (decimal)(MaxLoss + MinUint);
  318. }
  319. //StopLoss = _stopProfitChecked ? 0 : 0;
  320. }
  321. }
  322. /// <summary>
  323. /// Sets and gets the StopProfit property.
  324. /// Changes to that property's value raise the PropertyChanged event.
  325. /// </summary>
  326. public decimal StopProfit
  327. {
  328. get
  329. {
  330. return _stopProfit;
  331. }
  332. set
  333. {
  334. Set(() => StopProfit, ref _stopProfit, value);
  335. RaisePropertyChanged(() => StopProfitPips);
  336. }
  337. }
  338. /// <summary>
  339. /// 止盈点数
  340. /// </summary>
  341. public string StopProfitPips
  342. {
  343. get
  344. {
  345. if (_stopProfit == 0 || PipsPrice == 0)
  346. {
  347. return "-";
  348. }
  349. if (IsBidDirection)
  350. {
  351. return (int)((_stopProfit - PipsPrice) * GetBasePips()) + string.Empty;
  352. }
  353. else
  354. {
  355. return (int)((PipsPrice - _stopProfit) * GetBasePips()) + string.Empty;
  356. }
  357. }
  358. }
  359. /// <summary>
  360. /// Sets and gets the StopProfitChecked property.
  361. /// Changes to that property's value raise the PropertyChanged event.
  362. /// </summary>
  363. public bool StopProfitChecked
  364. {
  365. get
  366. {
  367. return _stopProfitChecked;
  368. }
  369. set
  370. {
  371. Set(() => StopProfitChecked, ref _stopProfitChecked, value);
  372. // StopProfit = _stopProfitChecked ? ExecutePrice : 0;
  373. if (IsBidDirection)
  374. {
  375. StopProfit = (decimal)(MaxProfit + MinUint);
  376. }
  377. else
  378. {
  379. StopProfit = (decimal)(MaxProfit - MinUint);
  380. }
  381. }
  382. }
  383. public decimal MinUint
  384. {
  385. get
  386. {
  387. int temp = 0;
  388. if (this._currentGoods != null && this._currentGoods.GoodsParameters != null)
  389. {
  390. temp = _currentGoods.GoodsParameters.HqExchFigures;
  391. }
  392. return Convert.ToDecimal(1 / Math.Pow(10, temp));
  393. }
  394. }
  395. /// <summary>
  396. /// 以点数计算
  397. /// </summary>
  398. /// <returns></returns>
  399. private decimal GetBasePips()
  400. {
  401. int temp = 0;
  402. if (this._currentGoods != null && this._currentGoods.GoodsParameters != null)
  403. {
  404. temp = _currentGoods.GoodsParameters.HqExchFigures;
  405. }
  406. return Convert.ToDecimal(Math.Pow(10, temp));
  407. }
  408. /// 设置最大止损价
  409. /// </summary>
  410. public decimal MaxLoss
  411. {
  412. get;
  413. set;
  414. }
  415. /// <summary>
  416. /// 格式化最大止损价
  417. /// </summary>
  418. public string DisplayMaxLoss
  419. {
  420. get { return MaxLoss.ToString(_currentGoods.FormatPrice); }
  421. }
  422. /// <summary>
  423. /// 格式化最大止盈价
  424. /// </summary>
  425. public string DisplayMaxProfit
  426. {
  427. get { return MaxProfit.ToString(_currentGoods.FormatPrice); }
  428. }
  429. /// <summary>
  430. /// 设置最大止盈价
  431. /// </summary>
  432. public decimal MaxProfit
  433. {
  434. get;
  435. set;
  436. }
  437. private decimal _maxLimit;
  438. /// <summary>
  439. /// 限价最大值
  440. /// </summary>
  441. public decimal MaxLimit
  442. {
  443. get
  444. {
  445. return _maxLimit;
  446. }
  447. set
  448. {
  449. Set(() => MaxLimit, ref _maxLimit, value);
  450. RaisePropertyChanged(() => DisplayMaxLimit);
  451. }
  452. }
  453. /// <summary>
  454. /// 格式化 限价最大值
  455. /// </summary>
  456. public string DisplayMaxLimit
  457. {
  458. get
  459. {
  460. if (MaxLimit <= 0)
  461. {
  462. return "-";
  463. }
  464. return MaxLimit.ToString(_currentGoods.FormatPrice);
  465. }
  466. }
  467. private decimal _minLimit;
  468. /// <summary>
  469. /// 限价最小值
  470. /// </summary>
  471. public decimal MinLimit
  472. {
  473. get
  474. {
  475. return _minLimit;
  476. }
  477. set
  478. {
  479. Set(() => MinLimit, ref _minLimit, value);
  480. RaisePropertyChanged(() => DisplayMinLimit);
  481. }
  482. }
  483. /// <summary>
  484. /// 格式化 限价最小值
  485. /// </summary>
  486. public string DisplayMinLimit
  487. {
  488. get
  489. {
  490. if (MinLimit <= 0)
  491. {
  492. return "-";
  493. }
  494. return MinLimit.ToString(_currentGoods.FormatPrice);
  495. }
  496. }
  497. private decimal _pipsPrice;
  498. /// <summary>
  499. /// 计算点数价格
  500. /// </summary>
  501. public decimal PipsPrice
  502. {
  503. get
  504. {
  505. return _pipsPrice;
  506. }
  507. set
  508. {
  509. _pipsPrice = value;
  510. RaisePropertyChanged(() => StopLossPips);
  511. RaisePropertyChanged(() => StopProfitPips);
  512. }
  513. }
  514. public override decimal ExecutePrice
  515. {
  516. get
  517. {
  518. return _executePrice;
  519. }
  520. set
  521. {
  522. Set(() => ExecutePrice, ref _executePrice, value);
  523. SetProfitLoss();
  524. SetMinMaxQtyVaule();
  525. }
  526. }
  527. public override GoodsOrderMode GoodsOrderMode
  528. {
  529. get { return _goodsOrderMode; }
  530. set
  531. {
  532. if (value == GoodsOrderMode.unSet)
  533. {
  534. return;
  535. }
  536. // var needInit = value != _goodsOrderMode;
  537. Set(() => GoodsOrderMode, ref _goodsOrderMode, value);
  538. CheckedVisibleEnable();
  539. SetMinMaxQtyVaule(); //设置数量
  540. //if (needInit)
  541. //{
  542. // SetInitVaules();
  543. //}
  544. }
  545. }
  546. /// <summary>
  547. /// 是否可显示人价格范围 默认不显示
  548. /// </summary>
  549. public override bool IsPriceRangeVsb
  550. {
  551. get
  552. {
  553. if (_currentGoods == null || _currentGoods.AskPrice == 0 || _currentGoods.BidPrice == 0)
  554. {
  555. return false;
  556. }
  557. return this.PriceMode == ePriceMode.PRICEMODE_LIMIT &&
  558. (this.OpenCloseMode == OpenCloseMode.BUILDTYPE_OPEN ||
  559. (OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSE && GoodsOrderMode == GoodsOrderMode.Goods));//|| OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSETHENOPEN
  560. }
  561. }
  562. public void SetProfitLoss()
  563. {
  564. MaxProfit = GetProfit();
  565. MaxLoss = GetLoss();
  566. RaisePropertyChanged(() => ProfitChar);
  567. RaisePropertyChanged(() => LossChar);
  568. RaisePropertyChanged(() => DisplayMaxProfit);
  569. RaisePropertyChanged(() => DisplayMaxLoss);
  570. SetEntrustPriceRange();
  571. PipsPrice = this.OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSE && SelectOrder !=null? SelectOrder.HoldingPrice : ExecutePrice;
  572. }
  573. //下限价买建仓单时,止损价 < 委托价-(买点差-卖点差+止损卖点差) * 最小变动单位;
  574. //下限价卖建仓单时,止损价 > 限价 - (卖点差-买点差-止损买点差)* 最小变动单位。
  575. ///// <summary>
  576. ///// 限价止盈买点差
  577. ///// </summary>
  578. //TRADERULE_XLIMITSPBUYPT = 4705,
  579. ///// <summary>
  580. ///// 限价止盈卖点差
  581. ///// </summary>
  582. //TRADERULE_XLIMITSPSELLPT = 4706,
  583. /// <summary>
  584. /// 获取止盈价
  585. /// </summary>
  586. /// <returns></returns>
  587. private decimal GetProfit()
  588. {
  589. if (this.OpenCloseMode == OpenCloseMode.BUILDTYPE_OPEN )//|| this.OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSETHENOPEN)
  590. {
  591. #region 建仓
  592. if (this.Direction == Direction.Bid)
  593. {
  594. //止损价 < 限价-(买点差-卖点差+止损卖点差) * 最小变动单位
  595. // _currentGoods.GoodsParameters.GoodsStatus != GoodsStatusType.Open
  596. if (_currentGoods == null || _currentGoods.GoodsParameters == null) return 0;
  597. if (_currentGoods.GoodsParameters.HqExchFigures < 20 &&
  598. _currentGoods.GoodsParameters.HqExchFigures > -20)
  599. {
  600. // ||_orderQuoteGoods.GoodsParameters.GoodsStatus != GoodsStatusType.Open
  601. var ptSubObj = CacheManager.GetTradeRule((int)_currentGoods.GoodsId,
  602. (int)eTradeRule.TRADERULE_SPPT);
  603. var ptSub = ptSubObj == null ? 0 : ptSubObj.FeeValue;
  604. var value = ( ptSub) / (decimal)
  605. Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures);
  606. return (_executePrice + value);
  607. }
  608. return _executePrice;
  609. }
  610. else
  611. {
  612. //止损价 > 限价 -(卖点差-买点差-止损买点差)* 最小变动单位
  613. //_currentGoods.GoodsParameters.GoodsStatus != GoodsStatusType.Open
  614. if (_currentGoods == null || _currentGoods.GoodsParameters == null) return 0;
  615. var ptSubObj = CacheManager.GetTradeRule((int)_currentGoods.GoodsId,
  616. (int)eTradeRule.TRADERULE_SPPT);
  617. var ptSub = ptSubObj == null ? 0 : ptSubObj.FeeValue;
  618. if (_currentGoods.GoodsParameters.HqExchFigures < 20 &&
  619. _currentGoods.GoodsParameters.HqExchFigures > -20)
  620. {
  621. var value = ( ptSub) / (decimal)
  622. Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures);
  623. return (_executePrice - value);
  624. }
  625. return _executePrice;
  626. }
  627. #endregion
  628. }
  629. else
  630. {
  631. //if (this.SelectOrder != null)
  632. //{
  633. // return this.SelectOrder.HoldingPrice;
  634. //}
  635. //return _currentGoods.CurrentPrice;
  636. bool flag = _currentGoods.GoodsParameters.HqExchFigures < 20 &&
  637. _currentGoods.GoodsParameters.HqExchFigures > -20;
  638. if (this.Direction == Direction.Ask)
  639. {
  640. //止盈价 > 买价 + (止盈点差 * 最小变动单位)
  641. //止盈价 >= 买价 + (止盈卖点差 * 最小变动单位)
  642. // ||_orderQuoteGoods.GoodsParameters.GoodsStatus != GoodsStatusType.Open
  643. var buyptSub = CacheManager.GetTradeRule((int)_currentGoods.GoodsId,
  644. (int)eTradeRule.TRADERULE_SPPT);
  645. var ptSub = buyptSub == null ? 0 : buyptSub.FeeValue;
  646. return _currentGoods.BidPrice +
  647. (flag
  648. ? ptSub /
  649. (decimal)Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures)
  650. : 0);
  651. }
  652. else
  653. {
  654. //止盈价 < 卖价 - (止盈点差 * 最小变动单位)
  655. //止盈价 <= 卖价 - (止盈买点差 * 最小变动单位)
  656. //||_orderQuoteGoods.GoodsParameters.GoodsStatus != GoodsStatusType.Open
  657. var sellptSub = CacheManager.GetTradeRule((int)_currentGoods.GoodsId,
  658. (int)eTradeRule.TRADERULE_SPPT);
  659. var ptSub = sellptSub == null ? 0 : sellptSub.FeeValue;
  660. return _currentGoods.AskPrice - (flag
  661. ? ptSub / (decimal)
  662. Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures)
  663. : 0);
  664. }
  665. }
  666. }
  667. // TRADERULE_XLIMITSLBUYPT = 4703,
  668. ///// <summary>
  669. ///// 限价止损卖点差
  670. ///// </summary>
  671. //TRADERULE_XLIMITSLSELLPT = 4704,
  672. /// <summary>
  673. /// 获取止损价
  674. /// </summary>
  675. /// <returns></returns>
  676. private decimal GetLoss()
  677. {
  678. if (this.OpenCloseMode == OpenCloseMode.BUILDTYPE_OPEN )//|| this.OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSETHENOPEN)
  679. {
  680. #region 建仓
  681. if (this.Direction == Direction.Bid)
  682. {
  683. //止损价 < 限价-(买点差-卖点差+止损卖点差) * 最小变动单位
  684. // _currentGoods.GoodsParameters.GoodsStatus != GoodsStatusType.Open
  685. if (_currentGoods == null || _currentGoods.GoodsParameters == null) return 0;
  686. if (_currentGoods.GoodsParameters.HqExchFigures < 20 &&
  687. _currentGoods.GoodsParameters.HqExchFigures > -20)
  688. {
  689. // ||_orderQuoteGoods.GoodsParameters.GoodsStatus != GoodsStatusType.Open
  690. var ptSubObj = CacheManager.GetTradeRule((int)_currentGoods.GoodsId,
  691. (int)eTradeRule.TRADERULE_SPPT);
  692. var ptSub = ptSubObj == null ? 0 : ptSubObj.FeeValue;
  693. var value = ( ptSub) / (decimal)
  694. Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures);
  695. return (_executePrice - value);
  696. }
  697. return _executePrice;
  698. }
  699. else
  700. {
  701. //止损价 > 限价 -(卖点差-买点差-止损买点差)* 最小变动单位
  702. //_currentGoods.GoodsParameters.GoodsStatus != GoodsStatusType.Open
  703. if (_currentGoods == null || _currentGoods.GoodsParameters == null) return 0;
  704. var ptSubObj = CacheManager.GetTradeRule((int)_currentGoods.GoodsId,
  705. (int)eTradeRule.TRADERULE_SPPT);
  706. var ptSub = ptSubObj == null ? 0 : ptSubObj.FeeValue;
  707. if (_currentGoods.GoodsParameters.HqExchFigures < 20 &&
  708. _currentGoods.GoodsParameters.HqExchFigures > -20)
  709. {
  710. var value = ( ptSub) / (decimal)
  711. Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures);
  712. return (_executePrice + value);
  713. }
  714. return _executePrice;
  715. }
  716. #endregion
  717. }
  718. else
  719. {
  720. bool flag = _currentGoods.GoodsParameters.HqExchFigures < 20 &&
  721. _currentGoods.GoodsParameters.HqExchFigures > -20;
  722. if (this.Direction == Direction.Ask)
  723. {
  724. //止损价 < =卖价 - (止损卖点差 * 最小变动单位)
  725. //||_orderQuoteGoods.GoodsParameters.GoodsStatus != GoodsStatusType.Open
  726. var ptSubObj = CacheManager.GetTradeRule((int)_currentGoods.GoodsId,
  727. (int)eTradeRule.TRADERULE_SPPT);
  728. var ptSub = ptSubObj == null ? 0 : ptSubObj.FeeValue;
  729. return (_currentGoods.BidPrice - (flag ? ptSub / (decimal)Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures)
  730. : 0));
  731. }
  732. else
  733. {
  734. //止损价 > =买价 + (止损买点差 * 最小变动单位)
  735. //||_orderQuoteGoods.GoodsParameters.GoodsStatus != GoodsStatusType.Open
  736. var ptSubObj = CacheManager.GetTradeRule((int)_currentGoods.GoodsId,
  737. (int)eTradeRule.TRADERULE_SPPT);
  738. var ptSub = ptSubObj == null ? 0 : ptSubObj.FeeValue;
  739. return (_currentGoods.AskPrice +
  740. (flag ? ptSub /
  741. (decimal)Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures)
  742. : 0));
  743. }
  744. }
  745. }
  746. /// <summary>
  747. /// 设置限价的范围
  748. /// </summary>
  749. protected override void SetEntrustPriceRange()
  750. {
  751. if (_currentGoods != null && _currentGoods.GoodsParameters != null)
  752. {
  753. RaisePropertyChanged(()=>IsPriceRangeVsb);
  754. bool flag = _currentGoods.GoodsParameters.HqExchFigures < 20 &&
  755. _currentGoods.GoodsParameters.HqExchFigures > -20;
  756. GoodsFeeType foodsfeeType;
  757. if (this.OpenCloseMode == OpenCloseMode.BUILDTYPE_OPEN)// || this.OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSETHENOPEN)
  758. {
  759. foodsfeeType = CacheManager.GetTradeRule((int) _currentGoods.GoodsId,
  760. (int)(Direction==Direction.Ask? eTradeRule.TRADERULE_SLPT:eTradeRule.TRADERULE_SPPT));
  761. if (Direction == Direction.Ask)
  762. {
  763. //限价 》 限价上限(max(买价, 卖价) + 限价卖点差*最小变动单位)
  764. //限价 《 限价下限(min(买价, 卖价) - 限价卖点差*最小变动单位)
  765. var ptSub = foodsfeeType == null ? 0 : foodsfeeType.FeeValue;
  766. MinLimit = _currentGoods.BidPrice;
  767. //Math.Max(_currentGoods.BidPrice, _currentGoods.AskPrice);
  768. // MinLimit = Math.Min(_currentGoods.BidPrice, _currentGoods.AskPrice) - _currentGoods.GoodsParameters.LimitOpenSellptSub / (decimal)
  769. //EntructPriceRange = QuotePrice -
  770. // _currentGoods.GoodsParameters.LimitOpenSellptSub / (decimal)
  771. // Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures);
  772. MaxLimit = _currentGoods.BidPrice + (flag
  773. ? ptSub / (decimal)
  774. Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures)
  775. : 0);
  776. }
  777. else
  778. {
  779. // 限 价 >= 【卖一价】 或 =< 【卖一价 - (限价买入买点差*最小变动单位)】
  780. var ptSub = foodsfeeType == null ? 0 : foodsfeeType.FeeValue;
  781. MinLimit = _currentGoods.AskPrice-(flag
  782. ? ptSub / (decimal)
  783. Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures)
  784. : 0) ;
  785. MaxLimit = _currentGoods.AskPrice;
  786. }
  787. }
  788. else
  789. {
  790. foodsfeeType = CacheManager.GetTradeRule((int) _currentGoods.GoodsId,
  791. (Direction==Direction.Ask? 4708:4707));
  792. if (Direction == Direction.Bid)
  793. {
  794. //限价 》 限价上限(max(买价, 卖价) + 限价卖点差*最小变动单位)
  795. //限价 《 限价下限(min(买价, 卖价) - 限价卖点差*最小变动单位)
  796. var ptSub = foodsfeeType == null ? 0 : foodsfeeType.FeeValue;
  797. MaxLimit = _currentGoods.AskPrice;
  798. //Math.Max(_currentGoods.BidPrice, _currentGoods.AskPrice);
  799. // MinLimit = Math.Min(_currentGoods.BidPrice, _currentGoods.AskPrice) - _currentGoods.GoodsParameters.LimitOpenSellptSub / (decimal)
  800. //EntructPriceRange = QuotePrice -
  801. // _currentGoods.GoodsParameters.LimitOpenSellptSub / (decimal)
  802. // Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures);
  803. MinLimit = _currentGoods.AskPrice - (flag
  804. ? ptSub / (decimal)
  805. Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures)
  806. : 0);
  807. }
  808. else
  809. {
  810. //限价 》 限价上限(max(买价, 卖价) + 限价买点差 * 最小变动单位)
  811. //限价 《 限价下限(min(买价, 卖价) - 限价买点差 * 最小变动单位)
  812. var ptSub = foodsfeeType == null ? 0 : foodsfeeType.FeeValue;
  813. MaxLimit = (flag
  814. ? ptSub / (decimal)
  815. Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures)
  816. : 0) + _currentGoods.BidPrice;
  817. MinLimit = _currentGoods.BidPrice;
  818. }
  819. }
  820. }
  821. //if (flag)
  822. //{
  823. // PriceMinUnit = 1 / Math.Pow(10, _currentGoods.GoodsParameters.HqExchFigures);
  824. //}
  825. }
  826. public override void CheckedVisibleEnable()
  827. {
  828. base.CheckedVisibleEnable();
  829. if (_priceMode == ePriceMode.PRICEMODE_LIMIT && OpenCloseMode == OpenCloseMode.BUILDTYPE_CLOSE&&_goodsOrderMode==GoodsOrderMode.Order) //限价只能按单平
  830. {
  831. ////设置原止损止盈
  832. if (SelectOrder != null)
  833. {
  834. StopLossChecked = SelectOrder.StopLoss > 0;///设置了止损
  835. this.StopLoss = SelectOrder.StopLoss;
  836. StopProfitChecked = SelectOrder.StopProfit > 0;///设置了止损
  837. this.StopProfit = SelectOrder.StopProfit;
  838. }
  839. SetProfitLoss();
  840. }
  841. }
  842. /// <summary>
  843. /// 设置平仓最大最小数量
  844. /// </summary>
  845. protected override void SetCloseQty()
  846. {
  847. var minQty = _goodsService.GetGoodsParamerRule((int)_currentGoods.GoodsId, _currentGoods.TradeMode, GoodsTradeConts.MINOPENTRADEQTY);
  848. MinLot = minQty == null ? defaut_minLot : minQty.FeeValue;
  849. decimal tempMaxLot = CalcAvailCloseQty();
  850. //按单平仓
  851. if (this.GoodsOrderMode == GoodsOrderMode.Order)
  852. {
  853. MaxLot = SelectOrder == null || !SelectOrder.IsCanClose ? 0 : SelectOrder.AvailQty;
  854. if (this.PriceMode == ePriceMode.PRICEMODE_LIMIT)
  855. {
  856. MaxLot = Math.Min(tempMaxLot, MaxLot);
  857. Lot = MaxLot;
  858. //#23420 投资者下做市商品的持仓,P+X交割申报配对成功,冻结头寸成功,选择做市商品进行限制平仓,报错:3093[头寸不足]
  859. }
  860. //MaxLot = SelectOrder == null || !SelectOrder.IsCanClose ? 0 : SelectOrder.AvailQty; ////未达持仓天数,不可平
  861. //MaxLot = Math.Min(tempMaxLot, MaxLot);
  862. }
  863. else
  864. {
  865. //按寸头平仓
  866. MaxLot = tempMaxLot;
  867. }
  868. }
  869. #endregion
  870. public override bool Validated(ref string msg)
  871. {
  872. if (!base.Validated(ref msg))
  873. {
  874. return false;
  875. }
  876. bool isProfitLoss = false;
  877. if (PriceMode==ePriceMode.PRICEMODE_LIMIT)
  878. {
  879. if (OpenCloseMode != OpenCloseMode.BUILDTYPE_CLOSE)
  880. {
  881. if (IsShowRaiseFall&&(ExecutePrice > this.UpPrice || ExecutePrice < LowPrice))
  882. {
  883. msg = Client_Resource.ExecutePrice_IsNotInRaiseFallRange;
  884. return false;
  885. }
  886. isProfitLoss = true;
  887. if (ExecutePrice > MinLimit && ExecutePrice < MaxLimit)
  888. {
  889. msg = Client_Resource.ErrorEntrustPrice;
  890. return false;
  891. }
  892. }
  893. else
  894. {
  895. if (GoodsOrderMode == GoodsOrderMode.Order)
  896. {
  897. isProfitLoss = true;
  898. if (!StopProfitChecked && !StopLossChecked)
  899. {
  900. msg = Client_Resource.xmacth_stopProfitLossSetError;
  901. return false;
  902. }
  903. }
  904. else
  905. {
  906. if (ExecutePrice > MinLimit && ExecutePrice < MaxLimit)
  907. {
  908. msg = Client_Resource.ErrorEntrustPrice;
  909. return false;
  910. }
  911. }
  912. }
  913. if (isProfitLoss && StopProfitChecked) ////止盈
  914. {
  915. //止盈
  916. if (!this.IsBidDirection)
  917. {
  918. if (this.StopProfit > this.MaxProfit)
  919. {
  920. msg = Muchinfo.MTPClient.Resources.Client_Resource.Trade_ProfitIsOut;
  921. return false;
  922. }
  923. }
  924. else
  925. {
  926. if (this.StopProfit < this.MaxProfit)
  927. {
  928. msg = Muchinfo.MTPClient.Resources.Client_Resource.Trade_ProfitIsOut;
  929. return false;
  930. }
  931. }
  932. if (this.StopProfit <= 0)
  933. {
  934. msg = Muchinfo.MTPClient.Resources.Client_Resource.Trade_ProfitLessThanZero;
  935. return false;
  936. }
  937. if (IsShowRaiseFall && (StopProfit > this.UpPrice || StopProfit < LowPrice))
  938. {
  939. msg = Client_Resource.ProfitPrice_IsNotInRaiseFallRange;
  940. return false;
  941. }
  942. }
  943. if (isProfitLoss && StopLossChecked) ////止损
  944. {
  945. if (!this.IsBidDirection)
  946. {
  947. if (this.StopLoss < this.MaxLoss)
  948. {
  949. msg = Muchinfo.MTPClient.Resources.Client_Resource.Trade_StopIsOut;
  950. return false;
  951. }
  952. }
  953. else
  954. {
  955. if (this.StopLoss > this.MaxLoss)
  956. {
  957. msg = Muchinfo.MTPClient.Resources.Client_Resource.Trade_StopIsOut;
  958. return false;
  959. }
  960. }
  961. if (this.StopLoss <= 0)
  962. {
  963. msg = Muchinfo.MTPClient.Resources.Client_Resource.Trade_StopLessThanZero;
  964. return false;
  965. }
  966. if (IsShowRaiseFall && (StopLoss > this.UpPrice || StopLoss < LowPrice))
  967. {
  968. msg = Client_Resource.LossPrice_IsNotInRaiseFallRange;
  969. return false;
  970. }
  971. }
  972. }
  973. return true;
  974. }
  975. }
  976. }