HoldingSummary.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. using System.Collections.Generic;
  2. using System.Windows.Documents;
  3. using Muchinfo.MTPClient.Data.Enums;
  4. using Muchinfo.MTPClient.Data.Helper;
  5. using System;
  6. using System.Windows;
  7. using Muchinfo.MTPClient.Infrastructure.Utilities;
  8. namespace Muchinfo.MTPClient.Data.Model.Account
  9. {
  10. /// <summary>
  11. /// 持仓汇总
  12. /// </summary>
  13. public class HoldingSummary : OrderBase,ICloneable
  14. {
  15. [PropertyDisc("AccountID")]
  16. public ulong AccountId
  17. {
  18. get;
  19. set;
  20. }
  21. /// <summary>
  22. /// 期初持仓数量
  23. /// </summary>
  24. private decimal _positionQty;
  25. /// <summary>
  26. /// 期初持仓数量
  27. /// Changes to that property's value raise the PropertyChanged event.
  28. /// </summary>
  29. [PropertyDisc("PositionQty")]
  30. public decimal PositionQty
  31. {
  32. get { return _positionQty; }
  33. set { Set(() => PositionQty, ref _positionQty, value); }
  34. }
  35. /// <summary>
  36. /// 期初持仓总金额
  37. /// </summary>
  38. private decimal _holderAmount;
  39. /// <summary>
  40. /// 期初持仓总金额
  41. /// </summary>
  42. [PropertyDisc("HolderAmount")]
  43. public decimal HolderAmount
  44. {
  45. get { return _holderAmount; }
  46. set { Set(() => HolderAmount, ref _holderAmount, value); }
  47. }
  48. /// <summary>
  49. /// 当前持仓总金额
  50. /// </summary>
  51. private decimal _curHolderAmount;
  52. /// <summary>
  53. /// 当前持仓总金额
  54. /// Changes to that property's value raise the PropertyChanged event.
  55. /// </summary>
  56. [PropertyDisc("CurHolderAmount")]
  57. public decimal CurHolderAmount
  58. {
  59. get { return _curHolderAmount; }
  60. set
  61. {
  62. Set(() => CurHolderAmount, ref _curHolderAmount, value);
  63. RaisePropertyChanged(() => GoodsPaymentDisplay);
  64. RaisePropertyChanged(() => ProfitPercen);
  65. }
  66. }
  67. /// <summary>
  68. /// 当前持仓数量
  69. /// </summary>
  70. private decimal _lot;
  71. /// <summary>
  72. /// 当前持仓数量
  73. /// Changes to that property's value raise the PropertyChanged event.
  74. /// </summary>
  75. [PropertyDisc("CurPositionQty")]
  76. public decimal Lot
  77. {
  78. get { return _lot; }
  79. set
  80. {
  81. Set(() => Lot, ref _lot, value);
  82. RaisePropertyChanged(() => AvailQty);
  83. }
  84. }
  85. private decimal _availQty;
  86. public decimal AvailQty
  87. {
  88. get
  89. {
  90. _availQty = _lot - _frozenQty - _otherFrozenQty;
  91. return _availQty;
  92. }
  93. }
  94. /// <summary>
  95. /// 持仓冻结数量
  96. /// </summary>
  97. private decimal _frozenQty;
  98. /// <summary>
  99. /// 持仓冻结数量
  100. /// Changes to that property's value raise the PropertyChanged event.
  101. /// </summary>
  102. [PropertyDisc("FrozenQty")]
  103. public decimal FrozenQty
  104. {
  105. get { return _frozenQty; }
  106. set
  107. {
  108. Set(() => FrozenQty, ref _frozenQty, value);
  109. RaisePropertyChanged(() => AvailQty);
  110. }
  111. }
  112. /// <summary>
  113. /// 其他冻结数量
  114. /// </summary>
  115. private decimal _otherFrozenQty;
  116. /// <summary>
  117. /// 其他冻结数量
  118. /// </summary>
  119. [PropertyDisc("OtherFrozenQty")]
  120. public decimal OtherFrozenQty
  121. {
  122. get { return _otherFrozenQty; }
  123. set
  124. {
  125. Set(() => OtherFrozenQty, ref _otherFrozenQty, value);
  126. RaisePropertyChanged(() => AvailQty);
  127. }
  128. }
  129. private decimal _openReqQty;
  130. [PropertyDisc("OpenReqQty")]
  131. public decimal OpenReqQty
  132. {
  133. get { return _openReqQty; }
  134. set { Set(() => OpenReqQty, ref _openReqQty, value); }
  135. }
  136. private decimal _openTotalQty;
  137. [PropertyDisc("OpenTotalQty")]
  138. public decimal OpenTotalQty
  139. {
  140. get { return _openTotalQty; }
  141. set { Set(() => OpenTotalQty, ref _openTotalQty, value); }
  142. }
  143. private decimal _closeTotalQty;
  144. [PropertyDisc("CloseTotalQty")]
  145. public decimal CloseTotalQty
  146. {
  147. get { return _closeTotalQty; }
  148. set { Set(() => CloseTotalQty, ref _closeTotalQty, value); }
  149. }
  150. /// <summary>
  151. /// 获取或设置 持仓均价
  152. /// Changes to that property's value raise the PropertyChanged event.
  153. /// </summary>
  154. public decimal HoldingAVGPrice
  155. {
  156. get { return _curHolderAmount / _lot / AgreeUnit; }
  157. }
  158. /// <summary>
  159. /// 显示持仓均价
  160. /// </summary>
  161. public string DisplayHoldingAVGPrice
  162. {
  163. get
  164. {
  165. if (HoldingAVGPrice > 0)
  166. {
  167. return HoldingAVGPrice.ToString(PriceFormat);
  168. }
  169. else
  170. {
  171. return "-";
  172. }
  173. }
  174. }
  175. [PropertyDisc("AgreeUnit")]
  176. public decimal AgreeUnit { get; set; }
  177. /// <summary>
  178. /// 最新价
  179. /// </summary>
  180. private decimal _latestPrice;
  181. /// <summary>
  182. /// 获取或设置 最新价
  183. /// Changes to that property's value raise the PropertyChanged event.
  184. /// </summary>
  185. public decimal LatestPrice
  186. {
  187. get
  188. {
  189. return _latestPrice;
  190. }
  191. set
  192. {
  193. Set(() => LatestPrice, ref _latestPrice, value);
  194. RaisePropertyChanged(() => DisplayLatestPrice);
  195. RaisePropertyChanged(() => MarketValue);
  196. }
  197. }
  198. /// <summary>
  199. /// 显示最新价
  200. /// </summary>
  201. public string DisplayLatestPrice
  202. {
  203. get
  204. {
  205. if (LatestPrice > 0)
  206. {
  207. return LatestPrice.ToString(PriceFormat);
  208. }
  209. else
  210. {
  211. return "-";
  212. }
  213. }
  214. }
  215. /// <summary>
  216. /// 浮动盈亏
  217. /// </summary>
  218. private decimal _pLFloat;
  219. /// <summary>
  220. /// 获取或设置 浮动盈亏
  221. /// Changes to that property's value raise the PropertyChanged event.
  222. /// </summary>
  223. public decimal PLFloat
  224. {
  225. get
  226. {
  227. return _pLFloat;
  228. }
  229. set
  230. {
  231. Set(() => PLFloat, ref _pLFloat, value);
  232. RaisePropertyChanged(() => DisplayPLFloat);
  233. //RaisePropertyChanged(() => SumFloatPL);
  234. // 错误 #92030 浮动盈亏
  235. RaisePropertyChanged(() => ProfitLossOpenDisplay);
  236. }
  237. }
  238. /// <summary>
  239. /// 浮动盈亏(计算商品目标汇率后,主要用于资金账户盈亏计算)
  240. /// </summary>
  241. private decimal _pLFloatWithRate;
  242. /// <summary>
  243. /// 浮动盈亏(计算商品目标汇率后,主要用于资金账户盈亏计算)
  244. /// </summary>
  245. public decimal PLFloatWithRate
  246. {
  247. get { return _pLFloatWithRate; }
  248. set
  249. {
  250. Set(() => PLFloatWithRate, ref _pLFloatWithRate, value);
  251. }
  252. }
  253. /// <summary>
  254. /// 显示 浮动盈亏
  255. /// </summary>
  256. public string DisplayPLFloat
  257. {
  258. get
  259. {
  260. if (PLFloat != decimal.Zero)
  261. {
  262. return PLFloat.ToString("N2");
  263. }
  264. else
  265. {
  266. return "-";
  267. }
  268. }
  269. }
  270. /// <summary>
  271. /// 平仓价
  272. /// </summary>
  273. private decimal _closePrice;
  274. /// <summary>
  275. /// 获取或设置 平仓价
  276. /// Changes to that property's value raise the PropertyChanged event.
  277. /// </summary>
  278. public decimal ClosePrice
  279. {
  280. get
  281. {
  282. return _closePrice;
  283. }
  284. set
  285. {
  286. Set(() => ClosePrice, ref _closePrice, value);
  287. RaisePropertyChanged(() => DisplayClosePrice);
  288. }
  289. }
  290. /// <summary>
  291. /// 显示平仓价格
  292. /// </summary>
  293. public string DisplayClosePrice
  294. {
  295. get
  296. {
  297. //if (ClosePrice > 0 && MarketType != eTradeMode.TRADEMODE_SALE)
  298. if (ClosePrice > 0)
  299. {
  300. return ClosePrice.ToString(PriceFormat);
  301. }
  302. else
  303. {
  304. return "-";
  305. }
  306. }
  307. }
  308. /// <summary>
  309. /// 显示建仓日期
  310. /// </summary>
  311. public string StrOpenDirection
  312. {
  313. get
  314. {
  315. return Direction.Discription();
  316. //switch (OpenDirection)
  317. //{
  318. // case Direction.Ask:
  319. // return Client_Resource.Domain_SellOut;
  320. // case Direction.Bid:
  321. // return Client_Resource.Domain_BuyIn;
  322. // default:
  323. // return Client_Resource.Domain_BuyIn;
  324. //}
  325. }
  326. }
  327. public eTradeMode TradeMode { get; set; }
  328. /// <summary>
  329. /// Gets a value indicating whether this instance is can close.
  330. /// </summary>
  331. /// <value><c>true</c> if this instance is can close; otherwise, <c>false</c>.</value>
  332. public bool IsCanClose
  333. {
  334. get
  335. {
  336. var canClose = ShowCloseOrder;
  337. //return TradeMode != eTradeMode.TRADEMODE_SALE;
  338. return AvailQty > 0 && canClose;
  339. //return true;
  340. }
  341. }
  342. /// <summary>
  343. /// Config.xml配置参数:是否显示平仓
  344. /// </summary>
  345. /// <value><c>true</c> if [show close order]; otherwise, <c>false</c>.</value>
  346. public bool ShowCloseOrder { get; set; }
  347. /// <summary>
  348. /// Gets or sets a value indicating whether this instance is can SPSL.
  349. /// </summary>
  350. /// <value><c>true</c> if this instance is can SPSL; otherwise, <c>false</c>.</value>
  351. public bool IsCanSPSL
  352. {
  353. get
  354. {
  355. //todo:通过服务配置控制
  356. var canSPSL = SystemParamManager.IsCanSPSL;
  357. return AvailQty > 0 && canSPSL;
  358. }
  359. }
  360. #region 添加锁仓数量
  361. ///// <summary>
  362. ///// 锁仓数量
  363. ///// </summary>
  364. //public decimal LockQty { get; set; }
  365. ///// <summary>
  366. ///// 持仓总量
  367. ///// </summary>
  368. //public decimal TotalLot
  369. //{
  370. // get { return Lot + LockQty; }
  371. //}
  372. #endregion
  373. /// <summary>
  374. /// 持仓单
  375. /// </summary>
  376. public List<HoldingOrder> Holders
  377. {
  378. get; set;
  379. }
  380. private decimal _sumFloatPL;
  381. /// <summary>
  382. /// 盈亏汇总
  383. /// </summary>
  384. public decimal SumFloatPL
  385. {
  386. get { return _sumFloatPL; }
  387. set { Set(() => SumFloatPL, ref _sumFloatPL, value); }
  388. }
  389. private decimal _goodsPayment;
  390. /// <summary>
  391. /// 货款=持仓价*持有总量*合约单位
  392. /// </summary>
  393. public decimal GoodsPayment
  394. {
  395. get { return _goodsPayment; }
  396. set
  397. {
  398. Set(() => GoodsPayment, ref _goodsPayment, value);
  399. RaisePropertyChanged(() => GoodsPaymentDisplay);
  400. RaisePropertyChanged(() => ProfitPercen);
  401. }
  402. }
  403. public string GoodsPaymentDisplay
  404. {
  405. get
  406. {
  407. if (GoodsPayment != 0)
  408. {
  409. return GoodsPayment.ToString("f2");
  410. }
  411. else
  412. {
  413. return "-";
  414. }
  415. }
  416. }
  417. private decimal _marketValue;
  418. /// <summary>
  419. /// 市值=最新价*持有总量*合约单位;
  420. /// </summary>
  421. public decimal MarketValue
  422. {
  423. get { return _marketValue; }
  424. set
  425. {
  426. Set(() => MarketValue, ref _marketValue, value);
  427. RaisePropertyChanged(() => MarketValueDisplay);
  428. RaisePropertyChanged(() => ProfitPercen);
  429. }
  430. }
  431. public string MarketValueDisplay
  432. {
  433. get
  434. {
  435. if (MarketValue != 0)
  436. {
  437. return MarketValue.ToString("f2");
  438. }
  439. else
  440. {
  441. return "-";
  442. }
  443. }
  444. }
  445. /// <summary>
  446. /// 盈亏比例=(市值—货款)/ 货款 * 100% ;
  447. /// </summary>
  448. public string ProfitPercen
  449. {
  450. get
  451. {
  452. if (GoodsPayment != 0 && MarketValue != 0)
  453. {
  454. return ((MarketValue - GoodsPayment) / GoodsPayment).ToString("P2");
  455. }
  456. else
  457. {
  458. return "-";
  459. }
  460. }
  461. }
  462. /// <summary>
  463. /// 可平数量
  464. /// </summary>
  465. public decimal CloseQty {
  466. get
  467. {
  468. return Math.Min((TnAvailQty - TnFreezeqty), (AvailQty));
  469. } }
  470. /// <summary>
  471. /// T+N 冻结
  472. /// </summary>
  473. public decimal TnFreezeqty { get; set; }
  474. /// <summary>
  475. /// 达到T+N的持仓数量(包括T+N冻结)
  476. /// </summary>
  477. public decimal TnAvailQty { get; set; }
  478. /// <summary>
  479. /// 是否显示交割
  480. /// </summary>
  481. public bool IsShowDelivery { get; set; }
  482. /// <summary>
  483. /// 价格小数位
  484. /// </summary>
  485. public int DecimalPlace { get; set; }
  486. //public override string PriceExpFormat
  487. //{
  488. // get
  489. // {
  490. // if (DecimalPlace < 3)
  491. // {
  492. // return "F2";
  493. // }
  494. // else
  495. // {
  496. // return PriceFormat;
  497. // }
  498. // }
  499. //}
  500. //public override string PriceFormat
  501. //{
  502. // get
  503. // {
  504. // if (DecimalPlace >= 0 && DecimalPlace < 20)
  505. // {
  506. // return "F" + DecimalPlace;
  507. // }
  508. // else
  509. // {
  510. // return "F2";
  511. // }
  512. // }
  513. //}
  514. [PropertyDisc("UsedMargin")]
  515. public decimal UsedMargin
  516. {
  517. get;
  518. set;
  519. }
  520. public string UsedMarginDisplay
  521. {
  522. get { return UsedMargin.ToString("f2"); }
  523. }
  524. /// <summary>
  525. /// 昨结价
  526. /// </summary>
  527. private decimal _preClosePrice;
  528. /// <summary>
  529. /// 结算价
  530. /// </summary>
  531. private decimal _preSettlePrice;
  532. [PropertyDisc("PreClosePrice")]
  533. public decimal PreClosePrice
  534. {
  535. get { return _preClosePrice; }
  536. set { Set(() => PreClosePrice, ref _preClosePrice, value); }
  537. }
  538. [PropertyDisc("PreSettlePrice")]
  539. public decimal PreSettlePrice
  540. {
  541. get { return _preClosePrice; }
  542. set { Set(() => PreSettlePrice, ref _preSettlePrice, value); }
  543. }
  544. public string PreClosePriceDisplay
  545. {
  546. get { return PreClosePrice.ToString(PriceFormat); }
  547. }
  548. public string PreSettlePriceDisplay
  549. {
  550. get { return PreSettlePrice.ToString(PriceFormat); }
  551. }
  552. public object Clone()
  553. {
  554. return MemberwiseClone();
  555. }
  556. /// <summary>
  557. /// 开仓均价
  558. /// </summary>
  559. private decimal _openAvaPrice;
  560. public decimal OpenAvaPrice
  561. {
  562. get { return _openAvaPrice; }
  563. set
  564. {
  565. if (value != 0)
  566. {
  567. _openAvaPrice = value;
  568. }
  569. }
  570. }
  571. public string OpenAvaPriceDisplay
  572. {
  573. get
  574. {
  575. return OpenAvaPrice.ToString(PriceFormat);
  576. }
  577. }
  578. private decimal _openProfitLoss;
  579. /// <summary>
  580. /// 开仓浮动盈亏
  581. /// </summary>
  582. public decimal OpenProfitLoss
  583. {
  584. get { return _openProfitLoss; }
  585. set { _openProfitLoss = value; }
  586. }
  587. /// <summary>
  588. /// 浮动盈亏=+/-(当前市价-开仓均价)*持仓数量*合约单位*汇率,买方向为正,卖方向为负
  589. /// </summary>
  590. public string ProfitLossOpenDisplay
  591. {
  592. get
  593. {
  594. if (_openProfitLoss == 0)
  595. {
  596. return "-";
  597. }
  598. return _openProfitLoss.ToString("f2");
  599. }
  600. }
  601. }
  602. }