Aftermath
  • Aftermath
    • About Aftermath Finance
      • What are we building?
  • Getting Started
    • Creating an account
      • zkLogin
        • Removing a zkLogin account
      • Sui Metamask Snap
      • Native Sui wallets
    • Dynamic Gas
    • Navigating Aftermath
      • Interacting with your Wallet
      • Viewing your Portfolio
      • Changing your Settings
      • Bridge
      • Referrals
  • Trade
    • Smart-Order Router
      • Agg of Aggs
      • Making a trade
      • Exact Out
      • Fees
    • DCA
      • Why should I use DCA
      • How does DCA work
      • Tutorials
        • Creating a DCA order
        • Monitoring DCA progress
        • Advanced Features
      • Fees
      • Contracts
  • Limit Orders
    • Contracts
    • Fees
  • Pools
    • Constant Function Market Maker
      • Tutorials
        • Depositing
        • Withdrawing
        • Creating a Pool
      • Fees
      • Contracts
      • Audit
  • Farms
    • Afterburner Vaults
      • Tutorials
        • Staking into a Farm
        • Claiming Rewards
        • Unstaking
        • Creating a Farm
      • Architecture
        • Vault
        • Stake Position
      • Fees
      • FAQs
  • Liquid Staking
    • afSUI
      • Tutorials
        • Staking
        • Unstaking
      • Architecture
        • Packages & Modules
        • Entry Points
      • Fees
      • FAQs
      • Contracts
      • Audit
  • Perpetuals
    • Aftermath Perpetuals
      • Tutorials
        • Creating an Account
        • Selecting a Market
        • Creating a Market Order
        • Creating a Limit Order
        • Maintaining your Positions
      • Architecture
        • Oracle Prices
        • Margin
        • Account
        • Trading
        • Funding
        • Liquidations
        • Fees
  • GameFi
    • NFT AMM
      • Architecture
        • Fission Vaults
        • AMM Pools
      • Tutorials
        • Buy
        • Sell
        • Deposit
        • Withdraw
      • Sui Overflow
  • Our validator
    • About us
  • Developers
    • Aftermath TS SDK
      • Utils
        • Coin
        • Users Data
        • Authorization
      • Products
        • Prices
        • Router
        • DCA
        • Limit Orders
        • Liquid Staking
        • Pools
        • Farms
    • Aftermath REST API
      • Authorization
  • Egg
    • About Egg
  • Legal
    • Terms of Service
    • Privacy Policy
  • Languages
    • 中文
    • 한국어
  • Links
    • X
    • Telegram
    • Discord
    • Github
    • Medium
    • Aftermath Validator
Powered by GitBook
On this page
  • Limit Orders
  • Constants
  • Order Management
  1. Developers
  2. Aftermath TS SDK
  3. Products

Limit Orders

Limit Orders allow you to set precise buy or sell conditions, enabling automated trades at your desired price levels. Secure better market entry or exit points and maintain control over your strategy,

Limit Orders

const afSdk = new Aftermath("MAINNET");
await afSdk.init(); // initialize provider

const dca = afSdk.Dca();
const limitOrders = afSdk.LimitOrders();
const userData = afSdk.UserData();

Constants

LimitOrders.constants = {
	gasAmount: BigInt(50_000_000),
};

Order Management

Authorization

To use the Aftermath Limit Orders service, you'll need to create a user account by signing a personal message in two cases:

  1. When creating your first order

  2. When fetching your active orders

This signature serves two important purposes:

  • It provides essential data that helps ensure the service works correctly

  • It verifies authorization identity

const messageToSign = userData.createUserAccountMessageToSign();

const signedMessage = await signPersonalMessage({
	message: new TextEncoder().encode(JSON.stringify(messageToSign)),
});

Fetch Orders

const activeOrders = await limit.getActiveLimitOrders({
  walletAddress: "0x..",
  bytes: signedMessage.bytes,
  signature: signedMessage.signature
});

const pastOrders = await limit.getPastLimitOrders({
  walletAddress: "0x..",
});
export interface LimitOrderObject {
	objectId: string;
	allocatedCoin: {
		coin: string;
		amount: string;
	};
	buyCoin: {
		coin: string;
		amount: string;
	};
	currentAmountSold: string;
	currentAmountBought: string;
	recipient: string;
	created: {
		timestamp: number;
		txnDigest: string;
	};
	finished?: {
		timestamp: number;
		txnDigest: string;
	};
	expiryTimestamp: number;
	status: 
	| "Active"
	| "Canceled"
	| "Failed"
	| "Filled"
	| "Expired"
	| "StopLossTriggered";
	error?: string;
	integratorFee?: {
        feeBps: number;
        feeRecipient: SuiAddress;
    };
	outputToInputStopLossExchangeRate?: number;
}

Create Order

const tx = await limitOrders.getCreateLimitOrderTx({
    walletAddress: "0x..",
    allocateCoinType:
        "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN",
    allocateCoinAmount: BigInt(50000),
    buyCoinType:
        "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",
    expiryDurationMs: 0,
    outputToInputExchangeRate: 0.45,
    outputToInputStopLossExchangeRate: 0,
    integratorFee: {
        feeBps: 6000, // 60%
        feeRecipient: "0x...",
    },
});

Cancel Order

const messageToSign = limit.cancelLimitOrderMessageToSign({
  orderIds: ["0x.."]
});

const signedMessage = await signPersonalMessage({
  message: new TextEncoder().encode(JSON.stringify(messageToSign)),
});

const success = await limit.cancelLimitOrder({
	...signedMessage,
	walletAddress: "0x..",
});
PreviousDCANextLiquid Staking

Last updated 2 months ago