forked from ccxt/go-binance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
1089 lines (887 loc) · 38.8 KB
/
client.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 binance
import (
"bytes"
"context"
"crypto/hmac"
"crypto/sha256"
"crypto/tls"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
"time"
"github.com/bitly/go-simplejson"
jsoniter "github.com/json-iterator/go"
"github.com/adshao/go-binance/v2/common"
"github.com/adshao/go-binance/v2/delivery"
"github.com/adshao/go-binance/v2/eoptions"
"github.com/adshao/go-binance/v2/futures"
)
// SideType define side type of order
type SideType string
// OrderType define order type
type OrderType string
// TimeInForceType define time in force type of order
type TimeInForceType string
// NewOrderRespType define response JSON verbosity
type NewOrderRespType string
// OrderStatusType define order status type
type OrderStatusType string
// SymbolType define symbol type
type SymbolType string
// SymbolStatusType define symbol status type
type SymbolStatusType string
// SymbolFilterType define symbol filter type
type SymbolFilterType string
// UserDataEventType define spot user data event type
type UserDataEventType string
// MarginTransferType define margin transfer type
type MarginTransferType int
// MarginLoanStatusType define margin loan status type
type MarginLoanStatusType string
// MarginRepayStatusType define margin repay status type
type MarginRepayStatusType string
// FuturesTransferStatusType define futures transfer status type
type FuturesTransferStatusType string
// SideEffectType define side effect type for orders
type SideEffectType string
// FuturesTransferType define futures transfer type
type FuturesTransferType int
// TransactionType define transaction type
type TransactionType string
// LendingType define the type of lending (flexible saving, activity, ...)
type LendingType string
// StakingProduct define the staking product (locked staking, flexible defi staking, locked defi staking, ...)
type StakingProduct string
// StakingTransactionType define the staking transaction type (subscription, redemption, interest)
type StakingTransactionType string
// LiquidityOperationType define the type of adding/removing liquidity to a liquidity pool(COMBINATION, SINGLE)
type LiquidityOperationType string
// SwappingStatus define the status of swap when querying the swap history
type SwappingStatus int
// LiquidityRewardType define the type of reward we'd claim
type LiquidityRewardType int
// RewardClaimStatus define the status of claiming a reward
type RewardClaimStatus int
// RateLimitType define the rate limitation types
// see https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md#enum-definitions
type RateLimitType string
// RateLimitInterval define the rate limitation intervals
type RateLimitInterval string
// AccountType define the account types
type AccountType string
// SubAccountTransferType define the sub account transfer types
type SubAccountTransferType int
// UserUniversalTransferType define the user universal transfer types
type UserUniversalTransferType string
// UserUniversalTransferStatus define the user universal transfer status
type UserUniversalTransferStatusType string
// Endpoints
var (
BaseAPIMainURL = "https://api.binance.com"
BaseAPITestnetURL = "https://testnet.binance.vision"
)
// UseTestnet switch all the API endpoints from production to the testnet
var UseTestnet = false
// Redefining the standard package
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// Global enums
const (
SideTypeBuy SideType = "BUY"
SideTypeSell SideType = "SELL"
OrderTypeLimit OrderType = "LIMIT"
OrderTypeMarket OrderType = "MARKET"
OrderTypeLimitMaker OrderType = "LIMIT_MAKER"
OrderTypeStopLoss OrderType = "STOP_LOSS"
OrderTypeStopLossLimit OrderType = "STOP_LOSS_LIMIT"
OrderTypeTakeProfit OrderType = "TAKE_PROFIT"
OrderTypeTakeProfitLimit OrderType = "TAKE_PROFIT_LIMIT"
TimeInForceTypeGTC TimeInForceType = "GTC"
TimeInForceTypeIOC TimeInForceType = "IOC"
TimeInForceTypeFOK TimeInForceType = "FOK"
NewOrderRespTypeACK NewOrderRespType = "ACK"
NewOrderRespTypeRESULT NewOrderRespType = "RESULT"
NewOrderRespTypeFULL NewOrderRespType = "FULL"
OrderStatusTypeNew OrderStatusType = "NEW"
OrderStatusTypePartiallyFilled OrderStatusType = "PARTIALLY_FILLED"
OrderStatusTypeFilled OrderStatusType = "FILLED"
OrderStatusTypeCanceled OrderStatusType = "CANCELED"
OrderStatusTypePendingCancel OrderStatusType = "PENDING_CANCEL"
OrderStatusTypeRejected OrderStatusType = "REJECTED"
OrderStatusTypeExpired OrderStatusType = "EXPIRED"
OrderStatusExpiredInMatch OrderStatusType = "EXPIRED_IN_MATCH" // STP Expired
SymbolTypeSpot SymbolType = "SPOT"
SymbolStatusTypePreTrading SymbolStatusType = "PRE_TRADING"
SymbolStatusTypeTrading SymbolStatusType = "TRADING"
SymbolStatusTypePostTrading SymbolStatusType = "POST_TRADING"
SymbolStatusTypeEndOfDay SymbolStatusType = "END_OF_DAY"
SymbolStatusTypeHalt SymbolStatusType = "HALT"
SymbolStatusTypeAuctionMatch SymbolStatusType = "AUCTION_MATCH"
SymbolStatusTypeBreak SymbolStatusType = "BREAK"
SymbolFilterTypeLotSize SymbolFilterType = "LOT_SIZE"
SymbolFilterTypePriceFilter SymbolFilterType = "PRICE_FILTER"
SymbolFilterTypePercentPriceBySide SymbolFilterType = "PERCENT_PRICE_BY_SIDE"
SymbolFilterTypeMinNotional SymbolFilterType = "MIN_NOTIONAL"
SymbolFilterTypeNotional SymbolFilterType = "NOTIONAL"
SymbolFilterTypeIcebergParts SymbolFilterType = "ICEBERG_PARTS"
SymbolFilterTypeMarketLotSize SymbolFilterType = "MARKET_LOT_SIZE"
SymbolFilterTypeMaxNumOrders SymbolFilterType = "MAX_NUM_ORDERS"
SymbolFilterTypeMaxNumAlgoOrders SymbolFilterType = "MAX_NUM_ALGO_ORDERS"
SymbolFilterTypeTrailingDelta SymbolFilterType = "TRAILING_DELTA"
UserDataEventTypeOutboundAccountPosition UserDataEventType = "outboundAccountPosition"
UserDataEventTypeBalanceUpdate UserDataEventType = "balanceUpdate"
UserDataEventTypeExecutionReport UserDataEventType = "executionReport"
UserDataEventTypeListStatus UserDataEventType = "ListStatus"
MarginTransferTypeToMargin MarginTransferType = 1
MarginTransferTypeToMain MarginTransferType = 2
FuturesTransferTypeToFutures FuturesTransferType = 1
FuturesTransferTypeToMain FuturesTransferType = 2
MarginLoanStatusTypePending MarginLoanStatusType = "PENDING"
MarginLoanStatusTypeConfirmed MarginLoanStatusType = "CONFIRMED"
MarginLoanStatusTypeFailed MarginLoanStatusType = "FAILED"
MarginRepayStatusTypePending MarginRepayStatusType = "PENDING"
MarginRepayStatusTypeConfirmed MarginRepayStatusType = "CONFIRMED"
MarginRepayStatusTypeFailed MarginRepayStatusType = "FAILED"
FuturesTransferStatusTypePending FuturesTransferStatusType = "PENDING"
FuturesTransferStatusTypeConfirmed FuturesTransferStatusType = "CONFIRMED"
FuturesTransferStatusTypeFailed FuturesTransferStatusType = "FAILED"
SideEffectTypeNoSideEffect SideEffectType = "NO_SIDE_EFFECT"
SideEffectTypeMarginBuy SideEffectType = "MARGIN_BUY"
SideEffectTypeAutoRepay SideEffectType = "AUTO_REPAY"
TransactionTypeDeposit TransactionType = "0"
TransactionTypeWithdraw TransactionType = "1"
TransactionTypeBuy TransactionType = "0"
TransactionTypeSell TransactionType = "1"
LendingTypeFlexible LendingType = "DAILY"
LendingTypeFixed LendingType = "CUSTOMIZED_FIXED"
LendingTypeActivity LendingType = "ACTIVITY"
LiquidityOperationTypeCombination LiquidityOperationType = "COMBINATION"
LiquidityOperationTypeSingle LiquidityOperationType = "SINGLE"
timestampKey = "timestamp"
signatureKey = "signature"
recvWindowKey = "recvWindow"
StakingProductLockedStaking = "STAKING"
StakingProductFlexibleDeFiStaking = "F_DEFI"
StakingProductLockedDeFiStaking = "L_DEFI"
StakingTransactionTypeSubscription = "SUBSCRIPTION"
StakingTransactionTypeRedemption = "REDEMPTION"
StakingTransactionTypeInterest = "INTEREST"
SwappingStatusPending SwappingStatus = 0
SwappingStatusDone SwappingStatus = 1
SwappingStatusFailed SwappingStatus = 2
RewardTypeTrading LiquidityRewardType = 0
RewardTypeLiquidity LiquidityRewardType = 1
RewardClaimPending RewardClaimStatus = 0
RewardClaimDone RewardClaimStatus = 1
RateLimitTypeRequestWeight RateLimitType = "REQUEST_WEIGHT"
RateLimitTypeOrders RateLimitType = "ORDERS"
RateLimitTypeRawRequests RateLimitType = "RAW_REQUESTS"
RateLimitIntervalSecond RateLimitInterval = "SECOND"
RateLimitIntervalMinute RateLimitInterval = "MINUTE"
RateLimitIntervalDay RateLimitInterval = "DAY"
AccountTypeSpot AccountType = "SPOT"
AccountTypeMargin AccountType = "MARGIN"
AccountTypeIsolatedMargin AccountType = "ISOLATED_MARGIN"
AccountTypeUSDTFuture AccountType = "USDT_FUTURE"
AccountTypeCoinFuture AccountType = "COIN_FUTURE"
SubAccountTransferTypeTransferIn SubAccountTransferType = 1
SubAccountTransferTypeTransferOut SubAccountTransferType = 2
UserUniversalTransferTypeMainToUmFutures UserUniversalTransferType = "MAIN_UMFUTURE"
UserUniversalTransferTypeMainToCmFutures UserUniversalTransferType = "MAIN_CMFUTURE"
UserUniversalTransferTypeMainToMargin UserUniversalTransferType = "MAIN_MARGIN"
UserUniversalTransferTypeUmFuturesToMain UserUniversalTransferType = "UMFUTURE_MAIN"
UserUniversalTransferTypeUmFuturesToMargin UserUniversalTransferType = "UMFUTURE_MARGIN"
UserUniversalTransferTypeCmFuturesToMain UserUniversalTransferType = "CMFUTURE_MAIN"
UserUniversalTransferTypeMarginToMain UserUniversalTransferType = "MARGIN_MAIN"
UserUniversalTransferTypeMarginToUmFutures UserUniversalTransferType = "MARGIN_UMFUTURE"
UserUniversalTransferTypeMarginToCmFutures UserUniversalTransferType = "MARGIN_CMFUTURE"
UserUniversalTransferTypeCmFuturesToMargin UserUniversalTransferType = "CMFUTURE_MARGIN"
UserUniversalTransferTypeIsolatedMarginToMargin UserUniversalTransferType = "ISOLATEDMARGIN_MARGIN"
UserUniversalTransferTypeMarginToIsolatedMargin UserUniversalTransferType = "MARGIN_ISOLATEDMARGIN"
UserUniversalTransferTypeIsolatedMarginToIsolatedMargin UserUniversalTransferType = "ISOLATEDMARGIN_ISOLATEDMARGIN"
UserUniversalTransferTypeMainToFunding UserUniversalTransferType = "MAIN_FUNDING"
UserUniversalTransferTypeFundingToMain UserUniversalTransferType = "FUNDING_MAIN"
UserUniversalTransferTypeFundingToUmFutures UserUniversalTransferType = "FUNDING_UMFUTURE"
UserUniversalTransferTypeUmFuturesToFunding UserUniversalTransferType = "UMFUTURE_FUNDING"
UserUniversalTransferTypeMarginToFunding UserUniversalTransferType = "MARGIN_FUNDING"
UserUniversalTransferTypeFundingToMargin UserUniversalTransferType = "FUNDING_MARGIN"
UserUniversalTransferTypeFundingToCmFutures UserUniversalTransferType = "FUNDING_CMFUTURE"
UserUniversalTransferTypeCmFuturesToFunding UserUniversalTransferType = "CMFUTURE_FUNDING"
UserUniversalTransferTypeMainToOption UserUniversalTransferType = "MAIN_OPTION"
UserUniversalTransferTypeOptionToMain UserUniversalTransferType = "OPTION_MAIN"
UserUniversalTransferTypeUmFuturesToOption UserUniversalTransferType = "UMFUTURE_OPTION"
UserUniversalTransferTypeOptionToUmFutures UserUniversalTransferType = "OPTION_UMFUTURE"
UserUniversalTransferTypeMarginToOption UserUniversalTransferType = "MARGIN_OPTION"
UserUniversalTransferTypeOptionToMargin UserUniversalTransferType = "OPTION_MARGIN"
UserUniversalTransferTypeFundingToOption UserUniversalTransferType = "FUNDING_OPTION"
UserUniversalTransferTypeOptionToFunding UserUniversalTransferType = "OPTION_FUNDING"
UserUniversalTransferTypeMainToPortfolioMargin UserUniversalTransferType = "MAIN_PORTFOLIO_MARGIN"
UserUniversalTransferTypePortfolioMarginToMain UserUniversalTransferType = "PORTFOLIO_MARGIN_MAIN"
UserUniversalTransferTypeMainToIsolatedMargin UserUniversalTransferType = "MAIN_ISOLATED_MARGIN"
UserUniversalTransferTypeIsolatedMarginToMain UserUniversalTransferType = "ISOLATED_MARGIN_MAIN"
UserUniversalTransferStatusTypePending UserUniversalTransferStatusType = "PENDING"
UserUniversalTransferStatusTypeConfirmed UserUniversalTransferStatusType = "CONFIRMED"
UserUniversalTransferStatusTypeFailed UserUniversalTransferStatusType = "FAILED"
)
func currentTimestamp() int64 {
return FormatTimestamp(time.Now())
}
// FormatTimestamp formats a time into Unix timestamp in milliseconds, as requested by Binance.
func FormatTimestamp(t time.Time) int64 {
return t.UnixNano() / int64(time.Millisecond)
}
func newJSON(data []byte) (j *simplejson.Json, err error) {
j, err = simplejson.NewJson(data)
if err != nil {
return nil, err
}
return j, nil
}
// getAPIEndpoint return the base endpoint of the Rest API according the UseTestnet flag
func getAPIEndpoint() string {
if UseTestnet {
return BaseAPITestnetURL
}
return BaseAPIMainURL
}
// NewClient initialize an API client instance with API key and secret key.
// You should always call this function before using this SDK.
// Services will be created by the form client.NewXXXService().
func NewClient(apiKey, secretKey string) *Client {
return &Client{
APIKey: apiKey,
SecretKey: secretKey,
BaseURL: getAPIEndpoint(),
UserAgent: "Binance/golang",
HTTPClient: http.DefaultClient,
Logger: log.New(os.Stderr, "Binance-golang ", log.LstdFlags),
}
}
// NewProxiedClient passing a proxy url
func NewProxiedClient(apiKey, secretKey, proxyUrl string) *Client {
proxy, err := url.Parse(proxyUrl)
if err != nil {
log.Fatal(err)
}
tr := &http.Transport{
Proxy: http.ProxyURL(proxy),
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
return &Client{
APIKey: apiKey,
SecretKey: secretKey,
BaseURL: getAPIEndpoint(),
UserAgent: "Binance/golang",
HTTPClient: &http.Client{
Transport: tr,
},
Logger: log.New(os.Stderr, "Binance-golang ", log.LstdFlags),
}
}
// NewFuturesClient initialize client for futures API
func NewFuturesClient(apiKey, secretKey string) *futures.Client {
return futures.NewClient(apiKey, secretKey)
}
// NewDeliveryClient initialize client for coin-M futures API
func NewDeliveryClient(apiKey, secretKey string) *delivery.Client {
return delivery.NewClient(apiKey, secretKey)
}
// NewOptionsClient initialize client for eoptions API
func NewOptionsClient(apiKey, secretKey string) *eoptions.Client {
return eoptions.NewClient(apiKey, secretKey)
}
type doFunc func(req *http.Request) (*http.Response, error)
// Client define API client
type Client struct {
APIKey string
SecretKey string
BaseURL string
UserAgent string
HTTPClient *http.Client
Debug bool
Logger *log.Logger
TimeOffset int64
do doFunc
}
func (c *Client) debug(format string, v ...interface{}) {
if c.Debug {
c.Logger.Printf(format, v...)
}
}
func (c *Client) parseRequest(r *request, opts ...RequestOption) (err error) {
// set request options from user
for _, opt := range opts {
opt(r)
}
err = r.validate()
if err != nil {
return err
}
fullURL := fmt.Sprintf("%s%s", c.BaseURL, r.endpoint)
if r.recvWindow > 0 {
r.setParam(recvWindowKey, r.recvWindow)
}
if r.secType == secTypeSigned {
r.setParam(timestampKey, currentTimestamp()-c.TimeOffset)
}
queryString := r.query.Encode()
body := &bytes.Buffer{}
bodyString := r.form.Encode()
header := http.Header{}
if r.header != nil {
header = r.header.Clone()
}
if bodyString != "" {
header.Set("Content-Type", "application/x-www-form-urlencoded")
body = bytes.NewBufferString(bodyString)
}
if r.secType == secTypeAPIKey || r.secType == secTypeSigned {
header.Set("X-MBX-APIKEY", c.APIKey)
}
if r.secType == secTypeSigned {
raw := fmt.Sprintf("%s%s", queryString, bodyString)
mac := hmac.New(sha256.New, []byte(c.SecretKey))
_, err = mac.Write([]byte(raw))
if err != nil {
return err
}
v := url.Values{}
v.Set(signatureKey, fmt.Sprintf("%x", (mac.Sum(nil))))
if queryString == "" {
queryString = v.Encode()
} else {
queryString = fmt.Sprintf("%s&%s", queryString, v.Encode())
}
}
if queryString != "" {
fullURL = fmt.Sprintf("%s?%s", fullURL, queryString)
}
c.debug("full url: %s, body: %s", fullURL, bodyString)
r.fullURL = fullURL
r.header = header
r.body = body
return nil
}
func (c *Client) callAPI(ctx context.Context, r *request, opts ...RequestOption) (data []byte, err error) {
err = c.parseRequest(r, opts...)
if err != nil {
return []byte{}, err
}
req, err := http.NewRequest(r.method, r.fullURL, r.body)
if err != nil {
return []byte{}, err
}
req = req.WithContext(ctx)
req.Header = r.header
c.debug("request: %#v", req)
f := c.do
if f == nil {
f = c.HTTPClient.Do
}
res, err := f(req)
if err != nil {
return []byte{}, err
}
data, err = ioutil.ReadAll(res.Body)
if err != nil {
return []byte{}, err
}
defer func() {
cerr := res.Body.Close()
// Only overwrite the retured error if the original error was nil and an
// error occurred while closing the body.
if err == nil && cerr != nil {
err = cerr
}
}()
c.debug("response: %#v", res)
c.debug("response body: %s", string(data))
c.debug("response status code: %d", res.StatusCode)
if res.StatusCode >= http.StatusBadRequest {
apiErr := new(common.APIError)
e := json.Unmarshal(data, apiErr)
if e != nil {
c.debug("failed to unmarshal json: %s", e)
}
return nil, apiErr
}
return data, nil
}
// SetApiEndpoint set api Endpoint
func (c *Client) SetApiEndpoint(url string) *Client {
c.BaseURL = url
return c
}
// NewPingService init ping service
func (c *Client) NewPingService() *PingService {
return &PingService{c: c}
}
// NewServerTimeService init server time service
func (c *Client) NewServerTimeService() *ServerTimeService {
return &ServerTimeService{c: c}
}
// NewSetServerTimeService init set server time service
func (c *Client) NewSetServerTimeService() *SetServerTimeService {
return &SetServerTimeService{c: c}
}
// NewDepthService init depth service
func (c *Client) NewDepthService() *DepthService {
return &DepthService{c: c}
}
// NewAggTradesService init aggregate trades service
func (c *Client) NewAggTradesService() *AggTradesService {
return &AggTradesService{c: c}
}
// NewRecentTradesService init recent trades service
func (c *Client) NewRecentTradesService() *RecentTradesService {
return &RecentTradesService{c: c}
}
// NewKlinesService init klines service
func (c *Client) NewKlinesService() *KlinesService {
return &KlinesService{c: c}
}
// NewListPriceChangeStatsService init list prices change stats service
func (c *Client) NewListPriceChangeStatsService() *ListPriceChangeStatsService {
return &ListPriceChangeStatsService{c: c}
}
// NewListPricesService init listing prices service
func (c *Client) NewListPricesService() *ListPricesService {
return &ListPricesService{c: c}
}
// NewListBookTickersService init listing booking tickers service
func (c *Client) NewListBookTickersService() *ListBookTickersService {
return &ListBookTickersService{c: c}
}
// NewListSymbolTickerService init listing symbols tickers
func (c *Client) NewListSymbolTickerService() *ListSymbolTickerService {
return &ListSymbolTickerService{c: c}
}
// NewCreateOrderService init creating order service
func (c *Client) NewCreateOrderService() *CreateOrderService {
return &CreateOrderService{c: c}
}
// NewCreateOCOService init creating OCO service
func (c *Client) NewCreateOCOService() *CreateOCOService {
return &CreateOCOService{c: c}
}
// NewCancelOCOService init cancel OCO service
func (c *Client) NewCancelOCOService() *CancelOCOService {
return &CancelOCOService{c: c}
}
// NewGetOrderService init get order service
func (c *Client) NewGetOrderService() *GetOrderService {
return &GetOrderService{c: c}
}
// NewCancelOrderService init cancel order service
func (c *Client) NewCancelOrderService() *CancelOrderService {
return &CancelOrderService{c: c}
}
// NewCancelOpenOrdersService init cancel open orders service
func (c *Client) NewCancelOpenOrdersService() *CancelOpenOrdersService {
return &CancelOpenOrdersService{c: c}
}
// NewListOpenOrdersService init list open orders service
func (c *Client) NewListOpenOrdersService() *ListOpenOrdersService {
return &ListOpenOrdersService{c: c}
}
// NewListOpenOcoService init list open oco service
func (c *Client) NewListOpenOcoService() *ListOpenOcoService {
return &ListOpenOcoService{c: c}
}
// NewListOrdersService init listing orders service
func (c *Client) NewListOrdersService() *ListOrdersService {
return &ListOrdersService{c: c}
}
// NewGetAccountService init getting account service
func (c *Client) NewGetAccountService() *GetAccountService {
return &GetAccountService{c: c}
}
// NewGetAPIKeyPermission init getting API key permission
func (c *Client) NewGetAPIKeyPermission() *GetAPIKeyPermission {
return &GetAPIKeyPermission{c: c}
}
// NewSavingFlexibleProductPositionsService get flexible products positions (Savings)
func (c *Client) NewSavingFlexibleProductPositionsService() *SavingFlexibleProductPositionsService {
return &SavingFlexibleProductPositionsService{c: c}
}
// NewSavingFixedProjectPositionsService get fixed project positions (Savings)
func (c *Client) NewSavingFixedProjectPositionsService() *SavingFixedProjectPositionsService {
return &SavingFixedProjectPositionsService{c: c}
}
// NewListSavingsFlexibleProductsService get flexible products list (Savings)
func (c *Client) NewListSavingsFlexibleProductsService() *ListSavingsFlexibleProductsService {
return &ListSavingsFlexibleProductsService{c: c}
}
// NewPurchaseSavingsFlexibleProductService purchase a flexible product (Savings)
func (c *Client) NewPurchaseSavingsFlexibleProductService() *PurchaseSavingsFlexibleProductService {
return &PurchaseSavingsFlexibleProductService{c: c}
}
// NewRedeemSavingsFlexibleProductService redeem a flexible product (Savings)
func (c *Client) NewRedeemSavingsFlexibleProductService() *RedeemSavingsFlexibleProductService {
return &RedeemSavingsFlexibleProductService{c: c}
}
// NewListSavingsFixedAndActivityProductsService get fixed and activity product list (Savings)
func (c *Client) NewListSavingsFixedAndActivityProductsService() *ListSavingsFixedAndActivityProductsService {
return &ListSavingsFixedAndActivityProductsService{c: c}
}
// NewGetAccountSnapshotService init getting account snapshot service
func (c *Client) NewGetAccountSnapshotService() *GetAccountSnapshotService {
return &GetAccountSnapshotService{c: c}
}
// NewListTradesService init listing trades service
func (c *Client) NewListTradesService() *ListTradesService {
return &ListTradesService{c: c}
}
// NewHistoricalTradesService init listing trades service
func (c *Client) NewHistoricalTradesService() *HistoricalTradesService {
return &HistoricalTradesService{c: c}
}
// NewListDepositsService init listing deposits service
func (c *Client) NewListDepositsService() *ListDepositsService {
return &ListDepositsService{c: c}
}
// NewGetDepositAddressService init getting deposit address service
func (c *Client) NewGetDepositAddressService() *GetDepositsAddressService {
return &GetDepositsAddressService{c: c}
}
// NewCreateWithdrawService init creating withdraw service
func (c *Client) NewCreateWithdrawService() *CreateWithdrawService {
return &CreateWithdrawService{c: c}
}
// NewListWithdrawsService init listing withdraw service
func (c *Client) NewListWithdrawsService() *ListWithdrawsService {
return &ListWithdrawsService{c: c}
}
// NewStartUserStreamService init starting user stream service
func (c *Client) NewStartUserStreamService() *StartUserStreamService {
return &StartUserStreamService{c: c}
}
// NewKeepaliveUserStreamService init keep alive user stream service
func (c *Client) NewKeepaliveUserStreamService() *KeepaliveUserStreamService {
return &KeepaliveUserStreamService{c: c}
}
// NewCloseUserStreamService init closing user stream service
func (c *Client) NewCloseUserStreamService() *CloseUserStreamService {
return &CloseUserStreamService{c: c}
}
// NewExchangeInfoService init exchange info service
func (c *Client) NewExchangeInfoService() *ExchangeInfoService {
return &ExchangeInfoService{c: c}
}
// NewRateLimitService init rate limit service
func (c *Client) NewRateLimitService() *RateLimitService {
return &RateLimitService{c: c}
}
// NewGetAssetDetailService init get asset detail service
func (c *Client) NewGetAssetDetailService() *GetAssetDetailService {
return &GetAssetDetailService{c: c}
}
// NewAveragePriceService init average price service
func (c *Client) NewAveragePriceService() *AveragePriceService {
return &AveragePriceService{c: c}
}
// NewMarginTransferService init margin account transfer service
func (c *Client) NewMarginTransferService() *MarginTransferService {
return &MarginTransferService{c: c}
}
// NewMarginLoanService init margin account loan service
func (c *Client) NewMarginLoanService() *MarginLoanService {
return &MarginLoanService{c: c}
}
// NewMarginRepayService init margin account repay service
func (c *Client) NewMarginRepayService() *MarginRepayService {
return &MarginRepayService{c: c}
}
// NewCreateMarginOrderService init creating margin order service
func (c *Client) NewCreateMarginOrderService() *CreateMarginOrderService {
return &CreateMarginOrderService{c: c}
}
// NewCancelMarginOrderService init cancel order service
func (c *Client) NewCancelMarginOrderService() *CancelMarginOrderService {
return &CancelMarginOrderService{c: c}
}
// NewCreateMarginOCOService init creating margin order service
func (c *Client) NewCreateMarginOCOService() *CreateMarginOCOService {
return &CreateMarginOCOService{c: c}
}
// NewCancelMarginOCOService init cancel order service
func (c *Client) NewCancelMarginOCOService() *CancelMarginOCOService {
return &CancelMarginOCOService{c: c}
}
// NewGetMarginOrderService init get order service
func (c *Client) NewGetMarginOrderService() *GetMarginOrderService {
return &GetMarginOrderService{c: c}
}
// NewListMarginLoansService init list margin loan service
func (c *Client) NewListMarginLoansService() *ListMarginLoansService {
return &ListMarginLoansService{c: c}
}
// NewListMarginRepaysService init list margin repay service
func (c *Client) NewListMarginRepaysService() *ListMarginRepaysService {
return &ListMarginRepaysService{c: c}
}
// NewGetMarginAccountService init get margin account service
func (c *Client) NewGetMarginAccountService() *GetMarginAccountService {
return &GetMarginAccountService{c: c}
}
// NewGetIsolatedMarginAccountService init get isolated margin asset service
func (c *Client) NewGetIsolatedMarginAccountService() *GetIsolatedMarginAccountService {
return &GetIsolatedMarginAccountService{c: c}
}
func (c *Client) NewIsolatedMarginTransferService() *IsolatedMarginTransferService {
return &IsolatedMarginTransferService{c: c}
}
// NewGetMarginAssetService init get margin asset service
func (c *Client) NewGetMarginAssetService() *GetMarginAssetService {
return &GetMarginAssetService{c: c}
}
// NewGetMarginPairService init get margin pair service
func (c *Client) NewGetMarginPairService() *GetMarginPairService {
return &GetMarginPairService{c: c}
}
// NewGetMarginAllPairsService init get margin all pairs service
func (c *Client) NewGetMarginAllPairsService() *GetMarginAllPairsService {
return &GetMarginAllPairsService{c: c}
}
// NewGetMarginPriceIndexService init get margin price index service
func (c *Client) NewGetMarginPriceIndexService() *GetMarginPriceIndexService {
return &GetMarginPriceIndexService{c: c}
}
// NewListMarginOpenOrdersService init list margin open orders service
func (c *Client) NewListMarginOpenOrdersService() *ListMarginOpenOrdersService {
return &ListMarginOpenOrdersService{c: c}
}
// NewListMarginOrdersService init list margin all orders service
func (c *Client) NewListMarginOrdersService() *ListMarginOrdersService {
return &ListMarginOrdersService{c: c}
}
// NewListMarginTradesService init list margin trades service
func (c *Client) NewListMarginTradesService() *ListMarginTradesService {
return &ListMarginTradesService{c: c}
}
// NewGetMaxBorrowableService init get max borrowable service
func (c *Client) NewGetMaxBorrowableService() *GetMaxBorrowableService {
return &GetMaxBorrowableService{c: c}
}
// NewGetMaxTransferableService init get max transferable service
func (c *Client) NewGetMaxTransferableService() *GetMaxTransferableService {
return &GetMaxTransferableService{c: c}
}
// NewStartMarginUserStreamService init starting margin user stream service
func (c *Client) NewStartMarginUserStreamService() *StartMarginUserStreamService {
return &StartMarginUserStreamService{c: c}
}
// NewKeepaliveMarginUserStreamService init keep alive margin user stream service
func (c *Client) NewKeepaliveMarginUserStreamService() *KeepaliveMarginUserStreamService {
return &KeepaliveMarginUserStreamService{c: c}
}
// NewCloseMarginUserStreamService init closing margin user stream service
func (c *Client) NewCloseMarginUserStreamService() *CloseMarginUserStreamService {
return &CloseMarginUserStreamService{c: c}
}
// NewStartIsolatedMarginUserStreamService init starting margin user stream service
func (c *Client) NewStartIsolatedMarginUserStreamService() *StartIsolatedMarginUserStreamService {
return &StartIsolatedMarginUserStreamService{c: c}
}
// NewKeepaliveIsolatedMarginUserStreamService init keep alive margin user stream service
func (c *Client) NewKeepaliveIsolatedMarginUserStreamService() *KeepaliveIsolatedMarginUserStreamService {
return &KeepaliveIsolatedMarginUserStreamService{c: c}
}
// NewCloseIsolatedMarginUserStreamService init closing margin user stream service
func (c *Client) NewCloseIsolatedMarginUserStreamService() *CloseIsolatedMarginUserStreamService {
return &CloseIsolatedMarginUserStreamService{c: c}
}
// NewFuturesTransferService init futures transfer service
func (c *Client) NewFuturesTransferService() *FuturesTransferService {
return &FuturesTransferService{c: c}
}
// NewListFuturesTransferService init list futures transfer service
func (c *Client) NewListFuturesTransferService() *ListFuturesTransferService {
return &ListFuturesTransferService{c: c}
}
// NewListDustLogService init list dust log service
func (c *Client) NewListDustLogService() *ListDustLogService {
return &ListDustLogService{c: c}
}
// NewDustTransferService init dust transfer service
func (c *Client) NewDustTransferService() *DustTransferService {
return &DustTransferService{c: c}
}
// NewListDustService init dust list service
func (c *Client) NewListDustService() *ListDustService {
return &ListDustService{c: c}
}
// NewTransferToSubAccountService transfer to subaccount service
func (c *Client) NewTransferToSubAccountService() *TransferToSubAccountService {
return &TransferToSubAccountService{c: c}
}
// NewSubaccountAssetsService init list subaccount assets
func (c *Client) NewSubaccountAssetsService() *SubaccountAssetsService {
return &SubaccountAssetsService{c: c}
}
// NewSubaccountSpotSummaryService init subaccount spot summary
func (c *Client) NewSubaccountSpotSummaryService() *SubaccountSpotSummaryService {
return &SubaccountSpotSummaryService{c: c}
}
// NewSubaccountDepositAddressService init subaccount deposit address service
func (c *Client) NewSubaccountDepositAddressService() *SubaccountDepositAddressService {
return &SubaccountDepositAddressService{c: c}
}
// NewAssetDividendService init the asset dividend list service
func (c *Client) NewAssetDividendService() *AssetDividendService {
return &AssetDividendService{c: c}
}
// NewUserUniversalTransferService
func (c *Client) NewUserUniversalTransferService() *CreateUserUniversalTransferService {
return &CreateUserUniversalTransferService{c: c}
}
// NewAllCoinsInformation
func (c *Client) NewGetAllCoinsInfoService() *GetAllCoinsInfoService {
return &GetAllCoinsInfoService{c: c}
}
// NewDustTransferService init Get All Margin Assets service
func (c *Client) NewGetAllMarginAssetsService() *GetAllMarginAssetsService {
return &GetAllMarginAssetsService{c: c}
}
// NewFiatDepositWithdrawHistoryService init the fiat deposit/withdraw history service
func (c *Client) NewFiatDepositWithdrawHistoryService() *FiatDepositWithdrawHistoryService {
return &FiatDepositWithdrawHistoryService{c: c}
}
// NewFiatPaymentsHistoryService init the fiat payments history service
func (c *Client) NewFiatPaymentsHistoryService() *FiatPaymentsHistoryService {
return &FiatPaymentsHistoryService{c: c}
}
// NewPayTransactionService init the pay transaction service
func (c *Client) NewPayTradeHistoryService() *PayTradeHistoryService {
return &PayTradeHistoryService{c: c}
}
// NewFiatPaymentsHistoryService init the spot rebate history service
func (c *Client) NewSpotRebateHistoryService() *SpotRebateHistoryService {
return &SpotRebateHistoryService{c: c}
}
// NewConvertTradeHistoryService init the convert trade history service
func (c *Client) NewConvertTradeHistoryService() *ConvertTradeHistoryService {
return &ConvertTradeHistoryService{c: c}
}
// NewGetIsolatedMarginAllPairsService init get isolated margin all pairs service
func (c *Client) NewGetIsolatedMarginAllPairsService() *GetIsolatedMarginAllPairsService {
return &GetIsolatedMarginAllPairsService{c: c}
}
// NewInterestHistoryService init the interest history service
func (c *Client) NewInterestHistoryService() *InterestHistoryService {
return &InterestHistoryService{c: c}
}
// NewTradeFeeService init the trade fee service
func (c *Client) NewTradeFeeService() *TradeFeeService {
return &TradeFeeService{c: c}
}
// NewC2CTradeHistoryService init the c2c trade history service
func (c *Client) NewC2CTradeHistoryService() *C2CTradeHistoryService {
return &C2CTradeHistoryService{c: c}
}
// NewStakingProductPositionService init the staking product position service
func (c *Client) NewStakingProductPositionService() *StakingProductPositionService {
return &StakingProductPositionService{c: c}
}
// NewStakingHistoryService init the staking history service
func (c *Client) NewStakingHistoryService() *StakingHistoryService {
return &StakingHistoryService{c: c}
}
// NewGetAllLiquidityPoolService init the get all swap pool service
func (c *Client) NewGetAllLiquidityPoolService() *GetAllLiquidityPoolService {
return &GetAllLiquidityPoolService{c: c}
}
// NewGetLiquidityPoolDetailService init the get liquidity pool detial service
func (c *Client) NewGetLiquidityPoolDetailService() *GetLiquidityPoolDetailService {
return &GetLiquidityPoolDetailService{c: c}
}
// NewAddLiquidityPreviewService init the add liquidity preview service
func (c *Client) NewAddLiquidityPreviewService() *AddLiquidityPreviewService {
return &AddLiquidityPreviewService{c: c}
}
// NewGetSwapQuoteService init the add liquidity preview service
func (c *Client) NewGetSwapQuoteService() *GetSwapQuoteService {
return &GetSwapQuoteService{c: c}
}
// NewSwapService init the swap service
func (c *Client) NewSwapService() *SwapService {
return &SwapService{c: c}
}
// NewAddLiquidityService init the add liquidity service
func (c *Client) NewAddLiquidityService() *AddLiquidityService {
return &AddLiquidityService{c: c}
}