Skip to content

Conversation

dboyliao
Copy link
Collaborator

@dboyliao dboyliao commented May 5, 2025

In this PR, I refactor the handleConnect method of the coinbase Stream object as following:

  1. wrapping connection logics of user and market data stream into two separate methods:
    • buildMapForUserDataStream
    • buildMapForMarketStream
  2. writeSubscribeJson: method that write the subscription JSON to the websocket connection
  3. Instead of just logging on subscription error, use panic to abort the process
    • the rationale is that we should prevent the process running since user/market data streams are important data feeds for the trading strategies. If there is any error on subscriptions, the stream is compromised and should be explicitly stopped instead of just logging a message.

@dboyliao dboyliao changed the title 🔧 refactor: wrapping connection logics into methods for better maintainability. REFACTOR: (coinbase) wrapping connection logics into methods for better maintainability. May 5, 2025
@dboyliao dboyliao force-pushed the dboy/coinbase-connect-refactor branch from 0fa3213 to dba8faa Compare May 5, 2025 02:40
@dboyliao dboyliao force-pushed the dboy/coinbase-connect-refactor branch from dba8faa to fe6bfdf Compare May 5, 2025 09:33
@@ -77,67 +77,131 @@ func (msg subscribeMsgType2) String() string {
}

func (s *Stream) handleConnect() {
subProductsMap := make(map[types.Channel][]string)
// channel2LocalSymbolsMap is a map from channel to local symbols
channel2LocalSymbolsMap := make(map[types.Channel][]string)

// user data strea, subscribe to user channel for the user order/trade updates
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also help fix the typo in the comment: strea"m".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opps, thanks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@dboyliao dboyliao requested a review from gx578007 May 7, 2025 06:20
@dboyliao dboyliao merged commit 3b091ac into main May 7, 2025
2 checks passed
@dboyliao dboyliao deleted the dboy/coinbase-connect-refactor branch May 7, 2025 07:52
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

Successfully merging this pull request may close these issues.

3 participants