Send orders heartbeat
curl --request POST \
--url https://api.4casters.io/user/ordersHeartbeat \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"timeout": 30
}'import requests
url = "https://api.4casters.io/user/ordersHeartbeat"
payload = { "timeout": 30 }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({timeout: 30})
};
fetch('https://api.4casters.io/user/ordersHeartbeat', 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://api.4casters.io/user/ordersHeartbeat",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'timeout' => 30
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"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://api.4casters.io/user/ordersHeartbeat"
payload := strings.NewReader("{\n \"timeout\": 30\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.post("https://api.4casters.io/user/ordersHeartbeat")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"timeout\": 30\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.4casters.io/user/ordersHeartbeat")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"timeout\": 30\n}"
response = http.request(request)
puts response.read_body用户
订单心跳
客户端断开时自动取消你的订单
POST
/
user
/
ordersHeartbeat
Send orders heartbeat
curl --request POST \
--url https://api.4casters.io/user/ordersHeartbeat \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"timeout": 30
}'import requests
url = "https://api.4casters.io/user/ordersHeartbeat"
payload = { "timeout": 30 }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({timeout: 30})
};
fetch('https://api.4casters.io/user/ordersHeartbeat', 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://api.4casters.io/user/ordersHeartbeat",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'timeout' => 30
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"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://api.4casters.io/user/ordersHeartbeat"
payload := strings.NewReader("{\n \"timeout\": 30\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.post("https://api.4casters.io/user/ordersHeartbeat")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"timeout\": 30\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.4casters.io/user/ordersHeartbeat")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"timeout\": 30\n}"
response = http.request(request)
puts response.read_body一种安全机制:发送带
timeout(单位为秒)的心跳。如果在 timeout 秒内未收到下一次心跳,你的所有未成交订单将被取消。
在任何会挂单的客户端中使用此端点 — 如果进程崩溃或失去连接,心跳可确保过期订单被撤下,而不是留在订单簿上。
请求
POST /user/ordersHeartbeat
integer
必填
超时后取消,单位为秒。必须大于
5。curl -X POST https://api.4casters.io/user/ordersHeartbeat \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"timeout": 30}'
{ "timeout": 30 }
响应
响应由订单服务转发:{ "data": { /* heartbeat ack payload */ } }
错误
| 状态 | 含义 |
|---|---|
400 | timeout 缺失、不是数字,或 <= 5。 |
503 | 订单服务不可达。 |
授权
Pass your auth token in the Authorization header. The Bearer prefix is optional; the server also accepts a signed auth cookie or a token field in the request body.
请求体
application/json
Cancel-after timeout, in seconds.
必填范围:
x >= 6响应
Heartbeat acknowledged. The response shape is forwarded from the orders service.
此页面对您有帮助吗?