Skip to content

Credit and Withdrawal Policy

Credit is broker-provided trading collateral. It is stored separately from the client's balance and participates in equity, free margin, Margin Call, and Stop Out calculations. Credit is not client-owned money and cannot be withdrawn.

equity = balance + credit + floating profit + commission + storage

Trading results always settle to balance. They never consume or convert credit directly. Credit changes only through explicit finance transactions:

Command Value Effect
OP_CREDIT_IN 7 Grants credit; amount must be positive
OP_CREDIT_OUT 9 Revokes credit; amount must be negative

The resulting credit cannot be negative. A credit revocation is rejected when its absolute amount exceeds current credit.

Credit revocation checks

Before applying OP_CREDIT_OUT, the server calculates a projected margin snapshot. Revocation is rejected when:

  • projected credit would be negative;
  • projected equity would be negative;
  • an account with open exposure would have non-positive equity;
  • projected free margin would be below withdrawal_margin_reserve;
  • an account with open exposure would enter Margin Call or Stop Out.

It is valid for balance to be negative while credit keeps total equity positive. However, credit cannot be fully revoked while that would leave the account with negative equity.

Withdrawal policy

Each account inherits the following settings from its group:

Field Type Default Description
credit_withdrawal_policy int 0 Determines whether credit may support remaining positions after a balance withdrawal
withdrawal_margin_reserve double 0.0 Minimum projected free margin, in account currency, required after withdrawal or credit revocation

Policy 0: CREDIT_WITHDRAWAL_IGNORE_CREDIT

Credit does not increase the withdrawable amount. The server uses client-owned equity:

floating_result = profit + commission + storage
own_equity = balance + min(0, floating_result)
withdrawable = max(0, own_equity - margin - withdrawal_margin_reserve)

Positive floating profit is not withdrawable before settlement. Floating losses reduce the available amount immediately.

Policy 1: CREDIT_WITHDRAWAL_ALLOW_CREDIT_AS_MARGIN

Credit may support positions remaining after withdrawal, but credit itself is still not withdrawable. The requested amount cannot exceed positive account balance. The projected account must remain above the configured reserve and outside Margin Call and Stop Out.

Runtime processing

Finance handlers return an accepted request after it is queued. The trading runtime performs the authoritative projected-state check immediately before applying the transaction. A policy failure leaves balance and credit unchanged and moves a new finance operation to TS_FINANCE_OPEN_DECLINE (18).

Synchronous commands wait for the corresponding trade:event. Integrations must also handle SYNC_TIMEOUT because the operation is processed asynchronously.

Persistence and reconciliation

Executed credit transactions store their signed amount in profit. BalanceFix reconstructs credit from completed OP_CREDIT_IN and OP_CREDIT_OUT transactions, so credit remains consistent after restart and reconciliation.

The group-level credit field is separate from account credit. It does not directly change an account and must not be treated as the current credit balance.