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
{
///
/// 持仓汇总
///
public class HoldingSummary : OrderBase,ICloneable
{
[PropertyDisc("AccountID")]
public ulong AccountId
{
get;
set;
}
///
/// 期初持仓数量
///
private decimal _positionQty;
///
/// 期初持仓数量
/// Changes to that property's value raise the PropertyChanged event.
///
[PropertyDisc("PositionQty")]
public decimal PositionQty
{
get { return _positionQty; }
set { Set(() => PositionQty, ref _positionQty, value); }
}
///
/// 期初持仓总金额
///
private decimal _holderAmount;
///
/// 期初持仓总金额
///
[PropertyDisc("HolderAmount")]
public decimal HolderAmount
{
get { return _holderAmount; }
set { Set(() => HolderAmount, ref _holderAmount, value); }
}
///
/// 当前持仓总金额
///
private decimal _curHolderAmount;
///
/// 当前持仓总金额
/// Changes to that property's value raise the PropertyChanged event.
///
[PropertyDisc("CurHolderAmount")]
public decimal CurHolderAmount
{
get { return _curHolderAmount; }
set
{
Set(() => CurHolderAmount, ref _curHolderAmount, value);
RaisePropertyChanged(() => GoodsPaymentDisplay);
RaisePropertyChanged(() => ProfitPercen);
}
}
///
/// 当前持仓数量
///
private decimal _lot;
///
/// 当前持仓数量
/// Changes to that property's value raise the PropertyChanged event.
///
[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;
}
}
///
/// 持仓冻结数量
///
private decimal _frozenQty;
///
/// 持仓冻结数量
/// Changes to that property's value raise the PropertyChanged event.
///
[PropertyDisc("FrozenQty")]
public decimal FrozenQty
{
get { return _frozenQty; }
set
{
Set(() => FrozenQty, ref _frozenQty, value);
RaisePropertyChanged(() => AvailQty);
}
}
///
/// 其他冻结数量
///
private decimal _otherFrozenQty;
///
/// 其他冻结数量
///
[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); }
}
///
/// 获取或设置 持仓均价
/// Changes to that property's value raise the PropertyChanged event.
///
public decimal HoldingAVGPrice
{
get { return _curHolderAmount / _lot / AgreeUnit; }
}
///
/// 显示持仓均价
///
public string DisplayHoldingAVGPrice
{
get
{
if (HoldingAVGPrice > 0)
{
return HoldingAVGPrice.ToString(PriceFormat);
}
else
{
return "-";
}
}
}
[PropertyDisc("AgreeUnit")]
public decimal AgreeUnit { get; set; }
///
/// 最新价
///
private decimal _latestPrice;
///
/// 获取或设置 最新价
/// Changes to that property's value raise the PropertyChanged event.
///
public decimal LatestPrice
{
get
{
return _latestPrice;
}
set
{
Set(() => LatestPrice, ref _latestPrice, value);
RaisePropertyChanged(() => DisplayLatestPrice);
RaisePropertyChanged(() => MarketValue);
}
}
///
/// 显示最新价
///
public string DisplayLatestPrice
{
get
{
if (LatestPrice > 0)
{
return LatestPrice.ToString(PriceFormat);
}
else
{
return "-";
}
}
}
///
/// 浮动盈亏
///
private decimal _pLFloat;
///
/// 获取或设置 浮动盈亏
/// Changes to that property's value raise the PropertyChanged event.
///
public decimal PLFloat
{
get
{
return _pLFloat;
}
set
{
Set(() => PLFloat, ref _pLFloat, value);
RaisePropertyChanged(() => DisplayPLFloat);
//RaisePropertyChanged(() => SumFloatPL);
// 错误 #92030 浮动盈亏
RaisePropertyChanged(() => ProfitLossOpenDisplay);
}
}
///
/// 浮动盈亏(计算商品目标汇率后,主要用于资金账户盈亏计算)
///
private decimal _pLFloatWithRate;
///
/// 浮动盈亏(计算商品目标汇率后,主要用于资金账户盈亏计算)
///
public decimal PLFloatWithRate
{
get { return _pLFloatWithRate; }
set
{
Set(() => PLFloatWithRate, ref _pLFloatWithRate, value);
}
}
///
/// 显示 浮动盈亏
///
public string DisplayPLFloat
{
get
{
if (PLFloat != decimal.Zero)
{
return PLFloat.ToString("N2");
}
else
{
return "-";
}
}
}
///
/// 平仓价
///
private decimal _closePrice;
///
/// 获取或设置 平仓价
/// Changes to that property's value raise the PropertyChanged event.
///
public decimal ClosePrice
{
get
{
return _closePrice;
}
set
{
Set(() => ClosePrice, ref _closePrice, value);
RaisePropertyChanged(() => DisplayClosePrice);
}
}
///
/// 显示平仓价格
///
public string DisplayClosePrice
{
get
{
//if (ClosePrice > 0 && MarketType != eTradeMode.TRADEMODE_SALE)
if (ClosePrice > 0)
{
return ClosePrice.ToString(PriceFormat);
}
else
{
return "-";
}
}
}
///
/// 显示建仓日期
///
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; }
///
/// Gets a value indicating whether this instance is can close.
///
/// true if this instance is can close; otherwise, false.
public bool IsCanClose
{
get
{
var canClose = ShowCloseOrder;
//return TradeMode != eTradeMode.TRADEMODE_SALE;
return AvailQty > 0 && canClose;
//return true;
}
}
///
/// Config.xml配置参数:是否显示平仓
///
/// true if [show close order]; otherwise, false.
public bool ShowCloseOrder { get; set; }
///
/// Gets or sets a value indicating whether this instance is can SPSL.
///
/// true if this instance is can SPSL; otherwise, false.
public bool IsCanSPSL
{
get
{
//todo:通过服务配置控制
var canSPSL = SystemParamManager.IsCanSPSL;
return AvailQty > 0 && canSPSL;
}
}
#region 添加锁仓数量
/////
///// 锁仓数量
/////
//public decimal LockQty { get; set; }
/////
///// 持仓总量
/////
//public decimal TotalLot
//{
// get { return Lot + LockQty; }
//}
#endregion
///
/// 持仓单
///
public List Holders
{
get; set;
}
private decimal _sumFloatPL;
///
/// 盈亏汇总
///
public decimal SumFloatPL
{
get { return _sumFloatPL; }
set { Set(() => SumFloatPL, ref _sumFloatPL, value); }
}
private decimal _goodsPayment;
///
/// 货款=持仓价*持有总量*合约单位
///
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;
///
/// 市值=最新价*持有总量*合约单位;
///
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 "-";
}
}
}
///
/// 盈亏比例=(市值—货款)/ 货款 * 100% ;
///
public string ProfitPercen
{
get
{
if (GoodsPayment != 0 && MarketValue != 0)
{
return ((MarketValue - GoodsPayment) / GoodsPayment).ToString("P2");
}
else
{
return "-";
}
}
}
///
/// 可平数量
///
public decimal CloseQty {
get
{
return Math.Min((TnAvailQty - TnFreezeqty), (AvailQty));
} }
///
/// T+N 冻结
///
public decimal TnFreezeqty { get; set; }
///
/// 达到T+N的持仓数量(包括T+N冻结)
///
public decimal TnAvailQty { get; set; }
///
/// 是否显示交割
///
public bool IsShowDelivery { get; set; }
///
/// 价格小数位
///
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"); }
}
///
/// 昨结价
///
private decimal _preClosePrice;
///
/// 结算价
///
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();
}
///
/// 开仓均价
///
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;
///
/// 开仓浮动盈亏
///
public decimal OpenProfitLoss
{
get { return _openProfitLoss; }
set { _openProfitLoss = value; }
}
///
/// 浮动盈亏=+/-(当前市价-开仓均价)*持仓数量*合约单位*汇率,买方向为正,卖方向为负
///
public string ProfitLossOpenDisplay
{
get
{
if (_openProfitLoss == 0)
{
return "-";
}
return _openProfitLoss.ToString("f2");
}
}
}
}