Engine
OpenPitPostTradeResult
Caller-owned aggregate returned by the post-trade engine operation.
typedef struct OpenPitPostTradeResult OpenPitPostTradeResult;
OpenPitSyncPolicy
Runtime selector for the engine's storage synchronization policy.
typedef uint8_t OpenPitSyncPolicy;
/**
* The handle stays on the OS thread that created it. Use this for
* single-threaded embeddings where synchronization overhead must be zero.
*/
#define OpenPitSyncPolicy_None ((OpenPitSyncPolicy) 0)
/**
* 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) 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)
OpenPitEngineBuilder
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;
OpenPitEngine
Opaque engine pointer.
The engine stores policies and mutable risk state. The caller owns the pointer until openpit_destroy_engine.
typedef struct OpenPitEngine OpenPitEngine;
OpenPitPretradePreTradeRequest
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;
OpenPitPretradePreTradeReservation
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;
OpenPitPretradePreTradeDryRunReport
Opaque report pointer returned by a pre-trade dry-run.
A dry-run reports the verdict the equivalent real call would produce with zero effect on engine state. Unlike OpenPitPretradePreTradeReservation, this report is inert: it carries no commit/rollback capability. The caller owns the pointer and MUST release it with openpit_destroy_pretrade_pre_trade_dry_run_report.
typedef struct OpenPitPretradePreTradeDryRunReport
OpenPitPretradePreTradeDryRunReport;
OpenPitPretradeStatus
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)
OpenPitAccountAdjustmentBatchError
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;
OpenPitEngineBuildErrorCode
Machine-readable discriminant describing why building an engine failed.
Each value identifies a distinct failure category. There is no success value: a build-error object exists only when a build did not produce an engine.
typedef uint8_t OpenPitEngineBuildErrorCode;
/**
* Two or more registered policies declare the same name.
*/
#define OpenPitEngineBuildErrorCode_DuplicatePolicyName \
((OpenPitEngineBuildErrorCode) 0)
/**
* Two or more registered policies declare the same non-default group id.
*/
#define OpenPitEngineBuildErrorCode_DuplicatePolicyGroupId \
((OpenPitEngineBuildErrorCode) 1)
/**
* A failure category not covered by the above. Forward-compatible catch-all;
* no structured payload is available.
*/
#define OpenPitEngineBuildErrorCode_Other ((OpenPitEngineBuildErrorCode) 2)
OpenPitEngineBuildError
Structured build-failure details returned by engine construction.
Ownership:
- created by
openpit_engine_builder_buildwhen building does not produce an engine; - owned by the caller;
- released with
openpit_destroy_engine_build_error.
typedef struct OpenPitEngineBuildError OpenPitEngineBuildError;
openpit_create_engine_builder
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_None(0),OpenPitSyncPolicy_Full(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
);
openpit_destroy_engine_builder
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
);
openpit_engine_builder_build
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 no policies were registered; - for those non-domain failures, if
out_erroris not null, writes a caller-ownedOpenPitSharedStringerror handle that MUST be released withopenpit_destroy_shared_string;out_build_erroris left untouched; - returns null when the configuration is rejected during building (for example, duplicate policy names or duplicate group ids); in that case, if
out_build_erroris not null, writes a caller-ownedOpenPitEngineBuildErrorpointer that carries the machine-readable failure code and the offending value, and MUST be released withopenpit_destroy_engine_build_error;out_erroris left untouched for this domain failure.
Ownership:
- on success the returned engine pointer is owned by the caller and must be released with
openpit_destroy_engine;out_build_erroris left untouched; - the builder becomes consumed regardless of success and must not be reused.
OpenPitEngine * openpit_engine_builder_build(
OpenPitEngineBuilder * builder,
OpenPitEngineBuildError ** out_build_error,
OpenPitOutError out_error
);
openpit_destroy_engine_build_error
Releases a build-error object returned by engine construction.
Contract:
- passing null is allowed;
- this function always succeeds.
void openpit_destroy_engine_build_error(
OpenPitEngineBuildError * build_error
);
openpit_engine_build_error_get_code
Returns the machine-readable failure category of a build error.
Contract:
build_errormust be a valid non-null pointer;- this function never fails;
- violating the pointer contract aborts the call.
OpenPitEngineBuildErrorCode openpit_engine_build_error_get_code(
const OpenPitEngineBuildError * build_error
);
openpit_engine_build_error_get_policy_name
Returns a non-owning view of the offending policy name from a build error.
Contract:
build_errormust be a valid non-null pointer;- the returned view points into memory owned by
build_errorand is valid whilebuild_erroris alive; it must not be used after the build error is destroyed; - the view is empty unless the failure category is the duplicate-policy-name category;
- this function never fails;
- violating the pointer contract aborts the call.
OpenPitStringView openpit_engine_build_error_get_policy_name(
const OpenPitEngineBuildError * build_error
);
openpit_engine_build_error_get_policy_group_id
Returns the offending policy group id from a build error.
Contract:
build_errormust be a valid non-null pointer;- the value is zero unless the failure category is the duplicate-policy-group-id category;
- this function never fails;
- violating the pointer contract aborts the call.
uint16_t openpit_engine_build_error_get_policy_group_id(
const OpenPitEngineBuildError * build_error
);
openpit_destroy_engine
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
);
openpit_engine_start_pre_trade
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.
Output ownership contract:
- on
Passed, a non-null request pointer is written toout_requestif it is not null; - on
Rejected, a non-nullOpenPitPretradeRejectListpointer is written toout_rejectsif it is not null; - the caller owns either returned object and MUST release it with the corresponding destroy function;
- no thread-local state is involved, and returned pointers are safe to read on any thread;
- on
PassedandError,out_rejectsis left untouched; - on
RejectedandError,out_requestis left untouched.
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
);
openpit_engine_execute_pre_trade
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.
Output ownership contract:
- on
Passed, a non-null reservation pointer is written toout_reservationif it is not null; - on
Rejected, a non-nullOpenPitPretradeRejectListpointer is written toout_rejectsif it is not null; - the caller owns either returned object and MUST release it with the corresponding destroy function;
- no thread-local state is involved, and returned pointers are safe to read on any thread;
- on
PassedandError,out_rejectsis left untouched; - on
RejectedandError,out_reservationis left untouched.
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
);
openpit_engine_execute_pre_trade_drop_copy
Runs the complete pre-trade pipeline without enforcing policy rejects.
Returns true on success and false when input pointers are invalid or the order payload cannot be decoded. Existing account and account-group blocks are ignored. Every policy still runs and keeps its normal mutations, locks, account adjustments, and account blocks, while its rejects are discarded.
On success, if out_reservation is not null, writes one caller-owned reservation pointer. Release it with openpit_pretrade_pre_trade_reservation_commit, openpit_pretrade_pre_trade_reservation_rollback, or openpit_destroy_pretrade_pre_trade_reservation.
On error, out_reservation is left untouched. If out_error is not null, it receives a caller-owned error string that MUST be released with openpit_destroy_shared_string.
bool openpit_engine_execute_pre_trade_drop_copy(
OpenPitEngine * engine,
const OpenPitOrder * order,
OpenPitPretradePreTradeReservation ** out_reservation,
OpenPitOutError out_error
);
openpit_engine_start_pre_trade_dry_run
Runs the start stage as a non-mutating pre-trade dry-run.
A dry-run reports the verdict the start stage would return for order with zero effect on engine state: no policy side effect is applied and no account block is recorded, even when an account-scope reject would latch one. The reported lock and account adjustments are always empty, because they are produced by the main stage, which this call does not run; see openpit_engine_execute_pre_trade_dry_run for a full-pipeline dry-run.
Success:
- returns
trueon valid input and writes a non-null caller-owned report toout_reportif it is not null; the pass/reject verdict lives inside the report (a dry-run never rejects the call).
Error:
- returns
falsewhen input pointers are invalid or the order payload cannot be decoded; - on
false, ifout_erroris not null, it is filled with a caller-ownedOpenPitSharedStringthat MUST be destroyed by the caller.
Cleanup:
- release a produced report with
openpit_destroy_pretrade_pre_trade_dry_run_report.
Output ownership contract:
- on success, a non-null report pointer is written to
out_reportif it is not null; - the caller owns the report and MUST release it with the corresponding destroy function;
- no thread-local state is involved, and the returned pointer is safe to read on any thread;
- on
false,out_reportis left untouched.
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.
bool openpit_engine_start_pre_trade_dry_run(
OpenPitEngine * engine,
const OpenPitOrder * order,
OpenPitPretradePreTradeDryRunReport ** out_report,
OpenPitOutError out_error
);
openpit_engine_execute_pre_trade_dry_run
Runs the full pre-trade pipeline as a non-mutating dry-run.
A dry-run reports the verdict, the lock, and the account adjustments both stages would produce for order with zero effect on engine state: no rate-limit budget is spent, no reservation or hold is applied, and no account block is recorded. Any mutations a main-stage policy registers on the dry-run path are dropped - neither committed nor rolled back - so a repeated dry-run never moves engine state.
Success:
- returns
trueon valid input and writes a non-null caller-owned report toout_reportif it is not null; the pass/reject verdict lives inside the report (a dry-run never rejects the call).
Error:
- returns
falsewhen input pointers are invalid or the order payload cannot be decoded; - on
false, ifout_erroris not null, it is filled with a caller-ownedOpenPitSharedStringthat MUST be destroyed by the caller.
Cleanup:
- release a produced report with
openpit_destroy_pretrade_pre_trade_dry_run_report.
Output ownership contract:
- on success, a non-null report pointer is written to
out_reportif it is not null; - the caller owns the report and MUST release it with the corresponding destroy function;
- no thread-local state is involved, and the returned pointer is safe to read on any thread;
- on
false,out_reportis left untouched.
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.
bool openpit_engine_execute_pre_trade_dry_run(
OpenPitEngine * engine,
const OpenPitOrder * order,
OpenPitPretradePreTradeDryRunReport ** out_report,
OpenPitOutError out_error
);
openpit_pretrade_pre_trade_request_execute
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.
Output ownership contract:
- on
Passed, a non-null reservation pointer is written toout_reservationif it is not null; - on
Rejected, a non-nullOpenPitPretradeRejectListpointer is written toout_rejectsif it is not null; - the caller owns either returned object and MUST release it with the corresponding destroy function;
- no thread-local state is involved, and returned pointers are safe to read on any thread;
- on
PassedandError,out_rejectsis left untouched; - on
RejectedandError,out_reservationis left untouched.
OpenPitPretradeStatus openpit_pretrade_pre_trade_request_execute(
OpenPitPretradePreTradeRequest * request,
OpenPitPretradePreTradeReservation ** out_reservation,
OpenPitPretradeRejectList ** out_rejects,
OpenPitOutError out_error
);
openpit_destroy_pretrade_pre_trade_request
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
);
openpit_pretrade_pre_trade_reservation_commit
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
);
openpit_pretrade_pre_trade_reservation_rollback
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
);
openpit_pretrade_pre_trade_reservation_get_lock
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
);
openpit_pretrade_pre_trade_reservation_get_account_adjustments
Returns the account-adjustment outcomes collected by the reservation.
Contract:
reservationmust be a valid non-null pointer;- violating the pointer contract aborts the call;
- this function never fails;
- always returns a caller-owned
OpenPitAccountAdjustmentOutcomeList(possibly empty); release it withopenpit_destroy_account_adjustment_outcome_list.
Lifetime contract:
- the returned list is detached from the reservation state.
OpenPitAccountAdjustmentOutcomeList *
openpit_pretrade_pre_trade_reservation_get_account_adjustments(
const OpenPitPretradePreTradeReservation * reservation
);
openpit_pretrade_pre_trade_reservation_get_account_block
Returns the winning account block produced by the reservation's pipeline.
Contract:
reservationmust be a valid non-null pointer;- violating the pointer contract aborts the call;
- this function never fails;
- always returns a caller-owned
OpenPitPretradeAccountBlockList(possibly empty); release it withopenpit_pretrade_destroy_account_block_list.
Lifetime contract:
- the returned list is detached from the reservation state.
OpenPitPretradeAccountBlockList *
openpit_pretrade_pre_trade_reservation_get_account_block(
const OpenPitPretradePreTradeReservation * reservation
);
openpit_destroy_pretrade_pre_trade_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
);
openpit_pretrade_pre_trade_dry_run_report_is_pass
Returns whether the order would have passed every pre-trade stage.
Contract:
reportmust be a valid non-null pointer;- violating the pointer contract aborts the call;
- this function never fails;
- equivalent to "the rejects list returned by
openpit_pretrade_pre_trade_dry_run_report_get_rejectsis empty".
bool openpit_pretrade_pre_trade_dry_run_report_is_pass(
const OpenPitPretradePreTradeDryRunReport * report
);
openpit_pretrade_pre_trade_dry_run_report_get_rejects
Returns the rejects the order would have collected.
Contract:
reportmust be a valid non-null pointer;- violating the pointer contract aborts the call;
- this function never fails;
- always returns a caller-owned
OpenPitPretradeRejectList(empty when the order would have passed); release it withopenpit_pretrade_destroy_reject_list.
Lifetime contract:
- the returned list is detached from the report state.
OpenPitPretradeRejectList *
openpit_pretrade_pre_trade_dry_run_report_get_rejects(
const OpenPitPretradePreTradeDryRunReport * report
);
openpit_pretrade_pre_trade_dry_run_report_get_lock
Returns a snapshot of the lock the main stage would have produced.
Contract:
reportmust be a valid non-null pointer;- violating the pointer contract aborts the call;
- this function never fails;
- the lock is empty when the start stage would have rejected (the main stage never runs in that case) or when no policy locks a price; release the returned handle with
openpit_destroy_pretrade_pre_trade_lock.
Lifetime contract:
- the returned snapshot is detached from the report state.
OpenPitPretradePreTradeLock *
openpit_pretrade_pre_trade_dry_run_report_get_lock(
const OpenPitPretradePreTradeDryRunReport * report
);
openpit_pretrade_pre_trade_dry_run_report_get_account_adjustments
Returns the account-adjustment outcomes the main stage would have produced.
Contract:
reportmust be a valid non-null pointer;- violating the pointer contract aborts the call;
- this function never fails;
- always returns a caller-owned
OpenPitAccountAdjustmentOutcomeList(possibly empty); release it withopenpit_destroy_account_adjustment_outcome_list. The numbers match what a real reservation reports for the same order and engine state.
Lifetime contract:
- the returned list is detached from the report state.
OpenPitAccountAdjustmentOutcomeList *
openpit_pretrade_pre_trade_dry_run_report_get_account_adjustments(
const OpenPitPretradePreTradeDryRunReport * report
);
openpit_pretrade_pre_trade_dry_run_report_get_account_block
Returns the account block an account-scope reject would have latched.
Contract:
reportmust be a valid non-null pointer;- violating the pointer contract aborts the call;
- this function never fails;
- always returns a caller-owned
OpenPitPretradeAccountBlockListcarrying the single would-be block, or empty when no account-scope reject would have latched one; release it withopenpit_pretrade_destroy_account_block_list. A real call records this block in the engine's blocked-accounts registry; a dry-run reports it here without recording it.
Lifetime contract:
- the returned list is detached from the report state.
OpenPitPretradeAccountBlockList *
openpit_pretrade_pre_trade_dry_run_report_get_account_block(
const OpenPitPretradePreTradeDryRunReport * report
);
openpit_destroy_pretrade_pre_trade_dry_run_report
Releases a dry-run report pointer owned by the caller.
Contract:
- passing null is allowed;
- after this call the pointer is invalid;
- this function always succeeds.
void openpit_destroy_pretrade_pre_trade_dry_run_report(
OpenPitPretradePreTradeDryRunReport * report
);
openpit_engine_apply_execution_report
Applies an execution report to engine state.
Returns true on success, false on error.
Success:
- returns
true; - if
out_resultis not null, writes one caller-ownedOpenPitPostTradeResultpointer; release it withopenpit_destroy_post_trade_result; - if
out_resultis null, applies the report without allocating a result.
Error:
- returns
falsewhen input pointers are invalid or the report payload cannot be decoded; out_resultis left untouched;- 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,
OpenPitPostTradeResult ** out_result,
OpenPitOutError out_error
);
openpit_destroy_post_trade_result
Releases a caller-owned post-trade result.
void openpit_destroy_post_trade_result(
OpenPitPostTradeResult * result
);
openpit_post_trade_result_get_account_blocks
Returns the borrowed account-block list from a post-trade result.
A valid result always returns a non-null list, including when it is empty. The list and every view copied from it remain valid only while result is alive.
Contract:
resultmust be a valid non-null pointer;- violating the pointer contract aborts the call.
const OpenPitPretradeAccountBlockList *
openpit_post_trade_result_get_account_blocks(
const OpenPitPostTradeResult * result
);
openpit_post_trade_result_get_account_adjustments
Returns the borrowed account-adjustment outcome list from a post-trade result.
A valid result always returns a non-null list, including when it is empty. The list and every view copied from it remain valid only while result is alive.
Contract:
resultmust be a valid non-null pointer;- violating the pointer contract aborts the call.
const OpenPitAccountAdjustmentOutcomeList *
openpit_post_trade_result_get_account_adjustments(
const OpenPitPostTradeResult * result
);
openpit_post_trade_result_get_account_pnls
Returns the borrowed account-level PnL outcome list from a post-trade result.
A valid result always returns a non-null list, including when it is empty. The list and every view copied from it remain valid only while result is alive.
Contract:
resultmust be a valid non-null pointer;- violating the pointer contract aborts the call.
const OpenPitAccountPnlOutcomeList * openpit_post_trade_result_get_account_pnls(
const OpenPitPostTradeResult * result
);
openpit_destroy_account_adjustment_batch_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
);
openpit_account_adjustment_batch_error_get_failed_adjustment_index
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
);
openpit_account_adjustment_batch_error_get_rejects
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
);
openpit_engine_apply_account_adjustment
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;- on
Applied, ifout_outcomesis not null and at least one policy produced an account-adjustment outcome, writes a caller-ownedOpenPitAccountAdjustmentOutcomeListpointer; release it withopenpit_destroy_account_adjustment_outcome_list; if no outcome was produced,out_outcomesis left untouched; - on
Applied, ifout_blocksis not null and a policy reported one or more account blocks, writes a caller-ownedOpenPitPretradeAccountBlockListpointer; release it withopenpit_pretrade_destroy_account_block_list; if no block was produced,out_blocksis left untouched. The engine has already recorded every returned block; 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; - release a returned account-block list with
openpit_pretrade_destroy_account_block_list.
OpenPitAccountAdjustmentApplyStatus openpit_engine_apply_account_adjustment(
OpenPitEngine * engine,
OpenPitParamAccountId account_id,
const OpenPitAccountAdjustment * adjustments,
size_t adjustments_len,
OpenPitAccountAdjustmentBatchError ** out_reject,
OpenPitAccountAdjustmentOutcomeList ** out_outcomes,
OpenPitPretradeAccountBlockList ** out_blocks,
OpenPitOutError out_error
);
OpenPitAccountGroupError
Structured error returned by account-group registry operations.
Ownership:
- created by
openpit_engine_register_account_groupandopenpit_engine_unregister_account_groupon failure; - owned by the caller;
- released with
openpit_destroy_account_group_error.
typedef struct OpenPitAccountGroupError OpenPitAccountGroupError;
openpit_destroy_account_group_error
Releases a caller-owned account-group error.
Contract:
- call exactly once per pointer returned by a registry function;
- passing null is allowed and has no effect.
void openpit_destroy_account_group_error(
OpenPitAccountGroupError * err
);
openpit_account_group_error_get_message
Returns the human-readable error message from an account-group error.
Contract:
errmust be a valid non-null pointer;- the returned view borrows from the error object and is valid while the error is alive;
- violating the pointer contract aborts the call.
OpenPitStringView openpit_account_group_error_get_message(
const OpenPitAccountGroupError * err
);
openpit_account_group_error_get_account
Returns the offending account identifier from an account-group error.
Contract:
errmust be a valid non-null pointer;- this function never fails;
- violating the pointer contract aborts the call.
OpenPitParamAccountId openpit_account_group_error_get_account(
const OpenPitAccountGroupError * err
);
openpit_account_group_error_get_current_group
Returns the current group of the offending account from an account-group error, or returns false and leaves out_group untouched when no group is set.
Contract:
errmust be a valid non-null pointer;out_groupmust be a valid non-null pointer;- returns
truewhen the account belongs to a group and writes that group toout_group; - returns
falsewhen the account belongs to no group;out_groupis written to only when the return value istrue; - violating the pointer contract aborts the call.
bool openpit_account_group_error_get_current_group(
const OpenPitAccountGroupError * err,
OpenPitParamAccountGroupId * out_group
);
openpit_engine_register_account_group
Atomically registers every account in accounts into group.
The operation is all-or-nothing: if any listed account is already a member of any group (including group), no account is registered.
Contract:
enginemust be a valid non-null engine pointer;accountsmust point to an array of at leastaccounts_lenaccount identifiers, or may be null whenaccounts_lenis zero;groupis the target group and must not be the reservedOPENPIT_DEFAULT_ACCOUNT_GROUP.
Success:
- returns
true; all listed accounts are now members ofgroup.
Error:
- returns
falsewhenengineis null,accountsis null with non-zero length,groupis the reserved default group, or any listed account is already registered; - for pointer/argument errors, if
out_erroris not null, writes a caller-ownedOpenPitSharedStringerror handle that MUST be released withopenpit_destroy_shared_string; - for domain errors (reserved target group, or account already registered), if
out_group_erroris not null, writes a caller-ownedOpenPitAccountGroupErrorpointer that MUST be released withopenpit_destroy_account_group_error;out_erroris left untouched for domain failures.
bool openpit_engine_register_account_group(
OpenPitEngine * engine,
const OpenPitParamAccountId * accounts,
size_t accounts_len,
OpenPitParamAccountGroupId group,
OpenPitAccountGroupError ** out_group_error,
OpenPitOutError out_error
);
openpit_engine_unregister_account_group
Atomically removes every account in accounts from group.
The operation is all-or-nothing: if any listed account is not currently a member of group, no account is removed.
Contract:
enginemust be a valid non-null engine pointer;accountsmust point to an array of at leastaccounts_lenaccount identifiers, or may be null whenaccounts_lenis zero;groupis the group to remove accounts from and must not be the reservedOPENPIT_DEFAULT_ACCOUNT_GROUP.
Success:
- returns
true; all listed accounts are now removed fromgroup.
Error:
- returns
falsewhenengineis null,accountsis null with non-zero length,groupis the reserved default group, or any listed account is not ingroup; - for pointer/argument errors, if
out_erroris not null, writes a caller-ownedOpenPitSharedStringerror handle that MUST be released withopenpit_destroy_shared_string; - for domain errors (reserved target group, or account not in group), if
out_group_erroris not null, writes a caller-ownedOpenPitAccountGroupErrorpointer that MUST be released withopenpit_destroy_account_group_error;out_erroris left untouched for domain failures.
bool openpit_engine_unregister_account_group(
OpenPitEngine * engine,
const OpenPitParamAccountId * accounts,
size_t accounts_len,
OpenPitParamAccountGroupId group,
OpenPitAccountGroupError ** out_group_error,
OpenPitOutError out_error
);
openpit_engine_account_group
Returns the account-group membership of a single account.
Contract:
enginemust be a valid non-null engine pointer;accountis the account identifier to look up;out_groupmust be a valid non-null pointer.
Success:
- returns
truewhen the account belongs to a group and writes that group identifier toout_group; - returns
falsewhen the account belongs to no group;out_groupis not written to when the return value isfalse.
Error:
- aborts the call when
engineorout_groupis null.
bool openpit_engine_account_group(
const OpenPitEngine * engine,
OpenPitParamAccountId account,
OpenPitParamAccountGroupId * out_group
);
openpit_engine_set_account_currency
Sets the explicit currency of account.
Setting or changing the account currency does not validate existing holdings and does not recompute stored average entry price or realized PnL. The caller owns the risk of changing currency on live state; a control or recompute API may be added later.
Contract:
- passing null for
enginereturnsfalseand writesout_error; assetis parsed as an asset code and must be present;- on parse failure, if
out_erroris not null, writes a caller-ownedOpenPitSharedStringerror handle that MUST be released withopenpit_destroy_shared_string.
bool openpit_engine_set_account_currency(
OpenPitEngine * engine,
OpenPitParamAccountId account_id,
OpenPitStringView asset,
OpenPitOutError out_error
);
openpit_engine_clear_account_currency
Clears the explicit currency of account.
Clearing the account currency does not validate existing holdings and does not recompute stored average entry price or realized PnL. The caller owns the risk of changing currency on live state; a control or recompute API may be added later.
Contract:
enginemust be a valid non-null engine pointer.
void openpit_engine_clear_account_currency(
OpenPitEngine * engine,
OpenPitParamAccountId account_id
);
openpit_engine_set_account_group_currency
Sets the currency inherited by accounts in group.
OPENPIT_DEFAULT_ACCOUNT_GROUP (value 0) is allowed and represents the global default tier.
Setting or changing the group currency does not validate existing holdings and does not recompute stored average entry price or realized PnL. The caller owns the risk of changing currency on live state; a control or recompute API may be added later.
Contract:
- passing null for
enginereturnsfalseand writesout_error; groupmust beOPENPIT_DEFAULT_ACCOUNT_GROUPor a valid non-reserved group id; an invalid (reserved) id returnsfalseand writesout_error;assetis parsed as an asset code and must be present;- on any failure, if
out_erroris not null, writes a caller-ownedOpenPitSharedStringerror handle that MUST be released withopenpit_destroy_shared_string.
bool openpit_engine_set_account_group_currency(
OpenPitEngine * engine,
OpenPitParamAccountGroupId group,
OpenPitStringView asset,
OpenPitOutError out_error
);
openpit_engine_clear_account_group_currency
Clears the currency inherited by accounts in group.
OPENPIT_DEFAULT_ACCOUNT_GROUP (value 0) is allowed and represents the global default tier.
Clearing the group currency does not validate existing holdings and does not recompute stored average entry price or realized PnL. The caller owns the risk of changing currency on live state; a control or recompute API may be added later.
Contract:
enginemust be a valid non-null engine pointer;groupmust beOPENPIT_DEFAULT_ACCOUNT_GROUPor a valid non-reserved group id; an invalid (reserved) id is silently ignored (no-op) because this function has no error-output channel; preferopenpit_engine_set_account_group_currencywhen error reporting is needed.
void openpit_engine_clear_account_group_currency(
OpenPitEngine * engine,
OpenPitParamAccountGroupId group
);
OpenPitAccountBlockError
Structured error returned by account block operations.
Ownership:
- created by
openpit_engine_replace_account_block_reason,openpit_engine_block_account_group,openpit_engine_unblock_account_group, andopenpit_engine_replace_account_group_block_reasonon failure; - owned by the caller;
- released with
openpit_destroy_account_block_error.
typedef struct OpenPitAccountBlockError OpenPitAccountBlockError;
OpenPitAccountBlockErrorKind
Discriminant for the variant carried by an OpenPitAccountBlockError.
typedef uint32_t OpenPitAccountBlockErrorKind;
/**
* The target group is the reserved default account group.
*/
#define OpenPitAccountBlockErrorKind_ReservedGroup \
((OpenPitAccountBlockErrorKind) 0)
/**
* The target account is not currently blocked.
*/
#define OpenPitAccountBlockErrorKind_AccountNotBlocked \
((OpenPitAccountBlockErrorKind) 1)
/**
* The target account group is not currently blocked.
*/
#define OpenPitAccountBlockErrorKind_GroupNotBlocked \
((OpenPitAccountBlockErrorKind) 2)
openpit_destroy_account_block_error
Releases a caller-owned account-block error.
Contract:
- call exactly once per pointer returned by a block function;
- passing null is allowed and has no effect.
void openpit_destroy_account_block_error(
OpenPitAccountBlockError * err
);
openpit_account_block_error_get_message
Returns the human-readable error message from an account-block error.
Contract:
errmust be a valid non-null pointer;- the returned view borrows from the error object and is valid while the error is alive;
- violating the pointer contract aborts the call.
OpenPitStringView openpit_account_block_error_get_message(
const OpenPitAccountBlockError * err
);
openpit_account_block_error_get_kind
Returns the variant kind of an account-block error.
Contract:
errmust be a valid non-null pointer;- this function never fails;
- violating the pointer contract aborts the call.
OpenPitAccountBlockErrorKind openpit_account_block_error_get_kind(
const OpenPitAccountBlockError * err
);
openpit_account_block_error_get_account
Returns the offending account identifier from an account-block error.
Contract:
errmust be a valid non-null pointer;out_accountmust be a valid non-null pointer;- returns
truewhen the error variant carries an account and writes it toout_account; - returns
falsewhen no account is present;out_accountis left untouched when the return value isfalse; - violating the pointer contract aborts the call.
bool openpit_account_block_error_get_account(
const OpenPitAccountBlockError * err,
OpenPitParamAccountId * out_account
);
openpit_account_block_error_get_group
Returns the offending account-group identifier from an account-block error.
Contract:
errmust be a valid non-null pointer;out_groupmust be a valid non-null pointer;- returns
truewhen the error variant carries a group and writes it toout_group; - returns
falsewhen no group is present;out_groupis left untouched when the return value isfalse; - violating the pointer contract aborts the call.
bool openpit_account_block_error_get_group(
const OpenPitAccountBlockError * err,
OpenPitParamAccountGroupId * out_group
);
OpenPitConfigureErrorKind
Discriminant for the variant carried by an OpenPitConfigureError.
typedef uint32_t OpenPitConfigureErrorKind;
/**
* No configurable policy carries the requested name.
*/
#define OpenPitConfigureErrorKind_Unknown ((OpenPitConfigureErrorKind) 0)
/**
* A policy is registered under the name, but its settings type differs from
* the one the called configure function targets.
*/
#define OpenPitConfigureErrorKind_TypeMismatch ((OpenPitConfigureErrorKind) 1)
/**
* The applied update was rejected by the policy's settings validation; the
* prior configuration still applies.
*/
#define OpenPitConfigureErrorKind_Validation ((OpenPitConfigureErrorKind) 2)
/**
* A configuration call re-entered configuration on the same thread.
*/
#define OpenPitConfigureErrorKind_NestedConfiguration \
((OpenPitConfigureErrorKind) 3)
OpenPitConfigureError
Structured error returned by runtime policy reconfiguration.
Ownership:
- created by the
openpit_engine_configure_*functions on failure; - owned by the caller;
- released with
openpit_destroy_configure_error.
typedef struct OpenPitConfigureError OpenPitConfigureError;
openpit_destroy_configure_error
Releases a caller-owned configure error.
Contract:
- call exactly once per pointer returned by an
openpit_engine_configure_*function; - passing null is allowed and has no effect.
void openpit_destroy_configure_error(
OpenPitConfigureError * err
);
openpit_configure_error_get_message
Returns the human-readable error message from a configure error.
Contract:
errmust be a valid non-null pointer;- the returned view borrows from the error object and is valid while the error is alive;
- violating the pointer contract aborts the call.
OpenPitStringView openpit_configure_error_get_message(
const OpenPitConfigureError * err
);
openpit_configure_error_get_kind
Returns the variant kind of a configure error.
Contract:
errmust be a valid non-null pointer;- this function never fails;
- violating the pointer contract aborts the call.
OpenPitConfigureErrorKind openpit_configure_error_get_kind(
const OpenPitConfigureError * err
);
openpit_engine_block_account
Blocks account with reason.
The first cause for an account wins: if the account is already blocked (by an admin call or a prior kill-switch), this call is a no-op and does not overwrite the stored reason. Use openpit_engine_replace_account_block_reason to change the stored reason.
Contract:
enginemust be a valid non-null engine pointer;reasonis interpreted as UTF-8; an empty string is used whenreason.ptris null ORreason.lenis zero; passing a nullptrwith a non-zerolenis caller misuse and is treated as empty (not read); an empty reason is explicitly allowed.
void openpit_engine_block_account(
OpenPitEngine * engine,
OpenPitParamAccountId account_id,
OpenPitStringView reason
);
openpit_engine_unblock_account
Unblocks account, clearing any block on it.
Idempotent: a no-op when account is not blocked. Both admin blocks and kill-switch blocks are cleared.
Contract:
enginemust be a valid non-null engine pointer.
void openpit_engine_unblock_account(
OpenPitEngine * engine,
OpenPitParamAccountId account_id
);
openpit_engine_replace_account_block_reason
Replaces the stored reason of an already-blocked account.
Unlike openpit_engine_block_account, which preserves the first cause, this overwrites the stored cause with reason, leaving the account blocked.
Contract:
enginemust be a valid non-null engine pointer;reasonis interpreted as UTF-8; an empty string is used whenreason.ptris null ORreason.lenis zero; passing a nullptrwith a non-zerolenis caller misuse and is treated as empty (not read); an empty reason is explicitly allowed;- on failure, if
out_erroris not null, writes a caller-ownedOpenPitAccountBlockErrorpointer that MUST be released withopenpit_destroy_account_block_error; - returns
falseand writesout_errorwhenengineis null.
Success:
- returns
true; the stored reason has been replaced.
Error:
- returns
falsewithOpenPitAccountBlockErrorKind_AccountNotBlockedwhenaccountis not currently blocked.
bool openpit_engine_replace_account_block_reason(
OpenPitEngine * engine,
OpenPitParamAccountId account_id,
OpenPitStringView reason,
OpenPitAccountBlockError ** out_error
);
openpit_engine_block_account_group
Blocks the account group group with reason.
The first cause for a group wins: re-blocking an already-blocked group is a no-op. Use openpit_engine_replace_account_group_block_reason to change the stored reason.
Contract:
enginemust be a valid non-null engine pointer;groupmust not beOPENPIT_DEFAULT_ACCOUNT_GROUP;reasonis interpreted as UTF-8; an empty string is used whenreason.ptris null ORreason.lenis zero; passing a nullptrwith a non-zerolenis caller misuse and is treated as empty (not read); an empty reason is explicitly allowed;- on failure, if
out_erroris not null, writes a caller-ownedOpenPitAccountBlockErrorpointer that MUST be released withopenpit_destroy_account_block_error; - returns
falseand writesout_errorwhenengineis null.
Success:
- returns
true; the group is now blocked.
Error:
- returns
falsewithOpenPitAccountBlockErrorKind_ReservedGroupwhengroupis the reserved default group.
bool openpit_engine_block_account_group(
OpenPitEngine * engine,
OpenPitParamAccountGroupId group,
OpenPitStringView reason,
OpenPitAccountBlockError ** out_error
);
openpit_engine_unblock_account_group
Unblocks the account group group, clearing the group block.
Idempotent: a no-op when group is not blocked. Accounts blocked individually remain blocked.
Contract:
enginemust be a valid non-null engine pointer;groupmust not beOPENPIT_DEFAULT_ACCOUNT_GROUP;- on failure, if
out_erroris not null, writes a caller-ownedOpenPitAccountBlockErrorpointer that MUST be released withopenpit_destroy_account_block_error; - returns
falseand writesout_errorwhenengineis null.
Success:
- returns
true; the group is now unblocked.
Error:
- returns
falsewithOpenPitAccountBlockErrorKind_ReservedGroupwhengroupis the reserved default group.
bool openpit_engine_unblock_account_group(
OpenPitEngine * engine,
OpenPitParamAccountGroupId group,
OpenPitAccountBlockError ** out_error
);
openpit_engine_replace_account_group_block_reason
Replaces the stored reason of an already-blocked account group.
Unlike openpit_engine_block_account_group, which preserves the first cause, this overwrites the stored cause with reason, leaving the group blocked.
Contract:
enginemust be a valid non-null engine pointer;groupmust not beOPENPIT_DEFAULT_ACCOUNT_GROUP;reasonis interpreted as UTF-8; an empty string is used whenreason.ptris null ORreason.lenis zero; passing a nullptrwith a non-zerolenis caller misuse and is treated as empty (not read); an empty reason is explicitly allowed;- on failure, if
out_erroris not null, writes a caller-ownedOpenPitAccountBlockErrorpointer that MUST be released withopenpit_destroy_account_block_error; - returns
falseand writesout_errorwhenengineis null.
Success:
- returns
true; the stored group-block reason has been replaced.
Error:
- returns
falsewithOpenPitAccountBlockErrorKind_ReservedGroupwhengroupis the reserved default group; - returns
falsewithOpenPitAccountBlockErrorKind_GroupNotBlockedwhengroupis not currently blocked.
bool openpit_engine_replace_account_group_block_reason(
OpenPitEngine * engine,
OpenPitParamAccountGroupId group,
OpenPitStringView reason,
OpenPitAccountBlockError ** out_error
);