Subscribe K-Line
API Description
This Websocket API provides real-time K-line data for a specified instrument, including deatils such as timestamp, high price, low price, open price, close price and trading volume.
Note: K-line data is accessible via both RESTful and Websocket APIs. This page describes the Websock API. For information on the RESTful API, please click here
Precautions
- Currently, two methods are availabe for k-line subscription. User should exercise caution while creating connection.
Method 1
Authentication
This is a public Websocket and does not require authentication. For details on using the Websocket API, please refer to Introduction > Authentication & Code Snippet > Spot > Websocket Public Interface > Method 1
Websocket URL
wss://ws.futurescw.info?token={your_token}
Frequency Limit
None
Request Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| event | True | String | subscribe |
| args | True | String | Format: "spot/candle-interval:symbol""interval" refers to Kline interval. Available options: 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d, 1w, 1M "symbol" refers to the trading instrument to be subscribed, such as BTC-USDT Example: "spot/candle-1m:BTC-USDT" |
Response Parameters
| Parameter | Type | Description |
|---|---|---|
| channel | String | Subscribed channel, i.e., "spot/candle-1m:BTC-USDT" |
| subject | String | Subject, i.e., "spot/candle-1m" |
| data | Array | Data object |
| - | String | Timestamp (milliseconds) |
| - | String | Open price in quote currency |
| - | String | Close price in quote currency |
| - | String | Highest price in quote currency |
| - | String | Lowest price in quote currency |
| - | String | Volume in base currency |
| - | String | Price in quote currency |
Request Example
The following Python code shows how to get K-line for BTC-USDT.
Note: For complete code, please refer to Introduction > Authentication & Code Snippet > Spot > Websocket Public Interface> Method 1.
interval= "1m"
symbol = "BTC-USDT"
args = f'spot/candle-{interval}:{symbol}'
SpotWebsocketPublic(args) # the function SpotWebsocketPublic() is defined in section (Introduction > Authentication & Code Snippet > Spot > Websocket Public Interface > Method 1)
Note: For a complete Java code, please refer to Introduction > Authentication & Code Snippet > Spot > Websocket Public Interface > Method 1.
Response Example
The following is an example response returned by the above Python subscription. The Websocket subscription will keep updating the k-line data in real-time. For brevity, only the initial response is provided below:
{'channel': 'spot/candle-1m:BTC-USDT',
'subject': 'spot/candle-1m',
'data':
'["1743154440000",
"85366.41",
"85357.8",
"85366.76",
"85357.8",
"2.4926",
"212784.301823"
]'
},......
Method 2
Authentication
This is a public Websocket and does not require authentication. For details on using the Websocket API, please refer to Introduction > Authentication & Code Snippet > Spot > Websocket Public Interface > Method 2
Websocket URL
Frequency Limit
None
Request Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| event | true | String | Subscribe or unsubscribe: sub: subscribe, unsub: unsubscribe. Note: This parameter is case-sensitive. |
| params | true | Json | Requested parameter objects including: |
| -biz | true | String | Specifies the channel, e.g., "exchange". Note: Lowercase is recommended. |
| -type | true | String | Defines the function type, e.g., "candles". Note: Lowercase is recommended. |
| -pairCode | true | String | Currency pair ID, i.e., 78 : BTC_USDT Note: The mapping between currency pair ID and trading instrument can be obtained through Get 24H Trade Summary for All Instruments interface. |
| -interval | true | String | Represents the Kline interval. Available options: 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d, 1w, and 1M |
Response Parameters
| Parameter | Type | Description |
|---|---|---|
| biz | String | Channel name, e.g., "exchange". |
| pairCode | String | Currency pair ID, i.e., 78 : BTC_USDT Note: The mapping between currency pair ID and trading instrument can be obtained through Get 24H Trade Summary for All Instruments interface. |
| channel | String | Subscription type, e.g., "subscribe". |
| type | String | Defines the function type, e.g., "candles". |
| -result | Boolean | Result of the subscription request: true or false. |
| data | Json | Data object, containing the following fields: |
| - | String | Timestamp (milliseconds) |
| - | String | Open price in quote currency |
| - | String | Close price in quote currency |
| - | String | Highest price in quote currency |
| - | String | Lowest price in quote currency |
| - | String | Volume in base currency |
| - | String | Price in quote currency |
Request Example
The following Python code shows how to subscribe to K-line for "BTC-USDT".
Note: For complete code, please refer to Introduction > Authentication & Code Snippet > Spot > Websocket Public Interface > Method 2
url = "wss://ws.futurescw.com"
subscription_params = {"event":"sub",
"params":
{"biz":"exchange",
"type":"candles",
"pairCode":"78", # “78” for BTC-USDT
"interval":"1m"}}
SpotWebsocketPublic(url, subscription_params) # the function SpotWebsocketPublic() is defined in section (Introduction > Authentication & Code Snippet > Spot > Websocket Public Interface > Method 2)
Note: For a complete Java code, please refer to Introduction > Authentication & Code Snippet > Spot > Websocket Public Interface > Method 2.
Response Example
The following is an example response returned by the above Python subscription. The Websocket subscription will keep updating the k-line data in real-time. For brevity, only the initial response is provided below:
{"biz":"exchange","pairCode":"78","data":{"result":true},"channel":"subscribe","interval":"1m","type":"candles"}
{"biz":"exchange","pairCode":"78","data":"
[\"1745823600000\",
\"94580.17\",
\"94600.06\",
\"94600.08\",
\"94579.66\",
\"2.6366\",
\"249401.987844\"
]","interval":"1m","type":"candles"},.....