@temple-digital-group/temple-canton-js 2.0.0-beta.7 → 2.0.0-beta.9

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/README.md CHANGED
@@ -139,7 +139,6 @@ Use this to check available funds before placing orders or withdrawals.
139
139
  ```javascript
140
140
  import { createOrderRequest } from "@temple-digital-group/temple-canton-js";
141
141
 
142
- // Single order
143
142
  const result = await createOrderRequest({
144
143
  symbol: "CC/USDCx",
145
144
  side: "buy",
@@ -148,12 +147,15 @@ const result = await createOrderRequest({
148
147
  order_type: "limit",
149
148
  });
150
149
 
151
- // Batch orders (max 20)
152
- const batchResult = await createOrderRequest([
153
- { symbol: "CC/USDCx", side: "buy", quantity: 100, price: 1.25, order_type: "limit" },
154
- { symbol: "CC/USDCx", side: "sell", quantity: 50, price: 1.50, order_type: "limit" },
155
- ]);
156
- // Returns { success, request_ids, count, message }
150
+ // Post-only order (rejected if it would match immediately)
151
+ const postOnly = await createOrderRequest({
152
+ symbol: "CC/USDCx",
153
+ side: "buy",
154
+ quantity: 10.5,
155
+ price: 1.25,
156
+ order_type: "limit",
157
+ order_subtype: "post_only",
158
+ });
157
159
  ```
158
160
 
159
161
  ### 5. Cancel Orders
@@ -161,13 +163,9 @@ const batchResult = await createOrderRequest([
161
163
  ```javascript
162
164
  import { cancelOrder, cancelAllOrders } from "@temple-digital-group/temple-canton-js";
163
165
 
164
- // Cancel a single order
166
+ // Cancel a specific order
165
167
  await cancelOrder("ord_abc123");
166
168
 
167
- // Cancel multiple orders (max 20)
168
- await cancelOrder(["ord_abc123", "ord_def456", "ord_ghi789"]);
169
- // Returns { success, canceled, already_queued, not_found, message }
170
-
171
169
  // Cancel all orders for a symbol
172
170
  await cancelAllOrders({ symbol: "CC/USDCx" });
173
171
 
@@ -422,10 +420,8 @@ const unsubOrder = ws.onUserEvent("user_order", (data) => { ... });
422
420
 
423
421
  | Function | Description |
424
422
  | ----------------------------------- | ------------------------------------------------------ |
425
- | `createOrderRequest(opts)` | Place a single order |
426
- | `createOrderRequest(opts[])` | Place up to 20 orders in one request |
427
- | `cancelOrder(orderId)` | Cancel a single order |
428
- | `cancelOrder(orderIds[])` | Cancel up to 20 orders in one request |
423
+ | `createOrderRequest(opts)` | Place a buy/sell order via the trading backend |
424
+ | `cancelOrder(orderId)` | Cancel a specific order |
429
425
  | `cancelAllOrders(options?)` | Cancel all orders (options: `symbol` filter) |
430
426
  | `getTradingBalance()` | Get user's trading balance (unlocked/locked/in-flight) |
431
427
  | `getActiveOrders(options?)` | Get active orders (options: `symbol`, `limit`) |
@@ -1,5 +1,5 @@
1
- import type { ApiError, Ticker, OrderBook, OrderBookOptions, SymbolConfig, OpenInterest, Trade, RecentTradesOptions, ActiveOrder, ActiveOrdersOptions, CancelOrderResponse, BatchCancelOrdersResponse, CancelAllOrdersOptions, CancelAllOrdersResponse, CreateOrderRequestOpts, CreateOrderRequestResponse, BatchCreateOrderRequestResponse, DelegationResponse, WithdrawalResponse, WithdrawalStatusResponse, TradingBalanceResponse, AmuletDisclosure, DisclosuresResponse } from "./types.js";
2
- export type { ApiError, Ticker, OrderBook, OrderBookOptions, SymbolConfig, OpenInterest, Trade, RecentTradesOptions, ActiveOrder, ActiveOrdersOptions, CancelOrderResponse, BatchCancelOrdersResponse, CancelAllOrdersOptions, CancelAllOrdersResponse, CreateOrderRequestResponse, BatchCreateOrderRequestResponse, DelegationResponse, WithdrawalResponse, WithdrawalStatusResponse, TradingBalanceResponse, AmuletDisclosure, DisclosuresResponse, };
1
+ import type { ApiError, Ticker, OrderBook, OrderBookOptions, SymbolConfig, OpenInterest, Trade, RecentTradesOptions, ActiveOrder, ActiveOrdersOptions, CancelOrderResponse, CancelAllOrdersOptions, CancelAllOrdersResponse, CreateOrderRequestOpts, CreateOrderRequestResponse, DelegationResponse, WithdrawalResponse, WithdrawalStatusResponse, TradingBalanceResponse, AmuletDisclosure, DisclosuresResponse } from "./types.js";
2
+ export type { ApiError, Ticker, OrderBook, OrderBookOptions, SymbolConfig, OpenInterest, Trade, RecentTradesOptions, ActiveOrder, ActiveOrdersOptions, CancelOrderResponse, CancelAllOrdersOptions, CancelAllOrdersResponse, CreateOrderRequestResponse, DelegationResponse, WithdrawalResponse, WithdrawalStatusResponse, TradingBalanceResponse, AmuletDisclosure, DisclosuresResponse, };
3
3
  export { getUserId } from "./tokenStore.js";
4
4
  export { setWalletAdapter } from "../../src/config/index.js";
5
5
  /**
@@ -40,15 +40,10 @@ export declare function getRecentTrades(symbol: string, options?: RecentTradesOp
40
40
  */
41
41
  export declare function getActiveOrders(options?: ActiveOrdersOptions): Promise<ActiveOrder[] | ApiError>;
42
42
  /**
43
- * Cancel a single order by ID.
43
+ * Cancel a specific order by ID.
44
44
  * @param orderId - The order ID to cancel
45
45
  */
46
46
  export declare function cancelOrder(orderId: string): Promise<CancelOrderResponse | ApiError>;
47
- /**
48
- * Cancel multiple orders by ID (max 20).
49
- * @param orderIds - Array of order IDs to cancel
50
- */
51
- export declare function cancelOrder(orderIds: string[]): Promise<BatchCancelOrdersResponse | ApiError>;
52
47
  /**
53
48
  * Cancel all active orders, optionally filtered by symbol.
54
49
  * @param options - Optional symbol filter
@@ -66,10 +61,9 @@ export declare function getDisclosures(partyId: string): Promise<DisclosuresResp
66
61
  export declare function getDelegation(): Promise<DelegationResponse | ApiError>;
67
62
  /**
68
63
  * Create an order request (limit buy/sell) on the Temple trading backend.
69
- * @param opts - Single order or array of orders (max 20)
64
+ * @param opts - Order parameters: symbol, side, quantity, price, order_type, expires_at
70
65
  */
71
66
  export declare function createOrderRequest(opts: CreateOrderRequestOpts): Promise<CreateOrderRequestResponse | ApiError>;
72
- export declare function createOrderRequest(opts: CreateOrderRequestOpts[]): Promise<BatchCreateOrderRequestResponse | ApiError>;
73
67
  /**
74
68
  * Create a withdrawal request.
75
69
  * @param assetId - Instrument symbol (e.g. "USDCx", "Amulet")
package/dist/api/index.js CHANGED
@@ -154,20 +154,15 @@ export async function getActiveOrders(options = {}) {
154
154
  limit: options.limit,
155
155
  });
156
156
  }
157
- export async function cancelOrder(orderIdOrIds) {
158
- if (Array.isArray(orderIdOrIds)) {
159
- if (orderIdOrIds.length === 0) {
160
- return { error: true, status: null, code: "INVALID_PARAMS", message: "At least one order ID is required." };
161
- }
162
- if (orderIdOrIds.length > 20) {
163
- return { error: true, status: null, code: "INVALID_PARAMS", message: "Maximum 20 order IDs per batch." };
164
- }
165
- return authenticatedPost("/api/trading/orders/cancel", { order_ids: orderIdOrIds });
166
- }
167
- if (!orderIdOrIds) {
157
+ /**
158
+ * Cancel a specific order by ID.
159
+ * @param orderId - The order ID to cancel
160
+ */
161
+ export async function cancelOrder(orderId) {
162
+ if (!orderId) {
168
163
  return { error: true, status: null, code: "INVALID_PARAMS", message: "Order ID is required." };
169
164
  }
170
- return authenticatedPost("/api/trading/orders/cancel", { order_id: orderIdOrIds });
165
+ return authenticatedPost(`/api/trading/orders/${encodeURIComponent(orderId)}/cancel`);
171
166
  }
172
167
  /**
173
168
  * Cancel all active orders, optionally filtered by symbol.
@@ -195,29 +190,20 @@ export async function getDisclosures(partyId) {
195
190
  export async function getDelegation() {
196
191
  return authenticatedGet("/api/trading/delegation");
197
192
  }
193
+ // ── Order Requests ──
194
+ /**
195
+ * Create an order request (limit buy/sell) on the Temple trading backend.
196
+ * @param opts - Order parameters: symbol, side, quantity, price, order_type, expires_at
197
+ */
198
198
  export async function createOrderRequest(opts) {
199
- if (Array.isArray(opts)) {
200
- if (opts.length === 0) {
201
- return { error: true, status: null, code: "INVALID_PARAMS", message: "At least one order is required." };
202
- }
203
- if (opts.length > 20) {
204
- return { error: true, status: null, code: "INVALID_PARAMS", message: "Maximum 20 orders per batch." };
205
- }
206
- const body = opts.map((o) => {
207
- const { symbol: rawSymbol, side, quantity, price, order_type = "limit", expires_at } = o;
208
- const order = { symbol: normalizeSymbol(rawSymbol), side, quantity: Number(quantity), price: Number(price), order_type };
209
- if (expires_at)
210
- order.expires_at = expires_at;
211
- return order;
212
- });
213
- return authenticatedPost("/api/trading/orders", body);
214
- }
215
- const { symbol: rawSymbol, side, quantity, price, order_type = "limit", expires_at } = opts || {};
199
+ const { symbol: rawSymbol, side, quantity, price, order_type = "limit", order_subtype, expires_at } = opts || {};
216
200
  if (!rawSymbol || !side || quantity == null || price == null) {
217
201
  return { error: true, status: null, code: "INVALID_PARAMS", message: "symbol, side, quantity, and price are required." };
218
202
  }
219
203
  const symbol = normalizeSymbol(rawSymbol);
220
204
  const body = { symbol, side, quantity: Number(quantity), price: Number(price), order_type };
205
+ if (order_subtype)
206
+ body.order_subtype = order_subtype;
221
207
  if (expires_at)
222
208
  body.expires_at = expires_at;
223
209
  return authenticatedPost("/api/trading/orders", body);
@@ -72,13 +72,6 @@ export interface CancelOrderResponse {
72
72
  already_queued: boolean;
73
73
  message: string;
74
74
  }
75
- export interface BatchCancelOrdersResponse {
76
- success: boolean;
77
- canceled: string[];
78
- already_queued: string[];
79
- not_found: string[];
80
- message: string;
81
- }
82
75
  export interface CancelAllOrdersOptions {
83
76
  symbol?: string;
84
77
  }
@@ -103,14 +96,9 @@ export interface CreateOrderRequestOpts {
103
96
  quantity: number;
104
97
  price: number;
105
98
  order_type?: string;
99
+ order_subtype?: "post_only";
106
100
  expires_at?: string;
107
101
  }
108
- export interface BatchCreateOrderRequestResponse {
109
- success: boolean;
110
- request_ids: number[];
111
- count: number;
112
- message: string;
113
- }
114
102
  export interface CreateOrderRequestResponse {
115
103
  [key: string]: unknown;
116
104
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temple-digital-group/temple-canton-js",
3
- "version": "2.0.0-beta.7",
3
+ "version": "2.0.0-beta.9",
4
4
  "description": "JavaScript library for interacting with Temple Canton blockchain",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/src/api/index.ts CHANGED
@@ -16,12 +16,10 @@ import type {
16
16
  ActiveOrder,
17
17
  ActiveOrdersOptions,
18
18
  CancelOrderResponse,
19
- BatchCancelOrdersResponse,
20
19
  CancelAllOrdersOptions,
21
20
  CancelAllOrdersResponse,
22
21
  CreateOrderRequestOpts,
23
22
  CreateOrderRequestResponse,
24
- BatchCreateOrderRequestResponse,
25
23
  DelegationResponse,
26
24
  WithdrawalResponse,
27
25
  WithdrawalStatusResponse,
@@ -43,11 +41,9 @@ export type {
43
41
  ActiveOrder,
44
42
  ActiveOrdersOptions,
45
43
  CancelOrderResponse,
46
- BatchCancelOrdersResponse,
47
44
  CancelAllOrdersOptions,
48
45
  CancelAllOrdersResponse,
49
46
  CreateOrderRequestResponse,
50
- BatchCreateOrderRequestResponse,
51
47
  DelegationResponse,
52
48
  WithdrawalResponse,
53
49
  WithdrawalStatusResponse,
@@ -232,30 +228,14 @@ export async function getActiveOrders(options: ActiveOrdersOptions = {}): Promis
232
228
  }
233
229
 
234
230
  /**
235
- * Cancel a single order by ID.
231
+ * Cancel a specific order by ID.
236
232
  * @param orderId - The order ID to cancel
237
233
  */
238
- export async function cancelOrder(orderId: string): Promise<CancelOrderResponse | ApiError>;
239
- /**
240
- * Cancel multiple orders by ID (max 20).
241
- * @param orderIds - Array of order IDs to cancel
242
- */
243
- export async function cancelOrder(orderIds: string[]): Promise<BatchCancelOrdersResponse | ApiError>;
244
- export async function cancelOrder(orderIdOrIds: string | string[]): Promise<CancelOrderResponse | BatchCancelOrdersResponse | ApiError> {
245
- if (Array.isArray(orderIdOrIds)) {
246
- if (orderIdOrIds.length === 0) {
247
- return { error: true, status: null, code: "INVALID_PARAMS", message: "At least one order ID is required." };
248
- }
249
- if (orderIdOrIds.length > 20) {
250
- return { error: true, status: null, code: "INVALID_PARAMS", message: "Maximum 20 order IDs per batch." };
251
- }
252
- return authenticatedPost("/api/trading/orders/cancel", { order_ids: orderIdOrIds });
253
- }
254
-
255
- if (!orderIdOrIds) {
234
+ export async function cancelOrder(orderId: string): Promise<CancelOrderResponse | ApiError> {
235
+ if (!orderId) {
256
236
  return { error: true, status: null, code: "INVALID_PARAMS", message: "Order ID is required." };
257
237
  }
258
- return authenticatedPost("/api/trading/orders/cancel", { order_id: orderIdOrIds });
238
+ return authenticatedPost(`/api/trading/orders/${encodeURIComponent(orderId)}/cancel`);
259
239
  }
260
240
 
261
241
  /**
@@ -293,33 +273,16 @@ export async function getDelegation(): Promise<DelegationResponse | ApiError> {
293
273
 
294
274
  /**
295
275
  * Create an order request (limit buy/sell) on the Temple trading backend.
296
- * @param opts - Single order or array of orders (max 20)
276
+ * @param opts - Order parameters: symbol, side, quantity, price, order_type, expires_at
297
277
  */
298
- export async function createOrderRequest(opts: CreateOrderRequestOpts): Promise<CreateOrderRequestResponse | ApiError>;
299
- export async function createOrderRequest(opts: CreateOrderRequestOpts[]): Promise<BatchCreateOrderRequestResponse | ApiError>;
300
- export async function createOrderRequest(opts: CreateOrderRequestOpts | CreateOrderRequestOpts[]): Promise<CreateOrderRequestResponse | BatchCreateOrderRequestResponse | ApiError> {
301
- if (Array.isArray(opts)) {
302
- if (opts.length === 0) {
303
- return { error: true, status: null, code: "INVALID_PARAMS", message: "At least one order is required." };
304
- }
305
- if (opts.length > 20) {
306
- return { error: true, status: null, code: "INVALID_PARAMS", message: "Maximum 20 orders per batch." };
307
- }
308
- const body = opts.map((o) => {
309
- const { symbol: rawSymbol, side, quantity, price, order_type = "limit", expires_at } = o;
310
- const order: Record<string, unknown> = { symbol: normalizeSymbol(rawSymbol), side, quantity: Number(quantity), price: Number(price), order_type };
311
- if (expires_at) order.expires_at = expires_at;
312
- return order;
313
- });
314
- return authenticatedPost("/api/trading/orders", body as unknown as Record<string, unknown>);
315
- }
316
-
317
- const { symbol: rawSymbol, side, quantity, price, order_type = "limit", expires_at } = opts || {};
278
+ export async function createOrderRequest(opts: CreateOrderRequestOpts): Promise<CreateOrderRequestResponse | ApiError> {
279
+ const { symbol: rawSymbol, side, quantity, price, order_type = "limit", order_subtype, expires_at } = opts || {};
318
280
  if (!rawSymbol || !side || quantity == null || price == null) {
319
281
  return { error: true, status: null, code: "INVALID_PARAMS", message: "symbol, side, quantity, and price are required." };
320
282
  }
321
283
  const symbol = normalizeSymbol(rawSymbol);
322
284
  const body: Record<string, unknown> = { symbol, side, quantity: Number(quantity), price: Number(price), order_type };
285
+ if (order_subtype) body.order_subtype = order_subtype;
323
286
  if (expires_at) body.expires_at = expires_at;
324
287
  return authenticatedPost("/api/trading/orders", body);
325
288
  }
package/src/api/types.ts CHANGED
@@ -87,14 +87,6 @@ export interface CancelOrderResponse {
87
87
  message: string;
88
88
  }
89
89
 
90
- export interface BatchCancelOrdersResponse {
91
- success: boolean;
92
- canceled: string[];
93
- already_queued: string[];
94
- not_found: string[];
95
- message: string;
96
- }
97
-
98
90
  export interface CancelAllOrdersOptions {
99
91
  symbol?: string;
100
92
  }
@@ -127,15 +119,10 @@ export interface CreateOrderRequestOpts {
127
119
  quantity: number;
128
120
  price: number;
129
121
  order_type?: string;
122
+ order_subtype?: "post_only";
130
123
  expires_at?: string;
131
124
  }
132
125
 
133
- export interface BatchCreateOrderRequestResponse {
134
- success: boolean;
135
- request_ids: number[];
136
- count: number;
137
- message: string;
138
- }
139
126
 
140
127
  export interface CreateOrderRequestResponse {
141
128
  [key: string]: unknown;