1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use crate::WSClient;
use std::collections::HashMap;
use super::ws_client_internal::WSClientInternal;
const SPOT_WEBSOCKET_URL: &str = "wss://api.huobi.pro/ws";
const FUTURES_WEBSOCKET_URL: &str = "wss://futures.huobi.com/ws";
const COIN_SWAP_WEBSOCKET_URL: &str = "wss://futures.huobi.com/swap-ws";
const USDT_SWAP_WEBSOCKET_URL: &str = "wss://futures.huobi.com/linear-swap-ws";
const OPTION_WEBSOCKET_URL: &str = "wss://futures.huobi.com/option-ws";
pub struct HuobiSpotWSClient {
client: WSClientInternal,
}
pub struct HuobiFuturesWSClient {
client: WSClientInternal,
}
pub struct HuobiCoinSwapWSClient {
client: WSClientInternal,
}
pub struct HuobiUsdtSwapWSClient {
client: WSClientInternal,
}
pub struct HuobiOptionWSClient {
client: WSClientInternal,
}
fn serialize_command(channels: &[String], subscribe: bool) -> Vec<String> {
channels
.iter()
.map(|ch| {
let mut command = HashMap::new();
command.insert(if subscribe { "sub" } else { "unsub" }, ch.as_str());
command.insert("id", "crypto-ws-client");
command
})
.map(|m| serde_json::to_string(&m).unwrap())
.collect::<Vec<String>>()
}
define_client!(HuobiSpotWSClient, SPOT_WEBSOCKET_URL, serialize_command);
define_client!(
HuobiFuturesWSClient,
FUTURES_WEBSOCKET_URL,
serialize_command
);
define_client!(
HuobiCoinSwapWSClient,
COIN_SWAP_WEBSOCKET_URL,
serialize_command
);
define_client!(
HuobiUsdtSwapWSClient,
USDT_SWAP_WEBSOCKET_URL,
serialize_command
);
define_client!(HuobiOptionWSClient, OPTION_WEBSOCKET_URL, serialize_command);