-
Notifications
You must be signed in to change notification settings - Fork 837
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
Huobi: Fix false failure on NW date #1809
base: master
Are you sure you want to change the base?
Conversation
Looks like "Within 2 weeks" fails on 22nd November during leap years. On 2025-02-21 we saw NW come up with 2025-03-07 for a few hours, and I'm guessing it's because they use local time. Added 1 day leeway to account for that timezone difference.
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.
question/suggestion: I don't know times very well (so this is probably completely wrong) but shouldn't we load the expiration as cst then use add date because it accounts for leaps? We might need a mock for this as well.
diff --git a/exchanges/huobi/huobi_test.go b/exchanges/huobi/huobi_test.go
index d3053550c..af7c2bf33 100644
--- a/exchanges/huobi/huobi_test.go
+++ b/exchanges/huobi/huobi_test.go
@@ -1811,14 +1811,16 @@ func TestPairFromContractExpiryCode(t *testing.T) {
require.True(t, ok, "%s type must be in contractExpiryNames", cType)
assert.Equal(t, currency.BTC, p.Base, "pair Base should be the same")
assert.Equal(t, exp, p.Quote, "pair Quote should be the same")
- d, err := time.Parse("060102", p.Quote.String())
+ cst, err := time.LoadLocation("Asia/Shanghai")
+ require.NoError(t, err)
+ d, err := time.ParseInLocation("060102", p.Quote.String(), cst)
require.NoError(t, err, "currency code must be a parsable date")
require.Falsef(t, d.Before(n), "%s expiry must be today or after", cType)
switch cType {
case "CW", "NW":
- require.Truef(t, d.Before(n.Add(24*time.Hour*15)), "%s expiry must be within 15 days; Got: `%s`", cType, d)
+ require.Truef(t, d.Before(n.AddDate(0, 0, 14)), "%s expiry must be within 15 days; Got: `%s`", cType, d)
case "CQ", "NQ":
- require.Truef(t, d.Before(n.Add(24*time.Hour*181)), "%s expiry must be within 181 days; Got: `%s`", cType, d)
+ require.Truef(t, d.Before(n.AddDate(0, 3, 0)), "%s expiry must be within 181 days; Got: `%s`", cType, d)
}
}
}
I mean ... technically they're based in the Seychelles 😂 Yeah. I like your solution. Fixed gbjk@ef5e85856b |
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.
Changes ACK. one suggestion.
exchanges/huobi/huobi_test.go
Outdated
cst, err := time.LoadLocation("Asia/Singapore") // Huobi HQ and apparent local time for when codes become effective | ||
require.NoError(t, err, "LoadLocation must not error") | ||
d, err := time.ParseInLocation("060102", p.Quote.String(), cst) |
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.
Going from this
cst, err := time.LoadLocation("Asia/Singapore") // Huobi HQ and apparent local time for when codes become effective | |
require.NoError(t, err, "LoadLocation must not error") | |
d, err := time.ParseInLocation("060102", p.Quote.String(), cst) | |
sgt, err := time.LoadLocation("Asia/Singapore") // Huobi HQ and apparent local time for when codes become effective | |
require.NoError(t, err, "LoadLocation must not error") | |
d, err := time.ParseInLocation("060102", p.Quote.String(), sgt) |
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 when we see a mistake happened because of unnecessary naming, best not to double down on it.
Fixed gbjk@0f841230be
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 the changes!
Looks like "Within 2 weeks" fails on 22nd November during leap years. On 2025-02-21 we saw NW come up with 2025-03-07 for a few hours, and I'm guessing it's because they use local time. Added 1 day leeway to account for that timezone difference.
Type of change