massive-com / massive-com/client-go
Configurable backoff strategy for websocket client
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 198
- Forks
- 59
- Avg merge
- 33m
- Merged PRs (30d)
- 2
Description
Is your feature request related to a problem? Please describe.
I'd like to be able to inject a backoff strategy into the websocket client.
The current implementation hardcodes an instance of ExponentialBackOff, which is suitable for most cases but the default interval is 500ms which is quite long when streaming real-time trades.
// Default values for ExponentialBackOff.
const (
DefaultInitialInterval = 500 * time.Millisecond
DefaultRandomizationFactor = 0.5
DefaultMultiplier = 1.5
DefaultMaxInterval = 60 * time.Second
DefaultMaxElapsedTime = 15 * time.Minute
)
// NewExponentialBackOff creates an instance of ExponentialBackOff using default values.
func NewExponentialBackOff(opts ...ExponentialBackOffOpts) *ExponentialBackOff {
b := &ExponentialBackOff{
InitialInterval: DefaultInitialInterval,
RandomizationFactor: DefaultRandomizationFactor,
Multiplier: DefaultMultiplier,
MaxInterval: DefaultMaxInterval,
MaxElapsedTime: DefaultMaxElapsedTime,
Stop: Stop,
Clock: SystemClock,
}
Describe the solution you'd like
The ability to inject my own backoff.Backoff instance into the Client via Config
// Client defines a client to the Polygon WebSocket API.
type Client struct {
apiKey string
feed Feed
market Market
url string
shouldClose bool
backoff backoff.BackOff
Describe alternatives you've considered
We could parameterize the backoff strategy itself by adding parameters like initialInterval to Config but that is verbose and not future proof. I agree that this is a sane default, but being able to inject in a custom backoff strategy is ideal.
Additional context
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the Client and Config definitions and the websocket connection code that currently creates or uses ExponentialBackOff. Trace how the backoff.BackOff value is applied during connection attempts, then determine how configuration should supply it. Done means a custom backoff can be provided through Config while the existing default behavior remains intact; add or update reconnect tests if the project has them.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, networking
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100