@cexyio/cexy 0.1.0-dev.5 → 0.1.0-dev.7
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 +34 -3
- package/dist/index.cjs +76 -12
- package/dist/index.d.cts +234 -19
- package/dist/index.d.ts +234 -19
- package/dist/index.js +76 -13
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -54,6 +54,11 @@ declare class RateLimiter {
|
|
|
54
54
|
get state(): RateLimiterState;
|
|
55
55
|
/** Waits until a request may be sent, then takes a token. */
|
|
56
56
|
acquire(signal?: AbortSignal): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* How long `acquire()` would wait right now, in ms (0 when a request may go at once). Lets a
|
|
59
|
+
* caller with a time budget, such as the cancelAll untilDone loop, count the limiter's wait.
|
|
60
|
+
*/
|
|
61
|
+
pendingWaitMs(): number;
|
|
57
62
|
/** Adapts to the server's rate-limit headers. Never raises the configured limit. */
|
|
58
63
|
update(headers: Headers): void;
|
|
59
64
|
/**
|
|
@@ -97,6 +102,7 @@ declare const OPERATIONS: {
|
|
|
97
102
|
readonly get_ledger: OperationInfo;
|
|
98
103
|
readonly list_notifications: OperationInfo;
|
|
99
104
|
readonly list_sub_accounts: OperationInfo;
|
|
105
|
+
readonly sub_account_balances: OperationInfo;
|
|
100
106
|
readonly list_api_keys: OperationInfo;
|
|
101
107
|
readonly export_deposits: OperationInfo;
|
|
102
108
|
readonly export_ledger: OperationInfo;
|
|
@@ -184,8 +190,8 @@ declare class Transport {
|
|
|
184
190
|
* Sends a request with the standard retry policy: retryable errors and network failures are
|
|
185
191
|
* retried. Pool join/exit carry an `Idempotency-Key` reused on every attempt (the server
|
|
186
192
|
* honours it there, which makes their retries safe); the other mutations routed here
|
|
187
|
-
* (cancel-all) are naturally repeatable and send no key.
|
|
188
|
-
* `attempt()` with their own policies.
|
|
193
|
+
* (cancel-all) are naturally repeatable and send no key. Any other mutation is sent once.
|
|
194
|
+
* `placeOrder` and `cancelOrder` use `attempt()` with their own policies.
|
|
189
195
|
*/
|
|
190
196
|
request(spec: CallSpec, opts?: RequestOptions): Promise<RawResponse>;
|
|
191
197
|
/**
|
|
@@ -200,7 +206,11 @@ declare class Transport {
|
|
|
200
206
|
buildUrl(info: OperationInfo, pathParams?: Record<string, string>, query?: Record<string, unknown>): URL;
|
|
201
207
|
redact(text: string): string;
|
|
202
208
|
}
|
|
203
|
-
/**
|
|
209
|
+
/**
|
|
210
|
+
* Retryable = a network failure/timeout, or an API error with `retryable: true` (incl. 409
|
|
211
|
+
* CONCURRENT_MODIFICATION). A 4xx is never retryable except 429 and 409 CONCURRENT_MODIFICATION,
|
|
212
|
+
* whatever its body says.
|
|
213
|
+
*/
|
|
204
214
|
declare function isRetryable(err: unknown): boolean;
|
|
205
215
|
|
|
206
216
|
interface paths {
|
|
@@ -309,6 +319,26 @@ interface paths {
|
|
|
309
319
|
patch?: never;
|
|
310
320
|
trace?: never;
|
|
311
321
|
};
|
|
322
|
+
"/api/v1/account/sub-accounts/{id}/balances": {
|
|
323
|
+
parameters: {
|
|
324
|
+
query?: never;
|
|
325
|
+
header?: never;
|
|
326
|
+
path?: never;
|
|
327
|
+
cookie?: never;
|
|
328
|
+
};
|
|
329
|
+
/**
|
|
330
|
+
* A sub-account's balances, for its parent.
|
|
331
|
+
* @description The same shape as `/account/balances`, zero balances omitted: what the sub-account holds, so its funds can be shown and moved back. Only the parent may read it; any id that is not one of the caller's sub-accounts is not found.
|
|
332
|
+
*/
|
|
333
|
+
get: operations["sub_account_balances"];
|
|
334
|
+
put?: never;
|
|
335
|
+
post?: never;
|
|
336
|
+
delete?: never;
|
|
337
|
+
options?: never;
|
|
338
|
+
head?: never;
|
|
339
|
+
patch?: never;
|
|
340
|
+
trace?: never;
|
|
341
|
+
};
|
|
312
342
|
"/api/v1/assets": {
|
|
313
343
|
parameters: {
|
|
314
344
|
query?: never;
|
|
@@ -731,8 +761,10 @@ interface paths {
|
|
|
731
761
|
get?: never;
|
|
732
762
|
put?: never;
|
|
733
763
|
/**
|
|
734
|
-
* Cancels every open order, optionally within
|
|
735
|
-
* @description
|
|
764
|
+
* Cancels every open order, and every stop order that has not triggered, optionally within
|
|
765
|
+
* @description one market.
|
|
766
|
+
*
|
|
767
|
+
* Best-effort: a failure on one order does not stop the rest, and every outcome is reported. A panic-button endpoint that stops at the first problem is worse than useless. A stop waiting for its trigger (`pending_trigger`) is cancelled too and its reservation released, so nothing fires into the market after the call.
|
|
736
768
|
*
|
|
737
769
|
* An order still being placed when the call starts (status `pending`, for as long as its own placement request runs) is waited for, up to 500 ms per call in total: cancelled if it opens, reported in `already_closed` if it fills or is refused, and in `failed` with code `INVALID_STATE` if it is still being placed at the deadline. Orders placed after the call starts are not part of it. At most 500 orders per call; `has_more` says there are others.
|
|
738
770
|
*
|
|
@@ -1034,6 +1066,8 @@ interface components {
|
|
|
1034
1066
|
/** @description Asset symbol. */
|
|
1035
1067
|
asset: string;
|
|
1036
1068
|
available: components["schemas"]["Amount"];
|
|
1069
|
+
/** @description Internal transfers to this account still held, soonest released first; empty when none. Their sum is part of `locked`. Shows at most 100. */
|
|
1070
|
+
held_incoming: components["schemas"]["HeldIncomingResponse"][];
|
|
1037
1071
|
locked: components["schemas"]["Amount"];
|
|
1038
1072
|
pending: components["schemas"]["Amount"];
|
|
1039
1073
|
total: components["schemas"]["Amount"];
|
|
@@ -1117,6 +1151,11 @@ interface components {
|
|
|
1117
1151
|
/** @description Network code. */
|
|
1118
1152
|
network: string;
|
|
1119
1153
|
};
|
|
1154
|
+
/**
|
|
1155
|
+
* @description Unique identifier of a deposit.
|
|
1156
|
+
* @example 507f1f77bcf86cd799439011
|
|
1157
|
+
*/
|
|
1158
|
+
DepositId: string;
|
|
1120
1159
|
/** @description A deposit. */
|
|
1121
1160
|
DepositResponse: {
|
|
1122
1161
|
/** @description Address that received it. */
|
|
@@ -1198,7 +1237,7 @@ interface components {
|
|
|
1198
1237
|
* Serialized as `SCREAMING_SNAKE_CASE`. Adding a variant is backwards-compatible; renaming or removing one is a breaking API change.
|
|
1199
1238
|
* @enum {string}
|
|
1200
1239
|
*/
|
|
1201
|
-
ErrorCode: "VALIDATION_FAILED" | "MALFORMED_REQUEST" | "INVALID_CURSOR" | "PRECISION_EXCEEDED" | "BELOW_MINIMUM" | "ABOVE_MAXIMUM" | "INVALID_ADDRESS" | "MEMO_REQUIRED" | "UNAUTHENTICATED" | "INVALID_CREDENTIALS" | "TOKEN_EXPIRED" | "SESSION_REVOKED" | "TWO_FACTOR_REQUIRED" | "TWO_FACTOR_INVALID" | "FRESH_TWO_FACTOR_REQUIRED" | "FORBIDDEN" | "API_KEY_NOT_ALLOWED" | "FUTURES_RESTRICTED" | "ACCOUNT_FROZEN" | "ACCOUNT_ON_HOLD" | "EMAIL_NOT_VERIFIED" | "REGION_BLOCKED" | "JURISDICTION_BLOCKED" | "NOT_FOUND" | "METHOD_NOT_ALLOWED" | "ALREADY_EXISTS" | "INVALID_STATE" | "IDEMPOTENCY_KEY_CONFLICT" | "WINDOW_OPEN" | "EVIDENCE_CONTRADICTS" | "AMOUNT_MISMATCH" | "CONCURRENT_MODIFICATION" | "INSUFFICIENT_FUNDS" | "INSUFFICIENT_FEE_FUNDS" | "MARKET_UNAVAILABLE" | "DEPOSIT_DISABLED" | "WITHDRAWAL_DISABLED" | "SELF_TRADE_BLOCKED" | "LIMIT_EXCEEDED" | "RATE_LIMITED" | "INTERNAL" | "SERVICE_UNAVAILABLE" | "UNDER_MAINTENANCE" | "ENGINE_OVERLOADED";
|
|
1240
|
+
ErrorCode: "VALIDATION_FAILED" | "MALFORMED_REQUEST" | "INVALID_CURSOR" | "PRECISION_EXCEEDED" | "BELOW_MINIMUM" | "ABOVE_MAXIMUM" | "INVALID_ADDRESS" | "MEMO_REQUIRED" | "UNAUTHENTICATED" | "INVALID_CREDENTIALS" | "TOKEN_EXPIRED" | "SESSION_REVOKED" | "TWO_FACTOR_REQUIRED" | "TWO_FACTOR_INVALID" | "FRESH_TWO_FACTOR_REQUIRED" | "FORBIDDEN" | "API_KEY_NOT_ALLOWED" | "FUTURES_RESTRICTED" | "ACCOUNT_FROZEN" | "ACCOUNT_ON_HOLD" | "EMAIL_NOT_VERIFIED" | "REGION_BLOCKED" | "JURISDICTION_BLOCKED" | "NOT_FOUND" | "METHOD_NOT_ALLOWED" | "ALREADY_EXISTS" | "INVALID_STATE" | "IDEMPOTENCY_KEY_CONFLICT" | "WINDOW_OPEN" | "EVIDENCE_CONTRADICTS" | "AMOUNT_MISMATCH" | "CONCURRENT_MODIFICATION" | "INSUFFICIENT_FUNDS" | "INSUFFICIENT_FEE_FUNDS" | "MARKET_UNAVAILABLE" | "DEPOSIT_DISABLED" | "WITHDRAWAL_DISABLED" | "SELF_TRADE_BLOCKED" | "LIMIT_EXCEEDED" | "PRICE_UNAVAILABLE" | "RATE_LIMITED" | "INTERNAL" | "SERVICE_UNAVAILABLE" | "UNDER_MAINTENANCE" | "ENGINE_OVERLOADED";
|
|
1202
1241
|
/** @description The top-level error envelope. */
|
|
1203
1242
|
ErrorResponse: {
|
|
1204
1243
|
error: components["schemas"]["ErrorBody"];
|
|
@@ -1309,14 +1348,26 @@ interface components {
|
|
|
1309
1348
|
/** @description Trade id. */
|
|
1310
1349
|
trade_id: string;
|
|
1311
1350
|
};
|
|
1351
|
+
/**
|
|
1352
|
+
* @description Unique identifier of a futures collateral transfer.
|
|
1353
|
+
* @example 507f1f77bcf86cd799439011
|
|
1354
|
+
*/
|
|
1355
|
+
FuturesTransferId: string;
|
|
1356
|
+
/** @description An internal transfer credited to `locked` and not yet available. */
|
|
1357
|
+
HeldIncomingResponse: {
|
|
1358
|
+
amount: components["schemas"]["Amount"];
|
|
1359
|
+
/**
|
|
1360
|
+
* Format: date-time
|
|
1361
|
+
* @description When it becomes available, unless an operator cancels it before then.
|
|
1362
|
+
*/
|
|
1363
|
+
available_at: string;
|
|
1364
|
+
/** @description The transfer. */
|
|
1365
|
+
transfer_id: string;
|
|
1366
|
+
};
|
|
1312
1367
|
/** @description Adds liquidity to a pool. */
|
|
1313
1368
|
JoinPoolRequest: {
|
|
1314
1369
|
base_amount: components["schemas"]["Amount"];
|
|
1315
|
-
|
|
1316
|
-
* @description How far, in percent, the offered ratio may sit from the pool's own before the request is refused rather than repriced. Defaults to 1%.
|
|
1317
|
-
* @example 1
|
|
1318
|
-
*/
|
|
1319
|
-
max_ratio_deviation_percent?: string | null;
|
|
1370
|
+
max_ratio_deviation_percent?: components["schemas"]["Amount"] | null;
|
|
1320
1371
|
quote_amount: components["schemas"]["Amount"];
|
|
1321
1372
|
};
|
|
1322
1373
|
/** @description What a join produced. */
|
|
@@ -1330,7 +1381,7 @@ interface components {
|
|
|
1330
1381
|
* @description What a ledger entry records.
|
|
1331
1382
|
* @enum {string}
|
|
1332
1383
|
*/
|
|
1333
|
-
LedgerEntryKind: "deposit" | "deposit_reversal" | "withdrawal_debit" | "withdrawal_fee" | "withdrawal_fee_reserve" | "withdrawal_release" | "withdrawal_fee_release" | "order_reserve" | "withdrawal_reserve" | "order_release" | "trade_debit" | "trade_credit" | "trade_fee" | "transfer_out" | "transfer_in" | "adjustment_credit" | "adjustment_debit" | "rebate" | "pool_join" | "pool_exit" | "futures_transfer_reserve" | "futures_transfer_release" | "futures_collateral_sent" | "futures_collateral_returned" | "trade_fee_revenue" | "withdrawal_fee_revenue" | "futures_transfer_fee_revenue" | "futures_hyperliquid_cost" | "futures_transfer_discrepancy" | "exchange_capital";
|
|
1384
|
+
LedgerEntryKind: "deposit" | "deposit_reversal" | "withdrawal_debit" | "withdrawal_fee" | "withdrawal_fee_reserve" | "withdrawal_release" | "withdrawal_fee_release" | "order_reserve" | "withdrawal_reserve" | "order_release" | "trade_debit" | "trade_credit" | "trade_fee" | "transfer_out" | "transfer_in" | "transfer_in_held" | "transfer_release" | "transfer_reversal" | "adjustment_credit" | "adjustment_debit" | "rebate" | "pool_join" | "pool_exit" | "futures_transfer_reserve" | "futures_transfer_release" | "futures_collateral_sent" | "futures_collateral_returned" | "trade_fee_revenue" | "withdrawal_fee_revenue" | "withdrawal_refund" | "withdrawal_fee_revenue_reversal" | "futures_transfer_fee_revenue" | "futures_hyperliquid_cost" | "futures_transfer_discrepancy" | "exchange_capital";
|
|
1334
1385
|
/** @description One entry from the account's ledger. */
|
|
1335
1386
|
LedgerEntryResponse: {
|
|
1336
1387
|
/** @description Asset symbol. */
|
|
@@ -1347,14 +1398,55 @@ interface components {
|
|
|
1347
1398
|
kind: components["schemas"]["LedgerEntryKind"];
|
|
1348
1399
|
locked_delta: components["schemas"]["Amount"];
|
|
1349
1400
|
pending_delta: components["schemas"]["Amount"];
|
|
1350
|
-
|
|
1351
|
-
reference: unknown;
|
|
1401
|
+
reference: components["schemas"]["LedgerReference"];
|
|
1352
1402
|
/**
|
|
1353
1403
|
* Format: int64
|
|
1354
1404
|
* @description Position in this account's history for this asset.
|
|
1355
1405
|
*/
|
|
1356
1406
|
sequence: number;
|
|
1357
1407
|
};
|
|
1408
|
+
/** @description What caused a ledger entry: one kind of cause per variant, told apart by `type`. */
|
|
1409
|
+
LedgerReference: {
|
|
1410
|
+
deposit_id: components["schemas"]["DepositId"];
|
|
1411
|
+
/** @enum {string} */
|
|
1412
|
+
type: "deposit";
|
|
1413
|
+
} | {
|
|
1414
|
+
/** @enum {string} */
|
|
1415
|
+
type: "withdrawal";
|
|
1416
|
+
withdrawal_id: components["schemas"]["WithdrawalId"];
|
|
1417
|
+
} | {
|
|
1418
|
+
order_id: components["schemas"]["OrderId"];
|
|
1419
|
+
/** @enum {string} */
|
|
1420
|
+
type: "order";
|
|
1421
|
+
} | {
|
|
1422
|
+
order_id: components["schemas"]["OrderId"];
|
|
1423
|
+
trade_id: components["schemas"]["TradeId"];
|
|
1424
|
+
/** @enum {string} */
|
|
1425
|
+
type: "trade";
|
|
1426
|
+
} | {
|
|
1427
|
+
counterparty_user_id: components["schemas"]["UserId"];
|
|
1428
|
+
/** @description Shared reference linking both halves. */
|
|
1429
|
+
transfer_ref: string;
|
|
1430
|
+
/** @enum {string} */
|
|
1431
|
+
type: "transfer";
|
|
1432
|
+
} | {
|
|
1433
|
+
operator_user_id: components["schemas"]["UserId"];
|
|
1434
|
+
/** @enum {string} */
|
|
1435
|
+
type: "adjustment";
|
|
1436
|
+
} | {
|
|
1437
|
+
pool_id: components["schemas"]["PoolId"];
|
|
1438
|
+
/** @enum {string} */
|
|
1439
|
+
type: "pool";
|
|
1440
|
+
} | {
|
|
1441
|
+
futures_transfer_id: components["schemas"]["FuturesTransferId"];
|
|
1442
|
+
/** @enum {string} */
|
|
1443
|
+
type: "futures_transfer";
|
|
1444
|
+
} | {
|
|
1445
|
+
/** @description Short machine-readable cause. */
|
|
1446
|
+
cause: string;
|
|
1447
|
+
/** @enum {string} */
|
|
1448
|
+
type: "system";
|
|
1449
|
+
};
|
|
1358
1450
|
/**
|
|
1359
1451
|
* @description Whether a fill added liquidity (maker) or removed it (taker).
|
|
1360
1452
|
* @enum {string}
|
|
@@ -1514,6 +1606,11 @@ interface components {
|
|
|
1514
1606
|
*/
|
|
1515
1607
|
timestamp: string;
|
|
1516
1608
|
};
|
|
1609
|
+
/**
|
|
1610
|
+
* @description Unique identifier of an order.
|
|
1611
|
+
* @example 507f1f77bcf86cd799439011
|
|
1612
|
+
*/
|
|
1613
|
+
OrderId: string;
|
|
1517
1614
|
/** @description An order. */
|
|
1518
1615
|
OrderResponse: {
|
|
1519
1616
|
average_price?: components["schemas"]["Amount"] | null;
|
|
@@ -1616,6 +1713,11 @@ interface components {
|
|
|
1616
1713
|
fills: components["schemas"]["FillResponse"][];
|
|
1617
1714
|
order: components["schemas"]["OrderResponse"];
|
|
1618
1715
|
};
|
|
1716
|
+
/**
|
|
1717
|
+
* @description Unique identifier of a liquidity pool.
|
|
1718
|
+
* @example 507f1f77bcf86cd799439011
|
|
1719
|
+
*/
|
|
1720
|
+
PoolId: string;
|
|
1619
1721
|
/**
|
|
1620
1722
|
* @description A pool as a client sees it.
|
|
1621
1723
|
*
|
|
@@ -1717,6 +1819,11 @@ interface components {
|
|
|
1717
1819
|
* @enum {string}
|
|
1718
1820
|
*/
|
|
1719
1821
|
TimeInForce: "gtc" | "ioc" | "fok" | "post_only";
|
|
1822
|
+
/**
|
|
1823
|
+
* @description Unique identifier of a trade.
|
|
1824
|
+
* @example 507f1f77bcf86cd799439011
|
|
1825
|
+
*/
|
|
1826
|
+
TradeId: string;
|
|
1720
1827
|
/**
|
|
1721
1828
|
* @description Which way the price must move for a stop to fire.
|
|
1722
1829
|
*
|
|
@@ -1724,6 +1831,11 @@ interface components {
|
|
|
1724
1831
|
* @enum {string}
|
|
1725
1832
|
*/
|
|
1726
1833
|
TriggerDirection: "above" | "below";
|
|
1834
|
+
/**
|
|
1835
|
+
* @description Unique identifier of a user account.
|
|
1836
|
+
* @example 507f1f77bcf86cd799439011
|
|
1837
|
+
*/
|
|
1838
|
+
UserId: string;
|
|
1727
1839
|
/** @description A saved withdrawal address. */
|
|
1728
1840
|
WithdrawalAddressResponse: {
|
|
1729
1841
|
/** @description The address. */
|
|
@@ -1762,6 +1874,11 @@ interface components {
|
|
|
1762
1874
|
reason?: string | null;
|
|
1763
1875
|
status: components["schemas"]["WithdrawalStatus"];
|
|
1764
1876
|
};
|
|
1877
|
+
/**
|
|
1878
|
+
* @description Unique identifier of a withdrawal.
|
|
1879
|
+
* @example 507f1f77bcf86cd799439011
|
|
1880
|
+
*/
|
|
1881
|
+
WithdrawalId: string;
|
|
1765
1882
|
/** @description A withdrawal. */
|
|
1766
1883
|
WithdrawalResponse: {
|
|
1767
1884
|
/** @description Destination. */
|
|
@@ -1818,7 +1935,7 @@ interface components {
|
|
|
1818
1935
|
* against the chain.
|
|
1819
1936
|
* @enum {string}
|
|
1820
1937
|
*/
|
|
1821
|
-
WithdrawalStatus: "requested" | "pending_approval" | "approved" | "processing" | "broadcast" | "completed" | "rejected" | "cancelled" | "failed" | "broadcast_unknown";
|
|
1938
|
+
WithdrawalStatus: "requested" | "pending_approval" | "approved" | "processing" | "broadcast" | "completed" | "rejected" | "cancelled" | "failed" | "broadcast_unknown" | "reverted";
|
|
1822
1939
|
};
|
|
1823
1940
|
responses: never;
|
|
1824
1941
|
parameters: never;
|
|
@@ -2002,6 +2119,49 @@ interface operations {
|
|
|
2002
2119
|
};
|
|
2003
2120
|
};
|
|
2004
2121
|
};
|
|
2122
|
+
sub_account_balances: {
|
|
2123
|
+
parameters: {
|
|
2124
|
+
query?: never;
|
|
2125
|
+
header?: never;
|
|
2126
|
+
path: {
|
|
2127
|
+
/** @description Sub-account id */
|
|
2128
|
+
id: string;
|
|
2129
|
+
};
|
|
2130
|
+
cookie?: never;
|
|
2131
|
+
};
|
|
2132
|
+
requestBody?: never;
|
|
2133
|
+
responses: {
|
|
2134
|
+
/** @description The sub-account's balances */
|
|
2135
|
+
200: {
|
|
2136
|
+
headers: {
|
|
2137
|
+
[name: string]: unknown;
|
|
2138
|
+
};
|
|
2139
|
+
content: {
|
|
2140
|
+
"application/json": {
|
|
2141
|
+
data: components["schemas"]["BalanceResponse"][];
|
|
2142
|
+
};
|
|
2143
|
+
};
|
|
2144
|
+
};
|
|
2145
|
+
/** @description Malformed sub-account id */
|
|
2146
|
+
400: {
|
|
2147
|
+
headers: {
|
|
2148
|
+
[name: string]: unknown;
|
|
2149
|
+
};
|
|
2150
|
+
content: {
|
|
2151
|
+
"application/json": components["schemas"]["ErrorResponse"];
|
|
2152
|
+
};
|
|
2153
|
+
};
|
|
2154
|
+
/** @description No such sub-account on this account */
|
|
2155
|
+
404: {
|
|
2156
|
+
headers: {
|
|
2157
|
+
[name: string]: unknown;
|
|
2158
|
+
};
|
|
2159
|
+
content: {
|
|
2160
|
+
"application/json": components["schemas"]["ErrorResponse"];
|
|
2161
|
+
};
|
|
2162
|
+
};
|
|
2163
|
+
};
|
|
2164
|
+
};
|
|
2005
2165
|
list_assets: {
|
|
2006
2166
|
parameters: {
|
|
2007
2167
|
query?: never;
|
|
@@ -3222,6 +3382,8 @@ type ApiScope = S["ApiScope"];
|
|
|
3222
3382
|
type Asset = S["AssetResponse"];
|
|
3223
3383
|
type AssetNetwork = S["AssetNetworkResponse"];
|
|
3224
3384
|
type Balance = S["BalanceResponse"];
|
|
3385
|
+
/** An incoming internal transfer still held (see `Balance.held_incoming`). */
|
|
3386
|
+
type HeldIncoming = S["HeldIncomingResponse"];
|
|
3225
3387
|
type CancelAllRequest = S["CancelAllRequest"];
|
|
3226
3388
|
type CancelAllResult = S["CancelAllResponse"];
|
|
3227
3389
|
/** Why one order could not be cancelled (`CancelAllResult.failures`). */
|
|
@@ -3256,7 +3418,31 @@ type FeeSchedule = S["FeeScheduleResponse"];
|
|
|
3256
3418
|
type Fill = S["FillResponse"];
|
|
3257
3419
|
type JoinPoolRequest = S["JoinPoolRequest"];
|
|
3258
3420
|
type JoinPoolResult = S["JoinPoolResponse"];
|
|
3259
|
-
|
|
3421
|
+
/** A ledger entry. `reference` also accepts cause types this SDK version does not know yet. */
|
|
3422
|
+
type LedgerEntry = Omit<S["LedgerEntryResponse"], "reference"> & {
|
|
3423
|
+
reference: LedgerReference;
|
|
3424
|
+
};
|
|
3425
|
+
/** What caused a ledger entry, as documented: one variant per `type`. */
|
|
3426
|
+
type KnownLedgerReference = S["LedgerReference"];
|
|
3427
|
+
/** The documented `LedgerReference` types. */
|
|
3428
|
+
type LedgerReferenceType = KnownLedgerReference["type"];
|
|
3429
|
+
/**
|
|
3430
|
+
* A cause type this SDK version does not know yet (the server may add new ones). The object is
|
|
3431
|
+
* kept as sent. Use `isLedgerReference()` to narrow to a documented variant.
|
|
3432
|
+
*/
|
|
3433
|
+
interface UnknownLedgerReference {
|
|
3434
|
+
type: string;
|
|
3435
|
+
[field: string]: unknown;
|
|
3436
|
+
}
|
|
3437
|
+
/** `LedgerEntry.reference`: a documented variant or an unknown one; never throws on new types. */
|
|
3438
|
+
type LedgerReference = KnownLedgerReference | UnknownLedgerReference;
|
|
3439
|
+
type DepositId = S["DepositId"];
|
|
3440
|
+
type FuturesTransferId = S["FuturesTransferId"];
|
|
3441
|
+
type OrderId = S["OrderId"];
|
|
3442
|
+
type PoolId = S["PoolId"];
|
|
3443
|
+
type TradeId = S["TradeId"];
|
|
3444
|
+
type UserId = S["UserId"];
|
|
3445
|
+
type WithdrawalId = S["WithdrawalId"];
|
|
3260
3446
|
type LedgerEntryKind = S["LedgerEntryKind"];
|
|
3261
3447
|
type LiquidityRole = S["LiquidityRole"];
|
|
3262
3448
|
type MaintenanceState = S["MaintenanceState"];
|
|
@@ -3355,13 +3541,29 @@ declare class PoolsResource extends Resource {
|
|
|
3355
3541
|
exit(symbol: string, body: ExitPoolRequest, opts?: RequestOptions): Promise<ExitPoolResult>;
|
|
3356
3542
|
}
|
|
3357
3543
|
declare class AccountResource extends Resource {
|
|
3544
|
+
/**
|
|
3545
|
+
* Balances per asset. `held_incoming` lists incoming internal transfers still held; their sum is
|
|
3546
|
+
* already included in `locked` (never add it again). Always an array (`[]` when none).
|
|
3547
|
+
*/
|
|
3358
3548
|
balances(opts?: RequestOptions): Promise<Balance[]>;
|
|
3549
|
+
/** One asset's balance. `held_incoming`: incoming transfers still held, already inside `locked`. */
|
|
3359
3550
|
balance(asset: string, opts?: RequestOptions): Promise<Balance>;
|
|
3360
3551
|
ledger(params?: Q<"get_ledger">, opts?: RequestOptions): Promise<Page<LedgerEntry>>;
|
|
3361
3552
|
iterateLedger(params?: Q<"get_ledger">, iter?: IterateOptions & RequestOptions): AsyncGenerator<LedgerEntry, void, undefined>;
|
|
3362
3553
|
notifications(params?: Q<"list_notifications">, opts?: RequestOptions): Promise<Page<Notification>>;
|
|
3363
3554
|
iterateNotifications(params?: Q<"list_notifications">, iter?: IterateOptions & RequestOptions): AsyncGenerator<Notification, void, undefined>;
|
|
3364
3555
|
subAccounts(opts?: RequestOptions): Promise<SubAccount[]>;
|
|
3556
|
+
/**
|
|
3557
|
+
* A sub-account's balances, read by its PARENT account: the same shape as `balances()`
|
|
3558
|
+
* (zero balances omitted), including `held_incoming`, whose sum is already inside `locked`.
|
|
3559
|
+
* The server currently returns them ordered by asset symbol; don't rely on the order.
|
|
3560
|
+
* An id that is not one of the caller's sub-accounts (or a call with the sub-account's own
|
|
3561
|
+
* key) gets `NotFoundError`; a sub-account's own key reads its balances with `balances()`.
|
|
3562
|
+
* A malformed id gets 400 (`ValidationError`); a key without the `read` scope gets 403
|
|
3563
|
+
* `FORBIDDEN` (`ForbiddenError`). `id` must be non-empty and not "." or ".."; it is sent as
|
|
3564
|
+
* one URL path segment.
|
|
3565
|
+
*/
|
|
3566
|
+
subAccountBalances(id: string, opts?: RequestOptions): Promise<Balance[]>;
|
|
3365
3567
|
/** Your API keys (metadata only; secrets are never returned). */
|
|
3366
3568
|
apiKeys(opts?: RequestOptions): Promise<ApiKey[]>;
|
|
3367
3569
|
}
|
|
@@ -3449,6 +3651,8 @@ declare class TradingResource extends Resource {
|
|
|
3449
3651
|
cancelOrder(orderId: string, opts?: RequestOptions): Promise<Order>;
|
|
3450
3652
|
/**
|
|
3451
3653
|
* Cancels every open order in one market: `cancelAll({ symbol: "BTC/USDT" })`.
|
|
3654
|
+
* This includes stop orders that have not triggered yet (status `pending_trigger`): they are
|
|
3655
|
+
* cancelled and their reservations released, so nothing fires into the market afterwards.
|
|
3452
3656
|
* To cancel across ALL markets, pass `symbol: null` explicitly: `cancelAll({ symbol: null })`.
|
|
3453
3657
|
* Omitting `symbol` is an error, so an account-wide cancel never happens by accident
|
|
3454
3658
|
* (the server itself treats `{}` as every market). An unknown symbol throws `NotFoundError`.
|
|
@@ -4050,12 +4254,23 @@ declare function isAmount(value: unknown): value is Amount;
|
|
|
4050
4254
|
*/
|
|
4051
4255
|
declare function assertAmountFields(body: Record<string, unknown>, fields: readonly string[], context: string): void;
|
|
4052
4256
|
|
|
4257
|
+
/**
|
|
4258
|
+
* Narrows a ledger entry's `reference`:
|
|
4259
|
+
* - `isLedgerReference(ref)`: true for any documented variant;
|
|
4260
|
+
* - `isLedgerReference(ref, "trade")`: true only for that variant, typed accordingly.
|
|
4261
|
+
* Unknown (newer) types return false and keep their raw fields.
|
|
4262
|
+
*/
|
|
4263
|
+
declare function isLedgerReference(ref: LedgerReference): ref is KnownLedgerReference;
|
|
4264
|
+
declare function isLedgerReference<T extends LedgerReferenceType>(ref: LedgerReference, type: T): ref is Extract<KnownLedgerReference, {
|
|
4265
|
+
type: T;
|
|
4266
|
+
}>;
|
|
4267
|
+
|
|
4053
4268
|
/** SDK version, kept in sync with package.json (a test enforces this). */
|
|
4054
|
-
declare const VERSION = "0.1.0-dev.
|
|
4269
|
+
declare const VERSION = "0.1.0-dev.7";
|
|
4055
4270
|
/** Default User-Agent product token. */
|
|
4056
|
-
declare const USER_AGENT = "cexy-typescript/0.1.0-dev.
|
|
4271
|
+
declare const USER_AGENT = "cexy-typescript/0.1.0-dev.7";
|
|
4057
4272
|
|
|
4058
4273
|
/** True for loopback hosts, the only ones where plain-text transport may be allowed. */
|
|
4059
4274
|
declare function isLocalHost(hostname: string): boolean;
|
|
4060
4275
|
|
|
4061
|
-
export { AccountResource, type Amount, type ApiKey, ApiKeyAuthenticator, type ApiScope, type Asset, type AssetNetwork, AssetsResource, type AuthRequest, type AuthResult, type AuthenticatedFrame, AuthenticationError, type Authenticator, type Balance, type BalanceUpdatedEvent, type BookLevel, CLIENT_ERROR_CODES, CancelAllInterruptedError, type CancelAllParams, type CancelAllRequest, type CancelAllResult, type CancelAllStopReason, type CancelAllUntilDoneResult, type CancelFailure, type Candle, type CandleInterval, CexyApiError, type CexyApiErrorInit, CexyClient, type CexyClientOptions, CexyConfigError, CexyConnectionError, CexyError, CexyTimeoutError, CexyWebSocket, CexyWebSocketError, type CexyWebSocketEvents, type CexyWebSocketOptions, type CloseInfo, ConflictError, type CursorParams, DEFAULT_BASE_URL, DEFAULT_RPM_ANONYMOUS, DEFAULT_RPM_WITH_KEY, DEFAULT_WS_URL, type Deposit, type DepositAddress, type DepositEvent, type DepositStatus, type ErrorBody, type ErrorCode, type ErrorFrame, type EventMap, type ExchangeConfig, type ExitPoolRequest, type ExitPoolResult, ExportsResource, type FeeSchedule, FeesResource, type FetchLike, type Fill, ForbiddenError, InvalidAmountError, type IterateOptions, type JoinPoolRequest, type JoinPoolResult, JurisdictionBlockedError, KNOWN_EVENT_TYPES, type KnownErrorCode, type LedgerEntry, type LedgerEntryKind, type LiquidityRole, type Listener, LiveOrderBook, type LiveOrderBookEvents, type LiveOrderBookOptions, MAX_SERVER_WAIT_MS, type MaintenanceState, type Market, type MarketStatus, type MarketStatusEvent, MarketsResource, type Network, NetworksResource, NotFoundError, type Notification, type NotificationKind, OPERATIONS, type OperationAuth, type OperationId, type OperationInfo, type OperationScope, type Order, type OrderBook, type OrderBookUpdateData, type OrderBookUpdateEvent, type OrderEvent, type OrderSide, OrderStateUnknownError, type OrderStatus, type OrderType, PRIVATE_CHANNELS, type Page, type PlaceOrderRequest, type PlaceOrderResponse, type PlaceOrderResult, type PongFrame, type Pool, type PoolStatus, PoolsResource, type PublicTrade, type QueryOf, RateLimitError, RateLimiter, type RateLimiterOptions, type RateLimiterState, type ReconnectOptions, type RequestOptions, type ResyncReason, type RetryInfo, SUPPORTED_PROTOCOL_VERSION, ServerError, type ServerTime, type SessionRevokedData, type SessionRevokedEvent, type SnapshotSource, type SortDirection, type SubAccount, type SubscribeResult, type SubscribedFrame, type TickerUpdateEvent, type TimeInForce, type TradeNewEvent, TradingResource, type TriggerDirection, TypedEmitter, USER_AGENT, UnprocessableError, type UnsubscribedFrame, VERSION, ValidationError, WS_BOOK_DEPTH, WalletResource, type WebSocketConstructor, type WebSocketLike, type WelcomeFrame, type Withdrawal, type WithdrawalAddress, type WithdrawalStatus, type WithdrawalUpdatedEvent, type WsEvent, type WsLogger, assertAmountFields, type components, errorFromResponse, isAmount, isKnownErrorCode, isLocalHost, isRetryable, type operations, paginate, type paths };
|
|
4276
|
+
export { AccountResource, type Amount, type ApiKey, ApiKeyAuthenticator, type ApiScope, type Asset, type AssetNetwork, AssetsResource, type AuthRequest, type AuthResult, type AuthenticatedFrame, AuthenticationError, type Authenticator, type Balance, type BalanceUpdatedEvent, type BookLevel, CLIENT_ERROR_CODES, CancelAllInterruptedError, type CancelAllParams, type CancelAllRequest, type CancelAllResult, type CancelAllStopReason, type CancelAllUntilDoneResult, type CancelFailure, type Candle, type CandleInterval, CexyApiError, type CexyApiErrorInit, CexyClient, type CexyClientOptions, CexyConfigError, CexyConnectionError, CexyError, CexyTimeoutError, CexyWebSocket, CexyWebSocketError, type CexyWebSocketEvents, type CexyWebSocketOptions, type CloseInfo, ConflictError, type CursorParams, DEFAULT_BASE_URL, DEFAULT_RPM_ANONYMOUS, DEFAULT_RPM_WITH_KEY, DEFAULT_WS_URL, type Deposit, type DepositAddress, type DepositEvent, type DepositId, type DepositStatus, type ErrorBody, type ErrorCode, type ErrorFrame, type EventMap, type ExchangeConfig, type ExitPoolRequest, type ExitPoolResult, ExportsResource, type FeeSchedule, FeesResource, type FetchLike, type Fill, ForbiddenError, type FuturesTransferId, type HeldIncoming, InvalidAmountError, type IterateOptions, type JoinPoolRequest, type JoinPoolResult, JurisdictionBlockedError, KNOWN_EVENT_TYPES, type KnownErrorCode, type KnownLedgerReference, type LedgerEntry, type LedgerEntryKind, type LedgerReference, type LedgerReferenceType, type LiquidityRole, type Listener, LiveOrderBook, type LiveOrderBookEvents, type LiveOrderBookOptions, MAX_SERVER_WAIT_MS, type MaintenanceState, type Market, type MarketStatus, type MarketStatusEvent, MarketsResource, type Network, NetworksResource, NotFoundError, type Notification, type NotificationKind, OPERATIONS, type OperationAuth, type OperationId, type OperationInfo, type OperationScope, type Order, type OrderBook, type OrderBookUpdateData, type OrderBookUpdateEvent, type OrderEvent, type OrderId, type OrderSide, OrderStateUnknownError, type OrderStatus, type OrderType, PRIVATE_CHANNELS, type Page, type PlaceOrderRequest, type PlaceOrderResponse, type PlaceOrderResult, type PongFrame, type Pool, type PoolId, type PoolStatus, PoolsResource, type PublicTrade, type QueryOf, RateLimitError, RateLimiter, type RateLimiterOptions, type RateLimiterState, type ReconnectOptions, type RequestOptions, type ResyncReason, type RetryInfo, SUPPORTED_PROTOCOL_VERSION, ServerError, type ServerTime, type SessionRevokedData, type SessionRevokedEvent, type SnapshotSource, type SortDirection, type SubAccount, type SubscribeResult, type SubscribedFrame, type TickerUpdateEvent, type TimeInForce, type TradeId, type TradeNewEvent, TradingResource, type TriggerDirection, TypedEmitter, USER_AGENT, type UnknownLedgerReference, UnprocessableError, type UnsubscribedFrame, type UserId, VERSION, ValidationError, WS_BOOK_DEPTH, WalletResource, type WebSocketConstructor, type WebSocketLike, type WelcomeFrame, type Withdrawal, type WithdrawalAddress, type WithdrawalId, type WithdrawalStatus, type WithdrawalUpdatedEvent, type WsEvent, type WsLogger, assertAmountFields, type components, errorFromResponse, isAmount, isKnownErrorCode, isLedgerReference, isLocalHost, isRetryable, type operations, paginate, type paths };
|
package/dist/index.js
CHANGED
|
@@ -137,13 +137,14 @@ var KNOWN_CODES = /* @__PURE__ */ new Set([
|
|
|
137
137
|
"INTERNAL",
|
|
138
138
|
"SERVICE_UNAVAILABLE",
|
|
139
139
|
"UNDER_MAINTENANCE",
|
|
140
|
-
"ENGINE_OVERLOADED"
|
|
140
|
+
"ENGINE_OVERLOADED",
|
|
141
|
+
"PRICE_UNAVAILABLE"
|
|
141
142
|
]);
|
|
142
143
|
var CLIENT_ERROR_CODES = { UNEXPECTED_REDIRECT: "UNEXPECTED_REDIRECT" };
|
|
143
144
|
function isKnownErrorCode(code) {
|
|
144
145
|
return KNOWN_CODES.has(code);
|
|
145
146
|
}
|
|
146
|
-
var DEFAULT_RETRYABLE_STATUS = /* @__PURE__ */ new Set([
|
|
147
|
+
var DEFAULT_RETRYABLE_STATUS = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
|
|
147
148
|
var MAX_SERVER_WAIT_MS = 12e4;
|
|
148
149
|
function retryAfterMs(headers, details) {
|
|
149
150
|
let best = null;
|
|
@@ -293,6 +294,7 @@ var OPERATIONS = {
|
|
|
293
294
|
get_ledger: op("GET", "/api/v1/account/ledger", "api_key", "read", "account.ledger"),
|
|
294
295
|
list_notifications: op("GET", "/api/v1/account/notifications", "api_key", "read", "account.notifications"),
|
|
295
296
|
list_sub_accounts: op("GET", "/api/v1/account/sub-accounts", "api_key", "read", "account.subAccounts"),
|
|
297
|
+
sub_account_balances: op("GET", "/api/v1/account/sub-accounts/{id}/balances", "api_key", "read", "account.subAccountBalances"),
|
|
296
298
|
list_api_keys: op("GET", "/api/v1/account/api-keys", "api_key", "read", "account.apiKeys"),
|
|
297
299
|
// Exports (read)
|
|
298
300
|
export_deposits: op("GET", "/api/v1/exports/deposits", "api_key", "read", "exports.deposits"),
|
|
@@ -323,6 +325,7 @@ var OPERATIONS = {
|
|
|
323
325
|
|
|
324
326
|
// src/http.ts
|
|
325
327
|
var IDEMPOTENT_OPS = /* @__PURE__ */ new Set(["join_pool", "exit_pool"]);
|
|
328
|
+
var REPEAT_SAFE_MUTATIONS = /* @__PURE__ */ new Set(["join_pool", "exit_pool", "cancel_all"]);
|
|
326
329
|
var BACKOFF_BASE_MS = 500;
|
|
327
330
|
var BACKOFF_MAX_MS = 1e4;
|
|
328
331
|
var Transport = class {
|
|
@@ -334,13 +337,14 @@ var Transport = class {
|
|
|
334
337
|
* Sends a request with the standard retry policy: retryable errors and network failures are
|
|
335
338
|
* retried. Pool join/exit carry an `Idempotency-Key` reused on every attempt (the server
|
|
336
339
|
* honours it there, which makes their retries safe); the other mutations routed here
|
|
337
|
-
* (cancel-all) are naturally repeatable and send no key.
|
|
338
|
-
* `attempt()` with their own policies.
|
|
340
|
+
* (cancel-all) are naturally repeatable and send no key. Any other mutation is sent once.
|
|
341
|
+
* `placeOrder` and `cancelOrder` use `attempt()` with their own policies.
|
|
339
342
|
*/
|
|
340
343
|
async request(spec, opts = {}) {
|
|
341
344
|
const info = OPERATIONS[spec.op];
|
|
342
345
|
const idempotencyKey = IDEMPOTENT_OPS.has(spec.op) ? spec.idempotencyKey ?? opts.idempotencyKey ?? newId() : void 0;
|
|
343
|
-
const
|
|
346
|
+
const repeatSafe = info.method === "GET" || REPEAT_SAFE_MUTATIONS.has(spec.op);
|
|
347
|
+
const maxRetries = repeatSafe ? opts.maxRetries ?? this.config.maxRetries : 0;
|
|
344
348
|
for (let attempt = 0; ; attempt++) {
|
|
345
349
|
try {
|
|
346
350
|
return await this.attempt({ ...spec, idempotencyKey }, opts);
|
|
@@ -455,6 +459,7 @@ var Transport = class {
|
|
|
455
459
|
const path = info.path.replace(/\{(\w+)\}/g, (_m, name) => {
|
|
456
460
|
const v = pathParams[name];
|
|
457
461
|
if (typeof v !== "string" || v === "") throw new CexyConfigError(`${info.sdkMethod}(): ${name} is required`);
|
|
462
|
+
if (v === "." || v === "..") throw new CexyConfigError(`${info.sdkMethod}(): ${name} must not be "." or ".."`);
|
|
458
463
|
return encodeURIComponent(v);
|
|
459
464
|
});
|
|
460
465
|
const url = new URL(this.config.baseUrl.replace(/\/+$/, "") + path);
|
|
@@ -477,7 +482,11 @@ function serverHintMs(err) {
|
|
|
477
482
|
}
|
|
478
483
|
function isRetryable(err) {
|
|
479
484
|
if (err instanceof CexyConnectionError) return true;
|
|
480
|
-
if (err instanceof CexyApiError)
|
|
485
|
+
if (err instanceof CexyApiError) {
|
|
486
|
+
const concurrent = err.code === "CONCURRENT_MODIFICATION";
|
|
487
|
+
if (err.status >= 400 && err.status < 500 && err.status !== 429 && !(err.status === 409 && concurrent)) return false;
|
|
488
|
+
return err.retryable || concurrent;
|
|
489
|
+
}
|
|
481
490
|
return false;
|
|
482
491
|
}
|
|
483
492
|
function isAmbiguous(err) {
|
|
@@ -543,6 +552,17 @@ var RateLimiter = class {
|
|
|
543
552
|
await this.#sleep(Math.min(MAX_BLOCK_MS, Math.ceil((1 - this.#tokens) * msPerToken)), signal);
|
|
544
553
|
}
|
|
545
554
|
}
|
|
555
|
+
/**
|
|
556
|
+
* How long `acquire()` would wait right now, in ms (0 when a request may go at once). Lets a
|
|
557
|
+
* caller with a time budget, such as the cancelAll untilDone loop, count the limiter's wait.
|
|
558
|
+
*/
|
|
559
|
+
pendingWaitMs() {
|
|
560
|
+
this.#refill();
|
|
561
|
+
const block = this.#blockedUntil - this.#now();
|
|
562
|
+
if (block > 0) return block;
|
|
563
|
+
if (this.#tokens >= 1) return 0;
|
|
564
|
+
return Math.min(MAX_BLOCK_MS, Math.ceil((1 - this.#tokens) * (6e4 / this.#rpm)));
|
|
565
|
+
}
|
|
546
566
|
/** Adapts to the server's rate-limit headers. Never raises the configured limit. */
|
|
547
567
|
update(headers) {
|
|
548
568
|
this.#refill();
|
|
@@ -738,12 +758,22 @@ var PoolsResource = class extends Resource {
|
|
|
738
758
|
return this.data({ op: "exit_pool", pathParams: { symbol }, body }, opts);
|
|
739
759
|
}
|
|
740
760
|
};
|
|
761
|
+
function withHeldIncoming(b) {
|
|
762
|
+
if (!b || typeof b !== "object" || Array.isArray(b.held_incoming)) return b;
|
|
763
|
+
return { ...b, held_incoming: [] };
|
|
764
|
+
}
|
|
741
765
|
var AccountResource = class extends Resource {
|
|
742
|
-
|
|
743
|
-
|
|
766
|
+
/**
|
|
767
|
+
* Balances per asset. `held_incoming` lists incoming internal transfers still held; their sum is
|
|
768
|
+
* already included in `locked` (never add it again). Always an array (`[]` when none).
|
|
769
|
+
*/
|
|
770
|
+
async balances(opts) {
|
|
771
|
+
const rows = await this.data({ op: "list_balances" }, opts);
|
|
772
|
+
return Array.isArray(rows) ? rows.map(withHeldIncoming) : rows;
|
|
744
773
|
}
|
|
745
|
-
balance
|
|
746
|
-
|
|
774
|
+
/** One asset's balance. `held_incoming`: incoming transfers still held, already inside `locked`. */
|
|
775
|
+
async balance(asset, opts) {
|
|
776
|
+
return withHeldIncoming(await this.data({ op: "get_balance", pathParams: { asset } }, opts));
|
|
747
777
|
}
|
|
748
778
|
ledger(params, opts) {
|
|
749
779
|
return this.page({ op: "get_ledger", query: params }, opts);
|
|
@@ -760,6 +790,20 @@ var AccountResource = class extends Resource {
|
|
|
760
790
|
subAccounts(opts) {
|
|
761
791
|
return this.data({ op: "list_sub_accounts" }, opts);
|
|
762
792
|
}
|
|
793
|
+
/**
|
|
794
|
+
* A sub-account's balances, read by its PARENT account: the same shape as `balances()`
|
|
795
|
+
* (zero balances omitted), including `held_incoming`, whose sum is already inside `locked`.
|
|
796
|
+
* The server currently returns them ordered by asset symbol; don't rely on the order.
|
|
797
|
+
* An id that is not one of the caller's sub-accounts (or a call with the sub-account's own
|
|
798
|
+
* key) gets `NotFoundError`; a sub-account's own key reads its balances with `balances()`.
|
|
799
|
+
* A malformed id gets 400 (`ValidationError`); a key without the `read` scope gets 403
|
|
800
|
+
* `FORBIDDEN` (`ForbiddenError`). `id` must be non-empty and not "." or ".."; it is sent as
|
|
801
|
+
* one URL path segment.
|
|
802
|
+
*/
|
|
803
|
+
async subAccountBalances(id, opts) {
|
|
804
|
+
const rows = await this.data({ op: "sub_account_balances", pathParams: { id } }, opts);
|
|
805
|
+
return Array.isArray(rows) ? rows.map(withHeldIncoming) : rows;
|
|
806
|
+
}
|
|
763
807
|
/** Your API keys (metadata only; secrets are never returned). */
|
|
764
808
|
apiKeys(opts) {
|
|
765
809
|
return this.data({ op: "list_api_keys" }, opts);
|
|
@@ -1013,8 +1057,10 @@ var TradingResource = class extends Resource {
|
|
|
1013
1057
|
if (progress) idle = 0;
|
|
1014
1058
|
else waitMs = (CANCEL_BACKOFF_S[Math.min(idle++, CANCEL_BACKOFF_S.length - 1)] ?? 15) * 1e3;
|
|
1015
1059
|
}
|
|
1016
|
-
|
|
1060
|
+
const limiterMs = this.t.config.limiter?.pendingWaitMs() ?? 0;
|
|
1061
|
+
if (now() - start + Math.max(waitMs, limiterMs) >= budgetMs) {
|
|
1017
1062
|
stopped = "time_budget";
|
|
1063
|
+
if (limiterMs > waitMs) lastErrorCode = "RATE_LIMITED";
|
|
1018
1064
|
break;
|
|
1019
1065
|
}
|
|
1020
1066
|
if (waitMs > 0) await this.t.config.sleep(waitMs, opts?.signal);
|
|
@@ -1024,7 +1070,7 @@ var TradingResource = class extends Resource {
|
|
|
1024
1070
|
};
|
|
1025
1071
|
|
|
1026
1072
|
// src/version.ts
|
|
1027
|
-
var VERSION = "0.1.0-dev.
|
|
1073
|
+
var VERSION = "0.1.0-dev.7";
|
|
1028
1074
|
var USER_AGENT = `cexy-typescript/${VERSION}`;
|
|
1029
1075
|
|
|
1030
1076
|
// src/ws/emitter.ts
|
|
@@ -1876,4 +1922,21 @@ function canSetUserAgent() {
|
|
|
1876
1922
|
return !(typeof g.window !== "undefined" && typeof g.window.document !== "undefined");
|
|
1877
1923
|
}
|
|
1878
1924
|
|
|
1879
|
-
|
|
1925
|
+
// src/ledger.ts
|
|
1926
|
+
var KNOWN_LEDGER_REFERENCE_TYPES = /* @__PURE__ */ new Set([
|
|
1927
|
+
"deposit",
|
|
1928
|
+
"withdrawal",
|
|
1929
|
+
"order",
|
|
1930
|
+
"trade",
|
|
1931
|
+
"transfer",
|
|
1932
|
+
"adjustment",
|
|
1933
|
+
"pool",
|
|
1934
|
+
"futures_transfer",
|
|
1935
|
+
"system"
|
|
1936
|
+
]);
|
|
1937
|
+
function isLedgerReference(ref, type) {
|
|
1938
|
+
if (typeof ref !== "object" || ref === null || typeof ref.type !== "string") return false;
|
|
1939
|
+
return type === void 0 ? KNOWN_LEDGER_REFERENCE_TYPES.has(ref.type) : ref.type === type;
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1942
|
+
export { AccountResource, ApiKeyAuthenticator, AssetsResource, AuthenticationError, CLIENT_ERROR_CODES, CancelAllInterruptedError, CexyApiError, CexyClient, CexyConfigError, CexyConnectionError, CexyError, CexyTimeoutError, CexyWebSocket, CexyWebSocketError, ConflictError, DEFAULT_BASE_URL, DEFAULT_RPM_ANONYMOUS, DEFAULT_RPM_WITH_KEY, DEFAULT_WS_URL, ExportsResource, FeesResource, ForbiddenError, InvalidAmountError, JurisdictionBlockedError, KNOWN_EVENT_TYPES, LiveOrderBook, MAX_SERVER_WAIT_MS, MarketsResource, NetworksResource, NotFoundError, OPERATIONS, OrderStateUnknownError, PRIVATE_CHANNELS, PoolsResource, RateLimitError, RateLimiter, SUPPORTED_PROTOCOL_VERSION, ServerError, TradingResource, TypedEmitter, USER_AGENT, UnprocessableError, VERSION, ValidationError, WS_BOOK_DEPTH, WalletResource, assertAmountFields, errorFromResponse, isAmount, isKnownErrorCode, isLedgerReference, isLocalHost, isRetryable, paginate };
|