Пример #1
0
        /// <summary>
        /// Retreives the PendingTransaciton obejct from the list if present, then removes the instance from the list and
        /// returns to the caller
        /// </summary>
        /// <param name="id"></param>
        /// <param name="pendingEntityType"></param>
        /// <returns></returns>
        private PendingTransaction RemovePendingTransaction(string id, PendingTransactionType pendingEntityType)
        {
            PendingTransaction pendingTransaction = null;

            if (PendingBalance > 0)
            {
                foreach (var tempPendingTransaction in _pendingTransactions)
                {
                    if (tempPendingTransaction.InstanceId == id &&
                        tempPendingTransaction.PendingTransactionType == pendingEntityType)
                    {
                        pendingTransaction = tempPendingTransaction;
                        break;
                    }
                }
                // If the instance is found, remove it from pending transaction list and update the balance
                if (pendingTransaction != null)
                {
                    _pendingTransactions.Remove(pendingTransaction);
                    return(pendingTransaction);
                }
            }
            else
            {
                Log.Error("No pending balance found for ID: " + id);
            }
            return(null);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:System.Object"/> class.
 /// </summary>
 public PendingTransaction(Currency currency, string instanceId, PendingTransactionType pendingEntityType,
                           decimal amount, int balanceId)
 {
     Currency               = currency;
     InstanceId             = instanceId;
     PendingTransactionType = pendingEntityType;
     Amount    = amount;
     BalanceId = balanceId;
 }
Пример #3
0
        /// <summary>
        /// Adds a transaction for either a withdrawal or Order that is yet pending
        /// </summary>
        /// <returns></returns>
        public bool AddPendingTransaction(string id, PendingTransactionType pendingEntityType, decimal amount)
        {
            // Add this pending transaction to the pending entities list. This entity can only be removed from this list
            // when the transaction is compelte for this entity(Trade, Withdraw confirmed) or reverted in case of order
            // cancelled
            PendingTransaction pendingEntity = new PendingTransaction(Currency, id, pendingEntityType, amount, BalanceId);

            _pendingTransactions.Add(pendingEntity);
            // Deduct the amount
            _availableBalance += amount;
            return(true);
        }
Пример #4
0
        /// <summary>
        /// Called when a transaction is confirmed, updates the balance and the Pending Transaction List accordingly
        /// </summary>
        /// <returns></returns>
        public bool ConfirmPendingTransaction(string id, PendingTransactionType pendingEntityType, decimal amount)
        {
            PendingTransaction pendingTransaction = RemovePendingTransaction(id, pendingEntityType);

            if (pendingTransaction != null)
            {
                // As the Pending transaction is confirmed for either withdraw or order
                _currentBalance += amount;
                return(true);
            }

            return(false);
        }
Пример #5
0
        /// <summary>
        /// Handles the event of an order cancel, and restores amount to the available balance
        /// </summary>
        /// <param name="id"></param>
        /// <param name="pendingEntityType"></param>
        /// <param name="amount"></param>
        /// <returns></returns>
        public bool CancelPendingTransaction(string id, PendingTransactionType pendingEntityType, decimal amount)
        {
            PendingTransaction pendingTransaction = RemovePendingTransaction(id, pendingEntityType);

            if (pendingTransaction != null)
            {
                // As the Pending transaction is cancelled for order
                _availableBalance += amount;
                return(true);
            }

            return(false);
        }