Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent strategies for managing options when creating new client instances #315

Open
ndewet opened this issue Dec 19, 2024 · 2 comments

Comments

@ndewet
Copy link

ndewet commented Dec 19, 2024

NewClient in alpaca/rest.go accepts a ClientOpts struct, where as NewStocksClient in marketdata/stream/client.go accepts a variadic list of stock options.

NewClient:

	key, secret, err := GetAlpacaCredentials()
	if err != nil {
		return nil, err
	}
	market := alpaca.NewClient(
		alpaca.ClientOpts{
			APIKey:    key,
			APISecret: secret,
			BaseURL:   "https://paper-api.alpaca.markets"},
	)

NewStocksClient:

	key, secret, err := GetAlpacaCredentials()
	if err != nil {
		return nil, err
	}
	processors, err := GetProcessorCount()
	if err != nil {
		return nil, err
	}
	stocks := stream.NewStocksClient(
		marketdata.IEX,
		stream.WithBufferSize(1000),
		stream.WithProcessors(processors),
		stream.WithCredentials(key, secret),
		stream.WithReconnectSettings(0, 500*time.Millisecond),
		stream.WithLogger(&AlpacaStreamLogger{}),
	)

Please note that WithCredentials and APIKey + APISecret are just different enough to cause confusion.

I by far prefer the variadic list approach.

@ndewet
Copy link
Author

ndewet commented Dec 19, 2024

In the land of dreams and ideas, I'd like an approach where some of the option types, such as credentials, were re-usable across different client types.

@gnvk
Copy link
Collaborator

gnvk commented Dec 20, 2024

@ndewet You are absolutely right, this duality is indeed unfortunate. Honestly, I'm not sure if it's worth the effort to fix this though. That being said, I'll list some suggestions if we / anyone ever wants to pick this up:

  • This can be fixed in a backward-compatible way by adding new constructors for the non-stream clients, e.g. alpaca.NewClientWithOptions().
  • The difficulty with using the same option types is that we have 3 packages (alpaca, marketdata and stream). Probably the best way to cope with this would be to define the base option type and any common options (e.g. WithCredentials) in the alpaca package and use them in marketdata and stream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants