| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671 |
- using System.Collections.Generic;
- using System.Windows.Documents;
- using Muchinfo.MTPClient.Data.Enums;
- using Muchinfo.MTPClient.Data.Helper;
- using System;
- using System.Windows;
- using Muchinfo.MTPClient.Infrastructure.Utilities;
- namespace Muchinfo.MTPClient.Data.Model.Account
- {
- /// <summary>
- /// 持仓汇总
- /// </summary>
- public class HoldingSummary : OrderBase,ICloneable
- {
- [PropertyDisc("AccountID")]
- public ulong AccountId
- {
- get;
- set;
- }
- /// <summary>
- /// 期初持仓数量
- /// </summary>
- private decimal _positionQty;
- /// <summary>
- /// 期初持仓数量
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- [PropertyDisc("PositionQty")]
- public decimal PositionQty
- {
- get { return _positionQty; }
- set { Set(() => PositionQty, ref _positionQty, value); }
- }
- /// <summary>
- /// 期初持仓总金额
- /// </summary>
- private decimal _holderAmount;
- /// <summary>
- /// 期初持仓总金额
- /// </summary>
- [PropertyDisc("HolderAmount")]
- public decimal HolderAmount
- {
- get { return _holderAmount; }
- set { Set(() => HolderAmount, ref _holderAmount, value); }
- }
- /// <summary>
- /// 当前持仓总金额
- /// </summary>
- private decimal _curHolderAmount;
- /// <summary>
- /// 当前持仓总金额
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- [PropertyDisc("CurHolderAmount")]
- public decimal CurHolderAmount
- {
- get { return _curHolderAmount; }
- set
- {
- Set(() => CurHolderAmount, ref _curHolderAmount, value);
- RaisePropertyChanged(() => GoodsPaymentDisplay);
- RaisePropertyChanged(() => ProfitPercen);
- }
- }
- /// <summary>
- /// 当前持仓数量
- /// </summary>
- private decimal _lot;
- /// <summary>
- /// 当前持仓数量
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- [PropertyDisc("CurPositionQty")]
- public decimal Lot
- {
- get { return _lot; }
- set
- {
- Set(() => Lot, ref _lot, value);
- RaisePropertyChanged(() => AvailQty);
- }
- }
- private decimal _availQty;
- public decimal AvailQty
- {
- get
- {
- _availQty = _lot - _frozenQty - _otherFrozenQty;
- return _availQty;
- }
- }
- /// <summary>
- /// 持仓冻结数量
- /// </summary>
- private decimal _frozenQty;
- /// <summary>
- /// 持仓冻结数量
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- [PropertyDisc("FrozenQty")]
- public decimal FrozenQty
- {
- get { return _frozenQty; }
- set
- {
- Set(() => FrozenQty, ref _frozenQty, value);
- RaisePropertyChanged(() => AvailQty);
- }
- }
- /// <summary>
- /// 其他冻结数量
- /// </summary>
- private decimal _otherFrozenQty;
- /// <summary>
- /// 其他冻结数量
- /// </summary>
- [PropertyDisc("OtherFrozenQty")]
- public decimal OtherFrozenQty
- {
- get { return _otherFrozenQty; }
- set
- {
- Set(() => OtherFrozenQty, ref _otherFrozenQty, value);
- RaisePropertyChanged(() => AvailQty);
- }
- }
- private decimal _openReqQty;
- [PropertyDisc("OpenReqQty")]
- public decimal OpenReqQty
- {
- get { return _openReqQty; }
- set { Set(() => OpenReqQty, ref _openReqQty, value); }
- }
- private decimal _openTotalQty;
- [PropertyDisc("OpenTotalQty")]
- public decimal OpenTotalQty
- {
- get { return _openTotalQty; }
- set { Set(() => OpenTotalQty, ref _openTotalQty, value); }
- }
- private decimal _closeTotalQty;
- [PropertyDisc("CloseTotalQty")]
- public decimal CloseTotalQty
- {
- get { return _closeTotalQty; }
- set { Set(() => CloseTotalQty, ref _closeTotalQty, value); }
- }
- /// <summary>
- /// 获取或设置 持仓均价
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public decimal HoldingAVGPrice
- {
- get { return _curHolderAmount / _lot / AgreeUnit; }
- }
- /// <summary>
- /// 显示持仓均价
- /// </summary>
- public string DisplayHoldingAVGPrice
- {
- get
- {
- if (HoldingAVGPrice > 0)
- {
- return HoldingAVGPrice.ToString(PriceFormat);
- }
- else
- {
- return "-";
- }
- }
- }
- [PropertyDisc("AgreeUnit")]
- public decimal AgreeUnit { get; set; }
- /// <summary>
- /// 最新价
- /// </summary>
- private decimal _latestPrice;
- /// <summary>
- /// 获取或设置 最新价
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public decimal LatestPrice
- {
- get
- {
- return _latestPrice;
- }
- set
- {
- Set(() => LatestPrice, ref _latestPrice, value);
- RaisePropertyChanged(() => DisplayLatestPrice);
- RaisePropertyChanged(() => MarketValue);
- }
- }
- /// <summary>
- /// 显示最新价
- /// </summary>
- public string DisplayLatestPrice
- {
- get
- {
- if (LatestPrice > 0)
- {
- return LatestPrice.ToString(PriceFormat);
- }
- else
- {
- return "-";
- }
- }
- }
- /// <summary>
- /// 浮动盈亏
- /// </summary>
- private decimal _pLFloat;
- /// <summary>
- /// 获取或设置 浮动盈亏
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public decimal PLFloat
- {
- get
- {
- return _pLFloat;
- }
- set
- {
- Set(() => PLFloat, ref _pLFloat, value);
- RaisePropertyChanged(() => DisplayPLFloat);
- //RaisePropertyChanged(() => SumFloatPL);
- // 错误 #92030 浮动盈亏
- RaisePropertyChanged(() => ProfitLossOpenDisplay);
- }
- }
- /// <summary>
- /// 浮动盈亏(计算商品目标汇率后,主要用于资金账户盈亏计算)
- /// </summary>
- private decimal _pLFloatWithRate;
- /// <summary>
- /// 浮动盈亏(计算商品目标汇率后,主要用于资金账户盈亏计算)
- /// </summary>
- public decimal PLFloatWithRate
- {
- get { return _pLFloatWithRate; }
- set
- {
- Set(() => PLFloatWithRate, ref _pLFloatWithRate, value);
- }
- }
- /// <summary>
- /// 显示 浮动盈亏
- /// </summary>
- public string DisplayPLFloat
- {
- get
- {
- if (PLFloat != decimal.Zero)
- {
- return PLFloat.ToString("N2");
- }
- else
- {
- return "-";
- }
- }
- }
- /// <summary>
- /// 平仓价
- /// </summary>
- private decimal _closePrice;
- /// <summary>
- /// 获取或设置 平仓价
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public decimal ClosePrice
- {
- get
- {
- return _closePrice;
- }
- set
- {
- Set(() => ClosePrice, ref _closePrice, value);
- RaisePropertyChanged(() => DisplayClosePrice);
- }
- }
- /// <summary>
- /// 显示平仓价格
- /// </summary>
- public string DisplayClosePrice
- {
- get
- {
- //if (ClosePrice > 0 && MarketType != eTradeMode.TRADEMODE_SALE)
- if (ClosePrice > 0)
- {
- return ClosePrice.ToString(PriceFormat);
- }
- else
- {
- return "-";
- }
- }
- }
- /// <summary>
- /// 显示建仓日期
- /// </summary>
- public string StrOpenDirection
- {
- get
- {
- return Direction.Discription();
- //switch (OpenDirection)
- //{
- // case Direction.Ask:
- // return Client_Resource.Domain_SellOut;
- // case Direction.Bid:
- // return Client_Resource.Domain_BuyIn;
- // default:
- // return Client_Resource.Domain_BuyIn;
- //}
- }
- }
- public eTradeMode TradeMode { get; set; }
- /// <summary>
- /// Gets a value indicating whether this instance is can close.
- /// </summary>
- /// <value><c>true</c> if this instance is can close; otherwise, <c>false</c>.</value>
- public bool IsCanClose
- {
- get
- {
- var canClose = ShowCloseOrder;
- //return TradeMode != eTradeMode.TRADEMODE_SALE;
- return AvailQty > 0 && canClose;
- //return true;
- }
- }
- /// <summary>
- /// Config.xml配置参数:是否显示平仓
- /// </summary>
- /// <value><c>true</c> if [show close order]; otherwise, <c>false</c>.</value>
- public bool ShowCloseOrder { get; set; }
- /// <summary>
- /// Gets or sets a value indicating whether this instance is can SPSL.
- /// </summary>
- /// <value><c>true</c> if this instance is can SPSL; otherwise, <c>false</c>.</value>
- public bool IsCanSPSL
- {
- get
- {
- //todo:通过服务配置控制
- var canSPSL = SystemParamManager.IsCanSPSL;
- return AvailQty > 0 && canSPSL;
- }
- }
- #region 添加锁仓数量
- ///// <summary>
- ///// 锁仓数量
- ///// </summary>
- //public decimal LockQty { get; set; }
- ///// <summary>
- ///// 持仓总量
- ///// </summary>
- //public decimal TotalLot
- //{
- // get { return Lot + LockQty; }
- //}
- #endregion
- /// <summary>
- /// 持仓单
- /// </summary>
- public List<HoldingOrder> Holders
- {
- get; set;
- }
- private decimal _sumFloatPL;
- /// <summary>
- /// 盈亏汇总
- /// </summary>
- public decimal SumFloatPL
- {
- get { return _sumFloatPL; }
- set { Set(() => SumFloatPL, ref _sumFloatPL, value); }
- }
- private decimal _goodsPayment;
- /// <summary>
- /// 货款=持仓价*持有总量*合约单位
- /// </summary>
- public decimal GoodsPayment
- {
- get { return _goodsPayment; }
- set
- {
- Set(() => GoodsPayment, ref _goodsPayment, value);
- RaisePropertyChanged(() => GoodsPaymentDisplay);
- RaisePropertyChanged(() => ProfitPercen);
- }
- }
- public string GoodsPaymentDisplay
- {
- get
- {
- if (GoodsPayment != 0)
- {
- return GoodsPayment.ToString("f2");
- }
- else
- {
- return "-";
- }
- }
- }
- private decimal _marketValue;
- /// <summary>
- /// 市值=最新价*持有总量*合约单位;
- /// </summary>
- public decimal MarketValue
- {
- get { return _marketValue; }
- set
- {
- Set(() => MarketValue, ref _marketValue, value);
- RaisePropertyChanged(() => MarketValueDisplay);
- RaisePropertyChanged(() => ProfitPercen);
- }
- }
- public string MarketValueDisplay
- {
- get
- {
- if (MarketValue != 0)
- {
- return MarketValue.ToString("f2");
- }
- else
- {
- return "-";
- }
- }
- }
- /// <summary>
- /// 盈亏比例=(市值—货款)/ 货款 * 100% ;
- /// </summary>
- public string ProfitPercen
- {
- get
- {
- if (GoodsPayment != 0 && MarketValue != 0)
- {
- return ((MarketValue - GoodsPayment) / GoodsPayment).ToString("P2");
- }
- else
- {
- return "-";
- }
- }
- }
- /// <summary>
- /// 可平数量
- /// </summary>
- public decimal CloseQty {
- get
- {
- return Math.Min((TnAvailQty - TnFreezeqty), (AvailQty));
- } }
- /// <summary>
- /// T+N 冻结
- /// </summary>
- public decimal TnFreezeqty { get; set; }
- /// <summary>
- /// 达到T+N的持仓数量(包括T+N冻结)
- /// </summary>
- public decimal TnAvailQty { get; set; }
- /// <summary>
- /// 是否显示交割
- /// </summary>
- public bool IsShowDelivery { get; set; }
- /// <summary>
- /// 价格小数位
- /// </summary>
- public int DecimalPlace { get; set; }
- //public override string PriceExpFormat
- //{
- // get
- // {
- // if (DecimalPlace < 3)
- // {
- // return "F2";
- // }
- // else
- // {
- // return PriceFormat;
- // }
- // }
- //}
- //public override string PriceFormat
- //{
- // get
- // {
- // if (DecimalPlace >= 0 && DecimalPlace < 20)
- // {
- // return "F" + DecimalPlace;
- // }
- // else
- // {
- // return "F2";
- // }
- // }
- //}
- [PropertyDisc("UsedMargin")]
- public decimal UsedMargin
- {
- get;
- set;
- }
- public string UsedMarginDisplay
- {
- get { return UsedMargin.ToString("f2"); }
- }
- /// <summary>
- /// 昨结价
- /// </summary>
- private decimal _preClosePrice;
- /// <summary>
- /// 结算价
- /// </summary>
- private decimal _preSettlePrice;
- [PropertyDisc("PreClosePrice")]
- public decimal PreClosePrice
- {
- get { return _preClosePrice; }
- set { Set(() => PreClosePrice, ref _preClosePrice, value); }
- }
- [PropertyDisc("PreSettlePrice")]
- public decimal PreSettlePrice
- {
- get { return _preClosePrice; }
- set { Set(() => PreSettlePrice, ref _preSettlePrice, value); }
- }
- public string PreClosePriceDisplay
- {
- get { return PreClosePrice.ToString(PriceFormat); }
- }
- public string PreSettlePriceDisplay
- {
- get { return PreSettlePrice.ToString(PriceFormat); }
- }
- public object Clone()
- {
- return MemberwiseClone();
- }
- /// <summary>
- /// 开仓均价
- /// </summary>
- private decimal _openAvaPrice;
- public decimal OpenAvaPrice
- {
- get { return _openAvaPrice; }
- set
- {
- if (value != 0)
- {
- _openAvaPrice = value;
- }
- }
- }
- public string OpenAvaPriceDisplay
- {
- get
- {
- return OpenAvaPrice.ToString(PriceFormat);
- }
- }
- private decimal _openProfitLoss;
- /// <summary>
- /// 开仓浮动盈亏
- /// </summary>
- public decimal OpenProfitLoss
- {
- get { return _openProfitLoss; }
- set { _openProfitLoss = value; }
- }
- /// <summary>
- /// 浮动盈亏=+/-(当前市价-开仓均价)*持仓数量*合约单位*汇率,买方向为正,卖方向为负
- /// </summary>
- public string ProfitLossOpenDisplay
- {
- get
- {
- if (_openProfitLoss == 0)
- {
- return "-";
- }
- return _openProfitLoss.ToString("f2");
- }
- }
- }
- }
|