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

trade: remove exchangeName for AddTradesToBuffer #1820

Merged
merged 1 commit into from
Mar 6, 2025

Conversation

junnplus
Copy link
Contributor

@junnplus junnplus commented Mar 3, 2025

PR Description

remove exchangeName for AddTradesToBuffer, exchangeName is redundant since data[i].Exchange already holds the exchange info.

Type of change

Please delete options that are not relevant and add an x in [] as item is complete.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How has this been tested

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration and
also consider improving test coverage whilst working on a certain feature or package.

  • go test ./... -race
  • golangci-lint run
  • Test X

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation and regenerated documentation via the documentation tool
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally and on Github Actions with my changes
  • Any dependent changes have been merged and published in downstream modules

@junnplus junnplus changed the title remove exchangeName for AddTradesToBuffer trade: remove exchangeName for AddTradesToBuffer Mar 3, 2025
Copy link
Collaborator

@shazbert shazbert left a comment

Choose a reason for hiding this comment

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

Thanks for opening this PR @junnplus I like the other changes you brought in. For reference the trade package will change from this conversation and it will be getting some love and attention soon.

@shazbert shazbert added the review me This pull request is ready for review label Mar 3, 2025

Choose a reason for hiding this comment

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

PR Overview

This PR removes the redundant use of an exchange name parameter from the AddTradesToBuffer calls in multiple exchange implementations, simplifying the trade buffering logic. Key changes include:

  • Removal of the extra exchange name argument passed to AddTradesToBuffer.
  • Minor refactoring to use more idiomatic Go (e.g. using short variable declarations).
  • Consistent update of various exchange websocket and wrapper files to reflect the change.

Reviewed Changes

File Description
exchanges/exchange.go Removed the extra exchange name parameter from AddTradesToBuffer.
exchanges/gemini/gemini_websocket.go Removed the redundant exchange name parameter in websocket handlers.
exchanges/kraken/kraken_websocket.go Updated trade buffering and improved variable declaration style.
exchanges/stream/websocket.go Removed exchangeName parameter from Trade.Setup for stream websocket.
(Other exchange files) Similar changes applied to remove the exchange name parameter uniformly.

Copilot reviewed 23 out of 23 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (4)

exchanges/exchange.go:1196

  • Ensure that the removal of the exchangeName argument from AddTradesToBuffer is safe and that trade.Data constructions still correctly include the exchange information.
return trade.AddTradesToBuffer(trades...)

exchanges/kraken/kraken_websocket.go:557

  • [nitpick] Using a short variable declaration here makes the code more idiomatic; ensure that similar changes across the codebase follow consistent style conventions.
tSide := order.Buy

exchanges/stream/websocket.go:203

  • Verify that removing the exchangeName parameter from the Trade.Setup call does not affect downstream behavior or break any assumptions about trade identification.
w.Trade.Setup(s.TradeFeed, w.DataHandler)

exchanges/okx/okx_websocket.go:696

  • Ensure that tests cover the updated trade buffering logic to verify that the exchange information is correctly propagated within the trade data.
return trade.AddTradesToBuffer(trades...)
Copy link
Collaborator

@gloriousCode gloriousCode left a comment

Choose a reason for hiding this comment

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

Will need a rebase/merge, but it all looks good to me

Copy link
Collaborator

@gloriousCode gloriousCode left a comment

Choose a reason for hiding this comment

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

tACK! Thanks for your contribution!

@gloriousCode gloriousCode added the gcrc GloriousCode Review Complete label Mar 5, 2025
@shazbert shazbert added the szrc shazbert review complete label Mar 5, 2025
Copy link
Collaborator

@thrasher- thrasher- left a comment

Choose a reason for hiding this comment

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

Approved with an optional side quest. Thanks for the PR!

var (
errParsingWSField = errors.New("error parsing WS field")
)
var errParsingWSField = errors.New("error parsing WS field")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
var errParsingWSField = errors.New("error parsing WS field")
var errParsingWSField = errors.New("error parsing WS field")

Up to you whether you want to do this in this PR, but you can delete this and use common.ErrParsingWSField instead. Looks like there's 4 areas where this is used in bitfinex_websocket.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can create another PR to deal with it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh it's fine, already have some cleanup PR's of my own so will include it in that. Will merge this one as is

Copy link
Collaborator

@gbjk gbjk left a comment

Choose a reason for hiding this comment

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

Good work, thank you 🙏
It's a step in the right direction for trades.

Code looks good to me 🎉

@thrasher- thrasher- merged commit 7a6d6cc into thrasher-corp:master Mar 6, 2025
5 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gcrc GloriousCode Review Complete review me This pull request is ready for review szrc shazbert review complete
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants