Esempio n. 1
0
 /// <summary>
 /// Limits the rate at which the sequence is enumerated.
 /// </summary>
 /// <typeparam name="T">The type of the elements of <paramref name="source"/>.</typeparam>
 /// <param name="source">The <see cref="IEnumerable{T}"/> whose enumeration is to be rate limited.</param>
 /// <param name="count">The number of items in the sequence that are allowed to be processed per time unit.</param>
 /// <param name="timeUnit">Length of the time unit.</param>
 /// <returns>An <see cref="IEnumerable{T}"/> containing the elements of the source sequence.</returns>
 public static IEnumerable <T> LimitRate <T>(this IEnumerable <T> source, int count, TimeSpan timeUnit)
 {
     using (var rateGate = new RateGate(count, timeUnit))
     {
         foreach (var item in source)
         {
             rateGate.WaitToProceed();
             yield return(item);
         }
     }
 }
Esempio n. 2
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_rateGate != null)
                {
                    _rateGate.Dispose();
                }
            }

            _rateGate = null;
        }
Esempio n. 3
0
        public KrakenRestApi(string key, string privateKey)
        {
            _url      = "https://api.kraken.com";
            _version  = 0;
            _key      = key;
            _secret   = privateKey;
            _rateGate = new RateGate(1, TimeSpan.FromSeconds(3));

            Thread canselThread = new Thread(DopThreadToCanselOrders);

            canselThread.Start();
        }