Lean
$LEAN_TAG$
|
Provides an implementation of ITokenBucket that implements the leaky bucket algorithm See: https://en.wikipedia.org/wiki/Leaky_bucket More...
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... | |
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.
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.
capacity | The maximum number of tokens this bucket can hold |
refillAmount | The number of tokens to add to the bucket each refillInterval |
refillInterval | The interval which after passing more tokens are added to the bucket |
Definition at line 57 of file LeakyBucket.cs.
QuantConnect.Util.RateLimit.LeakyBucket.LeakyBucket | ( | long | capacity, |
ISleepStrategy | sleep, | ||
IRefillStrategy | refill, | ||
ITimeProvider | timeProvider = null |
||
) |
Initializes a new instance of the LeakyBucket class
capacity | The maximum number of tokens this bucket can hold |
sleep | Defines the ISleepStrategy used when Consume is invoked but the bucket does not have enough tokens yet |
refill | Defines the IRefillStrategy that computes how many tokens to add back to the bucket each time consumption is attempted |
timeProvider | Defines the ITimeProvider used to enforce timeouts when invoking Consume |
Definition at line 74 of file LeakyBucket.cs.
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.
tokens | The number of tokens to consume |
timeout | The 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.
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.
|
get |
Gets the maximum capacity of tokens this bucket can hold.
Definition at line 37 of file LeakyBucket.cs.
|
get |
Gets the total number of currently available tokens for consumption
Definition at line 43 of file LeakyBucket.cs.