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
(BTC Markets): Wrapper SubmitOrder parameter order fix & IsOrderPlaced condition correction #394
(BTC Markets): Wrapper SubmitOrder parameter order fix & IsOrderPlaced condition correction #394
Conversation
Codecov Report
@@ Coverage Diff @@
## master #394 +/- ##
==========================================
- Coverage 41.4% 41.36% -0.04%
==========================================
Files 163 163
Lines 38341 38366 +25
==========================================
- Hits 15874 15870 -4
- Misses 21352 21372 +20
- Partials 1115 1124 +9
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice find! tACK
Just realised that there's another bug: https://github.com/thrasher-corp/gocryptotrader/blob/master/exchanges/btcmarkets/btcmarkets_wrapper.go#L547 This will return all orders (inactive/cancelled etc) so we can specify "open" as the last param to retrieve only open orders |
Addressed this and some other issues with GetActiveOrders() At quick glance GetOrderHistory() also needs to be reworked will push through another update soon and get you to rereview it |
BTC markets batch end points have limits (20 for cancel 50 for query) adds new method SplitStringSliceByLimit in common to split a slice by limit and return slice of slice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing these issues! Just have 2 basic nits
tempResp.OrderSide = order.Bid | ||
if tempData[y].Side == ask { | ||
tempResp.OrderSide = order.Ask | ||
} | ||
tempResp.OrderDate = tempData[y].CreationTime | ||
|
||
switch tempData[y].Type { | ||
case "Limit": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can use consts:
limit = "Limit" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this 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! I just noticed another 2 but they're related to the ntpclient
ntpclient/ntpclient.go
Outdated
@@ -38,7 +37,10 @@ func NTPClient(pool []string) (time.Time, error) { | |||
|
|||
defer con.Close() | |||
|
|||
con.SetDeadline(time.Now().Add(5 * time.Second)) | |||
err = con.SetDeadline(time.Now().Add(5 * time.Second)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change to
if err := con.SetDeadline(time.Now().Add(5 * time.Second)); err != nil {
log.Warnf(log.TimeMgr, "Unable to SetDeadline. Error: %s\n", err)
con.Close()
continue
}
The other thing I noticed with this is we are deferring con.Close() but on each for loop iteration, we are reassigning con. The defer will only execute upon func exit, so it's possible for lingering cons
ntpclient/ntpclient.go
Outdated
@@ -55,5 +57,6 @@ func NTPClient(pool []string) (time.Time, error) { | |||
|
|||
return time.Unix(int64(secs), nanos), nil | |||
} | |||
return time.Unix(0, 0), errors.New("no valid time servers") | |||
log.Warnln(log.Global, "No valid ntp server found returning current system time") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use log.TimeMgr here, and just a basic grammar fix:
No valid NTP servers found, using current system time
ntpclient/ntpclient.go
Outdated
@@ -30,30 +29,36 @@ type ntppacket struct { | |||
// NTPClient create's a new NTPClient and returns local based on ntp servers provided timestamp | |||
func NTPClient(pool []string) (time.Time, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we don't use err, we could do a check at the top to check if len(pool) == 0 and complain if it's empty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will remove the error return value
a pool should never be empty because of https://github.com/thrasher-corp/gocryptotrader/blob/master/config/config.go#L1250
if len(req.Currencies) == 0 { | ||
allPairs := b.GetEnabledPairs(asset.Spot) | ||
allPairs := b.GetAvailablePairs(asset.Spot) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should keep this as GetEnabledPairs, so that we're only interested in the ones the user has enabled (otherwise they can set it in req.Currencies). Our order manager will use enabled pairs in a future update.
…if no server can be reached
There was a problem hiding this 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 requested changes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Epic changes - Few nits
common/common_test.go
Outdated
slice50 := initStringSlice(t, 50) | ||
out := SplitStringSliceByLimit(slice50, 20) | ||
if len(out) != 3 { | ||
t.Errorf("test failed expected len() to be 3 instead received: %v", len(out)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we got rid of test failed strings. Might do that as well.
common/common_test.go
Outdated
@@ -499,3 +500,30 @@ func TestChangePermission(t *testing.T) { | |||
} | |||
} | |||
} | |||
|
|||
func initStringSlice(t *testing.T, size int) (out []string) { | |||
t.Helper() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no error messages here so this can be rm'd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Helper() is called here to cause this function to be ignored when printing out warnings/errors/line information
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It actually shifts the error to the calling function line if it has a t.Error or t.Fatal, it doesn't add anything to the output.
for example:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func initStringSlice(t *testing.T, size int) (out []string) {
t.Helper()
for x := 0; x < size; x++ {
out = append(out, "gct-"+strconv.Itoa(x))
}
t.Error("Cats")
return
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will indicate error at ln 514 instead of ln 509
_, err = NTPClient(firstInvalid) | ||
if err != nil { | ||
t.Errorf("failed to get time %v", err) | ||
if reflect.TypeOf(v) != reflect.TypeOf(time.Time{}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will always be a time.Time so can RM this check. Or could force a time.Now().UTC() check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly this was just a lazy way to maintain test coverage to at least know its returning a time.Now()
I can do a time.Now.UTC() check but i would have to also parse the time into a format that doen't include anything above milliseconds or return value of NTPClient and time.Now.UTC() will be out and cause a failure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another one is just comparing the year/day/month is the same, that's a good enough check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept the type check because you can never have to much test coverage right :D?
Also added a check for IsZero() and using 2006-01-02T15:04:05 format
There was a problem hiding this 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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reapproved!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reACK!
…d condition correction (thrasher-corp#394) * corrected param order Side -> Type, also corrected condition check for IsOrderPlaced * send open status for GetActiveOrders * GetActiveOrder() changes to include OrderID and status matching * BTC Markets batch order limit fixes & SplitStringSliceByLimit method BTC markets batch end points have limits (20 for cancel 50 for query) adds new method SplitStringSliceByLimit in common to split a slice by limit and return slice of slice * rm line :D * Added test for SplitStringSliceByLimit and moved to const * ntp client reworked to not return error if no valid time servers are found but default to system * clean up * new line added * use TimeMgr sublogger and wording correction on output * Moved to DialTimeout() & Removed SetDeadline call * removed line * added setdeadline fix * goimport file * removed unused error from NTPClient as we now default to system time if no server can be reached * Added checks for number overflows * converted to uint as you should not be passing a negative number in * Increased test cases for NTPClient * Removed Helper call as no longer outputting any data from function * removed unused param
PR Description
Corrects parameter order for BTCMarkets SubmitOrder() wrapper to NewOrder() Method
(OrderType & OrderSide were incorrect)
Also fixes the condition check on IsOrderPlaced in order manager Submit() Method that will cause it to return order cannot be placed error if IsOrderPlaced is true
Type of change
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.
Checklist