@lightconexyz/lightcone-sdk 0.7.1 → 0.8.1-rc.2

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.
Files changed (109) hide show
  1. package/README.md +20 -0
  2. package/dist/auth/client.d.ts +3 -3
  3. package/dist/auth/client.d.ts.map +1 -1
  4. package/dist/auth/client.js +19 -38
  5. package/dist/auth/client.js.map +1 -1
  6. package/dist/auth/index.d.ts +95 -54
  7. package/dist/auth/index.d.ts.map +1 -1
  8. package/dist/auth/index.js +82 -7
  9. package/dist/auth/index.js.map +1 -1
  10. package/dist/client.d.ts +0 -2
  11. package/dist/client.d.ts.map +1 -1
  12. package/dist/client.js +0 -4
  13. package/dist/client.js.map +1 -1
  14. package/dist/domain/index.d.ts +0 -1
  15. package/dist/domain/index.d.ts.map +1 -1
  16. package/dist/domain/index.js +1 -2
  17. package/dist/domain/index.js.map +1 -1
  18. package/dist/domain/market/tokens.d.ts +2 -0
  19. package/dist/domain/market/tokens.d.ts.map +1 -1
  20. package/dist/domain/market/tokens.js +8 -0
  21. package/dist/domain/market/tokens.js.map +1 -1
  22. package/dist/domain/market/wire.d.ts +1 -0
  23. package/dist/domain/market/wire.d.ts.map +1 -1
  24. package/dist/domain/market/wire.js.map +1 -1
  25. package/dist/domain/metrics/client.d.ts +8 -2
  26. package/dist/domain/metrics/client.d.ts.map +1 -1
  27. package/dist/domain/metrics/client.js +48 -1
  28. package/dist/domain/metrics/client.js.map +1 -1
  29. package/dist/domain/metrics/wire.d.ts +107 -4
  30. package/dist/domain/metrics/wire.d.ts.map +1 -1
  31. package/dist/domain/metrics/wire.js.map +1 -1
  32. package/dist/domain/order/client.d.ts +2 -0
  33. package/dist/domain/order/client.d.ts.map +1 -1
  34. package/dist/domain/order/client.js.map +1 -1
  35. package/dist/domain/orderbook/aggregation.d.ts +50 -0
  36. package/dist/domain/orderbook/aggregation.d.ts.map +1 -0
  37. package/dist/domain/orderbook/aggregation.js +85 -0
  38. package/dist/domain/orderbook/aggregation.js.map +1 -0
  39. package/dist/domain/orderbook/client.d.ts +11 -1
  40. package/dist/domain/orderbook/client.d.ts.map +1 -1
  41. package/dist/domain/orderbook/client.js +24 -3
  42. package/dist/domain/orderbook/client.js.map +1 -1
  43. package/dist/domain/orderbook/index.d.ts +1 -0
  44. package/dist/domain/orderbook/index.d.ts.map +1 -1
  45. package/dist/domain/orderbook/index.js +1 -0
  46. package/dist/domain/orderbook/index.js.map +1 -1
  47. package/dist/domain/orderbook/state.d.ts +29 -31
  48. package/dist/domain/orderbook/state.d.ts.map +1 -1
  49. package/dist/domain/orderbook/state.js +20 -67
  50. package/dist/domain/orderbook/state.js.map +1 -1
  51. package/dist/domain/orderbook/wire.d.ts +32 -0
  52. package/dist/domain/orderbook/wire.d.ts.map +1 -1
  53. package/dist/domain/orderbook/wire.js.map +1 -1
  54. package/dist/env.d.ts +18 -3
  55. package/dist/env.d.ts.map +1 -1
  56. package/dist/env.js +28 -4
  57. package/dist/env.js.map +1 -1
  58. package/dist/http/client.d.ts +1 -4
  59. package/dist/http/client.d.ts.map +1 -1
  60. package/dist/http/client.js +56 -22
  61. package/dist/http/client.js.map +1 -1
  62. package/dist/index.d.ts +3 -2
  63. package/dist/index.d.ts.map +1 -1
  64. package/dist/index.js +8 -1
  65. package/dist/index.js.map +1 -1
  66. package/dist/prelude.d.ts +9 -8
  67. package/dist/prelude.d.ts.map +1 -1
  68. package/dist/prelude.js +20 -4
  69. package/dist/prelude.js.map +1 -1
  70. package/dist/shared/fmt/index.d.ts +1 -0
  71. package/dist/shared/fmt/index.d.ts.map +1 -1
  72. package/dist/shared/fmt/index.js +2 -1
  73. package/dist/shared/fmt/index.js.map +1 -1
  74. package/dist/shared/fmt/str.d.ts +8 -0
  75. package/dist/shared/fmt/str.d.ts.map +1 -0
  76. package/dist/shared/fmt/str.js +17 -0
  77. package/dist/shared/fmt/str.js.map +1 -0
  78. package/dist/shared/index.d.ts +1 -1
  79. package/dist/shared/index.d.ts.map +1 -1
  80. package/dist/shared/index.js +11 -1
  81. package/dist/shared/index.js.map +1 -1
  82. package/dist/shared/rejection.d.ts.map +1 -1
  83. package/dist/shared/rejection.js +11 -0
  84. package/dist/shared/rejection.js.map +1 -1
  85. package/dist/shared/types.d.ts +41 -0
  86. package/dist/shared/types.d.ts.map +1 -1
  87. package/dist/shared/types.js +85 -1
  88. package/dist/shared/types.js.map +1 -1
  89. package/dist/ws/index.d.ts +25 -2
  90. package/dist/ws/index.d.ts.map +1 -1
  91. package/dist/ws/index.js +23 -2
  92. package/dist/ws/index.js.map +1 -1
  93. package/dist/ws/subscriptions.d.ts +12 -0
  94. package/dist/ws/subscriptions.d.ts.map +1 -1
  95. package/dist/ws/subscriptions.js +14 -4
  96. package/dist/ws/subscriptions.js.map +1 -1
  97. package/package.json +1 -1
  98. package/dist/domain/admin/client.d.ts +0 -63
  99. package/dist/domain/admin/client.d.ts.map +0 -1
  100. package/dist/domain/admin/client.js +0 -234
  101. package/dist/domain/admin/client.js.map +0 -1
  102. package/dist/domain/admin/index.d.ts +0 -16
  103. package/dist/domain/admin/index.d.ts.map +0 -1
  104. package/dist/domain/admin/index.js +0 -19
  105. package/dist/domain/admin/index.js.map +0 -1
  106. package/dist/domain/admin/wire.d.ts +0 -450
  107. package/dist/domain/admin/wire.d.ts.map +0 -1
  108. package/dist/domain/admin/wire.js +0 -3
  109. package/dist/domain/admin/wire.js.map +0 -1
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.shorten = shorten;
4
+ /**
5
+ * Shorten a string to its first and last `qty / 2` characters joined by an
6
+ * ellipsis — e.g. `shorten("FRGkJho6fY7XivWsEBjousTaZBT6eUBkkrDyCN4nWcPR", 8)`
7
+ * → `"FRGk...WcPR"`. Strings of `qty` characters or fewer are returned
8
+ * unchanged.
9
+ */
10
+ function shorten(value, qty) {
11
+ if (value.length > qty) {
12
+ const charsToShow = Math.floor(qty / 2);
13
+ return `${value.slice(0, charsToShow)}...${value.slice(value.length - charsToShow)}`;
14
+ }
15
+ return value;
16
+ }
17
+ //# sourceMappingURL=str.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"str.js","sourceRoot":"","sources":["../../../src/shared/fmt/str.ts"],"names":[],"mappings":";;AAMA,0BAMC;AAZD;;;;;GAKG;AACH,SAAgB,OAAO,CAAC,KAAa,EAAE,GAAW;IAChD,IAAI,KAAK,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;QACvB,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;QACxC,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,MAAM,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,WAAW,CAAC,EAAE,CAAC;IACvF,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/**\n * Shorten a string to its first and last `qty / 2` characters joined by an\n * ellipsis — e.g. `shorten(\"FRGkJho6fY7XivWsEBjousTaZBT6eUBkkrDyCN4nWcPR\", 8)`\n * → `\"FRGk...WcPR\"`. Strings of `qty` characters or fewer are returned\n * unchanged.\n */\nexport function shorten(value: string, qty: number): string {\n if (value.length > qty) {\n const charsToShow = Math.floor(qty / 2);\n return `${value.slice(0, charsToShow)}...${value.slice(value.length - charsToShow)}`;\n }\n return value;\n}\n"]}
@@ -1,4 +1,4 @@
1
- export { asOrderBookId, asPubkeyStr, DepositSource, deriveOrderbookId, parseResolution, parseSide, resolutionSeconds, sideLabel, OrderUpdateType, Resolution, Side, TimeInForce, TriggerResultStatus, TriggerStatus, TriggerType, TriggerUpdateType, type Branded, type OrderBookId, type PubkeyStr, type SubmitOrderRequest, } from "./types";
1
+ export { allDenominators, applyImpactProtection, asOrderBookId, asPubkeyStr, convertDenomination, Denominator, denominatorDepositSymbol, denominatorSymbol, denominatorToken, DepositSource, deriveOrderbookId, parseResolution, parseSide, receiveDenominator, resolutionSeconds, sideLabel, spendDenominator, toOrderSide, OrderUpdateType, Resolution, Side, TimeInForce, TriggerResultStatus, TriggerStatus, TriggerType, TriggerUpdateType, type Branded, type OrderBookId, type PubkeyStr, type SubmitOrderRequest, } from "./types";
2
2
  export { ApiRejectedDetails, isApiResponse, type ApiRejectedDetailsWire, type ApiResponse, } from "./api_response";
3
3
  export { RejectionCode } from "./rejection";
4
4
  export { formatDecimal, isZero, parseDecimal } from "./price";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,SAAS,EACT,iBAAiB,EACjB,SAAS,EACT,eAAe,EACf,UAAU,EACV,IAAI,EACJ,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,kBAAkB,GACxB,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,KAAK,sBAAsB,EAC3B,KAAK,WAAW,GACjB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE9D,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,oBAAoB,EACpB,YAAY,EACZ,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,aAAa,GACnB,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,oBAAoB,IAAI,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAErE,OAAO,EACL,kBAAkB,EAClB,KAAK,cAAc,EACnB,KAAK,eAAe,GACrB,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,WAAW,EACX,mBAAmB,EACnB,WAAW,EACX,wBAAwB,EACxB,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,SAAS,EACT,kBAAkB,EAClB,iBAAiB,EACjB,SAAS,EACT,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,UAAU,EACV,IAAI,EACJ,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,kBAAkB,GACxB,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,KAAK,sBAAsB,EAC3B,KAAK,WAAW,GACjB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE9D,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,oBAAoB,EACpB,YAAY,EACZ,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,aAAa,GACnB,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,oBAAoB,IAAI,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAErE,OAAO,EACL,kBAAkB,EAClB,KAAK,cAAc,EACnB,KAAK,eAAe,GACrB,MAAM,WAAW,CAAC"}
@@ -1,15 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isUserCancellation = exports.scalePriceSizeV1 = exports.ScalingError = exports.scalePriceSizeLegacy = exports.scalePriceSize = exports.alignPriceToTick = exports.parseDecimal = exports.isZero = exports.formatDecimal = exports.RejectionCode = exports.isApiResponse = exports.ApiRejectedDetails = exports.TriggerUpdateType = exports.TriggerType = exports.TriggerStatus = exports.TriggerResultStatus = exports.TimeInForce = exports.Side = exports.Resolution = exports.OrderUpdateType = exports.sideLabel = exports.resolutionSeconds = exports.parseSide = exports.parseResolution = exports.deriveOrderbookId = exports.DepositSource = exports.asPubkeyStr = exports.asOrderBookId = void 0;
3
+ exports.isUserCancellation = exports.scalePriceSizeV1 = exports.ScalingError = exports.scalePriceSizeLegacy = exports.scalePriceSize = exports.alignPriceToTick = exports.parseDecimal = exports.isZero = exports.formatDecimal = exports.RejectionCode = exports.isApiResponse = exports.ApiRejectedDetails = exports.TriggerUpdateType = exports.TriggerType = exports.TriggerStatus = exports.TriggerResultStatus = exports.TimeInForce = exports.Side = exports.Resolution = exports.OrderUpdateType = exports.toOrderSide = exports.spendDenominator = exports.sideLabel = exports.resolutionSeconds = exports.receiveDenominator = exports.parseSide = exports.parseResolution = exports.deriveOrderbookId = exports.DepositSource = exports.denominatorToken = exports.denominatorSymbol = exports.denominatorDepositSymbol = exports.Denominator = exports.convertDenomination = exports.asPubkeyStr = exports.asOrderBookId = exports.applyImpactProtection = exports.allDenominators = void 0;
4
4
  var types_1 = require("./types");
5
+ Object.defineProperty(exports, "allDenominators", { enumerable: true, get: function () { return types_1.allDenominators; } });
6
+ Object.defineProperty(exports, "applyImpactProtection", { enumerable: true, get: function () { return types_1.applyImpactProtection; } });
5
7
  Object.defineProperty(exports, "asOrderBookId", { enumerable: true, get: function () { return types_1.asOrderBookId; } });
6
8
  Object.defineProperty(exports, "asPubkeyStr", { enumerable: true, get: function () { return types_1.asPubkeyStr; } });
9
+ Object.defineProperty(exports, "convertDenomination", { enumerable: true, get: function () { return types_1.convertDenomination; } });
10
+ Object.defineProperty(exports, "Denominator", { enumerable: true, get: function () { return types_1.Denominator; } });
11
+ Object.defineProperty(exports, "denominatorDepositSymbol", { enumerable: true, get: function () { return types_1.denominatorDepositSymbol; } });
12
+ Object.defineProperty(exports, "denominatorSymbol", { enumerable: true, get: function () { return types_1.denominatorSymbol; } });
13
+ Object.defineProperty(exports, "denominatorToken", { enumerable: true, get: function () { return types_1.denominatorToken; } });
7
14
  Object.defineProperty(exports, "DepositSource", { enumerable: true, get: function () { return types_1.DepositSource; } });
8
15
  Object.defineProperty(exports, "deriveOrderbookId", { enumerable: true, get: function () { return types_1.deriveOrderbookId; } });
9
16
  Object.defineProperty(exports, "parseResolution", { enumerable: true, get: function () { return types_1.parseResolution; } });
10
17
  Object.defineProperty(exports, "parseSide", { enumerable: true, get: function () { return types_1.parseSide; } });
18
+ Object.defineProperty(exports, "receiveDenominator", { enumerable: true, get: function () { return types_1.receiveDenominator; } });
11
19
  Object.defineProperty(exports, "resolutionSeconds", { enumerable: true, get: function () { return types_1.resolutionSeconds; } });
12
20
  Object.defineProperty(exports, "sideLabel", { enumerable: true, get: function () { return types_1.sideLabel; } });
21
+ Object.defineProperty(exports, "spendDenominator", { enumerable: true, get: function () { return types_1.spendDenominator; } });
22
+ Object.defineProperty(exports, "toOrderSide", { enumerable: true, get: function () { return types_1.toOrderSide; } });
13
23
  Object.defineProperty(exports, "OrderUpdateType", { enumerable: true, get: function () { return types_1.OrderUpdateType; } });
14
24
  Object.defineProperty(exports, "Resolution", { enumerable: true, get: function () { return types_1.Resolution; } });
15
25
  Object.defineProperty(exports, "Side", { enumerable: true, get: function () { return types_1.Side; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":";;;AAAA,iCAqBiB;AApBf,sGAAA,aAAa,OAAA;AACb,oGAAA,WAAW,OAAA;AACX,sGAAA,aAAa,OAAA;AACb,0GAAA,iBAAiB,OAAA;AACjB,wGAAA,eAAe,OAAA;AACf,kGAAA,SAAS,OAAA;AACT,0GAAA,iBAAiB,OAAA;AACjB,kGAAA,SAAS,OAAA;AACT,wGAAA,eAAe,OAAA;AACf,mGAAA,UAAU,OAAA;AACV,6FAAA,IAAI,OAAA;AACJ,oGAAA,WAAW,OAAA;AACX,4GAAA,mBAAmB,OAAA;AACnB,sGAAA,aAAa,OAAA;AACb,oGAAA,WAAW,OAAA;AACX,0GAAA,iBAAiB,OAAA;AAOnB,+CAKwB;AAJtB,kHAAA,kBAAkB,OAAA;AAClB,6GAAA,aAAa,OAAA;AAKf,yCAA4C;AAAnC,0GAAA,aAAa,OAAA;AAEtB,iCAA8D;AAArD,sGAAA,aAAa,OAAA;AAAE,+FAAA,MAAM,OAAA;AAAE,qGAAA,YAAY,OAAA;AAE5C,qCAQmB;AAPjB,2GAAA,gBAAgB,OAAA;AAChB,yGAAA,cAAc,OAAA;AACd,+GAAA,oBAAoB,OAAA;AACpB,uGAAA,YAAY,OAAA;AAMd,oCAAoC;AACpC,qCAAqE;AAA5D,2GAAA,oBAAoB,OAAoB;AAEjD,qCAImB;AAHjB,6GAAA,kBAAkB,OAAA","sourcesContent":["export {\n asOrderBookId,\n asPubkeyStr,\n DepositSource,\n deriveOrderbookId,\n parseResolution,\n parseSide,\n resolutionSeconds,\n sideLabel,\n OrderUpdateType,\n Resolution,\n Side,\n TimeInForce,\n TriggerResultStatus,\n TriggerStatus,\n TriggerType,\n TriggerUpdateType,\n type Branded,\n type OrderBookId,\n type PubkeyStr,\n type SubmitOrderRequest,\n} from \"./types\";\n\nexport {\n ApiRejectedDetails,\n isApiResponse,\n type ApiRejectedDetailsWire,\n type ApiResponse,\n} from \"./api_response\";\n\nexport { RejectionCode } from \"./rejection\";\n\nexport { formatDecimal, isZero, parseDecimal } from \"./price\";\n\nexport {\n alignPriceToTick,\n scalePriceSize,\n scalePriceSizeLegacy,\n ScalingError,\n type LegacyScaledAmounts,\n type OrderbookDecimals,\n type ScaledAmounts,\n} from \"./scaling\";\n\n// Backward-compatible name from v1.\nexport { scalePriceSizeLegacy as scalePriceSizeV1 } from \"./scaling\";\n\nexport {\n isUserCancellation,\n type ExternalSigner,\n type SigningStrategy,\n} from \"./signing\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":";;;AAAA,iCA+BiB;AA9Bf,wGAAA,eAAe,OAAA;AACf,8GAAA,qBAAqB,OAAA;AACrB,sGAAA,aAAa,OAAA;AACb,oGAAA,WAAW,OAAA;AACX,4GAAA,mBAAmB,OAAA;AACnB,oGAAA,WAAW,OAAA;AACX,iHAAA,wBAAwB,OAAA;AACxB,0GAAA,iBAAiB,OAAA;AACjB,yGAAA,gBAAgB,OAAA;AAChB,sGAAA,aAAa,OAAA;AACb,0GAAA,iBAAiB,OAAA;AACjB,wGAAA,eAAe,OAAA;AACf,kGAAA,SAAS,OAAA;AACT,2GAAA,kBAAkB,OAAA;AAClB,0GAAA,iBAAiB,OAAA;AACjB,kGAAA,SAAS,OAAA;AACT,yGAAA,gBAAgB,OAAA;AAChB,oGAAA,WAAW,OAAA;AACX,wGAAA,eAAe,OAAA;AACf,mGAAA,UAAU,OAAA;AACV,6FAAA,IAAI,OAAA;AACJ,oGAAA,WAAW,OAAA;AACX,4GAAA,mBAAmB,OAAA;AACnB,sGAAA,aAAa,OAAA;AACb,oGAAA,WAAW,OAAA;AACX,0GAAA,iBAAiB,OAAA;AAOnB,+CAKwB;AAJtB,kHAAA,kBAAkB,OAAA;AAClB,6GAAA,aAAa,OAAA;AAKf,yCAA4C;AAAnC,0GAAA,aAAa,OAAA;AAEtB,iCAA8D;AAArD,sGAAA,aAAa,OAAA;AAAE,+FAAA,MAAM,OAAA;AAAE,qGAAA,YAAY,OAAA;AAE5C,qCAQmB;AAPjB,2GAAA,gBAAgB,OAAA;AAChB,yGAAA,cAAc,OAAA;AACd,+GAAA,oBAAoB,OAAA;AACpB,uGAAA,YAAY,OAAA;AAMd,oCAAoC;AACpC,qCAAqE;AAA5D,2GAAA,oBAAoB,OAAoB;AAEjD,qCAImB;AAHjB,6GAAA,kBAAkB,OAAA","sourcesContent":["export {\n allDenominators,\n applyImpactProtection,\n asOrderBookId,\n asPubkeyStr,\n convertDenomination,\n Denominator,\n denominatorDepositSymbol,\n denominatorSymbol,\n denominatorToken,\n DepositSource,\n deriveOrderbookId,\n parseResolution,\n parseSide,\n receiveDenominator,\n resolutionSeconds,\n sideLabel,\n spendDenominator,\n toOrderSide,\n OrderUpdateType,\n Resolution,\n Side,\n TimeInForce,\n TriggerResultStatus,\n TriggerStatus,\n TriggerType,\n TriggerUpdateType,\n type Branded,\n type OrderBookId,\n type PubkeyStr,\n type SubmitOrderRequest,\n} from \"./types\";\n\nexport {\n ApiRejectedDetails,\n isApiResponse,\n type ApiRejectedDetailsWire,\n type ApiResponse,\n} from \"./api_response\";\n\nexport { RejectionCode } from \"./rejection\";\n\nexport { formatDecimal, isZero, parseDecimal } from \"./price\";\n\nexport {\n alignPriceToTick,\n scalePriceSize,\n scalePriceSizeLegacy,\n ScalingError,\n type LegacyScaledAmounts,\n type OrderbookDecimals,\n type ScaledAmounts,\n} from \"./scaling\";\n\n// Backward-compatible name from v1.\nexport { scalePriceSizeLegacy as scalePriceSizeV1 } from \"./scaling\";\n\nexport {\n isUserCancellation,\n type ExternalSigner,\n type SigningStrategy,\n} from \"./signing\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"rejection.d.ts","sourceRoot":"","sources":["../../src/shared/rejection.ts"],"names":[],"mappings":"AAqBA,qBAAa,aAAa;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB,OAAO;IAIP,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa;IAIvC,KAAK,IAAI,MAAM;IAQf,QAAQ,IAAI,MAAM;IAQlB,QAAQ,IAAI,MAAM;CAGnB"}
1
+ {"version":3,"file":"rejection.d.ts","sourceRoot":"","sources":["../../src/shared/rejection.ts"],"names":[],"mappings":"AAgCA,qBAAa,aAAa;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB,OAAO;IAIP,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa;IAIvC,KAAK,IAAI,MAAM;IAQf,QAAQ,IAAI,MAAM;IAQlB,QAAQ,IAAI,MAAM;CAGnB"}
@@ -14,6 +14,17 @@ const REJECTION_CODE_LABELS = {
14
14
  NOT_ORDER_MAKER: "Not Order Maker",
15
15
  ORDER_ALREADY_FILLED: "Order Already Filled",
16
16
  ORDER_ALREADY_CANCELLED: "Order Already Cancelled",
17
+ DUPLICATE_ORDER: "Duplicate Order",
18
+ POST_ONLY_WOULD_CROSS: "Post Only Would Cross",
19
+ FOK_NO_FILL: "FOK No Fill",
20
+ IOC_NO_FILL: "IOC No Fill",
21
+ WOULD_CROSS_UNAVAILABLE_LIQUIDITY: "Would Cross Unavailable Liquidity",
22
+ WOULD_CROSS_BOOK: "Would Cross Book",
23
+ MARKET_NOT_FOUND: "Market Not Found",
24
+ ORDERBOOK_NOT_FOUND: "Orderbook Not Found",
25
+ TOKEN_PAIR_MISMATCH: "Token Pair Mismatch",
26
+ INSUFFICIENT_MARKET_FEE_BUFFER: "Insufficient Market Fee Buffer",
27
+ SIGNATURE_EXPIRED: "Signature Expired",
17
28
  };
18
29
  function normalizeRejectionCode(raw) {
19
30
  return raw.toUpperCase();
@@ -1 +1 @@
1
- {"version":3,"file":"rejection.js","sourceRoot":"","sources":["../../src/shared/rejection.ts"],"names":[],"mappings":";;;AAAA,MAAM,qBAAqB,GAAG;IAC5B,oBAAoB,EAAE,sBAAsB;IAC5C,OAAO,EAAE,SAAS;IAClB,cAAc,EAAE,gBAAgB;IAChC,UAAU,EAAE,YAAY;IACxB,eAAe,EAAE,iBAAiB;IAClC,oBAAoB,EAAE,sBAAsB;IAC5C,aAAa,EAAE,eAAe;IAC9B,iBAAiB,EAAE,mBAAmB;IACtC,eAAe,EAAE,iBAAiB;IAClC,eAAe,EAAE,iBAAiB;IAClC,oBAAoB,EAAE,sBAAsB;IAC5C,uBAAuB,EAAE,yBAAyB;CAC1C,CAAC;AAIX,SAAS,sBAAsB,CAAC,GAAW;IACzC,OAAO,GAAG,CAAC,WAAW,EAAE,CAAC;AAC3B,CAAC;AAED,MAAa,aAAa;IACf,GAAG,CAAS;IAErB,YAAoB,GAAW;QAC7B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,GAAW;QACrB,OAAO,IAAI,aAAa,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;IAED,KAAK;QACH,MAAM,UAAU,GAAG,sBAAsB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACpD,IAAI,UAAU,IAAI,qBAAqB,EAAE,CAAC;YACxC,OAAO,qBAAqB,CAAC,UAAgC,CAAC,CAAC;QACjE,CAAC;QACD,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAED,QAAQ;QACN,MAAM,UAAU,GAAG,sBAAsB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACpD,IAAI,UAAU,IAAI,qBAAqB,EAAE,CAAC;YACxC,OAAO,UAAU,CAAC;QACpB,CAAC;QACD,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACF;AA9BD,sCA8BC","sourcesContent":["const REJECTION_CODE_LABELS = {\n INSUFFICIENT_BALANCE: \"Insufficient Balance\",\n EXPIRED: \"Expired\",\n NONCE_MISMATCH: \"Nonce Mismatch\",\n SELF_TRADE: \"Self Trade\",\n MARKET_INACTIVE: \"Market Inactive\",\n BELOW_MIN_ORDER_SIZE: \"Below Min Order Size\",\n INVALID_NONCE: \"Invalid Nonce\",\n BROADCAST_FAILURE: \"Broadcast Failure\",\n ORDER_NOT_FOUND: \"Order Not Found\",\n NOT_ORDER_MAKER: \"Not Order Maker\",\n ORDER_ALREADY_FILLED: \"Order Already Filled\",\n ORDER_ALREADY_CANCELLED: \"Order Already Cancelled\",\n} as const;\n\ntype KnownRejectionCode = keyof typeof REJECTION_CODE_LABELS;\n\nfunction normalizeRejectionCode(raw: string): string {\n return raw.toUpperCase();\n}\n\nexport class RejectionCode {\n readonly raw: string;\n\n private constructor(raw: string) {\n this.raw = raw;\n }\n\n static from(raw: string): RejectionCode {\n return new RejectionCode(raw);\n }\n\n label(): string {\n const normalized = normalizeRejectionCode(this.raw);\n if (normalized in REJECTION_CODE_LABELS) {\n return REJECTION_CODE_LABELS[normalized as KnownRejectionCode];\n }\n return this.raw;\n }\n\n wireName(): string {\n const normalized = normalizeRejectionCode(this.raw);\n if (normalized in REJECTION_CODE_LABELS) {\n return normalized;\n }\n return this.raw;\n }\n\n toString(): string {\n return this.label();\n }\n}\n"]}
1
+ {"version":3,"file":"rejection.js","sourceRoot":"","sources":["../../src/shared/rejection.ts"],"names":[],"mappings":";;;AAAA,MAAM,qBAAqB,GAAG;IAC5B,oBAAoB,EAAE,sBAAsB;IAC5C,OAAO,EAAE,SAAS;IAClB,cAAc,EAAE,gBAAgB;IAChC,UAAU,EAAE,YAAY;IACxB,eAAe,EAAE,iBAAiB;IAClC,oBAAoB,EAAE,sBAAsB;IAC5C,aAAa,EAAE,eAAe;IAC9B,iBAAiB,EAAE,mBAAmB;IACtC,eAAe,EAAE,iBAAiB;IAClC,eAAe,EAAE,iBAAiB;IAClC,oBAAoB,EAAE,sBAAsB;IAC5C,uBAAuB,EAAE,yBAAyB;IAClD,eAAe,EAAE,iBAAiB;IAClC,qBAAqB,EAAE,uBAAuB;IAC9C,WAAW,EAAE,aAAa;IAC1B,WAAW,EAAE,aAAa;IAC1B,iCAAiC,EAAE,mCAAmC;IACtE,gBAAgB,EAAE,kBAAkB;IACpC,gBAAgB,EAAE,kBAAkB;IACpC,mBAAmB,EAAE,qBAAqB;IAC1C,mBAAmB,EAAE,qBAAqB;IAC1C,8BAA8B,EAAE,gCAAgC;IAChE,iBAAiB,EAAE,mBAAmB;CAC9B,CAAC;AAIX,SAAS,sBAAsB,CAAC,GAAW;IACzC,OAAO,GAAG,CAAC,WAAW,EAAE,CAAC;AAC3B,CAAC;AAED,MAAa,aAAa;IACf,GAAG,CAAS;IAErB,YAAoB,GAAW;QAC7B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,GAAW;QACrB,OAAO,IAAI,aAAa,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;IAED,KAAK;QACH,MAAM,UAAU,GAAG,sBAAsB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACpD,IAAI,UAAU,IAAI,qBAAqB,EAAE,CAAC;YACxC,OAAO,qBAAqB,CAAC,UAAgC,CAAC,CAAC;QACjE,CAAC;QACD,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAED,QAAQ;QACN,MAAM,UAAU,GAAG,sBAAsB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACpD,IAAI,UAAU,IAAI,qBAAqB,EAAE,CAAC;YACxC,OAAO,UAAU,CAAC;QACpB,CAAC;QACD,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACF;AA9BD,sCA8BC","sourcesContent":["const REJECTION_CODE_LABELS = {\n INSUFFICIENT_BALANCE: \"Insufficient Balance\",\n EXPIRED: \"Expired\",\n NONCE_MISMATCH: \"Nonce Mismatch\",\n SELF_TRADE: \"Self Trade\",\n MARKET_INACTIVE: \"Market Inactive\",\n BELOW_MIN_ORDER_SIZE: \"Below Min Order Size\",\n INVALID_NONCE: \"Invalid Nonce\",\n BROADCAST_FAILURE: \"Broadcast Failure\",\n ORDER_NOT_FOUND: \"Order Not Found\",\n NOT_ORDER_MAKER: \"Not Order Maker\",\n ORDER_ALREADY_FILLED: \"Order Already Filled\",\n ORDER_ALREADY_CANCELLED: \"Order Already Cancelled\",\n DUPLICATE_ORDER: \"Duplicate Order\",\n POST_ONLY_WOULD_CROSS: \"Post Only Would Cross\",\n FOK_NO_FILL: \"FOK No Fill\",\n IOC_NO_FILL: \"IOC No Fill\",\n WOULD_CROSS_UNAVAILABLE_LIQUIDITY: \"Would Cross Unavailable Liquidity\",\n WOULD_CROSS_BOOK: \"Would Cross Book\",\n MARKET_NOT_FOUND: \"Market Not Found\",\n ORDERBOOK_NOT_FOUND: \"Orderbook Not Found\",\n TOKEN_PAIR_MISMATCH: \"Token Pair Mismatch\",\n INSUFFICIENT_MARKET_FEE_BUFFER: \"Insufficient Market Fee Buffer\",\n SIGNATURE_EXPIRED: \"Signature Expired\",\n} as const;\n\ntype KnownRejectionCode = keyof typeof REJECTION_CODE_LABELS;\n\nfunction normalizeRejectionCode(raw: string): string {\n return raw.toUpperCase();\n}\n\nexport class RejectionCode {\n readonly raw: string;\n\n private constructor(raw: string) {\n this.raw = raw;\n }\n\n static from(raw: string): RejectionCode {\n return new RejectionCode(raw);\n }\n\n label(): string {\n const normalized = normalizeRejectionCode(this.raw);\n if (normalized in REJECTION_CODE_LABELS) {\n return REJECTION_CODE_LABELS[normalized as KnownRejectionCode];\n }\n return this.raw;\n }\n\n wireName(): string {\n const normalized = normalizeRejectionCode(this.raw);\n if (normalized in REJECTION_CODE_LABELS) {\n return normalized;\n }\n return this.raw;\n }\n\n toString(): string {\n return this.label();\n }\n}\n"]}
@@ -1,3 +1,7 @@
1
+ import Decimal from "decimal.js";
2
+ import type { OrderBookPair } from "../domain/orderbook";
3
+ import type { ConditionalToken } from "../domain/market/tokens";
4
+ import { OrderSide } from "../program/types";
1
5
  export type Branded<T, Brand extends string> = T & {
2
6
  readonly __brand: Brand;
3
7
  };
@@ -11,6 +15,43 @@ export declare enum Side {
11
15
  }
12
16
  export declare function parseSide(value: string): Side;
13
17
  export declare function sideLabel(side: Side): "Buy" | "Sell";
18
+ /**
19
+ * The denomination of the asset this side spends (Bid spends quote, Ask spends
20
+ * base). Also a trade form's default display denomination.
21
+ */
22
+ export declare function spendDenominator(side: Side): Denominator;
23
+ /**
24
+ * The denomination of the asset this side receives (Bid receives base, Ask
25
+ * receives quote).
26
+ */
27
+ export declare function receiveDenominator(side: Side): Denominator;
28
+ /**
29
+ * The price to submit with a market (IOC) order: the worst book fill price
30
+ * padded by the impact-protection percentage in the direction that lets the
31
+ * order fill.
32
+ *
33
+ * Returns null unless both inputs are positive.
34
+ */
35
+ export declare function applyImpactProtection(side: Side, worstFillPrice: Decimal, protectionPercent: Decimal): Decimal | null;
36
+ /** Map a wire/domain `Side` onto the on-chain `OrderSide`. */
37
+ export declare function toOrderSide(side: Side): OrderSide;
38
+ export declare enum Denominator {
39
+ Base = "Base",
40
+ Quote = "Quote"
41
+ }
42
+ export declare function allDenominators(): Denominator[];
43
+ /** The conditional token this denomination refers to on `pair`. */
44
+ export declare function denominatorToken(denominator: Denominator, pair: OrderBookPair): ConditionalToken;
45
+ export declare function denominatorSymbol(denominator: Denominator, pair: OrderBookPair): string;
46
+ export declare function denominatorDepositSymbol(denominator: Denominator, pair: OrderBookPair): string;
47
+ /**
48
+ * Convert `amount` from one denomination into another at the given price
49
+ * (quote per one base).
50
+ *
51
+ * Same-denomination conversion is the identity and never needs a price;
52
+ * crossing denominations requires a positive price — null otherwise.
53
+ */
54
+ export declare function convertDenomination(from: Denominator, to: Denominator, amount: Decimal, basePriceInQuote: Decimal): Decimal | null;
14
55
  export declare enum TimeInForce {
15
56
  Gtc = "GTC",
16
57
  Ioc = "IOC",
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,OAAO,CAAC,CAAC,EAAE,KAAK,SAAS,MAAM,IAAI,CAAC,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAA;CAAE,CAAC;AAE/E,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AACzD,MAAM,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAErD,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG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MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,WAAW,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,WAAW,CAAC;IAC3B,cAAc,CAAC,EAAE,aAAa,CAAC;CAChC"}
@@ -1,14 +1,28 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Resolution = exports.DepositSource = exports.TriggerResultStatus = exports.TriggerUpdateType = exports.OrderUpdateType = exports.TriggerStatus = exports.TriggerType = exports.TimeInForce = exports.Side = void 0;
6
+ exports.Resolution = exports.DepositSource = exports.TriggerResultStatus = exports.TriggerUpdateType = exports.OrderUpdateType = exports.TriggerStatus = exports.TriggerType = exports.TimeInForce = exports.Denominator = exports.Side = void 0;
4
7
  exports.asOrderBookId = asOrderBookId;
5
8
  exports.asPubkeyStr = asPubkeyStr;
6
9
  exports.parseSide = parseSide;
7
10
  exports.sideLabel = sideLabel;
11
+ exports.spendDenominator = spendDenominator;
12
+ exports.receiveDenominator = receiveDenominator;
13
+ exports.applyImpactProtection = applyImpactProtection;
14
+ exports.toOrderSide = toOrderSide;
15
+ exports.allDenominators = allDenominators;
16
+ exports.denominatorToken = denominatorToken;
17
+ exports.denominatorSymbol = denominatorSymbol;
18
+ exports.denominatorDepositSymbol = denominatorDepositSymbol;
19
+ exports.convertDenomination = convertDenomination;
8
20
  exports.parseResolution = parseResolution;
9
21
  exports.resolutionSeconds = resolutionSeconds;
10
22
  exports.deriveOrderbookId = deriveOrderbookId;
23
+ const decimal_js_1 = __importDefault(require("decimal.js"));
11
24
  const error_1 = require("../error");
25
+ const types_1 = require("../program/types");
12
26
  function asOrderBookId(value) {
13
27
  return value;
14
28
  }
@@ -30,6 +44,76 @@ function parseSide(value) {
30
44
  function sideLabel(side) {
31
45
  return side === Side.Bid ? "Buy" : "Sell";
32
46
  }
47
+ /**
48
+ * The denomination of the asset this side spends (Bid spends quote, Ask spends
49
+ * base). Also a trade form's default display denomination.
50
+ */
51
+ function spendDenominator(side) {
52
+ return side === Side.Bid ? Denominator.Quote : Denominator.Base;
53
+ }
54
+ /**
55
+ * The denomination of the asset this side receives (Bid receives base, Ask
56
+ * receives quote).
57
+ */
58
+ function receiveDenominator(side) {
59
+ return side === Side.Bid ? Denominator.Base : Denominator.Quote;
60
+ }
61
+ /**
62
+ * The price to submit with a market (IOC) order: the worst book fill price
63
+ * padded by the impact-protection percentage in the direction that lets the
64
+ * order fill.
65
+ *
66
+ * Returns null unless both inputs are positive.
67
+ */
68
+ function applyImpactProtection(side, worstFillPrice, protectionPercent) {
69
+ if (worstFillPrice.lte(0) || protectionPercent.lte(0)) {
70
+ return null;
71
+ }
72
+ const factor = protectionPercent.div(100);
73
+ return side === Side.Bid
74
+ ? worstFillPrice.mul(factor.add(1)) // buying: willing to pay more
75
+ : worstFillPrice.mul(new decimal_js_1.default(1).sub(factor)); // selling: willing to receive less
76
+ }
77
+ /** Map a wire/domain `Side` onto the on-chain `OrderSide`. */
78
+ function toOrderSide(side) {
79
+ return side === Side.Bid ? types_1.OrderSide.BID : types_1.OrderSide.ASK;
80
+ }
81
+ var Denominator;
82
+ (function (Denominator) {
83
+ Denominator["Base"] = "Base";
84
+ Denominator["Quote"] = "Quote";
85
+ })(Denominator || (exports.Denominator = Denominator = {}));
86
+ function allDenominators() {
87
+ return [Denominator.Quote, Denominator.Base];
88
+ }
89
+ /** The conditional token this denomination refers to on `pair`. */
90
+ function denominatorToken(denominator, pair) {
91
+ return denominator === Denominator.Base ? pair.base : pair.quote;
92
+ }
93
+ function denominatorSymbol(denominator, pair) {
94
+ return denominatorToken(denominator, pair).symbol;
95
+ }
96
+ function denominatorDepositSymbol(denominator, pair) {
97
+ return denominatorToken(denominator, pair).depositSymbol;
98
+ }
99
+ /**
100
+ * Convert `amount` from one denomination into another at the given price
101
+ * (quote per one base).
102
+ *
103
+ * Same-denomination conversion is the identity and never needs a price;
104
+ * crossing denominations requires a positive price — null otherwise.
105
+ */
106
+ function convertDenomination(from, to, amount, basePriceInQuote) {
107
+ if (from === to) {
108
+ return amount;
109
+ }
110
+ if (basePriceInQuote.lte(0)) {
111
+ return null;
112
+ }
113
+ return from === Denominator.Base
114
+ ? amount.mul(basePriceInQuote)
115
+ : amount.div(basePriceInQuote);
116
+ }
33
117
  var TimeInForce;
34
118
  (function (TimeInForce) {
35
119
  TimeInForce["Gtc"] = "GTC";
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":";;;AAOA,sCAEC;AAED,kCAEC;AAOD,8BAIC;AAED,8BAEC;AAwDD,0CAiBC;AAED,8CAeC;AAED,8CAEC;AA1HD,oCAAoC;AAOpC,SAAgB,aAAa,CAAC,KAAa;IACzC,OAAO,KAAoB,CAAC;AAC9B,CAAC;AAED,SAAgB,WAAW,CAAC,KAAa;IACvC,OAAO,KAAkB,CAAC;AAC5B,CAAC;AAED,IAAY,IAGX;AAHD,WAAY,IAAI;IACd,mBAAW,CAAA;IACX,mBAAW,CAAA;AACb,CAAC,EAHW,IAAI,oBAAJ,IAAI,QAGf;AAED,SAAgB,SAAS,CAAC,KAAa;IACrC,IAAI,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,KAAK;QAAE,OAAO,IAAI,CAAC,GAAG,CAAC;IACxD,IAAI,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC,GAAG,CAAC;IACzD,MAAM,gBAAQ,CAAC,UAAU,CAAC,iBAAiB,KAAK,EAAE,CAAC,CAAC;AACtD,CAAC;AAED,SAAgB,SAAS,CAAC,IAAU;IAClC,OAAO,IAAI,KAAK,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAA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ACb,CAAC,EAPW,UAAU,0BAAV,UAAU,QAOrB;AAED,SAAgB,eAAe,CAAC,KAAa;IAC3C,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,IAAI;YACP,OAAO,UAAU,CAAC,OAAO,CAAC;QAC5B,KAAK,IAAI;YACP,OAAO,UAAU,CAAC,OAAO,CAAC;QAC5B,KAAK,KAAK;YACR,OAAO,UAAU,CAAC,QAAQ,CAAC;QAC7B,KAAK,IAAI;YACP,OAAO,UAAU,CAAC,KAAK,CAAC;QAC1B,KAAK,IAAI;YACP,OAAO,UAAU,CAAC,KAAK,CAAC;QAC1B,KAAK,IAAI;YACP,OAAO,UAAU,CAAC,IAAI,CAAC;QACzB;YACE,MAAM,gBAAQ,CAAC,UAAU,CAAC,uBAAuB,KAAK,EAAE,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC;AAED,SAAgB,iBAAiB,CAAC,UAAsB;IACtD,QAAQ,UAAU,EAAE,CAAC;QACnB,KAAK,UAAU,CAAC,OAAO;YACrB,OAAO,EAAE,CAAC;QACZ,KAAK,UAAU,CAAC,OAAO;YACrB,OAAO,GAAG,CAAC;QACb,KAAK,UAAU,CAAC,QAAQ;YACtB,OAAO,GAAG,CAAC;QACb,KAAK,UAAU,CAAC,KAAK;YACnB,OAAO,IAAI,CAAC;QACd,KAAK,UAAU,CAAC,KAAK;YACnB,OAAO,KAAK,CAAC;QACf,KAAK,UAAU,CAAC,IAAI;YAClB,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC;AAED,SAAgB,iBAAiB,CAAC,SAAiB,EAAE,UAAkB;IACrE,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAiB,CAAC;AAC7E,CAAC","sourcesContent":["import { SdkError } from \"../error\";\n\nexport type Branded<T, Brand extends string> = T & { readonly __brand: Brand };\n\nexport type OrderBookId = Branded<string, \"OrderBookId\">;\nexport type PubkeyStr = Branded<string, \"PubkeyStr\">;\n\nexport function asOrderBookId(value: string): OrderBookId {\n return value as OrderBookId;\n}\n\nexport function asPubkeyStr(value: string): PubkeyStr {\n return value as PubkeyStr;\n}\n\nexport enum Side {\n Bid = \"bid\",\n Ask = \"ask\",\n}\n\nexport function parseSide(value: string): Side {\n if (value === \"bid\" || value === \"buy\") return Side.Bid;\n if (value === \"ask\" || value === \"sell\") return Side.Ask;\n throw SdkError.validation(`Invalid side: ${value}`);\n}\n\nexport function sideLabel(side: Side): \"Buy\" | \"Sell\" {\n return side === Side.Bid ? \"Buy\" : \"Sell\";\n}\n\nexport enum TimeInForce {\n Gtc = \"GTC\",\n Ioc = \"IOC\",\n Fok = \"FOK\",\n Alo = \"ALO\",\n}\n\nexport enum TriggerType {\n TakeProfit = \"TP\",\n StopLoss = \"SL\",\n}\n\nexport enum TriggerStatus {\n Created = \"created\",\n Triggered = \"triggered\",\n Failed = \"failed\",\n Expired = \"expired\",\n Invalidated = \"invalidated\",\n}\n\nexport enum OrderUpdateType {\n Placement = \"PLACEMENT\",\n Update = \"UPDATE\",\n Cancellation = \"CANCELLATION\",\n}\n\nexport enum TriggerUpdateType {\n Created = \"CREATED\",\n Triggered = \"TRIGGERED\",\n Failed = \"FAILED\",\n Expired = \"EXPIRED\",\n Invalidated = \"INVALIDATED\",\n}\n\nexport enum TriggerResultStatus {\n Filled = \"filled\",\n Accepted = \"accepted\",\n Rejected = \"rejected\",\n}\n\nexport enum DepositSource {\n Global = \"global\",\n Market = \"market\",\n}\n\nexport enum Resolution {\n Minute1 = \"1m\",\n Minute5 = \"5m\",\n Minute15 = \"15m\",\n Hour1 = \"1h\",\n Hour4 = \"4h\",\n Day1 = \"1d\",\n}\n\nexport function parseResolution(value: string): Resolution {\n switch (value) {\n case \"1m\":\n return Resolution.Minute1;\n case \"5m\":\n return Resolution.Minute5;\n case \"15m\":\n return Resolution.Minute15;\n case \"1h\":\n return Resolution.Hour1;\n case \"4h\":\n return Resolution.Hour4;\n case \"1d\":\n return Resolution.Day1;\n default:\n throw SdkError.validation(`Invalid resolution: ${value}`);\n }\n}\n\nexport function resolutionSeconds(resolution: Resolution): number {\n switch (resolution) {\n case Resolution.Minute1:\n return 60;\n case Resolution.Minute5:\n return 300;\n case Resolution.Minute15:\n return 900;\n case Resolution.Hour1:\n return 3600;\n case Resolution.Hour4:\n return 14400;\n case Resolution.Day1:\n return 86400;\n }\n}\n\nexport function deriveOrderbookId(baseToken: string, quoteToken: string): OrderBookId {\n return `${baseToken.slice(0, 8)}_${quoteToken.slice(0, 8)}` as OrderBookId;\n}\n\nexport interface SubmitOrderRequest {\n maker: string;\n nonce: number;\n salt: number;\n market_pubkey: string;\n base_token: string;\n quote_token: string;\n side: number;\n /** u64 amount — validated to fit in Number.MAX_SAFE_INTEGER at construction time */\n amount_in: number;\n /** u64 amount — validated to fit in Number.MAX_SAFE_INTEGER at construction time */\n amount_out: number;\n expiration: number;\n signature: string;\n orderbook_id: string;\n tif?: TimeInForce;\n trigger_price?: number;\n trigger_type?: TriggerType;\n deposit_source?: DepositSource;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":";;;;;;AAYA,sCAEC;AAED,kCAEC;AAOD,8BAIC;AAED,8BAEC;AAMD,4CAEC;AAMD,gDAEC;AASD,sDAYC;AAGD,kCAEC;AAOD,0CAEC;AAGD,4CAEC;AAED,8CAEC;AAED,4DAEC;AASD,kDAeC;AAwDD,0CAiBC;AAED,8CAeC;AAED,8CAEC;AAvND,4DAAiC;AAEjC,oCAAoC;AAGpC,4CAA6C;AAO7C,SAAgB,aAAa,CAAC,KAAa;IACzC,OAAO,KAAoB,CAAC;AAC9B,CAAC;AAED,SAAgB,WAAW,CAAC,KAAa;IACvC,OAAO,KAAkB,CAAC;AAC5B,CAAC;AAED,IAAY,IAGX;AAHD,WAAY,IAAI;IACd,mBAAW,CAAA;IACX,mBAAW,CAAA;AACb,CA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E,CAAC,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAiB,CAAC;AAC7E,CAAC","sourcesContent":["import Decimal from \"decimal.js\";\n\nimport { SdkError } from \"../error\";\nimport type { OrderBookPair } from \"../domain/orderbook\";\nimport type { ConditionalToken } from \"../domain/market/tokens\";\nimport { OrderSide } from \"../program/types\";\n\nexport type Branded<T, Brand extends string> = T & { readonly __brand: Brand };\n\nexport type OrderBookId = Branded<string, \"OrderBookId\">;\nexport type PubkeyStr = Branded<string, \"PubkeyStr\">;\n\nexport function asOrderBookId(value: string): OrderBookId {\n return value as OrderBookId;\n}\n\nexport function asPubkeyStr(value: string): PubkeyStr {\n return value as PubkeyStr;\n}\n\nexport enum Side {\n Bid = \"bid\",\n Ask = \"ask\",\n}\n\nexport function parseSide(value: string): Side {\n if (value === \"bid\" || value === \"buy\") return Side.Bid;\n if (value === \"ask\" || value === \"sell\") return Side.Ask;\n throw SdkError.validation(`Invalid side: ${value}`);\n}\n\nexport function sideLabel(side: Side): \"Buy\" | \"Sell\" {\n return side === Side.Bid ? \"Buy\" : \"Sell\";\n}\n\n/**\n * The denomination of the asset this side spends (Bid spends quote, Ask spends\n * base). Also a trade form's default display denomination.\n */\nexport function spendDenominator(side: Side): Denominator {\n return side === Side.Bid ? Denominator.Quote : Denominator.Base;\n}\n\n/**\n * The denomination of the asset this side receives (Bid receives base, Ask\n * receives quote).\n */\nexport function receiveDenominator(side: Side): Denominator {\n return side === Side.Bid ? Denominator.Base : Denominator.Quote;\n}\n\n/**\n * The price to submit with a market (IOC) order: the worst book fill price\n * padded by the impact-protection percentage in the direction that lets the\n * order fill.\n *\n * Returns null unless both inputs are positive.\n */\nexport function applyImpactProtection(\n side: Side,\n worstFillPrice: Decimal,\n protectionPercent: Decimal\n): Decimal | null {\n if (worstFillPrice.lte(0) || protectionPercent.lte(0)) {\n return null;\n }\n const factor = protectionPercent.div(100);\n return side === Side.Bid\n ? worstFillPrice.mul(factor.add(1)) // buying: willing to pay more\n : worstFillPrice.mul(new Decimal(1).sub(factor)); // selling: willing to receive less\n}\n\n/** Map a wire/domain `Side` onto the on-chain `OrderSide`. */\nexport function toOrderSide(side: Side): OrderSide {\n return side === Side.Bid ? OrderSide.BID : OrderSide.ASK;\n}\n\nexport enum Denominator {\n Base = \"Base\",\n Quote = \"Quote\",\n}\n\nexport function allDenominators(): Denominator[] {\n return [Denominator.Quote, Denominator.Base];\n}\n\n/** The conditional token this denomination refers to on `pair`. */\nexport function denominatorToken(denominator: Denominator, pair: OrderBookPair): ConditionalToken {\n return denominator === Denominator.Base ? pair.base : pair.quote;\n}\n\nexport function denominatorSymbol(denominator: Denominator, pair: OrderBookPair): string {\n return denominatorToken(denominator, pair).symbol;\n}\n\nexport function denominatorDepositSymbol(denominator: Denominator, pair: OrderBookPair): string {\n return denominatorToken(denominator, pair).depositSymbol;\n}\n\n/**\n * Convert `amount` from one denomination into another at the given price\n * (quote per one base).\n *\n * Same-denomination conversion is the identity and never needs a price;\n * crossing denominations requires a positive price — null otherwise.\n */\nexport function convertDenomination(\n from: Denominator,\n to: Denominator,\n amount: Decimal,\n basePriceInQuote: Decimal\n): Decimal | null {\n if (from === to) {\n return amount;\n }\n if (basePriceInQuote.lte(0)) {\n return null;\n }\n return from === Denominator.Base\n ? amount.mul(basePriceInQuote)\n : amount.div(basePriceInQuote);\n}\n\nexport enum TimeInForce {\n Gtc = \"GTC\",\n Ioc = \"IOC\",\n Fok = \"FOK\",\n Alo = \"ALO\",\n}\n\nexport enum TriggerType {\n TakeProfit = \"TP\",\n StopLoss = \"SL\",\n}\n\nexport enum TriggerStatus {\n Created = \"created\",\n Triggered = \"triggered\",\n Failed = \"failed\",\n Expired = \"expired\",\n Invalidated = \"invalidated\",\n}\n\nexport enum OrderUpdateType {\n Placement = \"PLACEMENT\",\n Update = \"UPDATE\",\n Cancellation = \"CANCELLATION\",\n}\n\nexport enum TriggerUpdateType {\n Created = \"CREATED\",\n Triggered = \"TRIGGERED\",\n Failed = \"FAILED\",\n Expired = \"EXPIRED\",\n Invalidated = \"INVALIDATED\",\n}\n\nexport enum TriggerResultStatus {\n Filled = \"filled\",\n Accepted = \"accepted\",\n Rejected = \"rejected\",\n}\n\nexport enum DepositSource {\n Global = \"global\",\n Market = \"market\",\n}\n\nexport enum Resolution {\n Minute1 = \"1m\",\n Minute5 = \"5m\",\n Minute15 = \"15m\",\n Hour1 = \"1h\",\n Hour4 = \"4h\",\n Day1 = \"1d\",\n}\n\nexport function parseResolution(value: string): Resolution {\n switch (value) {\n case \"1m\":\n return Resolution.Minute1;\n case \"5m\":\n return Resolution.Minute5;\n case \"15m\":\n return Resolution.Minute15;\n case \"1h\":\n return Resolution.Hour1;\n case \"4h\":\n return Resolution.Hour4;\n case \"1d\":\n return Resolution.Day1;\n default:\n throw SdkError.validation(`Invalid resolution: ${value}`);\n }\n}\n\nexport function resolutionSeconds(resolution: Resolution): number {\n switch (resolution) {\n case Resolution.Minute1:\n return 60;\n case Resolution.Minute5:\n return 300;\n case Resolution.Minute15:\n return 900;\n case Resolution.Hour1:\n return 3600;\n case Resolution.Hour4:\n return 14400;\n case Resolution.Day1:\n return 86400;\n }\n}\n\nexport function deriveOrderbookId(baseToken: string, quoteToken: string): OrderBookId {\n return `${baseToken.slice(0, 8)}_${quoteToken.slice(0, 8)}` as OrderBookId;\n}\n\nexport interface SubmitOrderRequest {\n maker: string;\n nonce: number;\n salt: number;\n market_pubkey: string;\n base_token: string;\n quote_token: string;\n side: number;\n /** u64 amount — validated to fit in Number.MAX_SAFE_INTEGER at construction time */\n amount_in: number;\n /** u64 amount — validated to fit in Number.MAX_SAFE_INTEGER at construction time */\n amount_out: number;\n expiration: number;\n signature: string;\n orderbook_id: string;\n tif?: TimeInForce;\n trigger_price?: number;\n trigger_type?: TriggerType;\n deposit_source?: DepositSource;\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  import type { MarketEvent } from "../domain/market";
2
2
  import { type AuthUpdate, type UserUpdate } from "../domain/order/wire";
3
3
  import type { OrderBook, WsTickerData } from "../domain/orderbook";
4
+ import { type BookAggregation } from "../domain/orderbook/aggregation";
4
5
  import type { DepositAssetPriceEvent, DepositPrice, PriceHistory } from "../domain/price_history";
5
6
  import type { WsTrade } from "../domain/trade";
6
7
  import type { OrderBookId, PubkeyStr, Resolution } from "../shared";
@@ -66,6 +67,14 @@ export interface WsError {
66
67
  error: string;
67
68
  code?: string;
68
69
  orderbook_id?: string;
70
+ /**
71
+ * Aggregation of the affected book subscription on book-scoped errors
72
+ * (`ENGINE_UNAVAILABLE`, `SUBSCRIPTION_LIMIT_REACHED`,
73
+ * `INVALID_ORDERBOOK_SUBSCRIPTION`). Absent = full precision; pass to
74
+ * `aggregationFromFrame` to identify the `(orderbook, aggregation)` pair.
75
+ */
76
+ n_sig_figs?: number;
77
+ mantissa?: number;
69
78
  wallet_address?: string;
70
79
  deposit_asset?: string;
71
80
  hint?: string;
@@ -103,8 +112,22 @@ export declare enum ReadyState {
103
112
  }
104
113
  export declare function readyStateFrom(value: number): ReadyState;
105
114
  export declare function ping(): MessageOut;
106
- export declare function subscribeBooks(orderbookIds: OrderBookId[]): MessageOut;
107
- export declare function unsubscribeBooks(orderbookIds: OrderBookId[]): MessageOut;
115
+ /**
116
+ * Subscribe to book snapshots, optionally aggregated (Hyperliquid-style).
117
+ *
118
+ * Omit `aggregation` for the raw book. The aggregation is normalized before
119
+ * sending ((5, none) → (5, 1)); validate with `validateAggregation` first —
120
+ * invalid combinations are rejected server-side with
121
+ * `INVALID_ORDERBOOK_SUBSCRIPTION`. `undefined` fields are dropped by
122
+ * `JSON.stringify`, so full precision stays byte-identical to the
123
+ * pre-aggregation message.
124
+ */
125
+ export declare function subscribeBooks(orderbookIds: OrderBookId[], aggregation?: BookAggregation): MessageOut;
126
+ /**
127
+ * Unsubscribe a book subscription. The aggregation must match the one
128
+ * subscribed (normalized) or the server removes nothing.
129
+ */
130
+ export declare function unsubscribeBooks(orderbookIds: OrderBookId[], aggregation?: BookAggregation): MessageOut;
108
131
  export declare function subscribeTrades(orderbookIds: OrderBookId[]): MessageOut;
109
132
  export declare function unsubscribeTrades(orderbookIds: OrderBookId[]): MessageOut;
110
133
  export declare function subscribeUser(walletAddress: PubkeyStr): MessageOut;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ws/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAuB,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC7F,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,KAAK,EACV,sBAAsB,EACtB,YAAY,EACZ,YAAY,EACb,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEpE,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,MAAM,MAAM,UAAU,GAClB;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,OAAO,iBAAiB,EAAE,eAAe,CAAA;CAAE,GAC1E;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,OAAO,iBAAiB,EAAE,iBAAiB,CAAA;CAAE,GAC9E;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvB,MAAM,MAAM,SAAS,GACjB;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GACzD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IA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,wBAAgB,eAAe,CAAC,YAAY,EAAE,WAAW,EAAE,GAAG,UAAU,CAQvE;AAED,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,WAAW,EAAE,GAAG,UAAU,CAQzE;AAED,wBAAgB,eAAe,CAAC,YAAY,EAAE,SAAS,GAAG,UAAU,CAQnE;AAED,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,SAAS,GAAG,UAAU,CAQrE;AAED,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,UAAU,CAS9F;AAED,wBAAgB,uBAAuB,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,UAAU,CAShG;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,YAAY,EAAE,MAAM,GAAG,UAAU,CAK3E;AAED,wBAAgB,4BAA4B,CAAC,YAAY,EAAE,MAAM,GAAG,UAAU,CAK7E;AAgBD,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAuBvD"}
package/dist/ws/index.js CHANGED
@@ -35,6 +35,7 @@ exports.subscribeDepositAssetPrice = subscribeDepositAssetPrice;
35
35
  exports.unsubscribeDepositAssetPrice = unsubscribeDepositAssetPrice;
36
36
  exports.parseMessageIn = parseMessageIn;
37
37
  const wire_1 = require("../domain/order/wire");
38
+ const aggregation_1 = require("../domain/orderbook/aggregation");
38
39
  const error_1 = require("../error");
39
40
  const env_1 = require("../env");
40
41
  __exportStar(require("./client.node"), exports);
@@ -70,21 +71,41 @@ function readyStateFrom(value) {
70
71
  function ping() {
71
72
  return { method: "ping" };
72
73
  }
73
- function subscribeBooks(orderbookIds) {
74
+ /**
75
+ * Subscribe to book snapshots, optionally aggregated (Hyperliquid-style).
76
+ *
77
+ * Omit `aggregation` for the raw book. The aggregation is normalized before
78
+ * sending ((5, none) → (5, 1)); validate with `validateAggregation` first —
79
+ * invalid combinations are rejected server-side with
80
+ * `INVALID_ORDERBOOK_SUBSCRIPTION`. `undefined` fields are dropped by
81
+ * `JSON.stringify`, so full precision stays byte-identical to the
82
+ * pre-aggregation message.
83
+ */
84
+ function subscribeBooks(orderbookIds, aggregation = aggregation_1.FULL_PRECISION) {
85
+ const normalized = (0, aggregation_1.normalizeAggregation)(aggregation);
74
86
  return {
75
87
  method: "subscribe",
76
88
  params: {
77
89
  type: "book_update",
78
90
  orderbook_ids: orderbookIds,
91
+ nSigFigs: normalized.nSigFigs,
92
+ mantissa: normalized.mantissa,
79
93
  },
80
94
  };
81
95
  }
82
- function unsubscribeBooks(orderbookIds) {
96
+ /**
97
+ * Unsubscribe a book subscription. The aggregation must match the one
98
+ * subscribed (normalized) or the server removes nothing.
99
+ */
100
+ function unsubscribeBooks(orderbookIds, aggregation = aggregation_1.FULL_PRECISION) {
101
+ const normalized = (0, aggregation_1.normalizeAggregation)(aggregation);
83
102
  return {
84
103
  method: "unsubscribe",
85
104
  params: {
86
105
  type: "book_update",
87
106
  orderbook_ids: orderbookIds,
107
+ nSigFigs: normalized.nSigFigs,
108
+ mantissa: normalized.mantissa,
88
109
  },
89
110
  };
90
111
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ws/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AA+EA,wCAYC;AAED,oBAEC;AAED,wCAQC;AAED,4CAQC;AAED,0CAQC;AAED,8CAQC;AAED,sCAQC;AAED,0CAQC;AAED,sDAUC;AAED,0DASC;AAED,0CAQC;AAED,8CAQC;AAED,0CAQC;AAED,8CAQC;AAED,sDASC;AAED,0DASC;AAOD,gEAKC;AAED,oEAKC;AAgBD,wCAuBC;AAzSD,+CAA6F;AAQ7F,oCAAmD;AACnD,gCAA6C;AAG7C,gDAA8B;AAC9B,kDAAgC;AAiDnB,QAAA,iBAAiB,GAAa;IACzC,GAAG,EAAE,IAAA,WAAK,EAAC,kBAAY,CAAC,IAAI,CAAC;IAC7B,SAAS,EAAE,IAAI;IACf,oBAA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I,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,EAAE,CAAC;QACzE,MAAM,IAAI,eAAY,CAAC,eAAe,EAAE,0CAA0C,CAAC,CAAC;IACtF,CAAC;IACD,MAAM,GAAG,GAAG,MAAiC,CAAC;IAC9C,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QACvE,MAAM,IAAI,eAAY,CAAC,eAAe,EAAE,6BAA6B,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC5F,CAAC;IACD,IAAI,CAAC,CAAC,SAAS,IAAI,GAAG,CAAC,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC3D,MAAM,IAAI,eAAY,CAAC,eAAe,EAAE,wDAAwD,CAAC,CAAC;IACpG,CAAC;IACD,IAAI,CAAC,CAAC,MAAM,IAAI,GAAG,CAAC,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;QAC1E,MAAM,IAAI,eAAY,CAAC,eAAe,EAAE,qDAAqD,CAAC,CAAC;IACjG,CAAC;IACD,MAAM,OAAO,GAAG,MAAmB,CAAC;IACpC,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QAC5B,OAAO;YACL,GAAG,OAAO;YACV,IAAI,EAAE,IAAA,0BAAmB,EAAC,OAAO,CAAC,IAAiD,CAAC;SACrF,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { MarketEvent } from \"../domain/market\";\nimport { normalizeUserUpdate, type AuthUpdate, type UserUpdate } from \"../domain/order/wire\";\nimport type { OrderBook, WsTickerData } from \"../domain/orderbook\";\nimport type {\n DepositAssetPriceEvent,\n DepositPrice,\n PriceHistory,\n} from \"../domain/price_history\";\nimport type { WsTrade } from \"../domain/trade\";\nimport { WsError as WsErrorClass } from \"../error\";\nimport { LightconeEnv, wsUrl } from \"../env\";\nimport type { OrderBookId, PubkeyStr, Resolution } from \"../shared\";\n\nexport * from \"./client.node\";\nexport * from \"./subscriptions\";\nexport type { IWsClient } from \"./types\";\n\nexport type MessageOut =\n | { method: \"subscribe\"; params: import(\"./subscriptions\").SubscribeParams }\n | { method: \"unsubscribe\"; params: import(\"./subscriptions\").UnsubscribeParams }\n | { method: \"ping\" };\n\nexport type MessageIn =\n | { type: \"book_update\"; version: number; data: OrderBook }\n | { type: \"pong\"; version: number; data: Record<string, never> }\n | { type: \"user\"; version: number; data: UserUpdate }\n | { type: \"error\"; version: number; data: WsError }\n | { type: \"price_history\"; version: number; data: PriceHistory }\n | { type: \"trades\"; version: number; data: WsTrade }\n | { type: \"auth\"; version: number; data: AuthUpdate }\n | { type: \"ticker\"; version: number; data: WsTickerData }\n | { type: \"market\"; version: number; data: MarketEvent }\n | { type: \"deposit_price\"; version: number; data: DepositPrice }\n | { type: \"deposit_asset_price\"; version: number; data: DepositAssetPriceEvent };\n\nexport type Kind = MessageIn;\n\nexport interface WsError {\n error: string;\n code?: string;\n orderbook_id?: string;\n wallet_address?: string;\n deposit_asset?: string;\n hint?: string;\n details?: string;\n}\n\nexport type WsEvent =\n | { type: \"Message\"; message: MessageIn }\n | { type: \"Connected\" }\n | { type: \"Disconnected\"; code?: number; reason: string }\n | { type: \"Error\"; error: string }\n | { type: \"MaxReconnectReached\" };\n\nexport interface WsConfig {\n url: string;\n reconnect: boolean;\n maxReconnectAttempts: number;\n baseReconnectDelayMs: number;\n pingIntervalMs: number;\n pongTimeoutMs: number;\n}\n\nexport const WS_DEFAULT_CONFIG: WsConfig = {\n url: wsUrl(LightconeEnv.Prod),\n reconnect: true,\n maxReconnectAttempts: 10,\n baseReconnectDelayMs: 1_000,\n pingIntervalMs: 30_000,\n pongTimeoutMs: 10_000,\n};\n\nexport enum ReadyState {\n Connecting = 0,\n Open = 1,\n Closing = 2,\n Closed = 3,\n}\n\nexport function readyStateFrom(value: number): ReadyState {\n switch (value) {\n case 0:\n return ReadyState.Connecting;\n case 1:\n return ReadyState.Open;\n case 2:\n return ReadyState.Closing;\n case 3:\n default:\n return ReadyState.Closed;\n }\n}\n\nexport function ping(): MessageOut {\n return { method: \"ping\" };\n}\n\nexport function subscribeBooks(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"book_update\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function unsubscribeBooks(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"book_update\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function subscribeTrades(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"trades\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function unsubscribeTrades(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"trades\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function subscribeUser(walletAddress: PubkeyStr): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"user\",\n wallet_address: walletAddress,\n },\n };\n}\n\nexport function unsubscribeUser(walletAddress: PubkeyStr): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"user\",\n wallet_address: walletAddress,\n },\n };\n}\n\nexport function subscribePriceHistory(orderbookId: OrderBookId, resolution: Resolution): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"price_history\",\n orderbook_id: orderbookId,\n resolution,\n include_ohlcv: false,\n },\n };\n}\n\nexport function unsubscribePriceHistory(orderbookId: OrderBookId, resolution: Resolution): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"price_history\",\n orderbook_id: orderbookId,\n resolution,\n },\n };\n}\n\nexport function subscribeTicker(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"ticker\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function unsubscribeTicker(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"ticker\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function subscribeMarket(marketPubkey: PubkeyStr): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"market\",\n market_pubkey: marketPubkey,\n },\n };\n}\n\nexport function unsubscribeMarket(marketPubkey: PubkeyStr): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"market\",\n market_pubkey: marketPubkey,\n },\n };\n}\n\nexport function subscribeDepositPrice(depositAsset: string, resolution: Resolution): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"deposit_price\",\n deposit_asset: depositAsset,\n resolution,\n },\n };\n}\n\nexport function unsubscribeDepositPrice(depositAsset: string, resolution: Resolution): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"deposit_price\",\n deposit_asset: depositAsset,\n resolution,\n },\n };\n}\n\n/**\n * Subscribe to the live spot price for one deposit asset (snapshot +\n * per-asset price ticks). Distinct from `subscribeDepositPrice`, which\n * carries OHLCV candles per resolution.\n */\nexport function subscribeDepositAssetPrice(depositAsset: string): MessageOut {\n return {\n method: \"subscribe\",\n params: { type: \"deposit_asset_price\", deposit_asset: depositAsset },\n };\n}\n\nexport function unsubscribeDepositAssetPrice(depositAsset: string): MessageOut {\n return {\n method: \"unsubscribe\",\n params: { type: \"deposit_asset_price\", deposit_asset: depositAsset },\n };\n}\n\nconst VALID_MESSAGE_TYPES = new Set([\n \"book_update\",\n \"pong\",\n \"user\",\n \"error\",\n \"price_history\",\n \"trades\",\n \"auth\",\n \"ticker\",\n \"market\",\n \"deposit_price\",\n \"deposit_asset_price\",\n]);\n\nexport function parseMessageIn(input: string): MessageIn {\n const parsed: unknown = JSON.parse(input);\n if (typeof parsed !== \"object\" || parsed === null || !(\"type\" in parsed)) {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message: missing \"type\" field`);\n }\n const obj = parsed as Record<string, unknown>;\n if (typeof obj.type !== \"string\" || !VALID_MESSAGE_TYPES.has(obj.type)) {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message type: \"${String(obj.type)}\"`);\n }\n if (!(\"version\" in obj) || typeof obj.version !== \"number\") {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message: missing or invalid \"version\" field`);\n }\n if (!(\"data\" in obj) || typeof obj.data !== \"object\" || obj.data === null) {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message: missing or invalid \"data\" field`);\n }\n const message = parsed as MessageIn;\n if (message.type === \"user\") {\n return {\n ...message,\n data: normalizeUserUpdate(message.data as Parameters<typeof normalizeUserUpdate>[0]),\n };\n }\n return message;\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ws/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AA4FA,wCAYC;AAED,oBAEC;AAYD,wCAcC;AAMD,4CAcC;AAED,0CAQC;AAED,8CAQC;AAED,sCAQC;AAED,0CAQC;AAED,sDAUC;AAED,0DASC;AAED,0CAQC;AAED,8CAQC;AAED,0CAQC;AAED,8CAQC;AAED,sDASC;AAED,0DASC;AAOD,gEAKC;AAED,oEAKC;AAgBD,wCAuBC;AAhVD,+CAA6F;AAE7F,iEAIyC;AAOzC,oCAAmD;AACnD,gCAA6C;AAG7C,gDAA8B;AAC9B,kDAAgC;AAyDnB,QAAA,iBAAiB,GAAa;IACzC,GAAG,EAAE,IAAA,WAAK,EAAC,kBAAY,CAAC,IAAI,CAAC;IAC7B,SAAS,EAAE,IAAI;IACf,oBAAoB,EAAE,EAAE;IACxB,oBAAoB,EAAE,KAAK;IAC3B,cAAc,EAAE,MAAM;IACtB,aAAa,EAAE,MAAM;CACtB,CAAC;AAEF,IAAY,UAKX;AALD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,0BAAmB,EAAC,OAAO,CAAC,IAAiD,CAAC;SACrF,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { MarketEvent } from \"../domain/market\";\nimport { normalizeUserUpdate, type AuthUpdate, type UserUpdate } from \"../domain/order/wire\";\nimport type { OrderBook, WsTickerData } from \"../domain/orderbook\";\nimport {\n FULL_PRECISION,\n normalizeAggregation,\n type BookAggregation,\n} from \"../domain/orderbook/aggregation\";\nimport type {\n DepositAssetPriceEvent,\n DepositPrice,\n PriceHistory,\n} from \"../domain/price_history\";\nimport type { WsTrade } from \"../domain/trade\";\nimport { WsError as WsErrorClass } from \"../error\";\nimport { LightconeEnv, wsUrl } from \"../env\";\nimport type { OrderBookId, PubkeyStr, Resolution } from \"../shared\";\n\nexport * from \"./client.node\";\nexport * from \"./subscriptions\";\nexport type { IWsClient } from \"./types\";\n\nexport type MessageOut =\n | { method: \"subscribe\"; params: import(\"./subscriptions\").SubscribeParams }\n | { method: \"unsubscribe\"; params: import(\"./subscriptions\").UnsubscribeParams }\n | { method: \"ping\" };\n\nexport type MessageIn =\n | { type: \"book_update\"; version: number; data: OrderBook }\n | { type: \"pong\"; version: number; data: Record<string, never> }\n | { type: \"user\"; version: number; data: UserUpdate }\n | { type: \"error\"; version: number; data: WsError }\n | { type: \"price_history\"; version: number; data: PriceHistory }\n | { type: \"trades\"; version: number; data: WsTrade }\n | { type: \"auth\"; version: number; data: AuthUpdate }\n | { type: \"ticker\"; version: number; data: WsTickerData }\n | { type: \"market\"; version: number; data: MarketEvent }\n | { type: \"deposit_price\"; version: number; data: DepositPrice }\n | { type: \"deposit_asset_price\"; version: number; data: DepositAssetPriceEvent };\n\nexport type Kind = MessageIn;\n\nexport interface WsError {\n error: string;\n code?: string;\n orderbook_id?: string;\n /**\n * Aggregation of the affected book subscription on book-scoped errors\n * (`ENGINE_UNAVAILABLE`, `SUBSCRIPTION_LIMIT_REACHED`,\n * `INVALID_ORDERBOOK_SUBSCRIPTION`). Absent = full precision; pass to\n * `aggregationFromFrame` to identify the `(orderbook, aggregation)` pair.\n */\n n_sig_figs?: number;\n mantissa?: number;\n wallet_address?: string;\n deposit_asset?: string;\n hint?: string;\n details?: string;\n}\n\nexport type WsEvent =\n | { type: \"Message\"; message: MessageIn }\n | { type: \"Connected\" }\n | { type: \"Disconnected\"; code?: number; reason: string }\n | { type: \"Error\"; error: string }\n | { type: \"MaxReconnectReached\" };\n\nexport interface WsConfig {\n url: string;\n reconnect: boolean;\n maxReconnectAttempts: number;\n baseReconnectDelayMs: number;\n pingIntervalMs: number;\n pongTimeoutMs: number;\n}\n\nexport const WS_DEFAULT_CONFIG: WsConfig = {\n url: wsUrl(LightconeEnv.Prod),\n reconnect: true,\n maxReconnectAttempts: 10,\n baseReconnectDelayMs: 1_000,\n pingIntervalMs: 30_000,\n pongTimeoutMs: 10_000,\n};\n\nexport enum ReadyState {\n Connecting = 0,\n Open = 1,\n Closing = 2,\n Closed = 3,\n}\n\nexport function readyStateFrom(value: number): ReadyState {\n switch (value) {\n case 0:\n return ReadyState.Connecting;\n case 1:\n return ReadyState.Open;\n case 2:\n return ReadyState.Closing;\n case 3:\n default:\n return ReadyState.Closed;\n }\n}\n\nexport function ping(): MessageOut {\n return { method: \"ping\" };\n}\n\n/**\n * Subscribe to book snapshots, optionally aggregated (Hyperliquid-style).\n *\n * Omit `aggregation` for the raw book. The aggregation is normalized before\n * sending ((5, none) → (5, 1)); validate with `validateAggregation` first —\n * invalid combinations are rejected server-side with\n * `INVALID_ORDERBOOK_SUBSCRIPTION`. `undefined` fields are dropped by\n * `JSON.stringify`, so full precision stays byte-identical to the\n * pre-aggregation message.\n */\nexport function subscribeBooks(\n orderbookIds: OrderBookId[],\n aggregation: BookAggregation = FULL_PRECISION\n): MessageOut {\n const normalized = normalizeAggregation(aggregation);\n return {\n method: \"subscribe\",\n params: {\n type: \"book_update\",\n orderbook_ids: orderbookIds,\n nSigFigs: normalized.nSigFigs,\n mantissa: normalized.mantissa,\n },\n };\n}\n\n/**\n * Unsubscribe a book subscription. The aggregation must match the one\n * subscribed (normalized) or the server removes nothing.\n */\nexport function unsubscribeBooks(\n orderbookIds: OrderBookId[],\n aggregation: BookAggregation = FULL_PRECISION\n): MessageOut {\n const normalized = normalizeAggregation(aggregation);\n return {\n method: \"unsubscribe\",\n params: {\n type: \"book_update\",\n orderbook_ids: orderbookIds,\n nSigFigs: normalized.nSigFigs,\n mantissa: normalized.mantissa,\n },\n };\n}\n\nexport function subscribeTrades(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"trades\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function unsubscribeTrades(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"trades\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function subscribeUser(walletAddress: PubkeyStr): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"user\",\n wallet_address: walletAddress,\n },\n };\n}\n\nexport function unsubscribeUser(walletAddress: PubkeyStr): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"user\",\n wallet_address: walletAddress,\n },\n };\n}\n\nexport function subscribePriceHistory(orderbookId: OrderBookId, resolution: Resolution): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"price_history\",\n orderbook_id: orderbookId,\n resolution,\n include_ohlcv: false,\n },\n };\n}\n\nexport function unsubscribePriceHistory(orderbookId: OrderBookId, resolution: Resolution): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"price_history\",\n orderbook_id: orderbookId,\n resolution,\n },\n };\n}\n\nexport function subscribeTicker(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"ticker\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function unsubscribeTicker(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"ticker\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function subscribeMarket(marketPubkey: PubkeyStr): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"market\",\n market_pubkey: marketPubkey,\n },\n };\n}\n\nexport function unsubscribeMarket(marketPubkey: PubkeyStr): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"market\",\n market_pubkey: marketPubkey,\n },\n };\n}\n\nexport function subscribeDepositPrice(depositAsset: string, resolution: Resolution): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"deposit_price\",\n deposit_asset: depositAsset,\n resolution,\n },\n };\n}\n\nexport function unsubscribeDepositPrice(depositAsset: string, resolution: Resolution): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"deposit_price\",\n deposit_asset: depositAsset,\n resolution,\n },\n };\n}\n\n/**\n * Subscribe to the live spot price for one deposit asset (snapshot +\n * per-asset price ticks). Distinct from `subscribeDepositPrice`, which\n * carries OHLCV candles per resolution.\n */\nexport function subscribeDepositAssetPrice(depositAsset: string): MessageOut {\n return {\n method: \"subscribe\",\n params: { type: \"deposit_asset_price\", deposit_asset: depositAsset },\n };\n}\n\nexport function unsubscribeDepositAssetPrice(depositAsset: string): MessageOut {\n return {\n method: \"unsubscribe\",\n params: { type: \"deposit_asset_price\", deposit_asset: depositAsset },\n };\n}\n\nconst VALID_MESSAGE_TYPES = new Set([\n \"book_update\",\n \"pong\",\n \"user\",\n \"error\",\n \"price_history\",\n \"trades\",\n \"auth\",\n \"ticker\",\n \"market\",\n \"deposit_price\",\n \"deposit_asset_price\",\n]);\n\nexport function parseMessageIn(input: string): MessageIn {\n const parsed: unknown = JSON.parse(input);\n if (typeof parsed !== \"object\" || parsed === null || !(\"type\" in parsed)) {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message: missing \"type\" field`);\n }\n const obj = parsed as Record<string, unknown>;\n if (typeof obj.type !== \"string\" || !VALID_MESSAGE_TYPES.has(obj.type)) {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message type: \"${String(obj.type)}\"`);\n }\n if (!(\"version\" in obj) || typeof obj.version !== \"number\") {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message: missing or invalid \"version\" field`);\n }\n if (!(\"data\" in obj) || typeof obj.data !== \"object\" || obj.data === null) {\n throw new WsErrorClass(\"ProtocolError\", `Invalid WS message: missing or invalid \"data\" field`);\n }\n const message = parsed as MessageIn;\n if (message.type === \"user\") {\n return {\n ...message,\n data: normalizeUserUpdate(message.data as Parameters<typeof normalizeUserUpdate>[0]),\n };\n }\n return message;\n}\n"]}
@@ -1,7 +1,17 @@
1
1
  import type { OrderBookId, PubkeyStr, Resolution } from "../shared";
2
+ /**
3
+ * Book subscriptions optionally carry a Hyperliquid-style aggregation
4
+ * (`nSigFigs`/`mantissa`, wire spelling — omit both for full precision; the
5
+ * backend rejects unknown/snake_case params). Each `(orderbook, aggregation)`
6
+ * pair is a distinct subscription: one connection may hold multiple
7
+ * aggregation views of the same orderbook, and unsubscribe must repeat the
8
+ * same (normalized) aggregation to match.
9
+ */
2
10
  export type SubscribeParams = {
3
11
  type: "book_update";
4
12
  orderbook_ids: OrderBookId[];
13
+ nSigFigs?: number;
14
+ mantissa?: number;
5
15
  } | {
6
16
  type: "trades";
7
17
  orderbook_ids: OrderBookId[];
@@ -30,6 +40,8 @@ export type SubscribeParams = {
30
40
  export type UnsubscribeParams = {
31
41
  type: "book_update";
32
42
  orderbook_ids: OrderBookId[];
43
+ nSigFigs?: number;
44
+ mantissa?: number;
33
45
  } | {
34
46
  type: "trades";
35
47
  orderbook_ids: OrderBookId[];
@@ -1 +1 @@
1
- {"version":3,"file":"subscriptions.d.ts","sourceRoot":"","sources":["../../src/ws/subscriptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEpE,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,aA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,GAAG,MAAM,CAyB/D;AAED,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,eAAe,EAC1B,WAAW,EAAE,iBAAiB,GAC7B,OAAO,CAyCT"}
@@ -2,10 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.subscriptionKey = subscriptionKey;
4
4
  exports.unsubscribeMatches = unsubscribeMatches;
5
+ const aggregation_1 = require("../domain/orderbook/aggregation");
5
6
  function subscriptionKey(params) {
6
7
  switch (params.type) {
7
- case "book_update":
8
- return `book:${idsKey(params.orderbook_ids)}`;
8
+ case "book_update": {
9
+ const aggregation = { nSigFigs: params.nSigFigs, mantissa: params.mantissa };
10
+ // Full precision keeps the pre-aggregation key shape so existing
11
+ // consumers' tracked subscriptions stay stable.
12
+ return (0, aggregation_1.isFullPrecision)(aggregation)
13
+ ? `book:${idsKey(params.orderbook_ids)}`
14
+ : `book:${idsKey(params.orderbook_ids)}:${(0, aggregation_1.aggregationKeySuffix)(aggregation)}`;
15
+ }
9
16
  case "trades":
10
17
  return `trades:${idsKey(params.orderbook_ids)}`;
11
18
  case "user":
@@ -27,8 +34,11 @@ function unsubscribeMatches(subscribe, unsubscribe) {
27
34
  return false;
28
35
  }
29
36
  switch (subscribe.type) {
30
- case "book_update":
31
- return idsKey(subscribe.orderbook_ids) === idsKey(unsubscribe.orderbook_ids);
37
+ case "book_update": {
38
+ const unsubscribeBooks = unsubscribe;
39
+ return (idsKey(subscribe.orderbook_ids) === idsKey(unsubscribeBooks.orderbook_ids) &&
40
+ (0, aggregation_1.aggregationsEqual)({ nSigFigs: subscribe.nSigFigs, mantissa: subscribe.mantissa }, { nSigFigs: unsubscribeBooks.nSigFigs, mantissa: unsubscribeBooks.mantissa }));
41
+ }
32
42
  case "trades":
33
43
  return idsKey(subscribe.orderbook_ids) === idsKey(unsubscribe.orderbook_ids);
34
44
  case "ticker":