pit

Policies

Back to index

OpenPitPostTradeContext

Opaque context passed to the apply_execution_report C policy callback.

Valid only for the duration of the callback. Cannot be constructed by caller code.

typedef struct OpenPitPostTradeContext OpenPitPostTradeContext;

OpenPitPretradePreTradePolicy

Opaque pointer for a pre-trade policy.

Contract:

typedef struct OpenPitPretradePreTradePolicy OpenPitPretradePreTradePolicy;

OpenPitPretradePreTradePolicyCheckPreTradeStartFn

Callback used by a custom pre-trade policy to validate one order before a deferred pre-trade request is created.

Contract:

typedef OpenPitPretradeRejectList *
(*OpenPitPretradePreTradePolicyCheckPreTradeStartFn)(
    const OpenPitPretradeContext * ctx,
    const OpenPitOrder * order,
    void * user_data
);

OpenPitPretradePreTradePolicyPerformPreTradeCheckFn

Callback used by a custom pre-trade policy to perform a main-stage check.

Contract:

Parameter ordering convention: read-only inputs first (ctx, order), then callback-scoped collectors in the order (mutations, out_result), then the trailing opaque user_data.

typedef OpenPitPretradeRejectList *
(*OpenPitPretradePreTradePolicyPerformPreTradeCheckFn)(
    const OpenPitPretradeContext * ctx,
    const OpenPitOrder * order,
    OpenPitMutations * mutations,
    OpenPitPretradePreTradeResult * out_result,
    void * user_data
);

OpenPitPretradePreTradePolicyApplyExecutionReportFn

Callback used by a custom pre-trade policy to observe an execution report.

Contract:

Parameter ordering convention: read-only context first (ctx), then read-only input (report), then the callback-scoped collector (out_adjustments), then the trailing opaque user_data.

typedef OpenPitPretradeAccountBlockList *
(*OpenPitPretradePreTradePolicyApplyExecutionReportFn)(
    const OpenPitPostTradeContext * ctx,
    const OpenPitExecutionReport * report,
    OpenPitPostTradeAdjustmentList * out_adjustments,
    void * user_data
);

OpenPitPretradePreTradePolicyApplyAccountAdjustmentFn

Callback used by a custom pre-trade policy to validate one account adjustment.

Contract:

Parameter ordering convention: read-only inputs first (ctx, account_id, adjustment), then callback-scoped collectors in the order (mutations, out_outcomes), then the trailing opaque user_data.

typedef OpenPitPretradeRejectList *
(*OpenPitPretradePreTradePolicyApplyAccountAdjustmentFn)(
    const OpenPitAccountAdjustmentContext * ctx,
    OpenPitParamAccountId account_id,
    const OpenPitAccountAdjustment * adjustment,
    OpenPitMutations * mutations,
    OpenPitAccountOutcomeEntryList * out_outcomes,
    void * user_data
);

OpenPitPretradePreTradePolicyFreeUserDataFn

Callback invoked when the last reference to a custom pre-trade policy is released and the policy object is about to be destroyed.

Contract:

typedef void (*OpenPitPretradePreTradePolicyFreeUserDataFn)(
    void * user_data
);

openpit_create_pretrade_custom_pre_trade_policy

Creates a custom pre-trade policy from caller-provided callbacks.

Contract:

Success:

Error:

Lifetime contract:

OpenPitPretradePreTradePolicy * openpit_create_pretrade_custom_pre_trade_policy(
    OpenPitStringView name,
    uint16_t policy_group_id,
    OpenPitPretradePreTradePolicyCheckPreTradeStartFn check_pre_trade_start_fn,
    OpenPitPretradePreTradePolicyPerformPreTradeCheckFn perform_pre_trade_check_fn,
    OpenPitPretradePreTradePolicyApplyExecutionReportFn apply_execution_report_fn,
    OpenPitPretradePreTradePolicyApplyAccountAdjustmentFn apply_account_adjustment_fn,
    OpenPitPretradePreTradePolicyFreeUserDataFn free_user_data_fn,
    void * user_data,
    OpenPitOutError out_error
);

openpit_create_pretrade_custom_pre_trade_policy_with_dry_run

Creates a custom pre-trade policy with explicit dry-run hooks.

This is an additive companion to openpit_create_pretrade_custom_pre_trade_policy: it takes the same callbacks plus a dry-run variant for each pre-trade stage, placed right after its normal counterpart. The dry-run callbacks reuse the SAME function-pointer types as their normal counterparts - check_pre_trade_start_dry_run_fn has the same shape as check_pre_trade_start_fn, and perform_pre_trade_check_dry_run_fn the same shape as perform_pre_trade_check_fn.

Contract:

A dry-run reports the verdict, lock, and account adjustments the order would produce without moving engine state. A policy whose normal hooks mutate immediately (for example, a rate limiter that spends budget) MUST install read-only dry-run hooks here so a dry-run leaves engine state untouched.

Success:

Error:

Lifetime contract:

OpenPitPretradePreTradePolicy *
openpit_create_pretrade_custom_pre_trade_policy_with_dry_run(
    OpenPitStringView name,
    uint16_t policy_group_id,
    OpenPitPretradePreTradePolicyCheckPreTradeStartFn check_pre_trade_start_fn,
    OpenPitPretradePreTradePolicyCheckPreTradeStartFn check_pre_trade_start_dry_run_fn,
    OpenPitPretradePreTradePolicyPerformPreTradeCheckFn perform_pre_trade_check_fn,
    OpenPitPretradePreTradePolicyPerformPreTradeCheckFn perform_pre_trade_check_dry_run_fn,
    OpenPitPretradePreTradePolicyApplyExecutionReportFn apply_execution_report_fn,
    OpenPitPretradePreTradePolicyApplyAccountAdjustmentFn apply_account_adjustment_fn,
    OpenPitPretradePreTradePolicyFreeUserDataFn free_user_data_fn,
    void * user_data,
    OpenPitOutError out_error
);

OpenPitPretradeContext

Opaque context passed to main-stage C policy callbacks.

Valid only for the duration of the callback. Cannot be constructed by caller code.

Future extension: this type is the designated seam for engine storage-cell access. A read accessor will be added here when the engine store is introduced.

typedef struct OpenPitPretradeContext OpenPitPretradeContext;

OpenPitAccountAdjustmentContext

Opaque context passed to account-adjustment C policy callbacks.

Valid only for the duration of the callback. Cannot be constructed by caller code.

Future extension: this type is the designated seam for engine storage-cell access. A read accessor will be added here when the engine store is introduced.

typedef struct OpenPitAccountAdjustmentContext OpenPitAccountAdjustmentContext;

OpenPitMutations

Opaque, non-owning pointer to the mutation collector.

Valid only during the policy callback that received it. The caller must not store or use this pointer after the callback returns.

typedef struct OpenPitMutations OpenPitMutations;

OpenPitMutationFn

Callback invoked for either commit or rollback of a registered mutation.

typedef void (*OpenPitMutationFn)(
    void * user_data
);

OpenPitMutationFreeFn

Optional callback to release mutation user_data after execution.

Called exactly once per openpit_mutations_push:

typedef void (*OpenPitMutationFreeFn)(
    void * user_data
);

openpit_destroy_pretrade_pre_trade_policy

Destroys the caller-owned pointer for a pre-trade policy.

Lifetime contract:

void openpit_destroy_pretrade_pre_trade_policy(
    OpenPitPretradePreTradePolicy * policy
);

openpit_pretrade_pre_trade_policy_get_name

Returns the stable policy name for a pre-trade policy pointer.

Contract:

OpenPitStringView openpit_pretrade_pre_trade_policy_get_name(
    const OpenPitPretradePreTradePolicy * policy
);

openpit_engine_builder_add_pre_trade_policy

Adds a pre-trade policy to the engine builder.

Contract:

Success:

Error:

Lifetime contract:

bool openpit_engine_builder_add_pre_trade_policy(
    OpenPitEngineBuilder * builder,
    OpenPitPretradePreTradePolicy * policy,
    OpenPitOutError out_error
);

openpit_mutations_push

Registers one commit/rollback mutation in the provided collector.

Contract:

Error:

bool openpit_mutations_push(
    OpenPitMutations * mutations,
    OpenPitMutationFn commit_fn,
    OpenPitMutationFn rollback_fn,
    void * user_data,
    OpenPitMutationFreeFn free_fn,
    OpenPitOutError out_error
);

OpenPitPretradePoliciesOrderSizeLimit

Shared order-size limits for openpit_engine_builder_add_builtin_order_size_limit_policy.

typedef struct OpenPitPretradePoliciesOrderSizeLimit {
    OpenPitParamQuantity max_quantity;
    OpenPitParamVolume max_notional;
} OpenPitPretradePoliciesOrderSizeLimit;

OpenPitPretradePoliciesOrderSizeBrokerBarrier

Broker-wide order-size barrier for openpit_engine_builder_add_builtin_order_size_limit_policy.

typedef struct OpenPitPretradePoliciesOrderSizeBrokerBarrier {
    OpenPitPretradePoliciesOrderSizeLimit limit;
} OpenPitPretradePoliciesOrderSizeBrokerBarrier;

OpenPitPretradePoliciesOrderSizeAssetBarrier

Per-settlement-asset order-size barrier for openpit_engine_builder_add_builtin_order_size_limit_policy.

typedef struct OpenPitPretradePoliciesOrderSizeAssetBarrier {
    OpenPitPretradePoliciesOrderSizeLimit limit;
    OpenPitStringView settlement_asset;
} OpenPitPretradePoliciesOrderSizeAssetBarrier;

OpenPitPretradePoliciesOrderSizeAccountAssetBarrier

Per-(account, settlement-asset) order-size barrier for openpit_engine_builder_add_builtin_order_size_limit_policy.

typedef struct OpenPitPretradePoliciesOrderSizeAccountAssetBarrier {
    OpenPitPretradePoliciesOrderSizeLimit limit;
    OpenPitParamAccountId account_id;
    OpenPitStringView settlement_asset;
} OpenPitPretradePoliciesOrderSizeAccountAssetBarrier;

openpit_engine_builder_add_builtin_order_size_limit_policy

Adds the built-in order-size limit policy to the engine builder.

Contract:

Success:

Error:

bool openpit_engine_builder_add_builtin_order_size_limit_policy(
    OpenPitEngineBuilder * builder,
    uint16_t policy_group_id,
    const OpenPitPretradePoliciesOrderSizeBrokerBarrier * broker,
    const OpenPitPretradePoliciesOrderSizeAssetBarrier * asset,
    size_t asset_len,
    const OpenPitPretradePoliciesOrderSizeAccountAssetBarrier * account_asset,
    size_t account_asset_len,
    OpenPitOutError out_error
);

openpit_engine_configure_order_size_limit

Retunes the built-in order-size limit policy registered under name.

This is a partial update (PATCH) at the axis level: each axis is replaced wholesale only when its has_* flag is true, mirroring the replace-shaped settings setters.

Contract:

Success:

Error:

bool openpit_engine_configure_order_size_limit(
    OpenPitEngine * engine,
    OpenPitStringView name,
    const OpenPitPretradePoliciesOrderSizeBrokerBarrier * broker,
    bool has_broker,
    const OpenPitPretradePoliciesOrderSizeAssetBarrier * asset,
    size_t asset_len,
    bool has_asset,
    const OpenPitPretradePoliciesOrderSizeAccountAssetBarrier * account_asset,
    size_t account_asset_len,
    bool has_account_asset,
    OpenPitConfigureError ** out_error
);

openpit_engine_builder_add_builtin_order_validation_policy

Adds the built-in order-validation policy to the engine builder.

Contract:

Success:

Error:

bool openpit_engine_builder_add_builtin_order_validation_policy(
    OpenPitEngineBuilder * builder,
    uint16_t policy_group_id,
    OpenPitOutError out_error
);

OpenPitPretradePoliciesPnlBoundsBarrier

One broker barrier definition for openpit_engine_builder_add_builtin_pnl_bounds_killswitch_policy.

What it describes:

Contract:

typedef struct OpenPitPretradePoliciesPnlBoundsBarrier {
    OpenPitStringView settlement_asset;
    OpenPitParamPnlOptional lower_bound;
    OpenPitParamPnlOptional upper_bound;
} OpenPitPretradePoliciesPnlBoundsBarrier;

OpenPitPretradePoliciesPnlBoundsAccountBarrier

Per-(account, settlement-asset) P&L bounds barrier with an initial P&L seed.

What it describes:

Passed to openpit_engine_builder_add_builtin_pnl_bounds_killswitch_policy in the account array.

typedef struct OpenPitPretradePoliciesPnlBoundsAccountBarrier {
    OpenPitParamAccountId account_id;
    OpenPitStringView settlement_asset;
    OpenPitParamPnlOptional lower_bound;
    OpenPitParamPnlOptional upper_bound;
    OpenPitParamPnl initial_pnl;
} OpenPitPretradePoliciesPnlBoundsAccountBarrier;

OpenPitPretradePoliciesPnlBoundsAccountBarrierUpdate

Runtime replacement for a per-(account, settlement-asset) P&L barrier.

Passed to openpit_engine_configure_pnl_bounds_killswitch. It intentionally has no initial_pnl: runtime replacement preserves and evaluates the live accumulated P&L.

typedef struct OpenPitPretradePoliciesPnlBoundsAccountBarrierUpdate {
    OpenPitParamAccountId account_id;
    OpenPitStringView settlement_asset;
    OpenPitParamPnlOptional lower_bound;
    OpenPitParamPnlOptional upper_bound;
} OpenPitPretradePoliciesPnlBoundsAccountBarrierUpdate;

openpit_engine_builder_add_builtin_pnl_bounds_killswitch_policy

Adds the built-in P&L bounds kill-switch policy to the engine builder.

Contract:

Success:

Error:

bool openpit_engine_builder_add_builtin_pnl_bounds_killswitch_policy(
    OpenPitEngineBuilder * builder,
    uint16_t policy_group_id,
    const OpenPitPretradePoliciesPnlBoundsBarrier * broker,
    size_t broker_len,
    const OpenPitPretradePoliciesPnlBoundsAccountBarrier * account,
    size_t account_len,
    OpenPitOutError out_error
);

openpit_engine_configure_pnl_bounds_killswitch

Retunes the built-in P&L bounds kill-switch policy registered under name.

This is a partial update (PATCH) at the axis level: each axis is replaced wholesale only when its has_* flag is true, mirroring the replace-shaped settings setters. Runtime account barriers use a dedicated update DTO with no initial_pnl; accumulated P&L is preserved.

Contract:

Success:

Error:

bool openpit_engine_configure_pnl_bounds_killswitch(
    OpenPitEngine * engine,
    OpenPitStringView name,
    const OpenPitPretradePoliciesPnlBoundsBarrier * broker,
    size_t broker_len,
    bool has_broker,
    const OpenPitPretradePoliciesPnlBoundsAccountBarrierUpdate * account,
    size_t account_len,
    bool has_account,
    OpenPitConfigureError ** out_error
);

openpit_engine_configure_pnl_bounds_killswitch_set_account_pnl

Force-sets the live accumulated P&L for a (account_id, settlement_asset) entry of the P&L bounds kill-switch policy registered under name.

This is an absolute assignment, deliberately distinct from openpit_engine_configure_pnl_bounds_killswitch: that function retunes the bounds and never touches accumulated P&L, whereas this overwrites the live accumulator. The entry is created if it does not exist yet. The new value is evaluated against the live bounds from the next check onward.

Contract:

Success:

Error:

bool openpit_engine_configure_pnl_bounds_killswitch_set_account_pnl(
    OpenPitEngine * engine,
    OpenPitStringView name,
    OpenPitParamAccountId account_id,
    OpenPitStringView settlement_asset,
    OpenPitParamPnl pnl,
    OpenPitConfigureError ** out_error
);

OpenPitPretradePoliciesRateLimitBrokerBarrier

Broker-wide rate-limit barrier for openpit_engine_builder_add_builtin_rate_limit_policy.

typedef struct OpenPitPretradePoliciesRateLimitBrokerBarrier {
    size_t max_orders;
    int64_t window_nanoseconds;
} OpenPitPretradePoliciesRateLimitBrokerBarrier;

OpenPitPretradePoliciesRateLimitAssetBarrier

Per-settlement-asset rate-limit barrier for openpit_engine_builder_add_builtin_rate_limit_policy.

typedef struct OpenPitPretradePoliciesRateLimitAssetBarrier {
    OpenPitStringView settlement_asset;
    size_t max_orders;
    int64_t window_nanoseconds;
} OpenPitPretradePoliciesRateLimitAssetBarrier;

OpenPitPretradePoliciesRateLimitAccountBarrier

Per-account rate-limit barrier for openpit_engine_builder_add_builtin_rate_limit_policy.

typedef struct OpenPitPretradePoliciesRateLimitAccountBarrier {
    OpenPitParamAccountId account_id;
    size_t max_orders;
    int64_t window_nanoseconds;
} OpenPitPretradePoliciesRateLimitAccountBarrier;

OpenPitPretradePoliciesRateLimitAccountAssetBarrier

Per-(account, settlement-asset) rate-limit barrier for openpit_engine_builder_add_builtin_rate_limit_policy.

typedef struct OpenPitPretradePoliciesRateLimitAccountAssetBarrier {
    OpenPitParamAccountId account_id;
    OpenPitStringView settlement_asset;
    size_t max_orders;
    int64_t window_nanoseconds;
} OpenPitPretradePoliciesRateLimitAccountAssetBarrier;

openpit_engine_builder_add_builtin_rate_limit_policy

Adds the built-in rate-limit policy to the engine builder.

Contract:

Success:

Error:

bool openpit_engine_builder_add_builtin_rate_limit_policy(
    OpenPitEngineBuilder * builder,
    uint16_t policy_group_id,
    const OpenPitPretradePoliciesRateLimitBrokerBarrier * broker,
    const OpenPitPretradePoliciesRateLimitAssetBarrier * asset,
    size_t asset_len,
    const OpenPitPretradePoliciesRateLimitAccountBarrier * account,
    size_t account_len,
    const OpenPitPretradePoliciesRateLimitAccountAssetBarrier * account_asset,
    size_t account_asset_len,
    OpenPitOutError out_error
);

openpit_engine_configure_rate_limit

Retunes the built-in rate-limit policy registered under name.

This is a partial update (PATCH): each axis is touched only when its has_* flag is true. A touched axis is replaced wholesale — barriers can be added and removed at runtime. A barrier key that survives the replacement keeps its live counter (no reset). An empty axis (len 0 with has_* true) clears it, subject to the policy’s at-least-one- barrier rule. Setting has_broker to true with a null broker pointer clears the broker barrier.

Contract:

Success:

Error:

bool openpit_engine_configure_rate_limit(
    OpenPitEngine * engine,
    OpenPitStringView name,
    const OpenPitPretradePoliciesRateLimitBrokerBarrier * broker,
    bool has_broker,
    const OpenPitPretradePoliciesRateLimitAssetBarrier * asset,
    size_t asset_len,
    bool has_asset,
    const OpenPitPretradePoliciesRateLimitAccountBarrier * account,
    size_t account_len,
    bool has_account,
    const OpenPitPretradePoliciesRateLimitAccountAssetBarrier * account_asset,
    size_t account_asset_len,
    bool has_account_asset,
    OpenPitConfigureError ** out_error
);

OpenPitPretradePoliciesSpotFundsLimitMode

Selects how the spot-funds control reacts to insufficient available funds.

The default is Enforce, matching the core [SpotFundsLimitMode] default.

typedef uint8_t OpenPitPretradePoliciesSpotFundsLimitMode;
/**
 * Reject a reservation when available funds are insufficient; the reservation
 * is not recorded.
 */
#define OpenPitPretradePoliciesSpotFundsLimitMode_Enforce \
    ((OpenPitPretradePoliciesSpotFundsLimitMode) 0)
/**
 * Always record the reservation; `available` may go negative and a shortfall
 * never rejects. Arithmetic overflow is still surfaced.
 */
#define OpenPitPretradePoliciesSpotFundsLimitMode_TrackOnly \
    ((OpenPitPretradePoliciesSpotFundsLimitMode) 1)

OpenPitPretradePoliciesSpotFundsOverrideTargetTag

Tagged target variants for a spot-funds slippage override.

Spot funds overrides use an explicit tagged hierarchy matching the Rust SpotFundsOverrideTarget variants: Instrument, InstrumentAccount, and InstrumentAccountGroup.

typedef uint8_t OpenPitPretradePoliciesSpotFundsOverrideTargetTag;
/**
 * Instrument-level override.
 */
#define OpenPitPretradePoliciesSpotFundsOverrideTargetTag_Instrument \
    ((OpenPitPretradePoliciesSpotFundsOverrideTargetTag) 0)
/**
 * Override for one instrument and account.
 */
#define OpenPitPretradePoliciesSpotFundsOverrideTargetTag_InstrumentAccount \
    ((OpenPitPretradePoliciesSpotFundsOverrideTargetTag) 1)
/**
 * Override for one instrument and account group.
 */
#define OpenPitPretradePoliciesSpotFundsOverrideTargetTag_InstrumentAccountGroup \
    ((OpenPitPretradePoliciesSpotFundsOverrideTargetTag) 2)

OpenPitPretradePoliciesSpotFundsOverrideTargetInstrument

Payload for an instrument-level spot-funds override target.

typedef struct OpenPitPretradePoliciesSpotFundsOverrideTargetInstrument {
    OpenPitMarketDataInstrumentId instrument_id;
} OpenPitPretradePoliciesSpotFundsOverrideTargetInstrument;

OpenPitPretradePoliciesSpotFundsOverrideTargetInstrumentAccount

Payload for an instrument-and-account spot-funds override target.

typedef struct OpenPitPretradePoliciesSpotFundsOverrideTargetInstrumentAccount {
    OpenPitMarketDataInstrumentId instrument_id;
    OpenPitParamAccountId account_id;
} OpenPitPretradePoliciesSpotFundsOverrideTargetInstrumentAccount;

OpenPitPretradePoliciesSpotFundsOverrideTargetInstrumentAccountGroup

Payload for an instrument-and-account-group spot-funds override target.

typedef struct
    OpenPitPretradePoliciesSpotFundsOverrideTargetInstrumentAccountGroup {
    OpenPitMarketDataInstrumentId instrument_id;
    OpenPitParamAccountGroupId account_group_id;
} OpenPitPretradePoliciesSpotFundsOverrideTargetInstrumentAccountGroup;

OpenPitPretradePoliciesSpotFundsOverrideTargetPayload

Variant payload for a tagged spot-funds override target.

typedef union OpenPitPretradePoliciesSpotFundsOverrideTargetPayload {
    OpenPitPretradePoliciesSpotFundsOverrideTargetInstrument instrument;
    OpenPitPretradePoliciesSpotFundsOverrideTargetInstrumentAccount
        instrument_account;
    OpenPitPretradePoliciesSpotFundsOverrideTargetInstrumentAccountGroup
        instrument_account_group;
} OpenPitPretradePoliciesSpotFundsOverrideTargetPayload;

OpenPitPretradePoliciesSpotFundsOverrideTarget

Explicit tagged target for a spot-funds slippage override.

The tag selects exactly one union payload. Unknown tags are rejected through the function’s existing error channel before the payload is read.

typedef struct OpenPitPretradePoliciesSpotFundsOverrideTarget {
    uint8_t tag;
    OpenPitPretradePoliciesSpotFundsOverrideTargetPayload payload;
} OpenPitPretradePoliciesSpotFundsOverrideTarget;

OpenPitPretradePoliciesSpotFundsOverride

Slippage override entry for the spot funds policy.

target mirrors the three variants of SpotFundsOverrideTarget. When has_slippage_bps is true, slippage_bps is used for the selected target. When it is false, construction ignores the entry and runtime configuration clears the selected override. Slippage resolves account -> account group -> instrument -> global for each order.

typedef struct OpenPitPretradePoliciesSpotFundsOverride {
    OpenPitPretradePoliciesSpotFundsOverrideTarget target;
    uint16_t slippage_bps;
    bool has_slippage_bps;
} OpenPitPretradePoliciesSpotFundsOverride;

OpenPitPretradePoliciesSpotFundsPnlBoundsBarrier

Spot-funds account-currency P&L bounds.

typedef struct OpenPitPretradePoliciesSpotFundsPnlBoundsBarrier {
    OpenPitStringView account_currency;
    OpenPitParamPnlOptional lower_bound;
    OpenPitParamPnlOptional upper_bound;
} OpenPitPretradePoliciesSpotFundsPnlBoundsBarrier;

OpenPitPretradePoliciesSpotFundsPnlBoundsAccountGroupBarrier

Account-group spot-funds P&L bounds refinement.

typedef struct OpenPitPretradePoliciesSpotFundsPnlBoundsAccountGroupBarrier {
    OpenPitParamAccountGroupId account_group_id;
    OpenPitPretradePoliciesSpotFundsPnlBoundsBarrier barrier;
} OpenPitPretradePoliciesSpotFundsPnlBoundsAccountGroupBarrier;

OpenPitPretradePoliciesSpotFundsPnlBoundsAccountBarrier

Account spot-funds P&L bounds refinement with construction-time seed.

typedef struct OpenPitPretradePoliciesSpotFundsPnlBoundsAccountBarrier {
    OpenPitParamAccountId account_id;
    OpenPitPretradePoliciesSpotFundsPnlBoundsBarrier barrier;
    OpenPitParamPnl initial_pnl;
} OpenPitPretradePoliciesSpotFundsPnlBoundsAccountBarrier;

OpenPitPretradePoliciesSpotFundsPnlBoundsAccountBarrierUpdate

Runtime account spot-funds P&L bounds replacement.

typedef struct OpenPitPretradePoliciesSpotFundsPnlBoundsAccountBarrierUpdate {
    OpenPitParamAccountId account_id;
    OpenPitPretradePoliciesSpotFundsPnlBoundsBarrier barrier;
} OpenPitPretradePoliciesSpotFundsPnlBoundsAccountBarrierUpdate;

openpit_engine_builder_add_builtin_spot_funds_policy

Adds the built-in spot funds policy to the engine builder.

Contract:

Mismatch guard: when market_data is non-null and the engine is multi-threaded (Full or Account sync mode) but the market-data service was built in no-sync (None, no-op locks) mode, this call fails with a descriptive error. A no-sync engine accepts both no-sync and full-sync MD services.

Success: returns true; the builder retains the policy.

Error: returns false. If out_error is non-null, writes a caller-owned OpenPitSharedString error handle (release with openpit_destroy_shared_string).

bool openpit_engine_builder_add_builtin_spot_funds_policy(
    OpenPitEngineBuilder * builder,
    const OpenPitMarketDataService * market_data,
    const uint16_t * market_slippage_bps,
    uint8_t pricing_source,
    const OpenPitPretradePoliciesSpotFundsOverride * instrument_overrides,
    size_t overrides_len,
    uint16_t policy_group_id,
    OpenPitOutError out_error
);

openpit_engine_builder_add_builtin_spot_funds_pnl_bounds_killswitch_policy

Adds the built-in spot-funds policy with account-currency P&L bounds.

This entry point builds the regular SpotFundsPolicy and configures only its P&L-bounds axis. The policy keeps its stable built-in name "SpotFundsPolicy"; no separate policy namespace is created. It seeds the funds-limit axis as TrackOnly and market pricing as Mark / 0 bps / no overrides; tune those regular spot-funds knobs after build with openpit_engine_configure_spot_funds.

Contract:

Success / error: mirrors openpit_engine_builder_add_builtin_spot_funds_policy.

bool openpit_engine_builder_add_builtin_spot_funds_pnl_bounds_killswitch_policy(
    OpenPitEngineBuilder * builder,
    const OpenPitMarketDataService * market_data,
    uint16_t policy_group_id,
    const OpenPitPretradePoliciesSpotFundsPnlBoundsBarrier * global,
    size_t global_len,
    const OpenPitPretradePoliciesSpotFundsPnlBoundsAccountGroupBarrier * account_group,
    size_t account_group_len,
    const OpenPitPretradePoliciesSpotFundsPnlBoundsAccountBarrier * account,
    size_t account_len,
    OpenPitOutError out_error
);

openpit_engine_configure_spot_funds

Retunes the built-in spot-funds policy registered under name.

This is a partial update (PATCH): the global slippage, pricing source, and each supplied override are applied only when their corresponding has_* flag is true. The market-data service handle is fixed at build time and cannot be changed here; this function only tunes the slippage / pricing cascade that lives in the settings cell.

Contract:

Success:

Error:

bool openpit_engine_configure_spot_funds(
    OpenPitEngine * engine,
    OpenPitStringView name,
    uint16_t global_slippage_bps,
    bool has_global_slippage_bps,
    uint8_t pricing_source,
    bool has_pricing_source,
    const OpenPitPretradePoliciesSpotFundsOverride * instrument_overrides,
    size_t overrides_len,
    bool has_overrides,
    OpenPitConfigureError ** out_error
);

openpit_engine_configure_spot_funds_pnl_bounds_killswitch

Retunes the P&L-bounds axis of the built-in spot-funds policy registered under name.

This is a partial update (PATCH): each supplied axis is replaced only when its has_* flag is true. Account barriers use the runtime update DTO with no initial_pnl; live accumulated P&L is preserved.

bool openpit_engine_configure_spot_funds_pnl_bounds_killswitch(
    OpenPitEngine * engine,
    OpenPitStringView name,
    const OpenPitPretradePoliciesSpotFundsPnlBoundsBarrier * global,
    size_t global_len,
    bool has_global,
    const OpenPitPretradePoliciesSpotFundsPnlBoundsAccountGroupBarrier * account_group,
    size_t account_group_len,
    bool has_account_group,
    const OpenPitPretradePoliciesSpotFundsPnlBoundsAccountBarrierUpdate * account,
    size_t account_len,
    bool has_account,
    OpenPitConfigureError ** out_error
);

openpit_engine_configure_spot_funds_set_account_pnl

Force-sets the live accumulated account-currency P&L for the spot-funds policy registered under name.

This is an absolute assignment and is separate from barrier retuning, which never resets the accumulator.

bool openpit_engine_configure_spot_funds_set_account_pnl(
    OpenPitEngine * engine,
    OpenPitStringView name,
    OpenPitParamAccountId account_id,
    OpenPitStringView account_currency,
    OpenPitParamPnl pnl,
    OpenPitConfigureError ** out_error
);

openpit_engine_configure_spot_funds_global_limit_mode

Sets the global spot-funds limit mode for the policy registered under name.

The global mode applies to every order that resolves to neither a per-account nor a per-account-group override.

Contract:

Success:

Error:

bool openpit_engine_configure_spot_funds_global_limit_mode(
    OpenPitEngine * engine,
    OpenPitStringView name,
    uint8_t mode,
    OpenPitConfigureError ** out_error
);

openpit_engine_configure_spot_funds_account_limit_mode

Pins or clears the spot-funds limit mode for one account on the policy registered under name.

The per-account override wins over the account-group and global tiers.

Contract:

Success / error: as openpit_engine_configure_spot_funds_global_limit_mode.

bool openpit_engine_configure_spot_funds_account_limit_mode(
    OpenPitEngine * engine,
    OpenPitStringView name,
    OpenPitParamAccountId account_id,
    uint8_t mode,
    bool has_mode,
    OpenPitConfigureError ** out_error
);

openpit_engine_configure_spot_funds_account_group_limit_mode

Pins or clears the spot-funds limit mode for one account group on the policy registered under name.

The override applies to every account in the group that has no per-account override.

Contract:

Success / error: as openpit_engine_configure_spot_funds_global_limit_mode.

bool openpit_engine_configure_spot_funds_account_group_limit_mode(
    OpenPitEngine * engine,
    OpenPitStringView name,
    OpenPitParamAccountGroupId account_group_id,
    uint8_t mode,
    bool has_mode,
    OpenPitConfigureError ** out_error
);