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

Kraken: Fix sending trades to the websocket DataHandler #1813

Merged
merged 6 commits into from
Mar 4, 2025

Conversation

Beadko
Copy link
Contributor

@Beadko Beadko commented Feb 24, 2025

PR Description

Currently, the Kraken trades are not streaming via the websocket.
Fix: when the tradeFeed is set to true, send the data down to the WebSocket DataHandler. Add a test.

Fixes # (issue)

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
  • TestWSProcessTrades

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

When the tradeFeed is enabled, send the trades down the DataHandler
Add TestWSProcessTrades
@thrasher- thrasher- changed the title Bug: Send Kraken trades to the DataHandler Kraken: Fix sending trades to the websocket DataHandler Feb 24, 2025
@thrasher- thrasher- added bug review me This pull request is ready for review labels Feb 24, 2025
@thrasher- thrasher- requested review from gloriousCode, thrasher- and gbjk and removed request for gloriousCode February 24, 2025 05:15
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 @Beadko! Just some minor things I saw.

@@ -531,7 +531,10 @@ func (k *Kraken) wsProcessTrades(response []any, pair currency.Pair) error {
if !ok {
return errors.New("received invalid trade data")
}
if !k.IsSaveTradeDataEnabled() {
saveTradeData := k.IsSaveTradeDataEnabled()
tradeFeed := k.IsTradeFeedEnabled()
Copy link
Collaborator

Choose a reason for hiding this comment

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

OOS: Just highlighting this as trade feed enabled is not necessary as it's a subscription customisation. No change needed.

@Beadko Beadko requested a review from shazbert February 25, 2025 07:48
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 Bea!

@shazbert shazbert added the szrc shazbert review complete label Feb 26, 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.

Thank you Beadko!

@Beadko Beadko requested a review from gloriousCode February 27, 2025 01:57
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.

ch ACK. 🚀

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

@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.

Great work 🎉

I think there's more than just nits here, so marking for changes.

Beadko added 2 commits March 1, 2025 16:24
Send individual trades down the DataHandler
Send multiple trades in test
Test error if the trade length is too short
Nits
@Beadko Beadko requested a review from gbjk March 1, 2025 09:33
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.

Great work; Looks good to me 🎉

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!

@gloriousCode gloriousCode added the gcrc GloriousCode Review Complete label Mar 2, 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.

Thanks for the PR @Beadko! Just some minor nits

i := 1 - len(k.Websocket.DataHandler)
exp := trade.Data{Exchange: k.Name, CurrencyPair: spotTestPair}
require.NoErrorf(t, json.Unmarshal([]byte(expJSON[i]), &exp), "Must not error unmarshalling json %d: %s", i, expJSON[i])
require.Equalf(t, exp, v, "Trade [%d] should be correct", i)
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
require.Equalf(t, exp, v, "Trade [%d] should be correct", i)
require.Equalf(t, exp, v, "Trade [%d] must be correct", i)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

common/common.go Outdated
@@ -72,6 +72,7 @@ var (
ErrUnknownError = errors.New("unknown error")
ErrGettingField = errors.New("error getting field")
ErrSettingField = errors.New("error setting field")
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
ErrParsingWSField = errors.New("error parsing WS field")
ErrParsingWSField = errors.New("error parsing websocket field")

This wasn't your doing, but I'd prefer that we don't use acronyms for error messages

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No worries, I originally wrote "websocket" but changed it when I saw the original errors 😄 . Updated

@@ -1997,7 +1997,7 @@ func TestGetErrResp(t *testing.T) {
seen++
switch seen {
case 1: // no event
assert.ErrorIs(t, testErr, errParsingWSField, "Message with no event Should get correct error type")
assert.ErrorIs(t, testErr, common.ErrParsingWSField, "Message with no event Should get correct error type")
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
assert.ErrorIs(t, testErr, common.ErrParsingWSField, "Message with no event Should get correct error type")
assert.ErrorIs(t, testErr, common.ErrParsingWSField, "Message with no event should get correct error type")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@Beadko Beadko requested a review from thrasher- March 3, 2025 06:30
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.

Thanks for making those changes!

@thrasher- thrasher- merged commit 7fa2592 into thrasher-corp:master Mar 4, 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
bug 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