pub struct StockDb { /* private fields */ }Expand description
股票列表数据库 (线程安全,Mutex 包装)
Implementations§
Source§impl StockDb
impl StockDb
Sourcepub fn open_at(path: impl AsRef<Path>) -> SqlResult<Self>
pub fn open_at(path: impl AsRef<Path>) -> SqlResult<Self>
打开(或创建)指定路径的数据库。
生产路径由 Self::open 统一选择;测试和诊断工具可用此入口避免污染
用户真实 ~/.futu-opend-rs/stock_data.db。
Sourcepub fn get_version(&self) -> u64
pub fn get_version(&self) -> u64
获取 stock_list_version
Sourcepub fn set_version(&self, version: u64) -> SqlResult<()>
pub fn set_version(&self, version: u64) -> SqlResult<()>
保存 stock_list_version
Sourcepub fn load_all(&self) -> SqlResult<Vec<DbStockItem>>
pub fn load_all(&self) -> SqlResult<Vec<DbStockItem>>
加载所有股票记录
Sourcepub fn load_by_code(&self, code: &str) -> SqlResult<Vec<DbStockItem>>
pub fn load_by_code(&self, code: &str) -> SqlResult<Vec<DbStockItem>>
Load all cached rows with the given public code.
Code is not globally unique across markets, so callers must still apply market projection/filtering before using the result.
Sourcepub fn load_warrants_by_owner(
&self,
owner_stock_id: u64,
) -> SqlResult<Vec<DbStockItem>>
pub fn load_warrants_by_owner( &self, owner_stock_id: u64, ) -> SqlResult<Vec<DbStockItem>>
C++ SQLite3SecListDBHelper::SearchWarrantByOwnerID equivalent:
SELECT * FROM security WHERE warrnt_owner = ? AND delete_flag=0.
Rust stores stock-list delete rows by physically removing them, so the
remaining table already represents delete_flag=0. Do not add a public
market filter here: C++ GetReference(Warrant) returns cross-market
associated warrants such as SG rows for HK.00700 when they can be
projected to a public QotMarket.
Sourcepub fn begin_batch(&self) -> SqlResult<()>
pub fn begin_batch(&self) -> SqlResult<()>
开始批量写入事务
Sourcepub fn commit_batch(&self) -> SqlResult<()>
pub fn commit_batch(&self) -> SqlResult<()>
提交事务
Sourcepub fn rollback_batch_if_open(&self) -> SqlResult<()>
pub fn rollback_batch_if_open(&self) -> SqlResult<()>
尝试回滚当前批量事务。
stock_list_sync 在网络请求前打开批量事务;若 CMD6746 中途失败,
需要显式回滚,避免下一轮同步碰到悬挂事务。SQLite 在没有活动事务时
会返回错误,caller 负责按上下文记录。
Sourcepub fn upsert(&self, item: &DbStockItem) -> SqlResult<()>
pub fn upsert(&self, item: &DbStockItem) -> SqlResult<()>
插入或更新一条股票记录
Sourcepub fn clear_all_securities(&self) -> SqlResult<()>
pub fn clear_all_securities(&self) -> SqlResult<()>
删除全部股票记录。
仅用于 CMD6746 stock_list_version=0 全量重建事务。普通 delta sync
必须继续依赖服务端 delete_flag,避免把增量页误当全量替换。
Sourcepub fn load_stock_ids(&self) -> SqlResult<Vec<u64>>
pub fn load_stock_ids(&self) -> SqlResult<Vec<u64>>
读取当前持久化的全部 stock_id。
full refresh 成功提交后,调用方用这个列表从内存 static cache 删除 服务端全量未再返回的旧 row。
Sourcepub fn calc_checksum_v2(&self) -> SqlResult<StockListChecksumV2>
pub fn calc_checksum_v2(&self) -> SqlResult<StockListChecksumV2>
C++ SQLite3SecListDBHelper::CalcSecInfoCheckSumV2 split SUM:
SUM(stock_id low32/high32) and SUM(sequence low32/high32).
Sourcepub fn schema_version(&self) -> u32
pub fn schema_version(&self) -> u32
v1.4.79 B1: 读取 SQLite schema version(调试 / daemon startup log)。