pub struct DatabaseQueries;Implementations§
Source§impl DatabaseQueries
impl DatabaseQueries
Sourcepub async fn truncate(pool: &PgPool) -> Result<()>
pub async fn truncate(pool: &PgPool) -> Result<()>
Truncates all tables in the cache database via the provided Postgres pool.
§Errors
Returns an error if the TRUNCATE operation fails.
Sourcepub async fn add(pool: &PgPool, key: String, value: Vec<u8>) -> Result<()>
pub async fn add(pool: &PgPool, key: String, value: Vec<u8>) -> Result<()>
Inserts a raw key-value entry into the general table via the provided pool.
§Errors
Returns an error if the INSERT operation fails.
Sourcepub async fn load(pool: &PgPool) -> Result<AHashMap<String, Vec<u8>>>
pub async fn load(pool: &PgPool) -> Result<AHashMap<String, Vec<u8>>>
Loads all entries from the general table via the provided pool.
§Errors
Returns an error if the SELECT operation fails.
Sourcepub async fn add_currency(pool: &PgPool, currency: Currency) -> Result<()>
pub async fn add_currency(pool: &PgPool, currency: Currency) -> Result<()>
Inserts or ignores a Currency row via the provided pool.
§Errors
Returns an error if the INSERT operation fails.
Sourcepub async fn load_currencies(pool: &PgPool) -> Result<Vec<Currency>>
pub async fn load_currencies(pool: &PgPool) -> Result<Vec<Currency>>
Loads all Currency entries via the provided pool.
§Errors
Returns an error if the SELECT operation fails.
Sourcepub async fn load_currency(
pool: &PgPool,
code: &str,
) -> Result<Option<Currency>>
pub async fn load_currency( pool: &PgPool, code: &str, ) -> Result<Option<Currency>>
Loads a single Currency entry by code via the provided pool.
§Errors
Returns an error if the SELECT operation fails.
Sourcepub async fn add_instrument(
pool: &PgPool,
kind: &str,
instrument: Box<dyn Instrument>,
) -> Result<()>
pub async fn add_instrument( pool: &PgPool, kind: &str, instrument: Box<dyn Instrument>, ) -> Result<()>
Inserts or updates an InstrumentAny entry via the provided pool.
§Errors
Returns an error if the INSERT or UPDATE operation fails.
Sourcepub async fn load_instrument(
pool: &PgPool,
instrument_id: &InstrumentId,
) -> Result<Option<InstrumentAny>>
pub async fn load_instrument( pool: &PgPool, instrument_id: &InstrumentId, ) -> Result<Option<InstrumentAny>>
Loads a single InstrumentAny entry by instrument_id via the provided pool.
§Errors
Returns an error if the SELECT operation fails.
Sourcepub async fn load_instruments(pool: &PgPool) -> Result<Vec<InstrumentAny>>
pub async fn load_instruments(pool: &PgPool) -> Result<Vec<InstrumentAny>>
Loads all InstrumentAny entries via the provided pool.
§Errors
Returns an error if the SELECT operation fails.
Sourcepub async fn add_order(
pool: &PgPool,
event: OrderInitialized,
client_id: Option<ClientId>,
) -> Result<()>
pub async fn add_order( pool: &PgPool, event: OrderInitialized, client_id: Option<ClientId>, ) -> Result<()>
Inserts an OrderInitialized event via the provided pool.
§Errors
Returns an error if the SQL INSERT or UPDATE operation fails.
Sourcepub async fn add_order_snapshot(
pool: &PgPool,
snapshot: OrderSnapshot,
) -> Result<()>
pub async fn add_order_snapshot( pool: &PgPool, snapshot: OrderSnapshot, ) -> Result<()>
Sourcepub async fn load_order_snapshot(
pool: &PgPool,
client_order_id: &ClientOrderId,
) -> Result<Option<OrderSnapshot>>
pub async fn load_order_snapshot( pool: &PgPool, client_order_id: &ClientOrderId, ) -> Result<Option<OrderSnapshot>>
Loads an OrderSnapshot entry by client order ID via the provided pool.
§Errors
Returns an error if the SQL SELECT or deserialization fails.
Sourcepub async fn add_position_snapshot(
pool: &PgPool,
snapshot: PositionSnapshot,
) -> Result<()>
pub async fn add_position_snapshot( pool: &PgPool, snapshot: PositionSnapshot, ) -> Result<()>
Inserts or updates a PositionSnapshot entry via the provided pool.
§Errors
Returns an error if the SQL INSERT or UPDATE operation fails, or if beginning the transaction fails.
Sourcepub async fn load_position_snapshot(
pool: &PgPool,
position_id: &PositionId,
) -> Result<Option<PositionSnapshot>>
pub async fn load_position_snapshot( pool: &PgPool, position_id: &PositionId, ) -> Result<Option<PositionSnapshot>>
Loads a PositionSnapshot entry by position_id via the provided pool.
§Errors
Returns an error if the SQL SELECT or deserialization fails.
Sourcepub async fn check_if_order_initialized_exists(
pool: &PgPool,
client_order_id: ClientOrderId,
) -> Result<bool>
pub async fn check_if_order_initialized_exists( pool: &PgPool, client_order_id: ClientOrderId, ) -> Result<bool>
Checks if an OrderInitialized event exists for the given client_order_id via the provided pool.
§Errors
Returns an error if the SQL SELECT operation fails.
Sourcepub async fn check_if_account_event_exists(
pool: &PgPool,
account_id: AccountId,
) -> Result<bool>
pub async fn check_if_account_event_exists( pool: &PgPool, account_id: AccountId, ) -> Result<bool>
Checks if any account event exists for the given account_id via the provided pool.
§Errors
Returns an error if the SQL SELECT operation fails.
Sourcepub async fn add_order_event(
pool: &PgPool,
order_event: Box<dyn OrderEvent>,
client_id: Option<ClientId>,
) -> Result<()>
pub async fn add_order_event( pool: &PgPool, order_event: Box<dyn OrderEvent>, client_id: Option<ClientId>, ) -> Result<()>
Inserts or updates an order event entry via the provided pool.
§Errors
Returns an error if the SQL INSERT or UPDATE operation fails.
Sourcepub async fn load_order_events(
pool: &PgPool,
client_order_id: &ClientOrderId,
) -> Result<Vec<OrderEventAny>>
pub async fn load_order_events( pool: &PgPool, client_order_id: &ClientOrderId, ) -> Result<Vec<OrderEventAny>>
Loads all order events for a client_order_id via the provided pool.
§Errors
Returns an error if the SQL SELECT or deserialization fails.
Sourcepub async fn load_order(
pool: &PgPool,
client_order_id: &ClientOrderId,
) -> Result<Option<OrderAny>>
pub async fn load_order( pool: &PgPool, client_order_id: &ClientOrderId, ) -> Result<Option<OrderAny>>
Loads and assembles a complete OrderAny for a client_order_id via the provided pool.
§Errors
Returns an error if assembling events or SQL operations fail.
Sourcepub async fn load_orders(pool: &PgPool) -> Result<Vec<OrderAny>>
pub async fn load_orders(pool: &PgPool) -> Result<Vec<OrderAny>>
Loads and assembles all OrderAny entries via the provided pool.
§Errors
Returns an error if loading events or SQL operations fail.
Sourcepub async fn add_position(
pool: &PgPool,
position_id: PositionId,
event: &OrderFilled,
) -> Result<()>
pub async fn add_position( pool: &PgPool, position_id: PositionId, event: &OrderFilled, ) -> Result<()>
Replaces the fill event log for a position_id via the provided pool.
§Errors
Returns an error if the fill is invalid or if the SQL operations fail.
Sourcepub async fn update_position(pool: &PgPool, event: &OrderFilled) -> Result<()>
pub async fn update_position(pool: &PgPool, event: &OrderFilled) -> Result<()>
Appends a fill event for a Position via the provided pool.
§Errors
Returns an error if the fill is invalid or if the SQL operations fail.
Sourcepub async fn add_position_event(
pool: &PgPool,
event: &OrderFilled,
) -> Result<()>
pub async fn add_position_event( pool: &PgPool, event: &OrderFilled, ) -> Result<()>
Appends an OrderFilled event to the position event log via the provided pool.
§Errors
Returns an error if the SQL INSERT operation fails.
Sourcepub async fn load_position_events(
pool: &PgPool,
position_id: &PositionId,
) -> Result<Vec<OrderFilled>>
pub async fn load_position_events( pool: &PgPool, position_id: &PositionId, ) -> Result<Vec<OrderFilled>>
Loads all fill events for a position_id via the provided pool.
§Errors
Returns an error if the SQL SELECT or deserialization fails.
Sourcepub async fn load_position(
pool: &PgPool,
position_id: &PositionId,
) -> Result<Option<Position>>
pub async fn load_position( pool: &PgPool, position_id: &PositionId, ) -> Result<Option<Position>>
Loads and replays a complete Position for a position_id via the provided pool.
§Errors
Returns an error if loading events, loading instruments, or replaying fills fails.
Sourcepub async fn load_positions(pool: &PgPool) -> Result<Vec<Position>>
pub async fn load_positions(pool: &PgPool) -> Result<Vec<Position>>
Loads and replays all Position entries via the provided pool.
§Errors
Returns an error if loading position IDs or replaying any position fails.
Sourcepub async fn add_account(
pool: &PgPool,
updated: bool,
account_event: AccountState,
) -> Result<()>
pub async fn add_account( pool: &PgPool, updated: bool, account_event: AccountState, ) -> Result<()>
Inserts or updates an AccountState event via the provided pool.
§Errors
Returns an error if the SQL INSERT or UPDATE operation fails.
Sourcepub async fn load_account_events(
pool: &PgPool,
account_id: &AccountId,
) -> Result<Vec<AccountState>>
pub async fn load_account_events( pool: &PgPool, account_id: &AccountId, ) -> Result<Vec<AccountState>>
Loads all account events for account_id via the provided pool.
§Errors
Returns an error if the SQL SELECT or deserialization fails.
Sourcepub async fn load_account(
pool: &PgPool,
account_id: &AccountId,
) -> Result<Option<AccountAny>>
pub async fn load_account( pool: &PgPool, account_id: &AccountId, ) -> Result<Option<AccountAny>>
Loads and assembles a complete AccountAny for account_id via the provided pool.
§Errors
Returns an error if assembling events or SQL operations fail.
Sourcepub async fn load_accounts(pool: &PgPool) -> Result<Vec<AccountAny>>
pub async fn load_accounts(pool: &PgPool) -> Result<Vec<AccountAny>>
Loads and assembles all AccountAny entries via the provided pool.
§Errors
Returns an error if loading events or SQL operations fail.
Sourcepub async fn add_trade(pool: &PgPool, trade: &TradeTick) -> Result<()>
pub async fn add_trade(pool: &PgPool, trade: &TradeTick) -> Result<()>
Inserts a TradeTick entry via the provided pool.
§Errors
Returns an error if the SQL INSERT operation fails.
Sourcepub async fn load_trades(
pool: &PgPool,
instrument_id: &InstrumentId,
) -> Result<Vec<TradeTick>>
pub async fn load_trades( pool: &PgPool, instrument_id: &InstrumentId, ) -> Result<Vec<TradeTick>>
Loads all TradeTick entries for instrument_id via the provided pool.
§Errors
Returns an error if the SQL SELECT or deserialization fails.
Sourcepub async fn add_quote(pool: &PgPool, quote: &QuoteTick) -> Result<()>
pub async fn add_quote(pool: &PgPool, quote: &QuoteTick) -> Result<()>
Inserts a QuoteTick entry via the provided pool.
§Errors
Returns an error if the SQL INSERT operation fails.
Sourcepub async fn load_quotes(
pool: &PgPool,
instrument_id: &InstrumentId,
) -> Result<Vec<QuoteTick>>
pub async fn load_quotes( pool: &PgPool, instrument_id: &InstrumentId, ) -> Result<Vec<QuoteTick>>
Loads all QuoteTick entries for instrument_id via the provided pool.
§Errors
Returns an error if the SQL SELECT or deserialization fails.
Sourcepub async fn add_bar(pool: &PgPool, bar: &Bar) -> Result<()>
pub async fn add_bar(pool: &PgPool, bar: &Bar) -> Result<()>
Inserts a Bar entry via the provided pool.
§Errors
Returns an error if the SQL INSERT operation fails.
Sourcepub async fn load_bars(
pool: &PgPool,
instrument_id: &InstrumentId,
) -> Result<Vec<Bar>>
pub async fn load_bars( pool: &PgPool, instrument_id: &InstrumentId, ) -> Result<Vec<Bar>>
Loads all Bar entries for instrument_id via the provided pool.
§Errors
Returns an error if the SQL SELECT or deserialization fails.
Sourcepub async fn load_distinct_order_event_client_ids(
pool: &PgPool,
) -> Result<AHashMap<ClientOrderId, ClientId>>
pub async fn load_distinct_order_event_client_ids( pool: &PgPool, ) -> Result<AHashMap<ClientOrderId, ClientId>>
Loads all distinct client order IDs from order events via the provided pool.
§Errors
Returns an error if the SQL SELECT or iteration fails.
Sourcepub async fn index_order_position(
pool: &PgPool,
client_order_id: ClientOrderId,
position_id: PositionId,
) -> Result<()>
pub async fn index_order_position( pool: &PgPool, client_order_id: ClientOrderId, position_id: PositionId, ) -> Result<()>
Inserts or updates an order ID to position ID index entry via the provided pool.
§Errors
Returns an error if the SQL INSERT or UPDATE operation fails.
Sourcepub async fn load_index_order_position(
pool: &PgPool,
) -> Result<AHashMap<ClientOrderId, PositionId>>
pub async fn load_index_order_position( pool: &PgPool, ) -> Result<AHashMap<ClientOrderId, PositionId>>
Loads the order ID to position ID index via the provided pool.
§Errors
Returns an error if the SQL SELECT or iteration fails.
Sourcepub async fn add_signal(pool: &PgPool, signal: &Signal) -> Result<()>
pub async fn add_signal(pool: &PgPool, signal: &Signal) -> Result<()>
Inserts a Signal entry via the provided pool.
§Errors
Returns an error if the SQL INSERT operation fails.
Sourcepub async fn load_signals(pool: &PgPool, name: &str) -> Result<Vec<Signal>>
pub async fn load_signals(pool: &PgPool, name: &str) -> Result<Vec<Signal>>
Loads all Signal entries by name via the provided pool.
§Errors
Returns an error if the SQL SELECT or deserialization fails.
Sourcepub async fn add_custom_data(pool: &PgPool, data: &CustomData) -> Result<()>
pub async fn add_custom_data(pool: &PgPool, data: &CustomData) -> Result<()>
Inserts a CustomData entry via the provided pool.
Serializes the model CustomData to full JSON and stores it in the JSONB value column.
§Errors
Returns an error if the SQL INSERT operation fails.
Sourcepub async fn load_custom_data(
pool: &PgPool,
data_type: &DataType,
) -> Result<Vec<CustomData>>
pub async fn load_custom_data( pool: &PgPool, data_type: &DataType, ) -> Result<Vec<CustomData>>
Loads all CustomData entries of data_type via the provided pool.
Filters by data_type, metadata, and identifier columns to match the requested data type.
§Errors
Returns an error if the SQL SELECT or deserialization fails.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DatabaseQueries
impl RefUnwindSafe for DatabaseQueries
impl Send for DatabaseQueries
impl Sync for DatabaseQueries
impl Unpin for DatabaseQueries
impl UnsafeUnpin for DatabaseQueries
impl UnwindSafe for DatabaseQueries
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more