Struct DatabaseQueries

Source
pub struct DatabaseQueries;

Implementations§

Source§

impl DatabaseQueries

Source

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.

Source

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.

Source

pub async fn load(pool: &PgPool) -> Result<HashMap<String, Vec<u8>>>

Loads all entries from the general table via the provided pool.

§Errors

Returns an error if the SELECT operation fails.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn add_order( pool: &PgPool, _kind: &str, updated: bool, order: Box<dyn Order>, client_id: Option<ClientId>, ) -> Result<()>

Inserts or updates an OrderAny entry via the provided pool.

§Errors

Returns an error if the SQL INSERT or UPDATE operation fails.

§Panics

Panics if the order initialization existence check unwraps None after awaiting.

Source

pub async fn add_order_snapshot( pool: &PgPool, snapshot: OrderSnapshot, ) -> Result<()>

Inserts an OrderSnapshot entry via the provided pool.

§Errors

Returns an error if the SQL INSERT operation fails.

§Panics

Panics if serialization of snapshot.exec_algorithm_params fails.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

§Panics

Panics if assembling the order from events fails.

Source

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.

§Panics

Panics if loading or assembling any individual order fails.

Source

pub async fn add_account( pool: &PgPool, kind: &str, updated: bool, account: Box<dyn Account>, ) -> Result<()>

Inserts or updates an AccountAny entry via the provided pool.

§Errors

Returns an error if the SQL INSERT or UPDATE operation fails.

§Panics

Panics if checking for existing account event unwrap fails.

Source

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.

Source

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.

§Panics

Panics if assembling the account from events fails.

Source

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.

§Panics

Panics if loading or assembling any individual account fails.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn load_distinct_order_event_client_ids( pool: &PgPool, ) -> Result<HashMap<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.

Source

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.

Source

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.

Source

pub async fn add_custom_data(pool: &PgPool, data: &CustomData) -> Result<()>

Inserts a CustomData entry via the provided pool.

§Errors

Returns an error if the SQL INSERT operation fails.

Source

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.

§Errors

Returns an error if the SQL SELECT or deserialization fails.

Trait Implementations§

Source§

impl Debug for DatabaseQueries

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
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
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> Ungil for T
where T: Send,