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

Kucoin: Implement GetFuturesTickers, update UpdateTickers and enhance test coverage #1431

Merged

Conversation

Beadko
Copy link
Contributor

@Beadko Beadko commented Dec 24, 2023

PR Description

Kucoin UpdateTickers returning incorrect values on futures.
Create the test to prove the concept.
Create a function GetFuturesTickers as the data is not available via the API call.
Expand the testing.
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
  • TestUpdateTickers TestGetFuturesTickers

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

@thrasher- thrasher- added the review me This pull request is ready for review label Dec 26, 2023
@thrasher- thrasher- requested review from gloriousCode, shazbert and thrasher- and removed request for shazbert December 26, 2023 22:39
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! This looks great. Just some minor things I came across.

exchanges/kucoin/kucoin_wrapper.go Outdated Show resolved Hide resolved
exchanges/kucoin/kucoin_wrapper.go Outdated Show resolved Hide resolved
exchanges/kucoin/kucoin_wrapper.go Outdated Show resolved Hide resolved
exchanges/kucoin/kucoin_wrapper.go Outdated Show resolved Hide resolved
exchanges/kucoin/kucoin_wrapper.go Outdated Show resolved Hide resolved
exchanges/kucoin/kucoin_wrapper.go Outdated Show resolved Hide resolved
@Beadko Beadko requested a review from shazbert December 27, 2023 07:58
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 making those changes. tACK! 💃

@shazbert shazbert added the szrc shazbert review complete label Dec 27, 2023
@thrasher- thrasher- changed the title Bugfix/kucoin update tickers futures Kucoin: Implement GetFuturesTickers, update UpdateTickers and enhance test coverage Jan 16, 2024
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 @Beadko , the new endpoint and tests look great! A nit wrt to efficiency however

exchanges/kucoin/kucoin_wrapper.go Outdated Show resolved Hide resolved
@Beadko Beadko force-pushed the bugfix/kucoin_update_tickers_futures branch from 0e77547 to 9819129 Compare January 22, 2024 09:03
Copy link

codecov bot commented Jan 22, 2024

Codecov Report

Attention: 16 lines in your changes are missing coverage. Please review.

Comparison is base (d907aab) 43.35% compared to head (f211919) 43.82%.
Report is 11 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1431      +/-   ##
==========================================
+ Coverage   43.35%   43.82%   +0.46%     
==========================================
  Files         366      363       -3     
  Lines      147087   143963    -3124     
==========================================
- Hits        63774    63086     -688     
+ Misses      75489    73288    -2201     
+ Partials     7824     7589     -235     
Files Coverage Δ
exchanges/kucoin/kucoin_wrapper.go 34.90% <75.00%> (+1.17%) ⬆️
exchanges/kucoin/kucoin_futures.go 23.39% <69.38%> (+3.72%) ⬆️

... and 74 files with indirect coverage 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 for opening this PR, however I'm not sure if it fits right now

exchanges/kucoin/kucoin_test.go Outdated Show resolved Hide resolved
exchanges/kucoin/kucoin_wrapper.go Outdated Show resolved Hide resolved
exchanges/kucoin/kucoin_test.go Outdated Show resolved Hide resolved
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! Have some more feedback

exchanges/kucoin/kucoin_wrapper.go Outdated Show resolved Hide resolved
exchanges/kucoin/kucoin_wrapper.go Outdated Show resolved Hide resolved
@Beadko Beadko force-pushed the bugfix/kucoin_update_tickers_futures branch from 0539eb8 to cadd396 Compare January 28, 2024 03:07
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.

Latest builds have a data race:

==================
WARNING: DATA RACE
Write at 0x00c000bfad30 by goroutine 452:
  github.com/thrasher-corp/gocryptotrader/exchanges/kucoin.(*Kucoin).GetFuturesTickers.func1()
      /home/runner/work/gocryptotrader/gocryptotrader/exchanges/kucoin/kucoin_wrapper.go:388 +0x2d1

Previous write at 0x00c000bfad30 by goroutine 453:
  github.com/thrasher-corp/gocryptotrader/exchanges/kucoin.(*Kucoin).GetFuturesTickers.func1()
      /home/runner/work/gocryptotrader/gocryptotrader/exchanges/kucoin/kucoin_wrapper.go:388 +0x2d1

Goroutine 452 (running) created at:
  github.com/thrasher-corp/gocryptotrader/exchanges/kucoin.(*Kucoin).GetFuturesTickers()
      /home/runner/work/gocryptotrader/gocryptotrader/exchanges/kucoin/kucoin_wrapper.go:384 +0x238
  github.com/thrasher-corp/gocryptotrader/exchanges/kucoin.TestGetFuturesTickers()
      /home/runner/work/gocryptotrader/gocryptotrader/exchanges/kucoin/kucoin_test.go:120 +0x64
  testing.tRunner()
      /opt/hostedtoolcache/go/1.21.6/x64/src/testing/testing.go:1595 +0x261
  testing.(*T).Run.func1()
      /opt/hostedtoolcache/go/1.21.6/x64/src/testing/testing.go:1648 +0x44

Goroutine 453 (finished) created at:
  github.com/thrasher-corp/gocryptotrader/exchanges/kucoin.(*Kucoin).GetFuturesTickers()
      /home/runner/work/gocryptotrader/gocryptotrader/exchanges/kucoin/kucoin_wrapper.go:384 +0x238
  github.com/thrasher-corp/gocryptotrader/exchanges/kucoin.TestGetFuturesTickers()
      /home/runner/work/gocryptotrader/gocryptotrader/exchanges/kucoin/kucoin_test.go:120 +0x64
  testing.tRunner()
      /opt/hostedtoolcache/go/1.21.6/x64/src/testing/testing.go:1595 +0x261
  testing.(*T).Run.func1()
      /opt/hostedtoolcache/go/1.21.6/x64/src/testing/testing.go:1648 +0x44
==================
--- FAIL: TestGetFuturesTickers (0.29s)
    testing.go:1465: race detected during execution of test
--- FAIL: TestGetTicker (0.18s)
    testing.go:1465: race detected during execution of test
--- FAIL: TestGetFuturesCurrentFundingRate (0.31s)
    testing.go:1465: race detected during execution of test
--- FAIL: TestUpdateTickers (0.97s)
    testing.go:1465: race detected during execution of test
FAIL
coverage: 38.8% of statements

@shazbert shazbert removed the szrc shazbert review complete label Jan 29, 2024
@Beadko
Copy link
Contributor Author

Beadko commented Jan 29, 2024

Amended the error to fix the race issue

@Beadko Beadko requested a review from gloriousCode January 29, 2024 09:58
@gloriousCode
Copy link
Collaborator

@thrasher-
Copy link
Collaborator

That second race looks to be impacting master and not related to this PR as I just noticed it on a deps upgrade: https://github.com/thrasher-corp/gocryptotrader/actions/runs/7691800287/job/20957671281#step:9:394

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.

Just one nit and then this looks good to go

exchanges/kucoin/kucoin_wrapper.go Outdated Show resolved Hide resolved
@Beadko Beadko requested a review from thrasher- January 30, 2024 12:36
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.

Thank you for making those changes!

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.

Good stuff 2 minor things.

if tick, err2 := ku.GetFuturesTicker(ctx, p.String()); err2 != nil {
errC <- err2
} else {
tickersC <- &ticker.Price{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Bid size and ask size not set

Copy link
Collaborator

Choose a reason for hiding this comment

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

diff --git a/exchanges/kucoin/kucoin_wrapper.go b/exchanges/kucoin/kucoin_wrapper.go
index 0ac27b210..8aa921e70 100644
--- a/exchanges/kucoin/kucoin_wrapper.go
+++ b/exchanges/kucoin/kucoin_wrapper.go
@@ -375,6 +375,8 @@ func (ku *Kucoin) GetFuturesTickers(ctx context.Context) ([]*ticker.Price, error
                                        Last:         tick.Price.Float64(),
                                        Bid:          tick.BestBidPrice.Float64(),
                                        Ask:          tick.BestAskPrice.Float64(),
+                                       AskSize:      tick.BestAskSize,
+                                       BidSize:      tick.BestBidSize,
                                        Volume:       tick.Size,
                                        Pair:         p,
                                        LastUpdated:  tick.FilledTime.Time(),

@@ -347,6 +347,62 @@ func (ku *Kucoin) UpdateTradablePairs(ctx context.Context, forceUpdate bool) err
return nil
}

// GetFuturesTickers does n * REST requests based on enabled pairs of the futures asset type
func (ku *Kucoin) GetFuturesTickers(ctx context.Context) ([]*ticker.Price, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion: shift to kucoin_futures.go as is not technically mapped to exchange.IBotInterfaceface

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 making those changes!

go func() {
defer wg.Done()

if tick, err2 := ku.GetFuturesTicker(ctx, p.String()); err2 != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Something I noticed that's outside of scope, but definitely in your interest is that the function ku.GetFuturesTicker now has a rate limit weight of 2, versus it using the default of 1. Given that this is a request per ticker, this could impact you.

On further inspection I think this is impacting a few Kucoin Futures endpoints and the numbers seem a bit whack, so I'm fine with continuing on, with the idea to relook at this in future

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.

re-tACK, thanks @Beadko !

@thrasher- thrasher- merged commit e16ee53 into thrasher-corp:master Feb 2, 2024
9 of 12 checks passed
@Beadko Beadko deleted the bugfix/kucoin_update_tickers_futures branch February 3, 2024 07:31
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.

5 participants