Lean  $LEAN_TAG$
QuantConnect.Util.RateLimit.LeakyBucket Class Reference

Provides an implementation of ITokenBucket that implements the leaky bucket algorithm See: https://en.wikipedia.org/wiki/Leaky_bucket More...

Inheritance diagram for QuantConnect.Util.RateLimit.LeakyBucket:
[legend]

Public Member Functions

 LeakyBucket (long capacity, long refillAmount, TimeSpan refillInterval)
 Initializes a new instance of the LeakyBucket class. This constructor initializes the bucket using the ThreadSleepStrategy.Sleep with a 1 millisecond sleep to prevent being CPU intensive and uses the FixedIntervalRefillStrategy to refill bucket tokens according to the refillAmount and refillInterval parameters. More...
 
 LeakyBucket (long capacity, ISleepStrategy sleep, IRefillStrategy refill, ITimeProvider timeProvider=null)
 Initializes a new instance of the LeakyBucket class More...
 
void Consume (long tokens, long timeout=Timeout.Infinite)
 Blocks until the specified number of tokens are available for consumption and then consumes that number of tokens. More...
 
bool TryConsume (long tokens)
 Attempts to consume the specified number of tokens from the bucket. If the requested number of tokens are not immediately available, then this method will return false to indicate that zero tokens have been consumed. More...
 

Properties

long Capacity [get]
 Gets the maximum capacity of tokens this bucket can hold. More...
 
long AvailableTokens [get]
 Gets the total number of currently available tokens for consumption More...
 
- Properties inherited from QuantConnect.Util.RateLimit.ITokenBucket
long Capacity [get]
 Gets the maximum capacity of tokens this bucket can hold. More...
 
long AvailableTokens [get]
 Gets the total number of currently available tokens for consumption More...
 

Detailed Description

Provides an implementation of ITokenBucket that implements the leaky bucket algorithm See: https://en.wikipedia.org/wiki/Leaky_bucket

Definition at line 25 of file LeakyBucket.cs.

Constructor & Destructor Documentation

◆ LeakyBucket() [1/2]

QuantConnect.Util.RateLimit.LeakyBucket.LeakyBucket ( long  capacity,
long  refillAmount,
TimeSpan  refillInterval 
)

Initializes a new instance of the LeakyBucket class. This constructor initializes the bucket using the ThreadSleepStrategy.Sleep with a 1 millisecond sleep to prevent being CPU intensive and uses the FixedIntervalRefillStrategy to refill bucket tokens according to the refillAmount and refillInterval parameters.

Parameters
capacityThe maximum number of tokens this bucket can hold
refillAmountThe number of tokens to add to the bucket each refillInterval
refillIntervalThe interval which after passing more tokens are added to the bucket

Definition at line 57 of file LeakyBucket.cs.

◆ LeakyBucket() [2/2]

QuantConnect.Util.RateLimit.LeakyBucket.LeakyBucket ( long  capacity,
ISleepStrategy  sleep,
IRefillStrategy  refill,
ITimeProvider  timeProvider = null 
)

Initializes a new instance of the LeakyBucket class

Parameters
capacityThe maximum number of tokens this bucket can hold
sleepDefines the ISleepStrategy used when Consume is invoked but the bucket does not have enough tokens yet
refillDefines the IRefillStrategy that computes how many tokens to add back to the bucket each time consumption is attempted
timeProviderDefines the ITimeProvider used to enforce timeouts when invoking Consume

Definition at line 74 of file LeakyBucket.cs.

Member Function Documentation

◆ Consume()

void QuantConnect.Util.RateLimit.LeakyBucket.Consume ( long  tokens,
long  timeout = Timeout.Infinite 
)

Blocks until the specified number of tokens are available for consumption and then consumes that number of tokens.

Parameters
tokensThe number of tokens to consume
timeoutThe maximum amount of time, in milliseconds, to block. An exception is throw in the event it takes longer than the stated timeout to consume the requested number of tokens

Implements QuantConnect.Util.RateLimit.ITokenBucket.

Definition at line 91 of file LeakyBucket.cs.

Here is the call graph for this function:

◆ TryConsume()

bool QuantConnect.Util.RateLimit.LeakyBucket.TryConsume ( long  tokens)

Attempts to consume the specified number of tokens from the bucket. If the requested number of tokens are not immediately available, then this method will return false to indicate that zero tokens have been consumed.

Implements QuantConnect.Util.RateLimit.ITokenBucket.

Definition at line 130 of file LeakyBucket.cs.

Here is the caller graph for this function:

Property Documentation

◆ Capacity

long QuantConnect.Util.RateLimit.LeakyBucket.Capacity
get

Gets the maximum capacity of tokens this bucket can hold.

Definition at line 37 of file LeakyBucket.cs.

◆ AvailableTokens

long QuantConnect.Util.RateLimit.LeakyBucket.AvailableTokens
get

Gets the total number of currently available tokens for consumption

Definition at line 43 of file LeakyBucket.cs.


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