-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: SSE implementation #11
feat: SSE implementation #11
Conversation
Reviewer's Guide by SourceryThis pull request migrates the Champion Trader application from WebSockets to Server-Sent Events (SSE) for real-time data streaming. It includes updates to the project structure, documentation, testing, and configuration to support the new SSE implementation. Sequence diagram for SSE market data streamingsequenceDiagram
participant UI as UI Component
participant Hook as useMarketSSE
participant Store as SSE Store
participant Service as MarketSSEService
participant Server as SSE Server
UI->>Hook: Initialize with instrumentId
Hook->>Store: initializeMarketService()
Store->>Service: new MarketSSEService()
Hook->>Store: subscribeToInstrumentPrice()
Store->>Service: subscribeToPrice(instrumentId)
Service->>Server: Connect SSE(action=instrument_price)
Server-->>Service: Connection Established
Server-->>Service: Price Update Event
Service->>Store: Update Price State
Store-->>Hook: New Price Available
Hook-->>UI: Render Updated Price
Note over Service,Server: Automatic reconnection on failure
UI->>Hook: Component Unmount
Hook->>Store: unsubscribeFromInstrumentPrice()
Store->>Service: unsubscribeFromPrice()
Service->>Server: Close Connection
Class diagram for the SSE service hierarchyclassDiagram
class SSEService {
<<abstract>>
#eventSource: EventSource
#messageHandlers: Map
#errorHandlers: Set
#reconnectCount: number
#options: SSEOptions
#isConnecting: boolean
+connect(): void
+disconnect(): void
#reconnect(): void
+on(action, handler): void
+off(action, handler): void
+onError(handler): void
+offError(handler): void
#abstract handleMessage(message): void
#abstract getEndpoint(): string
}
class PublicSSEService {
+constructor(options)
#getEndpoint(): string
#handleMessage(message): void
}
class ProtectedSSEService {
-authToken: string
+constructor(authToken, options)
#getEndpoint(): string
#handleMessage(message): void
+updateAuthToken(token): void
}
class MarketSSEService {
-subscriptions: Set
+subscribeToPrice(instrumentId): void
+unsubscribeFromPrice(instrumentId): void
}
class ContractSSEService {
-activeContracts: Map
+requestPrice(params): void
+cancelPrice(params): void
}
SSEService <|-- PublicSSEService
SSEService <|-- ProtectedSSEService
PublicSSEService <|-- MarketSSEService
ProtectedSSEService <|-- ContractSSEService
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.OpenSSF Scorecard
Scanned Manifest Files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @shafin-deriv - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider creating a shared types module for common interfaces between WebSocket and SSE implementations to reduce duplication and maintain consistency.
- Please add a clear deprecation timeline for the WebSocket implementation to ensure a smooth transition and avoid maintaining parallel systems longer than necessary.
Here's what I looked at during the review
- 🟡 General issues: 2 issues found
- 🟢 Security: all looks good
- 🟡 Testing: 4 issues found
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Deploying champion-trader with
|
Latest commit: |
f73bf67
|
Status: | ✅ Deploy successful! |
Preview URL: | https://fc9a3506.champion-trader.pages.dev |
Branch Preview URL: | https://shafin-championtrader-feat-s.champion-trader.pages.dev |
This pull request includes significant updates to the Champion Trader application, focusing on improving real-time data streaming by transitioning from WebSocket to Server-Sent Events (SSE). The changes also enhance documentation, project structure, and testing configurations.
Real-time Data Streaming Enhancements:
README.md
: Updated to reflect the transition from WebSocket to SSE for real-time data streaming, including detailed explanations of SSE benefits and usage examples.src/config/api.ts
: Added SSE configuration to the API config to support the new streaming method. [1] [2] [3] [4]rsbuild.config.ts
: Included environment variables for SSE paths to ensure proper configuration.Documentation Improvements:
llms.txt
: Updated to include information about the new SSE services and their advantages over WebSocket. [1] [2] [3]STRUCTURE.md
: Revised to provide a comprehensive overview of the project structure, highlighting the new SSE services and their integration.Testing Enhancements:
src/App.test.tsx
: Mocked EventSource for testing SSE functionalities, ensuring tests can simulate SSE behavior.These changes collectively improve the application's performance, maintainability, and developer experience by leveraging more efficient streaming technologies and enhancing the project's documentation and testing setup.
Summary by Sourcery
Implement Server-Sent Events (SSE) for real-time market and contract data streaming, replacing the existing WebSocket implementation.
New Features:
Tests: