mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
improve error logging
This commit is contained in:
parent
6b478b4e87
commit
87e5019b08
|
@ -3,6 +3,7 @@ package binance
|
|||
import (
|
||||
"context"
|
||||
"github.com/c9s/bbgo/pkg/util"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/adshao/go-binance"
|
||||
|
@ -23,9 +24,9 @@ type StreamRequest struct {
|
|||
type PrivateStream struct {
|
||||
types.StandardPrivateStream
|
||||
|
||||
Client *binance.Client
|
||||
ListenKey string
|
||||
Conn *websocket.Conn
|
||||
Client *binance.Client
|
||||
ListenKey string
|
||||
Conn *websocket.Conn
|
||||
|
||||
connectCallbacks []func(stream *PrivateStream)
|
||||
|
||||
|
@ -38,7 +39,6 @@ type PrivateStream struct {
|
|||
executionReportEventCallbacks []func(event *ExecutionReportEvent)
|
||||
}
|
||||
|
||||
|
||||
func (s *PrivateStream) dial(listenKey string) (*websocket.Conn, error) {
|
||||
url := "wss://stream.binance.com:9443/ws/" + listenKey
|
||||
conn, _, err := websocket.DefaultDialer.Dial(url, nil)
|
||||
|
@ -105,13 +105,15 @@ func (s *PrivateStream) read(ctx context.Context, eventC chan interface{}) {
|
|||
return
|
||||
|
||||
case <-ticker.C:
|
||||
if err := s.Conn.WriteControl(websocket.PingMessage, []byte("hb"), time.Now().Add(1 * time.Second)) ; err != nil {
|
||||
if err := s.Conn.WriteControl(websocket.PingMessage, []byte("hb"), time.Now().Add(1*time.Second)); err != nil {
|
||||
log.WithError(err).Error("ping error", err)
|
||||
}
|
||||
|
||||
err := s.Client.NewKeepaliveUserStreamService().ListenKey(s.ListenKey).Do(ctx)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("listen key keep-alive error", err)
|
||||
maskKey := s.ListenKey[0:5]
|
||||
maskKey = maskKey + strings.Repeat("*", len(s.ListenKey)-1-5)
|
||||
log.WithError(err).Errorf("listen key keep-alive error: %v key: %s", err, maskKey)
|
||||
}
|
||||
|
||||
default:
|
||||
|
|
|
@ -2,8 +2,10 @@ package slack
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/slack-go/slack"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type SlackLogHook struct {
|
||||
|
@ -36,19 +38,22 @@ func (t *SlackLogHook) Fire(e *logrus.Entry) error {
|
|||
|
||||
var slackAttachments []slack.Attachment = nil
|
||||
|
||||
logerr, ok := e.Data["err"]
|
||||
if ok {
|
||||
slackAttachments = append(slackAttachments, slack.Attachment{
|
||||
Color: color,
|
||||
Title: "Error",
|
||||
Fields: []slack.AttachmentField{
|
||||
{Title: "Error", Value: logerr.(error).Error()},
|
||||
},
|
||||
// error fields
|
||||
var fields []slack.AttachmentField
|
||||
for k, d := range e.Data {
|
||||
fields = append(fields, slack.AttachmentField{
|
||||
Title: k, Value: fmt.Sprintf("%v", d),
|
||||
})
|
||||
}
|
||||
|
||||
slackAttachments = append(slackAttachments, slack.Attachment{
|
||||
Color: color,
|
||||
Title: strings.ToUpper(e.Level.String()),
|
||||
Fields: fields,
|
||||
})
|
||||
|
||||
_, _, err := t.Slack.PostMessageContext(context.Background(), t.ErrorChannel,
|
||||
slack.MsgOptionText(e.Message, true),
|
||||
slack.MsgOptionText(":balloon: "+e.Message, true),
|
||||
slack.MsgOptionAttachments(slackAttachments...))
|
||||
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue
Block a user