Skip to content

Commit 3a9e2b2

Browse files
committed
add post-only support to limit order workflows
1 parent 708eba4 commit 3a9e2b2

6 files changed

Lines changed: 43 additions & 2 deletions

File tree

packages/client/src/actions/orders.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,19 @@ describe('Orders', () => {
155155
expect(result.ok).toBe(true);
156156
});
157157

158+
it('carries post-only submission options onto the prepared order', async () => {
159+
const order = await prepareLimitOrder(secureClient, {
160+
orderType: OrderType.GTC,
161+
postOnly: true,
162+
price: minPrice,
163+
side: OrderSide.BUY,
164+
size: minSize,
165+
tokenId: yesTokenId,
166+
}).then(completeWith(walletClient));
167+
168+
expect(order.postOnly).toBe(true);
169+
});
170+
158171
it('requests a collateral approval if necessary', async () => {
159172
const gaslessClient = await publicClientWithRelayerKey
160173
.beginAuthentication({ wallet: safeWalletAddress })
@@ -201,13 +214,17 @@ describe('Orders', () => {
201214
it('creates, signs, and posts a limit order in one workflow', async () => {
202215
const response = await prepareLimitOrderPosting(secureClient, {
203216
orderType: OrderType.GTC,
217+
postOnly: true,
204218
price: minPrice,
205219
side: OrderSide.BUY,
206220
size: minSize,
207221
tokenId: yesTokenId,
208222
}).then(completeWith(walletClient));
209223

210224
expect(response.ok).toBe(true);
225+
const acceptedResponse = expectAcceptedOrderResponse(response);
226+
227+
expect(acceptedResponse.status).toBe(OrderPostStatus.LIVE);
211228
});
212229
});
213230

packages/client/src/actions/orders/limit.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const PrepareLimitOrderParamsSchema = z
3434
size: z.number().positive(),
3535
side: OrderSideSchema,
3636
taker: EvmAddressSchema.optional(),
37+
postOnly: z.boolean().default(false),
3738
expiration: z.number().int().nonnegative().optional(),
3839
orderType: z
3940
.union([z.literal(OrderType.GTC), z.literal(OrderType.GTD)])

packages/client/src/actions/orders/post.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import {
33
OrderResponseSchema,
44
type OrderResponses,
55
OrderResponsesSchema,
6+
OrderType,
67
} from '@polymarket/bindings/clob';
7-
import { unwrap } from '@polymarket/types';
8+
import { invariant, unwrap } from '@polymarket/types';
89
import { z } from 'zod';
910
import type { BaseSecureClient } from '../../clients';
1011
import type {
@@ -108,6 +109,13 @@ export function postOrders(
108109
}
109110

110111
function createSendOrderPayload(client: BaseSecureClient, order: SignedOrder) {
112+
invariant(
113+
order.postOnly !== true ||
114+
order.orderType === OrderType.GTC ||
115+
order.orderType === OrderType.GTD,
116+
'Post-only orders are only supported for GTC and GTD order types.',
117+
);
118+
111119
return {
112120
deferExec: false,
113121
order: {
@@ -127,5 +135,6 @@ function createSendOrderPayload(client: BaseSecureClient, order: SignedOrder) {
127135
},
128136
orderType: order.orderType,
129137
owner: client.credentials.key,
138+
...(order.postOnly === true ? { postOnly: true } : {}),
130139
};
131140
}

packages/client/src/actions/orders/prepare.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export type PrepareLimitOrderError =
107107
* @example
108108
* ```ts
109109
* const order = await prepareLimitOrder(client, {
110+
* postOnly: true,
110111
* price: 0.52,
111112
* side: OrderSide.BUY,
112113
* size: 10,
@@ -134,7 +135,9 @@ export async function prepareLimitOrder(
134135
yield signOrder(createOrderTypedDataPayload(unsignedOrder)),
135136
);
136137

137-
return createSignedOrder(unsignedOrder, signature);
138+
const order = createSignedOrder(unsignedOrder, signature);
139+
140+
return params.postOnly === true ? { ...order, postOnly: true } : order;
138141
}.call(null);
139142
}
140143

@@ -178,6 +181,7 @@ export type PrepareLimitOrderPostingError = PrepareLimitOrderError;
178181
* @example
179182
* ```ts
180183
* const response = await prepareLimitOrderPosting(client, {
184+
* postOnly: true,
181185
* price: 0.52,
182186
* side: OrderSide.BUY,
183187
* size: 10,

packages/client/src/actions/orders/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ export type PrepareLimitOrderRequest = {
5555
/** Taker address. Omit for public orders (zero address is equivalent). */
5656
taker?: string;
5757

58+
/**
59+
* Posts the prepared order as post-only when submitted.
60+
*
61+
* @defaultValue false
62+
*/
63+
postOnly?: boolean;
64+
5865
/** Timestamp after which the order is expired. Required for GTD orders. */
5966
expiration?: number;
6067

@@ -119,6 +126,7 @@ export type SignedOrder = {
119126
takerAmount: string;
120127
tokenId: TokenId;
121128
signature: EvmSignature;
129+
postOnly?: boolean;
122130
};
123131

124132
export type OrderWorkflowRequest =

packages/client/src/decorators/trading.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export type TradingActions = {
8484
* @example
8585
* ```ts
8686
* const order = await client.prepareLimitOrder({
87+
* postOnly: true,
8788
* price: 0.52,
8889
* side: OrderSide.BUY,
8990
* size: 10,
@@ -105,6 +106,7 @@ export type TradingActions = {
105106
* @example
106107
* ```ts
107108
* const response = await client.prepareLimitOrderPosting({
109+
* postOnly: true,
108110
* price: 0.52,
109111
* side: OrderSide.BUY,
110112
* size: 10,

0 commit comments

Comments
 (0)