pit

Engine

Back to index

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:

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:

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:

typedef struct OpenPitEngineBuildError OpenPitEngineBuildError;

openpit_create_engine_builder

Creates a new engine builder with the chosen synchronization policy.

Success:

Error:

Cleanup:

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:

void openpit_destroy_engine_builder(
    OpenPitEngineBuilder * builder
);

openpit_engine_builder_build

Finalizes a builder and creates an engine.

Success:

Error:

Ownership:

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:

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:

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:

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:

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:

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:

Error:

Cleanup:

Output ownership contract:

Order lifetime contract:

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:

Error:

Cleanup:

Output ownership contract:

Order lifetime contract:

OpenPitPretradeStatus openpit_engine_execute_pre_trade(
    OpenPitEngine * engine,
    const OpenPitOrder * order,
    OpenPitPretradePreTradeReservation ** out_reservation,
    OpenPitPretradeRejectList ** out_rejects,
    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:

Error:

Cleanup:

Output ownership contract:

Order lifetime contract:

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:

Error:

Cleanup:

Output ownership contract:

Order lifetime contract:

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:

Error:

Ownership:

Output ownership contract:

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:

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:

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:

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:

Lifetime contract:

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:

Lifetime contract:

OpenPitAccountAdjustmentOutcomeList *
openpit_pretrade_pre_trade_reservation_get_account_adjustments(
    const OpenPitPretradePreTradeReservation * reservation
);

openpit_destroy_pretrade_pre_trade_reservation

Releases a reservation pointer owned by the caller.

Contract:

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:

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:

Lifetime contract:

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:

Lifetime contract:

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:

Lifetime contract:

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:

Lifetime contract:

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:

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:

Error:

Lifetime contract:

bool openpit_engine_apply_execution_report(
    OpenPitEngine * engine,
    const OpenPitExecutionReport * report,
    OpenPitPretradeAccountBlockList ** out_blocks,
    OpenPitAccountAdjustmentOutcomeList ** out_adjustments,
    OpenPitOutError out_error
);

openpit_destroy_account_adjustment_batch_error

Releases a batch-error object returned by account-adjustment apply.

Contract:

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:

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:

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:

Error:

Result handling:

Lifetime contract:

OpenPitAccountAdjustmentApplyStatus openpit_engine_apply_account_adjustment(
    OpenPitEngine * engine,
    OpenPitParamAccountId account_id,
    const OpenPitAccountAdjustment * adjustments,
    size_t adjustments_len,
    OpenPitAccountAdjustmentBatchError ** out_reject,
    OpenPitAccountAdjustmentOutcomeList ** out_outcomes,
    OpenPitOutError out_error
);

OpenPitAccountGroupError

Structured error returned by account-group registry operations.

Ownership:

typedef struct OpenPitAccountGroupError OpenPitAccountGroupError;

openpit_destroy_account_group_error

Releases a caller-owned account-group error.

Contract:

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:

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:

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:

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:

Success:

Error:

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:

Success:

Error:

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:

Success:

Error:

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:

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:

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:

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:

void openpit_engine_clear_account_group_currency(
    OpenPitEngine * engine,
    OpenPitParamAccountGroupId group
);

OpenPitAccountBlockError

Structured error returned by account block operations.

Ownership:

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:

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:

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:

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:

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:

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)

OpenPitConfigureError

Structured error returned by runtime policy reconfiguration.

Ownership:

typedef struct OpenPitConfigureError OpenPitConfigureError;

openpit_destroy_configure_error

Releases a caller-owned configure error.

Contract:

void openpit_destroy_configure_error(
    OpenPitConfigureError * err
);

openpit_configure_error_get_message

Returns the human-readable error message from a configure error.

Contract:

OpenPitStringView openpit_configure_error_get_message(
    const OpenPitConfigureError * err
);

openpit_configure_error_get_kind

Returns the variant kind of a configure error.

Contract:

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:

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:

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:

Success:

Error:

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:

Success:

Error:

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:

Success:

Error:

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:

Success:

Error:

bool openpit_engine_replace_account_group_block_reason(
    OpenPitEngine * engine,
    OpenPitParamAccountGroupId group,
    OpenPitStringView reason,
    OpenPitAccountBlockError ** out_error
);