-
Notifications
You must be signed in to change notification settings - Fork 145
/
message.go
93 lines (79 loc) · 2.63 KB
/
message.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package coinbasepro
import (
"encoding/json"
)
type Message struct {
Type string `json:"type"`
ProductID string `json:"product_id"`
ProductIds []string `json:"product_ids"`
Products []Product `json:"products"`
Currencies []Currency `json:"currencies"`
TradeID int `json:"trade_id,number"`
OrderID string `json:"order_id"`
ClientOID string `json:"client_oid"`
Sequence int64 `json:"sequence,number"`
MakerOrderID string `json:"maker_order_id"`
TakerOrderID string `json:"taker_order_id"`
Time Time `json:"time,string"`
RemainingSize string `json:"remaining_size"`
NewSize string `json:"new_size"`
OldSize string `json:"old_size"`
Size string `json:"size"`
Price string `json:"price"`
Side string `json:"side"`
Reason string `json:"reason"`
OrderType string `json:"order_type"`
Funds string `json:"funds"`
NewFunds string `json:"new_funds"`
OldFunds string `json:"old_funds"`
Message string `json:"message"`
Bids []SnapshotEntry `json:"bids,omitempty"`
Asks []SnapshotEntry `json:"asks,omitempty"`
Changes []SnapshotChange `json:"changes,omitempty"`
LastSize string `json:"last_size"`
BestBid string `json:"best_bid"`
BestAsk string `json:"best_ask"`
Channels []MessageChannel `json:"channels"`
UserID string `json:"user_id"`
ProfileID string `json:"profile_id"`
LastTradeID int `json:"last_trade_id"`
}
type MessageChannel struct {
Name string `json:"name"`
ProductIds []string `json:"product_ids"`
}
type SnapshotChange struct {
Side string
Price string
Size string
}
type SnapshotEntry struct {
Price string
Size string
}
type SignedMessage struct {
Message
Key string `json:"key"`
Passphrase string `json:"passphrase"`
Timestamp string `json:"timestamp"`
Signature string `json:"signature"`
}
func (e *SnapshotEntry) UnmarshalJSON(data []byte) error {
var entry []string
if err := json.Unmarshal(data, &entry); err != nil {
return err
}
e.Price = entry[0]
e.Size = entry[1]
return nil
}
func (e *SnapshotChange) UnmarshalJSON(data []byte) error {
var entry []string
if err := json.Unmarshal(data, &entry); err != nil {
return err
}
e.Side = entry[0]
e.Price = entry[1]
e.Size = entry[2]
return nil
}