Skip to content

Commit 1f9b59d

Browse files
committed
update limit order expiration handling
1 parent 3a9e2b2 commit 1f9b59d

4 files changed

Lines changed: 10 additions & 42 deletions

File tree

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ describe('Orders', () => {
143143

144144
it('allows to place a limit order for the desired size and price', async () => {
145145
const result = await prepareLimitOrder(secureClient, {
146-
orderType: OrderType.GTC,
147146
price: minPrice,
148147
side: OrderSide.BUY,
149148
size: minSize,
@@ -157,7 +156,6 @@ describe('Orders', () => {
157156

158157
it('carries post-only submission options onto the prepared order', async () => {
159158
const order = await prepareLimitOrder(secureClient, {
160-
orderType: OrderType.GTC,
161159
postOnly: true,
162160
price: minPrice,
163161
side: OrderSide.BUY,
@@ -186,7 +184,6 @@ describe('Orders', () => {
186184
.then((handle) => handle.wait());
187185

188186
const response = await prepareLimitOrder(gaslessClient, {
189-
orderType: OrderType.GTC,
190187
price: minPrice,
191188
side: OrderSide.BUY,
192189
size: minSize,
@@ -213,7 +210,6 @@ describe('Orders', () => {
213210

214211
it('creates, signs, and posts a limit order in one workflow', async () => {
215212
const response = await prepareLimitOrderPosting(secureClient, {
216-
orderType: OrderType.GTC,
217213
postOnly: true,
218214
price: minPrice,
219215
side: OrderSide.BUY,
@@ -321,7 +317,6 @@ async function createRestingLimitOrder(): Promise<{
321317
const tickSize = expectPresent(market.orderPriceMinTickSize);
322318
const size = expectPresent(market.orderMinSize);
323319
const response = await prepareLimitOrderPosting(secureClient, {
324-
orderType: OrderType.GTC,
325320
price: tickSize,
326321
side: OrderSide.BUY,
327322
size,
@@ -345,7 +340,6 @@ async function createSignedRestingLimitOrder() {
345340
const size = expectPresent(market.orderMinSize);
346341

347342
return prepareLimitOrder(secureClient, {
348-
orderType: OrderType.GTC,
349343
price: tickSize,
350344
side: OrderSide.BUY,
351345
size,

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

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,48 +28,26 @@ import {
2828
import type { OrderDraft, PrepareLimitOrderRequest } from './types';
2929

3030
export const PrepareLimitOrderParamsSchema = z
31-
.object({
31+
.strictObject({
3232
tokenId: TokenIdSchema,
3333
price: z.number().positive(),
3434
size: z.number().positive(),
3535
side: OrderSideSchema,
3636
taker: EvmAddressSchema.optional(),
3737
postOnly: z.boolean().default(false),
3838
expiration: z.number().int().nonnegative().optional(),
39-
orderType: z
40-
.union([z.literal(OrderType.GTC), z.literal(OrderType.GTD)])
41-
.default(OrderType.GTC),
4239
})
4340
.superRefine((params, context) => {
44-
if (params.orderType === OrderType.GTD) {
45-
if (params.expiration === undefined) {
46-
context.addIssue({
47-
code: 'custom',
48-
message: 'GTD orders require an expiration timestamp.',
49-
path: ['expiration'],
50-
});
51-
return;
52-
}
53-
41+
if (params.expiration !== undefined) {
5442
const minimumExpiration = Math.floor(Date.now() / 1000) + 60;
5543

5644
if (params.expiration <= minimumExpiration) {
5745
context.addIssue({
5846
code: 'custom',
59-
message: 'GTD expiration must be at least 60 seconds in the future.',
47+
message: 'Expiration must be at least 60 seconds in the future.',
6048
path: ['expiration'],
6149
});
6250
}
63-
64-
return;
65-
}
66-
67-
if (params.expiration !== undefined) {
68-
context.addIssue({
69-
code: 'custom',
70-
message: 'Expiration is only supported for GTD orders.',
71-
path: ['expiration'],
72-
});
7351
}
7452
}) satisfies z.ZodType<PrepareLimitOrderRequest>;
7553

@@ -104,7 +82,7 @@ export async function prepareLimitOrderDraft(
10482
feeRateBps: context.feeRateBps,
10583
funderAddress: context.funderAddress,
10684
offeredAmount: amounts.offeredAmount,
107-
orderType: params.orderType,
85+
orderType: params.expiration === undefined ? OrderType.GTC : OrderType.GTD,
10886
side: params.side,
10987
signer: context.signerAddress,
11088
allowedTaker: params.taker,

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,15 @@ export type PrepareLimitOrderRequest = {
6262
*/
6363
postOnly?: boolean;
6464

65-
/** Timestamp after which the order is expired. Required for GTD orders. */
66-
expiration?: number;
67-
6865
/**
69-
* Specifies the type of order execution.
70-
* - GTC (Good-Til-Cancelled): rests on the book until filled or cancelled
71-
* - GTD (Good-Til-Date): active until the specified expiration timestamp
66+
* Unix timestamp in seconds after which the order expires.
7267
*
73-
* @defaultValue OrderType.GTC
68+
* When provided, the SDK prepares a Good-Til-Date (GTD) limit order that
69+
* expires at the given timestamp.
70+
*
71+
* When omitted, the SDK prepares a Good-Til-Cancelled (GTC) limit order.
7472
*/
75-
orderType?: OrderType.GTC | OrderType.GTD;
73+
expiration?: number;
7674
};
7775

7876
export type OrderDraft = {

packages/client/src/ethers-v5.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
type AcceptedOrderResponse,
33
OrderSide,
4-
OrderType,
54
} from '@polymarket/bindings/clob';
65
import { expectPresent } from '@polymarket/types';
76
import { ethers } from 'ethers-v5';
@@ -60,7 +59,6 @@ describe('ethers-v5', () => {
6059
.then(authenticateWith(signer));
6160

6261
const response = await prepareLimitOrderPosting(secureClient, {
63-
orderType: OrderType.GTC,
6462
price,
6563
size,
6664
side: OrderSide.BUY,

0 commit comments

Comments
 (0)