Skip to content

Commit b2efca3

Browse files
committed
Update
1 parent 2eb8af7 commit b2efca3

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

rest/api_public2.go

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package rest
2+
3+
import "net/http"
4+
5+
// GetKLine2 (USDT永续)
6+
// https://bybit-exchange.github.io/docs/zh-cn/linear/#t-querykline
7+
// interval: 1 3 5 15 30 60 120 240 360 720 "D" "M" "W" "Y"
8+
// from: From timestamp in seconds
9+
// limit: Limit for data size per page, max size is 200. Default as showing 200 pieces of data per page
10+
func (b *ByBit) GetKLine2(symbol string, interval string, from int64, limit int) (result []OHLC2, err error) {
11+
var ret GetKlineResult2
12+
params := map[string]interface{}{}
13+
params["symbol"] = symbol
14+
params["interval"] = interval
15+
params["from"] = from
16+
if limit > 0 {
17+
params["limit"] = limit
18+
}
19+
_, err = b.PublicRequest(http.MethodGet, "public/linear/kline", params, &ret)
20+
if err != nil {
21+
return
22+
}
23+
result = ret.Result
24+
return
25+
}

rest/api_public2_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package rest
2+
3+
import (
4+
"testing"
5+
"time"
6+
)
7+
8+
func TestGetKLine2(t *testing.T) {
9+
b := newByBit()
10+
from := time.Now().Add(-1 * time.Hour).Unix()
11+
ohlcs, err := b.GetKLine2(
12+
"BTCUSDT",
13+
"1",
14+
from,
15+
0,
16+
)
17+
if err != nil {
18+
t.Error(err)
19+
return
20+
}
21+
for _, v := range ohlcs {
22+
t.Logf("%#v", v)
23+
}
24+
}

rest/result2.go

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package rest
2+
3+
type OHLC2 struct {
4+
ID int64 `json:"id"`
5+
Symbol string `json:"symbol"`
6+
Period string `json:"period"`
7+
Interval string `json:"interval"`
8+
StartAt int64 `json:"start_at"`
9+
OpenTime int64 `json:"open_time"`
10+
Volume float64 `json:"volume"`
11+
Open float64 `json:"open"`
12+
High float64 `json:"high"`
13+
Low float64 `json:"low"`
14+
Close float64 `json:"close"`
15+
Turnover float64 `json:"turnover"`
16+
}
17+
18+
type GetKlineResult2 struct {
19+
RetCode int `json:"ret_code"`
20+
RetMsg string `json:"ret_msg"`
21+
ExtCode string `json:"ext_code"`
22+
ExtInfo string `json:"ext_info"`
23+
Result []OHLC2 `json:"result"`
24+
TimeNow string `json:"time_now"`
25+
}

0 commit comments

Comments
 (0)