@temple-digital-group/temple-canton-js 2.0.0-beta.4 → 2.0.0-beta.6
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 +163 -61
- package/dist/api/index.d.ts +10 -4
- package/dist/api/index.js +28 -12
- package/dist/api/types.d.ts +13 -0
- package/dist/canton/deposits.d.ts +52 -0
- package/dist/canton/deposits.js +466 -0
- package/dist/canton/helpers.js +2 -2
- package/dist/canton/withdrawals.js +6 -3
- package/dist/websocket/index.d.ts +70 -0
- package/dist/websocket/index.js +295 -0
- package/index.js +3 -0
- package/package.json +4 -2
- package/src/api/index.ts +45 -7
- package/src/api/tokenStore.ts +30 -30
- package/src/api/types.ts +15 -0
- package/src/canton/deposits.ts +559 -0
- package/src/canton/helpers.ts +2 -2
- package/src/canton/index.d.ts +24 -0
- package/src/canton/index.js +130 -340
- package/src/canton/instrumentCatalog.d.ts +1 -0
- package/src/canton/instrumentCatalog.js +9 -0
- package/src/canton/withdrawals.ts +6 -3
- package/src/config/index.d.ts +2 -0
- package/src/config/index.js +7 -0
- package/src/websocket/index.ts +341 -0
- package/src/websocket/ws.d.ts +24 -0
package/README.md
CHANGED
|
@@ -45,13 +45,13 @@ setWalletAdapter(loop);
|
|
|
45
45
|
|
|
46
46
|
## Supported Instruments
|
|
47
47
|
|
|
48
|
-
| Asset
|
|
49
|
-
|
|
|
50
|
-
| CC
|
|
51
|
-
| USDCx
|
|
52
|
-
| CBTC
|
|
48
|
+
| Asset | Type | Networks |
|
|
49
|
+
| ----- | ----------- | ---------------- |
|
|
50
|
+
| CC | Canton Coin | testnet, mainnet |
|
|
51
|
+
| USDCx | Utility | testnet, mainnet |
|
|
52
|
+
| CBTC | Utility | testnet, mainnet |
|
|
53
53
|
|
|
54
|
-
> **Symbol normalization:** `CC`
|
|
54
|
+
> **Symbol normalization:** Use `CC` for Canton Coin in all SDK methods. The SDK handles the internal conversion to `Amulet` where required by the ledger. The `Amulet` symbol is deprecated — all API responses now return `CC`.
|
|
55
55
|
|
|
56
56
|
## Supported Trading Pairs
|
|
57
57
|
|
|
@@ -112,19 +112,19 @@ const result = await depositFunds(depositOpts);
|
|
|
112
112
|
|
|
113
113
|
`depositFunds` accepts:
|
|
114
114
|
|
|
115
|
-
| Option | Required | Description
|
|
116
|
-
| ---------------- | -------- |
|
|
117
|
-
| `sender` | Yes | Party allocating the assets
|
|
118
|
-
| `assetId` | Yes | Instrument symbol (`USDCx`, `Amulet`, `CBTC`)
|
|
119
|
-
| `amount` | Yes | Amount to allocate
|
|
120
|
-
| `holdingCids` | Yes | Holding contract IDs that fund the allocation
|
|
121
|
-
| `receiver` | No | Counterparty (defaults to sender)
|
|
122
|
-
| `settlementId` | No | Reference ID for the settlement
|
|
123
|
-
| `transferLegId` | No | Unique ID for this transfer leg
|
|
124
|
-
| `allocateBefore` | No | ISO timestamp; allocation deadline (default: +1h)
|
|
125
|
-
| `settleBefore` | No | ISO timestamp; settlement deadline (default: +2h)
|
|
126
|
-
| `disclosures` | No | Pre-fetched Amulet disclosures (for FE without API access)
|
|
127
|
-
| `userId` | No | User ID (falls back to wallet adapter / config)
|
|
115
|
+
| Option | Required | Description |
|
|
116
|
+
| ---------------- | -------- | ---------------------------------------------------------- |
|
|
117
|
+
| `sender` | Yes | Party allocating the assets |
|
|
118
|
+
| `assetId` | Yes | Instrument symbol (`USDCx`, `Amulet`, `CBTC`) |
|
|
119
|
+
| `amount` | Yes | Amount to allocate |
|
|
120
|
+
| `holdingCids` | Yes | Holding contract IDs that fund the allocation |
|
|
121
|
+
| `receiver` | No | Counterparty (defaults to sender) |
|
|
122
|
+
| `settlementId` | No | Reference ID for the settlement |
|
|
123
|
+
| `transferLegId` | No | Unique ID for this transfer leg |
|
|
124
|
+
| `allocateBefore` | No | ISO timestamp; allocation deadline (default: +1h) |
|
|
125
|
+
| `settleBefore` | No | ISO timestamp; settlement deadline (default: +2h) |
|
|
126
|
+
| `disclosures` | No | Pre-fetched Amulet disclosures (for FE without API access) |
|
|
127
|
+
| `userId` | No | User ID (falls back to wallet adapter / config) |
|
|
128
128
|
|
|
129
129
|
For Amulet deposits, the SDK fetches disclosures automatically. You can also pass them manually via `opts.disclosures`.
|
|
130
130
|
|
|
@@ -228,8 +228,6 @@ Each entry in the returned array contains:
|
|
|
228
228
|
}
|
|
229
229
|
```
|
|
230
230
|
|
|
231
|
-
|
|
232
|
-
|
|
233
231
|
### Merge Holdings
|
|
234
232
|
|
|
235
233
|
```javascript
|
|
@@ -252,6 +250,94 @@ const res = await walletProvider.submitTransaction(cmd);
|
|
|
252
250
|
const counts = await getUtxoCount(partyId, "USDCx", walletProvider);
|
|
253
251
|
```
|
|
254
252
|
|
|
253
|
+
## WebSocket — Real-Time Data
|
|
254
|
+
|
|
255
|
+
Subscribe to live market data and user events via WebSocket. Works in both Node.js and browsers.
|
|
256
|
+
|
|
257
|
+
The server has two types of data:
|
|
258
|
+
|
|
259
|
+
- **Market data** — public channels you explicitly subscribe to (orderbook, trades, ticker, candles, oracle)
|
|
260
|
+
- **User data** — automatically pushed after authentication, no subscribe needed (orders, trades, balances)
|
|
261
|
+
|
|
262
|
+
```javascript
|
|
263
|
+
import {
|
|
264
|
+
subscribeOrderbook,
|
|
265
|
+
subscribeTrades,
|
|
266
|
+
subscribeTicker,
|
|
267
|
+
subscribeCandles,
|
|
268
|
+
subscribeUserOrders,
|
|
269
|
+
subscribeUserTrades,
|
|
270
|
+
subscribeUserBalances,
|
|
271
|
+
disconnectWebSocket,
|
|
272
|
+
} from "@temple-digital-group/temple-canton-js";
|
|
273
|
+
|
|
274
|
+
// Market data — sends a subscribe message to the server
|
|
275
|
+
const unsub = subscribeOrderbook("Amulet/USDCx", (data) => {
|
|
276
|
+
console.log("Orderbook update:", data);
|
|
277
|
+
});
|
|
278
|
+
subscribeTrades("Amulet/USDCx", (data) => console.log("Trade:", data));
|
|
279
|
+
subscribeTicker("CBTC/USDCx", (data) => console.log("Ticker:", data));
|
|
280
|
+
subscribeCandles("Amulet/USDCx", 60, (data) => console.log("1m candle:", data));
|
|
281
|
+
|
|
282
|
+
// User data — auto-delivered after auth, no subscribe message needed
|
|
283
|
+
subscribeUserOrders((data) => console.log("Order update:", data));
|
|
284
|
+
subscribeUserTrades((data) => console.log("Trade fill:", data));
|
|
285
|
+
subscribeUserBalances((data) => console.log("Balance update:", data));
|
|
286
|
+
|
|
287
|
+
// Unsubscribe from a specific channel
|
|
288
|
+
unsub();
|
|
289
|
+
|
|
290
|
+
// Disconnect everything
|
|
291
|
+
disconnectWebSocket();
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### Market Data Channels
|
|
295
|
+
|
|
296
|
+
These require an explicit subscribe message. The SDK handles this automatically.
|
|
297
|
+
|
|
298
|
+
| Function | Channel | Example |
|
|
299
|
+
| ------------------------------------------- | -------------------------------- | ------------------------- |
|
|
300
|
+
| `subscribeOrderbook(symbol, cb)` | `orderbook:{symbol}` | `orderbook:Amulet/USDCx` |
|
|
301
|
+
| `subscribeTrades(symbol, cb)` | `trades:{symbol}` | `trades:Amulet/USDCx` |
|
|
302
|
+
| `subscribeTicker(symbol, cb)` | `ticker:{symbol}` | `ticker:CBTC/USDCx` |
|
|
303
|
+
| `subscribeCandles(symbol, granularity, cb)` | `candles:{symbol}:{granularity}` | `candles:Amulet/USDCx:60`|
|
|
304
|
+
| `subscribeOracle(symbol, cb)` | `oracle:{symbol}` | `oracle:cc` |
|
|
305
|
+
| `subscribeOracleVolume(symbol, cb)` | `oracle_volume:{symbol}` | `oracle_volume:cc` |
|
|
306
|
+
|
|
307
|
+
**Candle granularity values:** `60` (1m), `300` (5m), `900` (15m), `3600` (1h), `14400` (4h), `86400` (1d)
|
|
308
|
+
|
|
309
|
+
### User Data Events
|
|
310
|
+
|
|
311
|
+
Pushed automatically by the server after authentication. No subscribe message is sent — you just register a local handler. Requires `API_KEY` (Node.js) or cookie auth (browser).
|
|
312
|
+
|
|
313
|
+
| Function | Server Event | Description |
|
|
314
|
+
| -------------------------- | -------------- | -------------------------------------------------- |
|
|
315
|
+
| `subscribeUserOrders(cb)` | `user_order` | Order lifecycle updates (created, filled, cancelled)|
|
|
316
|
+
| `subscribeUserTrades(cb)` | `user_trade` | Trade fill confirmations |
|
|
317
|
+
| `subscribeUserBalances(cb)`| `user_balance` | Balance changes |
|
|
318
|
+
|
|
319
|
+
### Advanced Usage
|
|
320
|
+
|
|
321
|
+
Use the `TempleWebSocket` class directly for full control:
|
|
322
|
+
|
|
323
|
+
```javascript
|
|
324
|
+
import { TempleWebSocket } from "@temple-digital-group/temple-canton-js";
|
|
325
|
+
|
|
326
|
+
const ws = new TempleWebSocket();
|
|
327
|
+
ws.onConnect = () => console.log("Connected");
|
|
328
|
+
ws.onDisconnect = (code, reason) => console.log("Disconnected:", code, reason);
|
|
329
|
+
ws.onAuth = (success, userId) => console.log("Auth:", success, userId);
|
|
330
|
+
ws.onError = (err) => console.error("WS error:", err);
|
|
331
|
+
ws.autoReconnect = true; // default — reconnects with exponential backoff
|
|
332
|
+
ws.connect();
|
|
333
|
+
|
|
334
|
+
// Market data — sends subscribe to server
|
|
335
|
+
const unsub = ws.subscribe("orderbook:Amulet/USDCx", (data) => { ... });
|
|
336
|
+
|
|
337
|
+
// User data — no subscribe message, just local handler
|
|
338
|
+
const unsubOrder = ws.onUserEvent("user_order", (data) => { ... });
|
|
339
|
+
```
|
|
340
|
+
|
|
255
341
|
## API Reference
|
|
256
342
|
|
|
257
343
|
> Functions marked with **W** support Loop Wallet via the wallet adapter.
|
|
@@ -272,36 +358,36 @@ const counts = await getUtxoCount(partyId, "USDCx", walletProvider);
|
|
|
272
358
|
|
|
273
359
|
### Onboarding & Delegation
|
|
274
360
|
|
|
275
|
-
| Function
|
|
276
|
-
|
|
|
277
|
-
| `isUserOnboarded(party)`
|
|
278
|
-
| `onboardUser(party)`
|
|
279
|
-
| `withdrawDelegation(delegationId?, user?)` | **W**
|
|
361
|
+
| Function | Provider | Description |
|
|
362
|
+
| ------------------------------------------ | -------- | ------------------------------------------------------ |
|
|
363
|
+
| `isUserOnboarded(party)` | **W** | Check if user has a delegation contract on ledger |
|
|
364
|
+
| `onboardUser(party)` | **W** | Create the delegation contract needed for trading |
|
|
365
|
+
| `withdrawDelegation(delegationId?, user?)` | **W** | Archive the delegation contract (user must re-onboard) |
|
|
280
366
|
|
|
281
367
|
### Deposits & Withdrawals
|
|
282
368
|
|
|
283
|
-
| Function
|
|
284
|
-
|
|
|
285
|
-
| `prepareDepositHoldings(amount, assetId)` | **W**
|
|
286
|
-
| `depositFunds(opts)`
|
|
287
|
-
| `withdrawFunds({ asset_id, amount })`
|
|
288
|
-
| `emergencyWithdrawFunds(opts)`
|
|
369
|
+
| Function | Provider | Description |
|
|
370
|
+
| ----------------------------------------- | -------- | ----------------------------------------------------- |
|
|
371
|
+
| `prepareDepositHoldings(amount, assetId)` | **W** | Resolve holdings for a deposit amount |
|
|
372
|
+
| `depositFunds(opts)` | **W** | Deposit funds into the user's trading balance |
|
|
373
|
+
| `withdrawFunds({ asset_id, amount })` | **W** | Withdraw available trading balance back to wallet |
|
|
374
|
+
| `emergencyWithdrawFunds(opts)` | **W** | Cancel all orders and withdraw everything immediately |
|
|
289
375
|
|
|
290
376
|
### Holdings
|
|
291
377
|
|
|
292
|
-
| Function | Provider | Description
|
|
293
|
-
| ----------------------------------------------------------------- | -------- |
|
|
294
|
-
| `getUserBalances(party?, provider?)` | **W** | Get all balances grouped by asset (Amulet, locked, and utility)
|
|
295
|
-
| `getAmuletHoldingsForParty(party, returnCommand, provider)`
|
|
296
|
-
| `getLockedAmuletHoldingsForParty(party, returnCommand, provider)
|
|
297
|
-
| `getUtilityHoldingsForParty(party, returnCommand, provider)`
|
|
298
|
-
| `getUtxoCount(party, assetId, provider)`
|
|
378
|
+
| Function | Provider | Description |
|
|
379
|
+
| ----------------------------------------------------------------- | -------- | ----------------------------------------------------------------------------- |
|
|
380
|
+
| `getUserBalances(party?, provider?)` | **W** | Get all balances grouped by asset (Amulet, locked, and utility) |
|
|
381
|
+
| `getAmuletHoldingsForParty(party, returnCommand, provider)` | **W** | Get Amulet holdings |
|
|
382
|
+
| `getLockedAmuletHoldingsForParty(party, returnCommand, provider)` | **W** | Get locked Amulet holdings |
|
|
383
|
+
| `getUtilityHoldingsForParty(party, returnCommand, provider)` | **W** | Get utility token holdings |
|
|
384
|
+
| `getUtxoCount(party, assetId, provider)` | **W** | Get UTXO summary: counts, largest unlocked amount, and total unlocked balance |
|
|
299
385
|
|
|
300
386
|
### Holding Operations
|
|
301
387
|
|
|
302
|
-
| Function | Provider | Description
|
|
303
|
-
| ------------------------------------------------------------------------------------------ | -------- |
|
|
304
|
-
| `mergeAmuletHoldingsForParty(party, returnCommand, provider, maxUtxos, amuletDisclosures)` | **W** | Merge Amulet holdings into one
|
|
388
|
+
| Function | Provider | Description |
|
|
389
|
+
| ------------------------------------------------------------------------------------------ | -------- | ------------------------------- |
|
|
390
|
+
| `mergeAmuletHoldingsForParty(party, returnCommand, provider, maxUtxos, amuletDisclosures)` | **W** | Merge Amulet holdings into one |
|
|
305
391
|
| `mergeUtilityHoldingsForParty(party, utilityAsset, returnCommand, provider, maxUtxos)` | **W** | Merge utility holdings into one |
|
|
306
392
|
|
|
307
393
|
### Temple REST API
|
|
@@ -310,10 +396,10 @@ const counts = await getUtxoCount(partyId, "USDCx", walletProvider);
|
|
|
310
396
|
|
|
311
397
|
#### Auth
|
|
312
398
|
|
|
313
|
-
| Function
|
|
314
|
-
|
|
|
315
|
-
| `setApiKey(key)`
|
|
316
|
-
| `getUserId()`
|
|
399
|
+
| Function | Description |
|
|
400
|
+
| ---------------- | ------------------------------------------- |
|
|
401
|
+
| `setApiKey(key)` | Set the API key for REST API authentication |
|
|
402
|
+
| `getUserId()` | Get the stored user ID |
|
|
317
403
|
|
|
318
404
|
#### Market Data
|
|
319
405
|
|
|
@@ -327,24 +413,40 @@ const counts = await getUtxoCount(partyId, "USDCx", walletProvider);
|
|
|
327
413
|
|
|
328
414
|
#### Trading
|
|
329
415
|
|
|
330
|
-
| Function
|
|
331
|
-
|
|
|
332
|
-
| `createOrderRequest(opts)`
|
|
333
|
-
| `cancelOrder(orderId)`
|
|
334
|
-
| `cancelAllOrders(options?)`
|
|
335
|
-
| `getTradingBalance()`
|
|
336
|
-
| `getActiveOrders(options?)`
|
|
416
|
+
| Function | Description |
|
|
417
|
+
| --------------------------- | ------------------------------------------------------ |
|
|
418
|
+
| `createOrderRequest(opts)` | Place a buy/sell order via the trading backend |
|
|
419
|
+
| `cancelOrder(orderId)` | Cancel a specific order |
|
|
420
|
+
| `cancelAllOrders(options?)` | Cancel all orders (options: `symbol` filter) |
|
|
421
|
+
| `getTradingBalance()` | Get user's trading balance (unlocked/locked/in-flight) |
|
|
422
|
+
| `getActiveOrders(options?)` | Get active orders (options: `symbol`, `limit`) |
|
|
337
423
|
|
|
338
424
|
#### Withdrawals
|
|
339
425
|
|
|
340
|
-
| Function
|
|
341
|
-
|
|
|
342
|
-
| `createWithdrawalRequest(assetId, amount)`
|
|
343
|
-
| `getWithdrawalRequestStatus(requestId)`
|
|
426
|
+
| Function | Description |
|
|
427
|
+
| ------------------------------------------ | ------------------------------------------ |
|
|
428
|
+
| `createWithdrawalRequest(assetId, amount)` | Submit a withdrawal request to the backend |
|
|
429
|
+
| `getWithdrawalRequestStatus(requestId)` | Poll withdrawal status until ready |
|
|
344
430
|
|
|
345
431
|
#### Disclosures & Delegation
|
|
346
432
|
|
|
347
|
-
| Function | Description
|
|
348
|
-
| ------------------------- |
|
|
349
|
-
| `getDisclosures(partyId)` | Get Amulet disclosure data (factory ID, choice context, disclosed contracts)
|
|
350
|
-
| `getDelegation()` | Get the user's delegation contract from the API
|
|
433
|
+
| Function | Description |
|
|
434
|
+
| ------------------------- | ---------------------------------------------------------------------------- |
|
|
435
|
+
| `getDisclosures(partyId)` | Get Amulet disclosure data (factory ID, choice context, disclosed contracts) |
|
|
436
|
+
| `getDelegation()` | Get the user's delegation contract from the API |
|
|
437
|
+
|
|
438
|
+
### WebSocket
|
|
439
|
+
|
|
440
|
+
| Function | Description |
|
|
441
|
+
| ------------------------------------------- | -------------------------------------------------------------- |
|
|
442
|
+
| `createWebSocket()` | Get or create the shared WS instance (auto-connects) |
|
|
443
|
+
| `disconnectWebSocket()` | Disconnect and destroy the shared WS instance |
|
|
444
|
+
| `subscribeOrderbook(symbol, cb)` | Subscribe to orderbook updates |
|
|
445
|
+
| `subscribeTrades(symbol, cb)` | Subscribe to trade updates |
|
|
446
|
+
| `subscribeTicker(symbol, cb)` | Subscribe to ticker updates |
|
|
447
|
+
| `subscribeCandles(symbol, granularity, cb)` | Subscribe to candle updates |
|
|
448
|
+
| `subscribeOracle(symbol, cb)` | Subscribe to oracle price updates |
|
|
449
|
+
| `subscribeOracleVolume(symbol, cb)` | Subscribe to oracle volume updates |
|
|
450
|
+
| `subscribeUserOrders(cb)` | Listen to user order events (auto-pushed, no subscribe needed) |
|
|
451
|
+
| `subscribeUserTrades(cb)` | Listen to user trade events (auto-pushed, no subscribe needed) |
|
|
452
|
+
| `subscribeUserBalances(cb)` | Listen to user balance events (auto-pushed, no subscribe needed)|
|
package/dist/api/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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, };
|
|
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, };
|
|
3
3
|
export { getUserId } from "./tokenStore.js";
|
|
4
4
|
export { setWalletAdapter } from "../../src/config/index.js";
|
|
5
5
|
/**
|
|
@@ -40,10 +40,15 @@ 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
|
|
43
|
+
* Cancel a single 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>;
|
|
47
52
|
/**
|
|
48
53
|
* Cancel all active orders, optionally filtered by symbol.
|
|
49
54
|
* @param options - Optional symbol filter
|
|
@@ -61,9 +66,10 @@ export declare function getDisclosures(partyId: string): Promise<DisclosuresResp
|
|
|
61
66
|
export declare function getDelegation(): Promise<DelegationResponse | ApiError>;
|
|
62
67
|
/**
|
|
63
68
|
* Create an order request (limit buy/sell) on the Temple trading backend.
|
|
64
|
-
* @param opts -
|
|
69
|
+
* @param opts - Single order or array of orders (max 20)
|
|
65
70
|
*/
|
|
66
71
|
export declare function createOrderRequest(opts: CreateOrderRequestOpts): Promise<CreateOrderRequestResponse | ApiError>;
|
|
72
|
+
export declare function createOrderRequest(opts: CreateOrderRequestOpts[]): Promise<BatchCreateOrderRequestResponse | ApiError>;
|
|
67
73
|
/**
|
|
68
74
|
* Create a withdrawal request.
|
|
69
75
|
* @param assetId - Instrument symbol (e.g. "USDCx", "Amulet")
|
package/dist/api/index.js
CHANGED
|
@@ -154,15 +154,20 @@ export async function getActiveOrders(options = {}) {
|
|
|
154
154
|
limit: options.limit,
|
|
155
155
|
});
|
|
156
156
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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) {
|
|
163
168
|
return { error: true, status: null, code: "INVALID_PARAMS", message: "Order ID is required." };
|
|
164
169
|
}
|
|
165
|
-
return authenticatedPost(
|
|
170
|
+
return authenticatedPost("/api/trading/orders/cancel", { order_id: orderIdOrIds });
|
|
166
171
|
}
|
|
167
172
|
/**
|
|
168
173
|
* Cancel all active orders, optionally filtered by symbol.
|
|
@@ -190,12 +195,23 @@ export async function getDisclosures(partyId) {
|
|
|
190
195
|
export async function getDelegation() {
|
|
191
196
|
return authenticatedGet("/api/trading/delegation");
|
|
192
197
|
}
|
|
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
|
+
}
|
|
199
215
|
const { symbol: rawSymbol, side, quantity, price, order_type = "limit", expires_at } = opts || {};
|
|
200
216
|
if (!rawSymbol || !side || quantity == null || price == null) {
|
|
201
217
|
return { error: true, status: null, code: "INVALID_PARAMS", message: "symbol, side, quantity, and price are required." };
|
package/dist/api/types.d.ts
CHANGED
|
@@ -72,6 +72,13 @@ 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
|
+
}
|
|
75
82
|
export interface CancelAllOrdersOptions {
|
|
76
83
|
symbol?: string;
|
|
77
84
|
}
|
|
@@ -98,6 +105,12 @@ export interface CreateOrderRequestOpts {
|
|
|
98
105
|
order_type?: string;
|
|
99
106
|
expires_at?: string;
|
|
100
107
|
}
|
|
108
|
+
export interface BatchCreateOrderRequestResponse {
|
|
109
|
+
success: boolean;
|
|
110
|
+
request_ids: number[];
|
|
111
|
+
count: number;
|
|
112
|
+
message: string;
|
|
113
|
+
}
|
|
101
114
|
export interface CreateOrderRequestResponse {
|
|
102
115
|
[key: string]: unknown;
|
|
103
116
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export interface DepositFundsOpts {
|
|
2
|
+
sender: string;
|
|
3
|
+
receiver?: string;
|
|
4
|
+
assetId: string;
|
|
5
|
+
amount: string | number;
|
|
6
|
+
holdingCids?: string[];
|
|
7
|
+
settlementId?: string;
|
|
8
|
+
transferLegId?: string;
|
|
9
|
+
allocateBefore?: string;
|
|
10
|
+
settleBefore?: string;
|
|
11
|
+
disclosures?: Record<string, unknown>;
|
|
12
|
+
userId?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface PreparedDeposit {
|
|
15
|
+
sender: string;
|
|
16
|
+
receiver: string;
|
|
17
|
+
assetId: string;
|
|
18
|
+
amount: string;
|
|
19
|
+
holdingCids: string[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Prepare holdings for a deposit by selecting UTXOs from the wallet provider.
|
|
23
|
+
*
|
|
24
|
+
* Queries the provider for holdings, filters and sorts them, then greedily
|
|
25
|
+
* selects until the requested amount is covered.
|
|
26
|
+
*/
|
|
27
|
+
export declare function prepareDepositHoldings(amount: number | string, symbol: string): Promise<PreparedDeposit | {
|
|
28
|
+
error: string;
|
|
29
|
+
data?: Record<string, unknown>;
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* High-level deposit helper.
|
|
33
|
+
*
|
|
34
|
+
* Wraps `prepareDepositHoldings` and `depositFunds` into a single call.
|
|
35
|
+
* Validates the user has sufficient balance and reserves 10 CC for transaction fees.
|
|
36
|
+
*
|
|
37
|
+
* Requires:
|
|
38
|
+
* - Wallet adapter (for reading balances and submitting)
|
|
39
|
+
* - API connection (for disclosures on Amulet deposits)
|
|
40
|
+
*/
|
|
41
|
+
export declare function deposit(amount: number | string, symbol: string): Promise<Record<string, unknown>>;
|
|
42
|
+
/**
|
|
43
|
+
* Create a CIP-56 Allocation.
|
|
44
|
+
* Fetches the AllocationFactory, then exercises AllocationFactory_Allocate
|
|
45
|
+
* to lock holdings for a settlement leg.
|
|
46
|
+
*
|
|
47
|
+
* Three resolution paths:
|
|
48
|
+
* 1. Localhost: resolve factory and context from ledger directly
|
|
49
|
+
* 2. Amulet via disclosures (FE/proxy path — no Scan API access)
|
|
50
|
+
* 3. Remote: Scan API / Registry API
|
|
51
|
+
*/
|
|
52
|
+
export declare function depositFunds(opts: DepositFundsOpts, returnCommand?: boolean): Promise<Record<string, unknown>>;
|