Create Order
The fastest way to implement market order functionality is by using the Nitro Mode API.
Create Market Order (nitro mode)
POST
https://orderbook-mainnet.polynomial.finance/api/market_order/<market_id>
Query
market_id
You can find market id from markets api response. Retrieve All Markets Info
Headers
Request body
Note: All fields are required, even if not currently used. Fields like
allowAggregation
,allowPartialMatching
, andexpiration
are required for schema compliance but are not used functionally.
allowAggregation
boolean
true (Required but unused)
allowPartialMatching
boolean
true (Required but unused)
chainId
number
8008 (mainnet)
expiration
string
Order expirate time, in ms. (Required but unused)
referrerOrRelayer
string
0x4D387f5c0Ec87e47b9Df9b8C97B89D2977431b27
settlementStrategyId
string
0
sizeDelta
string
With 18 decimals precision. Ex -1000000000000000000
for shorting -1 size
trackingCode
string
0x0000000000000000000000000000000000000000000000000000000000000000
reduceOnly
boolean
If true
, ensures the order only reduces an existing position.
Signature Generation
The Nitro Mode Market Order API requires signed data for transaction execution.
export interface OffchainOrder {
marketId: string;
accountId: string;
sizeDelta: string;
chainId: number;
settlementStrategyId: string;
referrerOrRelayer: `0x${string}`;
allowAggregation: boolean;
allowPartialMatching: boolean;
reduceOnly: boolean;
acceptablePrice: string;
trackingCode: `0x${string}`;
expiration: string;
nonce: string;
}
export async function signOffchainOrder(
privateKey: `0x${string}`,
order: OffchainOrder,
isMainnet: boolean = false,
) {
const rpcUrl = isMainnet ? "https://rpc.sepolia.polynomial.fi/" : "https://rpc.sepolia.polynomial.fi/";
const types = {
OffchainOrder: [
{ name: 'marketId', type: 'uint128' },
{ name: 'accountId', type: 'uint128' },
{ name: 'sizeDelta', type: 'int128' },
{ name: 'settlementStrategyId', type: 'uint128' },
{ name: 'referrerOrRelayer', type: 'address' },
{ name: 'allowAggregation', type: 'bool' },
{ name: 'allowPartialMatching', type: 'bool' },
{ name: 'reduceOnly', type: 'bool' },
{ name: 'acceptablePrice', type: 'uint256' },
{ name: 'trackingCode', type: 'bytes32' },
{ name: 'expiration', type: 'uint256' },
{ name: 'nonce', type: 'uint256' },
],
};
const walletClient = createWalletClient({
transport: http(rpcUrl),
account: privateKeyToAccount(privateKey),
});
const mainnetDomain = {
name: 'PolynomialPerpetualFutures',
version: '1',
chainId: 8008,
verifyingContract: "0xD052Fa8b2af8Ed81C764D5d81cCf2725B2148688" as `0x${string}`,
};
const testnetDomain = {
name: 'PolynomialPerpetualFutures',
version: '1',
chainId: 80008,
verifyingContract: "0x52Fdc981472485232587E334c5Ca27F241CbA9AA" as `0x${string}`,
};
return await walletClient.signTypedData({
account: privateKeyToAccount(privateKey),
domain: isMainnet ? mainnetDomain : testnetDomain,
types,
primaryType: 'OffchainOrder',
message: order as any,
});
}
You can find a working TypeScript example here.
On-Chain Order via Contract Call
API wallets are permitted to create market orders directly through a smart contract call. Note: Since this method does not use a relayer, there may be a slight delay in order settlement.
For more details, refer to the documentation
Last updated
Was this helpful?