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

Okx: Fix sending trades to the websocket DataHandler #1833

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Beadko
Copy link
Contributor

@Beadko Beadko commented Mar 9, 2025

PR Description

Trades are not being sent down to the websocket DataHandler because the IsTradeFeedEnabled is not set.
Additional changes:

  • Send the trades down the DataHandler individually
  • Change the timestamp to .UTC()

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

Beadko added 3 commits March 9, 2025 13:02
Update the test to process trades for each asset type
Add raw trade data from OKX
Update the timestamp in the method
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!

Comment on lines 4055 to 4056
instrumentID := "BTC-USDT"
assets, err := ok.getAssetsFromInstrumentID(instrumentID)
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
instrumentID := "BTC-USDT"
assets, err := ok.getAssetsFromInstrumentID(instrumentID)
assets, err := ok.getAssetsFromInstrumentID("BTC-USDT")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

amended

Comment on lines 4093 to 4094
require.Len(t, ok.Websocket.DataHandler, total,
"Must see correct number of trades")
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.Len(t, ok.Websocket.DataHandler, total,
"Must see correct number of trades")
require.Len(t, ok.Websocket.DataHandler, total, "Must see correct number of trades")

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

Comment on lines 4097 to 4099
for _, a := range assets {
receivedTrades[a] = []trade.Data{}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

can remove this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

Comment on lines 4116 to 4117
require.Len(t, trades, len(exp),
"Should have received %d trades for asset %v", len(exp), assetType)
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.Len(t, trades, len(exp),
"Should have received %d trades for asset %v", len(exp), assetType)
require.Len(t, trades, len(exp), "Should have received %d trades for asset %v", len(exp), assetType)

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

Comment on lines 4114 to 4115
trades, exists := receivedTrades[assetType]
require.True(t, exists, "Should have received trades for asset %v", assetType)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This exists check is handled below by the trades length check and can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

Comment on lines 4124 to 4126
require.Equal(t, expected, trade,
"Trade %d (TID: %s) for asset %v should match expected data",
i, trade.TID, assetType)
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.Equal(t, expected, trade,
"Trade %d (TID: %s) for asset %v should match expected data",
i, trade.TID, assetType)
require.Equal(t, expected, trade, "Trade %d (TID: %s) for asset %v should match expected data", i, trade.TID, assetType)

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

return trade.AddTradesToBuffer(trades...)
if tradeFeed {
for i := range trades {
ok.Websocket.DataHandler <- trades[i]
Copy link
Collaborator

Choose a reason for hiding this comment

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

OOS: In trade.go under method Update we are passing the entire slice which can be updated to only send through individual updates. If you want to use this function to cut down on some code you are more than welcome. ok.Websocket.Trade.Update(...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will leave this out of this PR if that's ok

@shazbert shazbert added the review me This pull request is ready for review label Mar 9, 2025
@Beadko Beadko requested a review from shazbert March 10, 2025 05:07
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants