cURL
curl --request GET \
--url https://test.deribit.com/api/v2/public/set_heartbeat \
--header 'Content-Type: application/json' \
--data '
{
"jsonrpc": "2.0",
"id": 9098,
"method": "public/set_heartbeat",
"params": {
"interval": 30
}
}
'import requests
url = "https://test.deribit.com/api/v2/public/set_heartbeat"
payload = {
"jsonrpc": "2.0",
"id": 9098,
"method": "public/set_heartbeat",
"params": { "interval": 30 }
}
headers = {"Content-Type": "application/json"}
response = requests.get(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'GET',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
jsonrpc: '2.0',
id: 9098,
method: 'public/set_heartbeat',
params: {interval: 30}
})
};
fetch('https://test.deribit.com/api/v2/public/set_heartbeat', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://test.deribit.com/api/v2/public/set_heartbeat",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => json_encode([
'jsonrpc' => '2.0',
'id' => 9098,
'method' => 'public/set_heartbeat',
'params' => [
'interval' => 30
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://test.deribit.com/api/v2/public/set_heartbeat"
payload := strings.NewReader("{\n \"jsonrpc\": \"2.0\",\n \"id\": 9098,\n \"method\": \"public/set_heartbeat\",\n \"params\": {\n \"interval\": 30\n }\n}")
req, _ := http.NewRequest("GET", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://test.deribit.com/api/v2/public/set_heartbeat")
.header("Content-Type", "application/json")
.body("{\n \"jsonrpc\": \"2.0\",\n \"id\": 9098,\n \"method\": \"public/set_heartbeat\",\n \"params\": {\n \"interval\": 30\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://test.deribit.com/api/v2/public/set_heartbeat")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"jsonrpc\": \"2.0\",\n \"id\": 9098,\n \"method\": \"public/set_heartbeat\",\n \"params\": {\n \"interval\": 30\n }\n}"
response = http.request(request)
puts response.read_body{
"jsonrpc": "2.0",
"id": 9098,
"result": "ok"
}Session Management
public/set_heartbeat
Signals the WebSocket connection to send and request heartbeats. Heartbeats are used to detect stale or broken connections.
Heartbeat & Disconnect Lifecycle:
- When no message has been sent to the client for
intervalseconds, the server sends aheartbeatnotification ("params": {"type": "heartbeat"}). - When no message has been received from the client for
intervalseconds (plus 500 ms), the server sends aheartbeatnotification with"params": {"type": "test_request"}. Respond by sending a/api/v2/public/testrequest. - Any JSON text message from the client counts as activity and restarts this timer; WebSocket-level ping/pong frames and the plain-text
ping/PINGmessages do not. - If the connection stays silent until
(2 * interval) + 500 msafter the last client message, the server closes the WebSocket with close code 4000 (heartbeat close). - If Cancel on Disconnect is enabled for the connection (connection or account scope), orders created over this connection are cancelled when it is closed.
- Calling this method again replaces the previous interval.
Validation: interval must be an integer between 10 and 300 seconds inclusive. Any other value (including fractional numbers) returns JSON-RPC error -32602.
WebSocket Only: This method is designed exclusively for WebSocket connections. Calling it over REST/HTTP returns error 10030 (must_be_websocket_request).
cURL
curl --request GET \
--url https://test.deribit.com/api/v2/public/set_heartbeat \
--header 'Content-Type: application/json' \
--data '
{
"jsonrpc": "2.0",
"id": 9098,
"method": "public/set_heartbeat",
"params": {
"interval": 30
}
}
'import requests
url = "https://test.deribit.com/api/v2/public/set_heartbeat"
payload = {
"jsonrpc": "2.0",
"id": 9098,
"method": "public/set_heartbeat",
"params": { "interval": 30 }
}
headers = {"Content-Type": "application/json"}
response = requests.get(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'GET',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
jsonrpc: '2.0',
id: 9098,
method: 'public/set_heartbeat',
params: {interval: 30}
})
};
fetch('https://test.deribit.com/api/v2/public/set_heartbeat', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://test.deribit.com/api/v2/public/set_heartbeat",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => json_encode([
'jsonrpc' => '2.0',
'id' => 9098,
'method' => 'public/set_heartbeat',
'params' => [
'interval' => 30
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://test.deribit.com/api/v2/public/set_heartbeat"
payload := strings.NewReader("{\n \"jsonrpc\": \"2.0\",\n \"id\": 9098,\n \"method\": \"public/set_heartbeat\",\n \"params\": {\n \"interval\": 30\n }\n}")
req, _ := http.NewRequest("GET", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://test.deribit.com/api/v2/public/set_heartbeat")
.header("Content-Type", "application/json")
.body("{\n \"jsonrpc\": \"2.0\",\n \"id\": 9098,\n \"method\": \"public/set_heartbeat\",\n \"params\": {\n \"interval\": 30\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://test.deribit.com/api/v2/public/set_heartbeat")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"jsonrpc\": \"2.0\",\n \"id\": 9098,\n \"method\": \"public/set_heartbeat\",\n \"params\": {\n \"interval\": 30\n }\n}"
response = http.request(request)
puts response.read_body{
"jsonrpc": "2.0",
"id": 9098,
"result": "ok"
}Query Parameters
The heartbeat interval in seconds (allowed range: 10 to 300)
Required range:
10 <= x <= 300Example:
30
Was this page helpful?