Skip to content

Commit d71158d

Browse files
committed
also fix this in the delivery package
1 parent a41618e commit d71158d

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

v2/delivery/websocket_service.go

+38
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"errors"
66
"fmt"
7+
"strconv"
78
"strings"
89
"time"
910
)
@@ -671,6 +672,43 @@ type WsUserDataEvent struct {
671672
OrderTradeUpdate WsOrderTradeUpdate `json:"o"`
672673
}
673674

675+
func (e *WsUserDataEvent) UnmarshalJSON(data []byte) error {
676+
var tmp struct {
677+
Event UserDataEventType `json:"e"`
678+
Time interface{} `json:"E"`
679+
Alias string `json:"i"`
680+
CrossWalletBalance string `json:"cw"`
681+
MarginCallPositions []WsPosition `json:"p"`
682+
TransactionTime int64 `json:"T"`
683+
AccountUpdate WsAccountUpdate `json:"a"`
684+
OrderTradeUpdate WsOrderTradeUpdate `json:"o"`
685+
}
686+
if err := json.Unmarshal(data, &tmp); err != nil {
687+
return err
688+
}
689+
690+
e.Event = tmp.Event
691+
switch v := tmp.Time.(type) {
692+
case float64:
693+
e.Time = int64(v)
694+
case string:
695+
parsedTime, err := strconv.ParseInt(v, 10, 64)
696+
if err != nil {
697+
return err
698+
}
699+
e.Time = parsedTime
700+
default:
701+
return fmt.Errorf("unexpected type for E: %T", tmp.Time)
702+
}
703+
e.Alias = tmp.Alias
704+
e.CrossWalletBalance = tmp.CrossWalletBalance
705+
e.MarginCallPositions = tmp.MarginCallPositions
706+
e.TransactionTime = tmp.TransactionTime
707+
e.AccountUpdate = tmp.AccountUpdate
708+
e.OrderTradeUpdate = tmp.OrderTradeUpdate
709+
return nil
710+
}
711+
674712
// WsAccountUpdate define account update
675713
type WsAccountUpdate struct {
676714
Reason UserDataEventReasonType `json:"m"`

0 commit comments

Comments
 (0)