pub struct KeyRecord {Show 14 fields
pub id: String,
pub hash: String,
pub scopes: HashSet<Scope>,
pub allowed_markets: Option<HashSet<String>>,
pub allowed_symbols: Option<HashSet<String>>,
pub max_order_value: Option<f64>,
pub max_daily_value: Option<f64>,
pub hours_window: Option<String>,
pub max_orders_per_minute: Option<u32>,
pub allowed_trd_sides: Option<HashSet<String>>,
pub expires_at: Option<DateTime<Utc>>,
pub created_at: DateTime<Utc>,
pub note: Option<String>,
pub allowed_machines: Option<Vec<String>>,
}Expand description
单条 key 的持久化格式
Fields§
§id: String人读 ID(审计日志用)
hash: String“sha256:<64 hex>”
scopes: HashSet<Scope>§allowed_markets: Option<HashSet<String>>§allowed_symbols: Option<HashSet<String>>§max_order_value: Option<f64>§max_daily_value: Option<f64>§hours_window: Option<String>“HH:MM-HH:MM” 服务器本地时区;跨午夜用 “22:00-04:00”
max_orders_per_minute: Option<u32>每 60s 最多下单次数(滑动窗口,None 表示不限)
allowed_trd_sides: Option<HashSet<String>>允许的交易方向,例如 ["SELL"];None 不限
expires_at: Option<DateTime<Utc>>§created_at: DateTime<Utc>§note: Option<String>§allowed_machines: Option<Vec<String>>机器绑定指纹列表(软绑定,见 machine 模块)
None→ 未启用绑定,所有机器可用(向后兼容 v0.7.0 ~ v0.7.x 早期 key)Some(vec![])→ 强制锁定(无机器能通过),可用于临时冻结Some(vec!["<fingerprint_hex>", ...])→ 只允许这些机器
指纹由 machine::fingerprint_for(key_id) 生成,和 key_id 强耦合:
同一台机器上不同 key 的指纹不同。
Implementations§
Source§impl KeyRecord
impl KeyRecord
Sourcepub fn generate(
id: impl Into<String>,
scopes: HashSet<Scope>,
limits: Option<Limits>,
expires_at: Option<DateTime<Utc>>,
note: Option<String>,
) -> (String, KeyRecord)
pub fn generate( id: impl Into<String>, scopes: HashSet<Scope>, limits: Option<Limits>, expires_at: Option<DateTime<Utc>>, note: Option<String>, ) -> (String, KeyRecord)
生成新 key:返回 (plaintext, record)
plaintext 只会返回给调用方一次,必须立即展示给用户;record 落盘。
Sourcepub fn generate_with_machines(
id: impl Into<String>,
scopes: HashSet<Scope>,
limits: Option<Limits>,
expires_at: Option<DateTime<Utc>>,
note: Option<String>,
allowed_machines: Option<Vec<String>>,
) -> (String, KeyRecord)
pub fn generate_with_machines( id: impl Into<String>, scopes: HashSet<Scope>, limits: Option<Limits>, expires_at: Option<DateTime<Utc>>, note: Option<String>, allowed_machines: Option<Vec<String>>, ) -> (String, KeyRecord)
同 [generate],但允许一次性设置 allowed_machines
Sourcepub fn check_machine(&self) -> Result<(), MachineError>
pub fn check_machine(&self) -> Result<(), MachineError>
检查本机是否在 allowed_machines 白名单里(None 时始终通过)
Sourcepub fn is_expired(&self, now: DateTime<Utc>) -> bool
pub fn is_expired(&self, now: DateTime<Utc>) -> bool
是否已过期
Trait Implementations§
Source§impl<'de> Deserialize<'de> for KeyRecord
impl<'de> Deserialize<'de> for KeyRecord
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for KeyRecord
impl RefUnwindSafe for KeyRecord
impl Send for KeyRecord
impl Sync for KeyRecord
impl Unpin for KeyRecord
impl UnwindSafe for KeyRecord
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more