strat teardown¶
Safely close all positions for a strategy.
The teardown system unwinds positions in a safe order and converts holdings back to stable tokens. Strategies must implement the three teardown methods (supports_teardown, get_open_positions, generate_teardown_intents) for this command to work.
Usage¶
Prerequisites¶
- A running gateway (auto-started by default, or use an existing one)
- Environment variables:
ALMANAK_PRIVATE_KEY - The strategy must implement teardown methods (see Implementing Teardown)
Options¶
-
working_dir:- Type:
Path - Default:
. - Usage:
--working-dir,-dWorking directory containing the strategy files.
- Type:
-
config_file:- Type:
Path - Default:
None - Usage:
--config,-cPath to strategy config JSON file.
- Type:
-
mode:- Type: Choice
- Choices:
graceful,emergency - Default:
graceful - Usage:
--mode,-mTeardown mode.gracefuluses normal slippage tolerance;emergencyaccepts higher slippage (3%) for faster exit.
-
preview:- Type: BOOL
- Default:
False - Usage:
--previewPreview what positions will be closed without executing.
-
force:- Type: BOOL
- Default:
False - Usage:
--force,-fSkip the confirmation prompt.
-
gateway_host:- Type: STRING
- Default:
localhost - Env:
GATEWAY_HOST - Usage:
--gateway-hostGateway sidecar hostname.
-
gateway_port:- Type: INT
- Default:
50051 - Env:
GATEWAY_PORT - Usage:
--gateway-portGateway sidecar gRPC port.
Examples¶
# Preview what will be closed (no transactions)
almanak strat teardown execute --preview
# Graceful teardown from strategy directory
cd strategies/demo/uniswap_rsi
almanak strat teardown execute
# Graceful teardown with explicit path
almanak strat teardown execute -d strategies/demo/aerodrome_lp
# Emergency teardown (higher slippage, faster exit)
almanak strat teardown execute -d strategies/demo/aave_borrow --mode emergency
# Skip confirmation prompt
almanak strat teardown execute -d strategies/demo/uniswap_lp --force
How It Works¶
- Loads the strategy from its working directory
- Calls
get_open_positions()to discover what needs closing - Displays a preview of positions and estimated values
- Calls
generate_teardown_intents(mode)to build the unwind plan - Compiles and executes each intent through the normal execution pipeline
Position Closing Order¶
When a strategy holds multiple position types, teardown follows a strict order to avoid liquidation during unwind:
- Perps -- close perpetual positions first (highest risk)
- Borrows -- repay borrows to free collateral
- Supplies -- withdraw supplied collateral
- LPs -- close liquidity positions
- Tokens -- swap remaining tokens to stable
CLI Help¶
Usage: almanak strat teardown execute [OPTIONS]
Execute teardown directly from a strategy working directory.
This command loads a strategy from its working directory and immediately
executes a teardown to close all open positions. The gateway must be running.
Examples:
# Preview what will be closed
almanak strat teardown execute -d strategies/demo/aerodrome_lp --preview
# Execute graceful teardown
almanak strat teardown execute -d strategies/demo/aerodrome_lp
# Emergency teardown (faster, accepts higher slippage)
almanak strat teardown execute -d strategies/demo/aave_borrow --mode emergency
# Skip confirmation
almanak strat teardown execute -d strategies/demo/uniswap_lp --force
Options:
-d, --working-dir PATH Working directory containing the strategy files.
-c, --config PATH Path to strategy config JSON file.
-m, --mode [graceful|emergency] Teardown mode (default: graceful).
--preview Preview teardown without executing.
-f, --force Skip confirmation prompt.
--gateway-host TEXT Gateway sidecar hostname.
--gateway-port INTEGER Gateway sidecar gRPC port.
--help Show this message and exit.