Skip to main content

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

  1. 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

ParameterMandatoryTypeDescription
eventTrueStringsubscribe
argsTrueStringFormat: "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

ParameterTypeDescription
channelStringSubscribed channel, i.e., "spot/candle-1m:BTC-USDT"
subjectStringSubject, i.e., "spot/candle-1m"
dataArrayData object
-StringTimestamp (milliseconds)
-StringOpen price in quote currency
-StringClose price in quote currency
-StringHighest price in quote currency
-StringLowest price in quote currency
-StringVolume in base currency
-StringPrice 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

wss://ws.futurescw.com

Frequency Limit

None

Request Parameters

ParameterMandatoryTypeDescription
eventtrueStringSubscribe or unsubscribe:
sub: subscribe,
unsub: unsubscribe.
Note: This parameter is case-sensitive.
paramstrueJsonRequested parameter objects including:
-biztrueStringSpecifies the channel, e.g., "exchange".
Note: Lowercase is recommended.
-typetrueStringDefines the function type, e.g., "candles".
Note: Lowercase is recommended.
-pairCodetrueStringCurrency 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.
-intervaltrueStringRepresents the Kline interval. Available options: 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d, 1w, and 1M

Response Parameters

ParameterTypeDescription
bizStringChannel name, e.g., "exchange".
pairCodeStringCurrency 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.
channelStringSubscription type, e.g., "subscribe".
typeStringDefines the function type, e.g., "candles".
-resultBooleanResult of the subscription request: true or false.
dataJsonData object, containing the following fields:
-StringTimestamp (milliseconds)
-StringOpen price in quote currency
-StringClose price in quote currency
-StringHighest price in quote currency
-StringLowest price in quote currency
-StringVolume in base currency
-StringPrice 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"},.....