htx-rs 0.1.1

火币 HTX 现货交易 Rust SDK,支持下单、撤单、查单等主要接口,签名算法兼容官方。
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
//! HMAC-SHA256 签名工具,适配火币 API 请求签名
use hmac::{Hmac, Mac};
use sha2::Sha256;
use anyhow::{Result, anyhow};

/// 生成 HMAC-SHA256 签名
pub fn sign_sha256(secret: &str, message: &str) -> Result<String> {
    let mut mac = Hmac::<Sha256>::new_from_slice(secret.as_bytes())
        .map_err(|e| anyhow!("HMAC 初始化失败: {e}"))?;
    mac.update(message.as_bytes());
    let result = mac.finalize().into_bytes();
    Ok(base64::encode(result))
}