diff --git a/rest/api_public2.go b/rest/api_public2.go new file mode 100644 index 0000000..c4f917e --- /dev/null +++ b/rest/api_public2.go @@ -0,0 +1,25 @@ +package rest + +import "net/http" + +// GetKLine2 (USDT永续) +// https://bybit-exchange.github.io/docs/zh-cn/linear/#t-querykline +// interval: 1 3 5 15 30 60 120 240 360 720 "D" "M" "W" "Y" +// from: From timestamp in seconds +// limit: Limit for data size per page, max size is 200. Default as showing 200 pieces of data per page +func (b *ByBit) GetKLine2(symbol string, interval string, from int64, limit int) (result []OHLC2, err error) { + var ret GetKlineResult2 + params := map[string]interface{}{} + params["symbol"] = symbol + params["interval"] = interval + params["from"] = from + if limit > 0 { + params["limit"] = limit + } + _, err = b.PublicRequest(http.MethodGet, "public/linear/kline", params, &ret) + if err != nil { + return + } + result = ret.Result + return +} diff --git a/rest/api_public2_test.go b/rest/api_public2_test.go new file mode 100644 index 0000000..402c7c5 --- /dev/null +++ b/rest/api_public2_test.go @@ -0,0 +1,24 @@ +package rest + +import ( + "testing" + "time" +) + +func TestGetKLine2(t *testing.T) { + b := newByBit() + from := time.Now().Add(-1 * time.Hour).Unix() + ohlcs, err := b.GetKLine2( + "BTCUSDT", + "1", + from, + 0, + ) + if err != nil { + t.Error(err) + return + } + for _, v := range ohlcs { + t.Logf("%#v", v) + } +} diff --git a/rest/result2.go b/rest/result2.go new file mode 100644 index 0000000..3fad506 --- /dev/null +++ b/rest/result2.go @@ -0,0 +1,25 @@ +package rest + +type OHLC2 struct { + ID int64 `json:"id"` + Symbol string `json:"symbol"` + Period string `json:"period"` + Interval string `json:"interval"` + StartAt int64 `json:"start_at"` + OpenTime int64 `json:"open_time"` + Volume float64 `json:"volume"` + Open float64 `json:"open"` + High float64 `json:"high"` + Low float64 `json:"low"` + Close float64 `json:"close"` + Turnover float64 `json:"turnover"` +} + +type GetKlineResult2 struct { + RetCode int `json:"ret_code"` + RetMsg string `json:"ret_msg"` + ExtCode string `json:"ext_code"` + ExtInfo string `json:"ext_info"` + Result []OHLC2 `json:"result"` + TimeNow string `json:"time_now"` +}