Skip to main content

StockDb

Struct StockDb 

Source
pub struct StockDb { /* private fields */ }
Expand description

股票列表数据库 (线程安全,Mutex 包装)

Implementations§

Source§

impl StockDb

Source

pub fn open() -> SqlResult<Self>

打开(或创建)数据库

Source

pub fn open_at(path: impl AsRef<Path>) -> SqlResult<Self>

打开(或创建)指定路径的数据库。

生产路径由 Self::open 统一选择;测试和诊断工具可用此入口避免污染 用户真实 ~/.futu-opend-rs/stock_data.db

Source

pub fn get_version(&self) -> u64

获取 stock_list_version

Source

pub fn set_version(&self, version: u64) -> SqlResult<()>

保存 stock_list_version

Source

pub fn load_all(&self) -> SqlResult<Vec<DbStockItem>>

加载所有股票记录

Source

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.

Source

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.

Source

pub fn begin_batch(&self) -> SqlResult<()>

开始批量写入事务

Source

pub fn commit_batch(&self) -> SqlResult<()>

提交事务

Source

pub fn rollback_batch_if_open(&self) -> SqlResult<()>

尝试回滚当前批量事务。

stock_list_sync 在网络请求前打开批量事务;若 CMD6746 中途失败, 需要显式回滚,避免下一轮同步碰到悬挂事务。SQLite 在没有活动事务时 会返回错误,caller 负责按上下文记录。

Source

pub fn upsert(&self, item: &DbStockItem) -> SqlResult<()>

插入或更新一条股票记录

Source

pub fn delete(&self, stock_id: u64) -> SqlResult<()>

删除一条股票记录

Source

pub fn clear_all_securities(&self) -> SqlResult<()>

删除全部股票记录。

仅用于 CMD6746 stock_list_version=0 全量重建事务。普通 delta sync 必须继续依赖服务端 delete_flag,避免把增量页误当全量替换。

Source

pub fn load_stock_ids(&self) -> SqlResult<Vec<u64>>

读取当前持久化的全部 stock_id。

full refresh 成功提交后,调用方用这个列表从内存 static cache 删除 服务端全量未再返回的旧 row。

Source

pub fn count(&self) -> u64

获取记录总数

Source

pub fn calc_checksum_v2(&self) -> SqlResult<StockListChecksumV2>

C++ SQLite3SecListDBHelper::CalcSecInfoCheckSumV2 split SUM: SUM(stock_id low32/high32) and SUM(sequence low32/high32).

Source

pub fn schema_version(&self) -> u32

v1.4.79 B1: 读取 SQLite schema version(调试 / daemon startup log)。

Trait Implementations§

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more