Ejemplo n.º 1
0
 public bool Contains(uint256 hash)
 {
     lock (TransactionsLock)
     {
         return(Transactions.ContainsKey(hash));
     }
 }
        public async System.Threading.Tasks.Task RollbackTransactionAsync(string transId)
        {
            if (string.IsNullOrEmpty(transId))
            {
                return;
            }
            try
            {
                if (Transactions.ContainsKey(transId))
                {
                    var tran = Transactions[transId];
                    await tran.RollbackAsync();

                    //await tran.CreateSavepointAsync(transId);
                    Transactions.Remove(transId);
                    //GC.SuppressFinalize(tran);
                }
            }
            catch (Exception e)
            {
                await Logger.ErrorAsync(e);

                throw;
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Finds a transaction given an ID
 /// </summary>
 /// <param name="id">The id of the transaction to find..</param>
 /// <returns>The matched transaction.</returns>
 public Transaction FindTransaction(string id)
 {
     if (Transactions.ContainsKey(id))
     {
         return(Transactions[id]);
     }
     return(null);
 }
        /// <summary>
        ///		Crea una transacción para un proveedor
        /// </summary>
        internal void Add(ProviderModel provider)
        {
            string key = Normalize(provider.Key);

            if (!Transactions.ContainsKey(key))
            {
                Transactions.Add(key, new BatchTransactionModel(provider));
            }
        }
 /// <summary>
 ///		Elimina los datos de una transacción
 /// </summary>
 internal void Remove(string key)
 {
     // Normaliza la clave
     key = Normalize(key);
     // Borra el elemento
     if (Transactions.ContainsKey(key))
     {
         Transactions.Remove(key);
     }
 }
Ejemplo n.º 6
0
        public bool CheckStopLoss(IPattern p, Kline kline)
        {
            if (!Transactions.ContainsKey(kline.Symbol))
            {
                return(false);
            }

            var t = Transactions[kline.Symbol];

            t.HighPrice = p.HighPrice;

            var sell = t.CheckStopLoss(t, kline.Close);

            return(sell);
        }
Ejemplo n.º 7
0
        public void FillBulkOperations(ObservableCollection <Service.BOR> bulkOperationResponses)
        {
            foreach (Service.BOR bulkOperationResponse in bulkOperationResponses)
            {
                if (Transactions.ContainsKey(bulkOperationResponse.I))
                {
                    ISoapTransactionLink link = Transactions[bulkOperationResponse.I];

                    if (link is ISoapTransactionLinkExecutor)
                    {
                        ISoapTransactionLinkExecutor transactionLinkExecutor = link as ISoapTransactionLinkExecutor;

                        transactionLinkExecutor.ConsumeBulkOperationResponse(bulkOperationResponse);
                    }
                }
                else
                {
                    DebugLogger.Instance.LogMsg("A bulk operation response was returned that has no caller in this transaction chain.");
                }
            }
        }
Ejemplo n.º 8
0
 public void BuyPair(Kline kline, IPattern p, string name)/*Dictionary<string, PatternConfig> patternsConfig*/
 {
     if (Transactions.ContainsKey(kline.Symbol))
     {
         _logger.Info("Not Buying since we already baught it");
     }
     else
     {
         var time = Parser.ConvertTimeMsToDateTime(kline.CloseTime);
         var t    = new Transaction(kline.Symbol, kline.Close);
         t.StopLossConfig = GenerateStopLossObject(p);
         t.CalculateStopLoss(kline.Close);
         Transactions.Add(t.Symbol, t);
         var msg = String.Format("Trade: Buying {0} at {1}. Pattern: {2} Interval - {3}", t.Symbol, t.BuyPrice, p.Name, p.Interval);
         _logger.Email(string.Format("{0} Detected! Buy {1}", p.Name, t.Symbol), msg);
         if (FirstTransactionTime == DateTime.MinValue)
         {
             FirstTransactionTime = time;
         }
     }
 }
Ejemplo n.º 9
0
        public void Sell(Kline kline, out decimal profit)
        {
            profit = decimal.MinValue;
            var symbol = kline.Symbol;
            var price  = kline.Close;
            var time   = Parser.ConvertTimeMsToDateTime(kline.CloseTime);

            if (Transactions.Count > 0 && Transactions.ContainsKey(symbol))
            {
                var t = Transactions[symbol];
                profit = ((price / t.BuyPrice) - 1);
                var profitText = (profit * 100).ToString();
                if (profitText.Length > 5)
                {
                    profitText = profit.ToString().Substring(0, 5);
                }
                var msg = string.Format("Trade: SELLING {0}!!! Buy Price: {1}, Sell Price: {2}, Profit: {3}%", t.Symbol, t.BuyPrice, price.ToString(), profitText);
                _logger.Email(string.Format("SELL notice! selling {0} at {1}% from buy price", t.Symbol, profitText), msg);
                Transactions.Remove(symbol);
                UpdateStats(profit, time);
            }
        }
        private async Task ReloadTransactions(ICollection <string> transactions)
        {
            if (transactions == null)
            {
                return;
            }

            await Task.Run(async() =>
            {
                if ((NumberOfLoadedTransaction + transactionsToLoad.Count) < NumberOfTransaction)
                {
                    foreach (var t in transactions)
                    {
                        if (!Transactions.ContainsKey(t))
                        {
                            if (!transactionsToLoad.Contains(t))
                            {
                                transactionsToLoad.Enqueue(t);
                            }
                        }
                    }
                }
            });
        }
        public async System.Threading.Tasks.Task CommitTransactionAsync(string transId)
        {
            try
            {
                if (Transactions.ContainsKey(transId))
                {
                    var tran = Transactions[transId];
                    await tran.CommitAsync();

                    Transactions.Remove(transId);
                    //GC.SuppressFinalize(tran);
                }
                else
                {
                    throw new NotFoundException();
                }
            }
            catch (Exception e)
            {
                await Logger.ErrorAsync(e);

                throw;
            }
        }
Ejemplo n.º 12
0
		public bool Contains(DonationTransaction trans)
		{
			return Transactions.ContainsKey(trans.ID);
		}
Ejemplo n.º 13
0
        /// <summary>
        /// Stores the tracking information for the new transaction to the database in the same transaction.
        /// </summary>
        /// <param name="connection">The connection that began the transaction.</param>
        /// <param name="interceptionContext">Contextual information associated with the call.</param>
        /// <seealso cref="IDbConnectionInterceptor.BeganTransaction" />
        public override void BeganTransaction(DbConnection connection, BeginTransactionInterceptionContext interceptionContext)
        {
            if (TransactionContext == null ||
                !MatchesParentContext(connection, interceptionContext) ||
                interceptionContext.Result == null)
            {
                return;
            }

            var transactionId         = Guid.NewGuid();
            var savedSuccesfully      = false;
            var reinitializedDatabase = false;
            var objectContext         = ((IObjectContextAdapter)TransactionContext).ObjectContext;

            ((EntityConnection)objectContext.Connection).UseStoreTransaction(interceptionContext.Result);
            while (!savedSuccesfully)
            {
                Debug.Assert(!Transactions.ContainsKey(interceptionContext.Result), "The transaction has already been registered");
                var transactionRow = new TransactionRow {
                    Id = transactionId, CreationTime = DateTime.Now
                };
                Transactions.Add(interceptionContext.Result, transactionRow);

                TransactionContext.Transactions.Add(transactionRow);
                try
                {
                    objectContext.SaveChangesInternal(SaveOptions.AcceptAllChangesAfterSave, executeInExistingTransaction: true);
                    savedSuccesfully = true;
                }
                catch (UpdateException)
                {
                    Transactions.Remove(interceptionContext.Result);
                    TransactionContext.Entry(transactionRow).State = EntityState.Detached;

                    if (reinitializedDatabase)
                    {
                        throw;
                    }

                    try
                    {
                        var existingTransaction =
                            TransactionContext.Transactions
                            .AsNoTracking()
                            .WithExecutionStrategy(new DefaultExecutionStrategy())
                            .FirstOrDefault(t => t.Id == transactionId);

                        if (existingTransaction != null)
                        {
                            transactionId = Guid.NewGuid();
                            Debug.Assert(false, "Duplicate GUID! this should never happen");
                        }
                        else
                        {
                            // Unknown exception cause
                            throw;
                        }
                    }
                    catch (EntityCommandExecutionException)
                    {
                        // The necessary tables are not present.
                        // This can happen if the database was deleted after TransactionContext has been initialized
                        TransactionContext.Database.Initialize(force: true);

                        reinitializedDatabase = true;
                    }
                }
            }
        }
 /// <summary>
 ///		Comprueba si existe una transacción sobre un proveedor
 /// </summary>
 internal bool Exists(ProviderModel provider)
 {
     return(Transactions.ContainsKey(Normalize(provider.Key)));
 }
Ejemplo n.º 15
0
 public DonationTransaction Find(string id)
 {
     return(Transactions.ContainsKey(id) ? Transactions[id] : null);
 }