コード例 #1
0
ファイル: InstructionEngine.cs プロジェクト: kiquenet/B4F
 private bool transferAllCash(IClientDepartureInstruction instruction)
 {
     bool success = false;
     // Create MoneyTransferOrder
     Money totalValue = instruction.Account.TotalAll;
     if (totalValue.IsGreaterThanZero && instruction.MoneyTransferOrder == null)
     {
         if (instruction.Account.Portfolio.PortfolioInstrument.Where(x => x.Size.IsNotZero).Count() > 0)
             instruction.Message += "Active positions still exist. Cancel this instruction and create a new one.";
         else
         {
             Money moneyOrderAmount = instruction.Account.ActiveMoneyTransferOrders.Select(x => x.Amount).Sum();
             if ((totalValue - moneyOrderAmount).IsGreaterThanZero)
             {
                 IMoneyTransferOrder moneyOrder = new MoneyTransferOrder(instruction, totalValue);
                 instruction.MoneyTransferOrder = moneyOrder;
                 instruction.Message += string.Format("Money Transfer order created ({0})", moneyOrder.Amount.DisplayString);
                 success = true;
             }
             else
                 instruction.Message += string.Format("Money Transfer not possible since active moneyorders already exist ({0})", moneyOrderAmount.DisplayString);
         }
     }
     return success;
 }
コード例 #2
0
ファイル: InstructionEngine.cs プロジェクト: kiquenet/B4F
        private bool createMoneyTransferOrder(ICashWithdrawalInstruction instruction)
        {
            bool createMoneyOrder = false;
            if (Money.Add(instruction.Account.TotalCash, instruction.Amount).IsGreaterThanOrEqualToZero)
                createMoneyOrder = true;
            else
            {
                switch (instruction.CheckAccountCash(CashWithdrawalInstructionActions.PlaceFreeUpCashFundOrder))
                {
                    case CashWithdrawalInstructionCheckCashReturnValues.PlaceCashFundOrder:
                        instruction.Warning = true;
                        placeCashFundOrder(instruction);
                        createMoneyOrder = true;
                        break;
                    case CashWithdrawalInstructionCheckCashReturnValues.CreateRebalanceInstruction:
                        createRebalanceInstruction(instruction);
                        instruction.Warning = true;
                        instruction.Status = (int)CashWithdrawalInstructionStati.New;
                        break;
                    case CashWithdrawalInstructionCheckCashReturnValues.NotEnoughBuyingPower:
                        instruction.Message = "Not enough buying power to create the Money Transfer order.";
                        instruction.Warning = true;
                        break;
                }
            }

            if (createMoneyOrder)
            {
                IMoneyTransferOrder moneyOrder = new MoneyTransferOrder(instruction);
                string info = "";
                if (instruction.UpdateableOrders != null && instruction.UpdateableOrders.Count > 0)
                    info = " and a Cash Fund order";
                else if (instruction.Account.ActiveRebalanceInstructions.Count > 0)
                {
                    foreach (IInstruction rebInst in instruction.Account.ActiveRebalanceInstructions)
                    {
                        if (rebInst.Key == 0)
                            info = " and a Rebalance Instruction";
                    }
                }
                instruction.Message = string.Format("Money Transfer order{0} created on {1}", info, DateTime.Now.ToString("yyyy-MM-dd hh:mm"));
                instruction.Warning = (info != "");
            }
            return true;
        }