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: Update Poloniex exchange API #1351

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

Conversation

samuael
Copy link
Collaborator

@samuael samuael commented Sep 17, 2023

PR Description

This pull request included a Poloniex exchange code implementation with REST and WebSocket capabilities. The Wrapper and Web-socket functions have all undergone testing. My code conforms to the GCT style standards used by other exchanges.
golangci-lint was used to fix a few mistakes. For future use, endpoint methods that the GCT wrapper does not support are also implemented.

The PR included implementations for REST for trading and other endpoint methods, Web-socket streaming, and Trading through the web socket stream.

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

@gloriousCode gloriousCode changed the title exchanges: Update Poloniex exchange exchanges: Update Poloniex exchange API Sep 17, 2023
@gloriousCode gloriousCode requested a review from a team September 17, 2023 21:23
@gloriousCode gloriousCode added the review me This pull request is ready for review label Sep 17, 2023
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 update. just skimmed across changes and found some basic things. Nice work!

if err != nil {
return vals, err
if strings.EqualFold(err.Error(), "json: cannot unmarshal array into Go value of type 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.

Can you please have a valid test case for this?

intermediary := make(map[string]interface{})
err := json.Unmarshal(payload, &intermediary)
intermediary := make([]map[string]interface{}, 1, 5)
intermediary[0] = 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 should be allocated with the json call so can RM this.

@@ -181,12 +181,14 @@ func HTTPRecord(res *http.Response, service string, respContents []byte) error {
if jErr != nil {
return jErr
}

if MatchURLVals(reqVals, mockVals) {
found = true
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please have a test case for this?


// MatchBatchAndGetResponse matches a batch of incoming request values with mockdata response
// values and returns the payload
func MatchBatchAndGetResponse(mockData []HTTPResponse, requestVals []url.Values) (json.RawMessage, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs tests

var resp []SymbolDetail
path := "/markets"
if !symbol.IsEmpty() {
path = fmt.Sprintf("%s/%s", path, symbol)
Copy link
Collaborator

Choose a reason for hiding this comment

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

use concatenation instead of fmt.Sprintf across this PR.

sort.Sort(trade.ByDate(resp))
return resp, nil
}

// --------------------------------------------------------------------------------------------------------------------
Copy link
Collaborator

Choose a reason for hiding this comment

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

?

}
return s.DeriveSubmitResponse(sOrder.ID)
}
var response *PlaceOrderResponse
Copy link
Collaborator

Choose a reason for hiding this comment

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

can be shifted above smart order and used in all requests.

}
return nil, err
smartOrder = true
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can just do a length check on smartOrders

QuoteAmount: resp.Amount.Float64(),
ExecutedAmount: resp.FilledQuantity.Float64(),
RemainingAmount: resp.Quantity.Float64() - resp.FilledAmount.Float64(),
Cost: resp.Quantity.Float64() * resp.AvgPrice.Float64(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

resp.Quantity.Float64() -> resp.FilledQuantity.Float64() maybe there is a partial fill?

@@ -237,6 +237,7 @@ func (r *Requester) doRequest(ctx context.Context, endpoint EndpointLimit, newRe
if err != nil {
return err
}
println(string(contents))
Copy link
Collaborator

Choose a reason for hiding this comment

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

👁️

Copy link

codecov bot commented Oct 27, 2024

Codecov Report

Attention: Patch coverage is 38.35762% with 2327 lines in your changes missing coverage. Please review.

Project coverage is 36.97%. Comparing base (8f9ebcb) to head (e2798f3).

Files with missing lines Patch % Lines
exchanges/poloniex/poloniex_wrapper.go 22.88% 972 Missing and 42 partials ⚠️
exchanges/poloniex/poloniex.go 42.31% 376 Missing and 7 partials ⚠️
exchanges/poloniex/poloniex_futures.go 47.01% 287 Missing and 6 partials ⚠️
exchanges/poloniex/poloniex_futures_websocket.go 44.68% 253 Missing and 33 partials ⚠️
exchanges/poloniex/poloniex_websocket.go 53.57% 185 Missing and 10 partials ⚠️
exchanges/poloniex/poloniex_websocket_trade.go 15.38% 55 Missing ⚠️
exchanges/poloniex/poloniex_types.go 40.65% 36 Missing and 18 partials ⚠️
exchanges/mock/server.go 39.58% 27 Missing and 2 partials ⚠️
exchanges/mock/common.go 75.75% 8 Missing ⚠️
exchanges/mock/recording.go 0.00% 5 Missing ⚠️
... and 2 more
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1351      +/-   ##
==========================================
- Coverage   37.13%   36.97%   -0.17%     
==========================================
  Files         414      418       +4     
  Lines      180177   181977    +1800     
==========================================
+ Hits        66910    67277     +367     
- Misses     105411   106874    +1463     
+ Partials     7856     7826      -30     
Files with missing lines Coverage Δ
exchanges/poloniex/ratelimit.go 100.00% <100.00%> (ø)
exchanges/order/orders.go 90.87% <75.00%> (-0.13%) ⬇️
exchanges/poloniex/poloniex_futures_types.go 91.17% <91.17%> (ø)
exchanges/mock/recording.go 20.95% <0.00%> (-0.21%) ⬇️
exchanges/mock/common.go 75.86% <75.75%> (+6.81%) ⬆️
exchanges/mock/server.go 26.58% <39.58%> (+3.78%) ⬆️
exchanges/poloniex/poloniex_types.go 40.65% <40.65%> (ø)
exchanges/poloniex/poloniex_websocket_trade.go 15.38% <15.38%> (ø)
exchanges/poloniex/poloniex_websocket.go 45.76% <53.57%> (-6.87%) ⬇️
exchanges/poloniex/poloniex_futures_websocket.go 44.68% <44.68%> (ø)
... and 3 more

... and 14 files with indirect coverage changes

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