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

exchanges: Kucoin Update #1438

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

Conversation

samuael
Copy link
Contributor

@samuael samuael commented Jan 2, 2024

Selam Everyone

This pull request incorporates extensive revisions to type definitions, rate limiters, request endpoints, and functions within the websocket handlers. Additionally, I've addressed linter issues and conducted unit tests.

Fixes # (issue)

Type of change

Please delete options that are not relevant and add an x in [] as the 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 not to 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. Could you provide instructions so we can reproduce them? Please also list any relevant details for your test configuration and also, consider improving test coverage while 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 code
  • I have commented on 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

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 the improvement! Just two things I noticed on first glance. Also there is an issue with websocket orderbook syncs when running tests.

Kucoin error processing update - initiating new orderbook sync via REST: initial websocket orderbook sync failure for pair BTC-USDT and asset margin

return err
}
return ku.Subscribe(subscriptions)
// return nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

rm

case kline.OneWeek:
return "1week", nil
default:
intervalMap := map[kline.Interval]string{
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.go b/exchanges/kucoin/kucoin.go
index 11eb3895a..78bab48f8 100644
--- a/exchanges/kucoin/kucoin.go
+++ b/exchanges/kucoin/kucoin.go
@@ -1721,10 +1721,11 @@ func (ku *Kucoin) SendAuthHTTPRequest(ctx context.Context, ePath exchange.URL, e
        return resp.GetError()
 }

+var intervalMap = map[kline.Interval]string{
+       kline.OneMin: "1min", kline.ThreeMin: "3min", kline.FiveMin: "5min", kline.FifteenMin: "15min", kline.ThirtyMin: "30min", kline.OneHour: "1hour", kline.TwoHour: "2hour", kline.FourHour: "4hour", kline.SixHour: "6hour", kline.EightHour: "8hour", kline.TwelveHour: "12hour", kline.OneDay: "1day", kline.OneWeek: "1week",
+}
+
 func (ku *Kucoin) intervalToString(interval kline.Interval) (string, error) {
-       intervalMap := map[kline.Interval]string{
-               kline.OneMin: "1min", kline.ThreeMin: "3min", kline.FiveMin: "5min", kline.FifteenMin: "15min", kline.ThirtyMin: "30min", kline.OneHour: "1hour", kline.TwoHour: "2hour", kline.FourHour: "4hour", kline.SixHour: "6hour", kline.EightHour: "8hour", kline.TwelveHour: "12hour", kline.OneDay: "1day", kline.OneWeek: "1week",
-       }
        intervalString, okay := intervalMap[interval]
        if !okay {
                return "", kline.ErrUnsupportedInterval
diff --git a/exchanges/kucoin/kucoin_test.go b/exchanges/kucoin/kucoin_test.go
index 46e8d603e..560647320 100644
--- a/exchanges/kucoin/kucoin_test.go
+++ b/exchanges/kucoin/kucoin_test.go
@@ -2598,3 +2598,12 @@ func TestUpdateOrderExecutionLimits(t *testing.T) {
                }
        }
 }
+
+func BenchmarkXxx(b *testing.B) {
+       for x := 0; x < b.N; x++ {
+               _, err := ku.intervalToString(kline.OneWeek)
+               if err != nil {
+                       b.Fatal(err)
+               }
+       }
+}

You're allocating on every call.

Old:
 3082915	       370.7 ns/op	     896 B/op	       1 allocs/op
New:
223317469	         5.501 ns/op	       0 B/op	       0 allocs/op

@shazbert shazbert added the review me This pull request is ready for review label Jan 2, 2024
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.

tACK. Thanks Sam!

@shazbert shazbert added the szrc shazbert review complete label Jan 3, 2024
Copy link

codecov bot commented Jan 17, 2024

Codecov Report

Attention: Patch coverage is 13.20755% with 644 lines in your changes are missing coverage. Please review.

Project coverage is 37.58%. Comparing base (d518993) to head (7461fde).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1438      +/-   ##
==========================================
- Coverage   37.75%   37.58%   -0.18%     
==========================================
  Files         411      411              
  Lines      147817   148614     +797     
==========================================
+ Hits        55815    55863      +48     
- Misses      84218    84990     +772     
+ Partials     7784     7761      -23     
Files Coverage Δ
exchanges/kucoin/kucoin.go 12.28% <ø> (-3.36%) ⬇️
exchanges/kucoin/kucoin_types.go 64.81% <ø> (ø)
exchanges/kucoin/kucoin_websocket.go 59.39% <75.00%> (+0.80%) ⬆️
exchanges/kucoin/kucoin_futures.go 26.13% <12.08%> (+0.17%) ⬆️
exchanges/kucoin/kucoin_wrapper.go 33.59% <0.00%> (-3.24%) ⬇️
exchanges/kucoin/kucoin_ratelimit.go 22.13% <20.46%> (-24.54%) ⬇️

... and 16 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.

Just happened to have been the first thing I looked at 😅
Do you think you could review and implement the latest changes to the API? If not, happy for a new PR for Kucoin's changes, but at least could you remove deprecated functions?

if size == 0 {
return nil, errors.New("size can not be zero")
}
params := make(map[string]interface{})
Copy link
Collaborator

Choose a reason for hiding this comment

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

This endpoint is deprecated:
https://www.kucoin.com/announcement/the-kucoin-api-upgrade-has-been-completed-2023-09

  1. Deprecated: Place Isolated Borrow Order, abandon the "POST /api/v1/isolated/borrow" interface and replace it with the "POST /api/v3/margin/borrow" interface

I think there are more updates for Kucoin than in this PR

@samuael
Copy link
Contributor Author

samuael commented Feb 15, 2024

Well, Well, Well ... It is 26 endpoint updates🤔
I just completed the Unit test updates and started working on 26 updates.

@shazbert shazbert added lint requires fixing and removed szrc shazbert review complete labels Feb 16, 2024
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.

linter and spell checker needs to be fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
high priority review me This pull request is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants