Place a spot 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 the native token; NVDAx is the synthetic Nvidia base
const USD = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
const orderbookId = "0x0000000000000000000000000000000000000000000000000000000000000001"; // NVDAx-USD spot
const now = BigInt(Date.now()) * 1000n; // microseconds
// 1. Deposit USD (the quote token) into the orderbook
const depositAmount = ethers.parseEther("1000");
await (await orderbook.deposit(USD, wallet.address, depositAmount, now + 60_000_000n)).wait();
// 2. Submit a buy limit order: 1 NVDAx at 200 USD
const size = ethers.parseEther("1"); // buy 1 NVDAx (positive = buy)
const price = ethers.parseEther("200"); // limit price in USD
const orderType = 0; // 0 = Limit, 1 = Market
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, size, price, orderType, deadline, ttl,
false, // reduceOnly (perp only)
false, // ioc — immediate-or-cancel
);
console.log("Order tx:", tx.hash);Last updated

