@polyester/sdk 0.9.1 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/dist/catalogs/readers.d.ts.map +1 -1
- package/dist/catalogs/readers.js +22 -0
- package/dist/catalogs/readers.js.map +1 -1
- package/dist/core-client.d.ts.map +1 -1
- package/dist/core-client.js +49 -15
- package/dist/core-client.js.map +1 -1
- package/dist/environment.d.ts.map +1 -1
- package/dist/environment.js +3 -2
- package/dist/environment.js.map +1 -1
- package/dist/gen/auth/v1/api_keys_pb.d.ts +8 -7
- package/dist/gen/auth/v1/api_keys_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/api_keys_pb.js.map +1 -1
- package/dist/gen/auth/v1/policies_pb.d.ts +8 -4
- package/dist/gen/auth/v1/policies_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/policies_pb.js.map +1 -1
- package/dist/gen/auth/v1/subaccounts_pb.d.ts +382 -18
- package/dist/gen/auth/v1/subaccounts_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/subaccounts_pb.js +253 -38
- package/dist/gen/auth/v1/subaccounts_pb.js.map +1 -1
- package/dist/gen/orders/v1/orders_pb.d.ts +2 -2
- package/dist/gen/orders/v1/orders_pb.js.map +1 -1
- package/dist/gen/orders/v1/orders_read_pb.d.ts +8 -0
- package/dist/gen/orders/v1/orders_read_pb.d.ts.map +1 -1
- package/dist/gen/orders/v1/orders_read_pb.js +1 -1
- package/dist/gen/orders/v1/orders_read_pb.js.map +1 -1
- package/dist/gen/ratelimit/v1/ratelimit_pb.d.ts +2 -2
- package/dist/gen/ratelimit/v1/ratelimit_pb.js +1 -1
- package/dist/gen/ratelimit/v1/ratelimit_pb.js.map +1 -1
- package/dist/gen/triggers/v1/triggers_pb.d.ts +4 -4
- package/dist/gen/triggers/v1/triggers_pb.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/realtime/client.d.ts.map +1 -1
- package/dist/realtime/client.js +13 -5
- package/dist/realtime/client.js.map +1 -1
- package/dist/realtime/ready-gated-subscription.js +68 -0
- package/dist/realtime/ready-gated-subscription.js.map +1 -0
- package/dist/realtime/snapshot-then-stream.js +19 -10
- package/dist/realtime/snapshot-then-stream.js.map +1 -1
- package/dist/server-client.d.ts +3 -1
- package/dist/server-client.d.ts.map +1 -1
- package/dist/server-client.js +9 -4
- package/dist/server-client.js.map +1 -1
- package/dist/services/auth/session.d.ts.map +1 -1
- package/dist/services/auth/session.js +4 -1
- package/dist/services/auth/session.js.map +1 -1
- package/dist/services/auth/token-storage.js +2 -2
- package/dist/services/auth/token-storage.js.map +1 -1
- package/dist/services/balances/balances.js +5 -8
- package/dist/services/balances/balances.js.map +1 -1
- package/dist/services/candles/candles.js +9 -12
- package/dist/services/candles/candles.js.map +1 -1
- package/dist/services/heatmap/heatmap.js +5 -8
- package/dist/services/heatmap/heatmap.js.map +1 -1
- package/dist/services/lifecycle/lifecycle.schemas.js +1 -1
- package/dist/services/market-data/market-data.d.ts.map +1 -1
- package/dist/services/market-data/market-data.js +5 -8
- package/dist/services/market-data/market-data.js.map +1 -1
- package/dist/services/market-data/market-data.schemas.d.ts.map +1 -1
- package/dist/services/market-data/market-data.schemas.js +3 -2
- package/dist/services/market-data/market-data.schemas.js.map +1 -1
- package/dist/services/market-overview/market-overview.d.ts.map +1 -1
- package/dist/services/market-overview/market-overview.js +7 -13
- package/dist/services/market-overview/market-overview.js.map +1 -1
- package/dist/services/orderbook/orderbook.d.ts.map +1 -1
- package/dist/services/orderbook/orderbook.js +18 -11
- package/dist/services/orderbook/orderbook.js.map +1 -1
- package/dist/services/orders/orders-batch.schemas.d.ts +6 -22
- package/dist/services/orders/orders-batch.schemas.d.ts.map +1 -1
- package/dist/services/orders/orders-batch.schemas.js +23 -20
- package/dist/services/orders/orders-batch.schemas.js.map +1 -1
- package/dist/services/orders/orders-identifiers.schemas.js +6 -1
- package/dist/services/orders/orders-identifiers.schemas.js.map +1 -1
- package/dist/services/orders/orders-input.schemas.d.ts +11 -43
- package/dist/services/orders/orders-input.schemas.d.ts.map +1 -1
- package/dist/services/orders/orders-input.schemas.js +10 -11
- package/dist/services/orders/orders-input.schemas.js.map +1 -1
- package/dist/services/orders/orders-modify.schemas.d.ts +1 -25
- package/dist/services/orders/orders-modify.schemas.d.ts.map +1 -1
- package/dist/services/orders/orders-modify.schemas.js +2 -4
- package/dist/services/orders/orders-modify.schemas.js.map +1 -1
- package/dist/services/orders/orders-output.schemas.d.ts +165 -27
- package/dist/services/orders/orders-output.schemas.d.ts.map +1 -1
- package/dist/services/orders/orders-output.schemas.js +1 -1
- package/dist/services/orders/orders-output.schemas.js.map +1 -1
- package/dist/services/orders/orders-risk.schemas.d.ts +1 -20
- package/dist/services/orders/orders-risk.schemas.d.ts.map +1 -1
- package/dist/services/orders/orders-risk.schemas.js +52 -15
- package/dist/services/orders/orders-risk.schemas.js.map +1 -1
- package/dist/services/orders/orders.codecs.js +12 -1
- package/dist/services/orders/orders.codecs.js.map +1 -1
- package/dist/services/orders/orders.d.ts.map +1 -1
- package/dist/services/orders/orders.js +6 -9
- package/dist/services/orders/orders.js.map +1 -1
- package/dist/services/rate-limits/rate-limits.schemas.d.ts +4 -4
- package/dist/services/rate-limits/rate-limits.schemas.js +1 -1
- package/dist/services/rate-limits/rate-limits.schemas.js.map +1 -1
- package/dist/services/subaccounts/index.d.ts +2 -2
- package/dist/services/subaccounts/subaccounts.codecs.js +29 -1
- package/dist/services/subaccounts/subaccounts.codecs.js.map +1 -1
- package/dist/services/subaccounts/subaccounts.d.ts +9 -1
- package/dist/services/subaccounts/subaccounts.d.ts.map +1 -1
- package/dist/services/subaccounts/subaccounts.js +19 -2
- package/dist/services/subaccounts/subaccounts.js.map +1 -1
- package/dist/services/subaccounts/subaccounts.schemas.d.ts +46 -6
- package/dist/services/subaccounts/subaccounts.schemas.d.ts.map +1 -1
- package/dist/services/subaccounts/subaccounts.schemas.js +28 -3
- package/dist/services/subaccounts/subaccounts.schemas.js.map +1 -1
- package/dist/services/subaccounts/subaccounts.types.d.ts +2 -2
- package/dist/services/trades/trades.d.ts +1 -1
- package/dist/services/trades/trades.js +6 -9
- package/dist/services/trades/trades.js.map +1 -1
- package/dist/services/trades/trades.schemas.d.ts +3 -0
- package/dist/services/trades/trades.schemas.d.ts.map +1 -1
- package/dist/services/trades/trades.schemas.js +2 -1
- package/dist/services/trades/trades.schemas.js.map +1 -1
- package/dist/services/trailing-oneof-inputs.js +3 -3
- package/dist/services/trailing-oneof-inputs.js.map +1 -1
- package/dist/services/transfers/index.d.ts +2 -2
- package/dist/services/transfers/transfers.d.ts +1 -2
- package/dist/services/transfers/transfers.d.ts.map +1 -1
- package/dist/services/transfers/transfers.js +8 -13
- package/dist/services/transfers/transfers.js.map +1 -1
- package/dist/services/transfers/transfers.schemas.d.ts +5 -5
- package/dist/services/transfers/transfers.schemas.d.ts.map +1 -1
- package/dist/services/transfers/transfers.schemas.js +31 -33
- package/dist/services/transfers/transfers.schemas.js.map +1 -1
- package/dist/services/triggers/trigger-input.schemas.d.ts +22 -9
- package/dist/services/triggers/trigger-input.schemas.d.ts.map +1 -1
- package/dist/services/triggers/trigger-input.schemas.js +20 -43
- package/dist/services/triggers/trigger-input.schemas.js.map +1 -1
- package/dist/services/triggers/triggers-output.schemas.d.ts +14 -14
- package/dist/services/triggers/triggers-output.schemas.js +5 -5
- package/dist/services/triggers/triggers-output.schemas.js.map +1 -1
- package/dist/services/triggers/triggers.d.ts.map +1 -1
- package/dist/services/triggers/triggers.js +10 -23
- package/dist/services/triggers/triggers.js.map +1 -1
- package/dist/services/zipper/zipper.d.ts.map +1 -1
- package/dist/services/zipper/zipper.js +15 -18
- package/dist/services/zipper/zipper.js.map +1 -1
- package/dist/shared/connect-error-mapping.d.ts.map +1 -1
- package/dist/shared/connect-error-mapping.js +9 -2
- package/dist/shared/connect-error-mapping.js.map +1 -1
- package/dist/shared/decimal-surface.d.ts.map +1 -1
- package/dist/shared/decimal-surface.js +40 -17
- package/dist/shared/decimal-surface.js.map +1 -1
- package/dist/shared/transports.d.ts.map +1 -1
- package/dist/shared/transports.js +33 -11
- package/dist/shared/transports.js.map +1 -1
- package/dist/utils/base58-id.js +1 -2
- package/dist/utils/base58-id.js.map +1 -1
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +4 -3
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/event-emitter.d.ts.map +1 -1
- package/dist/utils/event-emitter.js +6 -3
- package/dist/utils/event-emitter.js.map +1 -1
- package/dist/utils/jwt.d.ts.map +1 -1
- package/dist/utils/jwt.js +2 -2
- package/dist/utils/jwt.js.map +1 -1
- package/dist/utils/numbers.js +20 -3
- package/dist/utils/numbers.js.map +1 -1
- package/dist/utils/timestamp.js +27 -16
- package/dist/utils/timestamp.js.map +1 -1
- package/dist/utils/u128.js +6 -18
- package/dist/utils/u128.js.map +1 -1
- package/dist/wired-services.d.ts.map +1 -1
- package/dist/wired-services.js +2 -1
- package/dist/wired-services.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orderbook.js","names":["#client","Proto.OrderbookService","#realtime","#scales","Proto.GetOrderBookResponseSchema","Proto.OrderBookDeltaSchema"],"sources":["../../../src/services/orderbook/orderbook.ts"],"sourcesContent":["import { create } from \"@bufbuild/protobuf\";\nimport * as Proto from \"../../gen/orderbook/v1/orderbook_pb.js\";\nimport { createClient, type Client, type Transport } from \"@connectrpc/connect\";\nimport { publicationHandlerErrorContext } from \"../../shared/subscription-errors.js\";\nimport type { PolyesterRealtime } from \"../../realtime/types.js\";\nimport {\n snapshotThenStream,\n type SnapshotThenStreamSubscription,\n} from \"../../realtime/snapshot-then-stream.js\";\nimport type { BaseSubscribeInput } from \"../../shared/types.js\";\nimport {\n toConnectCallOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport {\n createReadyGate,\n decimalInputToScaled,\n type SdkScales,\n} from \"../../shared/decimal-surface.js\";\nimport {\n formatOrderbookLevel,\n GetOrderbookInputSchema,\n createOrderbookDataSchema,\n type OrderbookLevel,\n type OrderbookData,\n} from \"./orderbook.schemas.js\";\nimport { orderbookWsChannelDepth } from \"./orderbook.codecs.js\";\nimport { toBig } from \"../../utils/u128.js\";\nimport { isResourceNotFoundError } from \"../../utils/errors.js\";\nimport type * as v from \"valibot\";\nimport { parse } from \"../../shared/validation.js\";\n\ninterface SubscribeOrderbookInput extends BaseSubscribeInput<OrderbookData> {\n symbolId: number;\n depth?: number;\n bucket?: string | null;\n}\n\nexport interface OrderbookStreamHandlers extends BaseSubscribeInput<OrderbookData> {}\n\nexport interface OrderbookSubscription {\n unsubscribe: () => void;\n setBucket: (bucket: string | null | undefined) => void;\n}\n\nexport interface CreateOrderbookSubscriptionInput\n extends\n OrderbookStreamHandlers,\n Pick<SubscribeOrderbookInput, \"symbolId\" | \"depth\" | \"bucket\"> {}\n\ntype BookSide = Map<bigint, bigint>;\n\n/**\n * Reads spot order book snapshots and maintains realtime local order book state from public delta channels.\n */\nexport class OrderbookService {\n #client: Client<typeof Proto.OrderbookService>;\n #realtime: PolyesterRealtime;\n #scales: SdkScales;\n\n constructor(transport: Transport, realtime: PolyesterRealtime, scales: SdkScales) {\n this.#client = createClient(Proto.OrderbookService, transport);\n this.#realtime = realtime;\n this.#scales = scales;\n }\n\n /**\n * Fetches a spot order book depth snapshot for a symbol ID and requested depth, returning best bids and asks with the backend book sequence.\n */\n async get(\n input: v.InferInput<typeof GetOrderbookInputSchema>,\n options?: PolyesterRequestOptions,\n ): Promise<OrderbookData> {\n const validated = parse(GetOrderbookInputSchema, input);\n await this.#scales.ready();\n const res = await this.#client.getOrderBook(\n { symbolId: validated.symbolId, depth: validated.protoDepth },\n toConnectCallOptions(options),\n );\n return parse(createOrderbookDataSchema(this.#scales, validated.symbolId), {\n symbolId: res.symbolId,\n depth: validated.depth,\n bookSeq: res.bookSeq,\n bids: res.bids,\n asks: res.asks,\n });\n }\n\n /**\n * Subscribes to the managed order book stream for a symbol ID and forwards reconstructed snapshots to onEvent. This is a convenience wrapper around createSubscription().unsubscribe.\n */\n subscribe(input: SubscribeOrderbookInput): () => void {\n return this.createSubscription(input).unsubscribe;\n }\n\n /**\n * Creates a stateful order book subscription that first fetches a snapshot, buffers proto deltas from public:spot:orderbook:deltas:depth:{depth}:{symbolId}:proto, applies sequence-checked updates, and refetches on observed sequence gaps or reconnects. The returned handle can unsubscribe or change local price bucket aggregation without reconnecting.\n *\n * `depth` is clamped to [1, 500] and rides the smallest published channel depth that covers it (see ORDERBOOK_WS_DEPTHS); levels are sliced back to the requested depth locally.\n *\n * Refetching is driven by observed sequence gaps and reconnect events only. A feed that stays subscribed but stops publishing is indistinguishable from a quiet market, so it does not trigger onError or a refetch. Callers that must detect a stalled book need their own idle watchdog plus a REST refetch.\n */\n createSubscription(input: CreateOrderbookSubscriptionInput): OrderbookSubscription {\n const { symbolId } = parse(GetOrderbookInputSchema, {\n symbolId: input.symbolId,\n depth: input.depth,\n });\n const requestedDepth = Math.min(500, Math.max(1, Math.trunc(input.depth ?? 50)));\n const channelDepth = orderbookWsChannelDepth(requestedDepth);\n const channel = `public:spot:orderbook:deltas:depth:${channelDepth}:${symbolId}:proto`;\n\n const client = this.#client;\n const scales = this.#scales;\n const gate = createReadyGate(\n () => scales.ready(),\n (error) => input.onError?.(publicationHandlerErrorContext(channel, error)),\n );\n\n let bidsMap: BookSide = new Map();\n let asksMap: BookSide = new Map();\n let currentBookSeq = 0n;\n let bucketTicks: bigint | null = null;\n let stream: SnapshotThenStreamSubscription | undefined;\n\n function levelsToMap(levels: Proto.PriceLevel[] | undefined): BookSide {\n const map: BookSide = new Map();\n for (const l of levels ?? []) {\n if (l.qtyScaled === 0n) continue;\n map.set(l.priceTicks, l.qtyScaled);\n }\n return map;\n }\n\n function applySideDelta(map: BookSide, levels: Proto.PriceLevel[] | undefined): void {\n for (const l of levels ?? []) {\n if (l.qtyScaled === 0n) map.delete(l.priceTicks);\n else map.set(l.priceTicks, l.qtyScaled);\n }\n }\n\n function sideToUI(map: BookSide, side: \"bids\" | \"asks\", limit: number): OrderbookLevel[] {\n const entries = Array.from(map.entries());\n entries.sort(([pa], [pb]) => {\n if (pa === pb) return 0;\n return side === \"bids\" ? (pa > pb ? -1 : 1) : pa < pb ? -1 : 1;\n });\n return entries\n .slice(0, limit)\n .map(([priceTicks, qtyScaled]) =>\n formatOrderbookLevel({ priceTicks, qtyScaled }, scales, symbolId),\n );\n }\n\n function sideToUIBucketed(\n map: BookSide,\n side: \"bids\" | \"asks\",\n limit: number,\n bucket: bigint | null,\n ): OrderbookLevel[] {\n if (!bucket || bucket <= 0n) return sideToUI(map, side, limit);\n\n const agg: BookSide = new Map();\n for (const [priceTicks, qtyScaled] of map.entries()) {\n if (qtyScaled <= 0n) continue;\n const bucketPrice = (priceTicks / bucket) * bucket;\n agg.set(bucketPrice, (agg.get(bucketPrice) ?? 0n) + qtyScaled);\n }\n return sideToUI(agg, side, limit);\n }\n\n function emit(): void {\n gate.run(() => {\n input.onEvent({\n symbolId,\n depth: requestedDepth,\n bookSeq: currentBookSeq.toString(),\n bids: sideToUIBucketed(bidsMap, \"bids\", requestedDepth, bucketTicks),\n asks: sideToUIBucketed(asksMap, \"asks\", requestedDepth, bucketTicks),\n });\n });\n }\n\n function setBucket(bucket: string | null | undefined): void {\n if (!bucket) {\n bucketTicks = null;\n } else {\n try {\n bucketTicks = decimalInputToScaled(\"bucket\", bucket, scales.price());\n } catch {\n bucketTicks = null;\n }\n }\n if (stream?.isReady()) emit();\n }\n\n async function inputServiceFetch(): Promise<Proto.GetOrderBookResponse> {\n const validated = parse(GetOrderbookInputSchema, {\n symbolId,\n depth: channelDepth,\n });\n try {\n return await client.getOrderBook({\n symbolId: validated.symbolId,\n depth: validated.protoDepth,\n });\n } catch (error: unknown) {\n if (!isResourceNotFoundError(error)) throw error;\n\n return create(Proto.GetOrderBookResponseSchema, {\n symbolId,\n bookSeq: 0n,\n bids: [],\n asks: [],\n });\n }\n }\n\n function handleDelta(delta: Proto.OrderBookDelta): void {\n if (delta.reset) {\n bidsMap.clear();\n asksMap.clear();\n currentBookSeq = 0n;\n }\n\n if (currentBookSeq !== 0n && delta.bookSeqStart > currentBookSeq + 1n) {\n stream?.refreshSnapshot();\n return;\n }\n\n if (delta.bookSeqEnd <= currentBookSeq) return;\n\n applySideDelta(bidsMap, delta.bids);\n applySideDelta(asksMap, delta.asks);\n\n currentBookSeq = delta.bookSeqEnd > currentBookSeq ? delta.bookSeqEnd : currentBookSeq;\n emit();\n }\n\n setBucket(input.bucket);\n stream = snapshotThenStream({\n realtime: this.#realtime,\n channel,\n schema: Proto.OrderBookDeltaSchema,\n maxBufferedPublications: 200,\n snapshotErrorLog: \"Failed to fetch orderbook\",\n fetchSnapshot: inputServiceFetch,\n readPublication: (delta) => [delta],\n applySnapshot: (snapshot, bufferedDeltas) => {\n bidsMap = levelsToMap(snapshot.bids);\n asksMap = levelsToMap(snapshot.asks);\n currentBookSeq = toBig(snapshot.bookSeq);\n emit();\n for (const delta of bufferedDeltas) {\n if (stream?.isDisposed()) return;\n handleDelta(delta);\n }\n },\n applyLivePublications: (deltas) => {\n for (const delta of deltas) {\n if (stream?.isDisposed()) return;\n handleDelta(delta);\n }\n },\n onOpen: input.onOpen,\n onClose: input.onClose,\n onError: input.onError,\n });\n\n function dispose(): void {\n stream?.unsubscribe();\n }\n\n return { unsubscribe: dispose, setBucket };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAuDA,IAAa,mBAAb,MAA8B;CAC1B;CACA;CACA;CAEA,YAAY,WAAsB,UAA6B,QAAmB;EAC9E,KAAKA,UAAU,aAAaC,oBAAwB,SAAS;EAC7D,KAAKC,YAAY;EACjB,KAAKC,UAAU;CACnB;;;;CAKA,MAAM,IACF,OACA,SACsB;EACtB,MAAM,YAAY,MAAM,yBAAyB,KAAK;EACtD,MAAM,KAAKA,QAAQ,MAAM;EACzB,MAAM,MAAM,MAAM,K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;EAAU;CAC7C;AACJ"}
|
|
1
|
+
{"version":3,"file":"orderbook.js","names":["#client","Proto.OrderbookService","#realtime","#scales","Proto.GetOrderBookResponseSchema","Proto.OrderBookDeltaSchema"],"sources":["../../../src/services/orderbook/orderbook.ts"],"sourcesContent":["import { create } from \"@bufbuild/protobuf\";\nimport * as Proto from \"../../gen/orderbook/v1/orderbook_pb.js\";\nimport { createClient, type Client, type Transport } from \"@connectrpc/connect\";\nimport { publicationHandlerErrorContext } from \"../../shared/subscription-errors.js\";\nimport type { PolyesterRealtime } from \"../../realtime/types.js\";\nimport {\n snapshotThenStream,\n type SnapshotThenStreamSubscription,\n} from \"../../realtime/snapshot-then-stream.js\";\nimport type { BaseSubscribeInput } from \"../../shared/types.js\";\nimport {\n toConnectCallOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport { decimalInputToScaled, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport {\n formatOrderbookLevel,\n GetOrderbookInputSchema,\n createOrderbookDataSchema,\n type OrderbookLevel,\n type OrderbookData,\n} from \"./orderbook.schemas.js\";\nimport { orderbookWsChannelDepth } from \"./orderbook.codecs.js\";\nimport { isResourceNotFoundError } from \"../../utils/errors.js\";\nimport type * as v from \"valibot\";\nimport { parse } from \"../../shared/validation.js\";\n\ninterface SubscribeOrderbookInput extends BaseSubscribeInput<OrderbookData> {\n symbolId: number;\n depth?: number;\n bucket?: string | null;\n}\n\nexport interface OrderbookStreamHandlers extends BaseSubscribeInput<OrderbookData> {}\n\nexport interface OrderbookSubscription {\n unsubscribe: () => void;\n setBucket: (bucket: string | null | undefined) => void;\n}\n\nexport interface CreateOrderbookSubscriptionInput\n extends\n OrderbookStreamHandlers,\n Pick<SubscribeOrderbookInput, \"symbolId\" | \"depth\" | \"bucket\"> {}\n\ntype BookSide = Map<bigint, bigint>;\n\n/**\n * Reads spot order book snapshots and maintains realtime local order book state from public delta channels.\n */\nexport class OrderbookService {\n #client: Client<typeof Proto.OrderbookService>;\n #realtime: PolyesterRealtime;\n #scales: SdkScales;\n\n constructor(transport: Transport, realtime: PolyesterRealtime, scales: SdkScales) {\n this.#client = createClient(Proto.OrderbookService, transport);\n this.#realtime = realtime;\n this.#scales = scales;\n }\n\n /**\n * Fetches a spot order book depth snapshot for a symbol ID and requested depth, returning best bids and asks with the backend book sequence.\n */\n async get(\n input: v.InferInput<typeof GetOrderbookInputSchema>,\n options?: PolyesterRequestOptions,\n ): Promise<OrderbookData> {\n const validated = parse(GetOrderbookInputSchema, input);\n await this.#scales.ready();\n const res = await this.#client.getOrderBook(\n { symbolId: validated.symbolId, depth: validated.protoDepth },\n toConnectCallOptions(options),\n );\n return parse(createOrderbookDataSchema(this.#scales, validated.symbolId), {\n symbolId: res.symbolId,\n depth: validated.depth,\n bookSeq: res.bookSeq,\n bids: res.bids,\n asks: res.asks,\n });\n }\n\n /**\n * Subscribes to the managed order book stream for a symbol ID and forwards reconstructed snapshots to onEvent. This is a convenience wrapper around createSubscription().unsubscribe.\n */\n subscribe(input: SubscribeOrderbookInput): () => void {\n return this.createSubscription(input).unsubscribe;\n }\n\n /**\n * Creates a stateful order book subscription that first fetches a snapshot, buffers proto deltas from public:spot:orderbook:deltas:depth:{depth}:{symbolId}:proto, applies sequence-checked updates, and refetches on observed sequence gaps or reconnects. The returned handle can unsubscribe or change local price bucket aggregation without reconnecting.\n *\n * `depth` is clamped to [1, 500] and rides the smallest published channel depth that covers it (see ORDERBOOK_WS_DEPTHS); levels are sliced back to the requested depth locally.\n *\n * Refetching is driven by observed sequence gaps and reconnect events only. A feed that stays subscribed but stops publishing is indistinguishable from a quiet market, so it does not trigger onError or a refetch. Callers that must detect a stalled book need their own idle watchdog plus a REST refetch.\n */\n createSubscription(input: CreateOrderbookSubscriptionInput): OrderbookSubscription {\n const { symbolId } = parse(GetOrderbookInputSchema, {\n symbolId: input.symbolId,\n depth: input.depth,\n });\n const requestedDepth = Math.min(500, Math.max(1, Math.trunc(input.depth ?? 50)));\n const channelDepth = orderbookWsChannelDepth(requestedDepth);\n const channel = `public:spot:orderbook:deltas:depth:${channelDepth}:${symbolId}:proto`;\n\n const client = this.#client;\n const scales = this.#scales;\n let bidsMap: BookSide = new Map();\n let asksMap: BookSide = new Map();\n let currentBookSeq = 0n;\n let bucketTicks: bigint | null = null;\n let stream: SnapshotThenStreamSubscription | undefined;\n\n function levelsToMap(levels: Proto.PriceLevel[] | undefined): BookSide {\n const map: BookSide = new Map();\n for (const l of levels ?? []) {\n if (l.qtyScaled === 0n) continue;\n map.set(l.priceTicks, l.qtyScaled);\n }\n return map;\n }\n\n function applySideDelta(map: BookSide, levels: Proto.PriceLevel[] | undefined): void {\n for (const l of levels ?? []) {\n if (l.qtyScaled === 0n) map.delete(l.priceTicks);\n else map.set(l.priceTicks, l.qtyScaled);\n }\n }\n\n function sideToUI(map: BookSide, side: \"bids\" | \"asks\", limit: number): OrderbookLevel[] {\n const entries = Array.from(map.entries());\n entries.sort(([pa], [pb]) => {\n if (pa === pb) return 0;\n return side === \"bids\" ? (pa > pb ? -1 : 1) : pa < pb ? -1 : 1;\n });\n return entries\n .slice(0, limit)\n .map(([priceTicks, qtyScaled]) =>\n formatOrderbookLevel({ priceTicks, qtyScaled }, scales, symbolId),\n );\n }\n\n function sideToUIBucketed(\n map: BookSide,\n side: \"bids\" | \"asks\",\n limit: number,\n bucket: bigint | null,\n ): OrderbookLevel[] {\n if (!bucket || bucket <= 0n) return sideToUI(map, side, limit);\n\n const agg: BookSide = new Map();\n for (const [priceTicks, qtyScaled] of map.entries()) {\n if (qtyScaled <= 0n) continue;\n const bucketFloor = (priceTicks / bucket) * bucket;\n const bucketPrice =\n side === \"asks\" && bucketFloor !== priceTicks\n ? bucketFloor + bucket\n : bucketFloor;\n agg.set(bucketPrice, (agg.get(bucketPrice) ?? 0n) + qtyScaled);\n }\n return sideToUI(agg, side, limit);\n }\n\n function emit(): void {\n try {\n input.onEvent({\n symbolId,\n depth: requestedDepth,\n bookSeq: currentBookSeq.toString(),\n bids: sideToUIBucketed(bidsMap, \"bids\", requestedDepth, bucketTicks),\n asks: sideToUIBucketed(asksMap, \"asks\", requestedDepth, bucketTicks),\n });\n } catch (error) {\n input.onError?.(publicationHandlerErrorContext(channel, error));\n }\n }\n\n function setBucket(bucket: string | null | undefined): void {\n if (!bucket) {\n bucketTicks = null;\n } else {\n try {\n bucketTicks = decimalInputToScaled(\"bucket\", bucket, scales.price());\n } catch {\n bucketTicks = null;\n }\n }\n if (stream?.isReady()) emit();\n }\n\n async function inputServiceFetch(): Promise<Proto.GetOrderBookResponse> {\n await scales.ready();\n const validated = parse(GetOrderbookInputSchema, {\n symbolId,\n depth: channelDepth,\n });\n try {\n return await client.getOrderBook({\n symbolId: validated.symbolId,\n depth: validated.protoDepth,\n });\n } catch (error: unknown) {\n if (!isResourceNotFoundError(error)) throw error;\n\n return create(Proto.GetOrderBookResponseSchema, {\n symbolId,\n bookSeq: 0n,\n bids: [],\n asks: [],\n });\n }\n }\n\n function handleDelta(delta: Proto.OrderBookDelta): boolean {\n if (delta.bookSeqEnd <= currentBookSeq) return true;\n\n if (delta.reset) {\n bidsMap.clear();\n asksMap.clear();\n currentBookSeq = 0n;\n }\n\n if (currentBookSeq !== 0n && delta.bookSeqStart > currentBookSeq + 1n) {\n stream?.refreshSnapshot();\n return false;\n }\n\n applySideDelta(bidsMap, delta.bids);\n applySideDelta(asksMap, delta.asks);\n\n currentBookSeq = delta.bookSeqEnd > currentBookSeq ? delta.bookSeqEnd : currentBookSeq;\n emit();\n return true;\n }\n\n setBucket(input.bucket);\n stream = snapshotThenStream({\n realtime: this.#realtime,\n channel,\n schema: Proto.OrderBookDeltaSchema,\n maxBufferedPublications: 200,\n snapshotErrorLog: \"Failed to fetch orderbook\",\n snapshotRetry: { maxAttempts: 3, delayMs: 1_000 },\n fetchSnapshot: inputServiceFetch,\n readPublication: (delta) => [delta],\n applySnapshot: (snapshot, bufferedDeltas) => {\n bidsMap = levelsToMap(snapshot.bids);\n asksMap = levelsToMap(snapshot.asks);\n currentBookSeq = snapshot.bookSeq;\n emit();\n for (const delta of bufferedDeltas) {\n if (stream?.isDisposed()) return;\n if (!handleDelta(delta)) return;\n }\n },\n applyLivePublications: (deltas) => {\n for (const delta of deltas) {\n if (stream?.isDisposed()) return;\n if (!handleDelta(delta)) return;\n }\n },\n onOpen: input.onOpen,\n onClose: input.onClose,\n onError: input.onError,\n });\n\n function dispose(): void {\n stream?.unsubscribe();\n }\n\n return { unsubscribe: dispose, setBucket };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAkDA,IAAa,mBAAb,MAA8B;CAC1B;CACA;CACA;CAEA,YAAY,WAAsB,UAA6B,QAAmB;EAC9E,KAAKA,UAAU,aAAaC,oBAAwB,SAAS;EAC7D,KAAKC,YAAY;EACjB,KAAKC,UAAU;CACnB;;;;CAKA,MAAM,IACF,OACA,SACsB;EACtB,MAAM,YAAY,MAAM,yBAAyB,KAAK;EACtD,MAAM,KAAKA,QAAQ,MAAM;EACzB,MAAM,MAAM,MAAM,KAAKH,QAAQ,aAC3B;GAAE,UAAU,UAAU;GAAU,OAAO,UAAU;EAAW,GAC5D,qBAAqB,OAAO,CAChC;EACA,OAAO,MAAM,0BAA0B,KAAKG,SAAS,UAAU,QAAQ,GAAG;GACtE,UAAU,IAAI;GACd,OAAO,UAAU;GACjB,SAAS,IAAI;GACb,MAAM,IAAI;GACV,MAAM,IAAI;EACd,CAAC;CACL;;;;CAKA,UAAU,OAA4C;EAClD,OAAO,KAAK,mBAAmB,KAAK,CAAC,CAAC;CAC1C;;;;;;;;CASA,mBAAmB,OAAgE;EAC/E,MAAM,EAAE,aAAa,MAAM,yBAAyB;GAChD,UAAU,MAAM;GAChB,OAAO,MAAM;EACjB,CAAC;EACD,MAAM,iBAAiB,KAAK,IAAI,KAAK,KAAK,IAAI,GAAG,KAAK,MAAM,MAAM,SAAS,EAAE,CAAC,CAAC;EAC/E,MAAM,eAAe,wBAAwB,cAAc;EAC3D,MAAM,UAAU,sCAAsC,aA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AAM,aAAa,iBAAiB,MAAM,aAAa;GACxE,KAAK;GACL,OAAO;EACX;EAEA,UAAU,MAAM,MAAM;EACtB,SAAS,mBAAmB;GACxB,UAAU,KAAKF;GACf;GACA,QAAQG;GACR,yBAAyB;GACzB,kBAAkB;GAClB,eAAe;IAAE,aAAa;IAAG,SAAS;GAAM;GAChD,eAAe;GACf,kBAAkB,UAAU,CAAC,KAAK;GAClC,gBAAgB,UAAU,mBAAmB;IACzC,UAAU,YAAY,SAAS,IAAI;IACnC,UAAU,YAAY,SAAS,IAAI;IACnC,iBAAiB,SAAS;IAC1B,KAAK;IACL,KAAK,MAAM,SAAS,gBAAgB;KAChC,IAAI,QAAQ,WAAW,GAAG;KAC1B,IAAI,CAAC,YAAY,KAAK,GAAG;IAC7B;GACJ;GACA,wBAAwB,WAAW;IAC/B,KAAK,MAAM,SAAS,QAAQ;KACxB,IAAI,QAAQ,WAAW,GAAG;KAC1B,IAAI,CAAC,YAAY,KAAK,GAAG;IAC7B;GACJ;GACA,QAAQ,MAAM;GACd,SAAS,MAAM;GACf,SAAS,MAAM;EACnB,CAAC;EAED,SAAS,UAAgB;GACrB,QAAQ,YAAY;EACxB;EAEA,OAAO;GAAE,aAAa;GAAS;EAAU;CAC7C;AACJ"}
|
|
@@ -212,8 +212,6 @@ declare function createBatchCreateOrdersInputSchema(scales: SdkScales): v.Schema
|
|
|
212
212
|
}, undefined>, v.StrictObjectSchema<{
|
|
213
213
|
readonly kind: v.LiteralSchema<"bps", undefined>;
|
|
214
214
|
readonly bps: v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>, v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.GtValueAction<number, 0, undefined>]>], undefined>;
|
|
215
|
-
}, undefined>, v.StrictObjectSchema<{
|
|
216
|
-
readonly kind: v.LiteralSchema<"none", undefined>;
|
|
217
215
|
}, undefined>], undefined>;
|
|
218
216
|
readonly maxSlippage: v.OptionalSchema<v.UnionSchema<[v.StrictObjectSchema<{
|
|
219
217
|
readonly kind: v.LiteralSchema<"slippage", undefined>;
|
|
@@ -229,8 +227,6 @@ declare function createBatchCreateOrdersInputSchema(scales: SdkScales): v.Schema
|
|
|
229
227
|
trailingDistance: {
|
|
230
228
|
kind: "bps";
|
|
231
229
|
bps: string | number;
|
|
232
|
-
} | {
|
|
233
|
-
kind: "none";
|
|
234
230
|
} | {
|
|
235
231
|
kind: "distance";
|
|
236
232
|
distance: string;
|
|
@@ -343,8 +339,6 @@ declare function createBatchCreateOrdersInputSchema(scales: SdkScales): v.Schema
|
|
|
343
339
|
}, undefined>, v.StrictObjectSchema<{
|
|
344
340
|
readonly kind: v.LiteralSchema<"bps", undefined>;
|
|
345
341
|
readonly bps: v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>, v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.GtValueAction<number, 0, undefined>]>], undefined>;
|
|
346
|
-
}, undefined>, v.StrictObjectSchema<{
|
|
347
|
-
readonly kind: v.LiteralSchema<"none", undefined>;
|
|
348
342
|
}, undefined>], undefined>;
|
|
349
343
|
readonly maxSlippage: v.OptionalSchema<v.UnionSchema<[v.StrictObjectSchema<{
|
|
350
344
|
readonly kind: v.LiteralSchema<"slippage", undefined>;
|
|
@@ -360,8 +354,6 @@ declare function createBatchCreateOrdersInputSchema(scales: SdkScales): v.Schema
|
|
|
360
354
|
trailingDistance: {
|
|
361
355
|
kind: "bps";
|
|
362
356
|
bps: string | number;
|
|
363
|
-
} | {
|
|
364
|
-
kind: "none";
|
|
365
357
|
} | {
|
|
366
358
|
kind: "distance";
|
|
367
359
|
distance: string;
|
|
@@ -743,8 +735,6 @@ declare function createBatchCreateOrdersInputSchema(scales: SdkScales): v.Schema
|
|
|
743
735
|
}, undefined>, v.StrictObjectSchema<{
|
|
744
736
|
readonly kind: v.LiteralSchema<"bps", undefined>;
|
|
745
737
|
readonly bps: v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>, v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.GtValueAction<number, 0, undefined>]>], undefined>;
|
|
746
|
-
}, undefined>, v.StrictObjectSchema<{
|
|
747
|
-
readonly kind: v.LiteralSchema<"none", undefined>;
|
|
748
738
|
}, undefined>], undefined>;
|
|
749
739
|
readonly maxSlippage: v.OptionalSchema<v.UnionSchema<[v.StrictObjectSchema<{
|
|
750
740
|
readonly kind: v.LiteralSchema<"slippage", undefined>;
|
|
@@ -760,8 +750,6 @@ declare function createBatchCreateOrdersInputSchema(scales: SdkScales): v.Schema
|
|
|
760
750
|
trailingDistance: {
|
|
761
751
|
kind: "bps";
|
|
762
752
|
bps: string | number;
|
|
763
|
-
} | {
|
|
764
|
-
kind: "none";
|
|
765
753
|
} | {
|
|
766
754
|
kind: "distance";
|
|
767
755
|
distance: string;
|
|
@@ -874,8 +862,6 @@ declare function createBatchCreateOrdersInputSchema(scales: SdkScales): v.Schema
|
|
|
874
862
|
}, undefined>, v.StrictObjectSchema<{
|
|
875
863
|
readonly kind: v.LiteralSchema<"bps", undefined>;
|
|
876
864
|
readonly bps: v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>, v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.GtValueAction<number, 0, undefined>]>], undefined>;
|
|
877
|
-
}, undefined>, v.StrictObjectSchema<{
|
|
878
|
-
readonly kind: v.LiteralSchema<"none", undefined>;
|
|
879
865
|
}, undefined>], undefined>;
|
|
880
866
|
readonly maxSlippage: v.OptionalSchema<v.UnionSchema<[v.StrictObjectSchema<{
|
|
881
867
|
readonly kind: v.LiteralSchema<"slippage", undefined>;
|
|
@@ -891,8 +877,6 @@ declare function createBatchCreateOrdersInputSchema(scales: SdkScales): v.Schema
|
|
|
891
877
|
trailingDistance: {
|
|
892
878
|
kind: "bps";
|
|
893
879
|
bps: string | number;
|
|
894
|
-
} | {
|
|
895
|
-
kind: "none";
|
|
896
880
|
} | {
|
|
897
881
|
kind: "distance";
|
|
898
882
|
distance: string;
|
|
@@ -3257,9 +3241,9 @@ declare const GetBatchReplaceStatusResultSchema: v.SchemaWithPipe<readonly [v.Ob
|
|
|
3257
3241
|
}>]>;
|
|
3258
3242
|
type GetBatchReplaceStatusResult = v.InferOutput<typeof GetBatchReplaceStatusResultSchema>;
|
|
3259
3243
|
declare const BatchCancelOrderInputSchema: v.UnionSchema<[v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
|
|
3260
|
-
readonly orderId: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.TransformAction<string, bigint>]>, v.CheckAction<bigint,
|
|
3244
|
+
readonly orderId: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.TransformAction<string, bigint>]>, v.CheckAction<bigint, `${string} must be greater than zero`>]>;
|
|
3261
3245
|
readonly clientOrderId: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
3262
|
-
readonly symbolId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.
|
|
3246
|
+
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>;
|
|
3263
3247
|
}, undefined>, v.TransformAction<{
|
|
3264
3248
|
orderId: bigint;
|
|
3265
3249
|
clientOrderId?: undefined;
|
|
@@ -3270,7 +3254,7 @@ declare const BatchCancelOrderInputSchema: v.UnionSchema<[v.SchemaWithPipe<reado
|
|
|
3270
3254
|
}>]>, v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
|
|
3271
3255
|
readonly orderId: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
3272
3256
|
readonly clientOrderId: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MaxLengthAction<string, 36, undefined>, v.RegexAction<string, "clientOrderId has an invalid format">]>, v.MinLengthAction<string, 1, undefined>]>;
|
|
3273
|
-
readonly symbolId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.
|
|
3257
|
+
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>;
|
|
3274
3258
|
}, undefined>, v.TransformAction<{
|
|
3275
3259
|
orderId?: undefined;
|
|
3276
3260
|
clientOrderId: string;
|
|
@@ -3283,9 +3267,9 @@ type BatchCancelOrderInput = v.InferInput<typeof BatchCancelOrderInputSchema>;
|
|
|
3283
3267
|
declare const BatchCancelOrdersInputSchema: v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
|
|
3284
3268
|
readonly requestId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 64, undefined>, v.RegexAction<string, "requestId has an invalid format">]>, undefined>;
|
|
3285
3269
|
readonly items: v.SchemaWithPipe<readonly [v.ArraySchema<v.UnionSchema<[v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
|
|
3286
|
-
readonly orderId: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.TransformAction<string, bigint>]>, v.CheckAction<bigint,
|
|
3270
|
+
readonly orderId: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.TransformAction<string, bigint>]>, v.CheckAction<bigint, `${string} must be greater than zero`>]>;
|
|
3287
3271
|
readonly clientOrderId: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
3288
|
-
readonly symbolId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.
|
|
3272
|
+
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>;
|
|
3289
3273
|
}, undefined>, v.TransformAction<{
|
|
3290
3274
|
orderId: bigint;
|
|
3291
3275
|
clientOrderId?: undefined;
|
|
@@ -3296,7 +3280,7 @@ declare const BatchCancelOrdersInputSchema: v.SchemaWithPipe<readonly [v.StrictO
|
|
|
3296
3280
|
}>]>, v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
|
|
3297
3281
|
readonly orderId: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
3298
3282
|
readonly clientOrderId: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MaxLengthAction<string, 36, undefined>, v.RegexAction<string, "clientOrderId has an invalid format">]>, v.MinLengthAction<string, 1, undefined>]>;
|
|
3299
|
-
readonly symbolId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.
|
|
3283
|
+
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>;
|
|
3300
3284
|
}, undefined>, v.TransformAction<{
|
|
3301
3285
|
orderId?: undefined;
|
|
3302
3286
|
clientOrderId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orders-batch.schemas.d.ts","names":[],"sources":["../../../src/services/orders/orders-batch.schemas.ts"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"orders-batch.schemas.d.ts","names":[],"sources":["../../../src/services/orders/orders-batch.schemas.ts"],"mappings":";;;;;;;;cAuDa,2BAAyB,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;KAc1B,sBAAsB,EAAE,kBAAkB;cAEzC,4BAA0B,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;KAgB3B,uBAAuB,EAAE,mBAAmB;iBAExC,mCAAmC,QAAQ,YAAS,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;KAgB7B,yBAAyB,EAAE,kBAAkB;cAEnD,8BAA4B,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;KAQtB,yBAAyB,EAAE,mBAAmB;cAE7C,+BAA6B,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAkB9B,0BAA0B,EAAE,mBAAmB"}
|
|
@@ -11,7 +11,7 @@ import { OrderSideCodec } from "./order-enums.codecs.js";
|
|
|
11
11
|
import { BatchReplaceAdmissionStatusCodec, BatchReplaceItemAdmissionStatusCodec, BatchReplacePhaseCodec, OrderStatusCodec } from "./orders.codecs.js";
|
|
12
12
|
import { OrderErrorDetailSchema } from "./order-errors.schemas.js";
|
|
13
13
|
import { createRequiredRiskPolicyInputSchema } from "./orders-risk.schemas.js";
|
|
14
|
-
import { ClientOrderIdInputSchema, OrderRequestIdInputSchema } from "./orders-identifiers.schemas.js";
|
|
14
|
+
import { ClientOrderIdInputSchema, OrderRequestIdInputSchema, positiveOrderIdInputSchema } from "./orders-identifiers.schemas.js";
|
|
15
15
|
import { createOrderIntentInputSchema } from "./orders-input.schemas.js";
|
|
16
16
|
import { create } from "@bufbuild/protobuf";
|
|
17
17
|
import * as v from "valibot";
|
|
@@ -127,7 +127,7 @@ const BatchReplaceTargetInputSchema = v.union([v.pipe(v.object({
|
|
|
127
127
|
case: "clientOrderId",
|
|
128
128
|
value: clientOrderId
|
|
129
129
|
} })))]);
|
|
130
|
-
function createBatchReplaceOrderItemInputSchema(scales
|
|
130
|
+
function createBatchReplaceOrderItemInputSchema(scales) {
|
|
131
131
|
const patchSchema = v.union([
|
|
132
132
|
v.object({
|
|
133
133
|
newPrice: DecimalInputStringSchema,
|
|
@@ -154,31 +154,34 @@ function createBatchReplaceOrderItemInputSchema(scales, symbolId) {
|
|
|
154
154
|
clearRisk: v.literal(true)
|
|
155
155
|
})
|
|
156
156
|
]);
|
|
157
|
-
return v.
|
|
157
|
+
return v.intersect([
|
|
158
158
|
BatchReplaceTargetInputSchema,
|
|
159
159
|
patchSchema,
|
|
160
160
|
v.object({ newClientOrderId: v.optional(ClientOrderIdInputSchema) })
|
|
161
|
-
])
|
|
162
|
-
key: input.key,
|
|
163
|
-
newPriceTicks: input.newPrice === void 0 ? void 0 : positiveDecimalInputToScaled("items.newPrice", input.newPrice, scales.price()),
|
|
164
|
-
newQtyScaled: input.newQty === void 0 ? void 0 : positiveDecimalInputToScaled("items.newQty", input.newQty, scales.baseQty(symbolId)),
|
|
165
|
-
newAttachedRisk: input.clearRisk === true ? create(RiskPolicySchema) : input.risk,
|
|
166
|
-
newClientOrderId: input.newClientOrderId ?? ""
|
|
167
|
-
})));
|
|
161
|
+
]);
|
|
168
162
|
}
|
|
169
|
-
function createBatchReplaceOrdersInputSchema(scales
|
|
163
|
+
function createBatchReplaceOrdersInputSchema(scales) {
|
|
170
164
|
return v.pipe(v.strictObject({
|
|
171
165
|
...AccountScopeInputEntries,
|
|
172
|
-
symbolId:
|
|
166
|
+
symbolId: SymbolIdInputSchema,
|
|
173
167
|
requestId: v.optional(OrderRequestIdInputSchema),
|
|
174
|
-
items: v.pipe(v.array(createBatchReplaceOrderItemInputSchema(scales
|
|
168
|
+
items: v.pipe(v.array(createBatchReplaceOrderItemInputSchema(scales)), v.minLength(1, "At least one replacement is required."), v.maxLength(50, "Batch replace accepts at most 50 replacements."))
|
|
175
169
|
}), v.check((input) => {
|
|
176
170
|
const targets = input.items.map((item) => `${item.key.case}:${item.key.value.toString()}`);
|
|
177
171
|
return new Set(targets).size === targets.length;
|
|
178
|
-
}, "Each batch replace target must be unique."), v.transform(({ account, ...input }) =>
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
172
|
+
}, "Each batch replace target must be unique."), v.transform(({ account, items, ...input }) => {
|
|
173
|
+
return {
|
|
174
|
+
...input,
|
|
175
|
+
items: items.map((item) => ({
|
|
176
|
+
key: item.key,
|
|
177
|
+
newPriceTicks: item.newPrice === void 0 ? void 0 : positiveDecimalInputToScaled("items.newPrice", item.newPrice, scales.price()),
|
|
178
|
+
newQtyScaled: item.newQty === void 0 ? void 0 : positiveDecimalInputToScaled("items.newQty", item.newQty, scales.baseQty(input.symbolId)),
|
|
179
|
+
newAttachedRisk: item.clearRisk === true ? create(RiskPolicySchema) : item.risk,
|
|
180
|
+
newClientOrderId: item.newClientOrderId ?? ""
|
|
181
|
+
})),
|
|
182
|
+
subaccountId: accountScopeToSubaccountId(account)
|
|
183
|
+
};
|
|
184
|
+
}));
|
|
182
185
|
}
|
|
183
186
|
const BatchReplaceAdmissionItemSchema = v.pipe(v.object({
|
|
184
187
|
itemIndex: BatchItemIndexSchema,
|
|
@@ -241,16 +244,16 @@ const GetBatchReplaceStatusResultSchema = v.pipe(v.object({
|
|
|
241
244
|
updatedTsNs: updatedTsNs.toString()
|
|
242
245
|
})));
|
|
243
246
|
const BatchCancelOrderInputSchema = v.union([v.pipe(v.strictObject({
|
|
244
|
-
orderId:
|
|
247
|
+
orderId: positiveOrderIdInputSchema("items.orderId"),
|
|
245
248
|
clientOrderId: v.optional(v.never()),
|
|
246
|
-
symbolId: v.optional(
|
|
249
|
+
symbolId: v.optional(SymbolIdInputSchema)
|
|
247
250
|
}), v.transform(({ orderId, symbolId }) => ({
|
|
248
251
|
orderId,
|
|
249
252
|
symbolId
|
|
250
253
|
}))), v.pipe(v.strictObject({
|
|
251
254
|
orderId: v.optional(v.never()),
|
|
252
255
|
clientOrderId: ClientOrderIdInputSchema,
|
|
253
|
-
symbolId: v.optional(
|
|
256
|
+
symbolId: v.optional(SymbolIdInputSchema)
|
|
254
257
|
}), v.transform(({ clientOrderId, symbolId }) => ({
|
|
255
258
|
clientOrderId,
|
|
256
259
|
symbolId
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orders-batch.schemas.js","names":["ProtoWrite.RiskPolicySchema","ProtoWrite.BatchReplaceItemAdmissionStatus","ProtoWrite.BatchReplaceAdmissionStatus","ProtoRead.BatchReplacePhase","ProtoRead.OrderStatus"],"sources":["../../../src/services/orders/orders-batch.schemas.ts"],"sourcesContent":["import * as ProtoWrite from \"../../gen/orders/v1/orders_pb.js\";\nimport * as ProtoRead from \"../../gen/orders/v1/orders_read_pb.js\";\nimport { create } from \"@bufbuild/protobuf\";\nimport * as v from \"valibot\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport { OptionalPublicIdSchema, PublicIdSchema, idInputSchema } from \"../../shared/schemas.js\";\nimport { requiredEnumLabel } from \"../../shared/proto-enum-codec.js\";\nimport { tsNsToMs } from \"../../utils/time.js\";\nimport { formatId } from \"../../utils/base58-id.js\";\nimport { SideSchema, SymbolIdInputSchema } from \"../shared.js\";\nimport {\n positiveDecimalInputToScaled,\n scaledToDecimalOutput,\n type SdkScales,\n} from \"../../shared/decimal-surface.js\";\nimport {\n BatchReplaceAdmissionStatusCodec,\n BatchReplaceItemAdmissionStatusCodec,\n BatchReplacePhaseCodec,\n OrderStatusCodec,\n OrderSideCodec,\n} from \"./orders.codecs.js\";\nimport { createOrderIntentInputSchema } from \"./orders-input.schemas.js\";\nimport { createRequiredRiskPolicyInputSchema } from \"./orders-risk.schemas.js\";\nimport {\n ClientOrderIdInputSchema,\n OrderRequestIdInputSchema,\n} from \"./orders-identifiers.schemas.js\";\nimport { OrderErrorDetailSchema } from \"./order-errors.schemas.js\";\n\nconst BatchCountSchema = v.pipe(v.number(), v.integer(), v.minValue(0));\nconst BatchItemIndexSchema = v.pipe(v.number(), v.integer(), v.minValue(0));\nconst PositivePublicIdSchema = v.pipe(\n v.bigint(),\n v.gtValue(0n),\n v.transform((value) => formatId(value)),\n);\nconst OptionalSideInputSchema = v.pipe(\n v.optional(SideSchema),\n v.transform((side) => (side ? OrderSideCodec.inputToProto[side] : undefined)),\n);\n\nconst CancelAllAfterTimeoutInputSchema = v.pipe(\n v.number(),\n v.integer(),\n v.check(\n (timeoutSec) => timeoutSec === 0 || (timeoutSec >= 10 && timeoutSec <= 120),\n \"timeoutSec must be 0 to disable or between 10 and 120 seconds to arm\",\n ),\n);\n\nexport const CancelAllAfterInputSchema = v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n timeoutSec: CancelAllAfterTimeoutInputSchema,\n symbolId: v.optional(SymbolIdInputSchema),\n side: OptionalSideInputSchema,\n requestId: v.optional(OrderRequestIdInputSchema),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\nexport type CancelAllAfterInput = v.InferInput<typeof CancelAllAfterInputSchema>;\n\nexport const CancelAllAfterResultSchema = v.pipe(\n v.object({\n status: v.picklist([\"armed\", \"disabled\"]),\n effectiveTimeoutSec: v.pipe(v.number(), v.integer(), v.minValue(0)),\n expiresAtTsNs: v.bigint(),\n tsNs: v.bigint(),\n }),\n v.transform(({ expiresAtTsNs, tsNs, ...result }) => ({\n ...result,\n expiresAt: tsNsToMs(expiresAtTsNs),\n expiresAtNs: expiresAtTsNs.toString(),\n ts: tsNsToMs(tsNs),\n tsNs: tsNs.toString(),\n })),\n);\n\nexport type CancelAllAfterResult = v.InferOutput<typeof CancelAllAfterResultSchema>;\n\nexport function createBatchCreateOrdersInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n requestId: v.optional(OrderRequestIdInputSchema),\n items: v.pipe(\n v.array(createOrderIntentInputSchema(scales)),\n v.minLength(1, \"At least one order is required.\"),\n v.maxLength(20, \"Batch create accepts at most 20 orders.\"),\n ),\n }),\n v.check((input) => {\n const clientOrderIds = input.items\n .map((item) => item.clientOrderId)\n .filter((clientOrderId) => clientOrderId !== undefined && clientOrderId !== \"\");\n return new Set(clientOrderIds).size === clientOrderIds.length;\n }, \"Each non-empty batch create clientOrderId must be unique.\"),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n );\n}\n\nexport type BatchCreateOrdersInput = v.InferInput<\n ReturnType<typeof createBatchCreateOrdersInputSchema>\n>;\n\nconst BatchCreateOrderResultRawSchema = v.object({\n clientOrderId: v.string(),\n outcome: v.variant(\"case\", [\n v.object({\n case: v.literal(\"accepted\"),\n value: v.object({\n orderId: PublicIdSchema,\n takeProfitTriggerId: OptionalPublicIdSchema,\n stopLossTriggerId: OptionalPublicIdSchema,\n trailingStopTriggerId: OptionalPublicIdSchema,\n resolvedBaseQtyScaled: v.bigint(),\n submittedMaxQuoteDebitScaled: v.optional(v.bigint()),\n }),\n }),\n v.object({\n case: v.literal(\"rejected\"),\n value: v.object({\n // The server may reject without a structured detail (e.g. capacity\n // limits); surface the rejection instead of failing the parse.\n error: v.optional(OrderErrorDetailSchema),\n }),\n }),\n ]),\n});\n\nexport function createBatchCreateOrdersResultSchema(scales: SdkScales, symbolIds: number[]) {\n return v.pipe(\n v.object({\n results: v.array(BatchCreateOrderResultRawSchema),\n acceptedCount: BatchCountSchema,\n rejectedCount: BatchCountSchema,\n tsNs: v.bigint(),\n }),\n v.check(\n (response) =>\n response.acceptedCount + response.rejectedCount === response.results.length,\n \"Batch create result counts do not match the returned results.\",\n ),\n v.check(\n (response) => response.results.length === symbolIds.length,\n \"Batch create result count does not match the submitted item count.\",\n ),\n v.transform(({ tsNs, ...response }) => ({\n ...response,\n results: response.results.map(({ clientOrderId, outcome }, index) => {\n if (outcome.case === \"rejected\") {\n return {\n status: \"rejected\" as const,\n clientOrderId,\n error: outcome.value.error,\n };\n }\n const { resolvedBaseQtyScaled, submittedMaxQuoteDebitScaled, ...accepted } =\n outcome.value;\n const symbolId = symbolIds[index]!;\n return {\n status: \"accepted\" as const,\n clientOrderId,\n ...accepted,\n resolvedBaseQty: scaledToDecimalOutput(\n resolvedBaseQtyScaled,\n scales.baseQty(symbolId),\n ),\n ...(submittedMaxQuoteDebitScaled === undefined\n ? {}\n : {\n submittedMaxQuoteDebit: scaledToDecimalOutput(\n submittedMaxQuoteDebitScaled,\n scales.quoteAmount(symbolId),\n ),\n }),\n };\n }),\n ts: tsNsToMs(tsNs),\n tsNs: tsNs.toString(),\n })),\n );\n}\n\nexport type BatchCreateOrdersResult = v.InferOutput<\n ReturnType<typeof createBatchCreateOrdersResultSchema>\n>;\nexport type BatchCreateOrderResult = BatchCreateOrdersResult[\"results\"][number];\n\nconst DecimalInputStringSchema = v.pipe(v.string(), v.trim(), v.minLength(1));\nconst BATCH_REPLACE_ITEM_INPUT_KEYS = new Set([\n \"orderId\",\n \"clientOrderId\",\n \"newPrice\",\n \"newQty\",\n \"risk\",\n \"clearRisk\",\n \"newClientOrderId\",\n]);\n\nexport function assertKnownBatchReplaceOrderItemInputKeys(input: object): void {\n for (const key of Object.keys(input)) {\n if (!BATCH_REPLACE_ITEM_INPUT_KEYS.has(key)) {\n throw new Error(`Unknown key \"${key}\" in batch replace order item.`);\n }\n }\n}\n\nconst BatchReplaceTargetInputSchema = v.union([\n v.pipe(\n v.object({\n orderId: v.pipe(\n idInputSchema(\"items.orderId\"),\n v.check((value) => value > 0n, \"items.orderId must be greater than zero\"),\n ),\n clientOrderId: v.optional(v.never()),\n }),\n v.transform(({ orderId }) => ({\n key: { case: \"orderId\" as const, value: orderId },\n })),\n ),\n v.pipe(\n v.object({\n orderId: v.optional(v.never()),\n clientOrderId: ClientOrderIdInputSchema,\n }),\n v.transform(({ clientOrderId }) => ({\n key: { case: \"clientOrderId\" as const, value: clientOrderId },\n })),\n ),\n]);\n\nfunction createBatchReplaceOrderItemInputSchema(scales: SdkScales, symbolId: number) {\n const patchSchema = v.union([\n v.object({\n newPrice: DecimalInputStringSchema,\n newQty: v.optional(DecimalInputStringSchema),\n risk: v.optional(createRequiredRiskPolicyInputSchema(scales)),\n clearRisk: v.optional(v.literal(false)),\n }),\n v.object({\n newPrice: v.optional(DecimalInputStringSchema),\n newQty: DecimalInputStringSchema,\n risk: v.optional(createRequiredRiskPolicyInputSchema(scales)),\n clearRisk: v.optional(v.literal(false)),\n }),\n v.object({\n newPrice: v.optional(v.never()),\n newQty: v.optional(v.never()),\n risk: createRequiredRiskPolicyInputSchema(scales),\n clearRisk: v.optional(v.literal(false)),\n }),\n v.object({\n newPrice: v.optional(v.never()),\n newQty: v.optional(v.never()),\n risk: v.optional(v.never()),\n clearRisk: v.literal(true),\n }),\n ]);\n return v.pipe(\n v.intersect([\n BatchReplaceTargetInputSchema,\n patchSchema,\n v.object({\n newClientOrderId: v.optional(ClientOrderIdInputSchema),\n }),\n ]),\n v.transform((input) => ({\n key: input.key,\n newPriceTicks:\n input.newPrice === undefined\n ? undefined\n : positiveDecimalInputToScaled(\n \"items.newPrice\",\n input.newPrice,\n scales.price(),\n ),\n newQtyScaled:\n input.newQty === undefined\n ? undefined\n : positiveDecimalInputToScaled(\n \"items.newQty\",\n input.newQty,\n scales.baseQty(symbolId),\n ),\n newAttachedRisk:\n input.clearRisk === true ? create(ProtoWrite.RiskPolicySchema) : input.risk,\n newClientOrderId: input.newClientOrderId ?? \"\",\n })),\n );\n}\n\nexport function createBatchReplaceOrdersInputSchema(scales: SdkScales, symbolId: number) {\n return v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n symbolId: v.pipe(v.literal(symbolId), v.integer(), v.minValue(1)),\n requestId: v.optional(OrderRequestIdInputSchema),\n items: v.pipe(\n v.array(createBatchReplaceOrderItemInputSchema(scales, symbolId)),\n v.minLength(1, \"At least one replacement is required.\"),\n v.maxLength(50, \"Batch replace accepts at most 50 replacements.\"),\n ),\n }),\n v.check((input) => {\n const targets = input.items.map(\n (item) => `${item.key.case}:${item.key.value.toString()}`,\n );\n return new Set(targets).size === targets.length;\n }, \"Each batch replace target must be unique.\"),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n );\n}\n\nexport type BatchReplaceOrdersInput = {\n account?: v.InferInput<typeof AccountScopeInputEntries.account>;\n symbolId: number;\n requestId?: string;\n items: Array<{\n orderId?: string;\n clientOrderId?: string;\n newPrice?: string;\n newQty?: string;\n risk?: v.InferInput<ReturnType<typeof createRequiredRiskPolicyInputSchema>>;\n clearRisk?: boolean;\n newClientOrderId?: string;\n }>;\n};\n\nconst BatchReplaceAdmissionItemSchema = v.pipe(\n v.object({\n itemIndex: BatchItemIndexSchema,\n status: v.pipe(\n v.enum(ProtoWrite.BatchReplaceItemAdmissionStatus),\n v.transform((status) =>\n requiredEnumLabel(\n BatchReplaceItemAdmissionStatusCodec.protoToOutput,\n status,\n \"BatchReplaceAdmissionItemSchema\",\n \"status\",\n ),\n ),\n ),\n oldOrderId: OptionalPublicIdSchema,\n replacementOrderId: OptionalPublicIdSchema,\n clientOrderId: v.string(),\n code: v.string(),\n error: v.optional(OrderErrorDetailSchema),\n }),\n v.transform((item) => ({\n ...item,\n code: item.code || undefined,\n })),\n);\n\nexport type BatchReplaceAdmissionItem = v.InferOutput<typeof BatchReplaceAdmissionItemSchema>;\n\nexport const BatchReplaceOrdersResultSchema = v.pipe(\n v.object({\n batchRequestId: PositivePublicIdSchema,\n status: v.pipe(\n v.enum(ProtoWrite.BatchReplaceAdmissionStatus),\n v.transform((status) =>\n requiredEnumLabel(\n BatchReplaceAdmissionStatusCodec.protoToOutput,\n status,\n \"BatchReplaceOrdersResultSchema\",\n \"status\",\n ),\n ),\n ),\n results: v.array(BatchReplaceAdmissionItemSchema),\n acceptedCount: BatchCountSchema,\n rejectedCount: BatchCountSchema,\n acceptedTsNs: v.bigint(),\n }),\n v.check(\n (response) => response.acceptedCount + response.rejectedCount === response.results.length,\n \"Batch replace result counts do not match the returned results.\",\n ),\n v.check(\n (response) => response.results.every((item, index) => item.itemIndex === index),\n \"Batch replace results must preserve request item order.\",\n ),\n v.transform(({ acceptedTsNs, ...response }) => ({\n ...response,\n acceptedTs: tsNsToMs(acceptedTsNs),\n acceptedTsNs: acceptedTsNs.toString(),\n })),\n);\n\nexport type BatchReplaceOrdersResult = v.InferOutput<typeof BatchReplaceOrdersResultSchema>;\n\nexport const GetBatchReplaceStatusInputSchema = v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n batchRequestId: v.pipe(\n idInputSchema(\"batchRequestId\"),\n v.check((value) => value > 0n, \"batchRequestId must be greater than zero\"),\n ),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\nexport type GetBatchReplaceStatusInput = v.InferInput<typeof GetBatchReplaceStatusInputSchema>;\n\nconst BatchReplaceStatusItemSchema = v.pipe(\n v.object({\n itemIndex: BatchItemIndexSchema,\n phase: v.pipe(\n v.enum(ProtoRead.BatchReplacePhase),\n v.transform((phase) =>\n requiredEnumLabel(\n BatchReplacePhaseCodec.protoToOutput,\n phase,\n \"BatchReplaceStatusItemSchema\",\n \"phase\",\n ),\n ),\n ),\n oldOrderId: OptionalPublicIdSchema,\n replacementOrderId: OptionalPublicIdSchema,\n orderStatus: v.pipe(\n v.enum(ProtoRead.OrderStatus),\n v.transform((status) =>\n requiredEnumLabel(\n OrderStatusCodec.protoToOutput,\n status,\n \"BatchReplaceStatusItemSchema\",\n \"order status\",\n ),\n ),\n ),\n code: v.string(),\n updatedTsNs: v.bigint(),\n }),\n v.transform(({ updatedTsNs, ...item }) => ({\n ...item,\n code: item.code || undefined,\n updatedTs: tsNsToMs(updatedTsNs),\n updatedTsNs: updatedTsNs.toString(),\n })),\n);\n\nexport const GetBatchReplaceStatusResultSchema = v.pipe(\n v.object({\n batchRequestId: PositivePublicIdSchema,\n admissionStatus: v.pipe(\n v.enum(ProtoWrite.BatchReplaceAdmissionStatus),\n v.transform((status) =>\n requiredEnumLabel(\n BatchReplaceAdmissionStatusCodec.protoToOutput,\n status,\n \"GetBatchReplaceStatusResultSchema\",\n \"admission status\",\n ),\n ),\n ),\n items: v.array(BatchReplaceStatusItemSchema),\n acceptedCount: BatchCountSchema,\n rejectedCount: BatchCountSchema,\n acceptedTsNs: v.bigint(),\n updatedTsNs: v.bigint(),\n }),\n v.check(\n (response) => response.acceptedCount + response.rejectedCount === response.items.length,\n \"Batch replace status counts do not match the returned items.\",\n ),\n v.check(\n (response) => response.items.every((item, index) => item.itemIndex === index),\n \"Batch replace status items must preserve request item order.\",\n ),\n v.transform(({ acceptedTsNs, updatedTsNs, ...response }) => ({\n ...response,\n acceptedTs: tsNsToMs(acceptedTsNs),\n acceptedTsNs: acceptedTsNs.toString(),\n updatedTs: tsNsToMs(updatedTsNs),\n updatedTsNs: updatedTsNs.toString(),\n })),\n);\n\nexport type GetBatchReplaceStatusResult = v.InferOutput<typeof GetBatchReplaceStatusResultSchema>;\n\nconst BatchCancelOrderInputSchema = v.union([\n v.pipe(\n v.strictObject({\n orderId: v.pipe(\n idInputSchema(\"items.orderId\"),\n v.check((value) => value > 0n, \"items.orderId must be greater than zero\"),\n ),\n clientOrderId: v.optional(v.never()),\n symbolId: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1))),\n }),\n v.transform(({ orderId, symbolId }) => ({ orderId, symbolId })),\n ),\n v.pipe(\n v.strictObject({\n orderId: v.optional(v.never()),\n clientOrderId: ClientOrderIdInputSchema,\n symbolId: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1))),\n }),\n v.transform(({ clientOrderId, symbolId }) => ({ clientOrderId, symbolId })),\n ),\n]);\n\nexport type BatchCancelOrderInput = v.InferInput<typeof BatchCancelOrderInputSchema>;\n\nexport const BatchCancelOrdersInputSchema = v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n requestId: v.optional(OrderRequestIdInputSchema),\n items: v.pipe(\n v.array(BatchCancelOrderInputSchema),\n v.minLength(1, \"At least one order is required.\"),\n v.maxLength(50, \"Batch cancel accepts at most 50 orders.\"),\n ),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\nexport type BatchCancelOrdersInput = v.InferInput<typeof BatchCancelOrdersInputSchema>;\n\nconst BatchCancelOrderResultSchema = v.object({\n status: v.picklist([\"accepted\", \"rejected\"]),\n orderId: OptionalPublicIdSchema,\n clientOrderId: v.string(),\n code: v.string(),\n error: v.optional(OrderErrorDetailSchema),\n});\n\nexport type BatchCancelOrderResult = v.InferOutput<typeof BatchCancelOrderResultSchema>;\n\nexport const BatchCancelOrdersResultSchema = v.pipe(\n v.object({\n results: v.array(BatchCancelOrderResultSchema),\n acceptedCount: BatchCountSchema,\n rejectedCount: BatchCountSchema,\n tsNs: v.bigint(),\n }),\n v.check(\n (response) => response.acceptedCount + response.rejectedCount === response.results.length,\n \"Batch cancel result counts do not match the returned results.\",\n ),\n v.transform(({ tsNs, ...response }) => ({\n ...response,\n ts: tsNsToMs(tsNs),\n tsNs: tsNs.toString(),\n })),\n);\n\nexport type BatchCancelOrdersResult = v.InferOutput<typeof BatchCancelOrdersResultSchema>;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiCA,MAAM,mBAAmB,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,QAAQ,GAAG,EAAE,SAAS,CAAC,CAAC;AACtE,MAAM,uBAAuB,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,QAAQ,GAAG,EAAE,SAAS,CAAC,CAAC;AAC1E,MAAM,yBAAyB,EAAE,KAC7B,EAAE,OAAO,GACT,EAAE,QAAQ,EAAE,GACZ,EAAE,WAAW,UAAU,SAAS,KAAK,CAAC,CAC1C;AACA,MAAM,0BAA0B,EAAE,KAC9B,EAAE,SAAS,UAAU,GACrB,EAAE,WAAW,SAAU,OAAO,eAAe,aAAa,QAAQ,KAAA,CAAU,CAChF;AAEA,MAAM,mCAAmC,EAAE,KACvC,EAAE,OAAO,GACT,EAAE,QAAQ,GACV,EAAE,OACG,eAAe,eAAe,KAAM,cAAc,MAAM,cAAc,KACvE,sEACJ,CACJ;AAEA,MAAa,4BAA4B,EAAE,KACvC,EAAE,aAAa;CACX,GAAG;CACH,YAAY;CACZ,UAAU,EAAE,SAAS,mBAAmB;CACxC,M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SAAS,sBAAsB;AAC5C,CAAC;AAID,MAAa,gCAAgC,EAAE,KAC3C,EAAE,OAAO;CACL,SAAS,EAAE,MAAM,4BAA4B;CAC7C,eAAe;CACf,eAAe;CACf,MAAM,EAAE,OAAO;AACnB,CAAC,GACD,EAAE,OACG,aAAa,SAAS,gBAAgB,SAAS,kBAAkB,SAAS,QAAQ,QACnF,+DACJ,GACA,EAAE,WAAW,EAAE,MAAM,GAAG,gBAAgB;CACpC,GAAG;CACH,IAAI,SAAS,IAAI;CACjB,MAAM,KAAK,SAAS;AACxB,EAAE,CACN"}
|
|
1
|
+
{"version":3,"file":"orders-batch.schemas.js","names":["ProtoWrite.RiskPolicySchema","ProtoWrite.BatchReplaceItemAdmissionStatus","ProtoWrite.BatchReplaceAdmissionStatus","ProtoRead.BatchReplacePhase","ProtoRead.OrderStatus"],"sources":["../../../src/services/orders/orders-batch.schemas.ts"],"sourcesContent":["import * as ProtoWrite from \"../../gen/orders/v1/orders_pb.js\";\nimport * as ProtoRead from \"../../gen/orders/v1/orders_read_pb.js\";\nimport { create } from \"@bufbuild/protobuf\";\nimport * as v from \"valibot\";\nimport {\n AccountScopeInputEntries,\n accountScopeToSubaccountId,\n} from \"../../shared/account-scope.js\";\nimport { OptionalPublicIdSchema, PublicIdSchema, idInputSchema } from \"../../shared/schemas.js\";\nimport { requiredEnumLabel } from \"../../shared/proto-enum-codec.js\";\nimport { tsNsToMs } from \"../../utils/time.js\";\nimport { formatId } from \"../../utils/base58-id.js\";\nimport { SideSchema, SymbolIdInputSchema } from \"../shared.js\";\nimport {\n positiveDecimalInputToScaled,\n scaledToDecimalOutput,\n type SdkScales,\n} from \"../../shared/decimal-surface.js\";\nimport {\n BatchReplaceAdmissionStatusCodec,\n BatchReplaceItemAdmissionStatusCodec,\n BatchReplacePhaseCodec,\n OrderStatusCodec,\n OrderSideCodec,\n} from \"./orders.codecs.js\";\nimport { createOrderIntentInputSchema } from \"./orders-input.schemas.js\";\nimport { createRequiredRiskPolicyInputSchema } from \"./orders-risk.schemas.js\";\nimport {\n ClientOrderIdInputSchema,\n positiveOrderIdInputSchema,\n OrderRequestIdInputSchema,\n} from \"./orders-identifiers.schemas.js\";\nimport { OrderErrorDetailSchema } from \"./order-errors.schemas.js\";\n\nconst BatchCountSchema = v.pipe(v.number(), v.integer(), v.minValue(0));\nconst BatchItemIndexSchema = v.pipe(v.number(), v.integer(), v.minValue(0));\nconst PositivePublicIdSchema = v.pipe(\n v.bigint(),\n v.gtValue(0n),\n v.transform((value) => formatId(value)),\n);\nconst OptionalSideInputSchema = v.pipe(\n v.optional(SideSchema),\n v.transform((side) => (side ? OrderSideCodec.inputToProto[side] : undefined)),\n);\n\nconst CancelAllAfterTimeoutInputSchema = v.pipe(\n v.number(),\n v.integer(),\n v.check(\n (timeoutSec) => timeoutSec === 0 || (timeoutSec >= 10 && timeoutSec <= 120),\n \"timeoutSec must be 0 to disable or between 10 and 120 seconds to arm\",\n ),\n);\n\nexport const CancelAllAfterInputSchema = v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n timeoutSec: CancelAllAfterTimeoutInputSchema,\n symbolId: v.optional(SymbolIdInputSchema),\n side: OptionalSideInputSchema,\n requestId: v.optional(OrderRequestIdInputSchema),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\nexport type CancelAllAfterInput = v.InferInput<typeof CancelAllAfterInputSchema>;\n\nexport const CancelAllAfterResultSchema = v.pipe(\n v.object({\n status: v.picklist([\"armed\", \"disabled\"]),\n effectiveTimeoutSec: v.pipe(v.number(), v.integer(), v.minValue(0)),\n expiresAtTsNs: v.bigint(),\n tsNs: v.bigint(),\n }),\n v.transform(({ expiresAtTsNs, tsNs, ...result }) => ({\n ...result,\n expiresAt: tsNsToMs(expiresAtTsNs),\n expiresAtNs: expiresAtTsNs.toString(),\n ts: tsNsToMs(tsNs),\n tsNs: tsNs.toString(),\n })),\n);\n\nexport type CancelAllAfterResult = v.InferOutput<typeof CancelAllAfterResultSchema>;\n\nexport function createBatchCreateOrdersInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n requestId: v.optional(OrderRequestIdInputSchema),\n items: v.pipe(\n v.array(createOrderIntentInputSchema(scales)),\n v.minLength(1, \"At least one order is required.\"),\n v.maxLength(20, \"Batch create accepts at most 20 orders.\"),\n ),\n }),\n v.check((input) => {\n const clientOrderIds = input.items\n .map((item) => item.clientOrderId)\n .filter((clientOrderId) => clientOrderId !== undefined && clientOrderId !== \"\");\n return new Set(clientOrderIds).size === clientOrderIds.length;\n }, \"Each non-empty batch create clientOrderId must be unique.\"),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n );\n}\n\nexport type BatchCreateOrdersInput = v.InferInput<\n ReturnType<typeof createBatchCreateOrdersInputSchema>\n>;\n\nconst BatchCreateOrderResultRawSchema = v.object({\n clientOrderId: v.string(),\n outcome: v.variant(\"case\", [\n v.object({\n case: v.literal(\"accepted\"),\n value: v.object({\n orderId: PublicIdSchema,\n takeProfitTriggerId: OptionalPublicIdSchema,\n stopLossTriggerId: OptionalPublicIdSchema,\n trailingStopTriggerId: OptionalPublicIdSchema,\n resolvedBaseQtyScaled: v.bigint(),\n submittedMaxQuoteDebitScaled: v.optional(v.bigint()),\n }),\n }),\n v.object({\n case: v.literal(\"rejected\"),\n value: v.object({\n // The server may reject without a structured detail (e.g. capacity\n // limits); surface the rejection instead of failing the parse.\n error: v.optional(OrderErrorDetailSchema),\n }),\n }),\n ]),\n});\n\nexport function createBatchCreateOrdersResultSchema(scales: SdkScales, symbolIds: number[]) {\n return v.pipe(\n v.object({\n results: v.array(BatchCreateOrderResultRawSchema),\n acceptedCount: BatchCountSchema,\n rejectedCount: BatchCountSchema,\n tsNs: v.bigint(),\n }),\n v.check(\n (response) =>\n response.acceptedCount + response.rejectedCount === response.results.length,\n \"Batch create result counts do not match the returned results.\",\n ),\n v.check(\n (response) => response.results.length === symbolIds.length,\n \"Batch create result count does not match the submitted item count.\",\n ),\n v.transform(({ tsNs, ...response }) => ({\n ...response,\n results: response.results.map(({ clientOrderId, outcome }, index) => {\n if (outcome.case === \"rejected\") {\n return {\n status: \"rejected\" as const,\n clientOrderId,\n error: outcome.value.error,\n };\n }\n const { resolvedBaseQtyScaled, submittedMaxQuoteDebitScaled, ...accepted } =\n outcome.value;\n const symbolId = symbolIds[index]!;\n return {\n status: \"accepted\" as const,\n clientOrderId,\n ...accepted,\n resolvedBaseQty: scaledToDecimalOutput(\n resolvedBaseQtyScaled,\n scales.baseQty(symbolId),\n ),\n ...(submittedMaxQuoteDebitScaled === undefined\n ? {}\n : {\n submittedMaxQuoteDebit: scaledToDecimalOutput(\n submittedMaxQuoteDebitScaled,\n scales.quoteAmount(symbolId),\n ),\n }),\n };\n }),\n ts: tsNsToMs(tsNs),\n tsNs: tsNs.toString(),\n })),\n );\n}\n\nexport type BatchCreateOrdersResult = v.InferOutput<\n ReturnType<typeof createBatchCreateOrdersResultSchema>\n>;\nexport type BatchCreateOrderResult = BatchCreateOrdersResult[\"results\"][number];\n\nconst DecimalInputStringSchema = v.pipe(v.string(), v.trim(), v.minLength(1));\nconst BATCH_REPLACE_ITEM_INPUT_KEYS = new Set([\n \"orderId\",\n \"clientOrderId\",\n \"newPrice\",\n \"newQty\",\n \"risk\",\n \"clearRisk\",\n \"newClientOrderId\",\n]);\n\nexport function assertKnownBatchReplaceOrderItemInputKeys(input: object): void {\n for (const key of Object.keys(input)) {\n if (!BATCH_REPLACE_ITEM_INPUT_KEYS.has(key)) {\n throw new Error(`Unknown key \"${key}\" in batch replace order item.`);\n }\n }\n}\n\nconst BatchReplaceTargetInputSchema = v.union([\n v.pipe(\n v.object({\n orderId: v.pipe(\n idInputSchema(\"items.orderId\"),\n v.check((value) => value > 0n, \"items.orderId must be greater than zero\"),\n ),\n clientOrderId: v.optional(v.never()),\n }),\n v.transform(({ orderId }) => ({\n key: { case: \"orderId\" as const, value: orderId },\n })),\n ),\n v.pipe(\n v.object({\n orderId: v.optional(v.never()),\n clientOrderId: ClientOrderIdInputSchema,\n }),\n v.transform(({ clientOrderId }) => ({\n key: { case: \"clientOrderId\" as const, value: clientOrderId },\n })),\n ),\n]);\n\nfunction createBatchReplaceOrderItemInputSchema(scales: SdkScales) {\n const patchSchema = v.union([\n v.object({\n newPrice: DecimalInputStringSchema,\n newQty: v.optional(DecimalInputStringSchema),\n risk: v.optional(createRequiredRiskPolicyInputSchema(scales)),\n clearRisk: v.optional(v.literal(false)),\n }),\n v.object({\n newPrice: v.optional(DecimalInputStringSchema),\n newQty: DecimalInputStringSchema,\n risk: v.optional(createRequiredRiskPolicyInputSchema(scales)),\n clearRisk: v.optional(v.literal(false)),\n }),\n v.object({\n newPrice: v.optional(v.never()),\n newQty: v.optional(v.never()),\n risk: createRequiredRiskPolicyInputSchema(scales),\n clearRisk: v.optional(v.literal(false)),\n }),\n v.object({\n newPrice: v.optional(v.never()),\n newQty: v.optional(v.never()),\n risk: v.optional(v.never()),\n clearRisk: v.literal(true),\n }),\n ]);\n return v.intersect([\n BatchReplaceTargetInputSchema,\n patchSchema,\n v.object({\n newClientOrderId: v.optional(ClientOrderIdInputSchema),\n }),\n ]);\n}\n\nexport function createBatchReplaceOrdersInputSchema(scales: SdkScales) {\n return v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n symbolId: SymbolIdInputSchema,\n requestId: v.optional(OrderRequestIdInputSchema),\n items: v.pipe(\n v.array(createBatchReplaceOrderItemInputSchema(scales)),\n v.minLength(1, \"At least one replacement is required.\"),\n v.maxLength(50, \"Batch replace accepts at most 50 replacements.\"),\n ),\n }),\n v.check((input) => {\n const targets = input.items.map(\n (item) => `${item.key.case}:${item.key.value.toString()}`,\n );\n return new Set(targets).size === targets.length;\n }, \"Each batch replace target must be unique.\"),\n v.transform(({ account, items, ...input }) => {\n return {\n ...input,\n items: items.map((item) => ({\n key: item.key,\n newPriceTicks:\n item.newPrice === undefined\n ? undefined\n : positiveDecimalInputToScaled(\n \"items.newPrice\",\n item.newPrice,\n scales.price(),\n ),\n newQtyScaled:\n item.newQty === undefined\n ? undefined\n : positiveDecimalInputToScaled(\n \"items.newQty\",\n item.newQty,\n scales.baseQty(input.symbolId),\n ),\n newAttachedRisk:\n item.clearRisk === true ? create(ProtoWrite.RiskPolicySchema) : item.risk,\n newClientOrderId: item.newClientOrderId ?? \"\",\n })),\n subaccountId: accountScopeToSubaccountId(account),\n };\n }),\n );\n}\n\nexport type BatchReplaceOrdersInput = {\n account?: v.InferInput<typeof AccountScopeInputEntries.account>;\n symbolId: number;\n requestId?: string;\n items: Array<{\n orderId?: string;\n clientOrderId?: string;\n newPrice?: string;\n newQty?: string;\n risk?: v.InferInput<ReturnType<typeof createRequiredRiskPolicyInputSchema>>;\n clearRisk?: boolean;\n newClientOrderId?: string;\n }>;\n};\n\nconst BatchReplaceAdmissionItemSchema = v.pipe(\n v.object({\n itemIndex: BatchItemIndexSchema,\n status: v.pipe(\n v.enum(ProtoWrite.BatchReplaceItemAdmissionStatus),\n v.transform((status) =>\n requiredEnumLabel(\n BatchReplaceItemAdmissionStatusCodec.protoToOutput,\n status,\n \"BatchReplaceAdmissionItemSchema\",\n \"status\",\n ),\n ),\n ),\n oldOrderId: OptionalPublicIdSchema,\n replacementOrderId: OptionalPublicIdSchema,\n clientOrderId: v.string(),\n code: v.string(),\n error: v.optional(OrderErrorDetailSchema),\n }),\n v.transform((item) => ({\n ...item,\n code: item.code || undefined,\n })),\n);\n\nexport type BatchReplaceAdmissionItem = v.InferOutput<typeof BatchReplaceAdmissionItemSchema>;\n\nexport const BatchReplaceOrdersResultSchema = v.pipe(\n v.object({\n batchRequestId: PositivePublicIdSchema,\n status: v.pipe(\n v.enum(ProtoWrite.BatchReplaceAdmissionStatus),\n v.transform((status) =>\n requiredEnumLabel(\n BatchReplaceAdmissionStatusCodec.protoToOutput,\n status,\n \"BatchReplaceOrdersResultSchema\",\n \"status\",\n ),\n ),\n ),\n results: v.array(BatchReplaceAdmissionItemSchema),\n acceptedCount: BatchCountSchema,\n rejectedCount: BatchCountSchema,\n acceptedTsNs: v.bigint(),\n }),\n v.check(\n (response) => response.acceptedCount + response.rejectedCount === response.results.length,\n \"Batch replace result counts do not match the returned results.\",\n ),\n v.check(\n (response) => response.results.every((item, index) => item.itemIndex === index),\n \"Batch replace results must preserve request item order.\",\n ),\n v.transform(({ acceptedTsNs, ...response }) => ({\n ...response,\n acceptedTs: tsNsToMs(acceptedTsNs),\n acceptedTsNs: acceptedTsNs.toString(),\n })),\n);\n\nexport type BatchReplaceOrdersResult = v.InferOutput<typeof BatchReplaceOrdersResultSchema>;\n\nexport const GetBatchReplaceStatusInputSchema = v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n batchRequestId: v.pipe(\n idInputSchema(\"batchRequestId\"),\n v.check((value) => value > 0n, \"batchRequestId must be greater than zero\"),\n ),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\nexport type GetBatchReplaceStatusInput = v.InferInput<typeof GetBatchReplaceStatusInputSchema>;\n\nconst BatchReplaceStatusItemSchema = v.pipe(\n v.object({\n itemIndex: BatchItemIndexSchema,\n phase: v.pipe(\n v.enum(ProtoRead.BatchReplacePhase),\n v.transform((phase) =>\n requiredEnumLabel(\n BatchReplacePhaseCodec.protoToOutput,\n phase,\n \"BatchReplaceStatusItemSchema\",\n \"phase\",\n ),\n ),\n ),\n oldOrderId: OptionalPublicIdSchema,\n replacementOrderId: OptionalPublicIdSchema,\n orderStatus: v.pipe(\n v.enum(ProtoRead.OrderStatus),\n v.transform((status) =>\n requiredEnumLabel(\n OrderStatusCodec.protoToOutput,\n status,\n \"BatchReplaceStatusItemSchema\",\n \"order status\",\n ),\n ),\n ),\n code: v.string(),\n updatedTsNs: v.bigint(),\n }),\n v.transform(({ updatedTsNs, ...item }) => ({\n ...item,\n code: item.code || undefined,\n updatedTs: tsNsToMs(updatedTsNs),\n updatedTsNs: updatedTsNs.toString(),\n })),\n);\n\nexport const GetBatchReplaceStatusResultSchema = v.pipe(\n v.object({\n batchRequestId: PositivePublicIdSchema,\n admissionStatus: v.pipe(\n v.enum(ProtoWrite.BatchReplaceAdmissionStatus),\n v.transform((status) =>\n requiredEnumLabel(\n BatchReplaceAdmissionStatusCodec.protoToOutput,\n status,\n \"GetBatchReplaceStatusResultSchema\",\n \"admission status\",\n ),\n ),\n ),\n items: v.array(BatchReplaceStatusItemSchema),\n acceptedCount: BatchCountSchema,\n rejectedCount: BatchCountSchema,\n acceptedTsNs: v.bigint(),\n updatedTsNs: v.bigint(),\n }),\n v.check(\n (response) => response.acceptedCount + response.rejectedCount === response.items.length,\n \"Batch replace status counts do not match the returned items.\",\n ),\n v.check(\n (response) => response.items.every((item, index) => item.itemIndex === index),\n \"Batch replace status items must preserve request item order.\",\n ),\n v.transform(({ acceptedTsNs, updatedTsNs, ...response }) => ({\n ...response,\n acceptedTs: tsNsToMs(acceptedTsNs),\n acceptedTsNs: acceptedTsNs.toString(),\n updatedTs: tsNsToMs(updatedTsNs),\n updatedTsNs: updatedTsNs.toString(),\n })),\n);\n\nexport type GetBatchReplaceStatusResult = v.InferOutput<typeof GetBatchReplaceStatusResultSchema>;\n\nconst BatchCancelOrderInputSchema = v.union([\n v.pipe(\n v.strictObject({\n orderId: positiveOrderIdInputSchema(\"items.orderId\"),\n clientOrderId: v.optional(v.never()),\n symbolId: v.optional(SymbolIdInputSchema),\n }),\n v.transform(({ orderId, symbolId }) => ({ orderId, symbolId })),\n ),\n v.pipe(\n v.strictObject({\n orderId: v.optional(v.never()),\n clientOrderId: ClientOrderIdInputSchema,\n symbolId: v.optional(SymbolIdInputSchema),\n }),\n v.transform(({ clientOrderId, symbolId }) => ({ clientOrderId, symbolId })),\n ),\n]);\n\nexport type BatchCancelOrderInput = v.InferInput<typeof BatchCancelOrderInputSchema>;\n\nexport const BatchCancelOrdersInputSchema = v.pipe(\n v.strictObject({\n ...AccountScopeInputEntries,\n requestId: v.optional(OrderRequestIdInputSchema),\n items: v.pipe(\n v.array(BatchCancelOrderInputSchema),\n v.minLength(1, \"At least one order is required.\"),\n v.maxLength(50, \"Batch cancel accepts at most 50 orders.\"),\n ),\n }),\n v.transform(({ account, ...input }) => ({\n ...input,\n subaccountId: accountScopeToSubaccountId(account),\n })),\n);\n\nexport type BatchCancelOrdersInput = v.InferInput<typeof BatchCancelOrdersInputSchema>;\n\nconst BatchCancelOrderResultSchema = v.object({\n status: v.picklist([\"accepted\", \"rejected\"]),\n orderId: OptionalPublicIdSchema,\n clientOrderId: v.string(),\n code: v.string(),\n error: v.optional(OrderErrorDetailSchema),\n});\n\nexport type BatchCancelOrderResult = v.InferOutput<typeof BatchCancelOrderResultSchema>;\n\nexport const BatchCancelOrdersResultSchema = v.pipe(\n v.object({\n results: v.array(BatchCancelOrderResultSchema),\n acceptedCount: BatchCountSchema,\n rejectedCount: BatchCountSchema,\n tsNs: v.bigint(),\n }),\n v.check(\n (response) => response.acceptedCount + response.rejectedCount === response.results.length,\n \"Batch cancel result counts do not match the returned results.\",\n ),\n v.transform(({ tsNs, ...response }) => ({\n ...response,\n ts: tsNsToMs(tsNs),\n tsNs: tsNs.toString(),\n })),\n);\n\nexport type BatchCancelOrdersResult = v.InferOutput<typeof BatchCancelOrdersResultSchema>;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkCA,MAAM,mBAAmB,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,QAAQ,GAAG,EAAE,SAAS,CAAC,CAAC;AACtE,MAAM,uBAAuB,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,QAAQ,GAAG,EAAE,SAAS,CAAC,CAAC;AAC1E,MAAM,yBAAyB,EAAE,KAC7B,EAAE,OAAO,GACT,EAAE,QAAQ,EAAE,GACZ,EAAE,WAAW,UAAU,SAAS,KAAK,CAAC,CAC1C;AACA,MAAM,0BAA0B,EAAE,KAC9B,EAAE,SAAS,UAAU,GACrB,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f,OAAO,EAAE,SAAS,sBAAsB;AAC5C,CAAC;AAID,MAAa,gCAAgC,EAAE,KAC3C,EAAE,OAAO;CACL,SAAS,EAAE,MAAM,4BAA4B;CAC7C,eAAe;CACf,eAAe;CACf,MAAM,EAAE,OAAO;AACnB,CAAC,GACD,EAAE,OACG,aAAa,SAAS,gBAAgB,SAAS,kBAAkB,SAAS,QAAQ,QACnF,+DACJ,GACA,EAAE,WAAW,EAAE,MAAM,GAAG,gBAAgB;CACpC,GAAG;CACH,IAAI,SAAS,IAAI;CACjB,MAAM,KAAK,SAAS;AACxB,EAAE,CACN"}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
import { idInputSchema } from "../../shared/schemas.js";
|
|
1
2
|
import * as v from "valibot";
|
|
2
3
|
//#region src/services/orders/orders-identifiers.schemas.ts
|
|
3
4
|
const OrderIdempotencyKeyPattern = /^[A-Za-z0-9._:/-]*$/;
|
|
4
5
|
const ClientOrderIdWireInputSchema = v.pipe(v.string(), v.trim(), v.maxLength(36), v.regex(OrderIdempotencyKeyPattern, "clientOrderId has an invalid format"));
|
|
5
6
|
const ClientOrderIdInputSchema = v.pipe(ClientOrderIdWireInputSchema, v.minLength(1));
|
|
6
7
|
const OptionalClientOrderIdInputSchema = v.optional(ClientOrderIdWireInputSchema);
|
|
8
|
+
function positiveOrderIdInputSchema(fieldName = "orderId") {
|
|
9
|
+
return v.pipe(idInputSchema(fieldName), v.check((value) => value > 0n, `${fieldName} must be greater than zero`));
|
|
10
|
+
}
|
|
11
|
+
const OrderIdInputSchema = positiveOrderIdInputSchema();
|
|
7
12
|
const OrderRequestIdInputSchema = v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(64), v.regex(OrderIdempotencyKeyPattern, "requestId has an invalid format"));
|
|
8
13
|
//#endregion
|
|
9
|
-
export { ClientOrderIdInputSchema, OptionalClientOrderIdInputSchema, OrderRequestIdInputSchema };
|
|
14
|
+
export { ClientOrderIdInputSchema, OptionalClientOrderIdInputSchema, OrderIdInputSchema, OrderRequestIdInputSchema, positiveOrderIdInputSchema };
|
|
10
15
|
|
|
11
16
|
//# sourceMappingURL=orders-identifiers.schemas.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orders-identifiers.schemas.js","names":[],"sources":["../../../src/services/orders/orders-identifiers.schemas.ts"],"sourcesContent":["import * as v from \"valibot\";\n\nconst OrderIdempotencyKeyPattern = /^[A-Za-z0-9._:/-]*$/;\n\nconst ClientOrderIdWireInputSchema = v.pipe(\n v.string(),\n v.trim(),\n v.maxLength(36),\n v.regex(OrderIdempotencyKeyPattern, \"clientOrderId has an invalid format\"),\n);\n\nexport const ClientOrderIdInputSchema = v.pipe(ClientOrderIdWireInputSchema, v.minLength(1));\n\nexport const OptionalClientOrderIdInputSchema = v.optional(ClientOrderIdWireInputSchema);\n\nexport const OrderRequestIdInputSchema = v.pipe(\n v.string(),\n v.trim(),\n v.minLength(1),\n v.maxLength(64),\n v.regex(OrderIdempotencyKeyPattern, \"requestId has an invalid format\"),\n);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"orders-identifiers.schemas.js","names":[],"sources":["../../../src/services/orders/orders-identifiers.schemas.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport { idInputSchema } from \"../../shared/schemas.js\";\n\nconst OrderIdempotencyKeyPattern = /^[A-Za-z0-9._:/-]*$/;\n\nconst ClientOrderIdWireInputSchema = v.pipe(\n v.string(),\n v.trim(),\n v.maxLength(36),\n v.regex(OrderIdempotencyKeyPattern, \"clientOrderId has an invalid format\"),\n);\n\nexport const ClientOrderIdInputSchema = v.pipe(ClientOrderIdWireInputSchema, v.minLength(1));\n\nexport const OptionalClientOrderIdInputSchema = v.optional(ClientOrderIdWireInputSchema);\n\nexport function positiveOrderIdInputSchema(fieldName = \"orderId\") {\n return v.pipe(\n idInputSchema(fieldName),\n v.check((value) => value > 0n, `${fieldName} must be greater than zero`),\n );\n}\n\nexport const OrderIdInputSchema = positiveOrderIdInputSchema();\n\nexport const OrderRequestIdInputSchema = v.pipe(\n v.string(),\n v.trim(),\n v.minLength(1),\n v.maxLength(64),\n v.regex(OrderIdempotencyKeyPattern, \"requestId has an invalid format\"),\n);\n"],"mappings":";;;AAGA,MAAM,6BAA6B;AAEnC,MAAM,+BAA+B,EAAE,KACnC,EAAE,OAAO,GACT,EAAE,KAAK,GACP,EAAE,UAAU,EAAE,GACd,EAAE,MAAM,4BAA4B,qCAAqC,CAC7E;AAEA,MAAa,2BAA2B,EAAE,KAAK,8BAA8B,EAAE,UAAU,CAAC,CAAC;AAE3F,MAAa,mCAAmC,EAAE,SAAS,4BAA4B;AAEvF,SAAgB,2BAA2B,YAAY,WAAW;CAC9D,OAAO,EAAE,KACL,cAAc,SAAS,GACvB,EAAE,OAAO,UAAU,QAAQ,IAAI,GAAG,UAAU,2BAA2B,CAC3E;AACJ;AAEA,MAAa,qBAAqB,2BAA2B;AAE7D,MAAa,4BAA4B,EAAE,KACvC,EAAE,OAAO,GACT,EAAE,KAAK,GACP,EAAE,UAAU,CAAC,GACb,EAAE,UAAU,EAAE,GACd,EAAE,MAAM,4BAA4B,iCAAiC,CACzE"}
|