Lean  $LEAN_TAG$
QuantConnect.Util.RateGate Class Reference

Used to control the rate of some occurrence per unit of time. More...

Inheritance diagram for QuantConnect.Util.RateGate:
[legend]

Public Member Functions

 RateGate (int occurrences, TimeSpan timeUnit)
 Initializes a RateGate with a rate of occurrences per timeUnit . More...
 
bool WaitToProceed (int millisecondsTimeout)
 Blocks the current thread until allowed to proceed or until the specified timeout elapses. More...
 
bool WaitToProceed (TimeSpan timeout)
 Blocks the current thread until allowed to proceed or until the specified timeout elapses. More...
 
void WaitToProceed ()
 Blocks the current thread indefinitely until allowed to proceed. More...
 
void Dispose ()
 Releases unmanaged resources held by an instance of this class. More...
 

Protected Member Functions

virtual void Dispose (bool isDisposing)
 Releases unmanaged resources held by an instance of this class. More...
 

Properties

int Occurrences [get]
 Number of occurrences allowed per unit of time. More...
 
int TimeUnitMilliseconds [get]
 The length of the time unit, in milliseconds. More...
 
bool IsRateLimited [get]
 Flag indicating we are currently being rate limited More...
 

Detailed Description

Used to control the rate of some occurrence per unit of time.

To control the rate of an action using a RateGate, code should simply call WaitToProceed() prior to performing the action. WaitToProceed() will block the current thread until the action is allowed based on the rate limit.

This class is thread safe. A single RateGate instance may be used to control the rate of an occurrence across multiple threads.

Definition at line 40 of file RateGate.cs.

Constructor & Destructor Documentation

◆ RateGate()

QuantConnect.Util.RateGate.RateGate ( int  occurrences,
TimeSpan  timeUnit 
)

Initializes a RateGate with a rate of occurrences per timeUnit .

Parameters
occurrencesNumber of occurrences allowed per unit of time.
timeUnitLength of the time unit.
Exceptions
ArgumentOutOfRangeExceptionIf occurrences or timeUnit is negative.

Definition at line 88 of file RateGate.cs.

Member Function Documentation

◆ WaitToProceed() [1/3]

bool QuantConnect.Util.RateGate.WaitToProceed ( int  millisecondsTimeout)

Blocks the current thread until allowed to proceed or until the specified timeout elapses.

Parameters
millisecondsTimeoutNumber of milliseconds to wait, or -1 to wait indefinitely.
Returns
true if the thread is allowed to proceed, or false if timed out

Definition at line 159 of file RateGate.cs.

◆ WaitToProceed() [2/3]

bool QuantConnect.Util.RateGate.WaitToProceed ( TimeSpan  timeout)

Blocks the current thread until allowed to proceed or until the specified timeout elapses.

Parameters
timeout
Returns
true if the thread is allowed to proceed, or false if timed out

Definition at line 190 of file RateGate.cs.

Here is the call graph for this function:

◆ WaitToProceed() [3/3]

void QuantConnect.Util.RateGate.WaitToProceed ( )

Blocks the current thread indefinitely until allowed to proceed.

Definition at line 198 of file RateGate.cs.

Here is the caller graph for this function:

◆ Dispose() [1/2]

void QuantConnect.Util.RateGate.Dispose ( )

Releases unmanaged resources held by an instance of this class.

Definition at line 213 of file RateGate.cs.

◆ Dispose() [2/2]

virtual void QuantConnect.Util.RateGate.Dispose ( bool  isDisposing)
protectedvirtual

Releases unmanaged resources held by an instance of this class.

Parameters
isDisposingWhether this object is being disposed.

Definition at line 223 of file RateGate.cs.

Property Documentation

◆ Occurrences

int QuantConnect.Util.RateGate.Occurrences
get

Number of occurrences allowed per unit of time.

Definition at line 59 of file RateGate.cs.

◆ TimeUnitMilliseconds

int QuantConnect.Util.RateGate.TimeUnitMilliseconds
get

The length of the time unit, in milliseconds.

Definition at line 67 of file RateGate.cs.

◆ IsRateLimited

bool QuantConnect.Util.RateGate.IsRateLimited
get

Flag indicating we are currently being rate limited

Definition at line 75 of file RateGate.cs.


The documentation for this class was generated from the following file: