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

Huobi: V2 subscription support #1703

Merged
merged 11 commits into from
Feb 19, 2025
Merged

Conversation

gbjk
Copy link
Collaborator

@gbjk gbjk commented Nov 6, 2024

  • Removes deprecated and non-functional WS endpoints
  • Adds V2 endpoints available as described here ( Account updates, Order updates, Trades )
  • Mock tests for Private subscriptions
  • Improves code structure for wsHandleData
  • Assertifies tests
  • Quite a few test fixes as well
  • Adds testexch.FixtureToDataHandlerWithErrors

Stacked Dependencies

Related

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)

How has this been tested

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

@gbjk gbjk self-assigned this Nov 6, 2024
@thrasher- thrasher- requested review from shazbert, gloriousCode and thrasher- and removed request for shazbert and gloriousCode November 6, 2024 22:29
@thrasher- thrasher- added review me This pull request is ready for review nomerge requires dependency This pull request is dependent on another, so it can't be merged until the dependent one is merged labels Nov 6, 2024
@gbjk gbjk added reconstructing Based on PR feedback, this is currently being reworked and is not to be merged review me This pull request is ready for review and removed review me This pull request is ready for review reconstructing Based on PR feedback, this is currently being reworked and is not to be merged labels Nov 7, 2024
@gbjk gbjk force-pushed the feature/huobi_v2 branch 3 times, most recently from 06c750a to 8d0146d Compare November 11, 2024 03:44
@gbjk gbjk removed the nomerge requires dependency This pull request is dependent on another, so it can't be merged until the dependent one is merged label Nov 11, 2024
@gbjk gbjk force-pushed the feature/huobi_v2 branch from 8d0146d to 2f10c4b Compare December 2, 2024 00:41
@gbjk
Copy link
Collaborator Author

gbjk commented Dec 2, 2024

Linter fixed; Rebased to resolve conflict

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.

Awesome update. 🍰 Just some minor nits.

@gbjk gbjk force-pushed the feature/huobi_v2 branch 3 times, most recently from ff199aa to 479095c Compare December 14, 2024 09:01
@gbjk gbjk requested a review from shazbert December 18, 2024 02:55
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.

Changes ACK, Thanks 🫡

@shazbert shazbert added the szrc shazbert review complete label Dec 19, 2024
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.

Nicely done

Comment on lines 94 to 93
h.Websocket.SetCanUseAuthenticatedEndpoints(false)
if h.IsWebsocketAuthenticationSupported() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

?
I don't see any other exchange behave in this manner

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In which sense?
Most of them use SetCanUseAuthenticatedEndpoints false on failure (Kraken, Okx)
Many of them use IsWebsocketAuthenticationSupported to choose to dial auth (Kraken, Okx)

This is using a different pattern, but I'm actually happier with it.
Set CanUseAuthEndpoints to false on a (re)connect, and then true if the auth succeeds.
It feels cleaner than having the branching logic we've seen elsewhere.
Definitely cleaner than using CanUseAuthenticatedEndpoints to decide to even dial, which I saw on one exchange, and feels definitely wrong.

Is there a downside to this that I'm missing?

If anything, I'd follow this pattern with others when I'm interfering with them.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why set something to false when you don't even know if they have credentials set or if its going to be used?
If you put the h.Websocket.SetCanUseAuthenticatedEndpoints(false) inside the if statement, it no longer looks out of place and that change will still work with all the reasoning you outlined

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why set something to false when you don't even know if they have credentials set or if its going to be used?
Because if we aren't about to go into the if statement, for any reason at all, then false is the correct state for the value. Not setting it to false seems wrong to me; Doing it inside an if statement that could be false and not run seems wrong to me.

I don't know what the use-cases might be. Feels like the user would have to unset credentials for it to need to be set to false where I have it. But that's kind of irrelevant. My point is that it's the best representation of the state at the right time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Kinda afraid you're going to ask me to change all the others if I convince you 🤦

Copy link
Collaborator

@gloriousCode gloriousCode Feb 17, 2025

Choose a reason for hiding this comment

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

After 30 days, I still don't like it, nor would I request you put it anywhere else. I didn't expect to talk this much about h.Websocket.SetCanUseAuthenticatedEndpoints(false) placement which doesn't affect performance. Its just doing something before even knowing its necessary.
Since it affects so little, I can say you can keep it, even though its a wasteful call without credentials

Copy link
Collaborator

Choose a reason for hiding this comment

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

I too don't see the point of this, we should only SetCanUseAuthenticatedEndpoints(false) if auth fails. We'll also always default to off unless a user has provided auth credentials and enabled websocket, which we'll test upon engine starting up

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay; I'll change it.

I'm still sticking to my view that WsConnect is the point at which we have lost whatever possible authenticated state we had before, not on failed auth response.
( Arguably we lost it on disconnect )
So if reconnect and we don't go into h.IsWebsocketAuthenticationSupported for literally any reason now, or in the future, we've left the bool in the wrong state. I know that's an edge case. I just don't see the point in not coding for it.

Fixup coming.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed gbjk@53425ab42

Moved the set to true up into WsConnect because that matches other exchanges (Kraken), and means setting true and false is in the same place.

@gbjk gbjk requested a review from gloriousCode January 11, 2025 06:09
Copy link

This PR is stale because it has been open 30 days with no activity. Please provide an update on the progress of this PR.

@github-actions github-actions bot added the stale label Feb 17, 2025
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.

Just needs a rebase, thank you! 🌈

@gbjk
Copy link
Collaborator Author

gbjk commented Feb 17, 2025

Rebase required an additional fix: gbjk@65e81e470

Immediately folded that down and pushed.

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

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.

Fantastic work on this PR. Just two minor nits and then this LGTG

@thrasher- thrasher- merged commit dc2d777 into thrasher-corp:master Feb 19, 2025
5 of 11 checks passed
@gbjk gbjk deleted the feature/huobi_v2 branch February 19, 2025 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

4 participants