-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
types.go
390 lines (351 loc) · 12.6 KB
/
types.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
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
package private
import (
"log"
"net/http"
"net/url"
"strconv"
"time"
"github.com/go-numb/go-dydx/types"
)
type Private struct {
NetworkId int
Host string
StarkPrivateKey string
DefaultAddress string
ApiKeyCredentials *types.ApiKeyCredentials
HttpClient *http.Client
RateLimit *types.RateLimit
Logger *log.Logger
}
type ApiBaseOrder struct {
Signature string `json:"signature"`
Expiration string `json:"expiration"`
}
type ApiOrder struct {
ApiBaseOrder
Market string `json:"market"`
Side string `json:"side"`
Type string `json:"type"`
Size string `json:"size"`
Price string `json:"price"`
ClientId string `json:"clientId"`
TimeInForce string `json:"timeInForce"`
LimitFee string `json:"limitFee"`
CancelId string `json:"cancelId,omitempty"`
TriggerPrice string `json:"triggerPrice,omitempty"`
TrailingPercent string `json:"trailingPercent,omitempty"`
PostOnly bool `json:"postOnly"`
}
type UsersResponse struct {
User User `json:"user"`
}
type User struct {
PublicID string `json:"publicId"`
EthereumAddress string `json:"ethereumAddress"`
IsRegistered bool `json:"isRegistered"`
Email string `json:"email"`
Username string `json:"username"`
UserData struct {
WalletType string `json:"walletType"`
Preferences struct {
SaveOrderAmount bool `json:"saveOrderAmount"`
UserTradeOptions struct {
Limit struct {
PostOnlyChecked bool `json:"postOnlyChecked"`
GoodTilTimeInput string `json:"goodTilTimeInput"`
GoodTilTimeTimescale string `json:"goodTilTimeTimescale"`
SelectedTimeInForceOption string `json:"selectedTimeInForceOption"`
} `json:"LIMIT"`
Market struct {
PostOnlyChecked bool `json:"postOnlyChecked"`
GoodTilTimeInput string `json:"goodTilTimeInput"`
GoodTilTimeTimescale string `json:"goodTilTimeTimescale"`
SelectedTimeInForceOption string `json:"selectedTimeInForceOption"`
} `json:"MARKET"`
StopLimit struct {
PostOnlyChecked bool `json:"postOnlyChecked"`
GoodTilTimeInput string `json:"goodTilTimeInput"`
GoodTilTimeTimescale string `json:"goodTilTimeTimescale"`
SelectedTimeInForceOption string `json:"selectedTimeInForceOption"`
} `json:"STOP_LIMIT"`
TakeProfit struct {
PostOnlyChecked bool `json:"postOnlyChecked"`
GoodTilTimeInput string `json:"goodTilTimeInput"`
GoodTilTimeTimescale string `json:"goodTilTimeTimescale"`
SelectedTimeInForceOption string `json:"selectedTimeInForceOption"`
} `json:"TAKE_PROFIT"`
LastPlacedTradeType string `json:"lastPlacedTradeType"`
} `json:"userTradeOptions"`
PopUpNotifications bool `json:"popUpNotifications"`
OrderbookAnimations bool `json:"orderbookAnimations"`
OneTimeNotifications []string `json:"oneTimeNotifications"`
LeaguesCurrentStartDate time.Time `json:"leaguesCurrentStartDate"`
} `json:"preferences"`
Notifications struct {
Trade struct {
Email bool `json:"email"`
} `json:"trade"`
Deposit struct {
Email bool `json:"email"`
} `json:"deposit"`
Transfer struct {
Email bool `json:"email"`
} `json:"transfer"`
Marketing struct {
Email bool `json:"email"`
} `json:"marketing"`
Withdrawal struct {
Email bool `json:"email"`
} `json:"withdrawal"`
Liquidation struct {
Email bool `json:"email"`
} `json:"liquidation"`
FundingPayment struct {
Email bool `json:"email"`
} `json:"funding_payment"`
} `json:"notifications"`
StarredMarkets []interface{} `json:"starredMarkets"`
} `json:"userData"`
MakerFeeRate string `json:"makerFeeRate"`
TakerFeeRate string `json:"takerFeeRate"`
MakerVolume30D string `json:"makerVolume30D"`
TakerVolume30D string `json:"takerVolume30D"`
Fees30D string `json:"fees30D"`
ReferredByAffiliateLink string `json:"referredByAffiliateLink"`
IsSharingUsername bool `json:"isSharingUsername"`
IsSharingAddress bool `json:"isSharingAddress"`
DydxTokenBalance string `json:"dydxTokenBalance"`
StakedDydxTokenBalance string `json:"stakedDydxTokenBalance"`
ActiveStakedDydxTokenBalance string `json:"activeStakedDydxTokenBalance"`
IsEmailVerified bool `json:"isEmailVerified"`
Country interface{} `json:"country"`
HedgiesHeld []interface{} `json:"hedgiesHeld"`
}
type AccountResponse struct {
Account Account `json:"account"`
}
type Account struct {
PositionId int64 `json:"positionId,string"`
ID string `json:"id"`
StarkKey string `json:"starkKey"`
Equity string `json:"equity"`
FreeCollateral string `json:"freeCollateral"`
QuoteBalance string `json:"quoteBalance"`
PendingDeposits string `json:"pendingDeposits"`
PendingWithdrawals string `json:"pendingWithdrawals"`
AccountNumber string `json:"accountNumber"`
OpenPositions map[string]Position `json:"openPositions"`
CreatedAt time.Time `json:"createdAt"`
}
type PositionResponse struct {
Positions []Position `json:"positions"`
}
type Position struct {
Market string `json:"market"`
Status string `json:"status"`
Side string `json:"side"`
Size string `json:"size"`
MaxSize string `json:"maxSize"`
EntryPrice string `json:"entryPrice"`
ExitPrice interface{} `json:"exitPrice"`
UnrealizedPnl string `json:"unrealizedPnl"`
RealizedPnl string `json:"realizedPnl"`
CreatedAt time.Time `json:"createdAt"`
ClosedAt interface{} `json:"closedAt"`
NetFunding string `json:"netFunding"`
SumOpen string `json:"sumOpen"`
SumClose string `json:"sumClose"`
}
type OrderResponse struct {
Order Order `json:"order"`
}
type CancelOrderResponse struct {
CancelOrder Order `json:"cancelOrder"`
}
type CancelOrdersResponse struct {
CancelOrders Order `json:"cancelOrder"`
}
type Order struct {
ID string `json:"id"`
ClientID string `json:"clientId"`
AccountID string `json:"accountId"`
Market string `json:"market"`
Side string `json:"side"`
Price string `json:"price"`
TriggerPrice string `json:"triggerPrice"`
TrailingPercent string `json:"trailingPercent"`
Size string `json:"size"`
RemainingSize string `json:"remainingSize"`
Type string `json:"type"`
UnfillableAt string `json:"unfillableAt"`
Status string `json:"status"`
TimeInForce string `json:"timeInForce"`
CancelReason string `json:"cancelReason"`
PostOnly bool `json:"postOnly"`
CreatedAt time.Time `json:"createdAt"`
ExpiresAt time.Time `json:"expiresAt"`
}
type OrderListResponse struct {
Orders []Order `json:"orders"`
}
type OrderQueryParam struct {
Limit int `json:"limit"`
Market string `json:"market"`
Status string `json:"status"`
Type string `json:"type"`
Side string `json:"side"`
CreatedBeforeOrAt string `json:"createdAt"`
ReturnLatestOrders string `json:"returnLatestOrders"`
}
type WithdrawResponse struct {
Withdrawal []Withdrawal `json:"withdrawal"`
}
type Withdrawal struct {
ID string `json:"id"`
Type string `json:"type"`
DebitAsset string `json:"debitAsset"`
CreditAsset string `json:"creditAsset"`
DebitAmount string `json:"debitAmount"`
CreditAmount string `json:"creditAmount"`
TransactionHash string `json:"transactionHash"`
Status string `json:"status"`
ClientID string `json:"clientId"`
FromAddress string `json:"fromAddress"`
ToAddress interface{} `json:"toAddress"`
ConfirmedAt interface{} `json:"confirmedAt"`
CreatedAt time.Time `json:"createdAt"`
}
type WithdrawalParam struct {
ClientID string `json:"clientId"`
ToAddress string `json:"toAddress"`
CreditAsset string `json:"creditAsset"`
CreditAmount string `json:"creditAmount"`
DebitAmount string `json:"debitAmount"`
LpPositionId string `json:"lpPositionId"`
Expiration string `json:"expiration"`
Signature string `json:"signature"`
}
type FillsResponse struct {
Fills []Fill `json:"fills"`
}
type Fill struct {
ID string `json:"id"`
Side string `json:"side"`
Liquidity string `json:"liquidity"`
Type string `json:"type"`
Market string `json:"market"`
OrderID string `json:"orderId"`
Price string `json:"price"`
Size string `json:"size"`
Fee string `json:"fee"`
CreatedAt time.Time `json:"createdAt"`
}
type FillsParam struct {
Market string `json:"market,omitempty"`
OrderId string `json:"order_id,omitempty"`
Limit string `json:"limit,omitempty"`
CreatedBeforeOrAt string `json:"createdBeforeOrAt,omitempty"`
}
type FundingPaymentsResponse struct {
FundingPayments []FundingPayment `json:"fundingPayments"`
}
type FundingPayment struct {
Market string `json:"market"`
Payment string `json:"payment"`
Rate string `json:"rate"`
PositionSize string `json:"positionSize"`
Price string `json:"price"`
EffectiveAt time.Time `json:"effectiveAt"`
}
type FundingPaymentsParam struct {
Market string `json:"market,omitempty"`
Limit string `json:"limit,omitempty"`
EffectiveBeforeOrAt string `json:"effectiveBeforeOrAt,omitempty"`
}
type HistoricalPnLResponse struct {
HistoricalPnLs []HistoricalPnL `json:"historicalPnl"`
}
type HistoricalPnL struct {
AccountID string `json:"accountId"`
Equity string `json:"equity"`
TotalPnl string `json:"totalPnl"`
NetTransfers string `json:"netTransfers"`
CreatedAt time.Time `json:"createdAt"`
}
type HistoricalPnLParam struct {
EffectiveBeforeOrAt string `json:"effectiveBeforeOrAt,omitempty"`
EffectiveAtOrAfter string `json:"effectiveAtOrAfter,omitempty"`
}
type TradingRewardsResponse TradingReward
type TradingReward struct {
Epoch int `json:"epoch"`
EpochStart time.Time `json:"epochStart"`
EpochEnd time.Time `json:"epochEnd"`
Fees struct {
FeesPaid string `json:"feesPaid"`
TotalFeesPaid string `json:"totalFeesPaid"`
} `json:"fees"`
OpenInterest struct {
AverageOpenInterest string `json:"averageOpenInterest"`
TotalAverageOpenInterest string `json:"totalAverageOpenInterest"`
} `json:"openInterest"`
StakedDYDX struct {
AverageStakedDYDX string `json:"averageStakedDYDX"`
AverageStakedDYDXWithFloor string `json:"averageStakedDYDXWithFloor"`
TotalAverageStakedDYDX string `json:"totalAverageStakedDYDX"`
} `json:"stakedDYDX"`
Weight struct {
Weight string `json:"weight"`
TotalWeight string `json:"totalWeight"`
} `json:"weight"`
TotalRewards string `json:"totalRewards"`
EstimatedRewards string `json:"estimatedRewards"`
}
type TradingRewardsParam struct {
Epoch int `json:"epoch,omitempty"`
}
type TransfersResponse struct {
Transfers []Transfer `json:"transfers"`
}
type Transfer struct {
Type string `json:"type"`
ID string `json:"id"`
ClientID string `json:"clientId"`
CreditAmount string `json:"creditAmount"`
CreditAsset string `json:"creditAsset"`
DebitAmount string `json:"debitAmount"`
DebitAsset string `json:"debitAsset"`
FromAddress string `json:"fromAddress"`
Status string `json:"status"`
ToAddress string `json:"toAddress"`
TransactionHash string `json:"transactionHash"`
ConfirmedAt time.Time `json:"confirmedAt"`
CreatedAt time.Time `json:"createdAt"`
}
type TransfersParam struct {
}
func (o OrderQueryParam) ToParams() url.Values {
params := url.Values{}
if o.Market != "" {
params.Add("market", o.Market)
}
if o.Status != "" {
params.Add("status", o.Status)
}
if o.Side != "" {
params.Add("side", o.Side)
}
if o.Type != "" {
params.Add("type", o.Type)
}
if o.Limit != 0 {
params.Add("limit", strconv.Itoa(o.Limit))
}
if o.CreatedBeforeOrAt != "" {
params.Add("createdBeforeOrAt", o.CreatedBeforeOrAt)
}
if o.ReturnLatestOrders != "" {
params.Add("returnLatestOrders", o.ReturnLatestOrders)
}
return params
}