mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
Kraken: Subscription improvements (#1587)
* Convert: Fix TimeFromUnixTimestampDecimal using local All parsed times should be in UTC * Subscriptions: Add IgnoringAssetsKey * Tests: Pass tb to curried WS handlers * Websocket: Make ErrNoMessageListener a public error * Kraken: Fix URLMap ignored for websocket URLs * Kraken: Move SeedAssets from Setup to Bootstrap Having SeedAssets in Setup is cruel and unusual because it calls the API. Most other interactive data seeding happens in Bootstrap. This made it so that fixing and creating unit tests for Kraken was painfully slow, particularly on flaky internet. * Kraken: Remove convert test Duplicate of convert_test.go TestTimeFromUnixTimestampDecimal * Kraken: Test config upgrades * Kraken: Sub Channel improvements * Use Websocket subscriptionChannels instead of local slice * Remove ChannelID - Deprecated in docs * Simplify ping handlers and hardcodes message * Add Depth as configurable orderbook channel param * Simplify auth/non-auth channel updates * Add configurable Book depth * Add configurable Candle timeframes Kraken: Simplify all WS handlers with reqId * Kraken: Subscription templating * Generate N+ subs for pairs If we generate one sub for all pairs, but then fan it out in the responses, we end up with a mis-match between the sub store and GenerateSubs, and when we do FlushChannels it will try to resub everything again. * Kraken: Rename channelName var throughout Avoid shadowing func of same name * Kraken: Add TestEnforceStandardChannelNames * Websocket: Fix Resubscribe erroring Duplicate
This commit is contained in:
@@ -58,11 +58,10 @@ func TimeFromUnixTimestampFloat(raw interface{}) (time.Time, error) {
|
||||
return time.UnixMilli(int64(ts)), nil
|
||||
}
|
||||
|
||||
// TimeFromUnixTimestampDecimal converts a unix timestamp in decimal form to
|
||||
// a time.Time
|
||||
// TimeFromUnixTimestampDecimal converts a unix timestamp in decimal form to a time.Time in UTC
|
||||
func TimeFromUnixTimestampDecimal(input float64) time.Time {
|
||||
i, f := math.Modf(input)
|
||||
return time.Unix(int64(i), int64(f*(1e9)))
|
||||
return time.Unix(int64(i), int64(f*(1e9))).UTC()
|
||||
}
|
||||
|
||||
// UnixTimestampToTime returns time.time
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestFloatFromString(t *testing.T) {
|
||||
@@ -97,18 +98,17 @@ func TestTimeFromUnixTimestampFloat(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTimeFromUnixTimestampDecimal(t *testing.T) {
|
||||
r := TimeFromUnixTimestampDecimal(1590633982.5714)
|
||||
if r.Year() != 2020 ||
|
||||
r.Month().String() != "May" ||
|
||||
r.Day() != 28 {
|
||||
t.Error("unexpected result")
|
||||
}
|
||||
|
||||
r = TimeFromUnixTimestampDecimal(1560516023.070651)
|
||||
if r.Year() != 2019 ||
|
||||
r.Month().String() != "June" ||
|
||||
r.Day() != 14 {
|
||||
t.Error("unexpected result")
|
||||
for in, exp := range map[float64]time.Time{
|
||||
1590633982.5714: time.Date(2020, 5, 28, 2, 46, 22, 571400000, time.UTC),
|
||||
1560516023.070651: time.Date(2019, 6, 14, 12, 40, 23, 70651000, time.UTC),
|
||||
// Examples from Kraken
|
||||
1373750306.9819: time.Date(2013, 7, 13, 21, 18, 26, 981900000, time.UTC),
|
||||
1534614098.345543: time.Date(2018, 8, 18, 17, 41, 38, 345543000, time.UTC),
|
||||
} {
|
||||
got := TimeFromUnixTimestampDecimal(in)
|
||||
z, _ := got.Zone()
|
||||
assert.Equal(t, "UTC", z, "TimeFromUnixTimestampDecimal should return a UTC time")
|
||||
assert.WithinRangef(t, got, exp.Add(-time.Microsecond), exp.Add(time.Microsecond), "TimeFromUnixTimestampDecimal(%f) should parse a unix timestamp correctly", in)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user