@polyester/sdk 0.35.0-devnet-20261111140253 → 0.35.0-devnet-20261111161451

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 (121) hide show
  1. package/CHANGELOG.md +10 -2
  2. package/dist/client.d.ts +6 -0
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.js +6 -0
  5. package/dist/client.js.map +1 -1
  6. package/dist/gen/ai/v1/assistant_pb.d.ts +2 -2
  7. package/dist/gen/ai/v1/assistant_pb.js +2 -2
  8. package/dist/gen/index.d.ts +11 -11
  9. package/dist/gen/index.js +9 -9
  10. package/dist/gen/ledger/read/v1/ledger_read_pb.d.ts +1 -1
  11. package/dist/gen/orders/v1/orders_read_pb.d.ts +1 -1
  12. package/dist/index.d.ts +10 -2
  13. package/dist/services/api-keys/api-keys.d.ts +16 -1
  14. package/dist/services/api-keys/api-keys.d.ts.map +1 -1
  15. package/dist/services/api-keys/api-keys.js +25 -1
  16. package/dist/services/api-keys/api-keys.js.map +1 -1
  17. package/dist/services/api-keys/api-keys.schemas.d.ts +112 -1
  18. package/dist/services/api-keys/api-keys.schemas.d.ts.map +1 -1
  19. package/dist/services/api-keys/api-keys.schemas.js +26 -2
  20. package/dist/services/api-keys/api-keys.schemas.js.map +1 -1
  21. package/dist/services/api-keys/api-keys.types.d.ts +2 -2
  22. package/dist/services/api-keys/index.d.ts +2 -2
  23. package/dist/services/assistant/assistant-events.schemas.d.ts +4618 -0
  24. package/dist/services/assistant/assistant-events.schemas.d.ts.map +1 -0
  25. package/dist/services/assistant/assistant-events.schemas.js +485 -0
  26. package/dist/services/assistant/assistant-events.schemas.js.map +1 -0
  27. package/dist/services/assistant/assistant.codecs.d.ts +24 -0
  28. package/dist/services/assistant/assistant.codecs.d.ts.map +1 -0
  29. package/dist/services/assistant/assistant.codecs.js +88 -0
  30. package/dist/services/assistant/assistant.codecs.js.map +1 -0
  31. package/dist/services/assistant/assistant.d.ts +76 -0
  32. package/dist/services/assistant/assistant.d.ts.map +1 -0
  33. package/dist/services/assistant/assistant.js +133 -0
  34. package/dist/services/assistant/assistant.js.map +1 -0
  35. package/dist/services/assistant/assistant.schemas.d.ts +184 -0
  36. package/dist/services/assistant/assistant.schemas.d.ts.map +1 -0
  37. package/dist/services/assistant/assistant.schemas.js +135 -0
  38. package/dist/services/assistant/assistant.schemas.js.map +1 -0
  39. package/dist/services/assistant/assistant.types.d.ts +4 -0
  40. package/dist/services/assistant/service.d.ts +8 -0
  41. package/dist/services/assistant/service.d.ts.map +1 -0
  42. package/dist/services/assistant/service.js +9 -0
  43. package/dist/services/assistant/service.js.map +1 -0
  44. package/dist/services/auto-withdraw/auto-withdraw.schemas.d.ts +22 -22
  45. package/dist/services/auto-withdraw/auto-withdraw.schemas.js +1 -1
  46. package/dist/services/balances/balances.js +1 -1
  47. package/dist/services/balances/balances.schemas.d.ts +3 -3
  48. package/dist/services/candles/candles.js +1 -1
  49. package/dist/services/candles/candles.schemas.d.ts +10 -10
  50. package/dist/services/candles/candles.schemas.js +5 -2
  51. package/dist/services/candles/candles.schemas.js.map +1 -1
  52. package/dist/services/changelog/changelog.schemas.d.ts +17 -17
  53. package/dist/services/checkpoints/checkpoints.schemas.d.ts +3 -3
  54. package/dist/services/heatmap/heatmap.schemas.d.ts +13 -13
  55. package/dist/services/lifecycle/lifecycle.schemas.d.ts +148 -148
  56. package/dist/services/market-data/market-data.js +1 -1
  57. package/dist/services/market-overview/market-overview.schemas.d.ts +4 -4
  58. package/dist/services/orderbook/orderbook.schemas.d.ts +1 -1
  59. package/dist/services/orders/order-errors.schemas.d.ts +1 -1
  60. package/dist/services/orders/orders-batch.schemas.d.ts +27 -27
  61. package/dist/services/orders/orders-input.schemas.d.ts +3 -3
  62. package/dist/services/orders/orders-input.schemas.js +1 -1
  63. package/dist/services/orders/orders-modify.schemas.js +1 -1
  64. package/dist/services/orders/orders-output.schemas.d.ts +11 -11
  65. package/dist/services/orders/orders-output.schemas.js +3 -3
  66. package/dist/services/orders/orders-risk.schemas.js +1 -1
  67. package/dist/services/orders/orders.codecs.js +1 -1
  68. package/dist/services/orders/orders.js +3 -3
  69. package/dist/services/price-alerts/price-alerts.codecs.d.ts +20 -0
  70. package/dist/services/price-alerts/price-alerts.codecs.d.ts.map +1 -0
  71. package/dist/services/price-alerts/price-alerts.codecs.js +66 -0
  72. package/dist/services/price-alerts/price-alerts.codecs.js.map +1 -0
  73. package/dist/services/price-alerts/price-alerts.d.ts +38 -0
  74. package/dist/services/price-alerts/price-alerts.d.ts.map +1 -0
  75. package/dist/services/price-alerts/price-alerts.js +60 -0
  76. package/dist/services/price-alerts/price-alerts.js.map +1 -0
  77. package/dist/services/price-alerts/price-alerts.schemas.d.ts +309 -0
  78. package/dist/services/price-alerts/price-alerts.schemas.d.ts.map +1 -0
  79. package/dist/services/price-alerts/price-alerts.schemas.js +130 -0
  80. package/dist/services/price-alerts/price-alerts.schemas.js.map +1 -0
  81. package/dist/services/price-alerts/price-alerts.types.d.ts +3 -0
  82. package/dist/services/price-alerts/service.d.ts +8 -0
  83. package/dist/services/price-alerts/service.d.ts.map +1 -0
  84. package/dist/services/price-alerts/service.js +9 -0
  85. package/dist/services/price-alerts/service.js.map +1 -0
  86. package/dist/services/social-verification/social-verification.schemas.d.ts +1 -1
  87. package/dist/services/subaccounts/subaccounts.schemas.d.ts +3 -3
  88. package/dist/services/system/service.d.ts +8 -0
  89. package/dist/services/system/service.d.ts.map +1 -0
  90. package/dist/services/system/service.js +9 -0
  91. package/dist/services/system/service.js.map +1 -0
  92. package/dist/services/system/system.d.ts +25 -0
  93. package/dist/services/system/system.d.ts.map +1 -0
  94. package/dist/services/system/system.js +24 -0
  95. package/dist/services/system/system.js.map +1 -0
  96. package/dist/services/trades/trades.js +1 -1
  97. package/dist/services/trades/trades.schemas.d.ts +2 -2
  98. package/dist/services/trades/trades.schemas.js +1 -1
  99. package/dist/services/transfers/transfers.schemas.d.ts +1 -1
  100. package/dist/services/triggers/trigger-child-order.schemas.js +1 -1
  101. package/dist/services/triggers/trigger-input.schemas.d.ts +2 -2
  102. package/dist/services/triggers/trigger-input.schemas.js +1 -1
  103. package/dist/services/triggers/triggers-output.schemas.d.ts +61 -61
  104. package/dist/services/triggers/triggers.codecs.js +1 -1
  105. package/dist/services/triggers/triggers.js +2 -2
  106. package/dist/shared/connect-error-mapping.d.ts.map +1 -1
  107. package/dist/shared/connect-error-mapping.js +1 -0
  108. package/dist/shared/connect-error-mapping.js.map +1 -1
  109. package/dist/shared/error-detail.d.ts +18 -10
  110. package/dist/shared/error-detail.d.ts.map +1 -1
  111. package/dist/shared/error-detail.js +2 -0
  112. package/dist/shared/error-detail.js.map +1 -1
  113. package/dist/shared/error-details/alerts.js +15 -0
  114. package/dist/shared/error-details/alerts.js.map +1 -0
  115. package/dist/shared/error-details/assistant.js +15 -0
  116. package/dist/shared/error-details/assistant.js.map +1 -0
  117. package/dist/shared/rate-limit.schemas.d.ts +1 -1
  118. package/dist/wired-services.d.ts.map +1 -1
  119. package/dist/wired-services.js +11 -5
  120. package/dist/wired-services.js.map +1 -1
  121. package/package.json +1 -1
@@ -0,0 +1,66 @@
1
+ import "../../gen/alerts/v1/price_alerts_pb.js";
2
+ //#region src/services/price-alerts/price-alerts.codecs.ts
3
+ const PRICE_ALERT_DIRECTION_VALUES = ["above", "below"];
4
+ const PRICE_ALERT_PRICE_SOURCE_VALUES = ["last_price", "index_price"];
5
+ const PRICE_ALERT_STATUS_VALUES = [
6
+ "active",
7
+ "triggered",
8
+ "cancelled"
9
+ ];
10
+ const PRICE_ALERT_CHANNEL_VALUES = ["in_app", "telegram"];
11
+ const PriceAlertDirectionCodec = {
12
+ inputToProto: {
13
+ above: 1,
14
+ below: 2
15
+ },
16
+ protoToOutput: {
17
+ [0]: "unspecified",
18
+ [1]: "above",
19
+ [2]: "below"
20
+ }
21
+ };
22
+ const PriceAlertPriceSourceCodec = {
23
+ inputToProto: {
24
+ last_price: 1,
25
+ index_price: 2
26
+ },
27
+ protoToOutput: {
28
+ [0]: "unspecified",
29
+ [1]: "last_price",
30
+ [2]: "index_price"
31
+ }
32
+ };
33
+ const PriceAlertStatusCodec = {
34
+ inputToProto: {
35
+ active: 1,
36
+ triggered: 2,
37
+ cancelled: 3
38
+ },
39
+ protoToOutput: {
40
+ [0]: "unspecified",
41
+ [1]: "active",
42
+ [2]: "triggered",
43
+ [3]: "cancelled"
44
+ }
45
+ };
46
+ const PriceAlertChannelCodec = {
47
+ inputToProto: {
48
+ in_app: 1,
49
+ telegram: 2
50
+ },
51
+ protoToOutput: {
52
+ [0]: "unspecified",
53
+ [1]: "in_app",
54
+ [2]: "telegram"
55
+ }
56
+ };
57
+ const PriceAlertUpdateOutcomeCodec = { protoToOutput: {
58
+ [0]: "unspecified",
59
+ [1]: "applied",
60
+ [2]: "unchanged",
61
+ [3]: "replayed"
62
+ } };
63
+ //#endregion
64
+ export { PRICE_ALERT_CHANNEL_VALUES, PRICE_ALERT_DIRECTION_VALUES, PRICE_ALERT_PRICE_SOURCE_VALUES, PRICE_ALERT_STATUS_VALUES, PriceAlertChannelCodec, PriceAlertDirectionCodec, PriceAlertPriceSourceCodec, PriceAlertStatusCodec, PriceAlertUpdateOutcomeCodec };
65
+
66
+ //# sourceMappingURL=price-alerts.codecs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"price-alerts.codecs.js","names":[],"sources":["../../../src/services/price-alerts/price-alerts.codecs.ts"],"sourcesContent":["import * as Proto from \"../../gen/alerts/v1/price_alerts_pb.js\";\nimport type { InputToProto, ProtoToOutput } from \"../../utils/types.js\";\n\nexport const PRICE_ALERT_DIRECTION_VALUES = [\"above\", \"below\"] as const;\n/** `above` fires at or above the alert price, `below` at or below it. */\nexport type PriceAlertDirection = (typeof PRICE_ALERT_DIRECTION_VALUES)[number];\n\nexport const PRICE_ALERT_PRICE_SOURCE_VALUES = [\"last_price\", \"index_price\"] as const;\nexport type PriceAlertPriceSource = (typeof PRICE_ALERT_PRICE_SOURCE_VALUES)[number];\n\nexport const PRICE_ALERT_STATUS_VALUES = [\"active\", \"triggered\", \"cancelled\"] as const;\nexport type PriceAlertStatus = (typeof PRICE_ALERT_STATUS_VALUES)[number];\n\nexport const PRICE_ALERT_CHANNEL_VALUES = [\"in_app\", \"telegram\"] as const;\nexport type PriceAlertChannel = (typeof PRICE_ALERT_CHANNEL_VALUES)[number];\n\nexport const PRICE_ALERT_UPDATE_OUTCOME_VALUES = [\"applied\", \"unchanged\", \"replayed\"] as const;\n/**\n * What an update did: `applied` changed the alert, `unchanged` found it already as requested,\n * and `replayed` recognized a reused idempotency key and changed nothing.\n */\nexport type PriceAlertUpdateOutcome = (typeof PRICE_ALERT_UPDATE_OUTCOME_VALUES)[number];\n\nexport const PriceAlertDirectionCodec = {\n inputToProto: {\n above: Proto.AlertDirection.ABOVE,\n below: Proto.AlertDirection.BELOW,\n } satisfies InputToProto<PriceAlertDirection, Proto.AlertDirection>,\n protoToOutput: {\n [Proto.AlertDirection.DIRECTION_UNSPECIFIED]: \"unspecified\",\n [Proto.AlertDirection.ABOVE]: \"above\",\n [Proto.AlertDirection.BELOW]: \"below\",\n } satisfies ProtoToOutput<Proto.AlertDirection, PriceAlertDirection>,\n} as const;\n\nexport const PriceAlertPriceSourceCodec = {\n inputToProto: {\n last_price: Proto.AlertPriceSource.LAST_PRICE,\n index_price: Proto.AlertPriceSource.INDEX_PRICE,\n } satisfies InputToProto<PriceAlertPriceSource, Proto.AlertPriceSource>,\n protoToOutput: {\n [Proto.AlertPriceSource.PRICE_SOURCE_UNSPECIFIED]: \"unspecified\",\n [Proto.AlertPriceSource.LAST_PRICE]: \"last_price\",\n [Proto.AlertPriceSource.INDEX_PRICE]: \"index_price\",\n } satisfies ProtoToOutput<Proto.AlertPriceSource, PriceAlertPriceSource>,\n} as const;\n\nexport const PriceAlertStatusCodec = {\n inputToProto: {\n active: Proto.AlertStatus.ACTIVE,\n triggered: Proto.AlertStatus.TRIGGERED,\n cancelled: Proto.AlertStatus.CANCELLED,\n } satisfies InputToProto<PriceAlertStatus, Proto.AlertStatus>,\n protoToOutput: {\n [Proto.AlertStatus.STATUS_UNSPECIFIED]: \"unspecified\",\n [Proto.AlertStatus.ACTIVE]: \"active\",\n [Proto.AlertStatus.TRIGGERED]: \"triggered\",\n [Proto.AlertStatus.CANCELLED]: \"cancelled\",\n } satisfies ProtoToOutput<Proto.AlertStatus, PriceAlertStatus>,\n} as const;\n\nexport const PriceAlertChannelCodec = {\n inputToProto: {\n in_app: Proto.AlertChannel.IN_APP,\n telegram: Proto.AlertChannel.TELEGRAM,\n } satisfies InputToProto<PriceAlertChannel, Proto.AlertChannel>,\n protoToOutput: {\n [Proto.AlertChannel.CHANNEL_UNSPECIFIED]: \"unspecified\",\n [Proto.AlertChannel.IN_APP]: \"in_app\",\n [Proto.AlertChannel.TELEGRAM]: \"telegram\",\n } satisfies ProtoToOutput<Proto.AlertChannel, PriceAlertChannel>,\n} as const;\n\nexport const PriceAlertUpdateOutcomeCodec = {\n protoToOutput: {\n [Proto.UpdateOutcome.UPDATE_OUTCOME_UNSPECIFIED]: \"unspecified\",\n [Proto.UpdateOutcome.APPLIED]: \"applied\",\n [Proto.UpdateOutcome.UNCHANGED]: \"unchanged\",\n [Proto.UpdateOutcome.REPLAYED]: \"replayed\",\n } satisfies ProtoToOutput<Proto.UpdateOutcome, PriceAlertUpdateOutcome>,\n} as const;\n"],"mappings":";;AAGA,MAAa,+BAA+B,CAAC,SAAS,OAAO;AAI7D,MAAa,kCAAkC,CAAC,cAAc,aAAa;AAG3E,MAAa,4BAA4B;CAAC;CAAU;CAAa;AAAW;AAG5E,MAAa,6BAA6B,CAAC,UAAU,UAAU;AAU/D,MAAa,2BAA2B;CACpC,cAAc;EACV,OAAA;EACA,OAAA;CACJ;CACA,eAAe;GACmC,IAAA;GAChB,IAAA;GACA,IAAA;CAClC;AACJ;AAEA,MAAa,6BAA6B;CACtC,cAAc;EACV,YAAA;EACA,aAAA;CACJ;CACA,eAAe;GACwC,IAAA;GACd,IAAA;GACC,IAAA;CAC1C;AACJ;AAEA,MAAa,wBAAwB;CACjC,cAAc;EACV,QAAA;EACA,WAAA;EACA,WAAA;CACJ;CACA,eAAe;GAC6B,IAAA;GACZ,IAAA;GACG,IAAA;GACA,IAAA;CACnC;AACJ;AAEA,MAAa,yBAAyB;CAClC,cAAc;EACV,QAAA;EACA,UAAA;CACJ;CACA,eAAe;GAC+B,IAAA;GACb,IAAA;GACE,IAAA;CACnC;AACJ;AAEA,MAAa,+BAA+B,EACxC,eAAe;EACuC,IAAA;EACnB,IAAA;EACE,IAAA;EACD,IAAA;AACpC,EACJ"}
@@ -0,0 +1,38 @@
1
+ import { AuthApiTransports } from "../../shared/transports.js";
2
+ import { PolyesterRequestOptions } from "../../shared/request-options.js";
3
+ import { CancelPriceAlertInput, CreatePriceAlertInput, ListPriceAlertsInput, ListPriceAlertsResult, PriceAlert, UpdatePriceAlertInput, UpdatePriceAlertResult } from "./price-alerts.schemas.js";
4
+ //#region src/services/price-alerts/price-alerts.d.ts
5
+ /**
6
+ * Manages the caller's price alerts. Alerts belong to the root account, not a trading account:
7
+ * a session and the root account's API keys see the same alerts, and an API key scoped to a
8
+ * subaccount is refused (`PermissionError`, detail `SUBACCOUNT_KEY_REFUSED`). An alert fires at
9
+ * most once, only on a crossing it observes from its `referencePrice`; `update` sets a fired
10
+ * alert again. No call changes balances, orders or account settings.
11
+ */
12
+ declare class PriceAlertsService {
13
+ #private;
14
+ constructor(transports: AuthApiTransports);
15
+ /**
16
+ * Creates an active alert. Throws `PreconditionFailedError` when the market has no index
17
+ * price (`PRICE_SOURCE_UNSUPPORTED`) or the active-alert limit is reached, and a retryable
18
+ * `ServiceUnavailableError` when the market has no current price yet.
19
+ */
20
+ create(input: CreatePriceAlertInput, options?: PolyesterRequestOptions): Promise<PriceAlert>;
21
+ /** Lists the caller's alerts, newest first. */
22
+ list(input?: ListPriceAlertsInput, options?: PolyesterRequestOptions): Promise<ListPriceAlertsResult>;
23
+ /**
24
+ * Changes an alert's direction, price or channels; omitted fields stay as they are. A new
25
+ * direction or price records a new reference price. Updating a triggered alert sets it
26
+ * again, even with no field given. A stale `expectedRevision` throws
27
+ * `RevisionConflictError`; a cancelled alert throws `PreconditionFailedError`.
28
+ */
29
+ update(input: UpdatePriceAlertInput, options?: PolyesterRequestOptions): Promise<UpdatePriceAlertResult>;
30
+ /**
31
+ * Cancels an active alert; cancelling a cancelled alert returns it unchanged. A triggered
32
+ * alert throws `PreconditionFailedError` (`ALERT_TRIGGERED`).
33
+ */
34
+ cancel(input: CancelPriceAlertInput, options?: PolyesterRequestOptions): Promise<PriceAlert>;
35
+ }
36
+ //#endregion
37
+ export { PriceAlertsService };
38
+ //# sourceMappingURL=price-alerts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"price-alerts.d.ts","names":[],"sources":["../../../src/services/price-alerts/price-alerts.ts"],"mappings":";;;;;;;;;;;cAiCa;;EAGG,YAAA,YAAY;;;;;;EASlB,OACF,OAAO,uBACP,UAAU,0BACX,QAAQ;;EAUL,KACF,QAAO,sBACP,UAAU,0BACX,QAAQ;;;;;;;EAeL,OACF,OAAO,uBACP,UAAU,0BACX,QAAQ;;;;;EAaL,OACF,OAAO,uBACP,UAAU,0BACX,QAAQ"}
@@ -0,0 +1,60 @@
1
+ import { parse } from "../../shared/validation.js";
2
+ import { removeUndefined } from "../../utils/remove-undefined.js";
3
+ import { toConnectCallOptions } from "../../shared/request-options.js";
4
+ import { PriceAlertService } from "../../gen/alerts/v1/price_alerts_pb.js";
5
+ import { CancelPriceAlertInputSchema, CreatePriceAlertInputSchema, ListPriceAlertsInputSchema, ListPriceAlertsResultSchema, PriceAlertSchema, UpdatePriceAlertInputSchema, UpdatePriceAlertResultSchema } from "./price-alerts.schemas.js";
6
+ import { createClient } from "@connectrpc/connect";
7
+ //#region src/services/price-alerts/price-alerts.ts
8
+ /**
9
+ * Manages the caller's price alerts. Alerts belong to the root account, not a trading account:
10
+ * a session and the root account's API keys see the same alerts, and an API key scoped to a
11
+ * subaccount is refused (`PermissionError`, detail `SUBACCOUNT_KEY_REFUSED`). An alert fires at
12
+ * most once, only on a crossing it observes from its `referencePrice`; `update` sets a fired
13
+ * alert again. No call changes balances, orders or account settings.
14
+ */
15
+ var PriceAlertsService = class {
16
+ #client;
17
+ constructor(transports) {
18
+ this.#client = createClient(PriceAlertService, transports.authApi);
19
+ }
20
+ /**
21
+ * Creates an active alert. Throws `PreconditionFailedError` when the market has no index
22
+ * price (`PRICE_SOURCE_UNSUPPORTED`) or the active-alert limit is reached, and a retryable
23
+ * `ServiceUnavailableError` when the market has no current price yet.
24
+ */
25
+ async create(input, options) {
26
+ const request = parse(CreatePriceAlertInputSchema, input);
27
+ const response = await this.#client.createAlert(removeUndefined(request), toConnectCallOptions(options));
28
+ return parse(PriceAlertSchema, response.alert);
29
+ }
30
+ /** Lists the caller's alerts, newest first. */
31
+ async list(input = {}, options) {
32
+ const request = parse(ListPriceAlertsInputSchema, input);
33
+ const response = await this.#client.listAlerts(removeUndefined(request), toConnectCallOptions(options));
34
+ return parse(ListPriceAlertsResultSchema, response);
35
+ }
36
+ /**
37
+ * Changes an alert's direction, price or channels; omitted fields stay as they are. A new
38
+ * direction or price records a new reference price. Updating a triggered alert sets it
39
+ * again, even with no field given. A stale `expectedRevision` throws
40
+ * `RevisionConflictError`; a cancelled alert throws `PreconditionFailedError`.
41
+ */
42
+ async update(input, options) {
43
+ const request = parse(UpdatePriceAlertInputSchema, input);
44
+ const response = await this.#client.updateAlert(removeUndefined(request), toConnectCallOptions(options));
45
+ return parse(UpdatePriceAlertResultSchema, response);
46
+ }
47
+ /**
48
+ * Cancels an active alert; cancelling a cancelled alert returns it unchanged. A triggered
49
+ * alert throws `PreconditionFailedError` (`ALERT_TRIGGERED`).
50
+ */
51
+ async cancel(input, options) {
52
+ const request = parse(CancelPriceAlertInputSchema, input);
53
+ const response = await this.#client.cancelAlert(request, toConnectCallOptions(options));
54
+ return parse(PriceAlertSchema, response.alert);
55
+ }
56
+ };
57
+ //#endregion
58
+ export { PriceAlertsService };
59
+
60
+ //# sourceMappingURL=price-alerts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"price-alerts.js","names":["#client","Proto.PriceAlertService"],"sources":["../../../src/services/price-alerts/price-alerts.ts"],"sourcesContent":["import { createClient, type Client } from \"@connectrpc/connect\";\nimport * as Proto from \"../../gen/alerts/v1/price_alerts_pb.js\";\nimport {\n toConnectCallOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport type { AuthApiTransports } from \"../../shared/transports.js\";\nimport { parse } from \"../../shared/validation.js\";\nimport { removeUndefined } from \"../../utils/remove-undefined.js\";\nimport {\n CancelPriceAlertInputSchema,\n CreatePriceAlertInputSchema,\n ListPriceAlertsInputSchema,\n ListPriceAlertsResultSchema,\n PriceAlertSchema,\n UpdatePriceAlertInputSchema,\n UpdatePriceAlertResultSchema,\n type CancelPriceAlertInput,\n type CreatePriceAlertInput,\n type ListPriceAlertsInput,\n type ListPriceAlertsResult,\n type PriceAlert,\n type UpdatePriceAlertInput,\n type UpdatePriceAlertResult,\n} from \"./price-alerts.schemas.js\";\n\n/**\n * Manages the caller's price alerts. Alerts belong to the root account, not a trading account:\n * a session and the root account's API keys see the same alerts, and an API key scoped to a\n * subaccount is refused (`PermissionError`, detail `SUBACCOUNT_KEY_REFUSED`). An alert fires at\n * most once, only on a crossing it observes from its `referencePrice`; `update` sets a fired\n * alert again. No call changes balances, orders or account settings.\n */\nexport class PriceAlertsService {\n #client: Client<typeof Proto.PriceAlertService>;\n\n constructor(transports: AuthApiTransports) {\n this.#client = createClient(Proto.PriceAlertService, transports.authApi);\n }\n\n /**\n * Creates an active alert. Throws `PreconditionFailedError` when the market has no index\n * price (`PRICE_SOURCE_UNSUPPORTED`) or the active-alert limit is reached, and a retryable\n * `ServiceUnavailableError` when the market has no current price yet.\n */\n async create(\n input: CreatePriceAlertInput,\n options?: PolyesterRequestOptions,\n ): Promise<PriceAlert> {\n const request = parse(CreatePriceAlertInputSchema, input);\n const response = await this.#client.createAlert(\n removeUndefined(request),\n toConnectCallOptions(options),\n );\n return parse(PriceAlertSchema, response.alert);\n }\n\n /** Lists the caller's alerts, newest first. */\n async list(\n input: ListPriceAlertsInput = {},\n options?: PolyesterRequestOptions,\n ): Promise<ListPriceAlertsResult> {\n const request = parse(ListPriceAlertsInputSchema, input);\n const response = await this.#client.listAlerts(\n removeUndefined(request),\n toConnectCallOptions(options),\n );\n return parse(ListPriceAlertsResultSchema, response);\n }\n\n /**\n * Changes an alert's direction, price or channels; omitted fields stay as they are. A new\n * direction or price records a new reference price. Updating a triggered alert sets it\n * again, even with no field given. A stale `expectedRevision` throws\n * `RevisionConflictError`; a cancelled alert throws `PreconditionFailedError`.\n */\n async update(\n input: UpdatePriceAlertInput,\n options?: PolyesterRequestOptions,\n ): Promise<UpdatePriceAlertResult> {\n const request = parse(UpdatePriceAlertInputSchema, input);\n const response = await this.#client.updateAlert(\n removeUndefined(request),\n toConnectCallOptions(options),\n );\n return parse(UpdatePriceAlertResultSchema, response);\n }\n\n /**\n * Cancels an active alert; cancelling a cancelled alert returns it unchanged. A triggered\n * alert throws `PreconditionFailedError` (`ALERT_TRIGGERED`).\n */\n async cancel(\n input: CancelPriceAlertInput,\n options?: PolyesterRequestOptions,\n ): Promise<PriceAlert> {\n const request = parse(CancelPriceAlertInputSchema, input);\n const response = await this.#client.cancelAlert(request, toConnectCallOptions(options));\n return parse(PriceAlertSchema, response.alert);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAiCA,IAAa,qBAAb,MAAgC;CAC5B;CAEA,YAAY,YAA+B;EACvC,KAAKA,UAAU,aAAaC,mBAAyB,WAAW,OAAO;CAC3E;;;;;;CAOA,MAAM,OACF,OACA,SACmB;EACnB,MAAM,UAAU,MAAM,6BAA6B,KAAK;EACxD,MAAM,WAAW,MAAM,KAAKD,QAAQ,YAChC,gBAAgB,OAAO,GACvB,qBAAqB,OAAO,CAChC;EACA,OAAO,MAAM,kBAAkB,SAAS,KAAK;CACjD;;CAGA,MAAM,KACF,QAA8B,CAAC,GAC/B,SAC8B;EAC9B,MAAM,UAAU,MAAM,4BAA4B,KAAK;EACvD,MAAM,WAAW,MAAM,KAAKA,QAAQ,WAChC,gBAAgB,OAAO,GACvB,qBAAqB,OAAO,CAChC;EACA,OAAO,MAAM,6BAA6B,QAAQ;CACtD;;;;;;;CAQA,MAAM,OACF,OACA,SAC+B;EAC/B,MAAM,UAAU,MAAM,6BAA6B,KAAK;EACxD,MAAM,WAAW,MAAM,KAAKA,QAAQ,YAChC,gBAAgB,OAAO,GACvB,qBAAqB,OAAO,CAChC;EACA,OAAO,MAAM,8BAA8B,QAAQ;CACvD;;;;;CAMA,MAAM,OACF,OACA,SACmB;EACnB,MAAM,UAAU,MAAM,6BAA6B,KAAK;EACxD,MAAM,WAAW,MAAM,KAAKA,QAAQ,YAAY,SAAS,qBAAqB,OAAO,CAAC;EACtF,OAAO,MAAM,kBAAkB,SAAS,KAAK;CACjD;AACJ"}
@@ -0,0 +1,309 @@
1
+ import { AlertChannel, AlertDirection, AlertPriceSource, AlertStatus } from "../../gen/alerts/v1/price_alerts_pb.js";
2
+ import * as v from "valibot";
3
+ //#region src/services/price-alerts/price-alerts.schemas.d.ts
4
+ declare const CreatePriceAlertInputSchema: v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
5
+ readonly symbolId: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>;
6
+ readonly direction: v.PicklistSchema<readonly ["above", "below"], undefined>;
7
+ /** Omit to watch the index price on markets that have one, else the last price. */
8
+ readonly priceSource: v.OptionalSchema<v.PicklistSchema<readonly ["last_price", "index_price"], undefined>, undefined>;
9
+ /** Alert price as a decimal string, e.g. `"90000"`. */
10
+ readonly price: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, bigint>]>;
11
+ readonly channels: v.SchemaWithPipe<readonly [v.ArraySchema<v.PicklistSchema<readonly ["in_app", "telegram"], undefined>, undefined>, v.MinLengthAction<("in_app" | "telegram")[], 1, "At least one channel is required.">, v.MaxLengthAction<("in_app" | "telegram")[], 2, "At most two channels are allowed.">, v.CheckAction<("in_app" | "telegram")[], "Channels must be distinct.">, v.TransformAction<("in_app" | "telegram")[], (AlertChannel.IN_APP | AlertChannel.TELEGRAM)[]>]>;
12
+ /** Reusing a key with the same request returns the alert it created. */
13
+ readonly idempotencyKey: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>, undefined>;
14
+ }, undefined>, v.TransformAction<{
15
+ symbolId: number;
16
+ direction: "above" | "below";
17
+ priceSource?: "last_price" | "index_price" | undefined;
18
+ price: bigint;
19
+ channels: (AlertChannel.IN_APP | AlertChannel.TELEGRAM)[];
20
+ idempotencyKey?: string | undefined;
21
+ }, {
22
+ direction: AlertDirection.ABOVE | AlertDirection.BELOW;
23
+ priceSource: AlertPriceSource.LAST_PRICE | AlertPriceSource.INDEX_PRICE | undefined;
24
+ priceTicks: bigint;
25
+ symbolId: number;
26
+ channels: (AlertChannel.IN_APP | AlertChannel.TELEGRAM)[];
27
+ idempotencyKey?: string | undefined;
28
+ }>]>;
29
+ type CreatePriceAlertInput = v.InferInput<typeof CreatePriceAlertInputSchema>;
30
+ declare const ListPriceAlertsInputSchema: v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
31
+ /** Only alerts in these states; omit or empty for every state. */
32
+ readonly statuses: v.OptionalSchema<v.ArraySchema<v.PicklistSchema<readonly ["active", "triggered", "cancelled"], undefined>, undefined>, undefined>;
33
+ /** Only alerts on this market. */
34
+ readonly symbolId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>, undefined>;
35
+ /** Page size: default 50, at most 200. */
36
+ readonly limit: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 200, undefined>]>, undefined>;
37
+ /** Previous `nextPageToken`; reuse only with the same filters. */
38
+ readonly pageToken: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, undefined>;
39
+ }, undefined>, v.TransformAction<{
40
+ statuses?: ("active" | "triggered" | "cancelled")[] | undefined;
41
+ symbolId?: number | undefined;
42
+ limit?: number | undefined;
43
+ pageToken?: string | undefined;
44
+ }, {
45
+ statuses: (AlertStatus.ACTIVE | AlertStatus.TRIGGERED | AlertStatus.CANCELLED)[] | undefined;
46
+ symbolId?: number | undefined;
47
+ limit?: number | undefined;
48
+ pageToken?: string | undefined;
49
+ }>]>;
50
+ type ListPriceAlertsInput = v.InferInput<typeof ListPriceAlertsInputSchema>;
51
+ declare const UpdatePriceAlertInputSchema: v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
52
+ readonly alertId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.TransformAction<string, bigint>]>;
53
+ /** The alert's `revision` from the last read. */
54
+ readonly expectedRevision: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, v.RegexAction<string, `${string} must be a decimal integer`>, v.TransformAction<string, bigint>]>, v.CheckAction<bigint, `${string} must be greater than 0`>]>, v.MaxValueAction<bigint, 18446744073709551615n, "expectedRevision exceeds the uint64 range">]>;
55
+ readonly direction: v.OptionalSchema<v.PicklistSchema<readonly ["above", "below"], undefined>, undefined>;
56
+ readonly price: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, bigint>]>, undefined>;
57
+ readonly channels: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.PicklistSchema<readonly ["in_app", "telegram"], undefined>, undefined>, v.MinLengthAction<("in_app" | "telegram")[], 1, "At least one channel is required.">, v.MaxLengthAction<("in_app" | "telegram")[], 2, "At most two channels are allowed.">, v.CheckAction<("in_app" | "telegram")[], "Channels must be distinct.">, v.TransformAction<("in_app" | "telegram")[], (AlertChannel.IN_APP | AlertChannel.TELEGRAM)[]>]>, undefined>;
58
+ readonly idempotencyKey: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>, undefined>;
59
+ }, undefined>, v.TransformAction<{
60
+ alertId: bigint;
61
+ expectedRevision: bigint;
62
+ direction?: "above" | "below" | undefined;
63
+ price?: bigint | undefined;
64
+ channels?: (AlertChannel.IN_APP | AlertChannel.TELEGRAM)[] | undefined;
65
+ idempotencyKey?: string | undefined;
66
+ }, {
67
+ alertId: bigint;
68
+ expectedRevision: bigint;
69
+ idempotencyKey: string | undefined;
70
+ update: Partial<{
71
+ direction: AlertDirection.ABOVE | AlertDirection.BELOW;
72
+ } & {
73
+ priceTicks: bigint;
74
+ } & {
75
+ channels: number[];
76
+ }>;
77
+ updateMask: {
78
+ paths: string[];
79
+ };
80
+ }>]>;
81
+ type UpdatePriceAlertInput = v.InferInput<typeof UpdatePriceAlertInputSchema>;
82
+ declare const CancelPriceAlertInputSchema: v.StrictObjectSchema<{
83
+ readonly alertId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.TransformAction<string, bigint>]>;
84
+ }, undefined>;
85
+ type CancelPriceAlertInput = v.InferInput<typeof CancelPriceAlertInputSchema>;
86
+ /** A price alert of the caller's root account. Prices are decimal strings. */
87
+ declare const PriceAlertSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
88
+ readonly alertId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
89
+ readonly symbolId: v.NumberSchema<undefined>;
90
+ readonly direction: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "above" | "below">]>;
91
+ readonly priceSource: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "last_price" | "index_price">]>;
92
+ readonly priceTicks: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
93
+ readonly referencePriceTicks: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
94
+ readonly armed: v.BooleanSchema<undefined>;
95
+ readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "active" | "triggered" | "cancelled">]>;
96
+ readonly channels: v.ArraySchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "in_app" | "telegram">]>, undefined>;
97
+ readonly revision: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
98
+ readonly createdAt: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ObjectSchema<{
99
+ readonly seconds: v.BigintSchema<undefined>;
100
+ readonly nanos: v.OptionalSchema<v.NumberSchema<undefined>, 0>;
101
+ }, undefined>, undefined>, v.TransformAction<{
102
+ seconds: bigint;
103
+ nanos: number;
104
+ } | undefined, number | undefined>]>;
105
+ readonly updatedAt: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ObjectSchema<{
106
+ readonly seconds: v.BigintSchema<undefined>;
107
+ readonly nanos: v.OptionalSchema<v.NumberSchema<undefined>, 0>;
108
+ }, undefined>, undefined>, v.TransformAction<{
109
+ seconds: bigint;
110
+ nanos: number;
111
+ } | undefined, number | undefined>]>;
112
+ readonly triggeredAt: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ObjectSchema<{
113
+ readonly seconds: v.BigintSchema<undefined>;
114
+ readonly nanos: v.OptionalSchema<v.NumberSchema<undefined>, 0>;
115
+ }, undefined>, undefined>, v.TransformAction<{
116
+ seconds: bigint;
117
+ nanos: number;
118
+ } | undefined, number | undefined>]>;
119
+ readonly triggeredPriceTicks: v.BigintSchema<undefined>;
120
+ }, undefined>, v.TransformAction<{
121
+ alertId: string;
122
+ symbolId: number;
123
+ direction: "unspecified" | "above" | "below";
124
+ priceSource: "unspecified" | "last_price" | "index_price";
125
+ priceTicks: string;
126
+ referencePriceTicks: string;
127
+ armed: boolean;
128
+ status: "unspecified" | "active" | "triggered" | "cancelled";
129
+ channels: ("unspecified" | "in_app" | "telegram")[];
130
+ revision: string;
131
+ createdAt?: number | undefined;
132
+ updatedAt?: number | undefined;
133
+ triggeredAt?: number | undefined;
134
+ triggeredPriceTicks: bigint;
135
+ }, {
136
+ alertId: string;
137
+ symbolId: number;
138
+ direction: "unspecified" | "above" | "below";
139
+ priceSource: "unspecified" | "last_price" | "index_price";
140
+ /** Alert price. */
141
+ price: string;
142
+ /** Price when the alert was created or last set again; it fires on a crossing from here. */
143
+ referencePrice: string;
144
+ /** False while an alert created past its price waits for the price to move back first. */
145
+ armed: boolean;
146
+ status: "unspecified" | "active" | "triggered" | "cancelled";
147
+ channels: ("unspecified" | "in_app" | "telegram")[];
148
+ /** Pass as `expectedRevision` to `update`. */
149
+ revision: string;
150
+ createdAt: number | null;
151
+ updatedAt: number | null;
152
+ /** Set only once the alert fired. */
153
+ triggeredAt: number | null;
154
+ /** Price that fired the alert; null unless it fired. */
155
+ triggeredPrice: string | null;
156
+ }>]>;
157
+ type PriceAlert = v.InferOutput<typeof PriceAlertSchema>;
158
+ declare const ListPriceAlertsResultSchema: v.ObjectSchema<{
159
+ readonly alerts: v.ArraySchema<v.SchemaWithPipe<readonly [v.ObjectSchema<{
160
+ readonly alertId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
161
+ readonly symbolId: v.NumberSchema<undefined>;
162
+ readonly direction: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "above" | "below">]>;
163
+ readonly priceSource: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "last_price" | "index_price">]>;
164
+ readonly priceTicks: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
165
+ readonly referencePriceTicks: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
166
+ readonly armed: v.BooleanSchema<undefined>;
167
+ readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "active" | "triggered" | "cancelled">]>;
168
+ readonly channels: v.ArraySchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "in_app" | "telegram">]>, undefined>;
169
+ readonly revision: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
170
+ readonly createdAt: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ObjectSchema<{
171
+ readonly seconds: v.BigintSchema<undefined>;
172
+ readonly nanos: v.OptionalSchema<v.NumberSchema<undefined>, 0>;
173
+ }, undefined>, undefined>, v.TransformAction<{
174
+ seconds: bigint;
175
+ nanos: number;
176
+ } | undefined, number | undefined>]>;
177
+ readonly updatedAt: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ObjectSchema<{
178
+ readonly seconds: v.BigintSchema<undefined>;
179
+ readonly nanos: v.OptionalSchema<v.NumberSchema<undefined>, 0>;
180
+ }, undefined>, undefined>, v.TransformAction<{
181
+ seconds: bigint;
182
+ nanos: number;
183
+ } | undefined, number | undefined>]>;
184
+ readonly triggeredAt: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ObjectSchema<{
185
+ readonly seconds: v.BigintSchema<undefined>;
186
+ readonly nanos: v.OptionalSchema<v.NumberSchema<undefined>, 0>;
187
+ }, undefined>, undefined>, v.TransformAction<{
188
+ seconds: bigint;
189
+ nanos: number;
190
+ } | undefined, number | undefined>]>;
191
+ readonly triggeredPriceTicks: v.BigintSchema<undefined>;
192
+ }, undefined>, v.TransformAction<{
193
+ alertId: string;
194
+ symbolId: number;
195
+ direction: "unspecified" | "above" | "below";
196
+ priceSource: "unspecified" | "last_price" | "index_price";
197
+ priceTicks: string;
198
+ referencePriceTicks: string;
199
+ armed: boolean;
200
+ status: "unspecified" | "active" | "triggered" | "cancelled";
201
+ channels: ("unspecified" | "in_app" | "telegram")[];
202
+ revision: string;
203
+ createdAt?: number | undefined;
204
+ updatedAt?: number | undefined;
205
+ triggeredAt?: number | undefined;
206
+ triggeredPriceTicks: bigint;
207
+ }, {
208
+ alertId: string;
209
+ symbolId: number;
210
+ direction: "unspecified" | "above" | "below";
211
+ priceSource: "unspecified" | "last_price" | "index_price";
212
+ /** Alert price. */
213
+ price: string;
214
+ /** Price when the alert was created or last set again; it fires on a crossing from here. */
215
+ referencePrice: string;
216
+ /** False while an alert created past its price waits for the price to move back first. */
217
+ armed: boolean;
218
+ status: "unspecified" | "active" | "triggered" | "cancelled";
219
+ channels: ("unspecified" | "in_app" | "telegram")[];
220
+ /** Pass as `expectedRevision` to `update`. */
221
+ revision: string;
222
+ createdAt: number | null;
223
+ updatedAt: number | null;
224
+ /** Set only once the alert fired. */
225
+ triggeredAt: number | null;
226
+ /** Price that fired the alert; null unless it fired. */
227
+ triggeredPrice: string | null;
228
+ }>]>, undefined>;
229
+ readonly nextPageToken: v.OptionalSchema<v.StringSchema<undefined>, "">;
230
+ }, undefined>;
231
+ /** One page of alerts, newest first; an empty `nextPageToken` means no more. */
232
+ type ListPriceAlertsResult = v.InferOutput<typeof ListPriceAlertsResultSchema>;
233
+ declare const UpdatePriceAlertResultSchema: v.ObjectSchema<{
234
+ readonly alert: v.SchemaWithPipe<readonly [v.ObjectSchema<{
235
+ readonly alertId: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
236
+ readonly symbolId: v.NumberSchema<undefined>;
237
+ readonly direction: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "above" | "below">]>;
238
+ readonly priceSource: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "last_price" | "index_price">]>;
239
+ readonly priceTicks: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
240
+ readonly referencePriceTicks: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
241
+ readonly armed: v.BooleanSchema<undefined>;
242
+ readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "active" | "triggered" | "cancelled">]>;
243
+ readonly channels: v.ArraySchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "in_app" | "telegram">]>, undefined>;
244
+ readonly revision: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
245
+ readonly createdAt: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ObjectSchema<{
246
+ readonly seconds: v.BigintSchema<undefined>;
247
+ readonly nanos: v.OptionalSchema<v.NumberSchema<undefined>, 0>;
248
+ }, undefined>, undefined>, v.TransformAction<{
249
+ seconds: bigint;
250
+ nanos: number;
251
+ } | undefined, number | undefined>]>;
252
+ readonly updatedAt: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ObjectSchema<{
253
+ readonly seconds: v.BigintSchema<undefined>;
254
+ readonly nanos: v.OptionalSchema<v.NumberSchema<undefined>, 0>;
255
+ }, undefined>, undefined>, v.TransformAction<{
256
+ seconds: bigint;
257
+ nanos: number;
258
+ } | undefined, number | undefined>]>;
259
+ readonly triggeredAt: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ObjectSchema<{
260
+ readonly seconds: v.BigintSchema<undefined>;
261
+ readonly nanos: v.OptionalSchema<v.NumberSchema<undefined>, 0>;
262
+ }, undefined>, undefined>, v.TransformAction<{
263
+ seconds: bigint;
264
+ nanos: number;
265
+ } | undefined, number | undefined>]>;
266
+ readonly triggeredPriceTicks: v.BigintSchema<undefined>;
267
+ }, undefined>, v.TransformAction<{
268
+ alertId: string;
269
+ symbolId: number;
270
+ direction: "unspecified" | "above" | "below";
271
+ priceSource: "unspecified" | "last_price" | "index_price";
272
+ priceTicks: string;
273
+ referencePriceTicks: string;
274
+ armed: boolean;
275
+ status: "unspecified" | "active" | "triggered" | "cancelled";
276
+ channels: ("unspecified" | "in_app" | "telegram")[];
277
+ revision: string;
278
+ createdAt?: number | undefined;
279
+ updatedAt?: number | undefined;
280
+ triggeredAt?: number | undefined;
281
+ triggeredPriceTicks: bigint;
282
+ }, {
283
+ alertId: string;
284
+ symbolId: number;
285
+ direction: "unspecified" | "above" | "below";
286
+ priceSource: "unspecified" | "last_price" | "index_price";
287
+ /** Alert price. */
288
+ price: string;
289
+ /** Price when the alert was created or last set again; it fires on a crossing from here. */
290
+ referencePrice: string;
291
+ /** False while an alert created past its price waits for the price to move back first. */
292
+ armed: boolean;
293
+ status: "unspecified" | "active" | "triggered" | "cancelled";
294
+ channels: ("unspecified" | "in_app" | "telegram")[];
295
+ /** Pass as `expectedRevision` to `update`. */
296
+ revision: string;
297
+ createdAt: number | null;
298
+ updatedAt: number | null;
299
+ /** Set only once the alert fired. */
300
+ triggeredAt: number | null;
301
+ /** Price that fired the alert; null unless it fired. */
302
+ triggeredPrice: string | null;
303
+ }>]>;
304
+ readonly outcome: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "applied" | "unchanged" | "replayed">]>;
305
+ }, undefined>;
306
+ type UpdatePriceAlertResult = v.InferOutput<typeof UpdatePriceAlertResultSchema>;
307
+ //#endregion
308
+ export { CancelPriceAlertInput, CancelPriceAlertInputSchema, CreatePriceAlertInput, CreatePriceAlertInputSchema, ListPriceAlertsInput, ListPriceAlertsInputSchema, ListPriceAlertsResult, ListPriceAlertsResultSchema, PriceAlert, PriceAlertSchema, UpdatePriceAlertInput, UpdatePriceAlertInputSchema, UpdatePriceAlertResult, UpdatePriceAlertResultSchema };
309
+ //# sourceMappingURL=price-alerts.schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"price-alerts.schemas.d.ts","names":[],"sources":["../../../src/services/price-alerts/price-alerts.schemas.ts"],"mappings":";;;cAqDa,6BAA2B,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;KAoB5B,wBAAwB,EAAE,kBAAkB;cAE3C,4BAA0B,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;KAiB3B,uBAAuB,EAAE,kBAAkB;cAiB1C,6BAA2B,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAmB5B,wBAAwB,EAAE,kBAAkB;cAE3C,6BAA2B,EAAA;;;KAE5B,wBAAwB,EAAE,kBAAkB;;cAQ3C,kBAAgB,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA4CjB,aAAa,EAAE,mBAAmB;cAEjC,6BAA2B,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAM5B,wBAAwB,EAAE,mBAAmB;cAE5C,8BAA4B,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAK7B,yBAAyB,EAAE,mBAAmB"}
@@ -0,0 +1,130 @@
1
+ import { PROTOBUF_UINT64_MAX } from "../../shared/wire-bounds.js";
2
+ import { BigIntStringSchema, OptionalTimestampMsSchema, PublicIdSchema, idInputSchema, positiveBigintStringInputSchema } from "../../shared/schemas.js";
3
+ import { enumLabelSchema } from "../../shared/proto-enum-codec.js";
4
+ import { positiveDecimalInputToScaled, scaledToDecimalOutput } from "../../shared/decimal-surface.js";
5
+ import { SymbolIdInputSchema } from "../shared.js";
6
+ import { buildProtoPatch, defineProtoPatchFields } from "../../utils/proto-patch.js";
7
+ import { PRICE_ALERT_CHANNEL_VALUES, PRICE_ALERT_DIRECTION_VALUES, PRICE_ALERT_PRICE_SOURCE_VALUES, PRICE_ALERT_STATUS_VALUES, PriceAlertChannelCodec, PriceAlertDirectionCodec, PriceAlertPriceSourceCodec, PriceAlertStatusCodec, PriceAlertUpdateOutcomeCodec } from "./price-alerts.codecs.js";
8
+ import * as v from "valibot";
9
+ //#region src/services/price-alerts/price-alerts.schemas.ts
10
+ const AlertIdInputSchema = idInputSchema("alertId");
11
+ /** Decimal alert price; sent as int64 ticks at the protocol price scale (1e9). */
12
+ function priceInputSchema(field) {
13
+ return v.pipe(v.string(), v.transform((price) => positiveDecimalInputToScaled(field, price, 9)));
14
+ }
15
+ /** One to two distinct delivery channels, sent in ascending enum order. */
16
+ const ChannelsInputSchema = v.pipe(v.array(v.picklist(PRICE_ALERT_CHANNEL_VALUES)), v.minLength(1, "At least one channel is required."), v.maxLength(2, "At most two channels are allowed."), v.check((channels) => new Set(channels).size === channels.length, "Channels must be distinct."), v.transform((channels) => channels.map((channel) => PriceAlertChannelCodec.inputToProto[channel]).sort()));
17
+ const IdempotencyKeySchema = v.optional(v.pipe(v.string(), v.trim(), v.minLength(1)));
18
+ const CreatePriceAlertInputSchema = v.pipe(v.strictObject({
19
+ symbolId: SymbolIdInputSchema,
20
+ direction: v.picklist(PRICE_ALERT_DIRECTION_VALUES),
21
+ /** Omit to watch the index price on markets that have one, else the last price. */
22
+ priceSource: v.optional(v.picklist(PRICE_ALERT_PRICE_SOURCE_VALUES)),
23
+ /** Alert price as a decimal string, e.g. `"90000"`. */
24
+ price: priceInputSchema("price"),
25
+ channels: ChannelsInputSchema,
26
+ /** Reusing a key with the same request returns the alert it created. */
27
+ idempotencyKey: IdempotencyKeySchema
28
+ }), v.transform(({ direction, priceSource, price, ...input }) => ({
29
+ ...input,
30
+ direction: PriceAlertDirectionCodec.inputToProto[direction],
31
+ priceSource: priceSource && PriceAlertPriceSourceCodec.inputToProto[priceSource],
32
+ priceTicks: price
33
+ })));
34
+ const ListPriceAlertsInputSchema = v.pipe(v.strictObject({
35
+ /** Only alerts in these states; omit or empty for every state. */
36
+ statuses: v.optional(v.array(v.picklist(PRICE_ALERT_STATUS_VALUES))),
37
+ /** Only alerts on this market. */
38
+ symbolId: v.optional(SymbolIdInputSchema),
39
+ /** Page size: default 50, at most 200. */
40
+ limit: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(200))),
41
+ /** Previous `nextPageToken`; reuse only with the same filters. */
42
+ pageToken: v.optional(v.pipe(v.string(), v.trim()))
43
+ }), v.transform(({ statuses, ...input }) => ({
44
+ ...input,
45
+ statuses: statuses?.map((status) => PriceAlertStatusCodec.inputToProto[status])
46
+ })));
47
+ const PRICE_ALERT_PATCH_FIELDS = defineProtoPatchFields()({
48
+ direction: {
49
+ path: "direction",
50
+ encode: (direction) => ({ direction: PriceAlertDirectionCodec.inputToProto[direction] })
51
+ },
52
+ price: {
53
+ path: "price_ticks",
54
+ encode: (priceTicks) => ({ priceTicks })
55
+ },
56
+ channels: {
57
+ path: "channels",
58
+ encode: (channels) => ({ channels })
59
+ }
60
+ });
61
+ const UpdatePriceAlertInputSchema = v.pipe(v.strictObject({
62
+ alertId: AlertIdInputSchema,
63
+ /** The alert's `revision` from the last read. */
64
+ expectedRevision: v.pipe(positiveBigintStringInputSchema("expectedRevision"), v.maxValue(PROTOBUF_UINT64_MAX, "expectedRevision exceeds the uint64 range")),
65
+ direction: v.optional(v.picklist(PRICE_ALERT_DIRECTION_VALUES)),
66
+ price: v.optional(priceInputSchema("price")),
67
+ channels: v.optional(ChannelsInputSchema),
68
+ idempotencyKey: IdempotencyKeySchema
69
+ }), v.transform(({ alertId, expectedRevision, idempotencyKey, ...fields }) => {
70
+ const { patch: update, updateMask } = buildProtoPatch(fields, PRICE_ALERT_PATCH_FIELDS);
71
+ return {
72
+ alertId,
73
+ expectedRevision,
74
+ idempotencyKey,
75
+ update,
76
+ updateMask
77
+ };
78
+ }));
79
+ const CancelPriceAlertInputSchema = v.strictObject({ alertId: AlertIdInputSchema });
80
+ const PriceSchema = v.pipe(v.bigint(), v.transform((ticks) => scaledToDecimalOutput(ticks, 9)));
81
+ /** A price alert of the caller's root account. Prices are decimal strings. */
82
+ const PriceAlertSchema = v.pipe(v.object({
83
+ alertId: PublicIdSchema,
84
+ symbolId: v.number(),
85
+ direction: enumLabelSchema(PriceAlertDirectionCodec.protoToOutput),
86
+ priceSource: enumLabelSchema(PriceAlertPriceSourceCodec.protoToOutput),
87
+ priceTicks: PriceSchema,
88
+ referencePriceTicks: PriceSchema,
89
+ armed: v.boolean(),
90
+ status: enumLabelSchema(PriceAlertStatusCodec.protoToOutput),
91
+ channels: v.array(enumLabelSchema(PriceAlertChannelCodec.protoToOutput)),
92
+ revision: BigIntStringSchema,
93
+ createdAt: OptionalTimestampMsSchema,
94
+ updatedAt: OptionalTimestampMsSchema,
95
+ triggeredAt: OptionalTimestampMsSchema,
96
+ triggeredPriceTicks: v.bigint()
97
+ }), v.transform((alert) => ({
98
+ alertId: alert.alertId,
99
+ symbolId: alert.symbolId,
100
+ direction: alert.direction,
101
+ priceSource: alert.priceSource,
102
+ /** Alert price. */
103
+ price: alert.priceTicks,
104
+ /** Price when the alert was created or last set again; it fires on a crossing from here. */
105
+ referencePrice: alert.referencePriceTicks,
106
+ /** False while an alert created past its price waits for the price to move back first. */
107
+ armed: alert.armed,
108
+ status: alert.status,
109
+ channels: alert.channels,
110
+ /** Pass as `expectedRevision` to `update`. */
111
+ revision: alert.revision,
112
+ createdAt: alert.createdAt ?? null,
113
+ updatedAt: alert.updatedAt ?? null,
114
+ /** Set only once the alert fired. */
115
+ triggeredAt: alert.triggeredAt ?? null,
116
+ /** Price that fired the alert; null unless it fired. */
117
+ triggeredPrice: alert.status === "triggered" ? scaledToDecimalOutput(alert.triggeredPriceTicks, 9) : null
118
+ })));
119
+ const ListPriceAlertsResultSchema = v.object({
120
+ alerts: v.array(PriceAlertSchema),
121
+ nextPageToken: v.optional(v.string(), "")
122
+ });
123
+ const UpdatePriceAlertResultSchema = v.object({
124
+ alert: PriceAlertSchema,
125
+ outcome: enumLabelSchema(PriceAlertUpdateOutcomeCodec.protoToOutput)
126
+ });
127
+ //#endregion
128
+ export { CancelPriceAlertInputSchema, CreatePriceAlertInputSchema, ListPriceAlertsInputSchema, ListPriceAlertsResultSchema, PriceAlertSchema, UpdatePriceAlertInputSchema, UpdatePriceAlertResultSchema };
129
+
130
+ //# sourceMappingURL=price-alerts.schemas.js.map