Skip to content

Commit eb2032e

Browse files
committed
feat: add market order preparation workflow
1 parent 0f92937 commit eb2032e

30 files changed

Lines changed: 1066 additions & 14 deletions

AGENTS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
- Prefer `type` over `interface` unless an interface is clearly needed, such as when a class implements it or declaration extensibility is a deliberate requirement.
4040
- Prefer function declarations over arrow functions unless there is a clear reason to use an arrow function.
41+
- When a request, params, or options object shape is specific to a single function, colocate that type directly above the function declaration.
42+
- Treat property-access-derived types like `SecureClient['signatureType']` as a code smell in most cases. Prefer a named domain type when the value is part of the public or shared model.
4143
- Prefer simple, local code. Accept small duplication when it keeps logic easier to read.
4244
- Introduce helpers only when they meaningfully improve reuse, safety, or readability. Helper names should reflect their real behavior; otherwise inline or rename them.
4345
- Shape abstractions around real supported workflows and current platform behavior, not generic completeness. Add breadth only when a concrete use case requires it.

docs/sdk-direction.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ The first shipping target is `@polymarket/client`. Its job is to make Polymarket
2727

2828
- In this case, make CLOB responses use camelCased fields.
2929
- Add a cache layer for `tickSize`, fee bps, and `negRisk` metadata.
30+
- Consider moving `SignedOrder` into `packages/client/src/types.ts` so it is easier to reuse across order actions and wallet helpers.
31+
- Revisit whether the Gamma `GET /markets` `active` flag should be modeled in the SDK, since it is accepted in practice but omitted from the current OpenAPI contract and current client request type.
3032

3133
## Package Direction
3234

packages/bindings/src/clob/account.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export enum AssetType {
9595
CONDITIONAL = 'CONDITIONAL',
9696
}
9797

98-
export const AssetTypeSchema = z.nativeEnum(AssetType);
98+
export const AssetTypeSchema = z.enum(AssetType);
9999

100100
export const BalanceAllowanceResponseSchema = z.object({
101101
allowances: z.record(z.string(), z.string()),

packages/bindings/src/clob/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ export * from './account';
22
export * from './api-key';
33
export * from './fee-rate';
44
export * from './neg-risk';
5+
export * from './order';
6+
export * from './order-book';
7+
export * from './order-response';
58
export * from './pagination';
69
export * from './signature-type';
710
export * from './tick-size';
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { z } from 'zod';
2+
3+
export const OrderBookLevelSchema = z.looseObject({
4+
price: z.string(),
5+
size: z.string(),
6+
});
7+
8+
export const OrderBookSchema = z.looseObject({
9+
market: z.string(),
10+
asset_id: z.string(),
11+
timestamp: z.string().nullish(),
12+
bids: z.array(OrderBookLevelSchema),
13+
asks: z.array(OrderBookLevelSchema),
14+
min_order_size: z.string(),
15+
tick_size: z.string(),
16+
neg_risk: z.boolean(),
17+
last_trade_price: z.string().nullish(),
18+
hash: z.string(),
19+
});
20+
21+
export const FetchOrderBookResponseSchema = OrderBookSchema;
22+
23+
export type OrderBookLevel = z.infer<typeof OrderBookLevelSchema>;
24+
export type OrderBook = z.infer<typeof OrderBookSchema>;
25+
export type FetchOrderBookResponse = z.infer<
26+
typeof FetchOrderBookResponseSchema
27+
>;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { z } from 'zod';
2+
3+
export const OrderResponseSchema = z.object({
4+
errorMsg: z.string(),
5+
makingAmount: z.string(),
6+
orderID: z.string(),
7+
status: z.string(),
8+
success: z.boolean(),
9+
takingAmount: z.string(),
10+
transactionsHashes: z.array(z.string()),
11+
});
12+
13+
export type OrderResponse = z.infer<typeof OrderResponseSchema>;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { z } from 'zod';
2+
3+
export enum OrderSide {
4+
BUY = 'BUY',
5+
SELL = 'SELL',
6+
}
7+
8+
export enum OrderType {
9+
GTC = 'GTC',
10+
FOK = 'FOK',
11+
GTD = 'GTD',
12+
FAK = 'FAK',
13+
}
14+
15+
export const OrderSideSchema = z.enum(OrderSide);
16+
export const OrderTypeSchema = z.enum(OrderType);

packages/bindings/src/clob/signature-type.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
import { z } from 'zod';
22

33
export enum SignatureType {
4+
/**
5+
* ECDSA EIP712 signatures signed by EOAs
6+
*/
47
EOA = 0,
8+
9+
/**
10+
* EIP712 signatures signed by EOAs that own Polymarket Proxy wallets
11+
*/
512
POLY_PROXY = 1,
13+
14+
/**
15+
* EIP712 signatures signed by EOAs that own Polymarket Gnosis safes
16+
*/
617
POLY_GNOSIS_SAFE = 2,
718
}
819

packages/bindings/src/clob/tick-size.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { z } from 'zod';
2+
import { TickSizeValueSchema } from '../shared';
23

34
export const TickSizeSchema = z.looseObject({
4-
minimum_tick_size: z.number(),
5+
minimum_tick_size: TickSizeValueSchema,
56
});
67

78
export const FetchTickSizeResponseSchema = TickSizeSchema;

packages/bindings/src/gamma/market.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { z } from 'zod';
2-
import { MarketIdSchema } from '../shared';
2+
import { MarketIdSchema, TickSizeValueSchema } from '../shared';
33
import {
44
CategoryReferenceSchema,
55
ClobRewardsSchema,
@@ -74,7 +74,7 @@ export const MarketSchema = z.looseObject({
7474
questionID: z.string().nullish(),
7575
umaEndDate: z.string().nullish(),
7676
enableOrderBook: z.boolean().nullish(),
77-
orderPriceMinTickSize: z.number().nullish(),
77+
orderPriceMinTickSize: TickSizeValueSchema.nullish(),
7878
orderMinSize: z.number().nullish(),
7979
umaResolutionStatus: z.string().nullish(),
8080
curationOrder: z.number().int().nullish(),

0 commit comments

Comments
 (0)