Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/api/exchange/_methods/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,16 @@ export const OrderRequest = /* @__PURE__ */ (() => {
* - `"na"`: Standard order without grouping.
* - `"normalTpsl"`: TP/SL order with fixed size that doesn't adjust with position changes.
* - `"positionTpsl"`: TP/SL order that adjusts proportionally with the position size.
* - `{ p: number }`: Order priority rate as a fraction `p / 1e8` (max `p = 80000`, i.e. 8 bps).
* Only valid when every order is IOC on a perp asset.
* - `{ p: number }`: Order priority rate as a fraction `p / 1e8`.
* Only valid when every order is on a non-outcome asset and either every order is IOC
* or every order is a non-reduce-only ALO.
*/
grouping: v.optional(
v.union([
v.picklist(["na", "normalTpsl", "positionTpsl"]),
v.object({
/** Priority rate as a fraction `p / 1e8` (max `80000`, i.e. 8 bps). */
p: v.pipe(UnsignedInteger, v.maxValue(80000)),
/** Priority rate as a fraction `p / 1e8`. */
p: v.pipe(UnsignedInteger, v.maxValue(100_000_000)),
}),
]),
"na",
Expand Down
36 changes: 28 additions & 8 deletions tests/api/exchange/order.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ runTest({
const params: OrderParameters[] = [
// resting | limit | Gtc | no cloid | grouping=default
{
orders: [{ a: id, b: true, p: pxDown, s: sz, r: false, t: { limit: { tif: "Gtc" } } }],
orders: [{
a: id,
b: true,
p: pxDown,
s: sz,
r: false,
t: { limit: { tif: "Gtc" } },
}],
},
// resting | limit | Alo | cloid
{
Expand Down Expand Up @@ -62,7 +69,14 @@ runTest({
},
// filled | limit | FrontendMarket | b=false | builder
{
orders: [{ a: id, b: false, p: pxDown, s: sz, r: false, t: { limit: { tif: "FrontendMarket" } } }],
orders: [{
a: id,
b: false,
p: pxDown,
s: sz,
r: false,
t: { limit: { tif: "FrontendMarket" } },
}],
grouping: "na",
builder: { b: "0xe019d6167E7e324aEd003d94098496b6d986aB05", f: 1 },
},
Expand Down Expand Up @@ -95,19 +109,25 @@ runTest({
},
];

// Priority order: grouping={p:N} requires IOC on a perp asset; the temp account
// has no resting orders to match against, so this rejects with "Order could not
// immediately match". p=0 means no priority cost (no delegatable balance required).
// Priority order at the maximum rate: the fee is charged from undelegated staking
// balance, which a freshly created temp account does not have.
const priorityParam: OrderParameters = {
orders: [{ a: id, b: true, p: pxDown, s: sz, r: false, t: { limit: { tif: "Ioc" } } }],
grouping: { p: 0 },
orders: [{
a: id,
b: true,
p: pxDown,
s: sz,
r: false,
t: { limit: { tif: "Ioc" } },
}],
grouping: { p: 100_000_000 },
};
await assertRejects(
async () => {
await exchClient.order(priorityParam);
},
ApiRequestError,
"Order could not immediately match",
"Insufficient delegatable balance for priority order",
);

const data = await Promise.all(params.map((p) => exchClient.order(p)));
Expand Down