implement UnixMilli in the util package

This commit is contained in:
c9s 2021-12-23 22:20:47 +08:00
parent d433c7f5b1
commit ed6f400161
2 changed files with 7 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import (
"github.com/c9s/bbgo/pkg/exchange/kucoin/kucoinapi"
"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/util"
"github.com/gorilla/websocket"
"github.com/pkg/errors"
)
@ -390,7 +391,7 @@ type WebSocketConnector interface {
}
func ping(ctx context.Context, w WebSocketConnector, interval time.Duration) {
log.Infof("starting ping worker with interval %s", interval)
log.Infof("starting websocket ping worker with interval %s", interval)
pingTicker := time.NewTicker(interval)
defer pingTicker.Stop()
@ -406,7 +407,7 @@ func ping(ctx context.Context, w WebSocketConnector, interval time.Duration) {
conn := w.Conn()
if err := conn.WriteJSON(WebSocketCommand{
Id: time.Now().UnixNano() / int64(time.Millisecond),
Id: util.UnixMilli(),
Type: "ping",
}); err != nil {
log.WithError(err).Error("websocket ping error", err)

View File

@ -18,3 +18,7 @@ func BeginningOfTheDay(t time.Time) time.Time {
func Over24Hours(since time.Time) bool {
return time.Since(since) >= 24 * time.Hour
}
func UnixMilli() int64 {
return time.Now().UnixNano() / int64(time.Millisecond)
}