-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"` | ||
} |