コード例 #1
0
 /// <summary>
 /// Update cash position based on account action
 /// TODO: add sync action to scheduler for live trading (get current funds from account via broker API) => will be done via tickethandler (it will contact the api)
 /// </summary>
 /// <param name="action"></param>
 /// <param name="currency"></param>
 /// <param name="amount"></param>
 /// <param name="quantfund">In case the cash position affects a specific quant fund</param>
 public void Process(AccountActionType action, CurrencyType currency, decimal amount, IQuantFund quantfund = null)
 {
     //Check action type and process
     if (action == AccountActionType.Sync)
     {
         SyncFunds(currency, amount);
     }
     else if (action == AccountActionType.Credit)
     {
         throw new NotImplementedException();
     }
     else if (action == AccountActionType.Deposit)
     {
         throw new NotImplementedException();
     }
     else if (action == AccountActionType.Dividend)
     {
         throw new NotImplementedException();
     }
     else if (action == AccountActionType.Withdrawal)
     {
         throw new NotImplementedException();
     }
     //TODO: What to do with currently set funds and fund withdrawals
 }
コード例 #2
0
ファイル: ConsoleInput.cs プロジェクト: Alex-x18/this
        public static void IncomeOrExpense(AccountActionType accountActionType)
        {
            Console.CursorVisible = true;
            string currencyType;
            string category;
            string note;

            Console.Write("@ Specify currency type > ");
            currencyType = Console.ReadLine().ToUpper();
            Console.Write("@ Specify amount > ");
            if (!SafeDecimalInput(out decimal amount))
            {
                ConsoleOutput.ShowApplicationResult(new ApplicationResult {
                    Success = false,
                    Message = "Invalid input"
                });
                return;
            }
            Console.Write("@ Specify category > ");
            category = Console.ReadLine();
            Console.Write("@ Specify note > ");
            note = Console.ReadLine();
            ConsoleOutput.ShowApplicationResult(Application.AddIncomeOrExpense(accountActionType, currencyType, amount, category, note));
            Console.CursorVisible = false;
        }
コード例 #3
0
ファイル: AccountAction.cs プロジェクト: Alex-x18/this
 public AccountAction(AccountActionType type, AccountCurrency currency, string category, string note)
 {
     Timestamp = DateTime.Now;
     Type      = type;
     Note      = note;
     Category  = category;
     Currency  = currency;
 }
コード例 #4
0
ファイル: Application.cs プロジェクト: Alex-x18/this
        private static void DoIncomeOrExpenseOperation(AccountActionType actionType, AccountCurrency targetCurrency, decimal finalAmount)
        {
            switch (actionType)
            {
            case AccountActionType.Expense: {
                targetCurrency.Substract(finalAmount);
                break;
            }

            case AccountActionType.Income: {
                targetCurrency.Add(finalAmount);
                break;
            }
            }
        }
コード例 #5
0
ファイル: Application.cs プロジェクト: Alex-x18/this
        public static ApplicationResult AddIncomeOrExpense(AccountActionType actionType, string currencyType, decimal amount, string category, string note)
        {
            if (amount <= 0)
            {
                return(new ApplicationResult {
                    Success = false,
                    Message = "Amount cannot be zero or less than zero"
                });
            }
            if (currencyType.ToLower() == "auto")
            {
                currencyType = CurrentAccount.Currency.Type;
            }
            var currentAccountCurrency = CurrentAccount.Currency;

            if (currencyType != CurrentAccount.Currency.Type)
            {
                try {
                    var result = AccountCurrency.Convert(currencyType, CurrentAccount.Currency.Type, amount);
                    DoIncomeOrExpenseOperation(actionType, currentAccountCurrency, result);
                    AccountActionManager.AddAccountAction(new AccountAction(actionType, new AccountCurrency(CurrentAccount.Currency.Type, result), category, note));
                    AccountActionManager.UpdateData();
                    AccountManager.UpdateData();
                } catch (BadConversionException ex) {
                    return(new ApplicationResult {
                        Success = false,
                        Message = ex.Message
                    });
                }
                return(new ApplicationResult {
                    Success = true,
                    Message = "Successfully converted and added"
                });
            }
            DoIncomeOrExpenseOperation(actionType, currentAccountCurrency, amount);
            AccountActionManager.AddAccountAction(new AccountAction(actionType, new AccountCurrency(currencyType, amount), category, note));
            AccountActionManager.UpdateData();
            AccountManager.UpdateData();
            return(new ApplicationResult {
                Success = true,
                Message = "Successfully added"
            });
        }
コード例 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AccountAction"/> class.
 /// </summary>
 /// <param name="accountactiontype">The accountactiontype.</param>
 /// <param name="currencytype">The currencytype.</param>
 /// <param name="balance">The balance.</param>
 public AccountAction(AccountActionType accountactiontype, CurrencyType currencytype, decimal balance)
 {
     AccountActionType = accountactiontype;
     CurrencyType      = currencytype;
     Balance           = balance;
 }
コード例 #7
0
        public async Task ShouldGetFilteredEntries(string userId, string userName, string email, AccountActionType type, DateTime?dateFrom = null, DateTime?dateTo = null)
        {
            // Arrange
            Context.AccountLogEntries.AddRange(AccountLogEntryFaker.Generate(10));

            Context.AccountLogEntries.Add(new AccountLogEntryDbModel
            {
                UserId    = "alexpvt",
                UserName  = "******",
                Email     = "*****@*****.**",
                Type      = (int)AccountActionType.SignIn,
                EventDate = DateTimeNow
            });

            await Context.SaveChangesAsync();

            var filter = new AccountLogsFilter
            {
                UserId   = userId,
                UserName = userName,
                Email    = email,
                Type     = type,
                DateFrom = dateFrom,
                DateTo   = dateTo
            };

            // Act
            var entries = await _accountLogService.GetLogsAsync(filter);

            // Assert
            entries.Count().ShouldBeEqualTo(1);

            var entry = entries.Single();

            entry.UserId.ShouldBeEqualTo("alexpvt");
            entry.UserName.ShouldBeEqualTo("Alexander Pashnikov");
            entry.Email.ShouldBeEqualTo("*****@*****.**");
            entry.Type.ShouldBeEqualTo(AccountActionType.SignIn);
            entry.EventDate.ShouldBeEqualTo(DateTimeNow);
        }