Place an order

This guide walks through placing a limit order on Pod's orderbook. For background on how the orderbook and matching work, see Orderbookarrow-up-right and Batch Auctionsarrow-up-right.

Steps

  1. Deposit tokens into the orderbook contract.

  2. Submit a limit order with price, volume, deadline, and TTL.

import { ethers } from "ethers";

const provider = new ethers.JsonRpcProvider("https://rpc.v1.dev.pod.network");
const wallet = new ethers.Wallet(PRIVATE_KEY, provider);

const ORDERBOOK = "0x000000000000000000000000000000000000C10B";
const abi = [
  "function deposit(address token, address recipient, uint256 amount, uint128 deadline)",
  "function submitOrder(bytes32 orderbookId, int256 volume, uint256 price, uint128 deadline, uint128 ttl, bool reduceOnly)",
];
const orderbook = new ethers.Contract(ORDERBOOK, abi, wallet);

const USDT = "0x0000000000000000000000000000000000000001";
const orderbookId = "0x0000000000000000000000000000000000000000000000000000000000000001";
const now = BigInt(Date.now()) * 1000n; // microseconds

// 1. Deposit tokens into the orderbook
const depositAmount = ethers.parseEther("1000");
await (await orderbook.deposit(USDT, wallet.address, depositAmount, now + 60_000_000n)).wait();

// 2. Submit a buy limit order
const volume = ethers.parseEther("1");       // buy 1 unit (positive = buy)
const price = ethers.parseEther("5000");     // limit price
const deadline = now + 10_000_000n;          // include in batches within next 10 seconds
const ttl = 60n * 1_000_000n;               // order lives for 60 seconds

const tx = await orderbook.submitOrder(orderbookId, volume, price, deadline, ttl, false);
console.log("Order tx:", tx.hash);
circle-exclamation

Last updated