Skip to content

Conversation

@SeUkKim
Copy link
Collaborator

@SeUkKim SeUkKim commented Apr 28, 2025

Summary by CodeRabbit

  • New Features

    • Added support for Curve DeFi, Bitget, and Geckoterminal as new API providers.
    • Enabled Bitget as a new exchange WebSocket provider.
  • Documentation

    • Introduced a new guide detailing how to configure custom endpoints for Connect using an oracle configuration file.
  • Bug Fixes

    • Improved error handling and response parsing for Curve API integration.
  • Refactor

    • Updated Curve API integration to handle single ticker and data entry for improved efficiency.
    • Adjusted internal structures to support dynamic URL formatting and updated response models.

@SeUkKim SeUkKim requested a review from beer-1 April 28, 2025 09:22
@coderabbitai
Copy link

coderabbitai bot commented Apr 28, 2025

Walkthrough

The changes introduce new provider integrations and update existing ones within an API and WebSocket provider registry. Specifically, Bitget and Curve DeFi providers are added, including their API handlers, configuration structures, and registration within the provider factory. The Curve DeFi API handler is refactored to process only a single ticker and expects the response data as an object rather than an array. A new documentation guide is included to instruct users on custom endpoint configuration. Test cases and utility files are updated accordingly to match the revised handler logic and response formats.

Changes

File(s) Change Summary
cmd/constants/providers.go Added Bitget and Curve DeFi API/WebSocket providers to the provider registry.
guide_oracle.md New documentation file with instructions and examples for custom Connect endpoint configuration.
providers/apis/bitget/api_handler.go
providers/apis/bitget/utils.go
Introduced Bitget API handler, configuration, and response data structures for price queries.
providers/apis/defi/curve/api_handler.go
providers/apis/defi/curve/utils.go
Refactored Curve DeFi API handler and utility to process a single ticker and updated response handling.
providers/apis/defi/curve/api_handler_test.go Updated tests for Curve handler to align with single-ticker processing and new response/error expectations.
providers/factories/oracle/api.go Registered Bitget and Curve DeFi API handlers in the API query handler factory.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ProviderFactory
    participant BitgetAPIHandler
    participant CurveAPIHandler

    User->>ProviderFactory: Request API handler for 'bitget' or 'curve'
    alt bitget
        ProviderFactory->>BitgetAPIHandler: Initialize with config
        BitgetAPIHandler-->>ProviderFactory: Return handler
    else curve
        ProviderFactory->>CurveAPIHandler: Initialize with config
        CurveAPIHandler-->>ProviderFactory: Return handler
    end
    ProviderFactory-->>User: Return requested API handler
Loading
sequenceDiagram
    participant User
    participant BitgetAPIHandler
    participant BitgetAPI

    User->>BitgetAPIHandler: CreateURL([ticker])
    BitgetAPIHandler->>BitgetAPI: Format endpoint with ticker symbol
    BitgetAPI-->>BitgetAPIHandler: Return URL
    User->>BitgetAPIHandler: ParseResponse([ticker], http.Response)
    BitgetAPIHandler->>BitgetAPI: Decode JSON, extract price
    BitgetAPI-->>BitgetAPIHandler: Return price data
    BitgetAPIHandler-->>User: PriceResponse
Loading

Poem

In the warren of code, new tunnels appear,
Bitget and Curve now hop in with cheer!
APIs and sockets, all lined in a row,
With guides for the keepers on where to now go.
One ticker at a time, the data flows right—
The rabbits rejoice, for their queries are light!
🐇✨

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Lite

📥 Commits

Reviewing files that changed from the base of the PR and between f9b582e and 64c07f4.

📒 Files selected for processing (2)
  • guide_oracle.md (1 hunks)
  • providers/apis/defi/curve/api_handler.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • guide_oracle.md
  • providers/apis/defi/curve/api_handler.go

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🧹 Nitpick comments (20)
pkg/math/math.go (1)

169-174: Add documentation and unit tests for Float64ToBigFloat: Please include a doc comment detailing its behavior (e.g., default mantissa size) and add unit tests covering typical and edge-case conversions (e.g., large/small floats, NaN/±Inf scenarios) to ensure correctness.

providers/apis/defi/curve/types.go (1)

1-8: Add documentation and consider renaming to avoid stutter: The exported type CurveMetadata lacks a doc comment; please add one above it. Additionally, since it will be referenced as curve.CurveMetadata, consider renaming it to Metadata to reduce redundancy in usage.

providers/apis/bitget/utils.go (1)

51-75: Avoid stuttering in exported types: In Go, bitget.BitgetResponse and bitget.BitgetData stutter when used as bitget.BitgetResponse/bitget.BitgetData. Consider renaming them to Response and Data within this package for improved readability. Also, update the inline JSON example comment to end sentences with periods to satisfy Go doc conventions.

🧰 Tools
🪛 golangci-lint (1.64.8)

[warning] 51-51: exported: type name will be used as bitget.BitgetResponse by other packages, and that stutters; consider calling this Response

(revive)


[warning] 58-58: exported: type name will be used as bitget.BitgetData by other packages, and that stutters; consider calling this Data

(revive)

providers/apis/geckoterminal/types.go (1)

1-5: Add documentation and consider renaming to avoid stutter: The exported type GeckoterminalMetadata should have a doc comment explaining its purpose. Additionally, consider renaming it to Metadata since it will be referenced as geckoterminal.Metadata, reducing redundancy.

🧰 Tools
🪛 golangci-lint (1.64.8)

[warning] 3-3: exported: type name will be used as geckoterminal.GeckoterminalMetadata by other packages, and that stutters; consider calling this Metadata

(revive)

providers/factories/oracle/api.go (1)

6-7: Fix import formatting.

The imports need proper spacing between the standard library imports and third-party packages.

-	"go.uber.org/zap"
+	"go.uber.org/zap"
 	"net/http"
 	"strings"
+

Also applies to: 9-9

🧰 Tools
🪛 golangci-lint (1.64.8)

6-6: File is not properly formatted

(gofumpt)

guide_oracle.md (3)

1-3: Add blank line after heading.

According to Markdown best practices, headings should be surrounded by blank lines for better readability and proper rendering.

 # Configuration for custom endpoints
+
 This file describes how to configure and use custom endpoints in your Connect connection setup.
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

1-1: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below

(MD022, blanks-around-headings)


130-134: Fix Markdown formatting.

The code blocks should be surrounded by blank lines and the file should end with a newline character.

with the oracle.json file path, enther the following command to run connect.
+

connect --oracle-config path/to/oracle.json

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 markdownlint-cli2 (0.17.2)</summary>

130-130: Fenced code blocks should be surrounded by blank lines
null

(MD031, blanks-around-fences)

---

132-132: Fenced code blocks should be surrounded by blank lines
null

(MD031, blanks-around-fences)

---

134-134: Files should end with a single newline character
null

(MD047, single-trailing-newline)

</details>

</details>

---

`131-131`: **Fix typo in command instruction.**

There's a typo in the explanation for the command.

```diff
-with the `oracle.json` file path, enther the following command to run connect.
+with the `oracle.json` file path, enter the following command to run connect.
providers/websockets/bitget/utils.go (1)

3-6: Fix import order

Standard library imports should come before third-party imports.

-import (
-	"github.com/skip-mev/connect/v2/oracle/config"
-	"time"
-)
+import (
+	"time"
+
+	"github.com/skip-mev/connect/v2/oracle/config"
+)
🧰 Tools
🪛 golangci-lint (1.64.8)

4-4: File is not properly formatted

(gofumpt)


5-5: File is not properly formatted

(gofumpt)

providers/apis/defi/curve/utils.go (1)

31-49: Well-structured response types with example documentation

The response type definitions (CurveResponse and CurveData) are clear and include helpful documentation showing the expected JSON response format.

One suggestion: Consider adding validation for the LastUpdated timestamp field when parsing the response, as it appears to be in ISO-8601 format.

In the corresponding API handler, consider adding timestamp validation:

// In the response parsing code
timeValue, err := time.Parse("2006-01-02T15:04:05", curveResponse.Data.LastUpdated)
if err != nil {
    return nil, fmt.Errorf("failed to parse timestamp: %w", err)
}
// Use timeValue or add it to the returned data if needed
providers/websockets/bitget/parse.go (1)

21-23: Consider using exact channel match

Using strings.Contains for channel validation might be too permissive. If the channel should be exactly "ticker", consider using equality check instead.

- if !strings.Contains(resp.Arg.Channel, string(TickerChannel)) {
+ if resp.Arg.Channel != string(TickerChannel) {
providers/apis/bitget/api_handler.go (2)

17-18: Incorrect comment reference

The comment mistakenly refers to "Coinbase API" instead of "Bitget API".

- // api is the config for the Coinbase API.
+ // api is the config for the Bitget API.

3-12: Import formatting issues

The static analysis tool has flagged formatting issues with the imports.

Format the imports following Go conventions by grouping standard library imports separate from third-party imports:

import (
	"encoding/json"
	"fmt"
+	"net/http"
+	"time"
+
	"github.com/skip-mev/connect/v2/oracle/config"
	"github.com/skip-mev/connect/v2/oracle/types"
	"github.com/skip-mev/connect/v2/pkg/math"
	providertypes "github.com/skip-mev/connect/v2/providers/types"
-	"net/http"
-	"time"
)
🧰 Tools
🪛 golangci-lint (1.64.8)

5-5: File is not properly formatted

(gofumpt)


10-10: File is not properly formatted

(gofumpt)

providers/apis/defi/curve/api_handler.go (1)

45-66: Consider handling multiple tickers more robustly.

The CreateURL method only uses the first ticker and ignores the rest. While this might be the intended behavior for the Curve API, it could lead to confusion if multiple different tickers are provided.

Consider adding a comment explaining why only the first ticker is used, or enhance the implementation to handle multiple tickers if the Curve API supports batch requests.

providers/websockets/bitget/ws_data_handler.go (2)

53-53: Fix commented-out unused variable.

There's a commented-out variable declaration that should be removed.

- 	//baseResp      BaseResponse

Alternatively, if this variable might be needed in the future, add a comment explaining why it's commented out.

🧰 Tools
🪛 golangci-lint (1.64.8)

53-53: commentFormatting: put a space between // and comment text

(gocritic)


47-83: Review error handling in HandleMessage method.

The error handling in the HandleMessage method could be improved to provide more context about what went wrong during unmarshaling, especially since you're already logging the error.

  	} else {
  		h.logger.Debug("failed to unmarshal ticker update message", zap.Error(err), zap.Binary("message", message))
- 		return resp, nil, err
+ 		return resp, nil, fmt.Errorf("failed to unmarshal message: %w", err)
  	}
🧰 Tools
🪛 golangci-lint (1.64.8)

53-53: commentFormatting: put a space between // and comment text

(gocritic)

providers/websockets/bitget/messages.go (4)

32-42: Improve JSON example comment formatting.

The JSON example comment would be more readable as a block comment.

- //{
- //	"op":"subscribe",
- //	"args":[
- //	{
- //		"instType":"SPOT",
- //		"channel":"ticker",
- //		"instId":"BTCUSDT"
- //	}
- //	]
- //}
+ /*
+ {
+ 	"op":"subscribe",
+ 	"args":[
+ 	{
+ 		"instType":"SPOT",
+ 		"channel":"ticker",
+ 		"instId":"BTCUSDT"
+ 	}
+ 	]
+ }
+ */

Apply similar changes to the other JSON example comments in the file.


49-52: Follow Go naming conventions for acronyms.

According to Go naming conventions, acronyms in field names should be capitalized consistently.

  type ArgsData struct {
  	InstType string `json:"instType"`
  	Channel  string `json:"channel"`
- 	InstId   string `json:"instId"`
+ 	InstID   string `json:"instId"`
  }
🧰 Tools
🪛 golangci-lint (1.64.8)

[warning] 51-51: var-naming: struct field InstId should be InstID

(revive)


145-159: Follow Go naming conventions for acronyms in TickerUpdateData.

Similar to the previous comment, the InstId field should be renamed to InstID to follow Go naming conventions for acronyms. Additional fields like OpenUtc could also be updated to OpenUTC.

  type TickerUpdateData struct {
- 	InstId       string `json:"instId"`
+ 	InstID       string `json:"instId"`
  	LastPr       string `json:"lastPr"`
  	Open24H      string `json:"open24h"`
  	High24H      string `json:"high24h"`
  	Low24H       string `json:"low24h"`
  	Change24H    string `json:"change24h"`
  	BidPr        string `json:"bidPr"`
  	AskPr        string `json:"askPr"`
  	BidSz        string `json:"bidSz"`
  	AskSz        string `json:"askSz"`
  	BaseVolume   string `json:"baseVolume"`
  	QuoteVolume  string `json:"quoteVolume"`
- 	OpenUtc      string `json:"openUtc"`
- 	ChangeUtc24H string `json:"changeUtc24h"`
+ 	OpenUTC      string `json:"openUtc"`
+ 	ChangeUTC24H string `json:"changeUtc24h"`
  	Ts           int64  `json:"ts,string"` // this is quoted string in JSON
  }
🧰 Tools
🪛 golangci-lint (1.64.8)

[warning] 145-145: var-naming: struct field InstId should be InstID

(revive)


159-159: Consider using a more descriptive field name for timestamp.

The field Ts could be renamed to be more descriptive, such as TimestampMs to indicate it's a timestamp in milliseconds.

- 	Ts           int64  `json:"ts,string"` // this is quoted string in JSON
+ 	TimestampMs  int64  `json:"ts,string"` // this is quoted string in JSON
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e2fed55 and c6262eb.

📒 Files selected for processing (20)
  • cmd/constants/providers.go (5 hunks)
  • guide_oracle.md (1 hunks)
  • pkg/math/math.go (1 hunks)
  • pkg/math/oracle/aggregator.go (1 hunks)
  • providers/apis/bitget/api_handler.go (1 hunks)
  • providers/apis/bitget/utils.go (1 hunks)
  • providers/apis/defi/curve/api_handler.go (1 hunks)
  • providers/apis/defi/curve/api_handler_test.go (1 hunks)
  • providers/apis/defi/curve/types.go (1 hunks)
  • providers/apis/defi/curve/utils.go (1 hunks)
  • providers/apis/geckoterminal/api_handler.go (2 hunks)
  • providers/apis/geckoterminal/api_handler_test.go (1 hunks)
  • providers/apis/geckoterminal/types.go (1 hunks)
  • providers/apis/geckoterminal/utils.go (2 hunks)
  • providers/factories/oracle/api.go (2 hunks)
  • providers/factories/oracle/websocket.go (2 hunks)
  • providers/websockets/bitget/messages.go (1 hunks)
  • providers/websockets/bitget/parse.go (1 hunks)
  • providers/websockets/bitget/utils.go (1 hunks)
  • providers/websockets/bitget/ws_data_handler.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (9)
providers/factories/oracle/api.go (4)
providers/apis/bitget/utils.go (1)
  • Name (9-9)
providers/apis/defi/curve/utils.go (1)
  • Name (14-14)
providers/apis/bitget/api_handler.go (1)
  • NewAPIHandler (21-39)
providers/apis/defi/curve/api_handler.go (1)
  • NewAPIHandler (24-43)
providers/apis/geckoterminal/api_handler.go (2)
providers/apis/geckoterminal/types.go (1)
  • GeckoterminalMetadata (3-5)
providers/apis/geckoterminal/utils.go (1)
  • URL (20-20)
providers/apis/geckoterminal/utils.go (1)
oracle/config/api.go (1)
  • Endpoint (52-59)
providers/websockets/bitget/parse.go (6)
providers/websockets/bitget/ws_data_handler.go (1)
  • WebSocketHandler (16-22)
providers/websockets/bitget/messages.go (3)
  • TickerUpdateMessage (139-142)
  • Channel (15-15)
  • TickerChannel (21-21)
oracle/types/oracle.go (5)
  • PriceResponse (73-73)
  • ResolvedPrices (76-76)
  • UnResolvedPrices (79-79)
  • NewPriceResponse (93-93)
  • NewPriceResult (87-87)
pkg/math/math.go (1)
  • Float64StringToBigFloat (89-96)
providers/types/response.go (1)
  • UnresolvedResult (62-64)
providers/types/errors.go (3)
  • ErrorWithCode (75-78)
  • NewErrorWithCode (90-95)
  • ErrorFailedToParsePrice (21-21)
providers/websockets/bitget/utils.go (2)
oracle/config/websocket.go (8)
  • WebSocketConfig (72-144)
  • DefaultReconnectionTimeout (15-15)
  • DefaultReadBufferSize (24-24)
  • DefaultWriteBufferSize (29-29)
  • DefaultEnableCompression (36-36)
  • DefaultReadTimeout (40-40)
  • DefaultMaxReadErrorCount (59-59)
  • DefaultMaxSubscriptionsPerBatch (68-68)
providers/websockets/okx/utils.go (3)
  • ReadTimeout (45-45)
  • WriteInterval (32-32)
  • MaxSubscriptionsPerBatch (42-42)
providers/apis/bitget/api_handler.go (6)
oracle/types/oracle.go (6)
  • PriceAPIDataHandler (43-43)
  • PriceResponse (73-73)
  • NewPriceResponseWithErr (96-96)
  • NewPriceResponse (93-93)
  • ResolvedPrices (76-76)
  • NewPriceResult (87-87)
oracle/config/api.go (1)
  • APIConfig (9-48)
providers/apis/bitget/utils.go (3)
  • Name (9-9)
  • URL (11-11)
  • BitgetResponse (51-56)
oracle/types/provider.go (1)
  • ProviderTicker (15-22)
providers/types/errors.go (4)
  • NewErrorWithCode (90-95)
  • ErrorInvalidResponse (19-19)
  • ErrorFailedToDecode (23-23)
  • ErrorFailedToParsePrice (21-21)
pkg/math/math.go (1)
  • Float64StringToBigFloat (89-96)
providers/factories/oracle/websocket.go (2)
providers/websockets/bitget/utils.go (1)
  • Name (9-9)
providers/websockets/bitget/ws_data_handler.go (1)
  • NewWebSocketDataHandler (24-45)
providers/websockets/bitget/ws_data_handler.go (6)
oracle/types/oracle.go (2)
  • PriceWebSocketDataHandler (62-62)
  • PriceResponse (73-73)
oracle/config/websocket.go (1)
  • WebSocketConfig (72-144)
oracle/types/provider.go (3)
  • ProviderTickers (33-37)
  • NewProviderTickers (66-76)
  • ProviderTicker (15-22)
providers/websockets/bitget/utils.go (1)
  • Name (9-9)
providers/base/websocket/handlers/ws_conn_handler.go (1)
  • WebsocketEncodedMessage (16-16)
providers/websockets/bitget/messages.go (4)
  • SubscriptionResponse (105-108)
  • TickerUpdateMessage (139-142)
  • OperationPing (23-23)
  • OperationSubscribe (19-19)
providers/websockets/bitget/messages.go (4)
providers/websockets/bitget/ws_data_handler.go (1)
  • WebSocketHandler (16-22)
providers/base/websocket/handlers/ws_conn_handler.go (1)
  • WebsocketEncodedMessage (16-16)
providers/websockets/okx/utils.go (1)
  • MaxSubscriptionsPerBatch (42-42)
pkg/math/math.go (1)
  • Min (13-25)
🪛 golangci-lint (1.64.8)
providers/apis/geckoterminal/types.go

[warning] 3-3: exported: type name will be used as geckoterminal.GeckoterminalMetadata by other packages, and that stutters; consider calling this Metadata

(revive)

providers/factories/oracle/api.go

6-6: File is not properly formatted

(gofumpt)


9-9: File is not properly formatted

(gofumpt)

providers/websockets/bitget/utils.go

4-4: File is not properly formatted

(gofumpt)


5-5: File is not properly formatted

(gofumpt)

providers/apis/bitget/utils.go

[warning] 51-51: exported: type name will be used as bitget.BitgetResponse by other packages, and that stutters; consider calling this Response

(revive)


[warning] 58-58: exported: type name will be used as bitget.BitgetData by other packages, and that stutters; consider calling this Data

(revive)


26-26: Comment should end in a period

(godot)


4-4: File is not properly formatted

(gofumpt)


5-5: File is not properly formatted

(gofumpt)

providers/apis/bitget/api_handler.go

5-5: File is not properly formatted

(gofumpt)


10-10: File is not properly formatted

(gofumpt)

providers/websockets/bitget/ws_data_handler.go

53-53: commentFormatting: put a space between // and comment text

(gocritic)

providers/websockets/bitget/messages.go

[warning] 51-51: var-naming: struct field InstId should be InstID

(revive)


[warning] 145-145: var-naming: struct field InstId should be InstID

(revive)

🪛 markdownlint-cli2 (0.17.2)
guide_oracle.md

1-1: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below

(MD022, blanks-around-headings)


130-130: Fenced code blocks should be surrounded by blank lines
null

(MD031, blanks-around-fences)


132-132: Fenced code blocks should be surrounded by blank lines
null

(MD031, blanks-around-fences)


134-134: Files should end with a single newline character
null

(MD047, single-trailing-newline)

🔇 Additional comments (31)
pkg/math/oracle/aggregator.go (1)

212-217: Trivial formatting improvement: The added blank line after the error check in CalculateAdjustedPrice enhances readability without changing behavior.

providers/factories/oracle/websocket.go (2)

17-17: Import organization looks good.

The import for the Bitget WebSocket package has been added appropriately to support the new provider integration.


104-105: Well-structured Bitget WebSocket handler integration.

The Bitget WebSocket provider has been properly integrated into the switch statement, following the same pattern as other providers. This implementation correctly initializes the WebSocket data handler using the configuration provided.

providers/factories/oracle/api.go (2)

13-14: Import organization for new providers looks good.

The imports for Bitget API and Curve DeFi API have been added in appropriate positions.

Also applies to: 18-19


102-105: Proper integration of Curve and Bitget API handlers.

The Curve and Bitget API providers have been successfully integrated into the provider switch statement, following the established pattern of other providers in the factory function.

guide_oracle.md (1)

25-33: Good documentation of Bitget WebSocket configuration.

The documentation properly includes the Bitget WebSocket endpoint configuration, which aligns with the newly added support in the code.

providers/apis/geckoterminal/api_handler.go (2)

55-66: Good implementation of network extraction from metadata.

The code now properly extracts the network information from ticker metadata to dynamically support multiple networks. This is a good improvement over a hardcoded approach and makes the provider more flexible.


68-68: URL creation with network parameter.

The URL creation now properly incorporates the dynamic network parameter extracted from ticker metadata, making the provider more flexible across different blockchain networks.

providers/apis/geckoterminal/utils.go (2)

20-20: Updated URL to support multiple networks

Good improvement! The URL was changed from an Ethereum-specific URL to a format that accepts a network identifier as a parameter, enabling support for multiple blockchain networks.


35-35:

✅ Verification successful

Endpoint configuration updated to use the generic URL

This change correctly updates the DefaultETHAPIConfig to use the new generic URL template. Make sure that the code that constructs API requests now properly extracts network information from ticker metadata.


🏁 Script executed:

#!/bin/bash
# Check if the CreateURL method in api_handler.go extracts network information from metadata
rg -A 10 "func.*CreateURL" --glob "providers/apis/geckoterminal/*.go"

Length of output: 1676


🏁 Script executed:

#!/bin/bash
# Retrieve the full CreateURL function for review
rg -n "func (h \*APIHandler) CreateURL" -A 200 providers/apis/geckoterminal/api_handler.go

Length of output: 92


🏁 Script executed:

#!/bin/bash
# Retrieve the full CreateURL implementation
rg -n "CreateURL(" -A200 providers/apis/geckoterminal/api_handler.go

# Locate the GeckoterminalMetadata struct to inspect its fields
rg -n "type GeckoterminalMetadata" -A20 providers/apis/geckoterminal

Length of output: 403


🏁 Script executed:

#!/bin/bash
# Retry locating the full CreateURL implementation with proper escaping
rg -n "func (h \*APIHandler) CreateURL" -A200 providers/apis/geckoterminal/api_handler.go || true
rg "CreateURL\\(" -A200 providers/apis/geckoterminal/api_handler.go || true
# Fallback to plain grep if ripgrep patterns fail
grep -R -n "CreateURL(" providers/apis/geckoterminal/api_handler.go || true

Length of output: 3151


Verified CreateURL correctly extracts and uses network metadata

The CreateURL method in providers/apis/geckoterminal/api_handler.go unmarshals metadata.Network from each ticker’s JSON and applies it in the fmt.Sprintf call for the endpoint URL. No further changes are needed.

providers/websockets/bitget/utils.go (1)

8-14: Well-defined constants for Bitget WebSocket

Good job defining clear constants for the Bitget WebSocket provider, including the provider name, WebSocket URL, and ping interval.

cmd/constants/providers.go (5)

8-8: New provider imports added

The imports for the new providers (Bitget API, Curve Finance, GeckoTerminal, and Bitget WebSocket) have been correctly added.

Also applies to: 13-13, 18-18, 25-25


62-66: New Curve Finance API provider registered

Curve Finance DeFi API provider is correctly registered with appropriate configuration.


88-92: GeckoTerminal API provider registered

GeckoTerminal Exchange API provider is correctly registered with the updated default Ethereum API configuration.


108-112: Bitget API provider registered

Bitget Exchange API provider is correctly registered with the default API configuration.


175-179: Bitget WebSocket provider registered

Bitget Exchange WebSocket provider is correctly registered with the default WebSocket configuration.

providers/apis/defi/curve/utils.go (2)

9-18: Well-documented API specification with clear constants

The file includes proper documentation referencing the Curve API specification and defines clear constants for the provider name and URL format.


20-29: Appropriate default API configuration

The DefaultAPIConfig is well structured with reasonable timeout and interval values. The API configuration follows the pattern established by other providers in the codebase.

providers/apis/geckoterminal/api_handler_test.go (2)

22-38: Test cases are comprehensive

The test cases for URL creation correctly cover both the happy path and error cases. The use of metadata in JSON format effectively tests the real-world scenario.

The tests properly check both successful URL creation and error handling for invalid JSON metadata.


152-163: Well-structured response parsing tests

The response parsing tests thoroughly check both success and failure cases with clear expectations. The checks for specific error codes provide good coverage of error handling paths.

The test verifies both the resolved price value and timestamp freshness which is a good practice.

providers/apis/defi/curve/api_handler_test.go (2)

16-56: Comprehensive initialization tests

The TestNewAPIHandler function covers all important scenarios for handler initialization: success with default config and failures with wrong name or disabled API.


182-191: Well-designed helper function

The createTickerWithMetadata helper function is well-designed and improves test readability by encapsulating the metadata JSON marshaling logic.

providers/apis/defi/curve/api_handler.go (4)

1-15: LGTM: Appropriate imports and package structure for the Curve API handler.

The imports include standard Go packages and necessary dependencies from the connect project, setting up a well-structured API handler for the Curve DeFi protocol.


16-22: Good practice: Interface compliance verification.

The variable declaration ensures that APIHandler implements the types.PriceAPIDataHandler interface at compile time, which is a good Go practice for interface compliance checking.


24-43: LGTM: Well-structured constructor with appropriate validation.

The NewAPIHandler constructor properly validates the API configuration before creating a new handler, checking for the correct name, enabled status, and basic validity. The returned handler is properly initialized with a new cache.


68-120: LGTM: Thorough response parsing with proper error handling.

The ParseResponse method comprehensively handles the Curve API response, including error cases for JSON decoding failures, empty data responses, and unknown tickers. It correctly maps resolved and unresolved prices.

providers/websockets/bitget/ws_data_handler.go (3)

1-15: LGTM: Appropriate imports and interface compliance check.

The file properly imports required packages and includes an interface compliance check to ensure the WebSocketHandler implements types.PriceWebSocketDataHandler.


16-45: Well-structured WebSocketHandler with proper validation.

The WebSocketHandler struct and its constructor NewWebSocketDataHandler are well-implemented with appropriate validation checks for the WebSocket configuration.


85-108: LGTM: Well-implemented methods for message creation and handler management.

The CreateMessages, HeartBeatMessages, and Copy methods are well-implemented, providing clear functionality for subscription requests, heartbeat signals, and handler cloning.

providers/websockets/bitget/messages.go (2)

12-26: LGTM: Clear type and constant definitions.

The types and constants for operations and channels are well-defined and properly named, providing clarity for the message handling logic.


54-89: LGTM: Well-implemented subscription message creation with batching.

The NewSubscriptionRequestMessage method correctly handles batching of tickers according to the configured limit, with proper validation and error handling.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
providers/apis/defi/curve/api_handler_test.go (1)

158-158: Consider Updating Test Data Description

The test data description "whole list of ethereum ..." seems to be a remnant from the previous array-based response format. Consider updating it to better reflect the new single-object structure, even though this is an error test case.

-            response:    testutils.CreateResponseFromJSON(`{"data": {whole list of ethereum ...}}`),
+            response:    testutils.CreateResponseFromJSON(`{"data": {invalid or incomplete data structure}}`),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Lite

📥 Commits

Reviewing files that changed from the base of the PR and between d18003d and 1eb2471.

📒 Files selected for processing (3)
  • providers/apis/defi/curve/api_handler.go (2 hunks)
  • providers/apis/defi/curve/api_handler_test.go (4 hunks)
  • providers/apis/defi/curve/utils.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • providers/apis/defi/curve/utils.go
  • providers/apis/defi/curve/api_handler.go
🧰 Additional context used
🧬 Code Graph Analysis (1)
providers/apis/defi/curve/api_handler_test.go (1)
providers/apis/defi/curve/types.go (1)
  • CurveMetadata (3-8)
🔇 Additional comments (4)
providers/apis/defi/curve/api_handler_test.go (4)

77-87: URL Construction Updates Correctly Verified

The test case has been properly updated to reflect the new URL construction that uses token addresses instead of symbols. The expected URL now correctly includes the network and token address in the path format.


133-137: Response Structure Change Properly Tested

The test correctly updates the expected JSON response structure from an array to a single object under the "data" field, matching the refactored API handler logic.


170-170: Error Code Appropriately Updated

The expected error code for unresolved tickers has been updated from ErrorNoResponse to ErrorUnknownPair, providing more accurate error classification.


126-171: Test Coverage is Good

The test cases provide good coverage for the refactored API handler, including both success scenarios and various error cases (invalid JSON, empty data, unresolved tickers). This follows best practices and addresses the previous review comment requesting additional error test cases.

Copy link
Member

@beer-1 beer-1 left a comment

Choose a reason for hiding this comment

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

one minor comment

Copy link
Member

@beer-1 beer-1 left a comment

Choose a reason for hiding this comment

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

other parts LGTM

@SeUkKim SeUkKim merged commit 7439b10 into main May 16, 2025
3 checks passed
@SeUkKim SeUkKim deleted the feat/bitget branch May 16, 2025 07:05
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