Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
f0cii committed Jul 24, 2020
1 parent 2eb8af7 commit b2efca3
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
25 changes: 25 additions & 0 deletions rest/api_public2.go
Original file line number Diff line number Diff line change
@@ -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
}
24 changes: 24 additions & 0 deletions rest/api_public2_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
25 changes: 25 additions & 0 deletions rest/result2.go
Original file line number Diff line number Diff line change
@@ -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"`
}

0 comments on commit b2efca3

Please sign in to comment.