OpenParable
Skip to content
← Back to skills

Kraken Liquidation Guard

Apps & Automation
kraken-liquidation-guard

Kraken Liquidation Guard is an Agent Skill for apps & automation published in the krakenfx/kraken-cli repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.

Prevent futures liquidation through margin monitoring and emergency procedures.

View on GitHub ↗
QUICK START

How to use this skill

Bring this guide into your coding agent with a prompt tailored to the tool you use.

  1. Open your project in Codex.
  2. Copy and paste the prompt below.
  3. Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/krakenfx/kraken-cli/blob/HEAD/skills/kraken-liquidation-guard/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/kraken-liquidation-guard, but wait for my approval before writing files or running scripts.

Copying this prompt does not install or run the skill. Review third-party files before use.

kraken-liquidation-guard

Use this skill for:

  • monitoring margin ratio to detect liquidation risk
  • automated position reduction when thresholds are breached
  • emergency flatten procedures
  • proactive margin top-up patterns

Margin Health Check

kraken futures accounts -o json 2>/dev/null

Key fields:

  • equity: total account value
  • initialMargin: margin held for positions
  • maintenanceMargin: minimum margin before liquidation
  • availableFunds: free margin for new positions

Margin ratio = maintenanceMargin / equity. Liquidation approaches as this ratio nears 1.0.

Alert Thresholds

RatioStatusAction
< 0.3HealthyNormal operation
0.3 - 0.5CautionReduce position or add margin
0.5 - 0.7WarningReduce position immediately
> 0.7CriticalEmergency flatten

Monitoring Loop

kraken futures ws balances -o json 2>/dev/null | while read -r line; do
  # Parse equity and maintenanceMargin
  # Calculate ratio
  # Alert or act when threshold is breached
done

Or poll periodically:

kraken futures accounts -o json 2>/dev/null

Unwind Queue Check

If a position enters the unwind queue, liquidation is imminent:

kraken futures unwind-queue -o json 2>/dev/null

Any result here requires immediate action.

Emergency Flatten

Cancel all open orders, then close all positions:

# Cancel all orders to free held margin
kraken futures cancel-all --yes -o json 2>/dev/null

# Close each position with reduce-only market orders
kraken futures positions -o json 2>/dev/null
# For each position:
kraken futures order sell PF_XBTUSD <SIZE> --reduce-only -o json 2>/dev/null

Margin Top-Up

Transfer funds from spot wallet to futures to increase margin:

kraken futures transfer 5000 USD -o json 2>/dev/null

Or from main account:

kraken wallet-transfer USD 5000 --from <SPOT_IIBAN> --to <FUTURES_IIBAN> -o json 2>/dev/null

Leverage Reduction

Lower leverage to reduce margin requirements:

kraken futures set-leverage PF_XBTUSD 2 -o json 2>/dev/null

Dead Man's Switch

Always run a dead man's switch during futures sessions:

kraken futures cancel-after 600 -o json 2>/dev/null

If the agent crashes, orders auto-cancel, preventing further margin consumption.

Hard Rules

  • Monitor margin ratio continuously during any futures session.
  • Alert at 0.5 ratio; act at 0.7. Do not wait for the exchange to liquidate.
  • Emergency flatten requires human approval unless the agent operates at autonomy level 4+.
  • Never increase position size when margin ratio is above 0.3.