-
-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathws_types.go
More file actions
278 lines (241 loc) · 9.36 KB
/
ws_types.go
File metadata and controls
278 lines (241 loc) · 9.36 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
package hyperliquid
import (
"encoding/json"
)
//go:generate easyjson -all
const (
ChannelPong string = "pong"
ChannelTrades string = "trades"
ChannelActiveAssetCtx string = "activeAssetCtx"
ChannelL2Book string = "l2Book"
ChannelCandle string = "candle"
ChannelAllMids string = "allMids"
ChannelNotification string = "notification"
ChannelOrderUpdates string = "orderUpdates"
ChannelUserFills string = "userFills"
ChannelWebData2 string = "webData2"
ChannelBbo string = "bbo"
ChannelSubResponse string = "subscriptionResponse"
ChannelClearinghouseState string = "clearinghouseState"
ChannelOpenOrders string = "openOrders"
ChannelTwapStates string = "twapStates"
ChannelWebData3 string = "webData3"
)
type wsMessage struct {
Channel string `json:"channel"`
Data json.RawMessage `json:"data"`
}
type wsCommand struct {
Method string `json:"method"`
Subscription any `json:"subscription,omitempty"`
}
type (
Trade struct {
Coin string `json:"coin"`
Side string `json:"side"`
Px string `json:"px"`
Sz string `json:"sz"`
Time int64 `json:"time"`
Hash string `json:"hash"`
Tid int64 `json:"tid"`
Users []string `json:"users"`
}
ActiveAssetCtx struct {
Coin string `json:"coin"`
Ctx SharedAssetCtx `json:"ctx"`
}
SharedAssetCtx struct {
DayNtlVlm float64 `json:"dayNtlVlm,string"`
PrevDayPx float64 `json:"prevDayPx,string"`
MarkPx float64 `json:"markPx,string"`
MidPx float64 `json:"midPx,string"`
// PerpsAssetCtx
Funding float64 `json:"funding,string,omitempty"`
OpenInterest float64 `json:"openInterest,string,omitempty"`
OraclePx float64 `json:"oraclePx,string,omitempty"`
// SpotAssetCtx
CirculatingSupply float64 `json:"circulatingSupply,string,omitempty"`
}
AllMids struct {
Mids map[string]string `json:"mids"`
}
Notification struct {
Notification string `json:"notification"`
}
//easyjson:skip
WebData2 struct {
ClearinghouseState *ClearinghouseState `json:"clearinghouseState,omitempty"`
LeadingVaults []any `json:"leadingVaults,omitempty"`
TotalVaultEquity string `json:"totalVaultEquity,omitempty"`
OpenOrders []WsBasicOrder `json:"openOrders,omitempty"`
AgentAddress *string `json:"agentAddress,omitempty"`
AgentValidUntil *int64 `json:"agentValidUntil,omitempty"`
CumLedger string `json:"cumLedger,omitempty"`
Meta *WebData2Meta `json:"meta,omitempty"`
AssetCtxs []AssetCtx `json:"assetCtxs,omitempty"`
ServerTime int64 `json:"serverTime,omitempty"`
IsVault bool `json:"isVault,omitempty"`
User string `json:"user,omitempty"`
TwapStates []any `json:"twapStates,omitempty"`
SpotState *SpotState `json:"spotState,omitempty"`
SpotAssetCtxs []SpotAssetCtx `json:"spotAssetCtxs,omitempty"`
PerpsAtOpenInterestCap []string `json:"perpsAtOpenInterestCap,omitempty"`
}
//easyjson:skip
WebData2Meta struct {
Universe []WebData2AssetInfo `json:"universe,omitempty"`
MarginTables []Tuple2[int, WebData2MarginTable] `json:"marginTables,omitempty"`
}
WebData2AssetInfo struct {
SzDecimals int `json:"szDecimals,omitempty"`
Name string `json:"name,omitempty"`
MaxLeverage int `json:"maxLeverage,omitempty"`
MarginTableID int `json:"marginTableId,omitempty"`
IsDelisted bool `json:"isDelisted,omitempty"`
OnlyIsolated bool `json:"onlyIsolated,omitempty"`
}
WebData2MarginTable struct {
Description string `json:"description,omitempty"`
MarginTiers []WebData2MarginTier `json:"marginTiers,omitempty"`
}
WebData2MarginTier struct {
LowerBound string `json:"lowerBound,omitempty"`
MaxLeverage int `json:"maxLeverage,omitempty"`
}
ClearinghouseState struct {
MarginSummary *MarginSummary `json:"marginSummary,omitempty"`
CrossMarginSummary *MarginSummary `json:"crossMarginSummary,omitempty"`
CrossMaintenanceMarginUsed string `json:"crossMaintenanceMarginUsed,omitempty"`
Withdrawable string `json:"withdrawable,omitempty"`
AssetPositions []AssetPosition `json:"assetPositions,omitempty"`
Time int64 `json:"time,omitempty"`
}
ClearinghouseStateMessage struct {
Dex string `json:"dex,omitempty"`
User string `json:"user,omitempty"`
ClearinghouseState ClearinghouseState `json:"clearinghouseState"`
}
SpotState struct {
Balances []SpotBalance `json:"balances,omitempty"`
}
OpenOrders struct {
Dex string `json:"dex"`
User string `json:"user"`
Orders []WsBasicOrder `json:"orders"`
}
WsOrder struct {
Order WsBasicOrder `json:"order"`
Status OrderStatusValue `json:"status"`
StatusTimestamp int64 `json:"statusTimestamp"`
}
WsBasicOrder struct {
Coin string `json:"coin"`
Side string `json:"side"`
LimitPx string `json:"limitPx"`
Sz string `json:"sz"`
Oid int64 `json:"oid"`
Timestamp int64 `json:"timestamp"`
OrigSz string `json:"origSz"`
Cloid *string `json:"cloid"`
}
WsOrderFills struct {
IsSnapshot bool `json:"isSnapshot"`
User string `json:"user"`
Fills []WsOrderFill `json:"fills"`
}
WsOrderFill struct {
Coin string `json:"coin"`
Px string `json:"px"` // price
Sz string `json:"sz"` // size
Side string `json:"side"`
Time int64 `json:"time"`
StartPosition string `json:"startPosition"`
Dir string `json:"dir"` // used for frontend display
ClosedPnl string `json:"closedPnl"`
Hash string `json:"hash"` // L1 transaction hash
Oid int64 `json:"oid"` // order id
Crossed bool `json:"crossed"` // whether order crossed the spread (was taker)
Fee string `json:"fee"` // negative means rebate
Tid int64 `json:"tid"` // unique trade id
Liquidation *FillLiquidation `json:"liquidation,omitempty"`
FeeToken string `json:"feeToken"` // the token the fee was paid in
BuilderFee *string `json:"builderFee,omitempty"` // amount paid to builder, also included in fee
}
FillLiquidation struct {
LiquidatedUser *string `json:"liquidatedUser,omitempty"`
MarkPx string `json:"markPx"`
Method string `json:"method"`
}
L2Book struct {
Coin string `json:"coin"`
Levels [][]Level `json:"levels"`
Time int64 `json:"time"`
}
Bbo struct {
Coin string `json:"coin"`
Time int64 `json:"time"`
Bbo []Level `json:"bbo"`
}
Level struct {
N int `json:"n"`
Px float64 `json:"px,string"`
Sz float64 `json:"sz,string"`
}
Candle struct {
TimeOpen int64 `json:"t"` // open millis
TimeClose int64 `json:"T"` // close millis
Interval string `json:"i"` // interval
TradesCount int `json:"n"` // number of trades
Open string `json:"o"` // open price
High string `json:"h"` // high price
Low string `json:"l"` // low price
Close string `json:"c"` // close price
Symbol string `json:"s"` // coin
Volume string `json:"v"` // volume (base unit)
}
//easyjson:skip
TwapStates struct {
Dex string `json:"dex"`
User string `json:"user"`
States []Tuple2[int, TwapState] `json:"states"`
}
TwapState struct {
Coin string `json:"coin"`
User string `json:"user"`
Side string `json:"side"`
Sz float64 `json:"sz,string"`
ExecutedSz float64 `json:"executedSz,string"`
ExecutedNtl float64 `json:"executedNtl,string"`
Minutes int `json:"minutes"`
ReduceOnly bool `json:"reduceOnly"`
Randomize bool `json:"randomize"`
Timestamp int64 `json:"timestamp"`
}
//easyjson:skip
WebData3 struct {
UserState WebData3UserState `json:"userState"`
PerpDexStates []PerpDexState `json:"perpDexStates"`
}
WebData3UserState struct {
AgentAddress *string `json:"agentAddress,omitempty"`
AgentValidUntil *int64 `json:"agentValidUntil,omitempty"`
ServerTime int64 `json:"serverTime"`
CumLedger float64 `json:"cumLedger,string"`
IsVault bool `json:"isVault"`
User string `json:"user"`
OptOutOfSpotDusting *bool `json:"optOutOfSpotDusting,omitempty"`
DexAbstractionEnabled *bool `json:"dexAbstractionEnabled,omitempty"`
}
PerpDexState struct {
TotalVaultEquity float64 `json:"totalVaultEquity,string"`
PerpsAtOpenInterestCap *[]string `json:"perpsAtOpenInterestCap,omitempty"`
LeadingVaults *[]LeadingVault `json:"leadingVaults,omitempty"`
}
LeadingVault struct {
Address string `json:"address"`
Name string `json:"name"`
}
)
var (
candleNoop = Candle{}
)