Runtime selector for the engine's storage synchronization policy.
typedef uint8_t OpenPitSyncPolicy;
/**
* Concurrent invocation of public methods on the same handle is safe.
* Sequential cross-thread access is also safe. Use this when the engine is
* shared across threads.
*/
#define OpenPitSyncPolicy_Full ((OpenPitSyncPolicy) 0)
/**
* The handle stays on the OS thread that created it. Use this for
* single-threaded embeddings where synchronization overhead must be zero.
*/
#define OpenPitSyncPolicy_Local ((OpenPitSyncPolicy) 1)
/**
* Sequential cross-thread access on the same handle is safe; the caller pins
* each account to a single processing chain (one queue or one worker at a
* time). Concurrent invocation on the same handle is not supported in this
* mode.
*/
#define OpenPitSyncPolicy_Account ((OpenPitSyncPolicy) 2)Opaque builder pointer used to assemble an engine instance.
Ownership:
- returned by
openpit_create_engine_builder; - owned by the caller until passed to
openpit_destroy_engine_builder; - consumed by
openpit_engine_builder_build.
typedef struct OpenPitEngineBuilder OpenPitEngineBuilder;Opaque engine pointer.
The engine stores policies and mutable risk state. The caller owns the pointer
until openpit_destroy_engine.
typedef struct OpenPitEngine OpenPitEngine;Opaque pointer for a deferred pre-trade request.
This is returned by openpit_engine_start_pre_trade. It can be executed once
with openpit_pretrade_pre_trade_request_execute or discarded with
openpit_destroy_pretrade_pre_trade_request.
typedef struct OpenPitPretradePreTradeRequest OpenPitPretradePreTradeRequest;Opaque reservation pointer returned by a successful pre-trade check.
A reservation represents resources that have been tentatively locked. The caller
must resolve it exactly once by calling
openpit_pretrade_pre_trade_reservation_commit,
openpit_pretrade_pre_trade_reservation_rollback, or
openpit_destroy_pretrade_pre_trade_reservation.
typedef struct OpenPitPretradePreTradeReservation
OpenPitPretradePreTradeReservation;Price-lock snapshot returned from a reservation.
typedef struct OpenPitPretradePreTradeLock {
OpenPitParamPriceOptional price;
} OpenPitPretradePreTradeLock;Result status for pre-trade operations.
typedef uint8_t OpenPitPretradeStatus;
/**
* Order/request passed this stage; read the success out-pointer.
*/
#define OpenPitPretradeStatus_Passed ((OpenPitPretradeStatus) 0)
/**
* Order/request was rejected; read the reject out-pointer.
*/
#define OpenPitPretradeStatus_Rejected ((OpenPitPretradeStatus) 1)
/**
* Call failed due to invalid input; read the error out-pointer.
*/
#define OpenPitPretradeStatus_Error ((OpenPitPretradeStatus) 2)Batch rejection details returned by account-adjustment apply API.
Ownership:
- created by
openpit_engine_apply_account_adjustmentonRejected; - owned by the caller;
- released with
openpit_destroy_account_adjustment_batch_error.
typedef struct OpenPitAccountAdjustmentBatchError
OpenPitAccountAdjustmentBatchError;Creates a new engine builder with the chosen synchronization policy.
Success:
- returns a non-null caller-owned builder object.
Error:
- returns null when
sync_policyis not one ofOpenPitSyncPolicy_Full(0),OpenPitSyncPolicy_Local(1), orOpenPitSyncPolicy_Account(2); - if
out_erroris not null, writes a caller-ownedOpenPitSharedStringerror handle that MUST be released withopenpit_destroy_shared_string.
Cleanup:
- release the pointer with
openpit_destroy_engine_builderif you stop before building; - after a successful build the builder is consumed and must still be released
with
openpit_destroy_engine_builder.
OpenPitEngineBuilder * openpit_create_engine_builder(
uint8_t sync_policy,
OpenPitOutError out_error
);Releases a builder pointer owned by the caller.
Contract:
- passing null is allowed;
- after this call the pointer is invalid;
- this function always succeeds.
void openpit_destroy_engine_builder(
OpenPitEngineBuilder * builder
);Finalizes a builder and creates an engine.
Success:
- returns a non-null engine pointer.
Error:
- returns null when
builderis null, the builder was already consumed, or configuration is invalid; - if
out_erroris not null, writes a caller-ownedOpenPitSharedStringerror handle that MUST be released withopenpit_destroy_shared_string.
Ownership:
- on success the returned engine pointer is owned by the caller and must be
released with
openpit_destroy_engine; - the builder becomes consumed regardless of success and must not be reused.
OpenPitEngine * openpit_engine_builder_build(
OpenPitEngineBuilder * builder,
OpenPitOutError out_error
);Releases an engine pointer owned by the caller.
Contract:
- passing null is allowed;
- destroying the engine also releases any state and policies retained by that engine instance;
- this function always succeeds.
void openpit_destroy_engine(
OpenPitEngine * engine
);Starts pre-trade processing and returns a deferred request pointer.
This stage validates whether the order can enter the full pre-trade flow.
Success:
- returns
Passedwhen the order passed this stage; readout_request; - returns
Rejectedwhen the order was rejected; readout_rejectsif not null.
Error:
- returns
Errorwhen input pointers are invalid or the order payload cannot be decoded; - on
Error, ifout_erroris not null, it is filled with a caller-ownedOpenPitSharedStringthat MUST be destroyed by the caller.
Cleanup:
- release a successful request with
openpit_pretrade_pre_trade_request_executeoropenpit_destroy_pretrade_pre_trade_request.
Reject ownership contract:
- on
Rejected, a non-nullOpenPitPretradeRejectListpointer is written toout_rejectsif it is not null; - the caller takes ownership and MUST release it with
openpit_pretrade_destroy_reject_list; failing to do so leaks the heap allocation made inside this call; - no thread-local state is involved, and the returned pointer is safe to read on any thread;
- on
PassedandError, null is written toout_rejects, and the caller must not call destroy in those cases.
Order lifetime contract:
orderis read as a borrowed view during this call;- the operation snapshots that payload before returning, because the deferred request may outlive the source buffers.
OpenPitPretradeStatus openpit_engine_start_pre_trade(
OpenPitEngine * engine,
const OpenPitOrder * order,
OpenPitPretradePreTradeRequest ** out_request,
OpenPitPretradeRejectList ** out_rejects,
OpenPitOutError out_error
);Runs the complete pre-trade check in one call.
Success:
- returns
Passedwhen the order passed this stage; readout_reservation; - returns
Rejectedwhen the order was rejected is not null; readout_rejects.
Error:
- returns
Errorwhen input pointers are invalid or the order payload cannot be decoded; - on
Error, ifout_erroris not null, it is filled with a caller-ownedOpenPitSharedStringthat MUST be destroyed by the caller.
Cleanup:
- release a successful reservation with
openpit_pretrade_pre_trade_reservation_commit,openpit_pretrade_pre_trade_reservation_rollback, oropenpit_destroy_pretrade_pre_trade_reservation.
Reject ownership contract:
- on
Rejected, a non-nullOpenPitPretradeRejectListpointer is written toout_rejectsif it is not null; - the caller takes ownership and MUST release it with
openpit_pretrade_destroy_reject_list; failing to do so leaks the heap allocation made inside this call; - no thread-local state is involved, and the returned pointer is safe to read on any thread;
- on
PassedandError, null is written toout_rejects, and the caller must not call destroy in those cases.
Order lifetime contract:
orderis read as a borrowed view during this call only;- the operation does not retain any pointer into source memory after this function returns.
OpenPitPretradeStatus openpit_engine_execute_pre_trade(
OpenPitEngine * engine,
const OpenPitOrder * order,
OpenPitPretradePreTradeReservation ** out_reservation,
OpenPitPretradeRejectList ** out_rejects,
OpenPitOutError out_error
);Executes a deferred request returned by openpit_engine_start_pre_trade.
Success:
- returns
Passedwhen the order passed this stage; readout_reservation; - returns
Rejectedwhen the order was rejected andout_rejectsis not null; readout_rejects.
Error:
- returns
Errorwhen input pointers are invalid or the order payload cannot be decoded; - on
Error, ifout_erroris not null, it is filled with a caller-ownedOpenPitSharedStringthat MUST be destroyed by the caller.
Ownership:
- this call consumes the request object's content exactly once;
- after a successful or failed execute, the object itself may still be
released with
openpit_destroy_pretrade_pre_trade_request, but it cannot be executed again.
Reject ownership contract:
- on
Rejected, a non-nullOpenPitPretradeRejectListpointer is written toout_rejectsif it is not null; - the caller takes ownership and MUST release it with
openpit_pretrade_destroy_reject_list; failing to do so leaks the heap allocation made inside this call; - no thread-local state is involved, and the returned pointer is safe to read on any thread;
- on
PassedandError, null is written toout_rejects, and the caller must not call destroy in those cases.
OpenPitPretradeStatus openpit_pretrade_pre_trade_request_execute(
OpenPitPretradePreTradeRequest * request,
OpenPitPretradePreTradeReservation ** out_reservation,
OpenPitPretradeRejectList ** out_rejects,
OpenPitOutError out_error
);Releases a deferred request pointer owned by the caller.
Contract:
- passing null is allowed;
- destroying an unexecuted request abandons it without creating a reservation;
- this function always succeeds.
void openpit_destroy_pretrade_pre_trade_request(
OpenPitPretradePreTradeRequest * request
);Finalizes a reservation and applies the reserved state permanently.
This call is idempotent at the pointer level: if the reservation was already consumed, nothing happens. Passing null is allowed.
Contract:
- passing null is allowed;
- this function always succeeds.
void openpit_pretrade_pre_trade_reservation_commit(
OpenPitPretradePreTradeReservation * reservation
);Cancels a reservation and releases the reserved state.
This call is idempotent at the pointer level: if the reservation was already consumed, nothing happens. Passing null is allowed.
Contract:
- passing null is allowed;
- this function always succeeds.
void openpit_pretrade_pre_trade_reservation_rollback(
OpenPitPretradePreTradeReservation * reservation
);Returns a snapshot of the lock attached to a reservation.
Contract:
reservationmust be a valid non-null pointer;- violating the pointer contract aborts the call;
- this function never fails.
Lifetime contract:
- the returned snapshot is detached from the reservation state.
OpenPitPretradePreTradeLock openpit_pretrade_pre_trade_reservation_get_lock(
const OpenPitPretradePreTradeReservation * reservation
);Releases a reservation pointer owned by the caller.
Contract:
- passing null is allowed;
- destroying an unresolved reservation triggers rollback of any pending mutations;
- callers that need explicit resolution should call commit or rollback first;
- this function always succeeds.
void openpit_destroy_pretrade_pre_trade_reservation(
OpenPitPretradePreTradeReservation * reservation
);Applies an execution report to engine state.
Returns true on success, false on error.
Success:
- returns
true; - if
out_blocksis not null and at least one policy entered a blocked state, writes a caller-ownedOpenPitPretradeAccountBlockListpointer; release it withopenpit_pretrade_destroy_account_block_list; - if
out_blocksis not null and no policy blocked, writes null.
Error:
- returns
falsewhen input pointers are invalid or the report payload cannot be decoded; - if
out_erroris not null, writes a caller-ownedOpenPitSharedStringerror handle that MUST be released withopenpit_destroy_shared_string.
Lifetime contract:
reportis read as a borrowed view during this call only;- the operation does not retain any pointer into source memory after this function returns.
bool openpit_engine_apply_execution_report(
OpenPitEngine * engine,
const OpenPitExecutionReport * report,
OpenPitPretradeAccountBlockList ** out_blocks,
OpenPitOutError out_error
);Releases a batch-error object returned by account-adjustment apply.
Contract:
- passing null is allowed;
- this function always succeeds.
void openpit_destroy_account_adjustment_batch_error(
OpenPitAccountAdjustmentBatchError * batch_error
);Returns the failing adjustment index from a batch error.
Contract:
batch_errormust be a valid non-null pointer;- this function never fails;
- violating the pointer contract aborts the call.
size_t openpit_account_adjustment_batch_error_get_failed_adjustment_index(
const OpenPitAccountAdjustmentBatchError * batch_error
);Returns a non-owning reject-list view from a batch error.
Contract:
batch_errormust be a valid non-null pointer;- the returned pointer is valid while
batch_erroris alive; - this function never fails;
- violating the pointer contract aborts the call.
const OpenPitPretradeRejectList *
openpit_account_adjustment_batch_error_get_rejects(
const OpenPitAccountAdjustmentBatchError * batch_error
);Applies a batch of account adjustments to one account.
Success:
- returns
OpenPitAccountAdjustmentApplyStatus::Appliedwhen the batch was accepted and applied; - returns
OpenPitAccountAdjustmentApplyStatus::Rejectedwhen the call itself completed normally but a policy rejected the batch; readout_reject.
Error:
- returns
OpenPitAccountAdjustmentApplyStatus::Errorwhen input pointers are invalid or some adjustment payload cannot be decoded; - on
Error, ifout_erroris not null, it is filled with a caller-ownedOpenPitSharedStringthat MUST be destroyed by the caller.
Result handling:
Appliedmeans there is no reject object to clean up;Rejectedstores batch error details inout_reject, the caller must release a returned object withopenpit_destroy_account_adjustment_batch_error;- rejects returned by
openpit_account_adjustment_batch_error_get_rejectscontain string views borrowed from the batch error and must not be used after the batch error is destroyed; - when
Erroris returned, do not use any pointer from a previous unrelated call as if it belonged to this failure.
Lifetime contract:
- every
adjustmententry from the contiguous input array is read as a borrowed view during this call only; - release a returned batch error with
openpit_destroy_account_adjustment_batch_error.
OpenPitAccountAdjustmentApplyStatus openpit_engine_apply_account_adjustment(
OpenPitEngine * engine,
OpenPitParamAccountId account_id,
const OpenPitAccountAdjustment * adjustments,
size_t adjustments_len,
OpenPitAccountAdjustmentBatchError ** out_reject,
OpenPitOutError out_error
);