Ejemplo n.º 1
0
 public UpdateBalanceInternalCommand(string operationId,
                                     string accountId, decimal amountDelta, string comment, string auditLog,
                                     string source, AccountBalanceChangeReasonType changeReasonType, string eventSourceId, string assetPairId, DateTime tradingDay)
 {
     OperationId      = operationId ?? throw new ArgumentNullException(nameof(operationId));
     AccountId        = accountId ?? throw new ArgumentNullException(nameof(accountId));
     AmountDelta      = amountDelta;
     Comment          = comment;
     AuditLog         = auditLog;
     Source           = source ?? throw new ArgumentNullException(nameof(source));
     EventSourceId    = eventSourceId;
     AssetPairId      = assetPairId;
     TradingDay       = tradingDay;
     ChangeReasonType = changeReasonType.RequiredEnum(nameof(changeReasonType));
 }
 public AccountHistory(string id, DateTime changeTimestamp, string accountId, string clientId,
                       decimal changeAmount, decimal balance, decimal withdrawTransferLimit, string comment,
                       AccountBalanceChangeReasonType reasonType, string eventSourceId, string legalEntity, string auditLog,
                       string instrument, DateTime tradingDate, string correlationId)
 {
     Id = id;
     ChangeTimestamp       = changeTimestamp;
     AccountId             = accountId;
     ClientId              = clientId;
     ChangeAmount          = changeAmount;
     Balance               = balance;
     WithdrawTransferLimit = withdrawTransferLimit;
     Comment               = comment;
     ReasonType            = reasonType;
     EventSourceId         = eventSourceId;
     LegalEntity           = legalEntity;
     AuditLog              = auditLog;
     Instrument            = instrument;
     TradingDate           = tradingDate;
     CorrelationId         = correlationId;
 }
 public Task <string> ChargeManuallyAsync(string accountId, decimal amountDelta,
                                          [CanBeNull] string operationId, string reason, string source, string auditLog,
                                          AccountBalanceChangeReasonType type, string eventSourceId, string assetPairId, DateTime tradingDay)
 {
     operationId = operationId ?? Guid.NewGuid().ToString();
     _cqrsEngine.SendCommand(
         new UpdateBalanceInternalCommand(
             operationId,
             accountId,
             amountDelta,
             reason,
             auditLog,
             source,
             type,
             eventSourceId,
             assetPairId,
             tradingDay),
         _cqrsContextNamesSettings.AccountsManagement,
         _cqrsContextNamesSettings.AccountsManagement);
     return(Task.FromResult(operationId));
 }
Ejemplo n.º 4
0
 private AccountBalanceChangeReasonTypeContract Convert(AccountBalanceChangeReasonType reasonType)
 {
     return _convertService.Convert<AccountBalanceChangeReasonTypeContract>(reasonType);
 }
Ejemplo n.º 5
0
        public async Task <bool> HandleBalanceChange(string accountId,
                                                     decimal accountBalance, decimal changeAmount, AccountBalanceChangeReasonType reasonType, DateTime eventTime)
        {
            _lockSlim.EnterWriteLock();
            try
            {
                var account = _accounts[accountId];

                switch (reasonType)
                {
                case AccountBalanceChangeReasonType.RealizedPnL:
                    account.TodayRealizedPnL += changeAmount;
                    break;

                case AccountBalanceChangeReasonType.UnrealizedDailyPnL:
                    account.TodayUnrealizedPnL += changeAmount;
                    account.TodayOtherAmount   += changeAmount;   // TODO: why?
                    break;

                case AccountBalanceChangeReasonType.Deposit:
                    account.TodayDepositAmount += changeAmount;
                    break;

                case AccountBalanceChangeReasonType.Withdraw:
                    account.TodayWithdrawAmount += changeAmount;
                    break;

                case AccountBalanceChangeReasonType.Commission:
                    account.TodayCommissionAmount += changeAmount;
                    break;

                default:
                    account.TodayOtherAmount += changeAmount;
                    break;
                }

                if (account.LastBalanceChangeTime > eventTime)
                {
                    await _log.WriteInfoAsync(nameof(AccountsCacheService), nameof(HandleBalanceChange),
                                              $"Account with id {account.Id} has balance in newer state then the event");

                    return(false);
                }

                account.Balance = accountBalance;
                account.LastBalanceChangeTime = eventTime;
            }
            finally
            {
                _lockSlim.ExitWriteLock();
            }
            return(true);
        }
Ejemplo n.º 6
0
        public static decimal GetTotalByType(this IEnumerable <IAccountBalanceChange> history, AccountBalanceChangeReasonType type)
        {
            if (history == null || !history.Any())
            {
                return(0);
            }

            return(history
                   .Where(x => x.ReasonType == type)
                   .Sum(x => x.ChangeAmount));
        }