# Pre-Submission Margin Checks

## Overview

City API supports SPAN margin checks as one of its several levels of risk checks available. If enabled, City API will calculate a worst-case margin scenario that includes the the current account position, open orders and the new order in question. If the margin exceeds the current net liquidating value of the account, the order will be rejected.

This feature can be enabled on the account risk limits page as shown here:

## Buying Power Margin %

Additionally, a 'buying power margin %' can be applied to this calculation, which is also shown in the screenshot above. This percent is applied to the net liq. of the account when comparing the worst-case margin. For example, assuming an account has a net liq. of $10,000.00, and the 'buying power margin %' is set to 150, the account will allow a worst case margin of $15,000.00. This value can be set above or below 100.

## Accounting for Open Orders

City API needs to consider the highest possible margin requirement that could result at any instant to perform this check. That is, it assumes that any combination of open orders could conceivably trade at any instant. This calculation can become costly to compute, however if an account has many open orders (the number of calculations is exponential with the number of orders).

Therefore, City API does not calculate the exact worst-case, but instead calculates an upper bound that is much cheaper to calculate (we always err on the side of requiring more, not less margin). Specifically, we make a modification to the calculation to address open orders: we do not apply any credits from risk arrays. That is, we assume the parts that add margin could be applicable, but not the parts that reduce margin.