Lean
$LEAN_TAG$
|
Defines a token bucket for rate limiting See: https://en.wikipedia.org/wiki/Token_bucket More...
Public Member Functions | |
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... | |
Defines a token bucket for rate limiting See: https://en.wikipedia.org/wiki/Token_bucket
This code is ported from https://github.com/mxplusb/TokenBucket - since it's a dotnet core project, there were issued importing the nuget package directly. The referenced repository is provided under the Apache V2 license.
Definition at line 30 of file ITokenBucket.cs.
void QuantConnect.Util.RateLimit.ITokenBucket.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. A TimeoutException is throw in the event it takes longer than the stated timeout to consume the requested number of tokens. The default timeout is set to infinite, which will block forever. |
Implemented in QuantConnect.Util.RateLimit.LeakyBucket.
bool QuantConnect.Util.RateLimit.ITokenBucket.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.
Implemented in QuantConnect.Util.RateLimit.LeakyBucket.
|
get |
Gets the maximum capacity of tokens this bucket can hold.
Definition at line 35 of file ITokenBucket.cs.
|
get |
Gets the total number of currently available tokens for consumption
Definition at line 40 of file ITokenBucket.cs.