forked from nntaoli-project/goex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OKExV5.go
720 lines (626 loc) · 18.8 KB
/
OKExV5.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
package okex
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"
"strings"
"time"
. "github.com/YuxSccc/goex"
"github.com/YuxSccc/goex/internal/logger"
)
const (
v5RestBaseUrl = "https://www.okex.com"
v5WsBaseUrl = "wss://ws.okex.com:8443/ws/v5"
CONTENT_TYPE = "Content-Type"
ACCEPT = "Accept"
APPLICATION_JSON_UTF8 = "application/json; charset=UTF-8"
APPLICATION_JSON = "application/json"
OK_ACCESS_KEY = "OK-ACCESS-KEY"
OK_ACCESS_SIGN = "OK-ACCESS-SIGN"
OK_ACCESS_TIMESTAMP = "OK-ACCESS-TIMESTAMP"
OK_ACCESS_PASSPHRASE = "OK-ACCESS-PASSPHRASE"
)
// base interface for okex v5
type OKExV5 struct {
config *APIConfig
customCIDFunc func() string
}
func NewOKExV5(config *APIConfig) *OKExV5 {
if config.Endpoint == "" {
config.Endpoint = v5RestBaseUrl
}
okex := &OKExV5{config: config}
return okex
}
func (ok *OKExV5) ExchangeName() string {
return OKEX
}
func (ok *OKExV5) SetCustomCID(f func() string) {
ok.customCIDFunc = f
}
//获取所有产品行情信息
//产品类型instType
// SPOT:币币
// SWAP:永续合约
// FUTURES:交割合约
// OPTION:期权
// func (ok *OKExV5) GetTickersV5(instType, uly string) ([]Ticker, error) {
// urlPath := fmt.Sprintf("/api/v5/market/tickers?instType=%s", instType)
// if instType == "SWAP" || instType == "FUTURES" || instType == "OPTION" {
// urlPath = fmt.Sprintf("%s&uly=%s", urlPath, uly)
// }
// var response spotTickerResponse
// err := ok.OKEx.DoAuthorRequest("GET", urlPath, "", &response)
// if err != nil {
// return nil, err
// }
// date, _ := time.Parse(time.RFC3339, response.Timestamp)
// return &Ticker{
// Pair: currency,
// Last: response.Last,
// High: response.High24h,
// Low: response.Low24h,
// Sell: response.BestAsk,
// Buy: response.BestBid,
// Vol: response.BaseVolume24h,
// Date: uint64(time.Duration(date.UnixNano() / int64(time.Millisecond)))}, nil
// }
type TickerV5 struct {
InstId string `json:"instId"`
Last float64 `json:"last,string"`
BuyPrice float64 `json:"bidPx,string"`
BuySize float64 `json:"bidSz,string"`
SellPrice float64 `json:"askPx,string"`
SellSize float64 `json:"askSz,string"`
Open float64 `json:"open24h,string"`
High float64 `json:"high24h,string"`
Low float64 `json:"low24h,string"`
Vol float64 `json:"volCcy24h,string"`
VolQuote float64 `json:"vol24h,string"`
Timestamp uint64 `json:"ts,string"` // 单位:ms
}
func (ok *OKExV5) GetTickerV5(instId string) (*TickerV5, error) {
urlPath := fmt.Sprintf("%s/api/v5/market/ticker?instId=%s", ok.config.Endpoint, instId)
type TickerV5Response struct {
Code int `json:"code,string"`
Msg string `json:"msg"`
Data []TickerV5 `json:"data"`
}
var response TickerV5Response
err := HttpGet4(ok.config.HttpClient, urlPath, nil, &response)
if err != nil {
return nil, err
}
if response.Code != 0 {
return nil, fmt.Errorf("GetTickerV5 error:%s", response.Msg)
}
return &response.Data[0], nil
}
type DepthV5 struct {
Asks [][]string `json:"asks,string"`
Bids [][]string `json:"bids,string"`
Timestamp uint64 `json:"ts,string"` // 单位:ms
}
func (ok *OKExV5) GetDepthV5(instId string, size int) (*DepthV5, error) {
urlPath := fmt.Sprintf("%s/api/v5/market/books?instId=%s", ok.config.Endpoint, instId)
if size > 0 {
urlPath = fmt.Sprintf("%s&sz=%d", urlPath, size)
}
type DepthV5Response struct {
Code int `json:"code,string"`
Msg string `json:"msg"`
Data []DepthV5 `json:"data"`
}
var response DepthV5Response
err := HttpGet4(ok.config.HttpClient, urlPath, nil, &response)
if err != nil {
return nil, err
}
if response.Code != 0 {
return nil, fmt.Errorf("GetDepthV5 error:%s", response.Msg)
}
return &response.Data[0], nil
}
func (ok *OKExV5) GetKlineRecordsV5(instId string, period KlinePeriod, params *url.Values) ([][]string, error) {
urlPath := fmt.Sprintf("%s/api/v5/market/candles?instId=%s&bar=%s", ok.config.Endpoint, instId, ok.adaptKLineBar(period))
if params.Encode() != "" {
urlPath = fmt.Sprintf("%s&%s", urlPath, params.Encode())
}
logger.Debugf("[OKExV5] GetKlineRecordsV5 Url: %s", urlPath)
type CandleResponse struct {
Code int `json:"code,string"`
Msg string `json:"msg"`
Data [][]string `json:"data"`
}
var response CandleResponse
err := HttpGet4(ok.config.HttpClient, urlPath, nil, &response)
if err != nil {
return nil, err
}
if response.Code != 0 {
return nil, fmt.Errorf("GetKlineRecordsV5 error:%s", response.Msg)
}
return response.Data, nil
}
/*
Get a iso time
eg: 2018-03-16T18:02:48.284Z
*/
func IsoTime() string {
utcTime := time.Now().UTC()
iso := utcTime.String()
isoBytes := []byte(iso)
iso = string(isoBytes[:10]) + "T" + string(isoBytes[11:23]) + "Z"
return iso
}
/*
Get a http request body is a json string and a byte array.
*/
func (ok *OKExV5) BuildRequestBody(params interface{}) (string, *bytes.Reader, error) {
if params == nil {
return "", nil, errors.New("illegal parameter")
}
data, err := json.Marshal(params)
if err != nil {
//log.Println(err)
return "", nil, errors.New("json convert string error")
}
jsonBody := string(data)
binBody := bytes.NewReader(data)
return jsonBody, binBody, nil
}
func (ok *OKExV5) doParamSign(httpMethod, uri, requestBody string) (string, string) {
timestamp := IsoTime()
preText := fmt.Sprintf("%s%s%s%s", timestamp, strings.ToUpper(httpMethod), uri, requestBody)
//log.Println("preHash", preText)
sign, _ := GetParamHmacSHA256Base64Sign(ok.config.ApiSecretKey, preText)
return sign, timestamp
}
func (ok *OKExV5) DoAuthorRequest(httpMethod, uri, reqBody string, response interface{}) error {
url := ok.config.Endpoint + uri
sign, timestamp := ok.doParamSign(httpMethod, uri, reqBody)
//logger.Log.Debug("timestamp=", timestamp, ", sign=", sign)
resp, err := NewHttpRequest(ok.config.HttpClient, httpMethod, url, reqBody, map[string]string{
CONTENT_TYPE: APPLICATION_JSON_UTF8,
ACCEPT: APPLICATION_JSON,
//COOKIE: LOCALE + "en_US",
OK_ACCESS_KEY: ok.config.ApiKey,
OK_ACCESS_PASSPHRASE: ok.config.ApiPassphrase,
OK_ACCESS_SIGN: sign,
OK_ACCESS_TIMESTAMP: fmt.Sprint(timestamp)})
if err != nil {
//log.Println(err)
return err
} else {
logger.Log.Debug(string(resp))
return json.Unmarshal(resp, &response)
}
}
type CreateOrderParam struct {
Symbol string //产品ID
TradeMode string //交易模式, 保证金模式:isolated:逐仓 ;cross:全仓, 非保证金模式:cash:非保证金
Side string // 订单方向 buy:买 sell:卖
OrderType string //订单类型
// market:市价单
// limit:限价单
// post_only:只做maker单
// fok:全部成交或立即取消
// ioc:立即成交并取消剩余
Size string // 委托数量
PosSide string //持仓方向 在双向持仓模式下必填,且仅可选择 long 或 short
Price string //委托价格,仅适用于限价单
CCY string // 保证金币种,仅适用于单币种保证金模式下的全仓杠杆订单
ClientOrdId string //客户自定义订单ID 字母(区分大小写)与数字的组合,可以是纯字母、纯数字且长度要在1-32位之间。
Tag string //订单标签 字母(区分大小写)与数字的组合,可以是纯字母、纯数字,且长度在1-8位之间。
ReduceOnly bool //是否只减仓,true 或 false,默认false 仅适用于币币杠杆订单
}
type OrderSummaryV5 struct {
OrdId string `json:"ordId"`
ClientOrdId string `json:"clOrdId"` //客户自定义订单ID 字母(区分大小写)与数字的组合,可以是纯字母、纯数字且长度要在1-32位之间。
Tag string `json:"tag"`
SCode string `json:"sCode"`
SMsg string `json:"sMsg"`
}
func (ok *OKExV5) CreateOrder(param *CreateOrderParam) (*OrderSummaryV5, error) {
reqBody := make(map[string]interface{})
reqBody["instId"] = param.Symbol
reqBody["tdMode"] = param.TradeMode
reqBody["side"] = param.Side
reqBody["ordType"] = param.OrderType
reqBody["sz"] = param.Size
if param.CCY != "" {
reqBody["ccy"] = param.CCY
}
if param.ClientOrdId != "" {
reqBody["clOrdId"] = param.ClientOrdId
} else {
reqBody["clOrdId"] = param.ClientOrdId
}
if param.Tag != "" {
reqBody["tag"] = param.Tag
}
if param.PosSide != "" {
reqBody["posSide"] = param.PosSide
}
if param.Price != "" {
reqBody["px"] = param.Price
}
if param.ReduceOnly != false {
reqBody["reduceOnly"] = param.ReduceOnly
}
type OrderResponse struct {
Code int `json:"code,string"`
Msg string `json:"msg"`
Data []OrderSummaryV5 `json:"data"`
}
var response OrderResponse
uri := "/api/v5/trade/order"
jsonStr, _, _ := ok.BuildRequestBody(reqBody)
err := ok.DoAuthorRequest(http.MethodPost, uri, jsonStr, &response)
if err != nil {
return nil, err
}
if response.Code != 0 {
msg := ""
if len(response.Data) > 0 {
msg = fmt.Sprintf("code:%d, scode:%s, smsg:%s", response.Code, response.Data[0].SCode, response.Data[0].SMsg)
} else {
msg = fmt.Sprintf("code:%d", response.Code)
}
return nil, fmt.Errorf("CreateOrder error:%s", msg)
}
return &response.Data[0], nil
}
func (ok *OKExV5) CancelOrderV5(instId, ordId, clOrdId string) (*OrderSummaryV5, error) {
reqBody := make(map[string]interface{})
reqBody["instId"] = instId
if ordId != "" {
reqBody["ordId"] = ordId
}
if clOrdId != "" {
reqBody["clOrdId"] = clOrdId
}
type OrderResponse struct {
Code int `json:"code,string"`
Msg string `json:"msg"`
Data []OrderSummaryV5 `json:"data"`
}
var response OrderResponse
uri := "/api/v5/trade/cancel-order"
jsonStr, _, _ := ok.BuildRequestBody(reqBody)
err := ok.DoAuthorRequest(http.MethodPost, uri, jsonStr, &response)
if err != nil {
return nil, err
}
if response.Code != 0 {
msg := response.Msg
if msg == "" {
if len(response.Data) > 0 {
msg = fmt.Sprintf("code:%d, scode:%s, smsg:%s", response.Code, response.Data[0].SCode, response.Data[0].SMsg)
} else {
msg = fmt.Sprintf("code:%d", response.Code)
}
}
return nil, fmt.Errorf("CancelOrderV5 error:%s", msg)
}
return &response.Data[0], nil
}
func (ok *OKExV5) ClosePositions(instId, mgnMode, posSide string) (*OrderSummaryV5, error) {
reqBody := make(map[string]interface{})
reqBody["instId"] = instId
reqBody["mgnMode"] = mgnMode
reqBody["posSide"] = posSide
type OrderResponse struct {
Code int `json:"code,string"`
Msg string `json:"msg"`
Data []OrderSummaryV5 `json:"data"`
}
var response OrderResponse
uri := "/api/v5/trade/close-position"
jsonStr, _, _ := ok.BuildRequestBody(reqBody)
err := ok.DoAuthorRequest(http.MethodPost, uri, jsonStr, &response)
if err != nil {
return nil, err
}
if response.Code != 0 {
msg := response.Msg
if msg == "" {
if len(response.Data) > 0 {
msg = fmt.Sprintf("code:%d, scode:%s, smsg:%s", response.Code, response.Data[0].SCode, response.Data[0].SMsg)
} else {
msg = fmt.Sprintf("code:%d", response.Code)
}
}
return nil, fmt.Errorf("ClosePositions error:%s", msg)
}
return &response.Data[0], nil
}
type PendingOrderParam struct {
InstType string
Uly string
InstId string //产品ID
OrdType string
State string
After string
Before string
Limit string
}
type OrderV5 struct {
AccFillSz string `json:"accFillSz"`
AvgPx string `json:"avgPx"`
CTime int `json:"cTime,string"`
Category string `json:"category"`
Ccy string `json:"ccy"`
ClOrdID string `json:"clOrdId"`
Fee float64 `json:"fee,string"`
FeeCcy string `json:"feeCcy"`
FillPx string `json:"fillPx"`
FillSz string `json:"fillSz"`
FillTime string `json:"fillTime"`
InstID string `json:"instId"`
InstType string `json:"instType"`
Lever string `json:"lever"`
OrdID string `json:"ordId"`
OrdType string `json:"ordType"`
Pnl string `json:"pnl"`
PosSide string `json:"posSide"`
Px float64 `json:"px,string"`
Rebate string `json:"rebate"`
RebateCcy string `json:"rebateCcy"`
Side string `json:"side"`
SlOrdPx string `json:"slOrdPx"`
SlTriggerPx string `json:"slTriggerPx"`
State string `json:"state"`
Sz float64 `json:"sz,string"`
Tag string `json:"tag"`
TdMode string `json:"tdMode"`
TpOrdPx string `json:"tpOrdPx"`
TpTriggerPx string `json:"tpTriggerPx"`
TradeID string `json:"tradeId"`
UTime int64 `json:"uTime,string"`
}
func (ok *OKExV5) GetPendingOrders(param *PendingOrderParam) ([]OrderV5, error) {
reqBody := make(map[string]string)
if param.InstType != "" {
reqBody["instType"] = param.InstType
}
if param.Uly != "" {
reqBody["uly"] = param.Uly
}
if param.InstId != "" {
reqBody["instId"] = param.InstId
}
if param.OrdType != "" {
reqBody["ordType"] = param.OrdType
}
if param.State != "" {
reqBody["state"] = param.State
}
if param.Before != "" {
reqBody["before"] = param.Before
}
if param.After != "" {
reqBody["after"] = param.After
}
if param.Limit != "" {
reqBody["limit"] = param.Limit
}
type OrderResponse struct {
Code int `json:"code,string"`
Msg string `json:"msg"`
Data []OrderV5 `json:"data"`
}
var response OrderResponse
uri := url.Values{}
for k, v := range reqBody {
uri.Set(k, v)
}
path := "/api/v5/trade/orders-pending"
if len(reqBody) > 0 {
path = fmt.Sprintf("%s?%s", path, uri.Encode())
}
jsonStr, _, _ := ok.BuildRequestBody(reqBody)
err := ok.DoAuthorRequest(http.MethodGet, path, jsonStr, &response)
if err != nil {
return nil, err
}
if response.Code != 0 {
return nil, fmt.Errorf("GetPendingOrders error:%s", response.Msg)
}
return response.Data, nil
}
func (ok *OKExV5) GetOrderV5(instId, ordId, clOrdId string) (*OrderV5, error) {
reqBody := make(map[string]string)
reqBody["instId"] = instId
if ordId != "" {
reqBody["ordId"] = ordId
}
if clOrdId != "" {
reqBody["clOrdId"] = clOrdId
}
type OrderResponse struct {
Code int `json:"code,string"`
Msg string `json:"msg"`
Data []OrderV5 `json:"data"`
}
var response OrderResponse
uri := url.Values{}
for k, v := range reqBody {
uri.Set(k, v)
}
path := "/api/v5/trade/order"
if len(reqBody) > 0 {
path = fmt.Sprintf("%s?%s", path, uri.Encode())
}
jsonStr, _, _ := ok.BuildRequestBody(reqBody)
err := ok.DoAuthorRequest(http.MethodGet, path, jsonStr, &response)
if err != nil {
return nil, err
}
if response.Code != 0 {
return nil, fmt.Errorf("GetOrderV5 error:%s", response.Msg)
}
return &response.Data[0], nil
}
func (ok *OKExV5) GetOrderHistory(instType, instId, ordType, state, afterID, beforeID string) ([]OrderV5, error) {
reqBody := make(map[string]string)
reqBody["instType"] = instType
if instId != "" {
reqBody["instId"] = instId
}
if ordType != "" {
reqBody["ordType"] = ordType
}
if state != "" {
reqBody["state"] = state
}
if afterID != "" {
reqBody["after"] = afterID
}
if beforeID != "" {
reqBody["before"] = beforeID
}
// reqBody["limit"] = "100"
type OrderResponse struct {
Code int `json:"code,string"`
Msg string `json:"msg"`
Data []OrderV5 `json:"data"`
}
var response OrderResponse
uri := url.Values{}
for k, v := range reqBody {
uri.Set(k, v)
}
path := "/api/v5/trade/orders-history-archive"
if len(reqBody) > 0 {
path = fmt.Sprintf("%s?%s", path, uri.Encode())
}
jsonStr, _, _ := ok.BuildRequestBody(reqBody)
err := ok.DoAuthorRequest(http.MethodGet, path, jsonStr, &response)
if err != nil {
return nil, err
}
if response.Code != 0 {
return nil, fmt.Errorf("GetOrderV5 error:%s", response.Msg)
}
return response.Data, nil
}
type AssetSummary struct {
Currency string `json:"ccy"`
Total float64 `json:"bal"`
Available float64 `json:"availBal,string"`
Frozen float64 `json:"frozenBal,string"`
}
func (ok *OKExV5) GetAssetBalances(currency string) ([]AssetSummary, error) {
reqBody := make(map[string]interface{})
path := "/api/v5/asset/balances"
jsonStr := ""
reqBody["ccy"] = currency
if currency != "" {
reqBody["ccy"] = currency
jsonStr, _, _ = ok.BuildRequestBody(reqBody)
path = fmt.Sprintf("%s?ccy=%s", path, currency)
}
type AssetSummaryResponse struct {
Code int `json:"code,string"`
Msg string `json:"msg"`
Data []AssetSummary `json:"data"`
}
var response AssetSummaryResponse
err := ok.DoAuthorRequest(http.MethodGet, path, jsonStr, &response)
if err != nil {
return nil, err
}
if response.Code != 0 {
return nil, fmt.Errorf("GetAssetBalances error:%s", response.Msg)
}
return response.Data, nil
}
type BalanceV5 struct {
AdjEq string `json:"adjEq"`
Details []BalanceDetail `json:"details"`
Imr string `json:"imr"`
IsoEq string `json:"isoEq"`
MgnRatio string `json:"mgnRatio"`
Mmr string `json:"mmr"`
OrdFroz string `json:"ordFroz"`
TotalEq string `json:"totalEq"`
UTime string `json:"uTime"`
}
type BalanceDetail struct {
Available string `json:"availBal"`
AvailEq string `json:"availEq"`
CashBal string `json:"cashBal"`
Currency string `json:"ccy"`
DisEq string `json:"disEq"`
Eq string `json:"eq"`
Frozen string `json:"frozenBal"`
Interest string `json:"interest"`
IsoEq string `json:"isoEq"`
Liab string `json:"liab"`
MgnRatio string `json:"mgnRatio"`
OrdFrozen string `json:"ordFrozen"`
UTime string `json:"uTime"`
Upl string `json:"upl"`
UplLiab string `json:"uplLiab"`
}
func (ok *OKExV5) GetAccountBalances(currency string) (*BalanceV5, error) {
reqBody := make(map[string]interface{})
path := "/api/v5/account/balance"
jsonStr := ""
reqBody["ccy"] = currency
if currency != "" {
reqBody["ccy"] = currency
jsonStr, _, _ = ok.BuildRequestBody(reqBody)
path = fmt.Sprintf("%s?ccy=%s", path, currency)
}
type BalanceV5Response struct {
Code int `json:"code,string"`
Msg string `json:"msg"`
Data []BalanceV5 `json:"data"`
}
var response BalanceV5Response
err := ok.DoAuthorRequest(http.MethodGet, path, jsonStr, &response)
if err != nil {
return nil, err
}
if response.Code != 0 {
return nil, fmt.Errorf("GetAccountBalances error:%s", response.Msg)
}
return &response.Data[0], nil
}
func (ok *OKExV5) adaptKLineBar(period KlinePeriod) string {
bar := "1D"
switch period {
case KLINE_PERIOD_1MIN:
bar = "1m"
case KLINE_PERIOD_3MIN:
bar = "3m"
case KLINE_PERIOD_5MIN:
bar = "5m"
case KLINE_PERIOD_15MIN:
bar = "15m"
case KLINE_PERIOD_30MIN:
bar = "30m"
case KLINE_PERIOD_1H, KLINE_PERIOD_60MIN:
bar = "1H"
case KLINE_PERIOD_2H:
bar = "2H"
case KLINE_PERIOD_4H:
bar = "4H"
case KLINE_PERIOD_6H:
bar = "6H"
case KLINE_PERIOD_12H:
bar = "12H"
case KLINE_PERIOD_1DAY:
bar = "1D"
case KLINE_PERIOD_1WEEK:
bar = "1W"
default:
bar = "1D"
}
return bar
}