forked from thrasher-corp/gocryptotrader
/
bitfinex_types.go
407 lines (364 loc) · 12.1 KB
/
bitfinex_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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
package bitfinex
// Ticker holds basic ticker information from the exchange
type Ticker struct {
Mid float64 `json:"mid,string"`
Bid float64 `json:"bid,string"`
Ask float64 `json:"ask,string"`
Last float64 `json:"last_price,string"`
Low float64 `json:"low,string"`
High float64 `json:"high,string"`
Volume float64 `json:"volume,string"`
Timestamp string `json:"timestamp"`
}
// Stat holds individual statistics from exchange
type Stat struct {
Period int64 `json:"period"`
Volume float64 `json:"volume,string"`
}
// FundingBook holds current the full margin funding book
type FundingBook struct {
Bids []Book `json:"bids"`
Asks []Book `json:"asks"`
}
// Orderbook holds orderbook information from bid and ask sides
type Orderbook struct {
Bids []Book
Asks []Book
}
// TradeStructure holds executed trade information
type TradeStructure struct {
Timestamp int64 `json:"timestamp"`
Tid int64 `json:"tid"`
Price float64 `json:"price,string"`
Amount float64 `json:"amount,string"`
Exchange string `json:"exchange"`
Type string `json:"sell"`
}
// Lendbook holds most recent funding data for a relevent currency
type Lendbook struct {
Bids []Book `json:"bids"`
Asks []Book `json:"asks"`
}
// Book is a generalised sub-type to hold book information
type Book struct {
Price float64 `json:"price,string"`
Rate float64 `json:"rate,string"`
Amount float64 `json:"amount,string"`
Period int `json:"period"`
Timestamp string `json:"timestamp"`
FlashReturnRate string `json:"frr"`
}
// Lends holds the lent information by currency
type Lends struct {
Rate float64 `json:"rate,string"`
AmountLent float64 `json:"amount_lent,string"`
AmountUsed float64 `json:"amount_used,string"`
Timestamp int64 `json:"timestamp"`
}
// SymbolDetails holds currency pair information
type SymbolDetails struct {
Pair string `json:"pair"`
PricePrecision int `json:"price_precision"`
InitialMargin float64 `json:"initial_margin,string"`
MinimumMargin float64 `json:"minimum_margin,string"`
MaximumOrderSize float64 `json:"maximum_order_size,string"`
MinimumOrderSize float64 `json:"minimum_order_size,string"`
Expiration string `json:"expiration"`
}
// AccountInfo general account information with fees
type AccountInfo struct {
MakerFees string `json:"maker_fees"`
TakerFees string `json:"taker_fees"`
Fees []struct {
Pairs string `json:"pairs"`
MakerFees string `json:"maker_fees"`
TakerFees string `json:"taker_fees"`
} `json:"fees"`
}
// AccountFees stores withdrawel account fee data from Bitfinex
type AccountFees struct {
Withdraw struct {
BTC float64 `json:"BTC,string"`
LTC float64 `json:"LTC,string"`
ETH float64 `json:"ETH,string"`
ETC float64 `json:"ETC,string"`
ZEC float64 `json:"ZEC,string"`
XMR float64 `json:"XMR,string"`
DSH float64 `json:"DSH,string"`
XRP float64 `json:"XRP,string"`
IOT float64 `json:"IOT"`
EOS float64 `json:"EOS,string"`
SAN float64 `json:"SAN,string"`
OMG float64 `json:"OMG,string"`
BCH float64 `json:"BCH,string"`
} `json:"withdraw"`
}
// AccountSummary holds account summary data
type AccountSummary struct {
TradeVolumePer30D []Currency `json:"trade_vol_30d"`
FundingProfit30D []Currency `json:"funding_profit_30d"`
MakerFee float64 `json:"maker_fee"`
TakerFee float64 `json:"taker_fee"`
}
// Currency is a sub-type for AccountSummary data
type Currency struct {
Currency string `json:"curr"`
Volume float64 `json:"vol,string"`
Amount float64 `json:"amount,string"`
}
// DepositResponse holds deposit address information
type DepositResponse struct {
Result string `json:"string"`
Method string `json:"method"`
Currency string `json:"currency"`
Address string `json:"address"`
}
// KeyPermissions holds the key permissions for the API key set
type KeyPermissions struct {
Account Permission `json:"account"`
History Permission `json:"history"`
Orders Permission `json:"orders"`
Positions Permission `json:"positions"`
Funding Permission `json:"funding"`
Wallets Permission `json:"wallets"`
Withdraw Permission `json:"withdraw"`
}
// Permission sub-type for KeyPermissions
type Permission struct {
Read bool `json:"read"`
Write bool `json:"write"`
}
// MarginInfo holds metadata for margin information from bitfinex
type MarginInfo struct {
Info MarginData
Message string `json:"message"`
}
// MarginData holds wallet information for margin trading
type MarginData struct {
MarginBalance float64 `json:"margin_balance,string"`
TradableBalance float64 `json:"tradable_balance,string"`
UnrealizedPL int64 `json:"unrealized_pl"`
UnrealizedSwap int64 `json:"unrealized_swap"`
NetValue float64 `json:"net_value,string"`
RequiredMargin int64 `json:"required_margin"`
Leverage float64 `json:"leverage,string"`
MarginRequirement float64 `json:"margin_requirement,string"`
MarginLimits []MarginLimits `json:"margin_limits"`
}
// MarginLimits holds limit data per pair
type MarginLimits struct {
OnPair string `json:"on_pair"`
InitialMargin float64 `json:"initial_margin,string"`
MarginRequirement float64 `json:"margin_requirement,string"`
TradableBalance float64 `json:"tradable_balance,string"`
}
// Balance holds current balance data
type Balance struct {
Type string `json:"type"`
Currency string `json:"currency"`
Amount float64 `json:"amount,string"`
Available float64 `json:"available,string"`
}
// WalletTransfer holds status of wallet to wallet content transfer on exchange
type WalletTransfer struct {
Status string `json:"status"`
Message string `json:"message"`
}
// Withdrawal holds withdrawel status information
type Withdrawal struct {
Status string `json:"status"`
Message string `json:"message"`
WithdrawalID int64 `json:"withdrawal_id,string"`
}
// Order holds order information when an order is in the market
type Order struct {
ID int64 `json:"id"`
Symbol string `json:"symbol"`
Exchange string `json:"exchange"`
Price float64 `json:"price,string"`
AverageExecutionPrice float64 `json:"avg_execution_price,string"`
Side string `json:"side"`
Type string `json:"type"`
Timestamp string `json:"timestamp"`
IsLive bool `json:"is_live"`
IsCancelled bool `json:"is_cancelled"`
IsHidden bool `json:"is_hidden"`
WasForced bool `json:"was_forced"`
OriginalAmount float64 `json:"original_amount,string"`
RemainingAmount float64 `json:"remaining_amount,string"`
ExecutedAmount float64 `json:"executed_amount,string"`
OrderID int64 `json:"order_id"`
}
// OrderMultiResponse holds order information on the executed orders
type OrderMultiResponse struct {
Orders []Order `json:"order_ids"`
Status string `json:"status"`
}
// PlaceOrder is used for order placement
type PlaceOrder struct {
Symbol string `json:"symbol"`
Amount float64 `json:"amount,string"`
Price float64 `json:"price,string"`
Exchange string `json:"exchange"`
Side string `json:"side"`
Type string `json:"type"`
}
// GenericResponse holds the result for a generic response
type GenericResponse struct {
Result string `json:"result"`
}
// Position holds position information
type Position struct {
ID int64 `json:"id"`
Symbol string `json:"string"`
Status string `json:"active"`
Base float64 `json:"base,string"`
Amount float64 `json:"amount,string"`
Timestamp string `json:"timestamp"`
Swap float64 `json:"swap,string"`
PL float64 `json:"pl,string"`
}
// BalanceHistory holds balance history information
type BalanceHistory struct {
Currency string `json:"currency"`
Amount float64 `json:"amount,string"`
Balance float64 `json:"balance,string"`
Description string `json:"description"`
Timestamp string `json:"timestamp"`
}
// MovementHistory holds deposit and withdrawal history data
type MovementHistory struct {
ID int64 `json:"id"`
TxID int64 `json:"txid"`
Currency string `json:"currency"`
Method string `json:"method"`
Type string `json:"withdrawal"`
Amount float64 `json:"amount,string"`
Description string `json:"description"`
Address string `json:"address"`
Status string `json:"status"`
Timestamp string `json:"timestamp"`
TimestampCreated string `json:"timestamp_created"`
Fee float64 `json:"fee"`
}
// TradeHistory holds trade history data
type TradeHistory struct {
Price float64 `json:"price,string"`
Amount float64 `json:"amount,string"`
Timestamp string `json:"timestamp"`
Exchange string `json:"exchange"`
Type string `json:"type"`
FeeCurrency string `json:"fee_currency"`
FeeAmount float64 `json:"fee_amount,string"`
TID int64 `json:"tid"`
OrderID int64 `json:"order_id"`
}
// Offer holds offer information
type Offer struct {
ID int64 `json:"id"`
Currency string `json:"currency"`
Rate float64 `json:"rate,string"`
Period int64 `json:"period"`
Direction string `json:"direction"`
Timestamp string `json:"timestamp"`
Type string `json:"type"`
IsLive bool `json:"is_live"`
IsCancelled bool `json:"is_cancelled"`
OriginalAmount float64 `json:"original_amount,string"`
RemainingAmount float64 `json:"remaining_amount,string"`
ExecutedAmount float64 `json:"executed_amount,string"`
}
// MarginFunds holds active funding information used in a margin positon
type MarginFunds struct {
ID int64 `json:"id"`
PositionID int64 `json:"position_id"`
Currency string `json:"currency"`
Rate float64 `json:"rate,string"`
Period int `json:"period"`
Amount float64 `json:"amount,string"`
Timestamp string `json:"timestamp"`
AutoClose bool `json:"auto_close"`
}
// MarginTotalTakenFunds holds position funding including sum of active backing
// as total swaps
type MarginTotalTakenFunds struct {
PositionPair string `json:"position_pair"`
TotalSwaps float64 `json:"total_swaps,string"`
}
// Fee holds fee data for a specified currency
type Fee struct {
Currency string
TakerFees float64
MakerFees float64
}
// WebsocketChanInfo holds websocket channel information
type WebsocketChanInfo struct {
Channel string
Pair string
}
// WebsocketBook holds booking information
type WebsocketBook struct {
Price float64
Count int
Amount float64
}
// WebsocketTrade holds trade information
type WebsocketTrade struct {
ID int64
Timestamp int64
Price float64
Amount float64
}
// WebsocketTicker holds ticker information
type WebsocketTicker struct {
Bid float64
BidSize float64
Ask float64
AskSize float64
DailyChange float64
DialyChangePerc float64
LastPrice float64
Volume float64
}
// WebsocketPosition holds position information
type WebsocketPosition struct {
Pair string
Status string
Amount float64
Price float64
MarginFunding float64
MarginFundingType int
}
// WebsocketWallet holds wallet information
type WebsocketWallet struct {
Name string
Currency string
Balance float64
UnsettledInterest float64
}
// WebsocketOrder holds order data
type WebsocketOrder struct {
OrderID int64
Pair string
Amount float64
OrigAmount float64
OrderType string
Status string
Price float64
PriceAvg float64
Timestamp string
Notify int
}
// WebsocketTradeExecuted holds executed trade data
type WebsocketTradeExecuted struct {
TradeID int64
Pair string
Timestamp int64
OrderID int64
AmountExecuted float64
PriceExecuted float64
}
// ErrorCapture is a simple type for returned errors from Bitfinex
type ErrorCapture struct {
Message string `json:"message"`
}