Skip to main content

OrdersService

Trait OrdersService 

Source
pub trait OrdersService:
    Send
    + Sync
    + 'static {
    // Required methods
    fn preview_order<'a>(
        &'a self,
        ctx: RequestContext,
        request: ServiceRequest<'_, PreviewOrderRequest>,
    ) -> impl Future<Output = ServiceResult<impl Encodable<PreviewOrderResponse> + Send + use<'a, Self>>> + Send;
    fn create_order<'a>(
        &'a self,
        ctx: RequestContext,
        request: ServiceRequest<'_, CreateOrderRequest>,
    ) -> impl Future<Output = ServiceResult<impl Encodable<CreateOrderResponse> + Send + use<'a, Self>>> + Send;
    fn cancel_order<'a>(
        &'a self,
        ctx: RequestContext,
        request: ServiceRequest<'_, CancelOrderRequest>,
    ) -> impl Future<Output = ServiceResult<impl Encodable<CancelOrderResponse> + Send + use<'a, Self>>> + Send;
    fn cancel_all_orders<'a>(
        &'a self,
        ctx: RequestContext,
        request: ServiceRequest<'_, CancelAllOrdersRequest>,
    ) -> impl Future<Output = ServiceResult<impl Encodable<CancelAllOrdersResponse> + Send + use<'a, Self>>> + Send;
    fn cancel_all_after<'a>(
        &'a self,
        ctx: RequestContext,
        request: ServiceRequest<'_, CancelAllAfterRequest>,
    ) -> impl Future<Output = ServiceResult<impl Encodable<CancelAllAfterResponse> + Send + use<'a, Self>>> + Send;
    fn batch_create_orders<'a>(
        &'a self,
        ctx: RequestContext,
        request: ServiceRequest<'_, BatchCreateOrdersRequest>,
    ) -> impl Future<Output = ServiceResult<impl Encodable<BatchCreateOrdersResponse> + Send + use<'a, Self>>> + Send;
    fn modify_order<'a>(
        &'a self,
        ctx: RequestContext,
        request: ServiceRequest<'_, ModifyOrderRequest>,
    ) -> impl Future<Output = ServiceResult<impl Encodable<ModifyOrderResponse> + Send + use<'a, Self>>> + Send;
    fn batch_replace_orders<'a>(
        &'a self,
        ctx: RequestContext,
        request: ServiceRequest<'_, BatchReplaceOrdersRequest>,
    ) -> impl Future<Output = ServiceResult<impl Encodable<BatchReplaceOrdersResponse> + Send + use<'a, Self>>> + Send;
    fn batch_cancel_orders<'a>(
        &'a self,
        ctx: RequestContext,
        request: ServiceRequest<'_, BatchCancelOrdersRequest>,
    ) -> impl Future<Output = ServiceResult<impl Encodable<BatchCancelOrdersResponse> + Send + use<'a, Self>>> + Send;
}
Expand description

Server trait for OrdersService.

§Implementing handlers

Implement methods with plain async fn; the returned future satisfies the Send bound automatically.

Unary and server-streaming requests arrive as ServiceRequest<'_, Req>: a zero-copy view of the request plus its body, valid for the duration of the call. Fields are read directly (request.name is a &str into the decoded buffer) and the borrow may be held across .await points. Anything that must outlive the call — tokio::spawn, channels, server state, or data captured by a returned response stream — takes owned data: call request.to_owned_message() (or copy the specific fields) first.

Client-streaming and bidi requests arrive as InboundStream<Req> — a ServiceStream of StreamMessages. Each item owns its decoded buffer and is Send + 'static, so items can be buffered or moved into spawned tasks; read fields zero-copy through the generated accessor methods (item.name()) or .view(), convert with .to_owned_message(), or yield an item back unchanged — StreamMessage<M> implements Encodable<M>.

Request types resolved through extern_path (e.g. well-known types from another crate) use the same wrappers; the crate that owns the type must be generated with buffa ≥ 0.8.0 and views enabled so the backing HasMessageView impl exists.

The impl Encodable<Out> return bound accepts the owned Out, the generated OutView<'_> / OwnedOutView, MaybeBorrowed, or PreEncoded for handlers that encode a non-'static view internally and pass the bytes across the handler boundary. View bodies are not emitted for output types mapped via extern_path (the impl would be an orphan); return owned for WKT/extern outputs.

Server-streaming and bidi-streaming methods return ServiceStream<impl Encodable<Out> + Send + use<Self>>. The use<Self> precise-capturing clause excludes &self’s lifetime and the request’s lifetime (unary methods use use<'a, Self> and may borrow from &self), so stream items must be 'static and cannot borrow from the request. To stream view-encoded data, encode each item inside the stream body and yield PreEncoded — see its # Streaming example doc.

Required Methods§

Source

fn preview_order<'a>( &'a self, ctx: RequestContext, request: ServiceRequest<'_, PreviewOrderRequest>, ) -> impl Future<Output = ServiceResult<impl Encodable<PreviewOrderResponse> + Send + use<'a, Self>>> + Send

Check whether an order is currently admissible without creating an order, claiming its client order ID, or reserving funds.

'a lets the response body borrow from &self (e.g. server-resident state).

request is borrowed from the request body and is valid for the duration of the call; message fields are read directly on it (zero-copy). The response cannot borrow from request — use .to_owned_message() (or copy the specific fields) for anything returned, stored, or moved into tokio::spawn.

Source

fn create_order<'a>( &'a self, ctx: RequestContext, request: ServiceRequest<'_, CreateOrderRequest>, ) -> impl Future<Output = ServiceResult<impl Encodable<CreateOrderResponse> + Send + use<'a, Self>>> + Send

Create a new order. REST clients submit decimal quantity and price strings. ConnectRPC clients submit scaled integer values.

'a lets the response body borrow from &self (e.g. server-resident state).

request is borrowed from the request body and is valid for the duration of the call; message fields are read directly on it (zero-copy). The response cannot borrow from request — use .to_owned_message() (or copy the specific fields) for anything returned, stored, or moved into tokio::spawn.

Source

fn cancel_order<'a>( &'a self, ctx: RequestContext, request: ServiceRequest<'_, CancelOrderRequest>, ) -> impl Future<Output = ServiceResult<impl Encodable<CancelOrderResponse> + Send + use<'a, Self>>> + Send

Cancels an existing order by id or client order id. REST clients submit base58 order IDs. ConnectRPC clients submit fixed64 order IDs.

'a lets the response body borrow from &self (e.g. server-resident state).

request is borrowed from the request body and is valid for the duration of the call; message fields are read directly on it (zero-copy). The response cannot borrow from request — use .to_owned_message() (or copy the specific fields) for anything returned, stored, or moved into tokio::spawn.

Source

fn cancel_all_orders<'a>( &'a self, ctx: RequestContext, request: ServiceRequest<'_, CancelAllOrdersRequest>, ) -> impl Future<Output = ServiceResult<impl Encodable<CancelAllOrdersResponse> + Send + use<'a, Self>>> + Send

Cancels all matching open orders for an account (kill switch). Evaluates matching orders from a consistent snapshot at request start. Final state is confirmed via the order update stream or read path.

'a lets the response body borrow from &self (e.g. server-resident state).

request is borrowed from the request body and is valid for the duration of the call; message fields are read directly on it (zero-copy). The response cannot borrow from request — use .to_owned_message() (or copy the specific fields) for anything returned, stored, or moved into tokio::spawn.

Source

fn cancel_all_after<'a>( &'a self, ctx: RequestContext, request: ServiceRequest<'_, CancelAllAfterRequest>, ) -> impl Future<Output = ServiceResult<impl Encodable<CancelAllAfterResponse> + Send + use<'a, Self>>> + Send

Set cancel-all-after (dead-man switch). Arms or disables automatic cancel-all if heartbeat is not refreshed before expiry.

'a lets the response body borrow from &self (e.g. server-resident state).

request is borrowed from the request body and is valid for the duration of the call; message fields are read directly on it (zero-copy). The response cannot borrow from request — use .to_owned_message() (or copy the specific fields) for anything returned, stored, or moved into tokio::spawn.

Source

fn batch_create_orders<'a>( &'a self, ctx: RequestContext, request: ServiceRequest<'_, BatchCreateOrdersRequest>, ) -> impl Future<Output = ServiceResult<impl Encodable<BatchCreateOrdersResponse> + Send + use<'a, Self>>> + Send

Places multiple orders in a single request (best-effort per item).

'a lets the response body borrow from &self (e.g. server-resident state).

request is borrowed from the request body and is valid for the duration of the call; message fields are read directly on it (zero-copy). The response cannot borrow from request — use .to_owned_message() (or copy the specific fields) for anything returned, stored, or moved into tokio::spawn.

Source

fn modify_order<'a>( &'a self, ctx: RequestContext, request: ServiceRequest<'_, ModifyOrderRequest>, ) -> impl Future<Output = ServiceResult<impl Encodable<ModifyOrderResponse> + Send + use<'a, Self>>> + Send

Modifies an existing order using explicit behavior policy.

'a lets the response body borrow from &self (e.g. server-resident state).

request is borrowed from the request body and is valid for the duration of the call; message fields are read directly on it (zero-copy). The response cannot borrow from request — use .to_owned_message() (or copy the specific fields) for anything returned, stored, or moved into tokio::spawn.

Source

fn batch_replace_orders<'a>( &'a self, ctx: RequestContext, request: ServiceRequest<'_, BatchReplaceOrdersRequest>, ) -> impl Future<Output = ServiceResult<impl Encodable<BatchReplaceOrdersResponse> + Send + use<'a, Self>>> + Send

Replaces same-symbol orders and returns after authoritative admission.

'a lets the response body borrow from &self (e.g. server-resident state).

request is borrowed from the request body and is valid for the duration of the call; message fields are read directly on it (zero-copy). The response cannot borrow from request — use .to_owned_message() (or copy the specific fields) for anything returned, stored, or moved into tokio::spawn.

Source

fn batch_cancel_orders<'a>( &'a self, ctx: RequestContext, request: ServiceRequest<'_, BatchCancelOrdersRequest>, ) -> impl Future<Output = ServiceResult<impl Encodable<BatchCancelOrdersResponse> + Send + use<'a, Self>>> + Send

Cancels multiple orders by explicit ID in a single request. Per-item results are returned; partial success is the default. Final state is confirmed via the order update stream or read path.

'a lets the response body borrow from &self (e.g. server-resident state).

request is borrowed from the request body and is valid for the duration of the call; message fields are read directly on it (zero-copy). The response cannot borrow from request — use .to_owned_message() (or copy the specific fields) for anything returned, stored, or moved into tokio::spawn.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§