@proof-labs/trading-sdk 4.0.0 → 5.0.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/README.md +137 -6
- package/dist/account-state.d.ts +17 -0
- package/dist/account-state.d.ts.map +1 -0
- package/dist/account-state.js +63 -0
- package/dist/account-state.js.map +1 -0
- package/dist/client.d.ts +112 -31
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +472 -188
- package/dist/client.js.map +1 -1
- package/dist/codec-adapter.d.ts.map +1 -1
- package/dist/codec-adapter.js +11 -4
- package/dist/codec-adapter.js.map +1 -1
- package/dist/crypto.d.ts +20 -0
- package/dist/crypto.d.ts.map +1 -1
- package/dist/crypto.js +39 -0
- package/dist/crypto.js.map +1 -1
- package/dist/errors.d.ts +26 -3
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +111 -15
- package/dist/errors.js.map +1 -1
- package/dist/feed-types.d.ts +76 -0
- package/dist/feed-types.d.ts.map +1 -0
- package/dist/feed-types.js +2 -0
- package/dist/feed-types.js.map +1 -0
- package/dist/feed.d.ts +158 -0
- package/dist/feed.d.ts.map +1 -0
- package/dist/feed.js +474 -0
- package/dist/feed.js.map +1 -0
- package/dist/financial-state.d.ts +65 -0
- package/dist/financial-state.d.ts.map +1 -0
- package/dist/financial-state.js +345 -0
- package/dist/financial-state.js.map +1 -0
- package/dist/gateway-reads.d.ts +74 -0
- package/dist/gateway-reads.d.ts.map +1 -0
- package/dist/gateway-reads.js +91 -0
- package/dist/gateway-reads.js.map +1 -0
- package/dist/governance-query.d.ts +7 -13
- package/dist/governance-query.d.ts.map +1 -1
- package/dist/governance-query.js +131 -70
- package/dist/governance-query.js.map +1 -1
- package/dist/history.d.ts +17 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +150 -0
- package/dist/history.js.map +1 -0
- package/dist/index.d.ts +13 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -3
- package/dist/index.js.map +1 -1
- package/dist/market-snapshot.d.ts +11 -0
- package/dist/market-snapshot.d.ts.map +1 -0
- package/dist/market-snapshot.js +325 -0
- package/dist/market-snapshot.js.map +1 -0
- package/dist/oracle-permissions.d.ts +51 -0
- package/dist/oracle-permissions.d.ts.map +1 -0
- package/dist/oracle-permissions.js +191 -0
- package/dist/oracle-permissions.js.map +1 -0
- package/dist/oracle-price-history.d.ts +30 -0
- package/dist/oracle-price-history.d.ts.map +1 -0
- package/dist/oracle-price-history.js +108 -0
- package/dist/oracle-price-history.js.map +1 -0
- package/dist/portfolio-history.d.ts +21 -0
- package/dist/portfolio-history.d.ts.map +1 -0
- package/dist/portfolio-history.js +49 -0
- package/dist/portfolio-history.js.map +1 -0
- package/dist/tx-result.d.ts +6 -0
- package/dist/tx-result.d.ts.map +1 -1
- package/dist/tx-result.js +42 -0
- package/dist/tx-result.js.map +1 -1
- package/dist/types.d.ts +235 -114
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +14 -5
- package/dist/types.js.map +1 -1
- package/dist/wasm/proof_trading_sdk_wasm_bg.wasm +0 -0
- package/package.json +5 -1
package/dist/errors.js
CHANGED
|
@@ -46,14 +46,13 @@ export var ExecErrorCode;
|
|
|
46
46
|
ExecErrorCode[ExecErrorCode["InvalidNonce"] = 21] = "InvalidNonce";
|
|
47
47
|
ExecErrorCode[ExecErrorCode["MarketAlreadyExists"] = 22] = "MarketAlreadyExists";
|
|
48
48
|
ExecErrorCode[ExecErrorCode["InvalidMarketConfig"] = 23] = "InvalidMarketConfig";
|
|
49
|
-
|
|
50
|
-
ExecErrorCode[ExecErrorCode["ImpactMarketNotFound"] = 25] = "ImpactMarketNotFound";
|
|
49
|
+
// 24 and 25 belonged to the retired impact-market family; never reassigned.
|
|
51
50
|
ExecErrorCode[ExecErrorCode["MarketClosedForTrading"] = 26] = "MarketClosedForTrading";
|
|
52
51
|
ExecErrorCode[ExecErrorCode["BinaryPriceOutOfRange"] = 27] = "BinaryPriceOutOfRange";
|
|
53
52
|
ExecErrorCode[ExecErrorCode["InvalidResolution"] = 28] = "InvalidResolution";
|
|
54
53
|
ExecErrorCode[ExecErrorCode["PositionLimitExceeded"] = 29] = "PositionLimitExceeded";
|
|
55
54
|
ExecErrorCode[ExecErrorCode["OracleTimestampNotMonotonic"] = 30] = "OracleTimestampNotMonotonic";
|
|
56
|
-
|
|
55
|
+
// 31 belonged to the retired impact-market family; never reassigned.
|
|
57
56
|
ExecErrorCode[ExecErrorCode["SettlementPriceMismatch"] = 32] = "SettlementPriceMismatch";
|
|
58
57
|
ExecErrorCode[ExecErrorCode["OracleNotApplicable"] = 33] = "OracleNotApplicable";
|
|
59
58
|
ExecErrorCode[ExecErrorCode["PostOnlyWouldCross"] = 34] = "PostOnlyWouldCross";
|
|
@@ -107,6 +106,27 @@ export var ExecErrorCode;
|
|
|
107
106
|
ExecErrorCode[ExecErrorCode["EmergencyActionRetired"] = 69] = "EmergencyActionRetired";
|
|
108
107
|
ExecErrorCode[ExecErrorCode["AdminActionRequiresProposal"] = 70] = "AdminActionRequiresProposal";
|
|
109
108
|
ExecErrorCode[ExecErrorCode["InvalidAdminRegistry"] = 71] = "InvalidAdminRegistry";
|
|
109
|
+
ExecErrorCode[ExecErrorCode["BridgeReceiptRegistryInactive"] = 72] = "BridgeReceiptRegistryInactive";
|
|
110
|
+
ExecErrorCode[ExecErrorCode["BridgeReceiptInvalid"] = 73] = "BridgeReceiptInvalid";
|
|
111
|
+
ExecErrorCode[ExecErrorCode["BridgeReceiptMismatch"] = 74] = "BridgeReceiptMismatch";
|
|
112
|
+
ExecErrorCode[ExecErrorCode["WithdrawalBelowMinimum"] = 75] = "WithdrawalBelowMinimum";
|
|
113
|
+
ExecErrorCode[ExecErrorCode["WithdrawalTerminalGated"] = 76] = "WithdrawalTerminalGated";
|
|
114
|
+
// 77-81 are reserved on the wire for oracle-observation and oracle-policy errors.
|
|
115
|
+
ExecErrorCode[ExecErrorCode["OracleGuardUnset"] = 82] = "OracleGuardUnset";
|
|
116
|
+
ExecErrorCode[ExecErrorCode["SubAccountNotFound"] = 83] = "SubAccountNotFound";
|
|
117
|
+
ExecErrorCode[ExecErrorCode["SubAccountAlreadyExists"] = 84] = "SubAccountAlreadyExists";
|
|
118
|
+
ExecErrorCode[ExecErrorCode["SubAccountTransferSameAccount"] = 85] = "SubAccountTransferSameAccount";
|
|
119
|
+
ExecErrorCode[ExecErrorCode["SubAccountTransferBothChildren"] = 86] = "SubAccountTransferBothChildren";
|
|
120
|
+
ExecErrorCode[ExecErrorCode["SubAccountTransferInsufficientBalance"] = 87] = "SubAccountTransferInsufficientBalance";
|
|
121
|
+
ExecErrorCode[ExecErrorCode["SubAccountIdZero"] = 88] = "SubAccountIdZero";
|
|
122
|
+
ExecErrorCode[ExecErrorCode["SubAccountTransferZeroAmount"] = 89] = "SubAccountTransferZeroAmount";
|
|
123
|
+
ExecErrorCode[ExecErrorCode["SubAccountsInactive"] = 90] = "SubAccountsInactive";
|
|
124
|
+
ExecErrorCode[ExecErrorCode["WithdrawalPayoutLeaseActive"] = 91] = "WithdrawalPayoutLeaseActive";
|
|
125
|
+
ExecErrorCode[ExecErrorCode["EventAlreadyExists"] = 92] = "EventAlreadyExists";
|
|
126
|
+
ExecErrorCode[ExecErrorCode["EventNotFound"] = 93] = "EventNotFound";
|
|
127
|
+
ExecErrorCode[ExecErrorCode["UnderlyingAlreadyAttached"] = 94] = "UnderlyingAlreadyAttached";
|
|
128
|
+
ExecErrorCode[ExecErrorCode["TooManyAttachedConditionals"] = 95] = "TooManyAttachedConditionals";
|
|
129
|
+
ExecErrorCode[ExecErrorCode["TooManyActiveEvents"] = 96] = "TooManyActiveEvents";
|
|
110
130
|
ExecErrorCode[ExecErrorCode["InternalError"] = 255] = "InternalError";
|
|
111
131
|
})(ExecErrorCode || (ExecErrorCode = {}));
|
|
112
132
|
const OPEN_INTEREST_LIMIT_EXCEEDED = {
|
|
@@ -168,14 +188,9 @@ const TABLE = {
|
|
|
168
188
|
name: "InvalidMarketConfig",
|
|
169
189
|
description: "invalid market configuration",
|
|
170
190
|
},
|
|
171
|
-
24: {
|
|
172
|
-
name: "ImpactMarketAlreadyExists",
|
|
173
|
-
description: "impact market already exists",
|
|
174
|
-
},
|
|
175
|
-
25: { name: "ImpactMarketNotFound", description: "impact market not found" },
|
|
176
191
|
26: {
|
|
177
192
|
name: "MarketClosedForTrading",
|
|
178
|
-
description: "order on a
|
|
193
|
+
description: "order on a conditional or binary book whose event is past settlement or resolved",
|
|
179
194
|
},
|
|
180
195
|
27: {
|
|
181
196
|
name: "BinaryPriceOutOfRange",
|
|
@@ -183,7 +198,7 @@ const TABLE = {
|
|
|
183
198
|
},
|
|
184
199
|
28: {
|
|
185
200
|
name: "InvalidResolution",
|
|
186
|
-
description: "
|
|
201
|
+
description: "resolve rejected — already resolved, before settlement, attachments still open, or outcome contradicts the oracle source",
|
|
187
202
|
},
|
|
188
203
|
29: {
|
|
189
204
|
name: "PositionLimitExceeded",
|
|
@@ -193,17 +208,13 @@ const TABLE = {
|
|
|
193
208
|
name: "OracleTimestampNotMonotonic",
|
|
194
209
|
description: "OracleUpdate publish_time_ms must be strictly greater than the last accepted update (audit B3)",
|
|
195
210
|
},
|
|
196
|
-
31: {
|
|
197
|
-
name: "TooManyActiveImpactMarkets",
|
|
198
|
-
description: "account would touch more impact markets than the scenario margin engine can enumerate (cap = 4)",
|
|
199
|
-
},
|
|
200
211
|
32: {
|
|
201
212
|
name: "SettlementPriceMismatch",
|
|
202
213
|
description: "net-delta margin grouping found legs of the same group with disagreeing settle prices (upstream data corruption)",
|
|
203
214
|
},
|
|
204
215
|
33: {
|
|
205
216
|
name: "OracleNotApplicable",
|
|
206
|
-
description: "OracleUpdate targets a market kind that doesn't take oracle prices (
|
|
217
|
+
description: "OracleUpdate targets a market kind that doesn't take oracle prices (conditional and binary books mark off the book)",
|
|
207
218
|
},
|
|
208
219
|
34: {
|
|
209
220
|
name: "PostOnlyWouldCross",
|
|
@@ -350,6 +361,80 @@ const TABLE = {
|
|
|
350
361
|
name: "InvalidAdminRegistry",
|
|
351
362
|
description: "proposed signer roster violates the registry invariants (threshold bounds, sorted unique members, roster size, version headroom)",
|
|
352
363
|
},
|
|
364
|
+
72: {
|
|
365
|
+
name: "BridgeReceiptRegistryInactive",
|
|
366
|
+
description: "receipt-gated withdrawal action while no operator receipt registry exists; the path fails closed",
|
|
367
|
+
},
|
|
368
|
+
73: {
|
|
369
|
+
name: "BridgeReceiptInvalid",
|
|
370
|
+
description: "operator quorum proof failed verification (structure, member count or signature)",
|
|
371
|
+
},
|
|
372
|
+
74: {
|
|
373
|
+
name: "BridgeReceiptMismatch",
|
|
374
|
+
description: "signed receipt does not bind to this withdrawal or deployment; the log names the field",
|
|
375
|
+
},
|
|
376
|
+
75: {
|
|
377
|
+
name: "WithdrawalBelowMinimum",
|
|
378
|
+
description: "net withdrawal amount is below the effective minimum (dust-griefing gate)",
|
|
379
|
+
},
|
|
380
|
+
76: {
|
|
381
|
+
name: "WithdrawalTerminalGated",
|
|
382
|
+
description: "retired legacy relayer terminal submitted at or above the receipt cutover",
|
|
383
|
+
},
|
|
384
|
+
82: {
|
|
385
|
+
name: "OracleGuardUnset",
|
|
386
|
+
description: "mark-dependent read refused: the oracle-guard gate is active and the market's max oracle age is unset",
|
|
387
|
+
},
|
|
388
|
+
83: {
|
|
389
|
+
name: "SubAccountNotFound",
|
|
390
|
+
description: "no sub-account for this master and id",
|
|
391
|
+
},
|
|
392
|
+
84: {
|
|
393
|
+
name: "SubAccountAlreadyExists",
|
|
394
|
+
description: "a sub-account with this master and id already exists",
|
|
395
|
+
},
|
|
396
|
+
85: {
|
|
397
|
+
name: "SubAccountTransferSameAccount",
|
|
398
|
+
description: "sub-account transfer from and to are the same account",
|
|
399
|
+
},
|
|
400
|
+
86: {
|
|
401
|
+
name: "SubAccountTransferBothChildren",
|
|
402
|
+
description: "neither side of the sub-account transfer is the master",
|
|
403
|
+
},
|
|
404
|
+
87: {
|
|
405
|
+
name: "SubAccountTransferInsufficientBalance",
|
|
406
|
+
description: "source sub-account balance is below the transfer amount",
|
|
407
|
+
},
|
|
408
|
+
88: {
|
|
409
|
+
name: "SubAccountIdZero",
|
|
410
|
+
description: "sub-account id zero is not valid",
|
|
411
|
+
},
|
|
412
|
+
89: {
|
|
413
|
+
name: "SubAccountTransferZeroAmount",
|
|
414
|
+
description: "sub-account transfer amount must be greater than zero",
|
|
415
|
+
},
|
|
416
|
+
90: {
|
|
417
|
+
name: "SubAccountsInactive",
|
|
418
|
+
description: "sub-account actions decode but the chain has not enabled them yet",
|
|
419
|
+
},
|
|
420
|
+
91: {
|
|
421
|
+
name: "WithdrawalPayoutLeaseActive",
|
|
422
|
+
description: "a live payout lease on this withdrawal is held by a different watcher",
|
|
423
|
+
},
|
|
424
|
+
92: { name: "EventAlreadyExists", description: "event id already exists" },
|
|
425
|
+
93: { name: "EventNotFound", description: "no event under this id" },
|
|
426
|
+
94: {
|
|
427
|
+
name: "UnderlyingAlreadyAttached",
|
|
428
|
+
description: "this underlying is already attached to the event",
|
|
429
|
+
},
|
|
430
|
+
95: {
|
|
431
|
+
name: "TooManyAttachedConditionals",
|
|
432
|
+
description: "the event's attachment cap is reached",
|
|
433
|
+
},
|
|
434
|
+
96: {
|
|
435
|
+
name: "TooManyActiveEvents",
|
|
436
|
+
description: "account would touch more events than the scenario margin engine can enumerate (per-account cap)",
|
|
437
|
+
},
|
|
353
438
|
255: { name: "InternalError", description: "unexpected runtime failure" },
|
|
354
439
|
};
|
|
355
440
|
/**
|
|
@@ -394,4 +479,15 @@ export function execErrorName(code, log) {
|
|
|
394
479
|
return "Ok";
|
|
395
480
|
return decodeExecError(code, log)?.name ?? "UnknownError";
|
|
396
481
|
}
|
|
482
|
+
/** Non-success gateway HTTP response; its unconsumed body remains available to callers. */
|
|
483
|
+
export class GatewayHttpError extends Error {
|
|
484
|
+
status;
|
|
485
|
+
response;
|
|
486
|
+
constructor(status, response) {
|
|
487
|
+
super(`Gateway request failed (${status})`);
|
|
488
|
+
this.status = status;
|
|
489
|
+
this.response = response;
|
|
490
|
+
this.name = "GatewayHttpError";
|
|
491
|
+
}
|
|
492
|
+
}
|
|
397
493
|
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAUH;;;;;;GAMG;AACH,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAUH;;;;;;GAMG;AACH,MAAM,CAAN,IAAY,aA4GX;AA5GD,WAAY,aAAa;IACvB,+DAAe,CAAA;IACf,mEAAiB,CAAA;IACjB,yDAAY,CAAA;IACZ,6EAAsB,CAAA;IACtB,yDAAY,CAAA;IACZ,iEAAgB,CAAA;IAChB,uEAAmB,CAAA;IACnB,+DAAe,CAAA;IACf,mEAAiB,CAAA;IACjB,wEAAoB,CAAA;IACpB,gFAAwB,CAAA;IACxB,8EAAuB,CAAA;IACvB,gFAAwB,CAAA;IACxB,8EAAuB,CAAA;IACvB,8FAA+B,CAAA;IAC/B,0EAAqB,CAAA;IACrB,0EAAqB,CAAA;IACrB,4EAAsB,CAAA;IACtB,8EAAuB,CAAA;IACvB,gFAAwB,CAAA;IACxB;6EACyE;IACzE,kEAAiB,CAAA;IACjB,gFAAwB,CAAA;IACxB,gFAAwB,CAAA;IACxB,4EAA4E;IAC5E,sFAA2B,CAAA;IAC3B,oFAA0B,CAAA;IAC1B,4EAAsB,CAAA;IACtB,oFAA0B,CAAA;IAC1B,gGAAgC,CAAA;IAChC,qEAAqE;IACrE,wFAA4B,CAAA;IAC5B,gFAAwB,CAAA;IACxB,8EAAuB,CAAA;IACvB,wFAA4B,CAAA;IAC5B,8EAAuB,CAAA;IACvB,gEAAgB,CAAA;IAChB,4FAA8B,CAAA;IAC9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O,iBAAiB,CAAC;IAC3B,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;AAC7B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,GAAY;IACtD,IAAI,IAAI,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAC5B,OAAO,eAAe,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,IAAI,IAAI,cAAc,CAAC;AAC5D,CAAC;AAED,2FAA2F;AAC3F,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAEvB;IACA;IAFlB,YACkB,MAAc,EACd,QAAkB;QAElC,KAAK,CAAC,2BAA2B,MAAM,GAAG,CAAC,CAAC;QAH5B,WAAM,GAAN,MAAM,CAAQ;QACd,aAAQ,GAAR,QAAQ,CAAU;QAGlC,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/** Channels exposed by the gateway's multiplexed `/ws` feed. */
|
|
2
|
+
export type FeedChannel = "orderbook" | "trades" | "accountEvents";
|
|
3
|
+
/** One aggregated book level on the wire: `[price, totalQuantity, orderCount]`.
|
|
4
|
+
* Price is micro-USDC, quantity integer lots. */
|
|
5
|
+
export type FeedOrderbookLevel = [
|
|
6
|
+
price: number,
|
|
7
|
+
totalQuantity: number,
|
|
8
|
+
orderCount: number
|
|
9
|
+
];
|
|
10
|
+
/** Full-book frame sent immediately on `orderbook` subscribe. */
|
|
11
|
+
export interface OrderbookSnapshotFrame {
|
|
12
|
+
channel: "orderbook";
|
|
13
|
+
type: "snapshot";
|
|
14
|
+
market: number;
|
|
15
|
+
bids: FeedOrderbookLevel[];
|
|
16
|
+
asks: FeedOrderbookLevel[];
|
|
17
|
+
}
|
|
18
|
+
/** Single-level delta on the `orderbook` channel. `totalQuantity === 0`
|
|
19
|
+
* (and `orderCount === 0`) means the level was emptied. */
|
|
20
|
+
export interface OrderbookUpdateFrame {
|
|
21
|
+
channel: "orderbook";
|
|
22
|
+
type: "update";
|
|
23
|
+
market: number;
|
|
24
|
+
side: "buy" | "sell";
|
|
25
|
+
price: number;
|
|
26
|
+
totalQuantity: number;
|
|
27
|
+
orderCount: number;
|
|
28
|
+
}
|
|
29
|
+
export type OrderbookFrame = OrderbookSnapshotFrame | OrderbookUpdateFrame;
|
|
30
|
+
/** A public fill on the `trades` channel. Price/quantity are decimal
|
|
31
|
+
* strings (micro-USDC / lots); `payload` is the full fill record. */
|
|
32
|
+
export interface TradeFrame {
|
|
33
|
+
channel: "trades";
|
|
34
|
+
type: "trade";
|
|
35
|
+
market: number;
|
|
36
|
+
fillId: string;
|
|
37
|
+
makerSide: "buy" | "sell";
|
|
38
|
+
price: string;
|
|
39
|
+
quantity: string;
|
|
40
|
+
payload: Record<string, string>;
|
|
41
|
+
}
|
|
42
|
+
/** Account state snapshot sent on `accountEvents` subscribe, proxied from
|
|
43
|
+
* the node REST `GET /v1/account/{owner}`. `account.data` is the base64
|
|
44
|
+
* msgpack envelope — decode with the same path as `queryAccount`. */
|
|
45
|
+
export interface AccountSnapshotFrame {
|
|
46
|
+
channel: "accountEvents";
|
|
47
|
+
type: "snapshot";
|
|
48
|
+
owner: string;
|
|
49
|
+
account: unknown;
|
|
50
|
+
}
|
|
51
|
+
/** A live engine event for a subscribed owner. `type` is the gateway's
|
|
52
|
+
* normalised family (`"order_update"`, `"fill"`, …); `eventType` is the
|
|
53
|
+
* original engine event name (`"order_placed"`, `"trade_executed"`, …). */
|
|
54
|
+
export interface AccountEventFrame {
|
|
55
|
+
channel: "accountEvents";
|
|
56
|
+
type: string;
|
|
57
|
+
eventType: string;
|
|
58
|
+
owner: string;
|
|
59
|
+
height: number;
|
|
60
|
+
payload: Record<string, unknown>;
|
|
61
|
+
}
|
|
62
|
+
export type AccountFrame = AccountSnapshotFrame | AccountEventFrame;
|
|
63
|
+
/** Any channel-tagged data frame delivered to a subscriber. */
|
|
64
|
+
export type FeedFrame = OrderbookFrame | TradeFrame | AccountFrame;
|
|
65
|
+
/** Error frame for a rejected control message or channel subscription.
|
|
66
|
+
* Correlates to the offending request via `id` when present. */
|
|
67
|
+
export interface FeedErrorFrame {
|
|
68
|
+
type: "error";
|
|
69
|
+
id?: number;
|
|
70
|
+
channel?: string;
|
|
71
|
+
code?: number;
|
|
72
|
+
error: string;
|
|
73
|
+
}
|
|
74
|
+
/** Connection state of a {@link GatewayFeed}. */
|
|
75
|
+
export type FeedState = "closed" | "connecting" | "open" | "reconnecting";
|
|
76
|
+
//# sourceMappingURL=feed-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feed-types.d.ts","sourceRoot":"","sources":["../src/feed-types.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,QAAQ,GAAG,eAAe,CAAC;AAEnE;kDACkD;AAClD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,MAAM;IACb,aAAa,EAAE,MAAM;IACrB,UAAU,EAAE,MAAM;CACnB,CAAC;AAEF,iEAAiE;AACjE,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,WAAW,CAAC;IACrB,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,kBAAkB,EAAE,CAAC;IAC3B,IAAI,EAAE,kBAAkB,EAAE,CAAC;CAC5B;AAED;4DAC4D;AAC5D,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,WAAW,CAAC;IACrB,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,cAAc,GAAG,sBAAsB,GAAG,oBAAoB,CAAC;AA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3,"file":"feed-types.js","sourceRoot":"","sources":["../src/feed-types.ts"],"names":[],"mappings":""}
|
package/dist/feed.d.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type { AccountFrame, FeedChannel, FeedErrorFrame, FeedFrame, FeedState, OrderbookFrame, TradeFrame } from "./feed-types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Minimal structural view of a WebSocket the feed needs. Both the browser
|
|
4
|
+
* `WebSocket` and Node's `ws` package satisfy this via the `onmessage`
|
|
5
|
+
* setter API.
|
|
6
|
+
*/
|
|
7
|
+
export interface WebSocketLike {
|
|
8
|
+
send(data: string): void;
|
|
9
|
+
close(): void;
|
|
10
|
+
onopen: ((ev: unknown) => void) | null;
|
|
11
|
+
onclose: ((ev: unknown) => void) | null;
|
|
12
|
+
onerror: ((ev: unknown) => void) | null;
|
|
13
|
+
onmessage: ((ev: {
|
|
14
|
+
data: unknown;
|
|
15
|
+
}) => void) | null;
|
|
16
|
+
}
|
|
17
|
+
/** Constructs a {@link WebSocketLike}. `options` is passed as the second
|
|
18
|
+
* argument when present (Node `ws` accepts `{ headers }`); browsers ignore
|
|
19
|
+
* it because we only forward options to an injected implementation. */
|
|
20
|
+
export type WebSocketFactory = (url: string, options?: {
|
|
21
|
+
headers?: Record<string, string>;
|
|
22
|
+
}) => WebSocketLike;
|
|
23
|
+
/** Existing signed account-subscription wire fields. */
|
|
24
|
+
export interface AccountFeedAuth {
|
|
25
|
+
public_key: string;
|
|
26
|
+
signature: string;
|
|
27
|
+
timestamp_ms: number;
|
|
28
|
+
after_id?: number;
|
|
29
|
+
}
|
|
30
|
+
/** An empty result explicitly selects an unsigned subscription on open gateways. */
|
|
31
|
+
export type AccountAuthProvider = (owner: string) => Promise<AccountFeedAuth | Record<string, never>>;
|
|
32
|
+
export interface GatewayFeedOptions {
|
|
33
|
+
/** Called on every account subscribe/reconnect; stale async completions are discarded. */
|
|
34
|
+
accountAuth?: AccountAuthProvider;
|
|
35
|
+
/** Feed URL, e.g. `wss://api.dev.proof.trade/ws`. */
|
|
36
|
+
url: string;
|
|
37
|
+
/** Upgrade headers (e.g. `{ "X-Api-Key": key }`). Only applied when a
|
|
38
|
+
* custom `webSocketFactory`/`WebSocketImpl` is supplied — the global
|
|
39
|
+
* browser `WebSocket` has no header support and is constructed bare. */
|
|
40
|
+
headers?: Record<string, string>;
|
|
41
|
+
/** App-level ping cadence in ms; 0 disables the heartbeat. Default 15000. */
|
|
42
|
+
pingIntervalMs?: number;
|
|
43
|
+
/** Reconnect if no `pong` arrives within this many ms of a ping. Default 10000. */
|
|
44
|
+
pongTimeoutMs?: number;
|
|
45
|
+
/** First reconnect backoff in ms, doubled each attempt up to `maxBackoffMs`. */
|
|
46
|
+
minBackoffMs?: number;
|
|
47
|
+
/** Backoff ceiling in ms. Default 10000. */
|
|
48
|
+
maxBackoffMs?: number;
|
|
49
|
+
/** Inject a WebSocket implementation (Node `ws`, or a fake in tests). */
|
|
50
|
+
WebSocketImpl?: new (url: string, options?: unknown) => WebSocketLike;
|
|
51
|
+
/** Full control over socket construction; takes precedence over `WebSocketImpl`. */
|
|
52
|
+
webSocketFactory?: WebSocketFactory;
|
|
53
|
+
/** Schedule a timer; injectable for deterministic tests. Defaults to `setTimeout`. */
|
|
54
|
+
setTimeoutImpl?: (fn: () => void, ms: number) => unknown;
|
|
55
|
+
clearTimeoutImpl?: (handle: unknown) => void;
|
|
56
|
+
/** Errors not tied to a single subscription (transport, unparseable frames,
|
|
57
|
+
* errors whose `id` matched no live subscription). */
|
|
58
|
+
onError?: (err: FeedErrorFrame | Error) => void;
|
|
59
|
+
/** Connection lifecycle transitions. */
|
|
60
|
+
onStateChange?: (state: FeedState) => void;
|
|
61
|
+
}
|
|
62
|
+
/** Handler for a channel's data frames; narrowed per `subscribe*` helper. */
|
|
63
|
+
type FrameHandler = (frame: FeedFrame) => void;
|
|
64
|
+
/**
|
|
65
|
+
* Lifecycle manager for the gateway's multiplexed `/ws` feed.
|
|
66
|
+
*
|
|
67
|
+
* One socket carries every channel. The class owns the full lifecycle so
|
|
68
|
+
* callers only deal with subscriptions:
|
|
69
|
+
*
|
|
70
|
+
* - **lazy connect** — the socket opens on the first `subscribe` and closes
|
|
71
|
+
* when the last subscription is disposed.
|
|
72
|
+
* - **auto-reconnect** — on an unexpected close it reconnects with
|
|
73
|
+
* exponential backoff and **replays every active subscription**, so a
|
|
74
|
+
* fresh snapshot arrives. Missed live events are not replayed.
|
|
75
|
+
* - **heartbeat** — an app-level `ping` runs on an interval; a missing
|
|
76
|
+
* `pong` forces a reconnect, catching half-open sockets the OS hasn't
|
|
77
|
+
* torn down.
|
|
78
|
+
*
|
|
79
|
+
* `subscribe` returns a disposer; the socket is reference-counted across all
|
|
80
|
+
* subscriptions. Construct via {@link ExchangeClient.feed} rather than
|
|
81
|
+
* directly so URL/auth derive from the client.
|
|
82
|
+
*/
|
|
83
|
+
export declare class GatewayFeed {
|
|
84
|
+
private readonly accountAuth?;
|
|
85
|
+
private readonly url;
|
|
86
|
+
private readonly headers?;
|
|
87
|
+
private readonly pingIntervalMs;
|
|
88
|
+
private readonly pongTimeoutMs;
|
|
89
|
+
private readonly minBackoffMs;
|
|
90
|
+
private readonly maxBackoffMs;
|
|
91
|
+
private readonly factory;
|
|
92
|
+
private readonly setTimer;
|
|
93
|
+
private readonly clearTimer;
|
|
94
|
+
private readonly onError?;
|
|
95
|
+
private readonly onStateChange?;
|
|
96
|
+
private ws;
|
|
97
|
+
private state;
|
|
98
|
+
private nextId;
|
|
99
|
+
private readonly subs;
|
|
100
|
+
/** True between `close()` and the next `subscribe` — suppresses reconnect. */
|
|
101
|
+
private closedByUser;
|
|
102
|
+
private reconnectAttempts;
|
|
103
|
+
private reconnectTimer;
|
|
104
|
+
private pingTimer;
|
|
105
|
+
private pongTimer;
|
|
106
|
+
private awaitingPong;
|
|
107
|
+
constructor(opts: GatewayFeedOptions);
|
|
108
|
+
/** Current connection state. */
|
|
109
|
+
get connectionState(): FeedState;
|
|
110
|
+
/** Number of distinct active channel subscriptions. */
|
|
111
|
+
get subscriptionCount(): number;
|
|
112
|
+
subscribeOrderbook(market: number, onFrame: (frame: OrderbookFrame) => void): () => void;
|
|
113
|
+
subscribeTrades(market: number, onFrame: (frame: TradeFrame) => void): () => void;
|
|
114
|
+
/** Subscribe to `accountEvents` for `owner` (lower-hex, 20 bytes). `params`
|
|
115
|
+
* carries any signed-auth fields already serialised to wire (snake_case). */
|
|
116
|
+
subscribeAccount(owner: string, onFrame: (frame: AccountFrame) => void, authParams?: Record<string, unknown> | AccountAuthProvider): () => void;
|
|
117
|
+
/**
|
|
118
|
+
* Unsubscribe a whole channel by key, dropping **all** of its listeners —
|
|
119
|
+
* the by-key counterpart to the per-listener disposer returned by
|
|
120
|
+
* `subscribe*`. Returns true if a subscription was present. Sends the wire
|
|
121
|
+
* `unsubscribe` and closes the socket if no subscriptions remain.
|
|
122
|
+
*/
|
|
123
|
+
unsubscribeOrderbook(market: number): boolean;
|
|
124
|
+
unsubscribeTrades(market: number): boolean;
|
|
125
|
+
unsubscribeAccount(owner: string): boolean;
|
|
126
|
+
/** Low-level unsubscribe by channel + key params (`market` / `owner`). */
|
|
127
|
+
unsubscribe(channel: FeedChannel, params: Record<string, unknown>): boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Low-level subscribe. `params` must use the gateway's wire keys
|
|
130
|
+
* (`market`, `owner`, `public_key`, …). Returns a disposer
|
|
131
|
+
* that drops this listener and unsubscribes the channel when its last
|
|
132
|
+
* listener goes away.
|
|
133
|
+
*/
|
|
134
|
+
subscribe(channel: FeedChannel, params: Record<string, unknown>, onFrame: FrameHandler, auth?: AccountAuthProvider): () => void;
|
|
135
|
+
/** Remove a subscription record: emit the wire `unsubscribe` when open, and
|
|
136
|
+
* close the socket once the last subscription is gone. Shared by the
|
|
137
|
+
* per-listener disposer and the by-key `unsubscribe*` methods. */
|
|
138
|
+
private dropRecord;
|
|
139
|
+
/** Tear down the socket and all subscriptions. Suppresses reconnect until
|
|
140
|
+
* the next `subscribe`. Idempotent. */
|
|
141
|
+
close(): void;
|
|
142
|
+
private ensureConnected;
|
|
143
|
+
private connect;
|
|
144
|
+
private teardownSocket;
|
|
145
|
+
private scheduleReconnect;
|
|
146
|
+
private clearReconnect;
|
|
147
|
+
private startHeartbeat;
|
|
148
|
+
private sendPing;
|
|
149
|
+
private stopHeartbeat;
|
|
150
|
+
private sendSubscribe;
|
|
151
|
+
private sendUnsubscribe;
|
|
152
|
+
private send;
|
|
153
|
+
private handleMessage;
|
|
154
|
+
private dispatchError;
|
|
155
|
+
private setState;
|
|
156
|
+
}
|
|
157
|
+
export {};
|
|
158
|
+
//# sourceMappingURL=feed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feed.d.ts","sourceRoot":"","sources":["../src/feed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,cAAc,EACd,SAAS,EACT,SAAS,EACT,cAAc,EACd,UAAU,EACX,MAAM,iBAAiB,CAAC;AAEzB;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,KAAK,IAAI,IAAI,CAAC;IACd,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,OAAO,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IACvC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,OAAO,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IACxC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,OAAO,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IACxC,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;CACrD;AAED;;wEAEwE;AACxE,MAAM,MAAM,gBAAgB,GAAG,CAC7B,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE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