Buying: bids
A bid is the mirror of an ask: you escrow payment, and sellers come to you.
Create
TypeScript
import { createBid, PricingKind } from '@otcdex/sdk';
const ix = createBid({
buyer: wallet.publicKey,
buyerQuoteAccount,
tokenMint, // what you want to buy
tokenProgram,
quoteMint, // what you are paying with
quoteTokenProgram,
seed: BigInt(Date.now()),
quoteAmount: 1_000_000_000n, // exactly amount x price, no fee padding
minFillQuote: 10_000_000n, // smallest sale you will accept
expiryTs: BigInt(Math.floor(Date.now() / 1000) + 86_400),
allowedSeller: null,
pricing: { kind: PricingKind.Fixed, pricePerToken: 1_000_000n },
});Read the capacity
remainingTokenCapacity on an indexed bid answers the question a seller actually asks: how many tokens will this bid take? It is floored, so it never overstates.
Cancel
TypeScript
import { cancelBid } from '@otcdex/sdk';
const ix = cancelBid({
closer: wallet.publicKey,
buyer: bid.buyer,
bid: bid.address,
quoteMint: bid.quoteMint,
quoteTokenProgram: bid.quoteProgram,
buyerQuoteAccount,
});Returns every unspent unit of escrowed payment.