@speculite/clob-client 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +153 -0
- package/dist/client/baseClient.d.ts +93 -0
- package/dist/client/baseClient.js +374 -0
- package/dist/client/baseClient.js.map +1 -0
- package/dist/client/lifecycleClient.d.ts +48 -0
- package/dist/client/lifecycleClient.js +163 -0
- package/dist/client/lifecycleClient.js.map +1 -0
- package/dist/client/publicClient.d.ts +44 -0
- package/dist/client/publicClient.js +127 -0
- package/dist/client/publicClient.js.map +1 -0
- package/dist/client/tradingClient.d.ts +15 -0
- package/dist/client/tradingClient.js +75 -0
- package/dist/client/tradingClient.js.map +1 -0
- package/dist/errors.d.ts +7 -0
- package/dist/errors.js +31 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/constants.d.ts +142 -0
- package/dist/internal/constants.js +84 -0
- package/dist/internal/constants.js.map +1 -0
- package/dist/internal/utils.d.ts +26 -0
- package/dist/internal/utils.js +115 -0
- package/dist/internal/utils.js.map +1 -0
- package/dist/speculiteClobClient.d.ts +16 -0
- package/dist/speculiteClobClient.js +17 -0
- package/dist/speculiteClobClient.js.map +1 -0
- package/dist/types.d.ts +353 -0
- package/dist/types.js +11 -0
- package/dist/types.js.map +1 -0
- package/package.json +58 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import type { Address, Hex, PublicClient, WalletClient } from 'viem';
|
|
2
|
+
/** Trade side used by order creation and order/trade responses. */
|
|
3
|
+
export declare const Side: {
|
|
4
|
+
readonly BUY: "BUY";
|
|
5
|
+
readonly SELL: "SELL";
|
|
6
|
+
};
|
|
7
|
+
/** Order execution mode. */
|
|
8
|
+
export declare const OrderType: {
|
|
9
|
+
readonly LIMIT: "LIMIT";
|
|
10
|
+
readonly MARKET: "MARKET";
|
|
11
|
+
};
|
|
12
|
+
export type OrderSide = typeof Side[keyof typeof Side];
|
|
13
|
+
export type OrderTypeValue = typeof OrderType[keyof typeof OrderType];
|
|
14
|
+
export type Outcome = 'YES' | 'NO';
|
|
15
|
+
/** Developer API credentials generated from the Speculite app UI. */
|
|
16
|
+
export interface ApiCredentials {
|
|
17
|
+
apiKey: string;
|
|
18
|
+
apiSecret: string;
|
|
19
|
+
}
|
|
20
|
+
/** High-level order arguments for `createOrder` / `createAndPostOrder`. */
|
|
21
|
+
export interface CreateOrderArgs {
|
|
22
|
+
marketId: string;
|
|
23
|
+
outcome: Outcome;
|
|
24
|
+
side: OrderSide;
|
|
25
|
+
price: number | string;
|
|
26
|
+
size: number | string;
|
|
27
|
+
nonce?: number | string | bigint;
|
|
28
|
+
expiry?: number;
|
|
29
|
+
orderType?: OrderTypeValue;
|
|
30
|
+
maxSlippage?: number | string;
|
|
31
|
+
maker?: string;
|
|
32
|
+
}
|
|
33
|
+
/** Canonical market metadata used for order-signing domain resolution. */
|
|
34
|
+
export interface MarketSigningInfo {
|
|
35
|
+
marketId: string;
|
|
36
|
+
exchangeAddress: string;
|
|
37
|
+
marketIdOnchain: number;
|
|
38
|
+
takerFeeBps: number;
|
|
39
|
+
}
|
|
40
|
+
/** ---------- Public Market Data Types ---------- */
|
|
41
|
+
export interface Market {
|
|
42
|
+
market_id: string;
|
|
43
|
+
exchange_address?: string | null;
|
|
44
|
+
market_id_onchain?: number | string | null;
|
|
45
|
+
taker_fee_bps?: number | string | null;
|
|
46
|
+
pyth_feed_id?: string | null;
|
|
47
|
+
expiration_timestamp?: string | number | null;
|
|
48
|
+
[key: string]: unknown;
|
|
49
|
+
}
|
|
50
|
+
export interface MarketsResponse {
|
|
51
|
+
success: boolean;
|
|
52
|
+
markets: Market[];
|
|
53
|
+
pagination?: {
|
|
54
|
+
total: number;
|
|
55
|
+
limit: number;
|
|
56
|
+
offset: number;
|
|
57
|
+
hasMore: boolean;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export interface MarketResponse {
|
|
61
|
+
success: boolean;
|
|
62
|
+
market: Market;
|
|
63
|
+
}
|
|
64
|
+
export interface MarketDataResponse {
|
|
65
|
+
market_id: string;
|
|
66
|
+
midpoint_price: string | null;
|
|
67
|
+
best_bid: string | null;
|
|
68
|
+
best_ask: string | null;
|
|
69
|
+
spread: string | null;
|
|
70
|
+
timestamp?: string;
|
|
71
|
+
}
|
|
72
|
+
export interface MarketDataBatchResponse {
|
|
73
|
+
success: boolean;
|
|
74
|
+
data: MarketDataResponse[];
|
|
75
|
+
}
|
|
76
|
+
export interface OrderbookLevel {
|
|
77
|
+
price: string;
|
|
78
|
+
size?: string;
|
|
79
|
+
token_id?: number;
|
|
80
|
+
tokenId?: number;
|
|
81
|
+
[key: string]: unknown;
|
|
82
|
+
}
|
|
83
|
+
export interface OrderbookResponse {
|
|
84
|
+
market_id?: string;
|
|
85
|
+
bids: OrderbookLevel[];
|
|
86
|
+
asks: OrderbookLevel[];
|
|
87
|
+
last_price?: string | null;
|
|
88
|
+
timestamp?: string;
|
|
89
|
+
[key: string]: unknown;
|
|
90
|
+
}
|
|
91
|
+
/** ---------- Developer API Types ---------- */
|
|
92
|
+
export interface DeveloperApiKey {
|
|
93
|
+
api_key_id: string;
|
|
94
|
+
key_prefix: string;
|
|
95
|
+
label: string | null;
|
|
96
|
+
scopes: string[];
|
|
97
|
+
status: 'ACTIVE' | 'REVOKED';
|
|
98
|
+
ip_allowlist: string[];
|
|
99
|
+
expires_at: string | null;
|
|
100
|
+
last_used_at: string | null;
|
|
101
|
+
last_used_ip: string | null;
|
|
102
|
+
created_at: string;
|
|
103
|
+
}
|
|
104
|
+
export interface DeveloperApiKeysResponse {
|
|
105
|
+
success: boolean;
|
|
106
|
+
keys: DeveloperApiKey[];
|
|
107
|
+
}
|
|
108
|
+
export interface DeveloperApiKeyRevokeResponse {
|
|
109
|
+
success: boolean;
|
|
110
|
+
api_key_id: string;
|
|
111
|
+
status: 'REVOKED';
|
|
112
|
+
}
|
|
113
|
+
export interface DeveloperWalletActivity {
|
|
114
|
+
wallet_address: string;
|
|
115
|
+
first_seen_at: string;
|
|
116
|
+
last_seen_at: string;
|
|
117
|
+
order_count: number;
|
|
118
|
+
traded_volume_usdc: string;
|
|
119
|
+
}
|
|
120
|
+
export interface DeveloperWalletActivityResponse {
|
|
121
|
+
success: boolean;
|
|
122
|
+
wallets: DeveloperWalletActivity[];
|
|
123
|
+
}
|
|
124
|
+
export interface DeveloperAuthMeResponse {
|
|
125
|
+
success: boolean;
|
|
126
|
+
principal: {
|
|
127
|
+
user_id: string;
|
|
128
|
+
api_key_id: string;
|
|
129
|
+
scopes: string[];
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
export interface DeveloperOpenOrder {
|
|
133
|
+
order_id: string;
|
|
134
|
+
market_id: string;
|
|
135
|
+
side: OrderSide;
|
|
136
|
+
token_id: number;
|
|
137
|
+
type: OrderTypeValue;
|
|
138
|
+
price: string;
|
|
139
|
+
size: string;
|
|
140
|
+
filled_size: string;
|
|
141
|
+
status: string;
|
|
142
|
+
client_order_id: string;
|
|
143
|
+
created_at: string;
|
|
144
|
+
}
|
|
145
|
+
export interface DeveloperOpenOrdersResponse {
|
|
146
|
+
success: boolean;
|
|
147
|
+
orders: DeveloperOpenOrder[];
|
|
148
|
+
}
|
|
149
|
+
export interface DeveloperPagination {
|
|
150
|
+
limit: number;
|
|
151
|
+
offset: number;
|
|
152
|
+
has_more: boolean;
|
|
153
|
+
}
|
|
154
|
+
export interface DeveloperOrderHistoryEntry extends DeveloperOpenOrder {
|
|
155
|
+
outcome: Outcome;
|
|
156
|
+
cancellation_reason?: string | null;
|
|
157
|
+
cancelled_at?: string | null;
|
|
158
|
+
updated_at?: string;
|
|
159
|
+
}
|
|
160
|
+
export interface DeveloperOrderHistoryResponse {
|
|
161
|
+
success: boolean;
|
|
162
|
+
orders: DeveloperOrderHistoryEntry[];
|
|
163
|
+
pagination: DeveloperPagination;
|
|
164
|
+
}
|
|
165
|
+
export interface DeveloperTradeFill {
|
|
166
|
+
trade_id: string;
|
|
167
|
+
market_id: string;
|
|
168
|
+
maker_order_id: string;
|
|
169
|
+
taker_order_id: string;
|
|
170
|
+
role: 'MAKER' | 'TAKER';
|
|
171
|
+
side: OrderSide;
|
|
172
|
+
token_id: number;
|
|
173
|
+
outcome: Outcome;
|
|
174
|
+
price: string;
|
|
175
|
+
size: string;
|
|
176
|
+
client_order_id: string | null;
|
|
177
|
+
settlement_status: string;
|
|
178
|
+
transaction_hash: string | null;
|
|
179
|
+
user_operation_hash: string | null;
|
|
180
|
+
matched_at: string;
|
|
181
|
+
}
|
|
182
|
+
export interface DeveloperTradesResponse {
|
|
183
|
+
success: boolean;
|
|
184
|
+
trades: DeveloperTradeFill[];
|
|
185
|
+
pagination: DeveloperPagination;
|
|
186
|
+
}
|
|
187
|
+
export interface DeveloperPosition {
|
|
188
|
+
position_id: string;
|
|
189
|
+
market_id: string;
|
|
190
|
+
market_name: string | null;
|
|
191
|
+
title: string | null;
|
|
192
|
+
question: string | null;
|
|
193
|
+
underlying_symbol: string | null;
|
|
194
|
+
expiration_timestamp: string;
|
|
195
|
+
market_status: string;
|
|
196
|
+
winning_outcome: number | null;
|
|
197
|
+
token_id: number;
|
|
198
|
+
outcome: Outcome;
|
|
199
|
+
quantity: string;
|
|
200
|
+
average_entry_price: string;
|
|
201
|
+
position_status: string;
|
|
202
|
+
updated_at: string;
|
|
203
|
+
}
|
|
204
|
+
export interface DeveloperPositionsResponse {
|
|
205
|
+
success: boolean;
|
|
206
|
+
positions: DeveloperPosition[];
|
|
207
|
+
pagination: DeveloperPagination;
|
|
208
|
+
}
|
|
209
|
+
export interface DeveloperListParams {
|
|
210
|
+
marketId?: string;
|
|
211
|
+
limit?: number;
|
|
212
|
+
offset?: number;
|
|
213
|
+
}
|
|
214
|
+
export interface DeveloperPositionsParams extends DeveloperListParams {
|
|
215
|
+
includeClosed?: boolean;
|
|
216
|
+
}
|
|
217
|
+
/** Response returned when an order is accepted by the backend lifecycle queue. */
|
|
218
|
+
export interface DeveloperOrderAcceptedResponse {
|
|
219
|
+
success: boolean;
|
|
220
|
+
lifecycle_status: 'ACCEPTED';
|
|
221
|
+
order_id: string;
|
|
222
|
+
client_order_id: string;
|
|
223
|
+
market_id: string;
|
|
224
|
+
side: OrderSide;
|
|
225
|
+
outcome: Outcome;
|
|
226
|
+
price: string;
|
|
227
|
+
size: string;
|
|
228
|
+
accepted_at: string;
|
|
229
|
+
}
|
|
230
|
+
export interface DeveloperCancelOrderResponse {
|
|
231
|
+
success: boolean;
|
|
232
|
+
message: string;
|
|
233
|
+
}
|
|
234
|
+
export interface DeveloperResolveMarketResponse {
|
|
235
|
+
success: boolean;
|
|
236
|
+
market_id: string;
|
|
237
|
+
resolutionTransactionHash: string;
|
|
238
|
+
resolutionData: {
|
|
239
|
+
resolutionPrice: string;
|
|
240
|
+
winningTokenId: number;
|
|
241
|
+
winningOutcome?: string;
|
|
242
|
+
} | null;
|
|
243
|
+
message: string;
|
|
244
|
+
}
|
|
245
|
+
/** ---------- Signing and Lifecycle Transaction Types ---------- */
|
|
246
|
+
/** Raw order payload shape expected by `/api/developer/orders`. */
|
|
247
|
+
export interface DeveloperOrderRequest {
|
|
248
|
+
market_id: string;
|
|
249
|
+
maker: string;
|
|
250
|
+
outcome: Outcome;
|
|
251
|
+
side: OrderSide;
|
|
252
|
+
price: string;
|
|
253
|
+
size: string;
|
|
254
|
+
nonce: string;
|
|
255
|
+
expiry: number;
|
|
256
|
+
signature: string;
|
|
257
|
+
order_type?: OrderTypeValue;
|
|
258
|
+
max_slippage?: string;
|
|
259
|
+
}
|
|
260
|
+
/** Minimal signer abstraction accepted by the SDK. */
|
|
261
|
+
export interface SignerLike {
|
|
262
|
+
address?: string;
|
|
263
|
+
account?: {
|
|
264
|
+
address?: string;
|
|
265
|
+
};
|
|
266
|
+
getAddress?: () => Promise<string> | string;
|
|
267
|
+
signTypedData: (...args: any[]) => Promise<string>;
|
|
268
|
+
}
|
|
269
|
+
/** Generic prepared transaction representation used by lifecycle helpers. */
|
|
270
|
+
export interface PreparedOnchainTransaction {
|
|
271
|
+
to: Address;
|
|
272
|
+
data: Hex;
|
|
273
|
+
value?: bigint;
|
|
274
|
+
chainId: number;
|
|
275
|
+
kind: 'approve_usdc' | 'mint' | 'merge' | 'claim' | 'resolve';
|
|
276
|
+
}
|
|
277
|
+
export interface PreparedResolveTransaction extends PreparedOnchainTransaction {
|
|
278
|
+
kind: 'resolve';
|
|
279
|
+
updateData: Hex[];
|
|
280
|
+
updateFeeWei: bigint;
|
|
281
|
+
marketIdOnchain: number;
|
|
282
|
+
}
|
|
283
|
+
/** On-chain metadata required to build lifecycle transactions. */
|
|
284
|
+
export interface OnchainMarketInfo {
|
|
285
|
+
marketId: string;
|
|
286
|
+
marketIdOnchain: number;
|
|
287
|
+
exchangeAddress: Address;
|
|
288
|
+
pythFeedId?: Hex | null;
|
|
289
|
+
expiryTimestamp?: number | null;
|
|
290
|
+
}
|
|
291
|
+
export interface PrepareApproveUsdcArgs {
|
|
292
|
+
spender: Address;
|
|
293
|
+
amount: number | string;
|
|
294
|
+
usdcAddress: Address;
|
|
295
|
+
}
|
|
296
|
+
export interface PrepareMintArgs {
|
|
297
|
+
marketId: string;
|
|
298
|
+
amount: number | string;
|
|
299
|
+
market?: Partial<OnchainMarketInfo>;
|
|
300
|
+
}
|
|
301
|
+
export interface PrepareMergeArgs {
|
|
302
|
+
marketId: string;
|
|
303
|
+
pairs: number | string;
|
|
304
|
+
holder: Address;
|
|
305
|
+
market?: Partial<OnchainMarketInfo>;
|
|
306
|
+
}
|
|
307
|
+
export interface PrepareClaimArgs {
|
|
308
|
+
marketId: string;
|
|
309
|
+
market?: Partial<OnchainMarketInfo>;
|
|
310
|
+
}
|
|
311
|
+
export interface PrepareResolveArgs {
|
|
312
|
+
marketId: string;
|
|
313
|
+
market?: Partial<OnchainMarketInfo>;
|
|
314
|
+
pythAddress?: Address;
|
|
315
|
+
rpcUrl?: string;
|
|
316
|
+
pythPriceServiceUrl?: string;
|
|
317
|
+
allowLatestFallback?: boolean;
|
|
318
|
+
}
|
|
319
|
+
/** Return type for lifecycle methods that both prepare and submit txs. */
|
|
320
|
+
export interface OnchainExecutionResult<T extends PreparedOnchainTransaction> {
|
|
321
|
+
hash: Hex;
|
|
322
|
+
tx: T;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Runtime overrides for networking/chain integrations.
|
|
326
|
+
* Useful in tests and advanced integrations.
|
|
327
|
+
*/
|
|
328
|
+
export interface RuntimeOptions {
|
|
329
|
+
fetch?: typeof fetch;
|
|
330
|
+
now?: () => number;
|
|
331
|
+
publicClient?: PublicClient;
|
|
332
|
+
walletClient?: WalletClient;
|
|
333
|
+
rpcUrl?: string;
|
|
334
|
+
pythAddress?: Address;
|
|
335
|
+
pythPriceServiceUrl?: string;
|
|
336
|
+
}
|
|
337
|
+
/** Preferred constructor options for `SpeculiteClobClient`. */
|
|
338
|
+
export interface ClientConstructorOptions extends RuntimeOptions {
|
|
339
|
+
signatureType?: number;
|
|
340
|
+
funderAddress?: string;
|
|
341
|
+
}
|
|
342
|
+
/** Internal request options used by client transport. */
|
|
343
|
+
export interface RequestOptions {
|
|
344
|
+
query?: Record<string, string | number | boolean | null | undefined>;
|
|
345
|
+
body?: unknown;
|
|
346
|
+
headers?: HeadersInit;
|
|
347
|
+
auth?: 'none' | 'bearer' | 'developer';
|
|
348
|
+
authToken?: string;
|
|
349
|
+
}
|
|
350
|
+
/** Lightweight JSON object shape used by error extraction utilities. */
|
|
351
|
+
export interface JsonObject {
|
|
352
|
+
[key: string]: unknown;
|
|
353
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Trade side used by order creation and order/trade responses. */
|
|
2
|
+
export const Side = {
|
|
3
|
+
BUY: 'BUY',
|
|
4
|
+
SELL: 'SELL'
|
|
5
|
+
};
|
|
6
|
+
/** Order execution mode. */
|
|
7
|
+
export const OrderType = {
|
|
8
|
+
LIMIT: 'LIMIT',
|
|
9
|
+
MARKET: 'MARKET'
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,mEAAmE;AACnE,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,MAAM;CACJ,CAAC;AAEX,4BAA4B;AAC5B,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,QAAQ;CACR,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@speculite/clob-client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Official TypeScript SDK for Speculite CLOB and developer trading APIs",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Speculite",
|
|
8
|
+
"homepage": "https://docs.speculite.com",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/mspurr/speculite-sdk.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/mspurr/speculite-sdk/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"speculite",
|
|
18
|
+
"prediction-market",
|
|
19
|
+
"clob",
|
|
20
|
+
"orderbook",
|
|
21
|
+
"trading-sdk"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=18"
|
|
25
|
+
},
|
|
26
|
+
"main": "./dist/index.js",
|
|
27
|
+
"module": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"README.md",
|
|
38
|
+
"LICENSE"
|
|
39
|
+
],
|
|
40
|
+
"sideEffects": false,
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"viem": "^2.38.4"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsc -p tsconfig.build.json",
|
|
46
|
+
"clean": "rm -rf dist",
|
|
47
|
+
"type-check": "tsc --noEmit",
|
|
48
|
+
"test": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --config jest.config.cjs",
|
|
49
|
+
"prepublishOnly": "npm run clean && npm run type-check && npm run test && npm run build"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@types/jest": "^29.5.14",
|
|
53
|
+
"@types/node": "^20.17.46",
|
|
54
|
+
"jest": "^29.7.0",
|
|
55
|
+
"ts-jest": "^29.2.5",
|
|
56
|
+
"typescript": "^5.7.3"
|
|
57
|
+
}
|
|
58
|
+
}
|