Exit All Positions¶
Use trader.exit_all_positions(at_market_price=True) to exit all open positions from the trading client.
This method checks open positions and places opposite-side exit orders for positions with non-zero netQuantity.
State-changing method
exit_all_positions() places exit orders. Use it only when you want to square off all open positions for the account.
Basic Usage¶
from nubra_python_sdk.start_sdk import InitNubraSdk, NubraEnv
from nubra_python_sdk.trading.trading_data import NubraTrader
# Use NubraEnv.PROD for live usage or NubraEnv.UAT for sandbox testing.
nubra = InitNubraSdk(NubraEnv.PROD, env_creds=True)
trader = NubraTrader(nubra)
response = trader.exit_all_positions(at_market_price=True)
print(response)
Behavior¶
When at_market_price=True, the SDK submits exit orders with:
| Field | Value |
|---|---|
side |
Opposite of the open position side |
orderQty |
Absolute value of the open netQuantity |
deliveryType |
Same delivery type as the open position |
priceType |
MARKET |
validityType |
IOC |
executionMode |
ENTRY |
If there are no open positions, the method returns [].
Response¶
The response contains the order confirmations returned by the V3 order flow.
orders=[
IntentOrderResponse(
intentOrderId=14620,
status="OPEN",
refId=73361,
orderQty=2,
deliveryType="IDAY",
priceType="MARKET",
validityType="IOC",
executionMode="ENTRY",
side="SELL",
)
]
The immediate response confirms that the exit orders were submitted. Use Get Order or Realtime Order Updates to confirm the final fill, cancellation, or rejection state.
Important Rules¶
exit_all_positions()is called onNubraTrader, notNubraPortfolio.- Only positions with non-zero
netQuantityandstatus="OPEN"are targeted. - Long positions are exited with
SELLorders. - Short positions are exited with
BUYorders. - Closed or zero-quantity positions are skipped.