forked from beldur/kraken-go-api-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
790 lines (738 loc) · 21.4 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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
package krakenapi
import (
"encoding/json"
"fmt"
"math/big"
"reflect"
"strconv"
"time"
)
// trade pairs constants
const (
ADACAD = "ADACAD"
ADAETH = "ADAETH"
ADAEUR = "ADAEUR"
ADAUSD = "ADAUSD"
ADAXBT = "ADAXBT"
AAVEUSD = "AAVEUSD"
BCHEUR = "BCHEUR"
BCHUSD = "BCHUSD"
BCHXBT = "BCHXBT"
DASHEUR = "DASHEUR"
DASHUSD = "DASHUSD"
DASHXBT = "DASHXBT"
EOSETH = "EOSETH"
EOSEUR = "EOSEUR"
EOSUSD = "EOSUSD"
EOSXBT = "EOSXBT"
GNOETH = "GNOETH"
GNOEUR = "GNOEUR"
GNOUSD = "GNOUSD"
GNOXBT = "GNOXBT"
LINKUSD = "LINKUSD"
LINKXBT = "LINKXBT"
QTUMCAD = "QTUMCAD"
QTUMETH = "QTUMETH"
QTUMEUR = "QTUMEUR"
QTUMUSD = "QTUMUSD"
QTUMXBT = "QTUMXBT"
USDTZUSD = "USDTZUSD"
XBTUSDT = "XBTUSDT"
XETCXETH = "XETCXETH"
XETCXXBT = "XETCXXBT"
XETCZEUR = "XETCZEUR"
XETCZUSD = "XETCZUSD"
XETHXXBT = "XETHXXBT"
XETHZCAD = "XETHZCAD"
XETHZEUR = "XETHZEUR"
XETHZGBP = "XETHZGBP"
XETHZJPY = "XETHZJPY"
XETHZUSD = "XETHZUSD"
XICNXETH = "XICNXETH"
XICNXXBT = "XICNXXBT"
XLTCXXBT = "XLTCXXBT"
XLTCZEUR = "XLTCZEUR"
XLTCZUSD = "XLTCZUSD"
XMLNXETH = "XMLNXETH"
XMLNXXBT = "XMLNXXBT"
XREPXETH = "XREPXETH"
XREPXXBT = "XREPXXBT"
XREPZEUR = "XREPZEUR"
XREPZUSD = "XREPZUSD"
XTZCAD = "XTZCAD"
XTZETH = "XTZETH"
XTZEUR = "XTZEUR"
XTZUSD = "XTZUSD"
XTZXBT = "XTZXBT"
XXBTZCAD = "XXBTZCAD"
XXBTZEUR = "XXBTZEUR"
XXBTZGBP = "XXBTZGBP"
XXBTZJPY = "XXBTZJPY"
XXBTZUSD = "XXBTZUSD"
XXDGXXBT = "XXDGXXBT"
XXLMXXBT = "XXLMXXBT"
XXLMZEUR = "XXLMZEUR"
XXLMZUSD = "XXLMZUSD"
XXMRXXBT = "XXMRXXBT"
XXMRZEUR = "XXMRZEUR"
XXMRZUSD = "XXMRZUSD"
XXRPXXBT = "XXRPXXBT"
XXRPZCAD = "XXRPZCAD"
XXRPZEUR = "XXRPZEUR"
XXRPZJPY = "XXRPZJPY"
XXRPZUSD = "XXRPZUSD"
XZECXXBT = "XZECXXBT"
XZECZEUR = "XZECZEUR"
XZECZUSD = "XZECZUSD"
)
// actions constants
const (
BUY = "b"
SELL = "s"
MARKET = "m"
LIMIT = "l"
)
// KrakenResponse wraps the Kraken API JSON response
type KrakenResponse struct {
Error []string `json:"error"`
Result json.RawMessage `json:"result"`
}
// TimeResponse represents the server's time
type TimeResponse struct {
// Unix timestamp
Unixtime int64
// RFC 1123 time format
Rfc1123 string
}
// AssetPairsResponse includes asset pair informations
type AssetPairsResponse struct {
ADACAD AssetPairInfo
AAVEUSD AssetPairInfo
ADAETH AssetPairInfo
ADAEUR AssetPairInfo
ADAUSD AssetPairInfo
ADAXBT AssetPairInfo
BCHEUR AssetPairInfo
BCHUSD AssetPairInfo
BCHXBT AssetPairInfo
DASHEUR AssetPairInfo
DASHUSD AssetPairInfo
DASHXBT AssetPairInfo
EOSETH AssetPairInfo
EOSEUR AssetPairInfo
EOSUSD AssetPairInfo
EOSXBT AssetPairInfo
GNOETH AssetPairInfo
GNOEUR AssetPairInfo
GNOUSD AssetPairInfo
GNOXBT AssetPairInfo
LINKUSD AssetPairInfo
LINKXBT AssetPairInfo
QTUMCAD AssetPairInfo
QTUMETH AssetPairInfo
QTUMEUR AssetPairInfo
QTUMUSD AssetPairInfo
QTUMXBT AssetPairInfo
USDTZUSD AssetPairInfo
XETCXETH AssetPairInfo
XETCXXBT AssetPairInfo
XETCZEUR AssetPairInfo
XETCZUSD AssetPairInfo
XETHXXBT AssetPairInfo
XETHZCAD AssetPairInfo
XETHZEUR AssetPairInfo
XETHZGBP AssetPairInfo
XETHZJPY AssetPairInfo
XETHZUSD AssetPairInfo
XICNXETH AssetPairInfo
XICNXXBT AssetPairInfo
XLTCXXBT AssetPairInfo
XLTCZEUR AssetPairInfo
XLTCZUSD AssetPairInfo
XMLNXETH AssetPairInfo
XMLNXXBT AssetPairInfo
XREPXETH AssetPairInfo
XREPXXBT AssetPairInfo
XREPZEUR AssetPairInfo
XREPZUSD AssetPairInfo
XTZCAD AssetPairInfo
XTZETH AssetPairInfo
XTZEUR AssetPairInfo
XTZUSD AssetPairInfo
XTZXBT AssetPairInfo
XXBTZCAD AssetPairInfo
XXBTZEUR AssetPairInfo
XXBTZGBP AssetPairInfo
XXBTZJPY AssetPairInfo
XXBTZUSD AssetPairInfo
XXDGXXBT AssetPairInfo
XXLMXXBT AssetPairInfo
XXLMZEUR AssetPairInfo
XXLMZUSD AssetPairInfo
XXMRXXBT AssetPairInfo
XXMRZEUR AssetPairInfo
XXMRZUSD AssetPairInfo
XXRPXXBT AssetPairInfo
XXRPZCAD AssetPairInfo
XXRPZEUR AssetPairInfo
XXRPZJPY AssetPairInfo
XXRPZUSD AssetPairInfo
XZECXXBT AssetPairInfo
XZECZEUR AssetPairInfo
XZECZUSD AssetPairInfo
}
// AssetPairInfo represents asset pair information
type AssetPairInfo struct {
// Alternate pair name
Altname string `json:"altname"`
// Asset class of base component
AssetClassBase string `json:"aclass_base"`
// Asset id of base component
Base string `json:"base"`
// Asset class of quote component
AssetClassQuote string `json:"aclass_quote"`
// Asset id of quote component
Quote string `json:"quote"`
// Volume lot size
Lot string `json:"lot"`
// Scaling decimal places for pair
PairDecimals int `json:"pair_decimals"`
// Scaling decimal places for volume
LotDecimals int `json:"lot_decimals"`
// Amount to multiply lot volume by to get currency volume
LotMultiplier int `json:"lot_multiplier"`
// Array of leverage amounts available when buying
LeverageBuy []float64 `json:"leverage_buy"`
// Array of leverage amounts available when selling
LeverageSell []float64 `json:"leverage_sell"`
// Fee schedule array in [volume, percent fee] tuples
Fees [][]float64 `json:"fees"`
// // Maker fee schedule array in [volume, percent fee] tuples (if on maker/taker)
FeesMaker [][]float64 `json:"fees_maker"`
// // Volume discount currency
FeeVolumeCurrency string `json:"fee_volume_currency"`
// Margin call level
MarginCall int `json:"margin_call"`
// Stop-out/Liquidation margin level
MarginStop int `json:"margin_stop"`
// Order minimum
OrderMin float64 `json:"ordermin"`
}
// AssetsResponse includes asset informations
type AssetsResponse struct {
ADA AssetInfo
AAVE AssetInfo
BCH AssetInfo
DASH AssetInfo
EOS AssetInfo
GNO AssetInfo
KFEE AssetInfo
LINK AssetInfo
QTUM AssetInfo
USDT AssetInfo
XDAO AssetInfo
XETC AssetInfo
XETH AssetInfo
XICN AssetInfo
XLTC AssetInfo
XMLN AssetInfo
XNMC AssetInfo
XREP AssetInfo
XXBT AssetInfo
XXDG AssetInfo
XXLM AssetInfo
XXMR AssetInfo
XXRP AssetInfo
XTZ AssetInfo
XXVN AssetInfo
XZEC AssetInfo
ZCAD AssetInfo
ZEUR AssetInfo
ZGBP AssetInfo
ZJPY AssetInfo
ZKRW AssetInfo
ZUSD AssetInfo
}
// AssetInfo represents an asset information
type AssetInfo struct {
// Alternate name
Altname string
// Asset class
AssetClass string `json:"aclass"`
// Scaling decimal places for record keeping
Decimals int
// Scaling decimal places for output display
DisplayDecimals int `json:"display_decimals"`
}
type TradeBalanceResponse struct {
EquivalentBalance float64 `json:"eb,string"`
TradeBalance float64 `json:"tb,string"`
MarginAmount float64 `json:"m,string"`
UnrealizedNetProfit float64 `json:"n,string"`
Cost float64 `json:"c,string"`
Valuation float64 `json:"v,string"`
Equity float64 `json:"e,string"`
FreeMargin float64 `json:"mf,string"`
MarginLevel float64 `json:"ml,string"`
}
type BalanceResponse map[string]float64
// Fees includes fees information for different currencies
type Fees struct {
ADACAD FeeInfo
ADAETH FeeInfo
ADAEUR FeeInfo
ADAUSD FeeInfo
ADAXBT FeeInfo
AAVEUSD FeeInfo
BCHEUR FeeInfo
BCHUSD FeeInfo
BCHXBT FeeInfo
DASHEUR FeeInfo
DASHUSD FeeInfo
DASHXBT FeeInfo
EOSETH FeeInfo
EOSEUR FeeInfo
EOSUSD FeeInfo
EOSXBT FeeInfo
GNOETH FeeInfo
GNOEUR FeeInfo
GNOUSD FeeInfo
GNOXBT FeeInfo
LINKUSD FeeInfo
LINKXBT FeeInfo
QTUMCAD FeeInfo
QTUMETH FeeInfo
QTUMEUR FeeInfo
QTUMUSD FeeInfo
QTUMXBT FeeInfo
USDTZUSD FeeInfo
XETCXETH FeeInfo
XETCXXBT FeeInfo
XETCZEUR FeeInfo
XETCZUSD FeeInfo
XETHXXBT FeeInfo
XETHZCAD FeeInfo
XETHZEUR FeeInfo
XETHZGBP FeeInfo
XETHZJPY FeeInfo
XETHZUSD FeeInfo
XICNXETH FeeInfo
XICNXXBT FeeInfo
XLTCXXBT FeeInfo
XLTCZEUR FeeInfo
XLTCZUSD FeeInfo
XMLNXETH FeeInfo
XMLNXXBT FeeInfo
XREPXETH FeeInfo
XREPXXBT FeeInfo
XREPZEUR FeeInfo
XREPZUSD FeeInfo
XTZCAD FeeInfo
XTZETH FeeInfo
XTZEUR FeeInfo
XTZUSD FeeInfo
XTZXBT FeeInfo
XXBTZCAD FeeInfo
XXBTZEUR FeeInfo
XXBTZGBP FeeInfo
XXBTZJPY FeeInfo
XXBTZUSD FeeInfo
XXDGXXBT FeeInfo
XXLMXXBT FeeInfo
XXLMZEUR FeeInfo
XXLMZUSD FeeInfo
XXMRXXBT FeeInfo
XXMRZEUR FeeInfo
XXMRZUSD FeeInfo
XXRPXXBT FeeInfo
XXRPZCAD FeeInfo
XXRPZEUR FeeInfo
XXRPZJPY FeeInfo
XXRPZUSD FeeInfo
XZECXXBT FeeInfo
XZECZEUR FeeInfo
XZECZUSD FeeInfo
}
// FeeInfo represents a fee information
type FeeInfo struct {
Fee float64 `json:"fee,string"`
MinFee float64 `json:"minfee,string"`
MaxFee float64 `json:"maxfee,string"`
NextFee float64 `json:"nextfee,string"`
NextVolume float64 `json:"nextvolume,string"`
TierVolume float64 `json:"tiervolume,string"`
}
// TradeVolumeResponse represents the response for trade volume
type TradeVolumeResponse struct {
Volume float64 `json:"volume,string"`
Currency string `json:"currency"`
Fees Fees `json:"fees"`
FeesMaker Fees `json:"fees_maker"`
}
// TickerResponse includes the requested ticker pairs
type TickerResponse struct {
ADACAD PairTickerInfo
ADAETH PairTickerInfo
ADAEUR PairTickerInfo
ADAUSD PairTickerInfo
ADAXBT PairTickerInfo
AAVEUSD PairTickerInfo
BCHEUR PairTickerInfo
BCHUSD PairTickerInfo
BCHXBT PairTickerInfo
DASHEUR PairTickerInfo
DASHUSD PairTickerInfo
DASHXBT PairTickerInfo
EOSETH PairTickerInfo
EOSEUR PairTickerInfo
EOSUSD PairTickerInfo
EOSXBT PairTickerInfo
GNOETH PairTickerInfo
GNOEUR PairTickerInfo
GNOUSD PairTickerInfo
GNOXBT PairTickerInfo
LINKUSD PairTickerInfo
LINKXBT PairTickerInfo
QTUMCAD PairTickerInfo
QTUMETH PairTickerInfo
QTUMEUR PairTickerInfo
QTUMUSD PairTickerInfo
QTUMXBT PairTickerInfo
USDTZUSD PairTickerInfo
XBTUSDT PairTickerInfo
XETCXETH PairTickerInfo
XETCXXBT PairTickerInfo
XETCZEUR PairTickerInfo
XETCZUSD PairTickerInfo
XETHXXBT PairTickerInfo
XETHZCAD PairTickerInfo
XETHZEUR PairTickerInfo
XETHZGBP PairTickerInfo
XETHZJPY PairTickerInfo
XETHZUSD PairTickerInfo
XICNXETH PairTickerInfo
XICNXXBT PairTickerInfo
XLTCXXBT PairTickerInfo
XLTCZEUR PairTickerInfo
XLTCZUSD PairTickerInfo
XMLNXETH PairTickerInfo
XMLNXXBT PairTickerInfo
XREPXETH PairTickerInfo
XREPXXBT PairTickerInfo
XREPZEUR PairTickerInfo
XREPZUSD PairTickerInfo
XXBTZCAD PairTickerInfo
XXBTZEUR PairTickerInfo
XXBTZGBP PairTickerInfo
XXBTZJPY PairTickerInfo
XXBTZUSD PairTickerInfo
XXDGXXBT PairTickerInfo
XXLMXXBT PairTickerInfo
XXLMZEUR PairTickerInfo
XXLMZUSD PairTickerInfo
XXMRXXBT PairTickerInfo
XXMRZEUR PairTickerInfo
XXMRZUSD PairTickerInfo
XXRPXXBT PairTickerInfo
XXRPZCAD PairTickerInfo
XXRPZEUR PairTickerInfo
XXRPZJPY PairTickerInfo
XXRPZUSD PairTickerInfo
XTZCAD PairTickerInfo
XTZETH PairTickerInfo
XTZEUR PairTickerInfo
XTZUSD PairTickerInfo
XTZXBT PairTickerInfo
XZECXXBT PairTickerInfo
XZECZEUR PairTickerInfo
XZECZUSD PairTickerInfo
}
// DepositAddressesResponse is the response type of a DepositAddresses query to the Kraken API.
type DepositAddressesResponse []struct {
Address string `json:"address"`
Expiretm string `json:"expiretm"`
New bool `json:"new,omitempty"`
}
// WithdrawResponse is the response type of a Withdraw query to the Kraken API.
type WithdrawResponse struct {
RefID string `json:"refid"`
}
// WithdrawInfoResponse is the response type showing withdrawal information for a selected withdrawal method.
type WithdrawInfoResponse struct {
Method string `json:"method"`
Limit big.Float `json:"limit"`
Amount big.Float `json:"amount"`
Fee big.Float `json:"fee"`
}
// GetPairTickerInfo is a helper method that returns given `pair`'s `PairTickerInfo`
func (v *TickerResponse) GetPairTickerInfo(pair string) PairTickerInfo {
r := reflect.ValueOf(v)
f := reflect.Indirect(r).FieldByName(pair)
return f.Interface().(PairTickerInfo)
}
// PairTickerInfo represents ticker information for a pair
type PairTickerInfo struct {
// Ask array(<price>, <whole lot volume>, <lot volume>)
Ask []string `json:"a"`
// Bid array(<price>, <whole lot volume>, <lot volume>)
Bid []string `json:"b"`
// Last trade closed array(<price>, <lot volume>)
Close []string `json:"c"`
// Volume array(<today>, <last 24 hours>)
Volume []string `json:"v"`
// Volume weighted average price array(<today>, <last 24 hours>)
VolumeAveragePrice []string `json:"p"`
// Number of trades array(<today>, <last 24 hours>)
Trades []int `json:"t"`
// Low array(<today>, <last 24 hours>)
Low []string `json:"l"`
// High array(<today>, <last 24 hours>)
High []string `json:"h"`
// Today's opening price
OpeningPrice float64 `json:"o,string"`
}
// TradesResponse represents a list of the last trades
type TradesResponse struct {
Last int64
Trades []TradeInfo
}
// TradesHistoryResponse represents a list of executed trade
type TradesHistoryResponse struct {
Trades map[string]TradeHistoryInfo `json:"trades"`
Count int `json:"count"`
}
// TradeHistoryInfo represents a transaction
type TradeHistoryInfo struct {
TransactionID string `json:"ordertxid"`
PostxID string `json:"postxid"`
AssetPair string `json:"pair"`
Time float64 `json:"time"`
Type string `json:"type"`
OrderType string `json:"ordertype"`
Price float64 `json:"price,string"`
Cost float64 `json:"cost,string"`
Fee float64 `json:"fee,string"`
Volume float64 `json:"vol,string"`
Margin float64 `json:"margin,string"`
Misc string `json:"misc"`
}
// TradeInfo represents a trades information
type TradeInfo struct {
Price string
PriceFloat float64
Volume string
VolumeFloat float64
Time int64
Buy bool
Sell bool
Market bool
Limit bool
Miscellaneous string
}
// LedgersResponse represents an associative array of ledgers infos
type LedgersResponse struct {
Ledger map[string]LedgerInfo `json:"ledger"`
}
// LedgerInfo Represents the ledger informations
type LedgerInfo struct {
RefID string `json:"refid"`
Time float64 `json:"time"`
Type string `json:"type"`
Aclass string `json:"aclass"`
Asset string `json:"asset"`
Amount big.Float `json:"amount"`
Fee big.Float `json:"fee"`
Balance big.Float `json:"balance"`
}
// OrderTypes for AddOrder
const (
OTMarket = "market"
OTLimit = "limit" // (price = limit price)
OTStopLoss = "stop-loss" // (price = stop loss price)
OTTakeProfi = "take-profit" // (price = take profit price)
OTStopLossProfit = "stop-loss-profit" // (price = stop loss price, price2 = take profit price)
OTStopLossProfitLimit = "stop-loss-profit-limit" // (price = stop loss price, price2 = take profit price)
OTStopLossLimit = "stop-loss-limit" // (price = stop loss trigger price, price2 = triggered limit price)
OTTakeProfitLimit = "take-profit-limit" // (price = take profit trigger price, price2 = triggered limit price)
OTTrailingStop = "trailing-stop" // (price = trailing stop offset)
OTTrailingStopLimit = "trailing-stop-limit" // (price = trailing stop offset, price2 = triggered limit offset)
OTStopLossAndLimit = "stop-loss-and-limit" // (price = stop loss price, price2 = limit price)
OTSettlePosition = "settle-position"
)
// OrderDescription represents an orders description
type OrderDescription struct {
AssetPair string `json:"pair"`
Close string `json:"close"`
Leverage string `json:"leverage"`
Order string `json:"order"`
OrderType string `json:"ordertype"`
PrimaryPrice string `json:"price"`
SecondaryPrice string `json:"price2"`
Type string `json:"type"`
}
// Order represents a single order
type Order struct {
TransactionID string `json:"-"`
ReferenceID string `json:"refid"`
UserRef int `json:"userref"`
Status string `json:"status"`
OpenTime float64 `json:"opentm"`
StartTime float64 `json:"starttm"`
ExpireTime float64 `json:"expiretm"`
Description OrderDescription `json:"descr"`
Volume string `json:"vol"`
VolumeExecuted float64 `json:"vol_exec,string"`
Cost float64 `json:"cost,string"`
Fee float64 `json:"fee,string"`
Price float64 `json:"price,string"`
StopPrice float64 `json:"stopprice.string"`
LimitPrice float64 `json:"limitprice,string"`
Misc string `json:"misc"`
OrderFlags string `json:"oflags"`
CloseTime float64 `json:"closetm"`
Reason string `json:"reason"`
Trades []string `json:"trades"`
}
type Trade struct {
TransactionID string `json:"ordertxid"`
PostXID string `json:"postxid"`
PositionStatus string `json:"posstatus"`
Pair string `json:"pair"`
Time float64 `json:"time"`
Type string `json:"type"`
OrderType string `json:"ordertype"`
Price float64 `json:"price,string"`
Cost float64 `json:"cost,string"`
Fee float64 `json:"fee,string"`
Volume float64 `json:"vol,string"`
Margin float64 `json:"margin,string"`
Misc string `json:"misc"`
// Closing string `json:"closing"`
}
// ClosedOrdersResponse represents a list of closed orders, indexed by id
type ClosedOrdersResponse struct {
Closed map[string]Order `json:"closed"`
Count int `json:"count"`
}
// OrderBookItem is a piece of information about an order.
type OrderBookItem struct {
Price float64
Amount float64
Ts int64
}
// UnmarshalJSON takes a json array from kraken and converts it into an OrderBookItem.
func (o *OrderBookItem) UnmarshalJSON(data []byte) error {
tmpStruct := struct {
price string
amount string
ts int64
}{}
tmpArray := []interface{}{&tmpStruct.price, &tmpStruct.amount, &tmpStruct.ts}
err := json.Unmarshal(data, &tmpArray)
if err != nil {
return err
}
o.Price, err = strconv.ParseFloat(tmpStruct.price, 64)
if err != nil {
return err
}
o.Amount, err = strconv.ParseFloat(tmpStruct.amount, 64)
if err != nil {
return err
}
o.Ts = tmpStruct.ts
return nil
}
// DepthResponse is a response from kraken to Depth request.
type DepthResponse map[string]OrderBook
// OrderBook contains top asks and bids.
type OrderBook struct {
Asks []OrderBookItem
Bids []OrderBookItem
}
// OpenOrdersResponse response when opening an order
type OpenOrdersResponse struct {
Open map[string]Order `json:"open"`
Count int `json:"count"`
}
// AddOrderResponse response when adding an order
type AddOrderResponse struct {
Description OrderDescription `json:"descr"`
TransactionIds []string `json:"txid"`
}
// CancelOrderResponse response when cancelling and order
type CancelOrderResponse struct {
Count int `json:"count"`
Pending bool `json:"pending"`
}
type QueryTradesResponse map[string]Trade
// QueryOrdersResponse response when checking all orders
type QueryOrdersResponse map[string]Order
// NewOHLC constructor for OHLC
func NewOHLC(input []interface{}) (*OHLC, error) {
if len(input) != 8 {
return nil, fmt.Errorf("the length is not 8 but %d", len(input))
}
tmp := new(OHLC)
tmp.Time = time.Unix(int64(input[0].(float64)), 0)
tmp.Open, _ = strconv.ParseFloat(input[1].(string), 64)
tmp.High, _ = strconv.ParseFloat(input[2].(string), 64)
tmp.Low, _ = strconv.ParseFloat(input[3].(string), 64)
tmp.Close, _ = strconv.ParseFloat(input[4].(string), 64)
tmp.Vwap, _ = strconv.ParseFloat(input[5].(string), 64)
tmp.Volume, _ = strconv.ParseFloat(input[6].(string), 64)
tmp.Count = int(input[7].(float64))
return tmp, nil
}
// OHLC represents the "Open-high-low-close chart"
type OHLC struct {
Time time.Time `json:"time"`
Open float64 `json:"open"`
High float64 `json:"high"`
Low float64 `json:"low"`
Close float64 `json:"close"`
Vwap float64 `json:"vwap"`
Volume float64 `json:"volume"`
Count int `json:"count"`
}
// OHLCResponse represents the OHLC's response
type OHLCResponse struct {
Pair string `json:"pair"`
OHLC []*OHLC `json:"OHLC"`
Last float64 `json:"last"`
}
type PositionsResponse map[string]Position
type Position struct {
TransactionID string `json:"ordertxid"`
PositionStatus string `json:"posstatus"`
Pair string `json:"pair"`
Time float64 `json:"time"`
Type string `json:"type"`
OrderType string `json:"ordertype"`
Cost float64 `json:"cost,string"`
Fee float64 `json:"fee,string"`
Volume float64 `json:"vol,string"`
VolumeClosed float64 `json:"vol_closed,string"`
Margin float64 `json:"margin,string"`
Value float64 `json:"value,string"` // if docalcs == true
Net string `json:"net"` // if docalcs == true
Terms string `json:"terms"`
RollOverTM string `json:"rollovertm"`
Misc string `json:"misc"`
Oflags string `json:"oflags"`
}
type DepositStatusResponse []MovementStatus
type WithdrawStatusResponse []MovementStatus
type MovementStatus struct {
Method string `json:"method"`
AClass string `json:"aclass"`
Asset string `json:"asset"`
RefId string `json:"refid"`
TxId string `json:"txid"`
Info string `json:"info"`
Amount float64 `json:"amount,string"` // likely a string given how everything else is a string float
Fee float64 `json:"fee,string"`
Time float64 `json:"time"`
Status string `json:"status"`
StatusProp interface{} `json:"status-prop"` // Not sure whether this will be a map or a string
}