LogoLogo
  • 👋Welcome to Zeta
  • The Zeta DEX
    • 🔗Official Links
    • 📚Learn how to trade on Zeta
      • 🎓Introduction to Perpetuals
      • 💸Compatible Wallets
      • 📖Getting Started on Zeta
      • ✅Order Types
      • 💟Margin Account Parameters
      • 📑Asset Parameters
      • ⚖️Funding Rates
    • 🔧Trading Specifications
      • Fee Tiers
      • Delisting Process
    • 🏗️Exchange Architecture
      • Margin Accounts
      • Margin System
        • Collateral Framework
        • Liquidations & Insurance
          • Insurance Fund
          • Socialized Loss
      • Oracles
      • Orderbook & Matching Engine
      • Trigger orders
      • Trading Mechanism
      • Perpetual Funding System
    • 📱Mobile is LIVE !
    • 🌉Bridging Guide
      • 💱From Exchanges
      • ⛓️From Other Chains
  • Rewards Programs
    • 🪙$ZEX
      • 🪙Staking
        • Staking $ZEX: Step-by-Step Guide
    • 💱Trading Rewards Program
      • Z-Score Active Boosts
        • 🎁Z-Loot
      • 🥩Stakers' Boosted Trading Rewards
      • $BERA Listing (Live)
      • 🗃️Ended Trading Campaigns and Boosts
        • 🪐Jupiter x Zeta (Finished)
        • 1️⃣Season 1 (Finished)
          • 1️⃣Z-Score Season 1
            • 👥NFT Community Partners
          • ⚡S1 Zeta Cards
        • 2️⃣Season 2 (Finished)
          • 2️⃣Z-Score Season 2
            • 🍴Bitcoin Halving (Finished)
            • 🐶$WIF Listing (Finished)
            • 🔴$RNDR Listing (Finished)
            • ⬛$TNSR Listing (Finished)
            • 🔮Pyth Stakers (Finished)
            • 🟥Backpack Boost (Finished)
            • 🏁AssetDash Elements (Finished)
          • ⚡S2 Zeta Cards (Finished)
          • 🎉Community Airdrop (Finished)
        • $POPCAT Listing (Finished)
        • 👯Referral Z-Score Boost (Finished)
        • $EIGEN Listing (Finished)
        • 🟡$DBR Listing (Finished)
        • 🟡$GOAT Listing (Finished)
        • 🟪$DRIFT Listing (Live)
        • 🟪$PNUT Listing (Finished)
        • $PENGU Listing (Finished)
        • $TRUMP Listing (Finished)
    • 🔒Final Epoch
    • 🚰Maker Rewards Program
    • 👨‍👩‍👦‍👦Referrals Program
      • Genesis Epoch Referral Boost (Finished)
      • Breakpoint Referral Boost
    • 🫂Content & Community Programs
      • Creators Program
      • Community Referral Program
  • Build with Zeta
    • 💽SDKs
      • 🐍Python SDK
        • Market Making Bot
      • 🧱Typescript SDK
        • 📚Examples
          • 👶Basic example
          • ⚙️Cranking
          • 🌊Liquidator
          • 🚅Subscription
          • 📬Versioned Transactions
    • 😴REST Data API
    • 💥Program ABI
    • 🎨Brand Assets
      • 📣Brand Book
      • 📰Media Kit
      • 🎨Logo & Visual Guidelines
  • Zeta X
  • Zeta Node
    • 🌐Validator Details
  • Legal
    • Terms and Conditions
    • Staking Terms and Conditions
    • Privacy Policy
    • Location Restrictions
    • TradingView
    • Audit Reports
  • Educational Resources
    • 🆕New to Solana? Start Here!
    • 🆘Support
Powered by GitBook
On this page
  • The TriggerOrder account
  • What can you do with triggers?
  • Executing a trigger
  • Trigger admin

Was this helpful?

  1. The Zeta DEX
  2. Exchange Architecture

Trigger orders

Not just TP/SL!

PreviousOrderbook & Matching EngineNextTrading Mechanism

Last updated 1 year ago

Was this helpful?

Zeta supports trigger orders which can be permissionlessly executed based on a set condition - either a price or a timestamp. You'll see these as "Take-profit/Stop-loss" on dex.zeta.markets, but you can make more complicated triggers yourself in the SDK too.

The TriggerOrder account

When a trigger order is placed using the place_trigger_order instruction, a new TriggerOrder account is created. This account contains all necessary information about the order, and is deleted when the order is executed.

The relevant TriggerOrder accounts for a given CrossMarginAccount can be found by checking the trigger_order_bits of the CrossMarginAccount. If a bit is 1, then the corresponding TriggerOrder account exists (see utils.getTriggerOrder() to see how the seeds work). One account can hold up to 128 triggers, as the bits value stored is a u128.

What can you do with triggers?

Besides regular TP/SL, trigger orders allow you to set any price+direction or timestamp as the trigger. Just be careful with margining, as margin requirements are not checked at the time you place a trigger, but only when it executes! Think of it as simply placing an order in the future.

You can do anything that a regular PlaceOrder allows you to do, including different order types, reduceOnly and setting your own order price.

You can also edit trigger orders before they execute using the edit_trigger_order instruction.

Executing a trigger

When either the price trigger or timestamp trigger is valid, a trigger order can be executed by calling the execute_trigger_order instruction. This is permissionless, so anyone can execute anyone's trigger orders! If the condition has not been met yet, a TriggerOrderCannotBeExecuted error will be returned.

As mentioned earlier, margin requirements are only checked when the trigger order executes. This is generally not an issue for the standard TP/SL offered on dex.zeta.markets as reduceOnly is set to true, but you might want to be careful if you're making your own triggers that increase your position.

TP/SL on dex.zeta.markets uses a FillOrKill order type for market, and Limit order type for limit, and sets order_price to be 5% away from trigger_price by default (you can edit this slippage in the Settings page). Therefore the slippage should be enough to cross the spread in volatile conditions.

Trigger admin

There is extra control given to the State.trigger_admin account, which is set to our crank's wallet. This account has the power to delete active trigger orders, which it does in certain conditions:

  • If a trigger order fails too many times (currently 300, which corresponds to approx 50 mins of failed execution)

  • If a TP/SL trigger is left hanging after a user closes their position, to ensure frontend UX remains fluid.

🏗️
The TriggerOrder account on chain