Skip to content

ITokenBucket

QuantConnect.Util.RateLimit.ITokenBucket

Defines a token bucket for rate limiting See: https://en.wikipedia.org/wiki/Token_bucket

capacity

capacity: int

Gets the maximum capacity of tokens this bucket can hold.

available_tokens

available_tokens: int

Gets the total number of currently available tokens for consumption

consume

consume(tokens: int, timeout: int = ...) -> None

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

Parameters:

Name Type Description Default
tokens int

The number of tokens to consume

required
timeout int

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.

...

try_consume

try_consume(tokens: int) -> bool

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.