查詢市場價格K線數據
查詢市場價格K線數據
覆蓋範圍: 現貨 / USDT永續 / USDC永續 / USDC交割 / 反向合約
HTTP請求
GET /v5/market/kline
請求參數
參數 | 是否必需 | 類型 | 說明 |
---|---|---|---|
category | false | string | 產品類型. spot ,linear ,inverse category 不指定時, 默認是linear |
symbol | true | string | 合約名稱 |
interval | true | string | 時間粒度. 1 ,3 ,5 ,15 ,30 ,60 ,120 ,240 ,360 ,720 ,D ,M ,W |
start | false | integer | 開始時間戳 (毫秒) |
end | false | integer | 結束時間戳 (毫秒) |
limit | false | integer | 每頁數量限制. [1 , 1000 ]. 默認: 200 |
響應參數
參數 | 類型 | 說明 |
---|---|---|
category | string | 產品類型 |
symbol | string | 合約名稱 |
list | array |
|
> list[0]: startTime | string | 蠟燭的開始時間戳 (毫秒) |
> list[1]: openPrice | string | 開始價格 |
> list[2]: highPrice | string | 最高價格 |
> list[3]: lowPrice | string | 最低價格 |
> list[4]: closePrice | string | 結束價格. 如果蠟燭尚未結束,則表示為最新成交價格 |
> list[5]: volume | string | 交易量. 合約單位: 合約的張數. 現貨單位: 幣種的數量 |
> list[6]: turnover | string | 交易額. 單位: 報價貨幣的數量 |
請求示例
- HTTP
- Python
- Go
- Java
- Node.js
GET /v5/market/kline?category=inverse&symbol=BTCUSD&interval=60&start=1670601600000&end=1670608800000 HTTP/1.1
Host: api-testnet.bybit.com
from pybit.unified_trading import HTTP
session = HTTP(testnet=True)
print(session.get_kline(
category="inverse",
symbol="BTCUSD",
interval=60,
start=1670601600000,
end=1670608800000,
))
import (
"context"
"fmt"
bybit "github.com/wuhewuhe/bybit.go.api"
)
client := bybit.NewBybitHttpClient("", "", bybit.WithBaseURL(bybit.TESTNET))
params := map[string]interface{}{"category": "spot", "symbol": "BTCUSDT", "interval": "1"}
client.NewUtaBybitServiceWithParams(params).GetMarketKline(context.Background())
import com.bybit.api.client.domain.CategoryType;
import com.bybit.api.client.domain.market.*;
import com.bybit.api.client.domain.market.request.MarketDataRequest;
import com.bybit.api.client.service.BybitApiClientFactory;
var client = BybitApiClientFactory.newInstance().newAsyncMarketDataRestClient();
var marketKLineRequest = MarketDataRequest.builder().category(CategoryType.LINEAR).symbol("BTCUSDT").marketInterval(MarketInterval.WEEKLY).build();
client.getMarketLinesData(marketKLineRequest, System.out::println);
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
});
client
.getKline({
category: 'inverse',
symbol: 'BTCUSD',
interval: '60',
start: 1670601600000,
end: 1670608800000,
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
響應示例
{
"retCode": 0,
"retMsg": "OK",
"result": {
"symbol": "BTCUSD",
"category": "inverse",
"list": [
[
"1670608800000",
"17071",
"17073",
"17027",
"17055.5",
"268611",
"15.74462667"
],
[
"1670605200000",
"17071.5",
"17071.5",
"17061",
"17071",
"4177",
"0.24469757"
],
[
"1670601600000",
"17086.5",
"17088",
"16978",
"17071.5",
"6356",
"0.37288112"
]
]
},
"retExtInfo": {},
"time": 1672025956592
}