@dimes-dot-fi/sdk 2.4.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/dist/{aliases-Dne14KBa.d.cts → aliases-BI1c3Yt0.d.cts} +981 -787
- package/dist/{aliases-Dne14KBa.d.ts → aliases-BI1c3Yt0.d.ts} +981 -787
- package/dist/{chunk-KNGEIWFR.cjs → chunk-ERM4WP6D.cjs} +8 -4
- package/dist/chunk-ERM4WP6D.cjs.map +1 -0
- package/dist/{chunk-LXZAXWLO.mjs → chunk-GA7ZBK6W.mjs} +8 -4
- package/dist/chunk-GA7ZBK6W.mjs.map +1 -0
- package/dist/{chunk-Q34TMZ5J.mjs → chunk-HJ5EVO5A.mjs} +11 -6
- package/dist/chunk-HJ5EVO5A.mjs.map +1 -0
- package/dist/{chunk-IZI65LZF.cjs → chunk-L273PAD4.cjs} +14 -9
- package/dist/chunk-L273PAD4.cjs.map +1 -0
- package/dist/contract/index.cjs +1487 -136
- package/dist/contract/index.cjs.map +1 -1
- package/dist/contract/index.d.cts +135 -8
- package/dist/contract/index.d.ts +135 -8
- package/dist/contract/index.mjs +1470 -119
- package/dist/contract/index.mjs.map +1 -1
- package/dist/{dimes-client-DJ1d_p31.d.ts → dimes-client-C4SsCNrZ.d.cts} +48 -3
- package/dist/{dimes-client-D9tohawC.d.cts → dimes-client-Ckn8yRG6.d.ts} +48 -3
- package/dist/{dimes-error-E9yPAZb-.d.cts → dimes-error-BRysMNV_.d.cts} +2 -2
- package/dist/{dimes-error-hSoOierP.d.ts → dimes-error-Ke7yuX1m.d.ts} +2 -2
- package/dist/index.cjs +78 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -9
- package/dist/index.d.ts +10 -9
- package/dist/index.mjs +74 -4
- package/dist/index.mjs.map +1 -1
- package/dist/{quote-sWguOcoJ.d.cts → quote-06n723we.d.ts} +7 -2
- package/dist/{quote-D4QunMtN.d.ts → quote-CcIqLwKb.d.cts} +7 -2
- package/dist/react/index.cjs +34 -33
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +12 -8
- package/dist/react/index.d.ts +12 -8
- package/dist/react/index.mjs +7 -6
- package/dist/react/index.mjs.map +1 -1
- package/dist/{types-Bvj_WDbX.d.cts → types-B881zrxm.d.cts} +1 -1
- package/dist/{types-BHU4Qq7e.d.ts → types-CcoiGMbT.d.ts} +1 -1
- package/dist/ws/index.d.cts +3 -3
- package/dist/ws/index.d.ts +3 -3
- package/package.json +1 -1
- package/dist/chunk-IZI65LZF.cjs.map +0 -1
- package/dist/chunk-KNGEIWFR.cjs.map +0 -1
- package/dist/chunk-LXZAXWLO.mjs.map +0 -1
- package/dist/chunk-Q34TMZ5J.mjs.map +0 -1
package/dist/react/index.cjs
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkL273PAD4cjs = require('../chunk-L273PAD4.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkERM4WP6Dcjs = require('../chunk-ERM4WP6D.cjs');
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
@@ -23,7 +23,7 @@ function DimesProvider({ client, children }) {
|
|
|
23
23
|
function useDimesClient() {
|
|
24
24
|
const client = _react.useContext.call(void 0, DimesContext);
|
|
25
25
|
if (!client) {
|
|
26
|
-
throw new (0,
|
|
26
|
+
throw new (0, _chunkERM4WP6Dcjs.DimesError)("missing_provider", "useDimesClient must be used within a <DimesProvider>");
|
|
27
27
|
}
|
|
28
28
|
return client;
|
|
29
29
|
}
|
|
@@ -68,7 +68,7 @@ function useQuote() {
|
|
|
68
68
|
async (params, options) => {
|
|
69
69
|
dispatch({ type: "loading" });
|
|
70
70
|
try {
|
|
71
|
-
const result = await
|
|
71
|
+
const result = await _chunkL273PAD4cjs.executeQuote.call(void 0, client, params, {
|
|
72
72
|
...options,
|
|
73
73
|
onDraftReady: (draft) => {
|
|
74
74
|
dispatch({ type: "draftReady", draft });
|
|
@@ -142,7 +142,7 @@ function useQuoteMachine(options) {
|
|
|
142
142
|
const getDraft = _react.useCallback.call(void 0,
|
|
143
143
|
async (params) => {
|
|
144
144
|
dispatch({ type: "loading" });
|
|
145
|
-
const quoteParams =
|
|
145
|
+
const quoteParams = _chunkL273PAD4cjs.buildQuoteParams.call(void 0, params);
|
|
146
146
|
lastParamsRef.current = quoteParams;
|
|
147
147
|
try {
|
|
148
148
|
const draft = await client.createDraftQuote(quoteParams);
|
|
@@ -155,14 +155,15 @@ function useQuoteMachine(options) {
|
|
|
155
155
|
[client]
|
|
156
156
|
);
|
|
157
157
|
const promote = _react.useCallback.call(void 0,
|
|
158
|
-
async (draft, retryCount = 0) => {
|
|
158
|
+
async (draft, retryCount = 0, riskModeOverride) => {
|
|
159
159
|
const quotedAt = quotedAtRef.current;
|
|
160
160
|
dispatch({ type: "promoting", draft, quotedAt });
|
|
161
161
|
try {
|
|
162
|
-
const
|
|
162
|
+
const riskMode = _nullishCoalesce(riskModeOverride, () => ( _optionalChain([lastParamsRef, 'access', _8 => _8.current, 'optionalAccess', _9 => _9.riskMode])));
|
|
163
|
+
const promotedQuote = await client.promoteDraftQuote(draft.id, riskMode ? { riskMode } : void 0);
|
|
163
164
|
dispatch({ type: "promoted", draft, promotedQuote, quotedAt });
|
|
164
165
|
} catch (err) {
|
|
165
|
-
if (
|
|
166
|
+
if (_chunkL273PAD4cjs.isMarketMovedError.call(void 0, err) && retryCount < maxRetries && lastParamsRef.current) {
|
|
166
167
|
try {
|
|
167
168
|
const newDraft = await client.createDraftQuote(lastParamsRef.current);
|
|
168
169
|
quotedAtRef.current = Date.now();
|
|
@@ -184,8 +185,8 @@ function useQuoteMachine(options) {
|
|
|
184
185
|
[client, maxRetries]
|
|
185
186
|
);
|
|
186
187
|
const acceptChanges = _react.useCallback.call(void 0,
|
|
187
|
-
async (newDraft, retryCount) => {
|
|
188
|
-
await promote(newDraft, retryCount);
|
|
188
|
+
async (newDraft, retryCount, riskMode) => {
|
|
189
|
+
await promote(newDraft, retryCount, riskMode);
|
|
189
190
|
},
|
|
190
191
|
[promote]
|
|
191
192
|
);
|
|
@@ -317,7 +318,7 @@ var DEFAULT_SLOW_POLL_MS = 15e3;
|
|
|
317
318
|
function adaptiveRefetchInterval(adaptive) {
|
|
318
319
|
const fastMs = typeof adaptive === "object" ? _nullishCoalesce(adaptive.fastMs, () => ( DEFAULT_FAST_POLL_MS)) : DEFAULT_FAST_POLL_MS;
|
|
319
320
|
const slowMs = typeof adaptive === "object" ? _nullishCoalesce(adaptive.slowMs, () => ( DEFAULT_SLOW_POLL_MS)) : DEFAULT_SLOW_POLL_MS;
|
|
320
|
-
return (query) => _optionalChain([query, 'access',
|
|
321
|
+
return (query) => _optionalChain([query, 'access', _10 => _10.state, 'access', _11 => _11.data, 'optionalAccess', _12 => _12.some, 'call', _13 => _13((p) => transientPositionStatuses.has(p.status))]) ? fastMs : slowMs;
|
|
321
322
|
}
|
|
322
323
|
function reconcileStructuralSharing(reconcile) {
|
|
323
324
|
const windowMs = typeof reconcile === "number" ? reconcile : defaultReconciliationWindowMs;
|
|
@@ -325,15 +326,15 @@ function reconcileStructuralSharing(reconcile) {
|
|
|
325
326
|
}
|
|
326
327
|
function usePositions(params, queryOptions, options) {
|
|
327
328
|
const client = useDimesClient();
|
|
328
|
-
const queryKey = _optionalChain([options, 'optionalAccess',
|
|
329
|
+
const queryKey = _optionalChain([options, 'optionalAccess', _14 => _14.scope]) !== void 0 ? ["dimes", "positions", params, options.scope] : ["dimes", "positions", params];
|
|
329
330
|
const config = {
|
|
330
331
|
queryKey,
|
|
331
332
|
queryFn: () => client.getPositions(params)
|
|
332
333
|
};
|
|
333
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
334
|
+
if (_optionalChain([options, 'optionalAccess', _15 => _15.adaptivePolling])) {
|
|
334
335
|
config.refetchInterval = adaptiveRefetchInterval(options.adaptivePolling);
|
|
335
336
|
}
|
|
336
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
337
|
+
if (_optionalChain([options, 'optionalAccess', _16 => _16.reconcile])) {
|
|
337
338
|
config.structuralSharing = reconcileStructuralSharing(options.reconcile);
|
|
338
339
|
}
|
|
339
340
|
return _reactquery.useQuery.call(void 0, { ...config, ...queryOptions });
|
|
@@ -395,14 +396,14 @@ function useLimits(queryOptions) {
|
|
|
395
396
|
var HTTP_CONFLICT = 409;
|
|
396
397
|
function useCancelPosition(mutationOptions, options) {
|
|
397
398
|
const client = useDimesClient();
|
|
398
|
-
const treatConflictAsAlreadyCancelling = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
399
|
+
const treatConflictAsAlreadyCancelling = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _17 => _17.treatConflictAsAlreadyCancelling]), () => ( false));
|
|
399
400
|
return _reactquery.useMutation.call(void 0, {
|
|
400
401
|
mutationFn: async (positionId) => {
|
|
401
402
|
try {
|
|
402
403
|
await client.cancelPosition(positionId);
|
|
403
404
|
return "cancelled";
|
|
404
405
|
} catch (err) {
|
|
405
|
-
if (treatConflictAsAlreadyCancelling && err instanceof
|
|
406
|
+
if (treatConflictAsAlreadyCancelling && err instanceof _chunkERM4WP6Dcjs.DimesApiError && err.status === HTTP_CONFLICT) {
|
|
406
407
|
return "already_cancelling";
|
|
407
408
|
}
|
|
408
409
|
throw err;
|
|
@@ -420,10 +421,10 @@ function usePositionStream(options) {
|
|
|
420
421
|
const queryClient = _reactquery.useQueryClient.call(void 0, );
|
|
421
422
|
const socketRef = _react.useRef.call(void 0, null);
|
|
422
423
|
const [connected, setConnected] = _react.useState.call(void 0, false);
|
|
423
|
-
const enabled = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
424
|
-
const mode = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
425
|
-
const pauseOnHidden = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
426
|
-
const invalidateOnReconnect = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
424
|
+
const enabled = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _18 => _18.enabled]), () => ( true));
|
|
425
|
+
const mode = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _19 => _19.mode]), () => ( "reconcile"));
|
|
426
|
+
const pauseOnHidden = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _20 => _20.pauseOnHidden]), () => ( true));
|
|
427
|
+
const invalidateOnReconnect = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _21 => _21.invalidateOnReconnect]), () => ( true));
|
|
427
428
|
const optionsRef = _react.useRef.call(void 0, options);
|
|
428
429
|
optionsRef.current = options;
|
|
429
430
|
_react.useEffect.call(void 0, () => {
|
|
@@ -439,10 +440,10 @@ function usePositionStream(options) {
|
|
|
439
440
|
if (mode === "reconcile") {
|
|
440
441
|
mergePositionEvent(queryClient, event, Date.now());
|
|
441
442
|
}
|
|
442
|
-
_optionalChain([optionsRef, 'access',
|
|
443
|
+
_optionalChain([optionsRef, 'access', _22 => _22.current, 'optionalAccess', _23 => _23.onEvent, 'optionalCall', _24 => _24(event)]);
|
|
443
444
|
});
|
|
444
445
|
const unsubNotification = socket.onNotification((event) => {
|
|
445
|
-
_optionalChain([optionsRef, 'access',
|
|
446
|
+
_optionalChain([optionsRef, 'access', _25 => _25.current, 'optionalAccess', _26 => _26.onNotification, 'optionalCall', _27 => _27(event)]);
|
|
446
447
|
});
|
|
447
448
|
let firstConnect = true;
|
|
448
449
|
const unsubConnect = socket.onConnect(() => {
|
|
@@ -452,14 +453,14 @@ function usePositionStream(options) {
|
|
|
452
453
|
} else if (mode === "reconcile" && invalidateOnReconnect) {
|
|
453
454
|
void queryClient.invalidateQueries({ queryKey: positionsQueryKey });
|
|
454
455
|
}
|
|
455
|
-
_optionalChain([optionsRef, 'access',
|
|
456
|
+
_optionalChain([optionsRef, 'access', _28 => _28.current, 'optionalAccess', _29 => _29.onConnect, 'optionalCall', _30 => _30()]);
|
|
456
457
|
});
|
|
457
458
|
const unsubDisconnect = socket.onDisconnect(() => {
|
|
458
459
|
setConnected(false);
|
|
459
|
-
_optionalChain([optionsRef, 'access',
|
|
460
|
+
_optionalChain([optionsRef, 'access', _31 => _31.current, 'optionalAccess', _32 => _32.onDisconnect, 'optionalCall', _33 => _33()]);
|
|
460
461
|
});
|
|
461
462
|
const unsubError = socket.onError((error) => {
|
|
462
|
-
_optionalChain([optionsRef, 'access',
|
|
463
|
+
_optionalChain([optionsRef, 'access', _34 => _34.current, 'optionalAccess', _35 => _35.onError, 'optionalCall', _36 => _36(error)]);
|
|
463
464
|
});
|
|
464
465
|
const handleVisibility = pauseOnHidden && typeof document !== "undefined" ? () => {
|
|
465
466
|
if (document.hidden) {
|
|
@@ -497,10 +498,10 @@ function useMarketStream(options) {
|
|
|
497
498
|
const queryClient = _reactquery.useQueryClient.call(void 0, );
|
|
498
499
|
const socketRef = _react.useRef.call(void 0, null);
|
|
499
500
|
const [connected, setConnected] = _react.useState.call(void 0, false);
|
|
500
|
-
const enabled = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
501
|
-
const mode = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
502
|
-
const pauseOnHidden = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
503
|
-
const invalidateOnReconnect = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
501
|
+
const enabled = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _37 => _37.enabled]), () => ( true));
|
|
502
|
+
const mode = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _38 => _38.mode]), () => ( "reconcile"));
|
|
503
|
+
const pauseOnHidden = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _39 => _39.pauseOnHidden]), () => ( true));
|
|
504
|
+
const invalidateOnReconnect = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _40 => _40.invalidateOnReconnect]), () => ( true));
|
|
504
505
|
const optionsRef = _react.useRef.call(void 0, options);
|
|
505
506
|
optionsRef.current = options;
|
|
506
507
|
_react.useEffect.call(void 0, () => {
|
|
@@ -516,7 +517,7 @@ function useMarketStream(options) {
|
|
|
516
517
|
if (mode === "reconcile" && event.type !== "market.discovered") {
|
|
517
518
|
mergeMarketDeltas(queryClient, event.data);
|
|
518
519
|
}
|
|
519
|
-
_optionalChain([optionsRef, 'access',
|
|
520
|
+
_optionalChain([optionsRef, 'access', _41 => _41.current, 'optionalAccess', _42 => _42.onEvent, 'optionalCall', _43 => _43(event)]);
|
|
520
521
|
});
|
|
521
522
|
let firstConnect = true;
|
|
522
523
|
const unsubConnect = socket.onConnect(() => {
|
|
@@ -526,14 +527,14 @@ function useMarketStream(options) {
|
|
|
526
527
|
} else if (mode === "reconcile" && invalidateOnReconnect) {
|
|
527
528
|
void queryClient.invalidateQueries({ queryKey: marketsQueryKey });
|
|
528
529
|
}
|
|
529
|
-
_optionalChain([optionsRef, 'access',
|
|
530
|
+
_optionalChain([optionsRef, 'access', _44 => _44.current, 'optionalAccess', _45 => _45.onConnect, 'optionalCall', _46 => _46()]);
|
|
530
531
|
});
|
|
531
532
|
const unsubDisconnect = socket.onDisconnect(() => {
|
|
532
533
|
setConnected(false);
|
|
533
|
-
_optionalChain([optionsRef, 'access',
|
|
534
|
+
_optionalChain([optionsRef, 'access', _47 => _47.current, 'optionalAccess', _48 => _48.onDisconnect, 'optionalCall', _49 => _49()]);
|
|
534
535
|
});
|
|
535
536
|
const unsubError = socket.onError((error) => {
|
|
536
|
-
_optionalChain([optionsRef, 'access',
|
|
537
|
+
_optionalChain([optionsRef, 'access', _50 => _50.current, 'optionalAccess', _51 => _51.onError, 'optionalCall', _52 => _52(error)]);
|
|
537
538
|
});
|
|
538
539
|
const handleVisibility = pauseOnHidden && typeof document !== "undefined" ? () => {
|
|
539
540
|
if (document.hidden) {
|
package/dist/react/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/alexemery/bl/dimes-sdk/dist/react/index.cjs","../../src/react/provider.tsx","../../src/react/use-quote.ts","../../src/react/use-quote-machine.ts","../../src/react/use-markets.ts","../../src/react/use-positions.ts","../../src/react/ws-reconcile.ts","../../src/react/use-contract-info.ts","../../src/react/use-partial-closes.ts","../../src/react/use-limits.ts","../../src/react/use-cancel-position.ts","../../src/react/use-position-stream.ts","../../src/react/use-market-stream.ts"],"names":["reducer","useReducer","useCallback","useQuery","useRef","useQueryClient","useState","useEffect"],"mappings":"AAAA;AACE;AACA;AACA;AACF,yDAA8B;AAC9B;AACE;AACA;AACF,yDAA8B;AAC9B;AACE;AACA;AACF,yDAA8B;AAC9B,iCAA8B;AAC9B;AACA;ACfA,8BAA0D;AAcjD,+CAAA;AATT,IAAM,aAAA,EAAe,kCAAA,IAAsC,CAAA;AAQpD,SAAS,aAAA,CAAc,EAAE,MAAA,EAAQ,SAAS,CAAA,EAAuB;AACtE,EAAA,uBAAO,6BAAA,YAAC,CAAa,QAAA,EAAb,EAAsB,KAAA,EAAO,MAAA,EAAS,SAAA,CAAS,CAAA;AACzD;AAEO,SAAS,cAAA,CAAA,EAA8B;AAC5C,EAAA,MAAM,OAAA,EAAS,+BAAA,YAAuB,CAAA;AACtC,EAAA,GAAA,CAAI,CAAC,MAAA,EAAQ;AACX,IAAA,MAAM,IAAI,iCAAA,CAAW,kBAAA,EAAoB,sDAAsD,CAAA;AAAA,EACjG;AACA,EAAA,OAAO,MAAA;AACT;ADMA;AACA;AE9BA;AA8BA,SAAS,OAAA,CAAQ,KAAA,EAAmB,MAAA,EAA4B;AAC9D,EAAA,OAAA,CAAQ,MAAA,CAAO,IAAA,EAAM;AAAA,IACnB,KAAK,SAAA;AACH,MAAA,OAAO,EAAE,KAAA,EAAO,eAAA,EAAiB,WAAA,EAAa,CAAC,CAAA,EAAG,OAAA,EAAS,EAAE,CAAA;AAAA,IAC/D,KAAK,YAAA;AACH,MAAA,OAAO,EAAE,GAAG,KAAA,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OAAA,EAAS,UAAU,CAAA;AAChD;AZ0bA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,6oBAAC","file":"/Users/alexemery/bl/dimes-sdk/dist/react/index.cjs","sourcesContent":[null,"import { createContext, useContext, type ReactNode } from \"react\";\nimport type { DimesClient } from \"../client/dimes-client\";\nimport { DimesError } from \"../errors/dimes-error\";\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst DimesContext = createContext<DimesClient | null>(null);\n\nexport interface DimesProviderProps {\n client: DimesClient;\n children: ReactNode;\n}\n\n// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/explicit-function-return-type\nexport function DimesProvider({ client, children }: DimesProviderProps) {\n return <DimesContext.Provider value={client}>{children}</DimesContext.Provider>;\n}\n\nexport function useDimesClient(): DimesClient {\n const client = useContext(DimesContext);\n if (!client) {\n throw new DimesError(\"missing_provider\", \"useDimesClient must be used within a <DimesProvider>\");\n }\n return client;\n}\n","import { useCallback, useReducer } from \"react\";\nimport { executeQuote } from \"../quote/quote\";\nimport type { HintAdjustment } from \"../quote/quote-error-hints\";\nimport type { Quote } from \"../types\";\nimport type { QuoteOptions, QuoteParams, QuoteResult } from \"../types/quote\";\nimport { useDimesClient } from \"./provider\";\n\nexport type QuotePhase = \"idle\" | \"loading-draft\" | \"draft-ready\" | \"promoting\" | \"promoted\" | \"market-moved\" | \"error\";\n\nexport interface QuoteState {\n phase: QuotePhase;\n draft?: Quote;\n quote?: Quote;\n /** @deprecated Renamed to {@link QuoteState.quote}. Still populated for backward compatibility. */\n // eslint-disable-next-line no-restricted-syntax -- intentional deprecated alias field\n offer?: Quote;\n corrections: HintAdjustment[];\n retries: number;\n error?: unknown;\n}\n\ntype Action =\n | { type: \"loading\" }\n | { type: \"draftReady\"; draft: Quote }\n | { type: \"promoting\" }\n | { type: \"marketMoved\" }\n | { type: \"done\"; result: QuoteResult }\n | { type: \"error\"; error: unknown }\n | { type: \"reset\" };\n\nfunction reducer(state: QuoteState, action: Action): QuoteState {\n switch (action.type) {\n case \"loading\":\n return { phase: \"loading-draft\", corrections: [], retries: 0 };\n case \"draftReady\":\n return { ...state, phase: \"draft-ready\", draft: action.draft };\n case \"promoting\":\n return { ...state, phase: \"promoting\" };\n case \"marketMoved\":\n return { ...state, phase: \"market-moved\" };\n case \"done\":\n return {\n phase: \"promoted\",\n quote: action.result.quote,\n offer: action.result.quote,\n corrections: action.result.corrections,\n retries: action.result.retries,\n draft: state.draft,\n };\n case \"error\":\n return { ...state, phase: \"error\", error: action.error };\n case \"reset\":\n return { phase: \"idle\", corrections: [], retries: 0 };\n default:\n return state;\n }\n}\n\nexport interface UseQuoteReturn {\n state: QuoteState;\n execute: (params: QuoteParams, options?: QuoteOptions) => Promise<QuoteResult>;\n reset: () => void;\n}\n\nexport function useQuote(): UseQuoteReturn {\n const client = useDimesClient();\n const [state, dispatch] = useReducer(reducer, {\n phase: \"idle\",\n corrections: [],\n retries: 0,\n });\n\n const execute = useCallback(\n async (params: QuoteParams, options?: QuoteOptions): Promise<QuoteResult> => {\n dispatch({ type: \"loading\" });\n\n try {\n const result = await executeQuote(client, params, {\n ...options,\n onDraftReady: (draft) => {\n dispatch({ type: \"draftReady\", draft });\n dispatch({ type: \"promoting\" });\n options?.onDraftReady?.(draft);\n },\n onMarketMoved: (event) => {\n dispatch({ type: \"marketMoved\" });\n return options?.onMarketMoved?.(event);\n },\n onCorrection: (adj) => {\n return options?.onCorrection?.(adj);\n },\n });\n\n dispatch({ type: \"done\", result });\n return result;\n } catch (err) {\n dispatch({ type: \"error\", error: err });\n throw err;\n }\n },\n [client],\n );\n\n const reset = useCallback(() => {\n dispatch({ type: \"reset\" });\n }, []);\n\n return { state, execute, reset };\n}\n","import { useCallback, useReducer, useRef } from \"react\";\nimport { buildQuoteParams } from \"../quote/build-quote-params\";\nimport { isMarketMovedError } from \"../quote/quote\";\nimport type { CreateQuoteParams, Quote } from \"../types\";\nimport type { QuoteParams } from \"../types/quote\";\nimport { useDimesClient } from \"./provider\";\n\nconst DEFAULT_MAX_RETRIES = 3;\n\n/**\n * Interactive, user-in-the-loop quote flow: draft → review → promote, pausing\n * across renders so the UI can show each step. This is the granular companion\n * to `useQuote`/`executeQuote` (which run draft→promote in one call). The steps\n * map directly onto the SDK client (`createDraftQuote`/`promoteDraftQuote`/\n * `createQuote`); on a market-moved promote failure it re-drafts and surfaces a\n * `market-moved` state so the user can review and accept the new draft.\n */\nexport type QuoteMachineState =\n | { phase: \"idle\" }\n | { phase: \"loading-draft\" }\n | { phase: \"draft-ready\"; draft: Quote; quotedAt: number }\n | { phase: \"promoting\"; draft: Quote; quotedAt: number }\n | { phase: \"promoted\"; draft: Quote; promotedQuote: Quote; correctedFrom?: Quote; quotedAt: number }\n | { phase: \"market-moved\"; originalDraft: Quote; newDraft: Quote; retryCount: number; quotedAt: number }\n | { phase: \"error\"; error: unknown; draft?: Quote };\n\ntype Action =\n | { type: \"loading\" }\n | { type: \"draftReady\"; draft: Quote; quotedAt: number }\n | { type: \"promoting\"; draft: Quote; quotedAt: number }\n | { type: \"promoted\"; draft: Quote; promotedQuote: Quote; correctedFrom?: Quote; quotedAt: number }\n | { type: \"marketMoved\"; originalDraft: Quote; newDraft: Quote; retryCount: number; quotedAt: number }\n | { type: \"error\"; error: unknown; draft?: Quote }\n | { type: \"reset\" };\n\nfunction reducer(_state: QuoteMachineState, action: Action): QuoteMachineState {\n switch (action.type) {\n case \"loading\":\n return { phase: \"loading-draft\" };\n case \"draftReady\":\n return { phase: \"draft-ready\", draft: action.draft, quotedAt: action.quotedAt };\n case \"promoting\":\n return { phase: \"promoting\", draft: action.draft, quotedAt: action.quotedAt };\n case \"promoted\":\n return {\n phase: \"promoted\",\n draft: action.draft,\n promotedQuote: action.promotedQuote,\n correctedFrom: action.correctedFrom,\n quotedAt: action.quotedAt,\n };\n case \"marketMoved\":\n return {\n phase: \"market-moved\",\n originalDraft: action.originalDraft,\n newDraft: action.newDraft,\n retryCount: action.retryCount,\n quotedAt: action.quotedAt,\n };\n case \"error\":\n return { phase: \"error\", error: action.error, draft: action.draft };\n case \"reset\":\n return { phase: \"idle\" };\n default:\n return _state;\n }\n}\n\nexport interface UseQuoteMachineOptions {\n /** Maximum number of re-draft attempts on a market-moved promote failure. Default 3. */\n maxRetries?: number;\n}\n\nexport interface UseQuoteMachineReturn {\n state: QuoteMachineState;\n /** Build params from a `QuoteParams` and fetch a draft quote. Moves to `draft-ready`. */\n getDraft: (params: QuoteParams) => Promise<void>;\n /** Promote a reviewed draft into a signed quote. On market-moved, re-drafts and surfaces `market-moved`. */\n promote: (draft: Quote, retryCount?: number) => Promise<void>;\n /** Accept a re-drafted quote after a `market-moved` and promote it. */\n acceptChanges: (newDraft: Quote, retryCount: number) => Promise<void>;\n /** Promote pre-adjusted params directly via `createQuote` (e.g. after applying a correction hint). */\n correctAndPromote: (originalDraft: Quote, adjustedParams: CreateQuoteParams) => Promise<void>;\n reset: () => void;\n}\n\nexport function useQuoteMachine(options?: UseQuoteMachineOptions): UseQuoteMachineReturn {\n const client = useDimesClient();\n const maxRetries = options?.maxRetries ?? DEFAULT_MAX_RETRIES;\n const [state, dispatch] = useReducer(reducer, { phase: \"idle\" } as QuoteMachineState);\n const lastParamsRef = useRef<CreateQuoteParams | null>(null);\n const quotedAtRef = useRef(0);\n\n const getDraft = useCallback(\n async (params: QuoteParams): Promise<void> => {\n dispatch({ type: \"loading\" });\n const quoteParams = buildQuoteParams(params);\n lastParamsRef.current = quoteParams;\n try {\n const draft = await client.createDraftQuote(quoteParams);\n\n quotedAtRef.current = Date.now();\n dispatch({ type: \"draftReady\", draft, quotedAt: quotedAtRef.current });\n } catch (err) {\n dispatch({ type: \"error\", error: err });\n }\n },\n [client],\n );\n\n const promote = useCallback(\n async (draft: Quote, retryCount = 0): Promise<void> => {\n const quotedAt = quotedAtRef.current;\n dispatch({ type: \"promoting\", draft, quotedAt });\n try {\n const promotedQuote = await client.promoteDraftQuote(draft.id);\n dispatch({ type: \"promoted\", draft, promotedQuote, quotedAt });\n } catch (err) {\n if (isMarketMovedError(err) && retryCount < maxRetries && lastParamsRef.current) {\n try {\n const newDraft = await client.createDraftQuote(lastParamsRef.current);\n // eslint-disable-next-line require-atomic-updates -- timestamp ref, no contended state\n quotedAtRef.current = Date.now();\n dispatch({\n type: \"marketMoved\",\n originalDraft: draft,\n newDraft,\n retryCount: retryCount + 1,\n quotedAt: quotedAtRef.current,\n });\n } catch (draftErr) {\n dispatch({ type: \"error\", error: draftErr, draft });\n }\n } else {\n dispatch({ type: \"error\", error: err, draft });\n }\n }\n },\n [client, maxRetries],\n );\n\n const acceptChanges = useCallback(\n async (newDraft: Quote, retryCount: number): Promise<void> => {\n await promote(newDraft, retryCount);\n },\n [promote],\n );\n\n const correctAndPromote = useCallback(\n async (originalDraft: Quote, adjustedParams: CreateQuoteParams): Promise<void> => {\n dispatch({ type: \"promoting\", draft: originalDraft, quotedAt: quotedAtRef.current });\n lastParamsRef.current = adjustedParams;\n try {\n const promotedQuote = await client.createQuote(adjustedParams);\n // eslint-disable-next-line require-atomic-updates -- timestamp ref, no contended state\n quotedAtRef.current = Date.now();\n dispatch({\n type: \"promoted\",\n draft: promotedQuote,\n promotedQuote,\n correctedFrom: originalDraft,\n quotedAt: quotedAtRef.current,\n });\n } catch (err) {\n dispatch({ type: \"error\", error: err });\n }\n },\n [client],\n );\n\n const reset = useCallback((): void => {\n dispatch({ type: \"reset\" });\n lastParamsRef.current = null;\n quotedAtRef.current = 0;\n }, []);\n\n return { state, getDraft, promote, acceptChanges, correctAndPromote, reset };\n}\n","import { useQuery, type UseQueryOptions, type UseQueryResult } from \"@tanstack/react-query\";\n// eslint-disable-next-line import-x/no-deprecated -- SearchMarketsParams imported for the deprecated shim below\nimport type { GetMarketsParams, SearchMarketsParams } from \"../client/dimes-client\";\nimport type { Market, Paginated } from \"../types\";\nimport { useDimesClient } from \"./provider\";\n\nexport function useMarkets(\n params?: GetMarketsParams,\n queryOptions?: Partial<UseQueryOptions<Paginated<Market>>>,\n): UseQueryResult<Paginated<Market>> {\n const client = useDimesClient();\n\n return useQuery({\n queryKey: [\"dimes\", \"markets\", params],\n queryFn: () => client.getMarkets(params),\n ...queryOptions,\n });\n}\n\n/**\n * @deprecated Use {@link useMarkets} with a `query` param: `useMarkets({ query })`.\n * Search is now served by `GET /markets?query=` instead of the deprecated `/markets/search` path.\n */\nexport function useSearchMarkets(\n // eslint-disable-next-line @typescript-eslint/no-deprecated, import-x/no-deprecated -- this IS the deprecated hook\n params: SearchMarketsParams,\n queryOptions?: Partial<UseQueryOptions<Paginated<Market>>>,\n): UseQueryResult<Paginated<Market>> {\n const client = useDimesClient();\n\n return useQuery({\n queryKey: [\"dimes\", \"markets\", \"search\", params],\n queryFn: () => client.getMarkets(params),\n enabled: !!params.query,\n ...queryOptions,\n });\n}\n\nexport function useMarket(ticker: string, queryOptions?: Partial<UseQueryOptions<Market>>): UseQueryResult<Market> {\n const client = useDimesClient();\n\n return useQuery({\n queryKey: [\"dimes\", \"market\", ticker],\n queryFn: () => client.getMarket(ticker),\n enabled: !!ticker,\n ...queryOptions,\n });\n}\n","import { useQuery, type Query, type UseQueryOptions, type UseQueryResult } from \"@tanstack/react-query\";\nimport type { GetPositionsParams } from \"../client/dimes-client\";\nimport type { Position } from \"../types\";\nimport { useDimesClient } from \"./provider\";\nimport { defaultReconciliationWindowMs, reconcilePolledPositions, transientPositionStatuses } from \"./ws-reconcile\";\n\nconst DEFAULT_FAST_POLL_MS = 5_000;\nconst DEFAULT_SLOW_POLL_MS = 15_000;\n\nexport interface UsePositionsOptions {\n /**\n * Appended to the query key so changing scope (e.g. switching wallet) does not serve the previous\n * scope's cached positions until a refetch. Omit to keep the default, scope-less cache key.\n */\n scope?: string | null;\n /**\n * Poll faster while any position is in a transient state (pending/closing/settling/unwinding) and\n * slower otherwise. Pass `true` for the defaults (5s / 15s) or an object to tune them.\n */\n adaptivePolling?: boolean | { fastMs?: number; slowMs?: number };\n /**\n * Defer to fresher WebSocket data: when a position was updated over the socket within the\n * reconciliation window, a slower REST poll won't overwrite it. Use with `usePositionStream` in\n * reconcile mode. Pass `true` for the default window or a number of milliseconds.\n */\n reconcile?: boolean | number;\n}\n\nfunction adaptiveRefetchInterval(\n adaptive: NonNullable<UsePositionsOptions[\"adaptivePolling\"]>,\n): (query: Query<Position[]>) => number {\n const fastMs = typeof adaptive === \"object\" ? (adaptive.fastMs ?? DEFAULT_FAST_POLL_MS) : DEFAULT_FAST_POLL_MS;\n const slowMs = typeof adaptive === \"object\" ? (adaptive.slowMs ?? DEFAULT_SLOW_POLL_MS) : DEFAULT_SLOW_POLL_MS;\n return (query) => (query.state.data?.some((p) => transientPositionStatuses.has(p.status)) ? fastMs : slowMs);\n}\n\nfunction reconcileStructuralSharing(reconcile: number | true): (oldData: unknown, newData: unknown) => Position[] {\n const windowMs = typeof reconcile === \"number\" ? reconcile : defaultReconciliationWindowMs;\n return (oldData, newData) =>\n reconcilePolledPositions(oldData as Position[] | undefined, newData as Position[], windowMs, Date.now());\n}\n\nexport function usePositions(\n params?: GetPositionsParams,\n queryOptions?: Partial<UseQueryOptions<Position[]>>,\n options?: UsePositionsOptions,\n): UseQueryResult<Position[]> {\n const client = useDimesClient();\n\n const queryKey =\n options?.scope !== undefined ? [\"dimes\", \"positions\", params, options.scope] : [\"dimes\", \"positions\", params];\n\n const config: UseQueryOptions<Position[]> = {\n queryKey,\n queryFn: () => client.getPositions(params),\n };\n\n if (options?.adaptivePolling) {\n config.refetchInterval = adaptiveRefetchInterval(options.adaptivePolling);\n }\n\n if (options?.reconcile) {\n config.structuralSharing = reconcileStructuralSharing(options.reconcile);\n }\n\n return useQuery({ ...config, ...queryOptions });\n}\n","import type { QueryClient } from \"@tanstack/react-query\";\nimport type { Market, Paginated, Position } from \"../types\";\nimport type { MarketDelta, PositionEvent } from \"../ws\";\n\n/**\n * Shared plumbing for merging WebSocket events into the React Query cache. Used by the optional\n * reconcile mode of `usePositionStream` / `useMarketStream` and the `reconcile` option on\n * `usePositions`. Kept internal so the query keys and the WS-timestamp registry stay in sync.\n */\n\nexport const positionsQueryKey = [\"dimes\", \"positions\"] as const;\n\nexport const marketsQueryKey = [\"dimes\", \"markets\"] as const;\n\nexport const defaultReconciliationWindowMs = 12_000;\n\n/** Position statuses that indicate an in-flight transition — polled faster by `adaptivePolling`. */\nexport const transientPositionStatuses: ReadonlySet<string> = new Set([\"pending\", \"closing\", \"settling\", \"unwinding\"]);\n\n/**\n * Records the last time each position id was written from a WebSocket event. Polling reconciliation\n * uses this so a slower REST poll never clobbers fresher WS data inside the reconciliation window.\n */\nexport const wsPositionTimestamps = new Map<string, number>();\n\n/** Merge a single position event into every cached positions query. */\nexport function mergePositionEvent(queryClient: QueryClient, event: PositionEvent, now: number): void {\n const position = event.data;\n queryClient.setQueriesData<Position[]>({ queryKey: positionsQueryKey }, (old) => {\n if (!old) {\n return old;\n }\n const idx = old.findIndex((p) => p.id === position.id);\n if (idx >= 0) {\n const next = [...old];\n next[idx] = position;\n return next;\n }\n if (event.type === \"position.created\") {\n return [position, ...old];\n }\n return old;\n });\n wsPositionTimestamps.set(position.id, now);\n}\n\n/**\n * `structuralSharing` for a polled positions list: keep the cached (WS-fresher) copy of any position\n * updated over the socket within `windowMs`, otherwise accept the polled copy.\n */\nexport function reconcilePolledPositions(\n oldData: Position[] | undefined,\n newData: Position[],\n windowMs: number,\n now: number,\n): Position[] {\n if (!oldData) {\n return newData;\n }\n return newData.map((polled) => {\n const wsTime = wsPositionTimestamps.get(polled.id);\n if (wsTime !== undefined && now - wsTime < windowMs) {\n const fresher = oldData.find((p) => p.id === polled.id);\n return fresher ?? polled;\n }\n if (wsTime !== undefined) {\n wsPositionTimestamps.delete(polled.id);\n }\n return polled;\n });\n}\n\n/**\n * Deep-merge a market delta onto a cached market. The nested `leverage` block must be merged rather\n * than replaced — a max-leverage delta carries only the changed leverage fields, so a shallow spread\n * would drop the constant `minBps`/`stepBps` until the next full refetch.\n */\nfunction mergeMarket(prev: Market, delta: MarketDelta): Market {\n return {\n ...prev,\n ...delta,\n leverage: delta.leverage ? { ...prev.leverage, ...delta.leverage } : prev.leverage,\n };\n}\n\n/** Merge market deltas into every cached paginated markets query (no-op for ids not present). */\nexport function mergeMarketDeltas(queryClient: QueryClient, deltas: MarketDelta[]): void {\n queryClient.setQueriesData<Paginated<Market>>({ queryKey: marketsQueryKey }, (old) => {\n if (!old) {\n return old;\n }\n const data = old.data.map((market) => {\n const delta = deltas.find((d) => d.id === market.id);\n return delta ? mergeMarket(market, delta) : market;\n });\n const changed = data.some((market, i) => market !== old.data[i]);\n return changed ? { ...old, data } : old;\n });\n}\n","import { useQuery, type UseQueryOptions, type UseQueryResult } from \"@tanstack/react-query\";\nimport type { ContractInfo } from \"../types\";\nimport { useDimesClient } from \"./provider\";\n\nexport function useContractInfo(queryOptions?: Partial<UseQueryOptions<ContractInfo>>): UseQueryResult<ContractInfo> {\n const client = useDimesClient();\n\n return useQuery({\n queryKey: [\"dimes\", \"contractInfo\"],\n queryFn: () => client.getContractInfo(),\n staleTime: Infinity,\n ...queryOptions,\n });\n}\n","import { useQuery, type UseQueryOptions, type UseQueryResult } from \"@tanstack/react-query\";\nimport type { PositionPartialCloseList } from \"../types\";\nimport { useDimesClient } from \"./provider\";\n\nexport function usePositionPartialCloses(\n positionId: string | null | undefined,\n queryOptions?: Partial<UseQueryOptions<PositionPartialCloseList>>,\n): UseQueryResult<PositionPartialCloseList> {\n const client = useDimesClient();\n\n return useQuery({\n queryKey: [\"dimes\", \"positionPartialCloses\", positionId],\n queryFn: () => {\n if (positionId == null) {\n return Promise.reject(new Error(\"positionId is required\"));\n }\n return client.getPositionPartialCloses(positionId);\n },\n enabled: Boolean(positionId),\n ...queryOptions,\n });\n}\n","import { useQuery, type UseQueryOptions, type UseQueryResult } from \"@tanstack/react-query\";\nimport type { CustomerLimit } from \"../types\";\nimport { useDimesClient } from \"./provider\";\n\n/** User trading limits (JWT auth) — `GET /user-limits`. */\nexport function useUserLimits(queryOptions?: Partial<UseQueryOptions<CustomerLimit>>): UseQueryResult<CustomerLimit> {\n const client = useDimesClient();\n\n return useQuery({\n queryKey: [\"dimes\", \"user-limits\"],\n queryFn: () => client.getUserLimits(),\n ...queryOptions,\n });\n}\n\n/** Partner-wide limits (API-key auth) — `GET /partner-limits`. */\nexport function usePartnerLimits(\n queryOptions?: Partial<UseQueryOptions<CustomerLimit>>,\n): UseQueryResult<CustomerLimit> {\n const client = useDimesClient();\n\n return useQuery({\n queryKey: [\"dimes\", \"partner-limits\"],\n queryFn: () => client.getPartnerLimits(),\n ...queryOptions,\n });\n}\n\n/** @deprecated Use {@link useUserLimits}. Alias kept for back-compat; resolves to user limits. */\nexport function useLimits(queryOptions?: Partial<UseQueryOptions<CustomerLimit>>): UseQueryResult<CustomerLimit> {\n return useUserLimits(queryOptions);\n}\n","import { useMutation, type UseMutationOptions, type UseMutationResult } from \"@tanstack/react-query\";\nimport { DimesApiError } from \"../errors/dimes-error\";\nimport { useDimesClient } from \"./provider\";\n\nconst HTTP_CONFLICT = 409;\n\nexport type CancelPositionResult = \"cancelled\" | \"already_cancelling\";\n\nexport interface UseCancelPositionOptions {\n /**\n * Treat a 409 Conflict (the position is already being cancelled) as success, resolving to\n * `\"already_cancelling\"` instead of throwing. Default false — a 409 rejects like any other error.\n */\n treatConflictAsAlreadyCancelling?: boolean;\n}\n\nexport function useCancelPosition(\n mutationOptions?: Partial<UseMutationOptions<CancelPositionResult, Error, string>>,\n options?: UseCancelPositionOptions,\n): UseMutationResult<CancelPositionResult, Error, string> {\n const client = useDimesClient();\n const treatConflictAsAlreadyCancelling = options?.treatConflictAsAlreadyCancelling ?? false;\n\n return useMutation({\n mutationFn: async (positionId: string): Promise<CancelPositionResult> => {\n try {\n await client.cancelPosition(positionId);\n return \"cancelled\";\n } catch (err) {\n if (treatConflictAsAlreadyCancelling && err instanceof DimesApiError && err.status === HTTP_CONFLICT) {\n return \"already_cancelling\";\n }\n throw err;\n }\n },\n ...mutationOptions,\n });\n}\n","import { useQueryClient } from \"@tanstack/react-query\";\nimport { useEffect, useRef, useState } from \"react\";\nimport { PositionSocket, type NotificationEvent, type PositionEvent } from \"../ws\";\nimport { useDimesClient } from \"./provider\";\nimport { mergePositionEvent, positionsQueryKey } from \"./ws-reconcile\";\n\nexport type StreamMode = \"raw\" | \"reconcile\";\n\nexport interface UsePositionStreamOptions {\n /** Connect the socket. Default true. Set false to gate on auth being ready. */\n enabled?: boolean;\n /**\n * `\"reconcile\"` (default) merges every event into the `usePositions` query cache so the UI updates\n * instantly; `\"raw\"` does not touch the cache and only forwards events to your callbacks.\n */\n mode?: StreamMode;\n /** Disconnect while the tab is hidden and reconnect when it becomes visible again. Default true. */\n pauseOnHidden?: boolean;\n /** Invalidate the positions query on reconnect (skipping the first connect) to catch missed events. Default true. */\n invalidateOnReconnect?: boolean;\n /** Always called with the raw (camelCased) event, in both modes. */\n onEvent?: (event: PositionEvent) => void;\n /** Called with user-gateway notification events (toasts, fill progress…). Never touches the cache. */\n onNotification?: (event: NotificationEvent) => void;\n onConnect?: () => void;\n onDisconnect?: () => void;\n onError?: (error: unknown) => void;\n}\n\nexport interface UsePositionStreamResult {\n socket: PositionSocket | null;\n connected: boolean;\n}\n\n/**\n * Subscribe to the user position WebSocket gateway. In `reconcile` mode (default) events are merged\n * into the React Query cache used by `usePositions`; in `raw` mode you handle events yourself via\n * `onEvent`. App-specific side effects (toasts, stores) belong in the callbacks, not the SDK.\n */\nexport function usePositionStream(options?: UsePositionStreamOptions): UsePositionStreamResult {\n const client = useDimesClient();\n const queryClient = useQueryClient();\n const socketRef = useRef<PositionSocket | null>(null);\n const [connected, setConnected] = useState(false);\n\n const enabled = options?.enabled ?? true;\n const mode = options?.mode ?? \"reconcile\";\n const pauseOnHidden = options?.pauseOnHidden ?? true;\n const invalidateOnReconnect = options?.invalidateOnReconnect ?? true;\n\n // Keep the latest callbacks/flags in a ref so the socket effect does not reconnect on every render.\n const optionsRef = useRef(options);\n optionsRef.current = options;\n\n useEffect(() => {\n if (!enabled) {\n return undefined;\n }\n\n const socket = new PositionSocket({\n baseUrl: client.baseUrl,\n getToken: (): string | null => client.getToken(),\n });\n socketRef.current = socket;\n\n const unsubEvent = socket.on(\"*\", (event) => {\n if (mode === \"reconcile\") {\n mergePositionEvent(queryClient, event, Date.now());\n }\n optionsRef.current?.onEvent?.(event);\n });\n\n const unsubNotification = socket.onNotification((event) => {\n optionsRef.current?.onNotification?.(event);\n });\n\n let firstConnect = true;\n const unsubConnect = socket.onConnect(() => {\n setConnected(true);\n if (firstConnect) {\n firstConnect = false;\n } else if (mode === \"reconcile\" && invalidateOnReconnect) {\n void queryClient.invalidateQueries({ queryKey: positionsQueryKey });\n }\n optionsRef.current?.onConnect?.();\n });\n\n const unsubDisconnect = socket.onDisconnect(() => {\n setConnected(false);\n optionsRef.current?.onDisconnect?.();\n });\n\n const unsubError = socket.onError((error) => {\n optionsRef.current?.onError?.(error);\n });\n\n const handleVisibility =\n pauseOnHidden && typeof document !== \"undefined\"\n ? (): void => {\n if (document.hidden) {\n socket.disconnect();\n } else {\n socket.connect();\n }\n }\n : null;\n if (handleVisibility) {\n document.addEventListener(\"visibilitychange\", handleVisibility);\n }\n\n socket.connect();\n\n return (): void => {\n if (handleVisibility) {\n document.removeEventListener(\"visibilitychange\", handleVisibility);\n }\n unsubEvent();\n unsubNotification();\n unsubConnect();\n unsubDisconnect();\n unsubError();\n socket.disconnect();\n socketRef.current = null;\n setConnected(false);\n };\n }, [client, queryClient, enabled, mode, pauseOnHidden, invalidateOnReconnect]);\n\n return { socket: socketRef.current, connected };\n}\n","import { useQueryClient } from \"@tanstack/react-query\";\nimport { useEffect, useRef, useState } from \"react\";\nimport { MarketSocket, type MarketDelta, type MarketEvent } from \"../ws\";\nimport { useDimesClient } from \"./provider\";\nimport type { StreamMode } from \"./use-position-stream\";\nimport { marketsQueryKey, mergeMarketDeltas } from \"./ws-reconcile\";\n\nexport interface UseMarketStreamOptions {\n /** Connect the socket. Default true. */\n enabled?: boolean;\n /**\n * `\"reconcile\"` (default) merges `eligibility_changed` / `max_leverage_changed` deltas into the\n * `useMarkets` query cache; `\"raw\"` only forwards events. `market.discovered` events are never\n * injected into the paginated cache (that would pollute server-filtered views) — handle them via\n * `onEvent` in either mode.\n */\n mode?: StreamMode;\n /** Disconnect while the tab is hidden and reconnect when visible again. Default true. */\n pauseOnHidden?: boolean;\n /** Invalidate the markets query on reconnect (skipping the first connect). Default true. */\n invalidateOnReconnect?: boolean;\n /** Always called with the raw (camelCased) event, in both modes. */\n onEvent?: (event: MarketEvent) => void;\n onConnect?: () => void;\n onDisconnect?: () => void;\n onError?: (error: unknown) => void;\n}\n\nexport interface UseMarketStreamResult {\n socket: MarketSocket | null;\n connected: boolean;\n}\n\n/**\n * Subscribe to the user market WebSocket gateway. In `reconcile` mode (default) eligibility and\n * max-leverage deltas are deep-merged into the `useMarkets` cache; discovered markets are forwarded\n * to `onEvent` for the app to route (e.g. a \"new markets\" strip).\n */\nexport function useMarketStream(options?: UseMarketStreamOptions): UseMarketStreamResult {\n const client = useDimesClient();\n const queryClient = useQueryClient();\n const socketRef = useRef<MarketSocket | null>(null);\n const [connected, setConnected] = useState(false);\n\n const enabled = options?.enabled ?? true;\n const mode = options?.mode ?? \"reconcile\";\n const pauseOnHidden = options?.pauseOnHidden ?? true;\n const invalidateOnReconnect = options?.invalidateOnReconnect ?? true;\n\n const optionsRef = useRef(options);\n optionsRef.current = options;\n\n useEffect(() => {\n if (!enabled) {\n return undefined;\n }\n\n const socket = new MarketSocket({\n baseUrl: client.baseUrl,\n getToken: (): string | null => client.getToken(),\n });\n socketRef.current = socket;\n\n const unsubEvent = socket.on(\"*\", (event) => {\n if (mode === \"reconcile\" && event.type !== \"market.discovered\") {\n mergeMarketDeltas(queryClient, event.data as MarketDelta[]);\n }\n optionsRef.current?.onEvent?.(event);\n });\n\n let firstConnect = true;\n const unsubConnect = socket.onConnect(() => {\n setConnected(true);\n if (firstConnect) {\n firstConnect = false;\n } else if (mode === \"reconcile\" && invalidateOnReconnect) {\n void queryClient.invalidateQueries({ queryKey: marketsQueryKey });\n }\n optionsRef.current?.onConnect?.();\n });\n\n const unsubDisconnect = socket.onDisconnect(() => {\n setConnected(false);\n optionsRef.current?.onDisconnect?.();\n });\n\n const unsubError = socket.onError((error) => {\n optionsRef.current?.onError?.(error);\n });\n\n const handleVisibility =\n pauseOnHidden && typeof document !== \"undefined\"\n ? (): void => {\n if (document.hidden) {\n socket.disconnect();\n } else {\n socket.connect();\n }\n }\n : null;\n if (handleVisibility) {\n document.addEventListener(\"visibilitychange\", handleVisibility);\n }\n\n socket.connect();\n\n return (): void => {\n if (handleVisibility) {\n document.removeEventListener(\"visibilitychange\", handleVisibility);\n }\n unsubEvent();\n unsubConnect();\n unsubDisconnect();\n unsubError();\n socket.disconnect();\n socketRef.current = null;\n setConnected(false);\n };\n }, [client, queryClient, enabled, mode, pauseOnHidden, invalidateOnReconnect]);\n\n return { socket: socketRef.current, connected };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/Users/alexemery/bl/dimes-sdk/dist/react/index.cjs","../../src/react/provider.tsx","../../src/react/use-quote.ts","../../src/react/use-quote-machine.ts","../../src/react/use-markets.ts","../../src/react/use-positions.ts","../../src/react/ws-reconcile.ts","../../src/react/use-contract-info.ts","../../src/react/use-partial-closes.ts","../../src/react/use-limits.ts","../../src/react/use-cancel-position.ts","../../src/react/use-position-stream.ts","../../src/react/use-market-stream.ts"],"names":["reducer","useReducer","useCallback","useQuery","useRef","useQueryClient","useState","useEffect"],"mappings":"AAAA;AACE;AACA;AACA;AACF,yDAA8B;AAC9B;AACE;AACA;AACF,yDAA8B;AAC9B;AACE;AACA;AACF,yDAA8B;AAC9B,iCAA8B;AAC9B;AACA;ACfA,8BAA0D;AAcjD,+CAAA;AATT,IAAM,aAAA,EAAe,kCAAA,IAAsC,CAAA;AAQpD,SAAS,aAAA,CAAc,EAAE,MAAA,EAAQ,SAAS,CAAA,EAAuB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A,KAAO;AACL,QAAA,MAAA,CAAO,OAAA,CAAQ,CAAA;AAAA,MACjB;AAAA,IACF,EAAA,EACA,IAAA;AACN,IAAA,GAAA,CAAI,gBAAA,EAAkB;AACpB,MAAA,QAAA,CAAS,gBAAA,CAAiB,kBAAA,EAAoB,gBAAgB,CAAA;AAAA,IAChE;AAEA,IAAA,MAAA,CAAO,OAAA,CAAQ,CAAA;AAEf,IAAA,OAAO,CAAA,EAAA,GAAY;AACjB,MAAA,GAAA,CAAI,gBAAA,EAAkB;AACpB,QAAA,QAAA,CAAS,mBAAA,CAAoB,kBAAA,EAAoB,gBAAgB,CAAA;AAAA,MACnE;AACA,MAAA,UAAA,CAAW,CAAA;AACX,MAAA,YAAA,CAAa,CAAA;AACb,MAAA,eAAA,CAAgB,CAAA;AAChB,MAAA,UAAA,CAAW,CAAA;AACX,MAAA,MAAA,CAAO,UAAA,CAAW,CAAA;AAClB,MAAA,SAAA,CAAU,QAAA,EAAU,IAAA;AACpB,MAAA,YAAA,CAAa,KAAK,CAAA;AAAA,IACpB,CAAA;AAAA,EACF,CAAA,EAAG,CAAC,MAAA,EAAQ,WAAA,EAAa,OAAA,EAAS,IAAA,EAAM,aAAA,EAAe,qBAAqB,CAAC,CAAA;AAE7E,EAAA,OAAO,EAAE,MAAA,EAAQ,SAAA,CAAU,OAAA,EAAS,UAAU,CAAA;AAChD;AZ2bA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,6oBAAC","file":"/Users/alexemery/bl/dimes-sdk/dist/react/index.cjs","sourcesContent":[null,"import { createContext, useContext, type ReactNode } from \"react\";\nimport type { DimesClient } from \"../client/dimes-client\";\nimport { DimesError } from \"../errors/dimes-error\";\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst DimesContext = createContext<DimesClient | null>(null);\n\nexport interface DimesProviderProps {\n client: DimesClient;\n children: ReactNode;\n}\n\n// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/explicit-function-return-type\nexport function DimesProvider({ client, children }: DimesProviderProps) {\n return <DimesContext.Provider value={client}>{children}</DimesContext.Provider>;\n}\n\nexport function useDimesClient(): DimesClient {\n const client = useContext(DimesContext);\n if (!client) {\n throw new DimesError(\"missing_provider\", \"useDimesClient must be used within a <DimesProvider>\");\n }\n return client;\n}\n","import { useCallback, useReducer } from \"react\";\nimport { executeQuote } from \"../quote/quote\";\nimport type { HintAdjustment } from \"../quote/quote-error-hints\";\nimport type { Quote } from \"../types\";\nimport type { QuoteOptions, QuoteParams, QuoteResult } from \"../types/quote\";\nimport { useDimesClient } from \"./provider\";\n\nexport type QuotePhase = \"idle\" | \"loading-draft\" | \"draft-ready\" | \"promoting\" | \"promoted\" | \"market-moved\" | \"error\";\n\nexport interface QuoteState {\n phase: QuotePhase;\n draft?: Quote;\n quote?: Quote;\n /** @deprecated Renamed to {@link QuoteState.quote}. Still populated for backward compatibility. */\n // eslint-disable-next-line no-restricted-syntax -- intentional deprecated alias field\n offer?: Quote;\n corrections: HintAdjustment[];\n retries: number;\n error?: unknown;\n}\n\ntype Action =\n | { type: \"loading\" }\n | { type: \"draftReady\"; draft: Quote }\n | { type: \"promoting\" }\n | { type: \"marketMoved\" }\n | { type: \"done\"; result: QuoteResult }\n | { type: \"error\"; error: unknown }\n | { type: \"reset\" };\n\nfunction reducer(state: QuoteState, action: Action): QuoteState {\n switch (action.type) {\n case \"loading\":\n return { phase: \"loading-draft\", corrections: [], retries: 0 };\n case \"draftReady\":\n return { ...state, phase: \"draft-ready\", draft: action.draft };\n case \"promoting\":\n return { ...state, phase: \"promoting\" };\n case \"marketMoved\":\n return { ...state, phase: \"market-moved\" };\n case \"done\":\n return {\n phase: \"promoted\",\n quote: action.result.quote,\n offer: action.result.quote,\n corrections: action.result.corrections,\n retries: action.result.retries,\n draft: state.draft,\n };\n case \"error\":\n return { ...state, phase: \"error\", error: action.error };\n case \"reset\":\n return { phase: \"idle\", corrections: [], retries: 0 };\n default:\n return state;\n }\n}\n\nexport interface UseQuoteReturn {\n state: QuoteState;\n execute: (params: QuoteParams, options?: QuoteOptions) => Promise<QuoteResult>;\n reset: () => void;\n}\n\nexport function useQuote(): UseQuoteReturn {\n const client = useDimesClient();\n const [state, dispatch] = useReducer(reducer, {\n phase: \"idle\",\n corrections: [],\n retries: 0,\n });\n\n const execute = useCallback(\n async (params: QuoteParams, options?: QuoteOptions): Promise<QuoteResult> => {\n dispatch({ type: \"loading\" });\n\n try {\n const result = await executeQuote(client, params, {\n ...options,\n onDraftReady: (draft) => {\n dispatch({ type: \"draftReady\", draft });\n dispatch({ type: \"promoting\" });\n options?.onDraftReady?.(draft);\n },\n onMarketMoved: (event) => {\n dispatch({ type: \"marketMoved\" });\n return options?.onMarketMoved?.(event);\n },\n onCorrection: (adj) => {\n return options?.onCorrection?.(adj);\n },\n });\n\n dispatch({ type: \"done\", result });\n return result;\n } catch (err) {\n dispatch({ type: \"error\", error: err });\n throw err;\n }\n },\n [client],\n );\n\n const reset = useCallback(() => {\n dispatch({ type: \"reset\" });\n }, []);\n\n return { state, execute, reset };\n}\n","import { useCallback, useReducer, useRef } from \"react\";\nimport { buildQuoteParams } from \"../quote/build-quote-params\";\nimport { isMarketMovedError } from \"../quote/quote\";\nimport type { CreateQuoteParams, Quote, RiskMode } from \"../types\";\nimport type { QuoteParams } from \"../types/quote\";\nimport { useDimesClient } from \"./provider\";\n\nconst DEFAULT_MAX_RETRIES = 3;\n\n/**\n * Interactive, user-in-the-loop quote flow: draft → review → promote, pausing\n * across renders so the UI can show each step. This is the granular companion\n * to `useQuote`/`executeQuote` (which run draft→promote in one call). The steps\n * map directly onto the SDK client (`createDraftQuote`/`promoteDraftQuote`/\n * `createQuote`); on a market-moved promote failure it re-drafts and surfaces a\n * `market-moved` state so the user can review and accept the new draft.\n */\nexport type QuoteMachineState =\n | { phase: \"idle\" }\n | { phase: \"loading-draft\" }\n | { phase: \"draft-ready\"; draft: Quote; quotedAt: number }\n | { phase: \"promoting\"; draft: Quote; quotedAt: number }\n | { phase: \"promoted\"; draft: Quote; promotedQuote: Quote; correctedFrom?: Quote; quotedAt: number }\n | { phase: \"market-moved\"; originalDraft: Quote; newDraft: Quote; retryCount: number; quotedAt: number }\n | { phase: \"error\"; error: unknown; draft?: Quote };\n\ntype Action =\n | { type: \"loading\" }\n | { type: \"draftReady\"; draft: Quote; quotedAt: number }\n | { type: \"promoting\"; draft: Quote; quotedAt: number }\n | { type: \"promoted\"; draft: Quote; promotedQuote: Quote; correctedFrom?: Quote; quotedAt: number }\n | { type: \"marketMoved\"; originalDraft: Quote; newDraft: Quote; retryCount: number; quotedAt: number }\n | { type: \"error\"; error: unknown; draft?: Quote }\n | { type: \"reset\" };\n\nfunction reducer(_state: QuoteMachineState, action: Action): QuoteMachineState {\n switch (action.type) {\n case \"loading\":\n return { phase: \"loading-draft\" };\n case \"draftReady\":\n return { phase: \"draft-ready\", draft: action.draft, quotedAt: action.quotedAt };\n case \"promoting\":\n return { phase: \"promoting\", draft: action.draft, quotedAt: action.quotedAt };\n case \"promoted\":\n return {\n phase: \"promoted\",\n draft: action.draft,\n promotedQuote: action.promotedQuote,\n correctedFrom: action.correctedFrom,\n quotedAt: action.quotedAt,\n };\n case \"marketMoved\":\n return {\n phase: \"market-moved\",\n originalDraft: action.originalDraft,\n newDraft: action.newDraft,\n retryCount: action.retryCount,\n quotedAt: action.quotedAt,\n };\n case \"error\":\n return { phase: \"error\", error: action.error, draft: action.draft };\n case \"reset\":\n return { phase: \"idle\" };\n default:\n return _state;\n }\n}\n\nexport interface UseQuoteMachineOptions {\n /** Maximum number of re-draft attempts on a market-moved promote failure. Default 3. */\n maxRetries?: number;\n}\n\nexport interface UseQuoteMachineReturn {\n state: QuoteMachineState;\n /** Build params from a `QuoteParams` and fetch a draft quote. Moves to `draft-ready`. */\n getDraft: (params: QuoteParams) => Promise<void>;\n /**\n * Promote a reviewed draft into a signed quote, in `riskMode` if given — a draft is always drawn\n * up as adaptive, so this is where a mode the user picked after seeing the draft is applied.\n * On market-moved, re-drafts and surfaces `market-moved`.\n */\n promote: (draft: Quote, retryCount?: number, riskMode?: RiskMode) => Promise<void>;\n /** Accept a re-drafted quote after a `market-moved` and promote it, in `riskMode` if given. */\n acceptChanges: (newDraft: Quote, retryCount: number, riskMode?: RiskMode) => Promise<void>;\n /** Promote pre-adjusted params directly via `createQuote` (e.g. after applying a correction hint). */\n correctAndPromote: (originalDraft: Quote, adjustedParams: CreateQuoteParams) => Promise<void>;\n reset: () => void;\n}\n\nexport function useQuoteMachine(options?: UseQuoteMachineOptions): UseQuoteMachineReturn {\n const client = useDimesClient();\n const maxRetries = options?.maxRetries ?? DEFAULT_MAX_RETRIES;\n const [state, dispatch] = useReducer(reducer, { phase: \"idle\" } as QuoteMachineState);\n const lastParamsRef = useRef<CreateQuoteParams | null>(null);\n const quotedAtRef = useRef(0);\n\n const getDraft = useCallback(\n async (params: QuoteParams): Promise<void> => {\n dispatch({ type: \"loading\" });\n const quoteParams = buildQuoteParams(params);\n lastParamsRef.current = quoteParams;\n try {\n const draft = await client.createDraftQuote(quoteParams);\n\n quotedAtRef.current = Date.now();\n dispatch({ type: \"draftReady\", draft, quotedAt: quotedAtRef.current });\n } catch (err) {\n dispatch({ type: \"error\", error: err });\n }\n },\n [client],\n );\n\n const promote = useCallback(\n async (draft: Quote, retryCount = 0, riskModeOverride?: RiskMode): Promise<void> => {\n const quotedAt = quotedAtRef.current;\n dispatch({ type: \"promoting\", draft, quotedAt });\n try {\n // A draft carries no mode — the promotion query decides it, and omitting it means adaptive.\n // The caller passes the mode the user picked off the draft's `committedUnwinds`; without one,\n // fall back to the mode the draft was requested with.\n const riskMode = riskModeOverride ?? lastParamsRef.current?.riskMode;\n const promotedQuote = await client.promoteDraftQuote(draft.id, riskMode ? { riskMode } : undefined);\n dispatch({ type: \"promoted\", draft, promotedQuote, quotedAt });\n } catch (err) {\n if (isMarketMovedError(err) && retryCount < maxRetries && lastParamsRef.current) {\n try {\n const newDraft = await client.createDraftQuote(lastParamsRef.current);\n // eslint-disable-next-line require-atomic-updates -- timestamp ref, no contended state\n quotedAtRef.current = Date.now();\n dispatch({\n type: \"marketMoved\",\n originalDraft: draft,\n newDraft,\n retryCount: retryCount + 1,\n quotedAt: quotedAtRef.current,\n });\n } catch (draftErr) {\n dispatch({ type: \"error\", error: draftErr, draft });\n }\n } else {\n dispatch({ type: \"error\", error: err, draft });\n }\n }\n },\n [client, maxRetries],\n );\n\n const acceptChanges = useCallback(\n async (newDraft: Quote, retryCount: number, riskMode?: RiskMode): Promise<void> => {\n await promote(newDraft, retryCount, riskMode);\n },\n [promote],\n );\n\n const correctAndPromote = useCallback(\n async (originalDraft: Quote, adjustedParams: CreateQuoteParams): Promise<void> => {\n dispatch({ type: \"promoting\", draft: originalDraft, quotedAt: quotedAtRef.current });\n lastParamsRef.current = adjustedParams;\n try {\n const promotedQuote = await client.createQuote(adjustedParams);\n // eslint-disable-next-line require-atomic-updates -- timestamp ref, no contended state\n quotedAtRef.current = Date.now();\n dispatch({\n type: \"promoted\",\n draft: promotedQuote,\n promotedQuote,\n correctedFrom: originalDraft,\n quotedAt: quotedAtRef.current,\n });\n } catch (err) {\n dispatch({ type: \"error\", error: err });\n }\n },\n [client],\n );\n\n const reset = useCallback((): void => {\n dispatch({ type: \"reset\" });\n lastParamsRef.current = null;\n quotedAtRef.current = 0;\n }, []);\n\n return { state, getDraft, promote, acceptChanges, correctAndPromote, reset };\n}\n","import { useQuery, type UseQueryOptions, type UseQueryResult } from \"@tanstack/react-query\";\n// eslint-disable-next-line import-x/no-deprecated -- SearchMarketsParams imported for the deprecated shim below\nimport type { GetMarketsParams, SearchMarketsParams } from \"../client/dimes-client\";\nimport type { Market, Paginated } from \"../types\";\nimport { useDimesClient } from \"./provider\";\n\nexport function useMarkets(\n params?: GetMarketsParams,\n queryOptions?: Partial<UseQueryOptions<Paginated<Market>>>,\n): UseQueryResult<Paginated<Market>> {\n const client = useDimesClient();\n\n return useQuery({\n queryKey: [\"dimes\", \"markets\", params],\n queryFn: () => client.getMarkets(params),\n ...queryOptions,\n });\n}\n\n/**\n * @deprecated Use {@link useMarkets} with a `query` param: `useMarkets({ query })`.\n * Search is now served by `GET /markets?query=` instead of the deprecated `/markets/search` path.\n */\nexport function useSearchMarkets(\n // eslint-disable-next-line @typescript-eslint/no-deprecated, import-x/no-deprecated -- this IS the deprecated hook\n params: SearchMarketsParams,\n queryOptions?: Partial<UseQueryOptions<Paginated<Market>>>,\n): UseQueryResult<Paginated<Market>> {\n const client = useDimesClient();\n\n return useQuery({\n queryKey: [\"dimes\", \"markets\", \"search\", params],\n queryFn: () => client.getMarkets(params),\n enabled: !!params.query,\n ...queryOptions,\n });\n}\n\nexport function useMarket(ticker: string, queryOptions?: Partial<UseQueryOptions<Market>>): UseQueryResult<Market> {\n const client = useDimesClient();\n\n return useQuery({\n queryKey: [\"dimes\", \"market\", ticker],\n queryFn: () => client.getMarket(ticker),\n enabled: !!ticker,\n ...queryOptions,\n });\n}\n","import { useQuery, type Query, type UseQueryOptions, type UseQueryResult } from \"@tanstack/react-query\";\nimport type { GetPositionsParams } from \"../client/dimes-client\";\nimport type { Position } from \"../types\";\nimport { useDimesClient } from \"./provider\";\nimport { defaultReconciliationWindowMs, reconcilePolledPositions, transientPositionStatuses } from \"./ws-reconcile\";\n\nconst DEFAULT_FAST_POLL_MS = 5_000;\nconst DEFAULT_SLOW_POLL_MS = 15_000;\n\nexport interface UsePositionsOptions {\n /**\n * Appended to the query key so changing scope (e.g. switching wallet) does not serve the previous\n * scope's cached positions until a refetch. Omit to keep the default, scope-less cache key.\n */\n scope?: string | null;\n /**\n * Poll faster while any position is in a transient state (pending/closing/settling/unwinding) and\n * slower otherwise. Pass `true` for the defaults (5s / 15s) or an object to tune them.\n */\n adaptivePolling?: boolean | { fastMs?: number; slowMs?: number };\n /**\n * Defer to fresher WebSocket data: when a position was updated over the socket within the\n * reconciliation window, a slower REST poll won't overwrite it. Use with `usePositionStream` in\n * reconcile mode. Pass `true` for the default window or a number of milliseconds.\n */\n reconcile?: boolean | number;\n}\n\nfunction adaptiveRefetchInterval(\n adaptive: NonNullable<UsePositionsOptions[\"adaptivePolling\"]>,\n): (query: Query<Position[]>) => number {\n const fastMs = typeof adaptive === \"object\" ? (adaptive.fastMs ?? DEFAULT_FAST_POLL_MS) : DEFAULT_FAST_POLL_MS;\n const slowMs = typeof adaptive === \"object\" ? (adaptive.slowMs ?? DEFAULT_SLOW_POLL_MS) : DEFAULT_SLOW_POLL_MS;\n return (query) => (query.state.data?.some((p) => transientPositionStatuses.has(p.status)) ? fastMs : slowMs);\n}\n\nfunction reconcileStructuralSharing(reconcile: number | true): (oldData: unknown, newData: unknown) => Position[] {\n const windowMs = typeof reconcile === \"number\" ? reconcile : defaultReconciliationWindowMs;\n return (oldData, newData) =>\n reconcilePolledPositions(oldData as Position[] | undefined, newData as Position[], windowMs, Date.now());\n}\n\nexport function usePositions(\n params?: GetPositionsParams,\n queryOptions?: Partial<UseQueryOptions<Position[]>>,\n options?: UsePositionsOptions,\n): UseQueryResult<Position[]> {\n const client = useDimesClient();\n\n const queryKey =\n options?.scope !== undefined ? [\"dimes\", \"positions\", params, options.scope] : [\"dimes\", \"positions\", params];\n\n const config: UseQueryOptions<Position[]> = {\n queryKey,\n queryFn: () => client.getPositions(params),\n };\n\n if (options?.adaptivePolling) {\n config.refetchInterval = adaptiveRefetchInterval(options.adaptivePolling);\n }\n\n if (options?.reconcile) {\n config.structuralSharing = reconcileStructuralSharing(options.reconcile);\n }\n\n return useQuery({ ...config, ...queryOptions });\n}\n","import type { QueryClient } from \"@tanstack/react-query\";\nimport type { Market, Paginated, Position } from \"../types\";\nimport type { MarketDelta, PositionEvent } from \"../ws\";\n\n/**\n * Shared plumbing for merging WebSocket events into the React Query cache. Used by the optional\n * reconcile mode of `usePositionStream` / `useMarketStream` and the `reconcile` option on\n * `usePositions`. Kept internal so the query keys and the WS-timestamp registry stay in sync.\n */\n\nexport const positionsQueryKey = [\"dimes\", \"positions\"] as const;\n\nexport const marketsQueryKey = [\"dimes\", \"markets\"] as const;\n\nexport const defaultReconciliationWindowMs = 12_000;\n\n/** Position statuses that indicate an in-flight transition — polled faster by `adaptivePolling`. */\nexport const transientPositionStatuses: ReadonlySet<string> = new Set([\"pending\", \"closing\", \"settling\", \"unwinding\"]);\n\n/**\n * Records the last time each position id was written from a WebSocket event. Polling reconciliation\n * uses this so a slower REST poll never clobbers fresher WS data inside the reconciliation window.\n */\nexport const wsPositionTimestamps = new Map<string, number>();\n\n/** Merge a single position event into every cached positions query. */\nexport function mergePositionEvent(queryClient: QueryClient, event: PositionEvent, now: number): void {\n const position = event.data;\n queryClient.setQueriesData<Position[]>({ queryKey: positionsQueryKey }, (old) => {\n if (!old) {\n return old;\n }\n const idx = old.findIndex((p) => p.id === position.id);\n if (idx >= 0) {\n const next = [...old];\n next[idx] = position;\n return next;\n }\n if (event.type === \"position.created\") {\n return [position, ...old];\n }\n return old;\n });\n wsPositionTimestamps.set(position.id, now);\n}\n\n/**\n * `structuralSharing` for a polled positions list: keep the cached (WS-fresher) copy of any position\n * updated over the socket within `windowMs`, otherwise accept the polled copy.\n */\nexport function reconcilePolledPositions(\n oldData: Position[] | undefined,\n newData: Position[],\n windowMs: number,\n now: number,\n): Position[] {\n if (!oldData) {\n return newData;\n }\n return newData.map((polled) => {\n const wsTime = wsPositionTimestamps.get(polled.id);\n if (wsTime !== undefined && now - wsTime < windowMs) {\n const fresher = oldData.find((p) => p.id === polled.id);\n return fresher ?? polled;\n }\n if (wsTime !== undefined) {\n wsPositionTimestamps.delete(polled.id);\n }\n return polled;\n });\n}\n\n/**\n * Deep-merge a market delta onto a cached market. The nested `leverage` block must be merged rather\n * than replaced — a max-leverage delta carries only the changed leverage fields, so a shallow spread\n * would drop the constant `minBps`/`stepBps` until the next full refetch.\n */\nfunction mergeMarket(prev: Market, delta: MarketDelta): Market {\n return {\n ...prev,\n ...delta,\n leverage: delta.leverage ? { ...prev.leverage, ...delta.leverage } : prev.leverage,\n };\n}\n\n/** Merge market deltas into every cached paginated markets query (no-op for ids not present). */\nexport function mergeMarketDeltas(queryClient: QueryClient, deltas: MarketDelta[]): void {\n queryClient.setQueriesData<Paginated<Market>>({ queryKey: marketsQueryKey }, (old) => {\n if (!old) {\n return old;\n }\n const data = old.data.map((market) => {\n const delta = deltas.find((d) => d.id === market.id);\n return delta ? mergeMarket(market, delta) : market;\n });\n const changed = data.some((market, i) => market !== old.data[i]);\n return changed ? { ...old, data } : old;\n });\n}\n","import { useQuery, type UseQueryOptions, type UseQueryResult } from \"@tanstack/react-query\";\nimport type { ContractInfo } from \"../types\";\nimport { useDimesClient } from \"./provider\";\n\nexport function useContractInfo(queryOptions?: Partial<UseQueryOptions<ContractInfo>>): UseQueryResult<ContractInfo> {\n const client = useDimesClient();\n\n return useQuery({\n queryKey: [\"dimes\", \"contractInfo\"],\n queryFn: () => client.getContractInfo(),\n staleTime: Infinity,\n ...queryOptions,\n });\n}\n","import { useQuery, type UseQueryOptions, type UseQueryResult } from \"@tanstack/react-query\";\nimport type { PositionPartialCloseList } from \"../types\";\nimport { useDimesClient } from \"./provider\";\n\nexport function usePositionPartialCloses(\n positionId: string | null | undefined,\n queryOptions?: Partial<UseQueryOptions<PositionPartialCloseList>>,\n): UseQueryResult<PositionPartialCloseList> {\n const client = useDimesClient();\n\n return useQuery({\n queryKey: [\"dimes\", \"positionPartialCloses\", positionId],\n queryFn: () => {\n if (positionId == null) {\n return Promise.reject(new Error(\"positionId is required\"));\n }\n return client.getPositionPartialCloses(positionId);\n },\n enabled: Boolean(positionId),\n ...queryOptions,\n });\n}\n","import { useQuery, type UseQueryOptions, type UseQueryResult } from \"@tanstack/react-query\";\nimport type { CustomerLimit } from \"../types\";\nimport { useDimesClient } from \"./provider\";\n\n/** User trading limits (JWT auth) — `GET /user-limits`. */\nexport function useUserLimits(queryOptions?: Partial<UseQueryOptions<CustomerLimit>>): UseQueryResult<CustomerLimit> {\n const client = useDimesClient();\n\n return useQuery({\n queryKey: [\"dimes\", \"user-limits\"],\n queryFn: () => client.getUserLimits(),\n ...queryOptions,\n });\n}\n\n/** Partner-wide limits (API-key auth) — `GET /partner-limits`. */\nexport function usePartnerLimits(\n queryOptions?: Partial<UseQueryOptions<CustomerLimit>>,\n): UseQueryResult<CustomerLimit> {\n const client = useDimesClient();\n\n return useQuery({\n queryKey: [\"dimes\", \"partner-limits\"],\n queryFn: () => client.getPartnerLimits(),\n ...queryOptions,\n });\n}\n\n/** @deprecated Use {@link useUserLimits}. Alias kept for back-compat; resolves to user limits. */\nexport function useLimits(queryOptions?: Partial<UseQueryOptions<CustomerLimit>>): UseQueryResult<CustomerLimit> {\n return useUserLimits(queryOptions);\n}\n","import { useMutation, type UseMutationOptions, type UseMutationResult } from \"@tanstack/react-query\";\nimport { DimesApiError } from \"../errors/dimes-error\";\nimport { useDimesClient } from \"./provider\";\n\nconst HTTP_CONFLICT = 409;\n\nexport type CancelPositionResult = \"cancelled\" | \"already_cancelling\";\n\nexport interface UseCancelPositionOptions {\n /**\n * Treat a 409 Conflict (the position is already being cancelled) as success, resolving to\n * `\"already_cancelling\"` instead of throwing. Default false — a 409 rejects like any other error.\n */\n treatConflictAsAlreadyCancelling?: boolean;\n}\n\nexport function useCancelPosition(\n mutationOptions?: Partial<UseMutationOptions<CancelPositionResult, Error, string>>,\n options?: UseCancelPositionOptions,\n): UseMutationResult<CancelPositionResult, Error, string> {\n const client = useDimesClient();\n const treatConflictAsAlreadyCancelling = options?.treatConflictAsAlreadyCancelling ?? false;\n\n return useMutation({\n mutationFn: async (positionId: string): Promise<CancelPositionResult> => {\n try {\n await client.cancelPosition(positionId);\n return \"cancelled\";\n } catch (err) {\n if (treatConflictAsAlreadyCancelling && err instanceof DimesApiError && err.status === HTTP_CONFLICT) {\n return \"already_cancelling\";\n }\n throw err;\n }\n },\n ...mutationOptions,\n });\n}\n","import { useQueryClient } from \"@tanstack/react-query\";\nimport { useEffect, useRef, useState } from \"react\";\nimport { PositionSocket, type NotificationEvent, type PositionEvent } from \"../ws\";\nimport { useDimesClient } from \"./provider\";\nimport { mergePositionEvent, positionsQueryKey } from \"./ws-reconcile\";\n\nexport type StreamMode = \"raw\" | \"reconcile\";\n\nexport interface UsePositionStreamOptions {\n /** Connect the socket. Default true. Set false to gate on auth being ready. */\n enabled?: boolean;\n /**\n * `\"reconcile\"` (default) merges every event into the `usePositions` query cache so the UI updates\n * instantly; `\"raw\"` does not touch the cache and only forwards events to your callbacks.\n */\n mode?: StreamMode;\n /** Disconnect while the tab is hidden and reconnect when it becomes visible again. Default true. */\n pauseOnHidden?: boolean;\n /** Invalidate the positions query on reconnect (skipping the first connect) to catch missed events. Default true. */\n invalidateOnReconnect?: boolean;\n /** Always called with the raw (camelCased) event, in both modes. */\n onEvent?: (event: PositionEvent) => void;\n /** Called with user-gateway notification events (toasts, fill progress…). Never touches the cache. */\n onNotification?: (event: NotificationEvent) => void;\n onConnect?: () => void;\n onDisconnect?: () => void;\n onError?: (error: unknown) => void;\n}\n\nexport interface UsePositionStreamResult {\n socket: PositionSocket | null;\n connected: boolean;\n}\n\n/**\n * Subscribe to the user position WebSocket gateway. In `reconcile` mode (default) events are merged\n * into the React Query cache used by `usePositions`; in `raw` mode you handle events yourself via\n * `onEvent`. App-specific side effects (toasts, stores) belong in the callbacks, not the SDK.\n */\nexport function usePositionStream(options?: UsePositionStreamOptions): UsePositionStreamResult {\n const client = useDimesClient();\n const queryClient = useQueryClient();\n const socketRef = useRef<PositionSocket | null>(null);\n const [connected, setConnected] = useState(false);\n\n const enabled = options?.enabled ?? true;\n const mode = options?.mode ?? \"reconcile\";\n const pauseOnHidden = options?.pauseOnHidden ?? true;\n const invalidateOnReconnect = options?.invalidateOnReconnect ?? true;\n\n // Keep the latest callbacks/flags in a ref so the socket effect does not reconnect on every render.\n const optionsRef = useRef(options);\n optionsRef.current = options;\n\n useEffect(() => {\n if (!enabled) {\n return undefined;\n }\n\n const socket = new PositionSocket({\n baseUrl: client.baseUrl,\n getToken: (): string | null => client.getToken(),\n });\n socketRef.current = socket;\n\n const unsubEvent = socket.on(\"*\", (event) => {\n if (mode === \"reconcile\") {\n mergePositionEvent(queryClient, event, Date.now());\n }\n optionsRef.current?.onEvent?.(event);\n });\n\n const unsubNotification = socket.onNotification((event) => {\n optionsRef.current?.onNotification?.(event);\n });\n\n let firstConnect = true;\n const unsubConnect = socket.onConnect(() => {\n setConnected(true);\n if (firstConnect) {\n firstConnect = false;\n } else if (mode === \"reconcile\" && invalidateOnReconnect) {\n void queryClient.invalidateQueries({ queryKey: positionsQueryKey });\n }\n optionsRef.current?.onConnect?.();\n });\n\n const unsubDisconnect = socket.onDisconnect(() => {\n setConnected(false);\n optionsRef.current?.onDisconnect?.();\n });\n\n const unsubError = socket.onError((error) => {\n optionsRef.current?.onError?.(error);\n });\n\n const handleVisibility =\n pauseOnHidden && typeof document !== \"undefined\"\n ? (): void => {\n if (document.hidden) {\n socket.disconnect();\n } else {\n socket.connect();\n }\n }\n : null;\n if (handleVisibility) {\n document.addEventListener(\"visibilitychange\", handleVisibility);\n }\n\n socket.connect();\n\n return (): void => {\n if (handleVisibility) {\n document.removeEventListener(\"visibilitychange\", handleVisibility);\n }\n unsubEvent();\n unsubNotification();\n unsubConnect();\n unsubDisconnect();\n unsubError();\n socket.disconnect();\n socketRef.current = null;\n setConnected(false);\n };\n }, [client, queryClient, enabled, mode, pauseOnHidden, invalidateOnReconnect]);\n\n return { socket: socketRef.current, connected };\n}\n","import { useQueryClient } from \"@tanstack/react-query\";\nimport { useEffect, useRef, useState } from \"react\";\nimport { MarketSocket, type MarketDelta, type MarketEvent } from \"../ws\";\nimport { useDimesClient } from \"./provider\";\nimport type { StreamMode } from \"./use-position-stream\";\nimport { marketsQueryKey, mergeMarketDeltas } from \"./ws-reconcile\";\n\nexport interface UseMarketStreamOptions {\n /** Connect the socket. Default true. */\n enabled?: boolean;\n /**\n * `\"reconcile\"` (default) merges `eligibility_changed` / `max_leverage_changed` deltas into the\n * `useMarkets` query cache; `\"raw\"` only forwards events. `market.discovered` events are never\n * injected into the paginated cache (that would pollute server-filtered views) — handle them via\n * `onEvent` in either mode.\n */\n mode?: StreamMode;\n /** Disconnect while the tab is hidden and reconnect when visible again. Default true. */\n pauseOnHidden?: boolean;\n /** Invalidate the markets query on reconnect (skipping the first connect). Default true. */\n invalidateOnReconnect?: boolean;\n /** Always called with the raw (camelCased) event, in both modes. */\n onEvent?: (event: MarketEvent) => void;\n onConnect?: () => void;\n onDisconnect?: () => void;\n onError?: (error: unknown) => void;\n}\n\nexport interface UseMarketStreamResult {\n socket: MarketSocket | null;\n connected: boolean;\n}\n\n/**\n * Subscribe to the user market WebSocket gateway. In `reconcile` mode (default) eligibility and\n * max-leverage deltas are deep-merged into the `useMarkets` cache; discovered markets are forwarded\n * to `onEvent` for the app to route (e.g. a \"new markets\" strip).\n */\nexport function useMarketStream(options?: UseMarketStreamOptions): UseMarketStreamResult {\n const client = useDimesClient();\n const queryClient = useQueryClient();\n const socketRef = useRef<MarketSocket | null>(null);\n const [connected, setConnected] = useState(false);\n\n const enabled = options?.enabled ?? true;\n const mode = options?.mode ?? \"reconcile\";\n const pauseOnHidden = options?.pauseOnHidden ?? true;\n const invalidateOnReconnect = options?.invalidateOnReconnect ?? true;\n\n const optionsRef = useRef(options);\n optionsRef.current = options;\n\n useEffect(() => {\n if (!enabled) {\n return undefined;\n }\n\n const socket = new MarketSocket({\n baseUrl: client.baseUrl,\n getToken: (): string | null => client.getToken(),\n });\n socketRef.current = socket;\n\n const unsubEvent = socket.on(\"*\", (event) => {\n if (mode === \"reconcile\" && event.type !== \"market.discovered\") {\n mergeMarketDeltas(queryClient, event.data as MarketDelta[]);\n }\n optionsRef.current?.onEvent?.(event);\n });\n\n let firstConnect = true;\n const unsubConnect = socket.onConnect(() => {\n setConnected(true);\n if (firstConnect) {\n firstConnect = false;\n } else if (mode === \"reconcile\" && invalidateOnReconnect) {\n void queryClient.invalidateQueries({ queryKey: marketsQueryKey });\n }\n optionsRef.current?.onConnect?.();\n });\n\n const unsubDisconnect = socket.onDisconnect(() => {\n setConnected(false);\n optionsRef.current?.onDisconnect?.();\n });\n\n const unsubError = socket.onError((error) => {\n optionsRef.current?.onError?.(error);\n });\n\n const handleVisibility =\n pauseOnHidden && typeof document !== \"undefined\"\n ? (): void => {\n if (document.hidden) {\n socket.disconnect();\n } else {\n socket.connect();\n }\n }\n : null;\n if (handleVisibility) {\n document.addEventListener(\"visibilitychange\", handleVisibility);\n }\n\n socket.connect();\n\n return (): void => {\n if (handleVisibility) {\n document.removeEventListener(\"visibilitychange\", handleVisibility);\n }\n unsubEvent();\n unsubConnect();\n unsubDisconnect();\n unsubError();\n socket.disconnect();\n socketRef.current = null;\n setConnected(false);\n };\n }, [client, queryClient, enabled, mode, pauseOnHidden, invalidateOnReconnect]);\n\n return { socket: socketRef.current, connected };\n}\n"]}
|
package/dist/react/index.d.cts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { D as DimesClient, H as HintAdjustment, d as GetMarketsParams,
|
|
4
|
-
import { Q as Quote, C as CreateQuoteParams, M as Market, P as Position,
|
|
5
|
-
import { Q as QuoteParams, a as QuoteOptions, b as QuoteResult } from '../quote-
|
|
3
|
+
import { D as DimesClient, H as HintAdjustment, d as GetMarketsParams, i as Paginated, S as SearchMarketsParams, f as GetPositionsParams } from '../dimes-client-C4SsCNrZ.cjs';
|
|
4
|
+
import { Q as Quote, R as RiskMode, C as CreateQuoteParams, M as Market, P as Position, f as ContractInfo, e as PositionPartialCloseList, g as CustomerLimit } from '../aliases-BI1c3Yt0.cjs';
|
|
5
|
+
import { Q as QuoteParams, a as QuoteOptions, b as QuoteResult } from '../quote-CcIqLwKb.cjs';
|
|
6
6
|
import { UseQueryOptions, UseQueryResult, UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
|
|
7
7
|
import { PositionSocket, MarketSocket } from '../ws/index.cjs';
|
|
8
|
-
import { P as PositionEvent, N as NotificationEvent, M as MarketEvent } from '../types-
|
|
8
|
+
import { P as PositionEvent, N as NotificationEvent, M as MarketEvent } from '../types-B881zrxm.cjs';
|
|
9
9
|
|
|
10
10
|
interface DimesProviderProps {
|
|
11
11
|
client: DimesClient;
|
|
@@ -77,10 +77,14 @@ interface UseQuoteMachineReturn {
|
|
|
77
77
|
state: QuoteMachineState;
|
|
78
78
|
/** Build params from a `QuoteParams` and fetch a draft quote. Moves to `draft-ready`. */
|
|
79
79
|
getDraft: (params: QuoteParams) => Promise<void>;
|
|
80
|
-
/**
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Promote a reviewed draft into a signed quote, in `riskMode` if given — a draft is always drawn
|
|
82
|
+
* up as adaptive, so this is where a mode the user picked after seeing the draft is applied.
|
|
83
|
+
* On market-moved, re-drafts and surfaces `market-moved`.
|
|
84
|
+
*/
|
|
85
|
+
promote: (draft: Quote, retryCount?: number, riskMode?: RiskMode) => Promise<void>;
|
|
86
|
+
/** Accept a re-drafted quote after a `market-moved` and promote it, in `riskMode` if given. */
|
|
87
|
+
acceptChanges: (newDraft: Quote, retryCount: number, riskMode?: RiskMode) => Promise<void>;
|
|
84
88
|
/** Promote pre-adjusted params directly via `createQuote` (e.g. after applying a correction hint). */
|
|
85
89
|
correctAndPromote: (originalDraft: Quote, adjustedParams: CreateQuoteParams) => Promise<void>;
|
|
86
90
|
reset: () => void;
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { D as DimesClient, H as HintAdjustment, d as GetMarketsParams,
|
|
4
|
-
import { Q as Quote, C as CreateQuoteParams, M as Market, P as Position,
|
|
5
|
-
import { Q as QuoteParams, a as QuoteOptions, b as QuoteResult } from '../quote-
|
|
3
|
+
import { D as DimesClient, H as HintAdjustment, d as GetMarketsParams, i as Paginated, S as SearchMarketsParams, f as GetPositionsParams } from '../dimes-client-Ckn8yRG6.js';
|
|
4
|
+
import { Q as Quote, R as RiskMode, C as CreateQuoteParams, M as Market, P as Position, f as ContractInfo, e as PositionPartialCloseList, g as CustomerLimit } from '../aliases-BI1c3Yt0.js';
|
|
5
|
+
import { Q as QuoteParams, a as QuoteOptions, b as QuoteResult } from '../quote-06n723we.js';
|
|
6
6
|
import { UseQueryOptions, UseQueryResult, UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
|
|
7
7
|
import { PositionSocket, MarketSocket } from '../ws/index.js';
|
|
8
|
-
import { P as PositionEvent, N as NotificationEvent, M as MarketEvent } from '../types-
|
|
8
|
+
import { P as PositionEvent, N as NotificationEvent, M as MarketEvent } from '../types-CcoiGMbT.js';
|
|
9
9
|
|
|
10
10
|
interface DimesProviderProps {
|
|
11
11
|
client: DimesClient;
|
|
@@ -77,10 +77,14 @@ interface UseQuoteMachineReturn {
|
|
|
77
77
|
state: QuoteMachineState;
|
|
78
78
|
/** Build params from a `QuoteParams` and fetch a draft quote. Moves to `draft-ready`. */
|
|
79
79
|
getDraft: (params: QuoteParams) => Promise<void>;
|
|
80
|
-
/**
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Promote a reviewed draft into a signed quote, in `riskMode` if given — a draft is always drawn
|
|
82
|
+
* up as adaptive, so this is where a mode the user picked after seeing the draft is applied.
|
|
83
|
+
* On market-moved, re-drafts and surfaces `market-moved`.
|
|
84
|
+
*/
|
|
85
|
+
promote: (draft: Quote, retryCount?: number, riskMode?: RiskMode) => Promise<void>;
|
|
86
|
+
/** Accept a re-drafted quote after a `market-moved` and promote it, in `riskMode` if given. */
|
|
87
|
+
acceptChanges: (newDraft: Quote, retryCount: number, riskMode?: RiskMode) => Promise<void>;
|
|
84
88
|
/** Promote pre-adjusted params directly via `createQuote` (e.g. after applying a correction hint). */
|
|
85
89
|
correctAndPromote: (originalDraft: Quote, adjustedParams: CreateQuoteParams) => Promise<void>;
|
|
86
90
|
reset: () => void;
|
package/dist/react/index.mjs
CHANGED
|
@@ -2,11 +2,11 @@ import {
|
|
|
2
2
|
buildQuoteParams,
|
|
3
3
|
executeQuote,
|
|
4
4
|
isMarketMovedError
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-HJ5EVO5A.mjs";
|
|
6
6
|
import {
|
|
7
7
|
DimesApiError,
|
|
8
8
|
DimesError
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-GA7ZBK6W.mjs";
|
|
10
10
|
import {
|
|
11
11
|
MarketSocket,
|
|
12
12
|
PositionSocket
|
|
@@ -155,11 +155,12 @@ function useQuoteMachine(options) {
|
|
|
155
155
|
[client]
|
|
156
156
|
);
|
|
157
157
|
const promote = useCallback2(
|
|
158
|
-
async (draft, retryCount = 0) => {
|
|
158
|
+
async (draft, retryCount = 0, riskModeOverride) => {
|
|
159
159
|
const quotedAt = quotedAtRef.current;
|
|
160
160
|
dispatch({ type: "promoting", draft, quotedAt });
|
|
161
161
|
try {
|
|
162
|
-
const
|
|
162
|
+
const riskMode = riskModeOverride ?? lastParamsRef.current?.riskMode;
|
|
163
|
+
const promotedQuote = await client.promoteDraftQuote(draft.id, riskMode ? { riskMode } : void 0);
|
|
163
164
|
dispatch({ type: "promoted", draft, promotedQuote, quotedAt });
|
|
164
165
|
} catch (err) {
|
|
165
166
|
if (isMarketMovedError(err) && retryCount < maxRetries && lastParamsRef.current) {
|
|
@@ -184,8 +185,8 @@ function useQuoteMachine(options) {
|
|
|
184
185
|
[client, maxRetries]
|
|
185
186
|
);
|
|
186
187
|
const acceptChanges = useCallback2(
|
|
187
|
-
async (newDraft, retryCount) => {
|
|
188
|
-
await promote(newDraft, retryCount);
|
|
188
|
+
async (newDraft, retryCount, riskMode) => {
|
|
189
|
+
await promote(newDraft, retryCount, riskMode);
|
|
189
190
|
},
|
|
190
191
|
[promote]
|
|
191
192
|
);
|