@temple-digital-group/temple-canton-js 1.0.38-beta → 1.0.39-beta.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/dist/api/index.d.ts +29 -2
- package/dist/api/index.js +66 -7
- package/dist/api/types.d.ts +55 -1
- package/package.json +1 -1
- package/src/api/index.ts +88 -7
- package/src/api/types.ts +75 -1
- package/src/canton/index.js +1477 -1281
- package/src/config/index.js +23 -0
package/dist/api/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ApiError, LoginUser, LoginResponse, RefreshResponse, Ticker, OrderBook, OrderBookOptions, SymbolConfig, OpenInterest, Trade, RecentTradesOptions, ActiveOrder, ActiveOrdersOptions, CancelOrderResponse, CancelAllOrdersOptions, CancelAllOrdersResponse, DisclosuresResponse } from "./types.js";
|
|
2
|
-
export type { ApiError, LoginUser, LoginResponse, RefreshResponse, Ticker, OrderBook, OrderBookOptions, SymbolConfig, OpenInterest, Trade, RecentTradesOptions, ActiveOrder, ActiveOrdersOptions, CancelOrderResponse, CancelAllOrdersOptions, CancelAllOrdersResponse, DisclosuresResponse, };
|
|
1
|
+
import type { ApiError, LoginUser, LoginResponse, RefreshResponse, 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, LoginUser, LoginResponse, RefreshResponse, Ticker, OrderBook, OrderBookOptions, SymbolConfig, OpenInterest, Trade, RecentTradesOptions, ActiveOrder, ActiveOrdersOptions, CancelOrderResponse, CancelAllOrdersOptions, CancelAllOrdersResponse, CreateOrderRequestResponse, DelegationResponse, WithdrawalResponse, WithdrawalStatusResponse, TradingBalanceResponse, AmuletDisclosure, DisclosuresResponse, };
|
|
3
3
|
export { setApiKey, getUserId } from "./tokenStore.js";
|
|
4
4
|
export { setWalletAdapter } from "../../src/config/index.js";
|
|
5
5
|
/**
|
|
@@ -75,3 +75,30 @@ export declare function cancelAllOrders(options?: CancelAllOrdersOptions): Promi
|
|
|
75
75
|
* @param partyId - Canton party ID
|
|
76
76
|
*/
|
|
77
77
|
export declare function getDisclosures(partyId: string): Promise<DisclosuresResponse | ApiError>;
|
|
78
|
+
/**
|
|
79
|
+
* Get the user's trading delegation status.
|
|
80
|
+
* The user ID is extracted from the JWT token automatically.
|
|
81
|
+
*/
|
|
82
|
+
export declare function getDelegation(): Promise<DelegationResponse | ApiError>;
|
|
83
|
+
/**
|
|
84
|
+
* Create an order request (limit buy/sell) on the Temple trading backend.
|
|
85
|
+
* @param opts - Order parameters: symbol, side, quantity, price, order_type, expires_at
|
|
86
|
+
*/
|
|
87
|
+
export declare function createOrderRequest(opts: CreateOrderRequestOpts): Promise<CreateOrderRequestResponse | ApiError>;
|
|
88
|
+
/**
|
|
89
|
+
* Create a withdrawal request.
|
|
90
|
+
* @param assetId - Instrument symbol (e.g. "USDCx", "Amulet")
|
|
91
|
+
* @param amount - Amount to withdraw
|
|
92
|
+
*/
|
|
93
|
+
export declare function createWithdrawalRequest(assetId: string, amount: string | number): Promise<WithdrawalResponse | ApiError>;
|
|
94
|
+
/**
|
|
95
|
+
* Get the status of a withdrawal request.
|
|
96
|
+
* @param requestId - The request ID returned by createWithdrawalRequest
|
|
97
|
+
*/
|
|
98
|
+
export declare function getWithdrawalRequestStatus(requestId: string | number): Promise<WithdrawalStatusResponse | ApiError>;
|
|
99
|
+
/**
|
|
100
|
+
* Get the user's trading balances.
|
|
101
|
+
*
|
|
102
|
+
* GET /api/trading/balances
|
|
103
|
+
*/
|
|
104
|
+
export declare function getTradingBalance(): Promise<TradingBalanceResponse | ApiError>;
|
package/dist/api/index.js
CHANGED
|
@@ -176,13 +176,18 @@ export async function refreshAccessToken(refreshTokenOverride) {
|
|
|
176
176
|
export function logout() {
|
|
177
177
|
clearTokens();
|
|
178
178
|
}
|
|
179
|
+
// ── Helpers ──
|
|
180
|
+
/** Normalize CC → Amulet in symbol strings (e.g. "CC/SBC" → "Amulet/SBC", "CC" → "Amulet") */
|
|
181
|
+
function normalizeSymbol(symbol) {
|
|
182
|
+
return symbol.replace(/\bCC\b/g, "Amulet");
|
|
183
|
+
}
|
|
179
184
|
// ── Market Data ──
|
|
180
185
|
/**
|
|
181
186
|
* Get ticker data for one or all trading pairs.
|
|
182
187
|
* @param symbol - Optional symbol filter (e.g., "Amulet/USDCx")
|
|
183
188
|
*/
|
|
184
189
|
export async function getTicker(symbol) {
|
|
185
|
-
return authenticatedGet("/api/v1/market/ticker", { symbol });
|
|
190
|
+
return authenticatedGet("/api/v1/market/ticker", { symbol: symbol ? normalizeSymbol(symbol) : undefined });
|
|
186
191
|
}
|
|
187
192
|
/**
|
|
188
193
|
* Get the order book for a trading pair.
|
|
@@ -194,7 +199,7 @@ export async function getOrderBook(symbol, options = {}) {
|
|
|
194
199
|
return { error: true, status: null, code: "INVALID_PARAMS", message: "Symbol is required." };
|
|
195
200
|
}
|
|
196
201
|
return authenticatedGet("/api/v1/market/orderbook", {
|
|
197
|
-
symbol,
|
|
202
|
+
symbol: normalizeSymbol(symbol),
|
|
198
203
|
levels: options.levels,
|
|
199
204
|
precision: options.precision,
|
|
200
205
|
});
|
|
@@ -207,7 +212,7 @@ export async function getSymbolConfig(symbol) {
|
|
|
207
212
|
if (!symbol) {
|
|
208
213
|
return { error: true, status: null, code: "INVALID_PARAMS", message: "Symbol is required." };
|
|
209
214
|
}
|
|
210
|
-
return authenticatedGet("/api/v1/trading/symbol-config", { symbol });
|
|
215
|
+
return authenticatedGet("/api/v1/trading/symbol-config", { symbol: normalizeSymbol(symbol) });
|
|
211
216
|
}
|
|
212
217
|
/**
|
|
213
218
|
* Get open interest for a trading pair.
|
|
@@ -217,7 +222,7 @@ export async function getOpenInterest(symbol) {
|
|
|
217
222
|
if (!symbol) {
|
|
218
223
|
return { error: true, status: null, code: "INVALID_PARAMS", message: "Symbol is required." };
|
|
219
224
|
}
|
|
220
|
-
return authenticatedGet("/api/v1/market/open-interest", { symbol });
|
|
225
|
+
return authenticatedGet("/api/v1/market/open-interest", { symbol: normalizeSymbol(symbol) });
|
|
221
226
|
}
|
|
222
227
|
/**
|
|
223
228
|
* Get recent trades for a trading pair.
|
|
@@ -229,7 +234,7 @@ export async function getRecentTrades(symbol, options = {}) {
|
|
|
229
234
|
return { error: true, status: null, code: "INVALID_PARAMS", message: "Symbol is required." };
|
|
230
235
|
}
|
|
231
236
|
return authenticatedGet("/api/v1/market/trades", {
|
|
232
|
-
symbol,
|
|
237
|
+
symbol: normalizeSymbol(symbol),
|
|
233
238
|
limit: options.limit,
|
|
234
239
|
});
|
|
235
240
|
}
|
|
@@ -240,7 +245,7 @@ export async function getRecentTrades(symbol, options = {}) {
|
|
|
240
245
|
*/
|
|
241
246
|
export async function getActiveOrders(options = {}) {
|
|
242
247
|
return authenticatedGet("/api/trading/orders/active", {
|
|
243
|
-
symbol: options.symbol,
|
|
248
|
+
symbol: options.symbol ? normalizeSymbol(options.symbol) : undefined,
|
|
244
249
|
limit: options.limit,
|
|
245
250
|
});
|
|
246
251
|
}
|
|
@@ -259,7 +264,7 @@ export async function cancelOrder(orderId) {
|
|
|
259
264
|
* @param options - Optional symbol filter
|
|
260
265
|
*/
|
|
261
266
|
export async function cancelAllOrders(options = {}) {
|
|
262
|
-
return authenticatedPost("/api/
|
|
267
|
+
return authenticatedPost("/api/trading/orders/cancel-all", options.symbol ? { symbol: normalizeSymbol(options.symbol) } : undefined);
|
|
263
268
|
}
|
|
264
269
|
// ── Disclosures ──
|
|
265
270
|
/**
|
|
@@ -273,3 +278,57 @@ export async function getDisclosures(partyId) {
|
|
|
273
278
|
}
|
|
274
279
|
return authenticatedGet("/api/amulet/disclosures", { partyId });
|
|
275
280
|
}
|
|
281
|
+
// ── Delegation ──
|
|
282
|
+
/**
|
|
283
|
+
* Get the user's trading delegation status.
|
|
284
|
+
* The user ID is extracted from the JWT token automatically.
|
|
285
|
+
*/
|
|
286
|
+
export async function getDelegation() {
|
|
287
|
+
return authenticatedGet("/api/trading/delegation");
|
|
288
|
+
}
|
|
289
|
+
// ── Order Requests ──
|
|
290
|
+
/**
|
|
291
|
+
* Create an order request (limit buy/sell) on the Temple trading backend.
|
|
292
|
+
* @param opts - Order parameters: symbol, side, quantity, price, order_type, expires_at
|
|
293
|
+
*/
|
|
294
|
+
export async function createOrderRequest(opts) {
|
|
295
|
+
const { symbol: rawSymbol, side, quantity, price, order_type = "limit", expires_at } = opts || {};
|
|
296
|
+
if (!rawSymbol || !side || quantity == null || price == null) {
|
|
297
|
+
return { error: true, status: null, code: "INVALID_PARAMS", message: "symbol, side, quantity, and price are required." };
|
|
298
|
+
}
|
|
299
|
+
const symbol = normalizeSymbol(rawSymbol);
|
|
300
|
+
const body = { symbol, side, quantity: Number(quantity), price: Number(price), order_type };
|
|
301
|
+
if (expires_at)
|
|
302
|
+
body.expires_at = expires_at;
|
|
303
|
+
return authenticatedPost("/api/trading/orders", body);
|
|
304
|
+
}
|
|
305
|
+
// ── Withdrawals ──
|
|
306
|
+
/**
|
|
307
|
+
* Create a withdrawal request.
|
|
308
|
+
* @param assetId - Instrument symbol (e.g. "USDCx", "Amulet")
|
|
309
|
+
* @param amount - Amount to withdraw
|
|
310
|
+
*/
|
|
311
|
+
export async function createWithdrawalRequest(assetId, amount) {
|
|
312
|
+
if (!assetId || amount == null) {
|
|
313
|
+
return { error: true, status: null, code: "INVALID_PARAMS", message: "asset_id and amount are required." };
|
|
314
|
+
}
|
|
315
|
+
return authenticatedPost("/api/trading/withdrawals", { asset_id: normalizeSymbol(assetId), amount: String(amount) });
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Get the status of a withdrawal request.
|
|
319
|
+
* @param requestId - The request ID returned by createWithdrawalRequest
|
|
320
|
+
*/
|
|
321
|
+
export async function getWithdrawalRequestStatus(requestId) {
|
|
322
|
+
if (requestId == null) {
|
|
323
|
+
return { error: true, status: null, code: "INVALID_PARAMS", message: "requestId is required." };
|
|
324
|
+
}
|
|
325
|
+
return authenticatedGet(`/api/trading/withdrawals/${encodeURIComponent(requestId)}`);
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Get the user's trading balances.
|
|
329
|
+
*
|
|
330
|
+
* GET /api/trading/balances
|
|
331
|
+
*/
|
|
332
|
+
export async function getTradingBalance() {
|
|
333
|
+
return authenticatedGet("/api/trading/balances");
|
|
334
|
+
}
|
package/dist/api/types.d.ts
CHANGED
|
@@ -98,8 +98,62 @@ export interface CancelAllOrdersResponse {
|
|
|
98
98
|
already_queued_count: number;
|
|
99
99
|
order_ids: string[];
|
|
100
100
|
}
|
|
101
|
+
export interface Delegation {
|
|
102
|
+
user_id: number;
|
|
103
|
+
delegation_cid: string;
|
|
104
|
+
created_at: string;
|
|
105
|
+
updated_at: string;
|
|
106
|
+
}
|
|
107
|
+
export interface DelegationResponse {
|
|
108
|
+
delegation: Delegation;
|
|
109
|
+
}
|
|
110
|
+
export interface CreateOrderRequestOpts {
|
|
111
|
+
symbol: string;
|
|
112
|
+
side: string;
|
|
113
|
+
quantity: number;
|
|
114
|
+
price: number;
|
|
115
|
+
order_type?: string;
|
|
116
|
+
expires_at?: string;
|
|
117
|
+
}
|
|
118
|
+
export interface CreateOrderRequestResponse {
|
|
119
|
+
[key: string]: unknown;
|
|
120
|
+
}
|
|
121
|
+
export interface WithdrawalRequest {
|
|
122
|
+
asset_id: string;
|
|
123
|
+
amount: string;
|
|
124
|
+
}
|
|
125
|
+
export interface WithdrawalResponse {
|
|
126
|
+
[key: string]: unknown;
|
|
127
|
+
}
|
|
128
|
+
export interface WithdrawalStatusResponse {
|
|
129
|
+
[key: string]: unknown;
|
|
130
|
+
}
|
|
131
|
+
export interface TradingBalanceResponse {
|
|
132
|
+
[key: string]: unknown;
|
|
133
|
+
}
|
|
134
|
+
export interface AmuletDisclosure {
|
|
135
|
+
contractId: string;
|
|
136
|
+
createdEventBlob: string;
|
|
137
|
+
synchronizerId: string;
|
|
138
|
+
templateId: string;
|
|
139
|
+
}
|
|
140
|
+
export interface ChoiceContextValue {
|
|
141
|
+
tag: string;
|
|
142
|
+
value: string;
|
|
143
|
+
}
|
|
144
|
+
export interface ChoiceContext {
|
|
145
|
+
choiceContextData: {
|
|
146
|
+
values: Record<string, ChoiceContextValue>;
|
|
147
|
+
};
|
|
148
|
+
disclosedContracts: AmuletDisclosure[];
|
|
149
|
+
}
|
|
150
|
+
export interface DisclosuresData {
|
|
151
|
+
choiceContext: ChoiceContext;
|
|
152
|
+
factoryId: string;
|
|
153
|
+
transferKind: string;
|
|
154
|
+
}
|
|
101
155
|
export interface DisclosuresResponse {
|
|
102
|
-
disclosures:
|
|
156
|
+
disclosures: DisclosuresData;
|
|
103
157
|
}
|
|
104
158
|
export interface ApiError {
|
|
105
159
|
error: true;
|
package/package.json
CHANGED
package/src/api/index.ts
CHANGED
|
@@ -27,6 +27,13 @@ import type {
|
|
|
27
27
|
CancelOrderResponse,
|
|
28
28
|
CancelAllOrdersOptions,
|
|
29
29
|
CancelAllOrdersResponse,
|
|
30
|
+
CreateOrderRequestOpts,
|
|
31
|
+
CreateOrderRequestResponse,
|
|
32
|
+
DelegationResponse,
|
|
33
|
+
WithdrawalResponse,
|
|
34
|
+
WithdrawalStatusResponse,
|
|
35
|
+
TradingBalanceResponse,
|
|
36
|
+
AmuletDisclosure,
|
|
30
37
|
DisclosuresResponse,
|
|
31
38
|
} from "./types.js";
|
|
32
39
|
|
|
@@ -48,6 +55,12 @@ export type {
|
|
|
48
55
|
CancelOrderResponse,
|
|
49
56
|
CancelAllOrdersOptions,
|
|
50
57
|
CancelAllOrdersResponse,
|
|
58
|
+
CreateOrderRequestResponse,
|
|
59
|
+
DelegationResponse,
|
|
60
|
+
WithdrawalResponse,
|
|
61
|
+
WithdrawalStatusResponse,
|
|
62
|
+
TradingBalanceResponse,
|
|
63
|
+
AmuletDisclosure,
|
|
51
64
|
DisclosuresResponse,
|
|
52
65
|
};
|
|
53
66
|
export { setApiKey, getUserId } from "./tokenStore.js";
|
|
@@ -245,6 +258,13 @@ export function logout(): void {
|
|
|
245
258
|
clearTokens();
|
|
246
259
|
}
|
|
247
260
|
|
|
261
|
+
// ── Helpers ──
|
|
262
|
+
|
|
263
|
+
/** Normalize CC → Amulet in symbol strings (e.g. "CC/SBC" → "Amulet/SBC", "CC" → "Amulet") */
|
|
264
|
+
function normalizeSymbol(symbol: string): string {
|
|
265
|
+
return symbol.replace(/\bCC\b/g, "Amulet");
|
|
266
|
+
}
|
|
267
|
+
|
|
248
268
|
// ── Market Data ──
|
|
249
269
|
|
|
250
270
|
/**
|
|
@@ -252,7 +272,7 @@ export function logout(): void {
|
|
|
252
272
|
* @param symbol - Optional symbol filter (e.g., "Amulet/USDCx")
|
|
253
273
|
*/
|
|
254
274
|
export async function getTicker(symbol?: string): Promise<Ticker | Ticker[] | ApiError> {
|
|
255
|
-
return authenticatedGet("/api/v1/market/ticker", { symbol });
|
|
275
|
+
return authenticatedGet("/api/v1/market/ticker", { symbol: symbol ? normalizeSymbol(symbol) : undefined });
|
|
256
276
|
}
|
|
257
277
|
|
|
258
278
|
/**
|
|
@@ -265,7 +285,7 @@ export async function getOrderBook(symbol: string, options: OrderBookOptions = {
|
|
|
265
285
|
return { error: true, status: null, code: "INVALID_PARAMS", message: "Symbol is required." };
|
|
266
286
|
}
|
|
267
287
|
return authenticatedGet("/api/v1/market/orderbook", {
|
|
268
|
-
symbol,
|
|
288
|
+
symbol: normalizeSymbol(symbol),
|
|
269
289
|
levels: options.levels,
|
|
270
290
|
precision: options.precision,
|
|
271
291
|
});
|
|
@@ -279,7 +299,7 @@ export async function getSymbolConfig(symbol: string): Promise<SymbolConfig | Ap
|
|
|
279
299
|
if (!symbol) {
|
|
280
300
|
return { error: true, status: null, code: "INVALID_PARAMS", message: "Symbol is required." };
|
|
281
301
|
}
|
|
282
|
-
return authenticatedGet("/api/v1/trading/symbol-config", { symbol });
|
|
302
|
+
return authenticatedGet("/api/v1/trading/symbol-config", { symbol: normalizeSymbol(symbol) });
|
|
283
303
|
}
|
|
284
304
|
|
|
285
305
|
/**
|
|
@@ -290,7 +310,7 @@ export async function getOpenInterest(symbol: string): Promise<OpenInterest | Ap
|
|
|
290
310
|
if (!symbol) {
|
|
291
311
|
return { error: true, status: null, code: "INVALID_PARAMS", message: "Symbol is required." };
|
|
292
312
|
}
|
|
293
|
-
return authenticatedGet("/api/v1/market/open-interest", { symbol });
|
|
313
|
+
return authenticatedGet("/api/v1/market/open-interest", { symbol: normalizeSymbol(symbol) });
|
|
294
314
|
}
|
|
295
315
|
|
|
296
316
|
/**
|
|
@@ -303,7 +323,7 @@ export async function getRecentTrades(symbol: string, options: RecentTradesOptio
|
|
|
303
323
|
return { error: true, status: null, code: "INVALID_PARAMS", message: "Symbol is required." };
|
|
304
324
|
}
|
|
305
325
|
return authenticatedGet("/api/v1/market/trades", {
|
|
306
|
-
symbol,
|
|
326
|
+
symbol: normalizeSymbol(symbol),
|
|
307
327
|
limit: options.limit,
|
|
308
328
|
});
|
|
309
329
|
}
|
|
@@ -316,7 +336,7 @@ export async function getRecentTrades(symbol: string, options: RecentTradesOptio
|
|
|
316
336
|
*/
|
|
317
337
|
export async function getActiveOrders(options: ActiveOrdersOptions = {}): Promise<ActiveOrder[] | ApiError> {
|
|
318
338
|
return authenticatedGet("/api/trading/orders/active", {
|
|
319
|
-
symbol: options.symbol,
|
|
339
|
+
symbol: options.symbol ? normalizeSymbol(options.symbol) : undefined,
|
|
320
340
|
limit: options.limit,
|
|
321
341
|
});
|
|
322
342
|
}
|
|
@@ -337,7 +357,7 @@ export async function cancelOrder(orderId: string): Promise<CancelOrderResponse
|
|
|
337
357
|
* @param options - Optional symbol filter
|
|
338
358
|
*/
|
|
339
359
|
export async function cancelAllOrders(options: CancelAllOrdersOptions = {}): Promise<CancelAllOrdersResponse | ApiError> {
|
|
340
|
-
return authenticatedPost("/api/
|
|
360
|
+
return authenticatedPost("/api/trading/orders/cancel-all", options.symbol ? { symbol: normalizeSymbol(options.symbol) } : undefined);
|
|
341
361
|
}
|
|
342
362
|
|
|
343
363
|
// ── Disclosures ──
|
|
@@ -353,3 +373,64 @@ export async function getDisclosures(partyId: string): Promise<DisclosuresRespon
|
|
|
353
373
|
}
|
|
354
374
|
return authenticatedGet("/api/amulet/disclosures", { partyId });
|
|
355
375
|
}
|
|
376
|
+
|
|
377
|
+
// ── Delegation ──
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Get the user's trading delegation status.
|
|
381
|
+
* The user ID is extracted from the JWT token automatically.
|
|
382
|
+
*/
|
|
383
|
+
export async function getDelegation(): Promise<DelegationResponse | ApiError> {
|
|
384
|
+
return authenticatedGet("/api/trading/delegation");
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// ── Order Requests ──
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Create an order request (limit buy/sell) on the Temple trading backend.
|
|
391
|
+
* @param opts - Order parameters: symbol, side, quantity, price, order_type, expires_at
|
|
392
|
+
*/
|
|
393
|
+
export async function createOrderRequest(opts: CreateOrderRequestOpts): Promise<CreateOrderRequestResponse | ApiError> {
|
|
394
|
+
const { symbol: rawSymbol, side, quantity, price, order_type = "limit", expires_at } = opts || {};
|
|
395
|
+
if (!rawSymbol || !side || quantity == null || price == null) {
|
|
396
|
+
return { error: true, status: null, code: "INVALID_PARAMS", message: "symbol, side, quantity, and price are required." };
|
|
397
|
+
}
|
|
398
|
+
const symbol = normalizeSymbol(rawSymbol);
|
|
399
|
+
const body: Record<string, unknown> = { symbol, side, quantity: Number(quantity), price: Number(price), order_type };
|
|
400
|
+
if (expires_at) body.expires_at = expires_at;
|
|
401
|
+
return authenticatedPost("/api/trading/orders", body);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// ── Withdrawals ──
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Create a withdrawal request.
|
|
408
|
+
* @param assetId - Instrument symbol (e.g. "USDCx", "Amulet")
|
|
409
|
+
* @param amount - Amount to withdraw
|
|
410
|
+
*/
|
|
411
|
+
export async function createWithdrawalRequest(assetId: string, amount: string | number): Promise<WithdrawalResponse | ApiError> {
|
|
412
|
+
if (!assetId || amount == null) {
|
|
413
|
+
return { error: true, status: null, code: "INVALID_PARAMS", message: "asset_id and amount are required." };
|
|
414
|
+
}
|
|
415
|
+
return authenticatedPost("/api/trading/withdrawals", { asset_id: normalizeSymbol(assetId), amount: String(amount) });
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Get the status of a withdrawal request.
|
|
420
|
+
* @param requestId - The request ID returned by createWithdrawalRequest
|
|
421
|
+
*/
|
|
422
|
+
export async function getWithdrawalRequestStatus(requestId: string | number): Promise<WithdrawalStatusResponse | ApiError> {
|
|
423
|
+
if (requestId == null) {
|
|
424
|
+
return { error: true, status: null, code: "INVALID_PARAMS", message: "requestId is required." };
|
|
425
|
+
}
|
|
426
|
+
return authenticatedGet(`/api/trading/withdrawals/${encodeURIComponent(requestId)}`);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Get the user's trading balances.
|
|
431
|
+
*
|
|
432
|
+
* GET /api/trading/balances
|
|
433
|
+
*/
|
|
434
|
+
export async function getTradingBalance(): Promise<TradingBalanceResponse | ApiError> {
|
|
435
|
+
return authenticatedGet("/api/trading/balances");
|
|
436
|
+
}
|
package/src/api/types.ts
CHANGED
|
@@ -120,10 +120,84 @@ export interface CancelAllOrdersResponse {
|
|
|
120
120
|
order_ids: string[];
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
// ── Delegation ──
|
|
124
|
+
|
|
125
|
+
export interface Delegation {
|
|
126
|
+
user_id: number;
|
|
127
|
+
delegation_cid: string;
|
|
128
|
+
created_at: string;
|
|
129
|
+
updated_at: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface DelegationResponse {
|
|
133
|
+
delegation: Delegation;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// ── Order Requests ──
|
|
137
|
+
|
|
138
|
+
export interface CreateOrderRequestOpts {
|
|
139
|
+
symbol: string;
|
|
140
|
+
side: string;
|
|
141
|
+
quantity: number;
|
|
142
|
+
price: number;
|
|
143
|
+
order_type?: string;
|
|
144
|
+
expires_at?: string;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface CreateOrderRequestResponse {
|
|
148
|
+
[key: string]: unknown;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// ── Withdrawals ──
|
|
152
|
+
|
|
153
|
+
export interface WithdrawalRequest {
|
|
154
|
+
asset_id: string;
|
|
155
|
+
amount: string;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export interface WithdrawalResponse {
|
|
159
|
+
[key: string]: unknown;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface WithdrawalStatusResponse {
|
|
163
|
+
[key: string]: unknown;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// ── Trading Balances ──
|
|
167
|
+
|
|
168
|
+
export interface TradingBalanceResponse {
|
|
169
|
+
[key: string]: unknown;
|
|
170
|
+
}
|
|
171
|
+
|
|
123
172
|
// ── Disclosures ──
|
|
124
173
|
|
|
174
|
+
export interface AmuletDisclosure {
|
|
175
|
+
contractId: string;
|
|
176
|
+
createdEventBlob: string;
|
|
177
|
+
synchronizerId: string;
|
|
178
|
+
templateId: string;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export interface ChoiceContextValue {
|
|
182
|
+
tag: string;
|
|
183
|
+
value: string;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export interface ChoiceContext {
|
|
187
|
+
choiceContextData: {
|
|
188
|
+
values: Record<string, ChoiceContextValue>;
|
|
189
|
+
};
|
|
190
|
+
disclosedContracts: AmuletDisclosure[];
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export interface DisclosuresData {
|
|
194
|
+
choiceContext: ChoiceContext;
|
|
195
|
+
factoryId: string;
|
|
196
|
+
transferKind: string;
|
|
197
|
+
}
|
|
198
|
+
|
|
125
199
|
export interface DisclosuresResponse {
|
|
126
|
-
disclosures:
|
|
200
|
+
disclosures: DisclosuresData;
|
|
127
201
|
}
|
|
128
202
|
|
|
129
203
|
// ── Errors ──
|