forked from luno/luno-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.go
1317 lines (1152 loc) · 44.9 KB
/
api.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
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package luno
import (
"context"
"github.com/luno/luno-go/decimal"
)
// CancelWithdrawalRequest is the request struct for CancelWithdrawal.
type CancelWithdrawalRequest struct {
// ID of the withdrawal to cancel.
//
// required: true
Id int64 `json:"id" url:"id"`
}
// CancelWithdrawalResponse is the response struct for CancelWithdrawal.
type CancelWithdrawalResponse struct {
Amount decimal.Decimal `json:"amount"`
CreatedAt Time `json:"created_at"`
Currency string `json:"currency"`
ExternalId string `json:"external_id"`
Fee decimal.Decimal `json:"fee"`
Id string `json:"id"`
Status string `json:"status"`
Type string `json:"type"`
}
// CancelWithdrawal makes a call to DELETE /api/1/withdrawals/{id}.
//
// Cancel a withdrawal request.
// This can only be done if the request is still in state <code>PENDING</code>.
//
// Permissions required: <code>Perm_W_Withdrawals</code>
func (cl *Client) CancelWithdrawal(ctx context.Context, req *CancelWithdrawalRequest) (*CancelWithdrawalResponse, error) {
var res CancelWithdrawalResponse
err := cl.do(ctx, "DELETE", "/api/1/withdrawals/{id}", req, &res, true)
if err != nil {
return nil, err
}
return &res, nil
}
// CreateAccountRequest is the request struct for CreateAccount.
type CreateAccountRequest struct {
// The currency code for the Account you want to create. Please see the Currency section for a detailed list of currencies supported by the Luno platform.
//
// Users must be verified to trade currency in order to be able to create an Account. For more information on the verification process, please see <a href="/help/en/articles/1000168396">How do I verify my identity?</a>.
//
// Users have a limit of 4 accounts per currency.
//
// required: true
Currency string `json:"currency" url:"currency"`
// The label to use for this account
//
// required: true
Name string `json:"name" url:"name"`
}
// CreateAccountResponse is the response struct for CreateAccount.
type CreateAccountResponse struct {
Currency string `json:"currency"`
Id string `json:"id"`
Name string `json:"name"`
Pending []Transaction `json:"pending"`
Transactions []Transaction `json:"transactions"`
}
// CreateAccount makes a call to POST /api/1/accounts.
//
// This request creates an Account for the specified currency. Please note that the balances for the Account will be displayed based on the <code>asset</code> value, which is the currency the Account is based on.
//
// Permissions required: <code>Perm_W_Addresses</code>
func (cl *Client) CreateAccount(ctx context.Context, req *CreateAccountRequest) (*CreateAccountResponse, error) {
var res CreateAccountResponse
err := cl.do(ctx, "POST", "/api/1/accounts", req, &res, true)
if err != nil {
return nil, err
}
return &res, nil
}
// CreateFundingAddressRequest is the request struct for CreateFundingAddress.
type CreateFundingAddressRequest struct {
// Currency code of the asset.
//
// required: true
Asset string `json:"asset" url:"asset"`
// An optional name for the new Receive Address
Name string `json:"name" url:"name"`
}
// CreateFundingAddressResponse is the response struct for CreateFundingAddress.
type CreateFundingAddressResponse struct {
AccountId string `json:"account_id"`
Address string `json:"address"`
AddressMeta []AddressMeta `json:"address_meta"`
Asset string `json:"asset"`
AssignedAt Time `json:"assigned_at"`
Name string `json:"name"`
QrCodeUri string `json:"qr_code_uri"`
ReceiveFee decimal.Decimal `json:"receive_fee"`
TotalReceived decimal.Decimal `json:"total_received"`
TotalUnconfirmed decimal.Decimal `json:"total_unconfirmed"`
}
// CreateFundingAddress makes a call to POST /api/1/funding_address.
//
// Allocates a new receive address to your account. There is a rate limit of 1
// address per hour, but bursts of up to 10 addresses are allowed. Only 1
// Ethereum receive address can be created.
//
// Permissions required: <code>Perm_W_Addresses</code>
func (cl *Client) CreateFundingAddress(ctx context.Context, req *CreateFundingAddressRequest) (*CreateFundingAddressResponse, error) {
var res CreateFundingAddressResponse
err := cl.do(ctx, "POST", "/api/1/funding_address", req, &res, true)
if err != nil {
return nil, err
}
return &res, nil
}
// CreateQuoteRequest is the request struct for CreateQuote.
type CreateQuoteRequest struct {
// Amount to buy or sell in the pair base currency.
//
// required: true
BaseAmount decimal.Decimal `json:"base_amount" url:"base_amount"`
// Currency pair to trade. The pair can also be flipped if you want to buy
// or sell the counter currency (e.g. ZARXBT).
//
// required: true
Pair string `json:"pair" url:"pair"`
// <code>BUY</code> or <code>SELL</code>.
//
// required: true
Type string `json:"type" url:"type"`
// Optional Account for the pair's base currency.
BaseAccountId int64 `json:"base_account_id" url:"base_account_id"`
// Optional Account for the pair's counter currency.
CounterAccountId int64 `json:"counter_account_id" url:"counter_account_id"`
}
// CreateQuoteResponse is the response struct for CreateQuote.
type CreateQuoteResponse struct {
BaseAmount decimal.Decimal `json:"base_amount"`
CounterAmount decimal.Decimal `json:"counter_amount"`
CreatedAt Time `json:"created_at"`
Discarded bool `json:"discarded"`
Exercised bool `json:"exercised"`
ExpiresAt Time `json:"expires_at"`
Id string `json:"id"`
Pair string `json:"pair"`
Type string `json:"type"`
}
// CreateQuote makes a call to POST /api/1/quotes.
//
// Creates a new quote to buy or sell a particular amount of a base currency for a counter currency.
//
// Users can specify either the exact amount to pay or the exact amount to receive.
//
// For example, to buy exactly 0.1 Bitcoin using ZAR, you would create a quote to BUY 0.1 XBTZAR.
// The returned quote includes the appropriate ZAR amount.
// To buy Bitcoin using exactly ZAR 100, create a quote to SELL 100 ZARXBT.
// The returned quote specifies the Bitcoin as the counter amount returned.
//
// An error is returned if the Account is not verified for the currency pair,
// or if the Account would have insufficient balance to ever exercise the quote.
//
// Permissions required: <code>Perm_W_Orders</code>
func (cl *Client) CreateQuote(ctx context.Context, req *CreateQuoteRequest) (*CreateQuoteResponse, error) {
var res CreateQuoteResponse
err := cl.do(ctx, "POST", "/api/1/quotes", req, &res, true)
if err != nil {
return nil, err
}
return &res, nil
}
// CreateWithdrawalRequest is the request struct for CreateWithdrawal.
type CreateWithdrawalRequest struct {
// Amount to withdraw. The currency withdrawn depends on the type setting.
//
// required: true
Amount decimal.Decimal `json:"amount" url:"amount"`
// Withdrawal type.
//
// required: true
Type string `json:"type" url:"type"`
// The beneficiary ID of the bank account the withdrawal will be paid out to.
// This parameter is required if the user has set up multiple beneficiaries.
// The beneficiary ID can be found by selecting on the beneficiary name on the user’s <a href="/wallet/beneficiaries">Beneficiaries</a> page.
BeneficiaryId int64 `json:"beneficiary_id" url:"beneficiary_id"`
// Optional unique ID to associate with this withdrawal.
// Useful to prevent duplicate sends.
// This field supports all alphanumeric characters including "-" and "_".
ExternalId string `json:"external_id" url:"external_id"`
// For internal use.
Reference string `json:"reference" url:"reference"`
}
// CreateWithdrawalResponse is the response struct for CreateWithdrawal.
type CreateWithdrawalResponse struct {
Amount decimal.Decimal `json:"amount"`
CreatedAt Time `json:"created_at"`
Currency string `json:"currency"`
ExternalId string `json:"external_id"`
Fee decimal.Decimal `json:"fee"`
Id string `json:"id"`
Status string `json:"status"`
Type string `json:"type"`
}
// CreateWithdrawal makes a call to POST /api/1/withdrawals.
//
// Creates a new withdrawal request to the specified beneficiary.
//
// Permissions required: <code>Perm_W_Withdrawals</code>
func (cl *Client) CreateWithdrawal(ctx context.Context, req *CreateWithdrawalRequest) (*CreateWithdrawalResponse, error) {
var res CreateWithdrawalResponse
err := cl.do(ctx, "POST", "/api/1/withdrawals", req, &res, true)
if err != nil {
return nil, err
}
return &res, nil
}
// DiscardQuoteRequest is the request struct for DiscardQuote.
type DiscardQuoteRequest struct {
// ID of the quote to discard.
//
// required: true
Id int64 `json:"id" url:"id"`
}
// DiscardQuoteResponse is the response struct for DiscardQuote.
type DiscardQuoteResponse struct {
BaseAmount decimal.Decimal `json:"base_amount"`
CounterAmount decimal.Decimal `json:"counter_amount"`
CreatedAt Time `json:"created_at"`
Discarded bool `json:"discarded"`
Exercised bool `json:"exercised"`
ExpiresAt Time `json:"expires_at"`
Id string `json:"id"`
Pair string `json:"pair"`
Type string `json:"type"`
}
// DiscardQuote makes a call to DELETE /api/1/quotes/{id}.
//
// Discard a Quote.
// Once a Quote has been discarded, it cannot be exercised even if it has not expired.
//
// Permissions required: <code>Perm_W_Orders</code>
func (cl *Client) DiscardQuote(ctx context.Context, req *DiscardQuoteRequest) (*DiscardQuoteResponse, error) {
var res DiscardQuoteResponse
err := cl.do(ctx, "DELETE", "/api/1/quotes/{id}", req, &res, true)
if err != nil {
return nil, err
}
return &res, nil
}
// ExerciseQuoteRequest is the request struct for ExerciseQuote.
type ExerciseQuoteRequest struct {
// ID of the quote to exercise.
//
// required: true
Id int64 `json:"id" url:"id"`
}
// ExerciseQuoteResponse is the response struct for ExerciseQuote.
type ExerciseQuoteResponse struct {
BaseAmount decimal.Decimal `json:"base_amount"`
CounterAmount decimal.Decimal `json:"counter_amount"`
CreatedAt Time `json:"created_at"`
Discarded bool `json:"discarded"`
Exercised bool `json:"exercised"`
ExpiresAt Time `json:"expires_at"`
Id string `json:"id"`
Pair string `json:"pair"`
Type string `json:"type"`
}
// ExerciseQuote makes a call to PUT /api/1/quotes/{id}.
//
// Exercise a quote to perform the Trade.
// If there is sufficient balance available in the Account,
// it will be debited and the counter amount credited.
//
// An error is returned if the quote has expired or if the Account has insufficient available balance.
//
// Permissions required: <code>Perm_W_Orders</code>
func (cl *Client) ExerciseQuote(ctx context.Context, req *ExerciseQuoteRequest) (*ExerciseQuoteResponse, error) {
var res ExerciseQuoteResponse
err := cl.do(ctx, "PUT", "/api/1/quotes/{id}", req, &res, true)
if err != nil {
return nil, err
}
return &res, nil
}
// GetBalancesRequest is the request struct for GetBalances.
type GetBalancesRequest struct {
// Only return balances for wallets with these currencies (if not provided,
// all balances will be returned)
Assets []string `json:"assets" url:"assets"`
}
// GetBalancesResponse is the response struct for GetBalances.
type GetBalancesResponse struct {
Balance []AccountBalance `json:"balance"`
}
// GetBalances makes a call to GET /api/1/balance.
//
// The list of all Accounts and their respective balances for the requesting user.
//
// Permissions required: <code>Perm_R_Balance</code>
func (cl *Client) GetBalances(ctx context.Context, req *GetBalancesRequest) (*GetBalancesResponse, error) {
var res GetBalancesResponse
err := cl.do(ctx, "GET", "/api/1/balance", req, &res, true)
if err != nil {
return nil, err
}
return &res, nil
}
// GetFeeInfoRequest is the request struct for GetFeeInfo.
type GetFeeInfoRequest struct {
// Get fee information about this pair.
//
// required: true
Pair string `json:"pair" url:"pair"`
}
// GetFeeInfoResponse is the response struct for GetFeeInfo.
type GetFeeInfoResponse struct {
MakerFee string `json:"maker_fee"`
TakerFee string `json:"taker_fee"`
ThirtyDayVolume string `json:"thirty_day_volume"`
}
// GetFeeInfo makes a call to GET /api/1/fee_info.
//
// Returns the fees and 30 day trading volume (as of midnight) for a given currency pair. For complete details, please see <a href="en/countries">Fees & Features</a>.
//
// Permissions required: <code>Perm_R_Orders</code>
func (cl *Client) GetFeeInfo(ctx context.Context, req *GetFeeInfoRequest) (*GetFeeInfoResponse, error) {
var res GetFeeInfoResponse
err := cl.do(ctx, "GET", "/api/1/fee_info", req, &res, true)
if err != nil {
return nil, err
}
return &res, nil
}
// GetFundingAddressRequest is the request struct for GetFundingAddress.
type GetFundingAddressRequest struct {
// Currency code of the asset.
//
// required: true
Asset string `json:"asset" url:"asset"`
// Specific cryptocurrency address to retrieve. If not provided, the
// default address will be used.
Address string `json:"address" url:"address"`
}
// GetFundingAddressResponse is the response struct for GetFundingAddress.
type GetFundingAddressResponse struct {
AccountId string `json:"account_id"`
Address string `json:"address"`
AddressMeta []AddressMeta `json:"address_meta"`
Asset string `json:"asset"`
AssignedAt Time `json:"assigned_at"`
Name string `json:"name"`
QrCodeUri string `json:"qr_code_uri"`
ReceiveFee decimal.Decimal `json:"receive_fee"`
TotalReceived decimal.Decimal `json:"total_received"`
TotalUnconfirmed decimal.Decimal `json:"total_unconfirmed"`
}
// GetFundingAddress makes a call to GET /api/1/funding_address.
//
// Returns the default receive address associated with your account and the
// amount received via the address. Users can specify an optional address parameter to return information for a non-default receive address.
//
// In the response, <code>total_received</code> is the total confirmed amount received excluding unconfirmed transactions.
// <code>total_unconfirmed</code> is the total sum of unconfirmed receive transactions.
//
// Permissions required: <code>Perm_R_Addresses</code>
func (cl *Client) GetFundingAddress(ctx context.Context, req *GetFundingAddressRequest) (*GetFundingAddressResponse, error) {
var res GetFundingAddressResponse
err := cl.do(ctx, "GET", "/api/1/funding_address", req, &res, true)
if err != nil {
return nil, err
}
return &res, nil
}
// GetOrderRequest is the request struct for GetOrder.
type GetOrderRequest struct {
// The order ID.
//
// required: true
Id string `json:"id" url:"id"`
}
// GetOrderResponse is the response struct for GetOrder.
type GetOrderResponse struct {
Base decimal.Decimal `json:"base"`
CompletedTimestamp Time `json:"completed_timestamp"`
Counter decimal.Decimal `json:"counter"`
CreationTimestamp Time `json:"creation_timestamp"`
ExpirationTimestamp Time `json:"expiration_timestamp"`
FeeBase decimal.Decimal `json:"fee_base"`
FeeCounter decimal.Decimal `json:"fee_counter"`
LimitPrice decimal.Decimal `json:"limit_price"`
LimitVolume decimal.Decimal `json:"limit_volume"`
OrderId string `json:"order_id"`
// Specifies the market.
Pair string `json:"pair"`
// <code>PENDING</code> The order has been placed. Some trades may have
// taken place but the order is not filled yet.<br>
// <code>COMPLETE</code> The order is no longer active. It has been settled
// or has been cancelled.
State OrderState `json:"state"`
// <code>BID</code> bid (buy) limit order.<br>
// <code>ASK</code> ask (sell) limit order.
Type OrderType `json:"type"`
}
// GetOrder makes a call to GET /api/1/orders/{id}.
//
// Get an Order's details by its ID.
//
// Permissions required: <code>Perm_R_Orders</code>
func (cl *Client) GetOrder(ctx context.Context, req *GetOrderRequest) (*GetOrderResponse, error) {
var res GetOrderResponse
err := cl.do(ctx, "GET", "/api/1/orders/{id}", req, &res, true)
if err != nil {
return nil, err
}
return &res, nil
}
// GetOrderBookRequest is the request struct for GetOrderBook.
type GetOrderBookRequest struct {
// Currency pair of the Orders to retrieve
//
// required: true
Pair string `json:"pair" url:"pair"`
}
// GetOrderBookResponse is the response struct for GetOrderBook.
type GetOrderBookResponse struct {
Asks []OrderBookEntry `json:"asks"`
Bids []OrderBookEntry `json:"bids"`
Timestamp int64 `json:"timestamp"`
}
// GetOrderBook makes a call to GET /api/1/orderbook_top.
//
// Returns a list of the top 100 <em>bids</em> and <em>asks</em> for the currency pair specified in the Order Book.
//
// Ask Orders are sorted by price ascending.
//
// Bid Orders are sorted by price descending.
//
// Orders of the same price are aggregated.
func (cl *Client) GetOrderBook(ctx context.Context, req *GetOrderBookRequest) (*GetOrderBookResponse, error) {
var res GetOrderBookResponse
err := cl.do(ctx, "GET", "/api/1/orderbook_top", req, &res, false)
if err != nil {
return nil, err
}
return &res, nil
}
// GetOrderBookFullRequest is the request struct for GetOrderBookFull.
type GetOrderBookFullRequest struct {
// Currency pair of the Orders to retrieve
//
// required: true
Pair string `json:"pair" url:"pair"`
}
// GetOrderBookFullResponse is the response struct for GetOrderBookFull.
type GetOrderBookFullResponse struct {
Asks []OrderBookEntry `json:"asks"`
Bids []OrderBookEntry `json:"bids"`
Timestamp int64 `json:"timestamp"`
}
// GetOrderBookFull makes a call to GET /api/1/orderbook.
//
// This request returns a list of all <em>bids</em> and <em>asks</em> for the currency pair specified in the Order Book.
//
// Ask orders are sorted by price ascending.
//
// Bid orders are sorted by price descending.
//
// Multiple orders at the same price are not aggregated.
//
// <b>Warning:</b> This may return a large amount of data.
// Users are recommended to use the <a href="#operation/getOrderBook">top 100 bids and asks</a>
// or the <a href="#tag/streaming-API-(beta)">Streaming API</a>.
func (cl *Client) GetOrderBookFull(ctx context.Context, req *GetOrderBookFullRequest) (*GetOrderBookFullResponse, error) {
var res GetOrderBookFullResponse
err := cl.do(ctx, "GET", "/api/1/orderbook", req, &res, false)
if err != nil {
return nil, err
}
return &res, nil
}
// GetOrderV2Request is the request struct for GetOrderV2.
type GetOrderV2Request struct {
// Order reference
//
// required: true
Id string `json:"id" url:"id"`
}
// GetOrderV2Response is the response struct for GetOrderV2.
type GetOrderV2Response struct {
// Amount of base filled
Base decimal.Decimal `json:"base"`
// Time of order completion in milliseconds
CompletedTimestamp Time `json:"completed_timestamp"`
// Amount of counter filled
Counter decimal.Decimal `json:"counter"`
// Time of order creation in milliseconds
CreationTimestamp Time `json:"creation_timestamp"`
// Time of order expiration in milliseconds
ExpirationTimestamp Time `json:"expiration_timestamp"`
// Base amount of fees to be charged
FeeBase decimal.Decimal `json:"fee_base"`
// Counter amount of fees to be charged
FeeCounter decimal.Decimal `json:"fee_counter"`
// Limit price to transact
LimitPrice decimal.Decimal `json:"limit_price"`
// Limit volume to transact
LimitVolume decimal.Decimal `json:"limit_volume"`
// The order reference
OrderId string `json:"order_id"`
// Specifies the market
Pair string `json:"pair"`
// The order intention
Side Side `json:"side"`
// The current state of the order
//
// Status meaning:<br>
// <code>AWAITING</code> The order is awaiting to enter the order book.<br>
// <code>PENDING</code> The order is in the order book. Some trades may
// have taken place but the order is not filled yet.<br>
// <code>COMPLETE</code> The order is no longer in the order book. It has
// been settled/filled or has been cancelled.
Status Status `json:"status"`
// Direction to trigger the order
StopDirection StopDirection `json:"stop_direction"`
// Price to trigger the order
StopPrice decimal.Decimal `json:"stop_price"`
// The order type
Type Type `json:"type"`
}
// GetOrderV2 makes a call to GET /api/exchange/2/orders/{id}.
//
// Get the details for an order.<br>
// This endpoint is in BETA, behaviour and specification may change without
// any previous notice.
//
// Permissions required: <code>Perm_R_Orders</code>
func (cl *Client) GetOrderV2(ctx context.Context, req *GetOrderV2Request) (*GetOrderV2Response, error) {
var res GetOrderV2Response
err := cl.do(ctx, "GET", "/api/exchange/2/orders/{id}", req, &res, true)
if err != nil {
return nil, err
}
return &res, nil
}
// GetQuoteRequest is the request struct for GetQuote.
type GetQuoteRequest struct {
// ID of the quote to retrieve.
//
// required: true
Id int64 `json:"id" url:"id"`
}
// GetQuoteResponse is the response struct for GetQuote.
type GetQuoteResponse struct {
BaseAmount decimal.Decimal `json:"base_amount"`
CounterAmount decimal.Decimal `json:"counter_amount"`
CreatedAt Time `json:"created_at"`
Discarded bool `json:"discarded"`
Exercised bool `json:"exercised"`
ExpiresAt Time `json:"expires_at"`
Id string `json:"id"`
Pair string `json:"pair"`
Type string `json:"type"`
}
// GetQuote makes a call to GET /api/1/quotes/{id}.
//
// Get the latest status of a quote by its id.
//
// Permissions required: <code>Perm_R_Orders</code>
func (cl *Client) GetQuote(ctx context.Context, req *GetQuoteRequest) (*GetQuoteResponse, error) {
var res GetQuoteResponse
err := cl.do(ctx, "GET", "/api/1/quotes/{id}", req, &res, true)
if err != nil {
return nil, err
}
return &res, nil
}
// GetTickerRequest is the request struct for GetTicker.
type GetTickerRequest struct {
// Currency pair
//
// required: true
Pair string `json:"pair" url:"pair"`
}
// GetTickerResponse is the response struct for GetTicker.
type GetTickerResponse struct {
Ask decimal.Decimal `json:"ask"`
Bid decimal.Decimal `json:"bid"`
LastTrade decimal.Decimal `json:"last_trade"`
Pair string `json:"pair"`
Rolling24HourVolume decimal.Decimal `json:"rolling_24_hour_volume"`
// <code>ACTIVE</code> when the market is trading normally
//
// <code>POSTONLY</code> when the market has been suspended and only post-only orders will be accepted
//
// <code>DISABLED</code> when the market is shutdown and no orders can be accepted
Status Status `json:"status"`
Timestamp Time `json:"timestamp"`
}
// GetTicker makes a call to GET /api/1/ticker.
//
// Returns the latest ticker indicators for the specified currency pair.
//
// Please see the <a href="#tag/currency ">Currency list</a> for the complete list of supported currency pairs.
func (cl *Client) GetTicker(ctx context.Context, req *GetTickerRequest) (*GetTickerResponse, error) {
var res GetTickerResponse
err := cl.do(ctx, "GET", "/api/1/ticker", req, &res, false)
if err != nil {
return nil, err
}
return &res, nil
}
// GetTickersRequest is the request struct for GetTickers.
type GetTickersRequest struct {
// Currency pairs
Pair []string `json:"pair" url:"pair"`
}
// GetTickersResponse is the response struct for GetTickers.
type GetTickersResponse struct {
Tickers []Ticker `json:"tickers"`
}
// GetTickers makes a call to GET /api/1/tickers.
//
// Returns the latest ticker indicators from all active Luno exchanges.
//
// Please see the <a href="#tag/currency ">Currency list</a> for the complete list of supported currency pairs.
func (cl *Client) GetTickers(ctx context.Context, req *GetTickersRequest) (*GetTickersResponse, error) {
var res GetTickersResponse
err := cl.do(ctx, "GET", "/api/1/tickers", req, &res, false)
if err != nil {
return nil, err
}
return &res, nil
}
// GetWithdrawalRequest is the request struct for GetWithdrawal.
type GetWithdrawalRequest struct {
// Withdrawal ID to retrieve.
//
// required: true
Id int64 `json:"id" url:"id"`
}
// GetWithdrawalResponse is the response struct for GetWithdrawal.
type GetWithdrawalResponse struct {
Amount decimal.Decimal `json:"amount"`
CreatedAt Time `json:"created_at"`
Currency string `json:"currency"`
ExternalId string `json:"external_id"`
Fee decimal.Decimal `json:"fee"`
Id string `json:"id"`
Status string `json:"status"`
Type string `json:"type"`
}
// GetWithdrawal makes a call to GET /api/1/withdrawals/{id}.
//
// Returns the status of a particular withdrawal request.
//
// Permissions required: <code>Perm_R_Withdrawals</code>
func (cl *Client) GetWithdrawal(ctx context.Context, req *GetWithdrawalRequest) (*GetWithdrawalResponse, error) {
var res GetWithdrawalResponse
err := cl.do(ctx, "GET", "/api/1/withdrawals/{id}", req, &res, true)
if err != nil {
return nil, err
}
return &res, nil
}
// ListBeneficiariesResponseRequest is the request struct for ListBeneficiariesResponse.
type ListBeneficiariesResponseRequest struct {
}
// ListBeneficiariesResponseResponse is the response struct for ListBeneficiariesResponse.
type ListBeneficiariesResponseResponse struct {
Beneficiaries []beneficiary `json:"beneficiaries"`
}
// ListBeneficiariesResponse makes a call to GET /api/1/beneficiaries.
//
// Returns a list of bank beneficiaries.
//
// Permissions required: <code>Perm_R_Beneficiaries</code>
func (cl *Client) ListBeneficiariesResponse(ctx context.Context, req *ListBeneficiariesResponseRequest) (*ListBeneficiariesResponseResponse, error) {
var res ListBeneficiariesResponseResponse
err := cl.do(ctx, "GET", "/api/1/beneficiaries", req, &res, true)
if err != nil {
return nil, err
}
return &res, nil
}
// ListOrdersRequest is the request struct for ListOrders.
type ListOrdersRequest struct {
// Filter to orders created before this timestamp (Unix milliseconds)
CreatedBefore int64 `json:"created_before" url:"created_before"`
// Limit to this many orders
Limit int64 `json:"limit" url:"limit"`
// Filter to only orders of this currency pair
Pair string `json:"pair" url:"pair"`
// Filter to only orders of this state
State OrderState `json:"state" url:"state"`
}
// ListOrdersResponse is the response struct for ListOrders.
type ListOrdersResponse struct {
Orders []Order `json:"orders"`
}
// ListOrders makes a call to GET /api/1/listorders.
//
// Returns a list of the most recently placed Orders.
// Users can specify an optional <code>state=PENDING</code> parameter to restrict the results to only open Orders.
// Users can also specify the market by using the optional currency pair parameter.
// The list is truncated after 100 items.
//
// Permissions required: <code>Perm_R_Orders</code>
func (cl *Client) ListOrders(ctx context.Context, req *ListOrdersRequest) (*ListOrdersResponse, error) {
var res ListOrdersResponse
err := cl.do(ctx, "GET", "/api/1/listorders", req, &res, true)
if err != nil {
return nil, err
}
return &res, nil
}
// ListOrdersV2Request is the request struct for ListOrdersV2.
type ListOrdersV2Request struct {
// If true, will return closed orders instead of open orders.
Closed bool `json:"closed" url:"closed"`
// Filter to orders created before this timestamp (Unix milliseconds)
CreatedBefore int64 `json:"created_before" url:"created_before"`
// Limit to this many orders
Limit int64 `json:"limit" url:"limit"`
// Filter to only orders of this currency pair.
Pair string `json:"pair" url:"pair"`
}
// ListOrdersV2Response is the response struct for ListOrdersV2.
type ListOrdersV2Response struct {
Orders []OrderV2 `json:"orders"`
}
// ListOrdersV2 makes a call to GET /api/exchange/2/listorders.
//
// Returns a list of the most recently placed orders. This endpoint will list
// up to 100 open orders by default.<br>
// This endpoint is in BETA, behaviour and specification may change without
// any previous notice.
//
// Permissions required: <Code>Perm_R_Orders</Code>
func (cl *Client) ListOrdersV2(ctx context.Context, req *ListOrdersV2Request) (*ListOrdersV2Response, error) {
var res ListOrdersV2Response
err := cl.do(ctx, "GET", "/api/exchange/2/listorders", req, &res, true)
if err != nil {
return nil, err
}
return &res, nil
}
// ListPendingTransactionsRequest is the request struct for ListPendingTransactions.
type ListPendingTransactionsRequest struct {
// Account ID
//
// required: true
Id int64 `json:"id" url:"id"`
}
// ListPendingTransactionsResponse is the response struct for ListPendingTransactions.
type ListPendingTransactionsResponse struct {
Currency string `json:"currency"`
Id string `json:"id"`
Name string `json:"name"`
Pending []Transaction `json:"pending"`
Transactions []Transaction `json:"transactions"`
}
// ListPendingTransactions makes a call to GET /api/1/accounts/{id}/pending.
//
// Return a list of all transactions that have not completed for the Account.
//
// Pending transactions are not numbered, and may be reordered, deleted or updated at any time.
//
// Permissions required: <code>Perm_R_Transactions</code>
func (cl *Client) ListPendingTransactions(ctx context.Context, req *ListPendingTransactionsRequest) (*ListPendingTransactionsResponse, error) {
var res ListPendingTransactionsResponse
err := cl.do(ctx, "GET", "/api/1/accounts/{id}/pending", req, &res, true)
if err != nil {
return nil, err
}
return &res, nil
}
// ListTradesRequest is the request struct for ListTrades.
type ListTradesRequest struct {
// Currency pair
//
// required: true
Pair string `json:"pair" url:"pair"`
// Fetch trades executed after this time, specified as a Unix timestamp in
// milliseconds.
Since Time `json:"since" url:"since"`
}
// ListTradesResponse is the response struct for ListTrades.
type ListTradesResponse struct {
Trades []Trade `json:"trades"`
}
// ListTrades makes a call to GET /api/1/trades.
//
// Returns a list of the most recent Trades for the specified currency pair in the last 24 hours.
// At most 100 results are returned per call.
//
// Please see the <a href="#tag/currency ">Currency list</a> for the complete list of supported currency pairs.
func (cl *Client) ListTrades(ctx context.Context, req *ListTradesRequest) (*ListTradesResponse, error) {
var res ListTradesResponse
err := cl.do(ctx, "GET", "/api/1/trades", req, &res, false)
if err != nil {
return nil, err
}
return &res, nil
}
// ListTransactionsRequest is the request struct for ListTransactions.
type ListTransactionsRequest struct {
// Account ID - the unique identifier for the specific Account.
//
// required: true
Id int64 `json:"id" url:"id"`
// Maximum of the row range to return (exclusive)
//
// required: true
MaxRow int64 `json:"max_row" url:"max_row"`
// Minimum of the row range to return (inclusive)
//
// required: true
MinRow int64 `json:"min_row" url:"min_row"`
}
// ListTransactionsResponse is the response struct for ListTransactions.
type ListTransactionsResponse struct {
Currency string `json:"currency"`
Id string `json:"id"`
Name string `json:"name"`
Pending []Transaction `json:"pending"`
Transactions []Transaction `json:"transactions"`
}
// ListTransactions makes a call to GET /api/1/accounts/{id}/transactions.
//
// Return a list of transaction entries from an account.
//
// Transaction entry rows are numbered sequentially starting from 1, where 1 is
// the oldest entry. The range of rows to return are specified with the
// <code>min_row</code> (inclusive) and <code>max_row</code> (exclusive)
// parameters. At most 1000 rows can be requested per call.
//
// If <code>min_row</code> or <code>max_row</code> is non-positive, the range
// wraps around the most recent row. For example, to fetch the 100 most recent
// rows, use <code>min_row=-100</code> and <code>max_row=0</code>.
//
// Permissions required: <code>Perm_R_Transactions</code>
func (cl *Client) ListTransactions(ctx context.Context, req *ListTransactionsRequest) (*ListTransactionsResponse, error) {
var res ListTransactionsResponse
err := cl.do(ctx, "GET", "/api/1/accounts/{id}/transactions", req, &res, true)
if err != nil {
return nil, err
}
return &res, nil
}
// ListUserTradesRequest is the request struct for ListUserTrades.
type ListUserTradesRequest struct {
// Filter to trades of this currency pair.
//
// required: true
Pair string `json:"pair" url:"pair"`
// Filter to trades from (including) this sequence number.
// Default behaviour is not to include this filter.
AfterSeq int64 `json:"after_seq" url:"after_seq"`
// Filter to trades before this timestamp.
Before Time `json:"before" url:"before"`
// Filter to trades before (excluding) this sequence number.
// Default behaviour is not to include this filter.
BeforeSeq int64 `json:"before_seq" url:"before_seq"`
// Limit to this number of trades (default 100).
Limit int64 `json:"limit" url:"limit"`
// Filter to trades on or after this timestamp.
Since Time `json:"since" url:"since"`
// If set to true, sorts trades in descending order, otherwise ascending
// order will be assumed.
SortDesc bool `json:"sort_desc" url:"sort_desc"`
}
// ListUserTradesResponse is the response struct for ListUserTrades.
type ListUserTradesResponse struct {
Trades []Trade `json:"trades"`
}
// ListUserTrades makes a call to GET /api/1/listtrades.
//
// Returns a list of the recent Trades for a given currency pair for this user, sorted by oldest first.
// If <code>before</code> is specified, then Trades are returned sorted by most-recent first.
//
// <code>type</code> in the response indicates the type of Order that was placed to participate in the trade.
// Possible types: <code>BID</code>, <code>ASK</code>.
//