Docs, Build

Integration

Read positions and the pool from your own code

Read a position

Positions are program accounts at ["position", owner, nonce]. To list one wallet's positions, call getProgramAccounts on the program with a memcmp filter on the owner field, which starts at byte 8 after the account discriminator.

const positions = await connection.getProgramAccounts(PROGRAM_ID, {
  filters: [{ memcmp: { offset: 8, bytes: owner.toBase58() } }],
})

Decode them with the program's IDL through Anchor's BorshAccountsCoder.

Read the pool

Config at ["config"] holds the pool accounting. Pool equity is cash - queue_liability, floored at zero. The live payout queue is the positions with queue_seq between queue_head and queue_tail.

Compute a bust price

// side: 1 for long, -1 for short; bufferBps from the market's terms
const bust = entry * (1 - side * (1 / leverage - bufferBps / 10_000))

Use the terms.bust_buffer_bps stored in the position, which never changes after the request.

Submit an order

request_open(nonce, side, margin, leverage) with a fresh nonce per position. The trader is the only signer. Keep the transaction under about 950 bytes and let the wallet sign first, so Phantom has room to add its own guard.

Prices

BTC/USD, ETH/USD and SOL/USD, signed every second by the venue's price signers. The fill must use the first signed second at or after the target time. An integrator who wants to fill orders asks any signer for it (GET /v1/price?symbol=BTC&target=<unix second>), posts it with an ed25519 check followed by post_price, then sends execute_open or execute_close with the price account.

NextAPI reference