Place a perpetual order
Steps
import { ethers } from "ethers";
const provider = new ethers.JsonRpcProvider("https://rpc.podtestnet.dev");
const wallet = new ethers.Wallet(PRIVATE_KEY, provider);
const ORDERBOOK = "0x50d0000000000000000000000000000000000002";
const abi = [
"function deposit(address token, address recipient, uint256 amount, uint128 deadline)",
"function submitOrder(bytes32 orderbookId, int256 size, uint256 price, uint8 orderType, uint128 deadline, uint128 ttl, bool reduceOnly, bool ioc)",
];
const orderbook = new ethers.Contract(ORDERBOOK, abi, wallet);
// USD is Pod's native token — use the canonical native-token sentinel address
const USD = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
const nvdaPerpId = "0x0000000000000000000000000000000000000000000000000000000000000007"; // NVDA-USD perp (max 20x)
const now = BigInt(Date.now()) * 1000n; // microseconds
// 1. Deposit USD margin
const margin = ethers.parseEther("1000"); // 1,000 USD
await (await orderbook.deposit(USD, wallet.address, margin, now + 60_000_000n)).wait();
// 2. Open a long on NVDA-USD: 5 NVDA at $140 limit
const size = ethers.parseEther("5"); // +5 NVDA long (negative = short)
const price = ethers.parseEther("140"); // limit price in USD
const orderType = 0; // 0 = Limit
const deadline = now + 10_000_000n;
const ttl = 60n * 1_000_000n;
const tx = await orderbook.submitOrder(
nvdaPerpId, size, price, orderType, deadline, ttl,
false, // reduceOnly — set true to only close existing positions
false, // ioc
);
console.log("Perp order tx:", tx.hash);Closing a position
Last updated

