Example #1
0
        private List <KeyValuePair <Guid, decimal> > CalculateUsableAmount(Agent.Account account, Settings.MarginInterestOption interestOption, DateTime tradeDay)
        {
            Dictionary <Guid, decimal> floatingPLDict = this.GetFloatingPLs(account, tradeDay);
            var balanceDict = this.GetBalances(account, tradeDay);
            var result      = new List <KeyValuePair <Guid, decimal> >(balanceDict.Count);
            Dictionary <Guid, MarginResult> usableDict = null;

            if (interestOption == Settings.MarginInterestOption.Usable)
            {
                usableDict = AccountUsableNecessaryCalculator.Default.Calculate(account, tradeDay, _instrumentManager);
            }
            foreach (var eachPair in balanceDict)
            {
                decimal usable     = 0m;
                decimal balance    = eachPair.Value;
                Guid    currencyId = eachPair.Key;

                if (interestOption == Settings.MarginInterestOption.Usable)
                {
                    usable = balance + this.GetFloatingPL(currencyId, floatingPLDict, tradeDay) - this.GetUsableMargin(currencyId, usableDict);
                }
                else if (interestOption == Settings.MarginInterestOption.Balance)
                {
                    usable = balance;
                }
                else if (interestOption == Settings.MarginInterestOption.Equity)
                {
                    usable = balance + this.GetFloatingPL(currencyId, floatingPLDict, tradeDay);
                }
                result.Add(new KeyValuePair <Guid, decimal>(currencyId, usable));
            }
            return(result);
        }
Example #2
0
 internal HistoryOrderDeleter(Order order, Settings.Setting setting, bool isPayForInstalmentDebitInterest)
 {
     this.Account = order.Owner.Owner;
     _order       = order;
     _isPayForInstalmentDebitInterest = isPayForInstalmentDebitInterest;
     _physicalOrder       = _order as PhysicalOrder;
     _currencyId          = DBResetRepository.GetCurrencyId(this.Account.Id, order.Instrument().Id, _order.Owner.ExecuteTime.Value);
     _historyOrderRecover = new HistoryOrderRecover(this.Account, _order.Instrument().Id, OrderHelper.GetAffectedOrders(_order), new List <Guid> {
         order.Id
     }, setting);
 }
Example #3
0
 internal TradeDayInfo(Agent.Account account, Guid instrumentId, DateTime tradeDay, InstrumentTradeDaySetting instrumentTradeDaySetting, List <Guid> affectedOrders, Setting setting)
 {
     _setting = setting;
     _instrumentTradeDaySetting = instrumentTradeDaySetting;
     this.Account         = _setting.GetAccount(account.Id, tradeDay);
     this.Instrument      = _setting.GetInstrument(instrumentId, tradeDay);
     _resetOrders         = account.GetResetOrders(instrumentId);
     _resetOrderRelations = account.GetResetOrderRelations(instrumentId);
     this.TradeDay        = tradeDay;
     _instrumentTradeDaySetting.UseCompatibleMode = _instrumentTradeDaySetting.ValueDate == null && this.Instrument.PLValueDay < 1 ? true : false;
     this.RateSetting    = new RateSetting(this.Account.IsMultiCurrency, this.Account.CurrencyId, this.Instrument.CurrencyId, tradeDay, setting);
     this.AffectedOrders = affectedOrders;
 }
Example #4
0
        private Dictionary <Guid, decimal> GetBalances(Agent.Account account, DateTime tradeDate)
        {
            var tradeDay = Settings.Setting.Default.GetTradeDay(tradeDate);
            Dictionary <Guid, decimal> result = new Dictionary <Guid, decimal>(account.Funds.Count());

            foreach (var eachFund in account.Funds)
            {
                result.Add(eachFund.CurrencyId, eachFund.Balance);
            }

            foreach (var eachBill in account.Bills)
            {
                if (eachBill.UpdateTime > tradeDay.EndTime)
                {
                    decimal balance;
                    if (result.TryGetValue(eachBill.CurrencyID, out balance))
                    {
                        result[eachBill.CurrencyID] = balance - eachBill.Value;
                    }
                }
            }
            return(result);
        }
Example #5
0
        internal static decimal GetAllExecuteMarketValue(Agent.Account account)
        {
            decimal result = 0m;

            foreach (var tran in account.Transactions)
            {
                if (!tran.IsPhysical)
                {
                    continue;
                }
                foreach (PhysicalOrder order in tran.Orders)
                {
                    bool isExecuted = order.Phase == OrderPhase.Executed;
                    bool isDeposit  = order.PhysicalTradeSide == PhysicalTradeSide.Deposit;
                    bool isBuy      = order.PhysicalTradeSide == PhysicalTradeSide.Buy;
                    if (order.IsOpen && order.IsPhysical && isExecuted && (isDeposit || isBuy))
                    {
                        result += order.MarketValue;
                    }
                }
            }
            return(result);
        }
Example #6
0
        private Dictionary <Guid, decimal> GetFloatingPLs(Agent.Account account, DateTime tradeDay)
        {
            Dictionary <Guid, decimal> result = new Dictionary <Guid, decimal>();

            foreach (var eachInstrument in _instrumentManager.Instruments)
            {
                InstrumentResetItem resetItem = eachInstrument.GetResetItem(tradeDay);
                if (resetItem == null)
                {
                    continue;
                }
                var     settingInstrument = Settings.Setting.Default.GetInstrument(eachInstrument.Id, tradeDay);
                decimal lastFloatingPL;
                if (!result.TryGetValue(settingInstrument.CurrencyId, out lastFloatingPL))
                {
                    result.Add(settingInstrument.CurrencyId, resetItem.FloatingPL);
                }
                else
                {
                    result[settingInstrument.CurrencyId] = lastFloatingPL + resetItem.FloatingPL;
                }
            }
            return(result);
        }