@dimes-dot-fi/sdk 1.5.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +88 -19
  3. package/dist/{aliases-ByZ2DcA5.d.cts → aliases-BJyM8ydu.d.cts} +54 -4
  4. package/dist/{aliases-ByZ2DcA5.d.ts → aliases-BJyM8ydu.d.ts} +54 -4
  5. package/dist/{chunk-UHQZSMUD.cjs → chunk-53U53KZ2.cjs} +5 -1
  6. package/dist/chunk-53U53KZ2.cjs.map +1 -0
  7. package/dist/chunk-5VHDXPRV.mjs +240 -0
  8. package/dist/chunk-5VHDXPRV.mjs.map +1 -0
  9. package/dist/{chunk-Y5WQ3UWF.cjs → chunk-DIH3ORFA.cjs} +18 -12
  10. package/dist/chunk-DIH3ORFA.cjs.map +1 -0
  11. package/dist/chunk-FAW2C5AM.cjs +240 -0
  12. package/dist/chunk-FAW2C5AM.cjs.map +1 -0
  13. package/dist/{chunk-3OPRSKCY.mjs → chunk-NHAIL4SN.mjs} +17 -11
  14. package/dist/chunk-NHAIL4SN.mjs.map +1 -0
  15. package/dist/{chunk-4MO3HKMS.mjs → chunk-PK2PRTQW.mjs} +5 -1
  16. package/dist/chunk-PK2PRTQW.mjs.map +1 -0
  17. package/dist/contract/index.cjs +5522 -293
  18. package/dist/contract/index.cjs.map +1 -1
  19. package/dist/contract/index.d.cts +68 -10
  20. package/dist/contract/index.d.ts +68 -10
  21. package/dist/contract/index.mjs +5523 -294
  22. package/dist/contract/index.mjs.map +1 -1
  23. package/dist/{dimes-client-B-thu7VQ.d.cts → dimes-client-DYFvnZUx.d.ts} +41 -9
  24. package/dist/{dimes-client-CerC9mTr.d.ts → dimes-client-DZPhU1CG.d.cts} +41 -9
  25. package/dist/{dimes-error-BY5qVGZC.d.cts → dimes-error-BlQWPqhQ.d.cts} +2 -2
  26. package/dist/{dimes-error-CrvPuFzB.d.ts → dimes-error-DBKV5bfr.d.ts} +2 -2
  27. package/dist/index.cjs +78 -8
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +23 -14
  30. package/dist/index.d.ts +23 -14
  31. package/dist/index.mjs +78 -8
  32. package/dist/index.mjs.map +1 -1
  33. package/dist/quote-BFNgVsY-.d.ts +39 -0
  34. package/dist/quote-CanwfT9m.d.cts +39 -0
  35. package/dist/react/index.cjs +414 -16
  36. package/dist/react/index.cjs.map +1 -1
  37. package/dist/react/index.d.cts +165 -8
  38. package/dist/react/index.d.ts +165 -8
  39. package/dist/react/index.mjs +413 -15
  40. package/dist/react/index.mjs.map +1 -1
  41. package/dist/{types-2bGyrtqd.d.cts → types-ClHQbIcY.d.ts} +3 -3
  42. package/dist/{types-CAuPxEwO.d.ts → types-Co-2bQSi.d.cts} +3 -3
  43. package/dist/ws/index.cjs +4 -230
  44. package/dist/ws/index.cjs.map +1 -1
  45. package/dist/ws/index.d.cts +3 -3
  46. package/dist/ws/index.d.ts +3 -3
  47. package/dist/ws/index.mjs +5 -231
  48. package/dist/ws/index.mjs.map +1 -1
  49. package/package.json +43 -4
  50. package/dist/chunk-3OPRSKCY.mjs.map +0 -1
  51. package/dist/chunk-4MO3HKMS.mjs.map +0 -1
  52. package/dist/chunk-UHQZSMUD.cjs.map +0 -1
  53. package/dist/chunk-Y5WQ3UWF.cjs.map +0 -1
  54. package/dist/quote-Czq3Selh.d.ts +0 -30
  55. package/dist/quote-quIOosIv.d.cts +0 -30
@@ -13,7 +13,9 @@ function buildQuoteParams(params, stepBps = DEFAULT_LEVERAGE_STEP_BPS) {
13
13
  effectiveSide: params.side,
14
14
  leverageBps,
15
15
  notionalAmountUsdPips: notionalUsdPips.toString(),
16
- slippageBps: params.slippageBps
16
+ slippageBps: params.slippageBps,
17
+ ...params.allowPartialFill !== void 0 ? { allowPartialFill: params.allowPartialFill } : {},
18
+ ...params.minFillBps !== void 0 ? { minFillBps: params.minFillBps } : {}
17
19
  };
18
20
  }
19
21
 
@@ -242,6 +244,8 @@ function applyAdjustment(params, adj, currentParams) {
242
244
  }
243
245
  case "slippage":
244
246
  return { ...params, slippageBps: adj.toValue };
247
+ case "minFill":
248
+ return { ...params, allowPartialFill: true, minFillBps: adj.toValue };
245
249
  default:
246
250
  return params;
247
251
  }
@@ -259,7 +263,8 @@ function handleCorrection(err, currentParams) {
259
263
  const adj = hintAdjustment(hint, {
260
264
  collateralUsd: currentParams.collateralUsd,
261
265
  leverageBps: currentParams.leverageBps,
262
- slippageBps: currentParams.slippageBps
266
+ slippageBps: currentParams.slippageBps,
267
+ minFillBps: currentParams.minFillBps
263
268
  });
264
269
  if (!adj) {
265
270
  return null;
@@ -271,18 +276,18 @@ async function executeQuote(client, params, options) {
271
276
  const autoCorrect = options?.autoCorrect ?? true;
272
277
  const corrections = [];
273
278
  let retries = 0;
274
- let offerParams = buildQuoteParams(params);
279
+ let quoteParams = buildQuoteParams(params);
275
280
  const currentParams = { ...params };
276
- const draft = await client.createDraftQuote(offerParams);
281
+ const draft = await client.createDraftQuote(quoteParams);
277
282
  options?.onDraftReady?.(draft);
278
283
  let currentDraft = draft;
279
284
  for (let attempt = 0; attempt <= maxRetries; attempt++) {
280
285
  try {
281
- const promotedOffer = await client.promoteDraftQuote(currentDraft.id);
282
- return { offer: promotedOffer, corrections, retries };
286
+ const promotedQuote = await client.promoteDraftQuote(currentDraft.id);
287
+ return { quote: promotedQuote, offer: promotedQuote, corrections, retries };
283
288
  } catch (err) {
284
289
  if (handleMarketMoved(err, attempt, maxRetries)) {
285
- const newDraft = await client.createDraftQuote(offerParams);
290
+ const newDraft = await client.createDraftQuote(quoteParams);
286
291
  retries++;
287
292
  const callbackResult = options?.onMarketMoved?.({
288
293
  originalDraft: currentDraft,
@@ -302,10 +307,10 @@ async function executeQuote(client, params, options) {
302
307
  if (callbackResult === false) {
303
308
  throw err;
304
309
  }
305
- offerParams = applyAdjustment(offerParams, correction.adj, currentParams);
310
+ quoteParams = applyAdjustment(quoteParams, correction.adj, currentParams);
306
311
  corrections.push(correction.adj);
307
- const correctedOffer = await client.createQuote(offerParams);
308
- return { offer: correctedOffer, corrections, retries };
312
+ const correctedQuote = await client.createQuote(quoteParams);
313
+ return { quote: correctedQuote, offer: correctedQuote, corrections, retries };
309
314
  }
310
315
  }
311
316
  throw err;
@@ -319,6 +324,7 @@ export {
319
324
  marketMovedCodes,
320
325
  quoteErrorHint,
321
326
  hintAdjustment,
327
+ isMarketMovedError,
322
328
  executeQuote
323
329
  };
324
- //# sourceMappingURL=chunk-3OPRSKCY.mjs.map
330
+ //# sourceMappingURL=chunk-NHAIL4SN.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/quote/build-quote-params.ts","../src/quote/quote-error-hints.ts","../src/quote/quote.ts"],"sourcesContent":["import type { CreateQuoteParams } from \"../types\";\nimport type { QuoteParams } from \"../types/quote\";\n\nconst DEFAULT_LEVERAGE_STEP_BPS = 2500;\n\nexport function buildQuoteParams(params: QuoteParams, stepBps: number = DEFAULT_LEVERAGE_STEP_BPS): CreateQuoteParams {\n const leverageBps = Math.round(params.leverageBps / stepBps) * stepBps;\n const notionalUsdPips = Math.round(params.collateralUsd * leverageBps);\n\n return {\n marketTicker: params.marketTicker,\n effectiveSide: params.side,\n leverageBps,\n notionalAmountUsdPips: notionalUsdPips.toString(),\n slippageBps: params.slippageBps,\n ...(params.allowPartialFill !== undefined ? { allowPartialFill: params.allowPartialFill } : {}),\n ...(params.minFillBps !== undefined ? { minFillBps: params.minFillBps } : {}),\n };\n}\n","const pipsPerUsd = 10_000;\nconst bpsPerUnit = 10_000;\nconst bpsPerPct = 100;\nconst minFillBpsMax = 5_000;\nconst centsFactor = 100;\nconst decimalPlaces = 2;\n\nexport const marketMovedCodes = new Set([\n \"quote_slippage_too_high\",\n \"quote_insufficient_liquidity\",\n \"quote_entry_price_out_of_range\",\n \"quote_entry_bid_depth_too_low\",\n \"quote_entry_depth_too_low\",\n \"quote_entry_spread_too_wide\",\n]);\n\nexport type QuoteHint =\n | { kind: \"use-max-collateral\"; maxCollateralUsd: number; minCollateralUsd: number }\n | { kind: \"raise-collateral\"; minCollateralUsd: number }\n | { kind: \"clamp-leverage\"; maxLeverageBps?: number }\n | { kind: \"raise-leverage\"; minLeverageBps: number }\n | { kind: \"raise-slippage\"; currentSlippageBps: number; maxSlippageBps: number }\n | { kind: \"raise-min-fill\"; minFillBps: number }\n | { kind: \"market-full\" }\n | { kind: \"insufficient-liquidity\"; maxCollateralUsd: number; minCollateralUsd: number }\n | null;\n\ntype Params = Record<string, unknown> | null | undefined;\n\nfunction num(params: Params, key: string): number | null {\n if (!params) {\n return null;\n }\n const raw = params[key];\n if (raw === null || raw === undefined) {\n return null;\n }\n // eslint-disable-next-line no-restricted-syntax\n const n = typeof raw === \"string\" ? Number(raw) : typeof raw === \"number\" ? raw : NaN;\n return Number.isFinite(n) ? n : null;\n}\n\nfunction pipsToUsd(pips: number): number {\n return pips / pipsPerUsd;\n}\n\nfunction notionalPipsToCollateralUsd(notionalPips: number, leverageBps: number): number | null {\n if (!Number.isFinite(leverageBps) || leverageBps <= 0) {\n return null;\n }\n return (notionalPips * bpsPerUnit) / leverageBps / pipsPerUsd;\n}\n\nfunction buildExhaustedHint(\n exhaustedKind: \"market-full\" | \"insufficient-liquidity\",\n maxCollateralUsd: number,\n minCollateralUsd: number,\n): QuoteHint {\n if (exhaustedKind === \"insufficient-liquidity\") {\n return { kind: \"insufficient-liquidity\", maxCollateralUsd, minCollateralUsd };\n }\n return { kind: \"market-full\" };\n}\n\nfunction resolveMaxCollateralHint(\n params: Params,\n context: { leverageBps: number },\n capacityKey: string,\n exhaustedKind: \"market-full\" | \"insufficient-liquidity\",\n): QuoteHint {\n const serverMaxCollateralPips = num(params, \"maxSupportedCollateralUsdPips\");\n const capacityPips = num(params, capacityKey);\n const minNotionalPips = num(params, \"minNotionalUsdPips\");\n\n const fromServer = serverMaxCollateralPips !== null ? pipsToUsd(serverMaxCollateralPips) : null;\n const fromCapacity = capacityPips !== null ? notionalPipsToCollateralUsd(capacityPips, context.leverageBps) : null;\n const maxCollateralUsd =\n fromServer !== null && fromCapacity !== null ? Math.min(fromServer, fromCapacity) : (fromServer ?? fromCapacity);\n\n const minCollateralUsd =\n minNotionalPips !== null ? notionalPipsToCollateralUsd(minNotionalPips, context.leverageBps) : null;\n\n if (maxCollateralUsd === null || minCollateralUsd === null) {\n return null;\n }\n if (maxCollateralUsd < minCollateralUsd) {\n return buildExhaustedHint(exhaustedKind, maxCollateralUsd, minCollateralUsd);\n }\n return { kind: \"use-max-collateral\", maxCollateralUsd, minCollateralUsd };\n}\n\n// eslint-disable-next-line complexity\nexport function quoteErrorHint(code: string | null, params: Params, context: { leverageBps: number }): QuoteHint {\n if (!code) {\n return null;\n }\n\n switch (code) {\n case \"quote_side_capacity_exceeded\":\n case \"quote_user_position_limit_exceeded\":\n case \"quote_market_position_limit_exceeded\":\n case \"quote_side_position_limit_exceeded\":\n case \"quote_global_position_limit_exceeded\":\n case \"quote_partner_position_limit_exceeded\":\n return resolveMaxCollateralHint(params, context, \"availableCapacityUsdPips\", \"market-full\");\n\n case \"quote_insufficient_liquidity\":\n return resolveMaxCollateralHint(params, context, \"slippageMaxUsdPips\", \"market-full\");\n\n case \"notional_selector_insufficient_liquidity\":\n return resolveMaxCollateralHint(params, context, \"slippageMaxUsdPips\", \"insufficient-liquidity\");\n\n case \"quote_leverage_exceeds_collateral_floor\": {\n const minCollateralPips = num(params, \"minCollateralUsdPips\");\n if (minCollateralPips === null) {\n return null;\n }\n return { kind: \"raise-collateral\", minCollateralUsd: pipsToUsd(minCollateralPips) };\n }\n\n case \"quote_leverage_exceeds_maximum\":\n case \"quote_leverage_exceeds_model_max\": {\n const maxLeverageBps = num(params, \"maxLeverageBps\");\n if (maxLeverageBps === null) {\n return null;\n }\n return { kind: \"clamp-leverage\", maxLeverageBps };\n }\n\n case \"quote_leverage_too_high_for_price\": {\n const maxLeverageBps = num(params, \"maxAcceptableLeverageBps\");\n if (maxLeverageBps === null) {\n return null;\n }\n return { kind: \"clamp-leverage\", maxLeverageBps };\n }\n\n case \"quote_leverage_below_minimum\": {\n const minLeverageBps = num(params, \"minLeverageBps\");\n if (minLeverageBps === null) {\n return null;\n }\n return { kind: \"raise-leverage\", minLeverageBps };\n }\n\n case \"quote_min_fill_bps_below_floor\": {\n const floorMinFillBps = num(params, \"floorMinFillBps\");\n if (floorMinFillBps === null || floorMinFillBps > minFillBpsMax) {\n return null;\n }\n return { kind: \"raise-min-fill\", minFillBps: floorMinFillBps };\n }\n\n case \"quote_slippage_too_high\": {\n const currentSlippageBps = num(params, \"currentSlippageBps\");\n const maxSlippageBps = num(params, \"maxSlippageBps\");\n if (currentSlippageBps === null || maxSlippageBps === null) {\n return null;\n }\n return { kind: \"raise-slippage\", currentSlippageBps, maxSlippageBps };\n }\n\n default:\n return null;\n }\n}\n\nexport type CorrectedField = \"collateral\" | \"leverage\" | \"slippage\" | \"minFill\";\n\nexport type HintAdjustment =\n | {\n field: \"collateral\";\n fromValue: number;\n toValue: number;\n toLabel: string;\n reason: \"max-collateral\" | \"min-collateral\";\n }\n | {\n field: \"leverage\";\n fromValue: number;\n toValue: number;\n toLabel: string;\n reason: \"clamp-max\" | \"raise-min\";\n }\n | {\n field: \"slippage\";\n fromValue: number;\n toValue: number;\n toLabel: string;\n reason: \"raise-slippage\";\n }\n | {\n field: \"minFill\";\n fromValue: number;\n toValue: number;\n toLabel: string;\n reason: \"raise-min-fill\";\n }\n | null;\n\nfunction formatUsd(value: number): string {\n return new Intl.NumberFormat(\"en-US\", {\n style: \"currency\",\n currency: \"USD\",\n minimumFractionDigits: 2,\n maximumFractionDigits: 2,\n }).format(value);\n}\n\nfunction bpsToMultiplier(bps: number): string {\n return `${(bps / bpsPerUnit).toFixed(1).replace(/\\.0$/, \"\")}x`;\n}\n\n// eslint-disable-next-line complexity\nexport function hintAdjustment(\n hint: QuoteHint,\n current: { collateralUsd: number; leverageBps: number; slippageBps: number; minFillBps?: number },\n): HintAdjustment {\n if (!hint) {\n return null;\n }\n\n switch (hint.kind) {\n case \"use-max-collateral\": {\n const to = Math.max(0, Math.floor(hint.maxCollateralUsd * centsFactor) / centsFactor);\n if (to <= 0) {\n return null;\n }\n return {\n field: \"collateral\",\n fromValue: current.collateralUsd,\n toValue: to,\n toLabel: formatUsd(to),\n reason: \"max-collateral\",\n };\n }\n case \"raise-collateral\": {\n const to = Math.ceil(hint.minCollateralUsd * centsFactor) / centsFactor;\n if (to <= 0) {\n return null;\n }\n return {\n field: \"collateral\",\n fromValue: current.collateralUsd,\n toValue: to,\n toLabel: formatUsd(to),\n reason: \"min-collateral\",\n };\n }\n case \"clamp-leverage\": {\n if (hint.maxLeverageBps === undefined) {\n return null;\n }\n return {\n field: \"leverage\",\n fromValue: current.leverageBps,\n toValue: hint.maxLeverageBps,\n toLabel: bpsToMultiplier(hint.maxLeverageBps),\n reason: \"clamp-max\",\n };\n }\n case \"raise-leverage\":\n return {\n field: \"leverage\",\n fromValue: current.leverageBps,\n toValue: hint.minLeverageBps,\n toLabel: bpsToMultiplier(hint.minLeverageBps),\n reason: \"raise-min\",\n };\n case \"raise-slippage\":\n return {\n field: \"slippage\",\n fromValue: hint.currentSlippageBps,\n toValue: hint.maxSlippageBps,\n toLabel: `${(hint.maxSlippageBps / bpsPerPct).toFixed(decimalPlaces).replace(/\\.?0+$/, \"\")}%`,\n reason: \"raise-slippage\",\n };\n case \"raise-min-fill\":\n return {\n field: \"minFill\",\n fromValue: current.minFillBps ?? 0,\n toValue: hint.minFillBps,\n toLabel: `${(hint.minFillBps / bpsPerPct).toFixed(decimalPlaces).replace(/\\.?0+$/, \"\")}%`,\n reason: \"raise-min-fill\",\n };\n default:\n return null;\n }\n}\n","import { DimesApiError, DimesError } from \"../errors/dimes-error\";\nimport type { CreateQuoteParams, Quote } from \"../types\";\nimport type { QuoteOptions, QuoteParams, QuoteResult } from \"../types/quote\";\nimport { buildQuoteParams } from \"./build-quote-params\";\nimport { type HintAdjustment, hintAdjustment, marketMovedCodes, quoteErrorHint } from \"./quote-error-hints\";\n\nexport interface QuoteClient {\n createDraftQuote(params: CreateQuoteParams): Promise<Quote>;\n promoteDraftQuote(draftId: string): Promise<Quote>;\n createQuote(params: CreateQuoteParams): Promise<Quote>;\n}\n\nconst DEFAULT_MAX_RETRIES = 3;\n\nexport function isMarketMovedError(err: unknown): boolean {\n return err instanceof DimesApiError && marketMovedCodes.has(err.code);\n}\n\nfunction applyAdjustment(\n params: CreateQuoteParams,\n adj: NonNullable<HintAdjustment>,\n currentParams: QuoteParams,\n): CreateQuoteParams {\n switch (adj.field) {\n case \"collateral\": {\n const notionalUsdPips = Math.round(adj.toValue * params.leverageBps);\n return { ...params, notionalAmountUsdPips: notionalUsdPips.toString() };\n }\n case \"leverage\": {\n const notionalUsdPips = Math.round(currentParams.collateralUsd * adj.toValue);\n return {\n ...params,\n leverageBps: adj.toValue,\n notionalAmountUsdPips: notionalUsdPips.toString(),\n };\n }\n case \"slippage\":\n return { ...params, slippageBps: adj.toValue };\n case \"minFill\":\n return { ...params, allowPartialFill: true, minFillBps: adj.toValue };\n default:\n return params;\n }\n}\n\nfunction handleMarketMoved(err: unknown, attempt: number, maxRetries: number): boolean {\n return isMarketMovedError(err) && attempt < maxRetries;\n}\n\nfunction handleCorrection(err: unknown, currentParams: QuoteParams): { adj: NonNullable<HintAdjustment> } | null {\n if (!(err instanceof DimesApiError)) {\n return null;\n }\n\n const hint = quoteErrorHint(err.code, err.params, {\n leverageBps: currentParams.leverageBps,\n });\n\n const adj = hintAdjustment(hint, {\n collateralUsd: currentParams.collateralUsd,\n leverageBps: currentParams.leverageBps,\n slippageBps: currentParams.slippageBps,\n minFillBps: currentParams.minFillBps,\n });\n\n if (!adj) {\n return null;\n }\n\n return { adj };\n}\n\n// eslint-disable-next-line complexity\nexport async function executeQuote(\n client: QuoteClient,\n params: QuoteParams,\n options?: QuoteOptions,\n): Promise<QuoteResult> {\n const maxRetries = options?.maxRetries ?? DEFAULT_MAX_RETRIES;\n const autoCorrect = options?.autoCorrect ?? true;\n const corrections: NonNullable<HintAdjustment>[] = [];\n let retries = 0;\n\n let quoteParams = buildQuoteParams(params);\n const currentParams = { ...params };\n\n const draft = await client.createDraftQuote(quoteParams);\n options?.onDraftReady?.(draft);\n\n let currentDraft: Quote = draft;\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n const promotedQuote = await client.promoteDraftQuote(currentDraft.id);\n return { quote: promotedQuote, offer: promotedQuote, corrections, retries };\n } catch (err) {\n if (handleMarketMoved(err, attempt, maxRetries)) {\n const newDraft = await client.createDraftQuote(quoteParams);\n retries++;\n\n const callbackResult = options?.onMarketMoved?.({\n originalDraft: currentDraft,\n newDraft,\n retryCount: retries,\n });\n\n if (callbackResult === false) {\n throw err;\n }\n\n currentDraft = newDraft;\n continue;\n }\n\n if (autoCorrect) {\n const correction = handleCorrection(err, currentParams);\n\n if (correction) {\n const callbackResult = options?.onCorrection?.(correction.adj);\n if (callbackResult === false) {\n throw err;\n }\n\n quoteParams = applyAdjustment(quoteParams, correction.adj, currentParams);\n corrections.push(correction.adj);\n\n const correctedQuote = await client.createQuote(quoteParams);\n return { quote: correctedQuote, offer: correctedQuote, corrections, retries };\n }\n }\n\n throw err;\n }\n }\n\n throw new DimesError(\"market_moved_retries_exhausted\", \"Exhausted market-moved retries\");\n}\n"],"mappings":";;;;;;AAGA,IAAM,4BAA4B;AAE3B,SAAS,iBAAiB,QAAqB,UAAkB,2BAA8C;AACpH,QAAM,cAAc,KAAK,MAAM,OAAO,cAAc,OAAO,IAAI;AAC/D,QAAM,kBAAkB,KAAK,MAAM,OAAO,gBAAgB,WAAW;AAErE,SAAO;AAAA,IACL,cAAc,OAAO;AAAA,IACrB,eAAe,OAAO;AAAA,IACtB;AAAA,IACA,uBAAuB,gBAAgB,SAAS;AAAA,IAChD,aAAa,OAAO;AAAA,IACpB,GAAI,OAAO,qBAAqB,SAAY,EAAE,kBAAkB,OAAO,iBAAiB,IAAI,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,QAAM,IAAI,WAAW,kCAAkC,gCAAgC;AACzF;","names":[]}
@@ -8,6 +8,10 @@ var positionEventTypes = [
8
8
  "position.liquidated",
9
9
  "position.opened",
10
10
  "position.opening",
11
+ "position.partial_close_requested",
12
+ "position.partial_close_initiated",
13
+ "position.partial_closed",
14
+ "position.partial_close_aborted",
11
15
  "position.reverted",
12
16
  "position.settled"
13
17
  ];
@@ -25,4 +29,4 @@ export {
25
29
  marketEventTypes,
26
30
  notificationCodes
27
31
  };
28
- //# sourceMappingURL=chunk-4MO3HKMS.mjs.map
32
+ //# sourceMappingURL=chunk-PK2PRTQW.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/ws/types.ts"],"sourcesContent":["import type { Market, MarketLeverage, MarketPolymarket, Position } from \"../types\";\n\nexport const positionEventTypes = [\n \"position.cancelled\",\n \"position.close_requested\",\n \"position.closed\",\n \"position.created\",\n \"position.force_unwound\",\n \"position.liquidated\",\n \"position.opened\",\n \"position.opening\",\n \"position.partial_close_requested\",\n \"position.partial_close_initiated\",\n \"position.partial_closed\",\n \"position.partial_close_aborted\",\n \"position.reverted\",\n \"position.settled\",\n] as const;\n\nexport type PositionEventType = (typeof positionEventTypes)[number];\n\nexport interface PositionEventEnvelope {\n id: string;\n type: PositionEventType;\n created_at: string;\n data: Record<string, unknown>;\n}\n\nexport interface PositionEvent {\n id: string;\n type: PositionEventType;\n createdAt: string;\n data: Position;\n}\n\nexport const marketEventTypes = [\n \"market.discovered\",\n \"market.eligibility_changed\",\n \"market.max_leverage_changed\",\n] as const;\n\nexport type MarketEventType = (typeof marketEventTypes)[number];\n\nexport type MarketDelta = Pick<Market, \"id\"> & {\n polymarket: MarketPolymarket;\n leverage?: MarketLeverage;\n} & Partial<Omit<Market, \"id\" | \"leverage\">>;\n\nexport interface MarketEventEnvelope {\n id: string;\n type: MarketEventType;\n created_at: string;\n data: Record<string, unknown>[];\n}\n\nexport interface MarketEvent {\n id: string;\n type: MarketEventType;\n createdAt: string;\n data: Market[] | MarketDelta[];\n}\n\nexport interface NotificationEventEnvelope {\n id: string;\n type: \"notification\";\n created_at: string;\n data: {\n code: string;\n message: string;\n params?: Record<string, unknown>;\n };\n}\n\nexport interface NotificationEvent {\n id: string;\n type: \"notification\";\n createdAt: string;\n data: {\n code: string;\n message: string;\n params?: Record<string, unknown>;\n };\n}\n\nexport const notificationCodes = {\n orderFulfillmentRetrying: \"ORDER_FULFILLMENT_RETRYING\",\n} as const;\n\nexport type NotificationCode = (typeof notificationCodes)[keyof typeof notificationCodes];\n"],"mappings":";AAEO,IAAM,qBAAqB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAkBO,IAAM,mBAAmB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AACF;AA6CO,IAAM,oBAAoB;AAAA,EAC/B,0BAA0B;AAC5B;","names":[]}