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

orderbook: Check assignment of time values and reject if not set #1318

Merged
merged 15 commits into from
Sep 7, 2023

Conversation

shazbert
Copy link
Collaborator

PR Description

From PR #1315 some timestamps where not set. To maintain adequate data quality this should be strictly set and this PR rejects all snapshots and updates without a time value.

NOTES:

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
  • 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/AppVeyor with my changes
  • Any dependent changes have been merged and published in downstream modules

@shazbert shazbert added nomerge requires dependency This pull request is dependent on another, so it can't be merged until the dependent one is merged blocked labels Aug 11, 2023
@shazbert shazbert requested a review from a team August 11, 2023 04:50
@shazbert shazbert self-assigned this Aug 11, 2023
@shazbert shazbert added review me This pull request is ready for review and removed nomerge requires dependency This pull request is dependent on another, so it can't be merged until the dependent one is merged blocked labels Aug 15, 2023
@shazbert shazbert added reconstructing Based on PR feedback, this is currently being reworked and is not to be merged and removed review me This pull request is ready for review labels Aug 15, 2023
@shazbert shazbert added review me This pull request is ready for review and removed reconstructing Based on PR feedback, this is currently being reworked and is not to be merged labels Aug 16, 2023
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.

Nice QA PR! First round of nitterinos

@@ -111,6 +111,8 @@ const (
bitMEXPriceIndexID = "MRCXXX"
bitMEXLendingPremiumIndexID = "MRRXXX"
bitMEXVolatilityIndexID = "MRIXXX"

timeLayout = "2006-01-02T15:04:05.999Z"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can rid this since Go std can handle it natively

Side string `json:"side"`
Size int64 `json:"size"`
Symbol string `json:"symbol"`
Timestamp string `json:"timestamp"`
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
Timestamp string `json:"timestamp"`
Timestamp time.Time `json:"timestamp"`

@@ -862,7 +863,7 @@ func TestWsOrderbook(t *testing.T) {
pressXToJSON = []byte(`{
"type": "l2update",
"product_id": "BTC-USD",
"time": "2019-08-14T20:42:27.265Z",
"time": "2023-08-15T06:46:57.933713Z"",
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
"time": "2023-08-15T06:46:57.933713Z"",
"time": "2023-08-15T06:46:57.933713Z",

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

🦅

@@ -441,6 +441,7 @@ type WebsocketOrderbookSnapshot struct {
Type string `json:"type"`
Bids [][2]string `json:"bids"`
Asks [][2]string `json:"asks"`
Time string `json:"time"`
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
Time string `json:"time"`
Time time.Time `json:"time"`

@@ -50,6 +50,8 @@ const (
coinbaseproWithdrawalCrypto = "withdrawals/crypto"
coinbaseproCoinbaseAccounts = "coinbase-accounts"
coinbaseproTrailingVolume = "users/self/trailing-volume"

timeLayout = "2006-01-02T15:04:05.999999Z"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can rid this as Go can handle this

Sequence int64 `json:"sequence"`
Symbol string `json:"symbol"`
Sequence int64 `json:"sequence"`
Timestamp string `json:"timestamp"`
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
Timestamp string `json:"timestamp"`
Timestamp time.Time `json:"timestamp"`

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.

Lovely

🕊️

@@ -265,7 +269,7 @@ func (b *BTSE) wsHandleData(respRaw []byte) error {
})
}
return trade.AddTradesToBuffer(b.Name, trades...)
case strings.Contains(topic, "orderBookL2Api"):
case strings.Contains(topic, "orderBookL2Api"): // TODO: Fix orderbook updates.
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's happened?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

BTSE websocket orderbook not working. 🤷

@@ -253,7 +264,7 @@ func TestInvalidate(t *testing.T) {
t.Fatalf("received: '%v' but expected: '%v'", err, ErrOrderbookInvalid)
}

if err.Error() != "testexchange BTCWABI spot orderbook data integrity compromised Reason: [random reason]" {
if err.Error() != "testexchange BTCWABI spot Reason: [orderbook data integrity compromised, random reason]" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Only if something else comes up, make this errors.Is

@@ -391,6 +391,20 @@ func (p *Poloniex) WsProcessOrderbookSnapshot(data []interface{}) error {
errTypeAssertionFailure)
}

if len(data) < 3 {
return errNotEnoughData
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you should wrap this error with the above pair at least to help know that maybe its a terrible currency

exchanges/orderbook/depth.go Show resolved Hide resolved
exchanges/orderbook/depth.go Show resolved Hide resolved
exchanges/orderbook/depth.go Show resolved Hide resolved
Comment on lines +200 to +206
if update.UpdateTime.IsZero() {
return fmt.Errorf("%s %s %s %w",
d.exchange,
d.pair,
d.asset,
errLastUpdatedNotSet)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add coverage

Comment on lines +227 to +233
if update.UpdateTime.IsZero() {
return fmt.Errorf("%s %s %s %w",
d.exchange,
d.pair,
d.asset,
errLastUpdatedNotSet)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add coverage

Comment on lines +254 to +260
if update.UpdateTime.IsZero() {
return fmt.Errorf("%s %s %s %w",
d.exchange,
d.pair,
d.asset,
errLastUpdatedNotSet)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add coverage

d.pair,
d.asset,
errLastUpdatedNotSet)
}
tn := getNow()
Copy link
Collaborator

@gloriousCode gloriousCode Aug 31, 2023

Choose a reason for hiding this comment

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

Is this still needed now we have an update 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.

Nar not really, Last updated is more a time for when the update occurred at a matching engine level on the external exchange. This time is for the stack nodes when it gets pushed onto the stack to be re-used later more like an insertion time so it can be clean if its never been used. Either way the times are going to be like a second or two out depending on colocation from exchange and processing time. Default allowance is 30 seconds so might as well use it and reduce allocation. 🤷 🦅

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!

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.

thanks ACK!

@thrasher- thrasher- changed the title orderbook: Check assignment of time values and reject if not set. orderbook: Check assignment of time values and reject if not set Sep 7, 2023
@thrasher- thrasher- merged commit ad9de19 into thrasher-corp:master Sep 7, 2023
shazbert added a commit to shazbert/gocryptotrader that referenced this pull request Nov 10, 2023
…asher-corp#1318)

* orderbook: Check assignment of time values and reject if not set.

* linter: fix

* buffer: additional linter winter fixter

* Implement through pending exchanges

* finished push

* linty: minty

* gomod: tidy

* thrasher: nits

* glorious: nits

* orderbook: purge type now in favour of external call allocation

* orderbook: push last param

* orderbook: only 1 unlock call is needed

---------

Co-authored-by: Ryan O'Hara-Reid <[email protected]>
@shazbert shazbert deleted the book_time branch May 3, 2024 00:39
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.

3 participants