示例#1
0
        /// <summary>
        /// 定时查询--账户资金查询。
        /// </summary>
        /// <param name="queryInfo"></param>
        private void OnQueryFundExpired(CtpQueryFundInfo queryInfo)
        {
            try
            {
                TradingAccountField field = QueryTradingAccountFromCtp();
                m_dataBuffer.UpdateTradingAccountInfo(field);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(string.Format("OnQueryFundExpired() query fund info failed,{0}", ex.Message));
                m_logger.WriteError(string.Format("{0}.OnQueryFundExpired() query fund info failed,Error:{1}.",
                                                  ToString(), ex.Message));
                return;
            }

            try
            {
                USeFund fundInfo = m_dataBuffer.GetFund();

                FireFundChanged(fundInfo);
            }
            catch (Exception ex)
            {
                Debug.Assert(false, ex.Message);
                m_logger.WriteError(string.Format("{0}.OnQueryFundExpired() failed,Error:{1}.", ToString(), ex.Message));
            }
        }
 /// <summary>
 /// 查询帐户详细资金信息。
 /// </summary>
 /// <returns></returns>
 public override USeFundDetail QueryFundDetailInfo()
 {
     try
     {
         TradingAccountField field      = QueryTradingAccountFromCtp();
         USeFundDetail       fundDetail = CtpTradingAccountFieldToUSeFundDetail(field);
         return(fundDetail);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
示例#3
0
 //交易账户回报
 public static void Body_OnTradingAccount(TradingAccountField taf)
 {
     lock (OcAllTradingAccountField)
     {
         int index = OcAllTradingAccountField.IndexOf(taf);
         if (index == -1)
         {
             OcAllTradingAccountField.Insert(0, taf);
         }
         else
         {
             OcAllTradingAccountField[index].CThostFtdcTradingAccountFieldInstance = taf.CThostFtdcTradingAccountFieldInstance;
         }
     }
 }
        /// <summary>
        /// CTP InvestorPositionField To USeFundDetail。
        /// </summary>
        /// <param name="field"></param>
        /// <returns></returns>
        private USeFundDetail CtpTradingAccountFieldToUSeFundDetail(TradingAccountField field)
        {
            USeFundDetail fundDetail = new USeFundDetail();

            try
            {
                fundDetail.AccountID   = field.AccountID.Trim();
                fundDetail.Available   = field.Available.ToDecimal();
                fundDetail.Deposit     = field.Deposit.ToDecimal();
                fundDetail.Mortgage    = field.Mortgage.ToDecimal();
                fundDetail.PreBalance  = field.PreBalance.ToDecimal();
                fundDetail.PreCredit   = field.PreCredit.ToDecimal();
                fundDetail.PreMortgage = field.PreMortgage.ToDecimal();
                fundDetail.WithDraw    = field.Withdraw.ToDecimal();

                // 静态权益 =  上日结存 - 上次信用额度 - 上次质押金额
                //           + 质押金额- 今日出金 + 今日入金
                decimal staticBenefit = field.PreBalance.ToDecimal() - field.PreCredit.ToDecimal() - field.PreMortgage.ToDecimal() +
                                        field.Mortgage.ToDecimal() - field.Withdraw.ToDecimal() + field.Deposit.ToDecimal();
                // 动态权益 = 静态权益 + 持仓盈亏 + 平仓盈亏 - 手续费(取成交回报手续费)
                decimal dynamicBenefit = staticBenefit + field.CloseProfit.ToDecimal() + field.PositionProfit.ToDecimal() - field.Commission.ToDecimal();
                fundDetail.StaticBenefit  = staticBenefit;
                fundDetail.CloseProfit    = field.CloseProfit.ToDecimal();
                fundDetail.TradeFee       = field.Commission.ToDecimal();
                fundDetail.HoldProfit     = field.PositionProfit.ToDecimal();
                fundDetail.HoldMargin     = field.CurrMargin.ToDecimal();
                fundDetail.DynamicBenefit = dynamicBenefit;
                fundDetail.FrozonMargin   = field.FrozenMargin.ToDecimal();
                fundDetail.FrozonFee      = field.FrozenCommission.ToDecimal();
                fundDetail.Fronzon        = field.FrozenCommission.ToDecimal() + field.FrozenCash.ToDecimal() + field.FrozenMargin.ToDecimal();
                //风险度 = (占用保证金 + 交割保证金 + 买冻结保证金 + 卖冻结保证金) / 动态权益
                //[yangming]修正风险度 = (占用保证金 + 交割保证金 ) / 动态权益
                //decimal risk = (field.CurrMargin.ToDecimal() + field.DeliveryMargin.ToDecimal() + field.FrozenMargin.ToDecimal()).Divide(dynamicBenefit);
                decimal risk = (field.CurrMargin.ToDecimal() + field.DeliveryMargin.ToDecimal()).Divide(dynamicBenefit);
                fundDetail.Risk       = risk;
                fundDetail.PreferCash = field.WithdrawQuota.ToDecimal();
            }
            catch (Exception ex)
            {
                Debug.Assert(false, "CtpTradingAccountFieldToUSeFundDetail() convet failed," + ex.Message);
            }
            return(fundDetail);
        }
        /// <summary>
        /// CTP InvestorPositionField To USePosition。
        /// </summary>
        /// <param name="field"></param>
        /// <returns></returns>
        private USeFund CtpTradingAccountFieldToUSeFund(TradingAccountField field)
        {
            USeFund fundInfo = new USeFund();

            try
            {
                fundInfo.AccountID      = field.AccountID.Trim();
                fundInfo.PreMortgage    = field.PreMortgage.ToDecimal();
                fundInfo.PreCredit      = field.PreCredit.ToDecimal();
                fundInfo.PreBalance     = field.PreBalance.ToDecimal();
                fundInfo.Deposit        = field.Deposit.ToDecimal();
                fundInfo.WithDraw       = field.Withdraw.ToDecimal();
                fundInfo.Mortgage       = field.Mortgage.ToDecimal();
                fundInfo.DeliveryMargin = field.DeliveryMargin.ToDecimal();
            }
            catch (Exception ex)
            {
                Debug.Assert(false, "CtpTradingAccountFieldToUSeAccountInfo() convet failed," + ex.Message);
            }
            return(fundInfo);
        }