|
4 | 4 | "encoding/json"
|
5 | 5 | "errors"
|
6 | 6 | "fmt"
|
| 7 | + "strconv" |
7 | 8 | "strings"
|
8 | 9 | "time"
|
9 | 10 | )
|
@@ -671,6 +672,43 @@ type WsUserDataEvent struct {
|
671 | 672 | OrderTradeUpdate WsOrderTradeUpdate `json:"o"`
|
672 | 673 | }
|
673 | 674 |
|
| 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 | + |
674 | 712 | // WsAccountUpdate define account update
|
675 | 713 | type WsAccountUpdate struct {
|
676 | 714 | Reason UserDataEventReasonType `json:"m"`
|
|
0 commit comments