@dimes-dot-fi/sdk 1.4.3 → 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.
- package/LICENSE +21 -0
- package/README.md +88 -19
- package/dist/{aliases-C2l_JZX_.d.cts → aliases-BJyM8ydu.d.cts} +288 -4
- package/dist/{aliases-C2l_JZX_.d.ts → aliases-BJyM8ydu.d.ts} +288 -4
- package/dist/{chunk-UHQZSMUD.cjs → chunk-53U53KZ2.cjs} +5 -1
- package/dist/chunk-53U53KZ2.cjs.map +1 -0
- package/dist/chunk-5VHDXPRV.mjs +240 -0
- package/dist/chunk-5VHDXPRV.mjs.map +1 -0
- package/dist/{chunk-DYPABUKC.cjs → chunk-72LTVPD2.cjs} +16 -1
- package/dist/chunk-72LTVPD2.cjs.map +1 -0
- package/dist/{chunk-COSLZ5TM.cjs → chunk-DIH3ORFA.cjs} +38 -16
- package/dist/chunk-DIH3ORFA.cjs.map +1 -0
- package/dist/chunk-FAW2C5AM.cjs +240 -0
- package/dist/chunk-FAW2C5AM.cjs.map +1 -0
- package/dist/{chunk-SGA6OZEU.mjs → chunk-NHAIL4SN.mjs} +34 -12
- package/dist/chunk-NHAIL4SN.mjs.map +1 -0
- package/dist/{chunk-4MO3HKMS.mjs → chunk-PK2PRTQW.mjs} +5 -1
- package/dist/chunk-PK2PRTQW.mjs.map +1 -0
- package/dist/{chunk-BVILILIV.mjs → chunk-PZCBUVPD.mjs} +16 -1
- package/dist/chunk-PZCBUVPD.mjs.map +1 -0
- package/dist/contract/index.cjs +5534 -305
- package/dist/contract/index.cjs.map +1 -1
- package/dist/contract/index.d.cts +68 -10
- package/dist/contract/index.d.ts +68 -10
- package/dist/contract/index.mjs +5524 -295
- package/dist/contract/index.mjs.map +1 -1
- package/dist/{dimes-client-ty6xwk0b.d.cts → dimes-client-DYFvnZUx.d.ts} +57 -10
- package/dist/{dimes-client-u5wLYVfp.d.ts → dimes-client-DZPhU1CG.d.cts} +57 -10
- package/dist/{dimes-error-5ldDx2_G.d.cts → dimes-error-BlQWPqhQ.d.cts} +2 -2
- package/dist/{dimes-error-D2RVknPr.d.ts → dimes-error-DBKV5bfr.d.ts} +2 -2
- package/dist/index.cjs +164 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +151 -12
- package/dist/index.d.ts +151 -12
- package/dist/index.mjs +161 -9
- package/dist/index.mjs.map +1 -1
- package/dist/quote-BFNgVsY-.d.ts +39 -0
- package/dist/quote-CanwfT9m.d.cts +39 -0
- package/dist/react/index.cjs +416 -18
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +165 -8
- package/dist/react/index.d.ts +165 -8
- package/dist/react/index.mjs +414 -16
- package/dist/react/index.mjs.map +1 -1
- package/dist/{types-CM14Dx5b.d.cts → types-ClHQbIcY.d.ts} +3 -3
- package/dist/{types-CVcrVq0A.d.ts → types-Co-2bQSi.d.cts} +3 -3
- package/dist/ws/index.cjs +4 -230
- package/dist/ws/index.cjs.map +1 -1
- package/dist/ws/index.d.cts +3 -3
- package/dist/ws/index.d.ts +3 -3
- package/dist/ws/index.mjs +5 -231
- package/dist/ws/index.mjs.map +1 -1
- package/package.json +43 -4
- package/dist/chunk-4MO3HKMS.mjs.map +0 -1
- package/dist/chunk-BVILILIV.mjs.map +0 -1
- package/dist/chunk-COSLZ5TM.cjs.map +0 -1
- package/dist/chunk-DYPABUKC.cjs.map +0 -1
- package/dist/chunk-SGA6OZEU.mjs.map +0 -1
- package/dist/chunk-UHQZSMUD.cjs.map +0 -1
- package/dist/quote-DoRJUXld.d.cts +0 -30
- package/dist/quote-GCNVcEoo.d.ts +0 -30
|
@@ -32,12 +32,196 @@ interface components {
|
|
|
32
32
|
* @example 0x70997970C51812dc3A010C7d01b50e0d17dc79C8
|
|
33
33
|
*/
|
|
34
34
|
polygon_signer_address: string;
|
|
35
|
+
/**
|
|
36
|
+
* @description Checksummed address of the stablecoin (pUSD) token that collateral must be transferred in. Use this when building the push deposit transfer — sending any other token (e.g. USDC.e) will fail.
|
|
37
|
+
* @example 0xC011a7E12a19f7B1f670d46F03B03f3342E82DFB
|
|
38
|
+
*/
|
|
39
|
+
polygon_usdc_token_address: string;
|
|
35
40
|
/**
|
|
36
41
|
* @description Checksummed address of the vault contract on Polygon
|
|
37
42
|
* @example 0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc
|
|
38
43
|
*/
|
|
39
44
|
polygon_vault_contract_address: string;
|
|
40
45
|
};
|
|
46
|
+
CustomerOriginationFeeTier: {
|
|
47
|
+
/**
|
|
48
|
+
* @description Upper leverage bound (inclusive) in basis points for this tier. The last tier is the catch-all.
|
|
49
|
+
* @example 40000
|
|
50
|
+
*/
|
|
51
|
+
max_leverage_bps: number;
|
|
52
|
+
/**
|
|
53
|
+
* @description Protocol origination fee in basis points applied at or below this tier's leverage bound.
|
|
54
|
+
* @example 200
|
|
55
|
+
*/
|
|
56
|
+
fee_bps: number;
|
|
57
|
+
};
|
|
58
|
+
CustomerFeeRatesMarket: {
|
|
59
|
+
/**
|
|
60
|
+
* @description Market ticker
|
|
61
|
+
* @example TRUMP-2024-WIN
|
|
62
|
+
*/
|
|
63
|
+
ticker: string;
|
|
64
|
+
/**
|
|
65
|
+
* @description Polymarket venue trading fee rate in basis points (`feeRateBps`).
|
|
66
|
+
* @example 0
|
|
67
|
+
*/
|
|
68
|
+
polymarket_trading_fee_bps: number;
|
|
69
|
+
/**
|
|
70
|
+
* @description Polymarket fee-curve exponent (`feeExponent`). `1` for the standard quadratic curve.
|
|
71
|
+
* @example 1
|
|
72
|
+
*/
|
|
73
|
+
polymarket_fee_exponent: number;
|
|
74
|
+
};
|
|
75
|
+
CustomerFeeRates: {
|
|
76
|
+
/** @description Per-market venue fee fields. Only present when the request includes a `ticker` query parameter. */
|
|
77
|
+
market?: components["schemas"]["CustomerFeeRatesMarket"];
|
|
78
|
+
/** @description Leverage-tiered protocol origination fee schedule. Resolve a leverage to its fee by picking the first tier whose `maxLeverageBps >= leverageBps` (the last tier is the catch-all). */
|
|
79
|
+
origination_fee_tiers: components["schemas"]["CustomerOriginationFeeTier"][];
|
|
80
|
+
/**
|
|
81
|
+
* @description Maximum combined (protocol + partner) origination fee in basis points enforced on-chain.
|
|
82
|
+
* @example 1000
|
|
83
|
+
*/
|
|
84
|
+
contract_max_origination_fee_bps: number;
|
|
85
|
+
/**
|
|
86
|
+
* @description Lifetime fee APR in basis points
|
|
87
|
+
* @example 2000
|
|
88
|
+
*/
|
|
89
|
+
lifetime_fee_apr_bps: number;
|
|
90
|
+
/**
|
|
91
|
+
* @description Liquidation fee in basis points
|
|
92
|
+
* @example 250
|
|
93
|
+
*/
|
|
94
|
+
liquidation_fee_bps: number;
|
|
95
|
+
/**
|
|
96
|
+
* @description This partner's origination fee component in basis points, added to the protocol tier fee. `0` by default.
|
|
97
|
+
* @example 0
|
|
98
|
+
*/
|
|
99
|
+
partner_origination_fee_bps: number;
|
|
100
|
+
/**
|
|
101
|
+
* @description This partner's Polymarket builder taker fee in basis points (flat percentage of notional). `0` by default.
|
|
102
|
+
* @example 0
|
|
103
|
+
*/
|
|
104
|
+
partner_trading_fee_bps: number;
|
|
105
|
+
};
|
|
106
|
+
FeeReportBody: {
|
|
107
|
+
/**
|
|
108
|
+
* @description Leverage in basis points (20000 = 2x, 100000 = 10x). Must be divisible by 2500. Maximum 10x.
|
|
109
|
+
* @example 50000
|
|
110
|
+
*/
|
|
111
|
+
leverage_bps: number;
|
|
112
|
+
/**
|
|
113
|
+
* @description Market ticker
|
|
114
|
+
* @example TRUMP-2024-WIN
|
|
115
|
+
*/
|
|
116
|
+
market_ticker: string;
|
|
117
|
+
/**
|
|
118
|
+
* @description Notional amount in USD pips (10,000 pips = $1.00)
|
|
119
|
+
* @example 50000
|
|
120
|
+
*/
|
|
121
|
+
notional_amount_usd_pips: string;
|
|
122
|
+
/**
|
|
123
|
+
* @description Market side (yes or no)
|
|
124
|
+
* @enum {string}
|
|
125
|
+
*/
|
|
126
|
+
effective_side: "yes" | "no";
|
|
127
|
+
/**
|
|
128
|
+
* @description Effective-side entry price in USD pips (10000 pips = $1) to compute against. When omitted, the market's current reference price is used. Provide it to compute deterministically against a known price.
|
|
129
|
+
* @example 5100
|
|
130
|
+
*/
|
|
131
|
+
entry_price_usd_pips?: string;
|
|
132
|
+
};
|
|
133
|
+
CustomerFeeReport: {
|
|
134
|
+
/**
|
|
135
|
+
* @description Market ticker
|
|
136
|
+
* @example TRUMP-2024-WIN
|
|
137
|
+
*/
|
|
138
|
+
market_ticker: string;
|
|
139
|
+
/**
|
|
140
|
+
* @description Market side
|
|
141
|
+
* @enum {string}
|
|
142
|
+
*/
|
|
143
|
+
effective_side: "yes" | "no";
|
|
144
|
+
/**
|
|
145
|
+
* @description Leverage in basis points (20000 = 2x)
|
|
146
|
+
* @example 20000
|
|
147
|
+
*/
|
|
148
|
+
leverage_bps: number;
|
|
149
|
+
/**
|
|
150
|
+
* @description Entry price used for the computation, in USD pips
|
|
151
|
+
* @example 5100
|
|
152
|
+
*/
|
|
153
|
+
entry_price_usd_pips: string;
|
|
154
|
+
/**
|
|
155
|
+
* @description Notional in USD pips (10000 pips = $1)
|
|
156
|
+
* @example 500000
|
|
157
|
+
*/
|
|
158
|
+
notional_amount_usd_pips: string;
|
|
159
|
+
/**
|
|
160
|
+
* @description Notional in USDC units (1,000,000 = 1 USDC)
|
|
161
|
+
* @example 50000000
|
|
162
|
+
*/
|
|
163
|
+
notional_usdc_units: string;
|
|
164
|
+
/**
|
|
165
|
+
* @description Collateral in USDC units
|
|
166
|
+
* @example 25000000
|
|
167
|
+
*/
|
|
168
|
+
collateral_usdc_units: string;
|
|
169
|
+
/**
|
|
170
|
+
* @description Combined origination fee in basis points
|
|
171
|
+
* @example 200
|
|
172
|
+
*/
|
|
173
|
+
origination_fee_bps: number;
|
|
174
|
+
/**
|
|
175
|
+
* @description Origination fee in USDC units
|
|
176
|
+
* @example 1000000
|
|
177
|
+
*/
|
|
178
|
+
origination_fee_usdc_units: string;
|
|
179
|
+
/**
|
|
180
|
+
* @description Protocol component of the origination fee in basis points
|
|
181
|
+
* @example 200
|
|
182
|
+
*/
|
|
183
|
+
protocol_origination_fee_bps: number;
|
|
184
|
+
/**
|
|
185
|
+
* @description Partner component of the origination fee in basis points
|
|
186
|
+
* @example 0
|
|
187
|
+
*/
|
|
188
|
+
partner_origination_fee_bps: number;
|
|
189
|
+
/**
|
|
190
|
+
* @description Polymarket venue trading fee rate in basis points (`feeRateBps`).
|
|
191
|
+
* @example 0
|
|
192
|
+
*/
|
|
193
|
+
polymarket_trading_fee_bps: number;
|
|
194
|
+
/**
|
|
195
|
+
* @description Partner Polymarket builder taker fee in basis points (flat percentage of notional).
|
|
196
|
+
* @example 0
|
|
197
|
+
*/
|
|
198
|
+
partner_trading_fee_bps: number;
|
|
199
|
+
/**
|
|
200
|
+
* @description Expected venue trading fee in USDC units charged to open the position (protocol venue fee + partner builder fee), computed from notional and entry price.
|
|
201
|
+
* @example 2204118
|
|
202
|
+
*/
|
|
203
|
+
expected_open_trading_fee_usdc_units: string;
|
|
204
|
+
/**
|
|
205
|
+
* @description Total amount the user must provide to open, in USDC units.
|
|
206
|
+
* @example 28204118
|
|
207
|
+
*/
|
|
208
|
+
total_user_amount_usdc_units: string;
|
|
209
|
+
/**
|
|
210
|
+
* @description Deterministic at-entry liquidation price ESTIMATE in USD pips (10000 pips = $1): `entry * (L-1)/L * (1 + liquidationFeeBps/10000)`. This is a closed-form estimate; the binding offer uses a TWAP/inference-based price that may differ.
|
|
211
|
+
* @example 2629
|
|
212
|
+
*/
|
|
213
|
+
estimated_liquidation_price_usd_pips: string;
|
|
214
|
+
/**
|
|
215
|
+
* @description Gross maximum gain in USDC units: full value on a win (settlement at $1) minus notional, before fees. Profit over principal; may be negative.
|
|
216
|
+
* @example 48039215
|
|
217
|
+
*/
|
|
218
|
+
gross_max_gain_usdc_units: string;
|
|
219
|
+
/**
|
|
220
|
+
* @description Net maximum gain in USDC units: grossMaxGain minus the open trading fee and the origination fee. Assumes a win via settlement (no exit trading fee) and excludes lifetime fees, so it is an upper bound. May be negative.
|
|
221
|
+
* @example 44835097
|
|
222
|
+
*/
|
|
223
|
+
net_max_gain_usdc_units: string;
|
|
224
|
+
};
|
|
41
225
|
CustomerLimit: {
|
|
42
226
|
/**
|
|
43
227
|
* @description Total limit formatted as USD
|
|
@@ -477,6 +661,11 @@ interface components {
|
|
|
477
661
|
* @example 50
|
|
478
662
|
*/
|
|
479
663
|
effective_slippage_bps?: number | null;
|
|
664
|
+
/**
|
|
665
|
+
* @description Original position token units delivered when the position opened (1000000 units = 1 token). Unlike `current.positionTokenUnits` (the live, possibly partially-closed survivor), this is the fixed size credited at open and is the basis for the partial-close minimum. Null until the open fill is recorded on chain.
|
|
666
|
+
* @example 10000000
|
|
667
|
+
*/
|
|
668
|
+
position_token_units?: string | null;
|
|
480
669
|
};
|
|
481
670
|
CustomerPositionFailure: {
|
|
482
671
|
/**
|
|
@@ -539,6 +728,24 @@ interface components {
|
|
|
539
728
|
*/
|
|
540
729
|
deferred_at: string;
|
|
541
730
|
};
|
|
731
|
+
CustomerPendingOperation: {
|
|
732
|
+
/**
|
|
733
|
+
* @description The lifecycle operation currently in flight on this position. Present whenever the position is mid-operation (open, close, partial close, unwind, liquidate, or settle); null when the position is at rest. Note `status` stays `open` throughout a `partial_close`, so this is the only signal a slice is in flight after a reload.
|
|
734
|
+
* @enum {string}
|
|
735
|
+
*/
|
|
736
|
+
type: "open" | "close" | "partial_close" | "unwind" | "liquidate" | "settle";
|
|
737
|
+
/**
|
|
738
|
+
* @description Sub-state of the operation: `requested` (submitted, not yet executing), `initiated` (executing on the venue), `pending` (tokens withdrawn, finalizing on chain), `awaiting_settlement` (a close deferred until the market settles). Null when the operation has no distinct phase.
|
|
739
|
+
* @example initiated
|
|
740
|
+
* @enum {string|null}
|
|
741
|
+
*/
|
|
742
|
+
phase?: "requested" | "initiated" | "pending" | "awaiting_settlement" | null;
|
|
743
|
+
/**
|
|
744
|
+
* @description Token units involved in the in-flight operation (1000000 units = 1 token). For `partial_close` this is the slice being closed; for `close`/`liquidate` the units withdrawn; for the awaiting-settlement close the remaining tokens. Null when the operation carries no specific token amount.
|
|
745
|
+
* @example 5000000
|
|
746
|
+
*/
|
|
747
|
+
token_units?: string | null;
|
|
748
|
+
};
|
|
542
749
|
CustomerPositionCurrent: {
|
|
543
750
|
/**
|
|
544
751
|
* @description Current book-value leverage in basis points (20000 = 2x)
|
|
@@ -611,6 +818,16 @@ interface components {
|
|
|
611
818
|
* @example 55000
|
|
612
819
|
*/
|
|
613
820
|
notional_usd_pips: string;
|
|
821
|
+
/**
|
|
822
|
+
* @description Smallest partial-close slice the contract will accept right now, in token units (1000000 units = 1 token): `max(5 tokens, 20% of the original opened size)`. Null when the position is not partial-closeable (an operation is already in flight, the open fill isn't recorded yet, or the survivor is below the minimum).
|
|
823
|
+
* @example 5000000
|
|
824
|
+
*/
|
|
825
|
+
min_partial_close_token_units?: string | null;
|
|
826
|
+
/**
|
|
827
|
+
* @description Largest partial-close slice allowed right now, in token units (1000000 units = 1 token): the full survivor size currently held (`positionTokenUnits`). Null when the position is not partial-closeable.
|
|
828
|
+
* @example 10000000
|
|
829
|
+
*/
|
|
830
|
+
max_partial_close_token_units?: string | null;
|
|
614
831
|
/**
|
|
615
832
|
* @description Position token units held (1000000 units = 1 token)
|
|
616
833
|
* @example 10000000
|
|
@@ -802,8 +1019,13 @@ interface components {
|
|
|
802
1019
|
* @example 7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU
|
|
803
1020
|
*/
|
|
804
1021
|
wallet_address: string;
|
|
805
|
-
/**
|
|
1022
|
+
/**
|
|
1023
|
+
* @deprecated
|
|
1024
|
+
* @description Deprecated — use `pendingOperation` (a deferred close now surfaces as `{ type: 'close', phase: 'awaiting_settlement' }`). Details of a close request that could not complete and was deferred. Null unless the customer requested a close that is now waiting on market settlement to redeem the remaining tokens.
|
|
1025
|
+
*/
|
|
806
1026
|
close_attempt?: components["schemas"]["CustomerCloseAttempt"] | null;
|
|
1027
|
+
/** @description The lifecycle operation currently in flight on this position, or null when the position is at rest. Survives reload (unlike the ephemeral websocket events), so a UI can show that a close / partial close / unwind / settle is in progress after re-fetching REST. */
|
|
1028
|
+
pending_operation?: components["schemas"]["CustomerPendingOperation"] | null;
|
|
807
1029
|
};
|
|
808
1030
|
CustomerPositionClosedFees: {
|
|
809
1031
|
/**
|
|
@@ -898,6 +1120,16 @@ interface components {
|
|
|
898
1120
|
* @example 0
|
|
899
1121
|
*/
|
|
900
1122
|
collected_liquidation_fee_usd_pips: string;
|
|
1123
|
+
/**
|
|
1124
|
+
* @description Volume-weighted notional realized across all unwinds and the final close, formatted as USD. Null for reverted or cancelled positions.
|
|
1125
|
+
* @example 5.25
|
|
1126
|
+
*/
|
|
1127
|
+
exit_notional_usd?: string | null;
|
|
1128
|
+
/**
|
|
1129
|
+
* @description Exit notional in USD pips. Null for reverted or cancelled positions.
|
|
1130
|
+
* @example 52500
|
|
1131
|
+
*/
|
|
1132
|
+
exit_notional_usd_pips?: string | null;
|
|
901
1133
|
/**
|
|
902
1134
|
* @description Realized PnL net of all fees (origination + lifetime + liquidation + venue) as return on equity in basis points
|
|
903
1135
|
* @example 1700
|
|
@@ -1078,6 +1310,38 @@ interface components {
|
|
|
1078
1310
|
*/
|
|
1079
1311
|
min_fill_bps?: number;
|
|
1080
1312
|
};
|
|
1313
|
+
CustomerOfferMaxGain: {
|
|
1314
|
+
/**
|
|
1315
|
+
* @description Gross max gain (profit before fees) formatted as USD
|
|
1316
|
+
* @example 1.90
|
|
1317
|
+
*/
|
|
1318
|
+
gross_max_gain_usd: string;
|
|
1319
|
+
/**
|
|
1320
|
+
* @description Gross max gain in USD pips (10000 pips = $1)
|
|
1321
|
+
* @example 19000
|
|
1322
|
+
*/
|
|
1323
|
+
gross_max_gain_usd_pips: string;
|
|
1324
|
+
/**
|
|
1325
|
+
* @description Gross max gain in USDC units (1,000,000 units = 1 USDC). May be negative.
|
|
1326
|
+
* @example 1900000
|
|
1327
|
+
*/
|
|
1328
|
+
gross_max_gain_usdc_units: string;
|
|
1329
|
+
/**
|
|
1330
|
+
* @description Net max gain (profit after fees) formatted as USD
|
|
1331
|
+
* @example 1.40
|
|
1332
|
+
*/
|
|
1333
|
+
net_max_gain_usd: string;
|
|
1334
|
+
/**
|
|
1335
|
+
* @description Net max gain in USD pips (10000 pips = $1)
|
|
1336
|
+
* @example 14000
|
|
1337
|
+
*/
|
|
1338
|
+
net_max_gain_usd_pips: string;
|
|
1339
|
+
/**
|
|
1340
|
+
* @description Net max gain in USDC units (1,000,000 units = 1 USDC). May be negative.
|
|
1341
|
+
* @example 1400000
|
|
1342
|
+
*/
|
|
1343
|
+
net_max_gain_usdc_units: string;
|
|
1344
|
+
};
|
|
1081
1345
|
CustomerOffer: {
|
|
1082
1346
|
/**
|
|
1083
1347
|
* @description Offer ID
|
|
@@ -1325,6 +1589,8 @@ interface components {
|
|
|
1325
1589
|
min_fill_bps?: number;
|
|
1326
1590
|
/** @description Base64-encoded Solana transaction (present for Solana markets only) */
|
|
1327
1591
|
swap_transaction?: string;
|
|
1592
|
+
/** @description Expected maximum gain on a win (profit over principal). Only present when the request includes `expand=max_gain`; omitted otherwise. Assumes settlement at $1.00 (no exit trading fee) and excludes time-based lifetime fees, so it is an upper bound. */
|
|
1593
|
+
max_gain?: components["schemas"]["CustomerOfferMaxGain"];
|
|
1328
1594
|
/**
|
|
1329
1595
|
* @description Total amount user must provide formatted as USD
|
|
1330
1596
|
* @example 2.73
|
|
@@ -1364,7 +1630,9 @@ interface MarketPolymarket {
|
|
|
1364
1630
|
yesTokenId: string;
|
|
1365
1631
|
}
|
|
1366
1632
|
type OriginationTier = CamelizeKeys<Raw["CustomerOriginationTier"]>;
|
|
1367
|
-
type
|
|
1633
|
+
type Quote = CamelizeKeys<Raw["CustomerOffer"]>;
|
|
1634
|
+
/** @deprecated Use {@link Quote}. Back-compat alias; removed in a future major. */
|
|
1635
|
+
type Offer = Quote;
|
|
1368
1636
|
type OpenPosition = CamelizeKeys<Raw["CustomerOpenPosition"]>;
|
|
1369
1637
|
type ClosedPosition = CamelizeKeys<Raw["CustomerClosedPosition"]>;
|
|
1370
1638
|
type Position = OpenPosition | ClosedPosition;
|
|
@@ -1377,22 +1645,38 @@ type PositionResult = CamelizeKeys<Raw["CustomerPositionResult"]>;
|
|
|
1377
1645
|
type PositionTiming = CamelizeKeys<Raw["CustomerPositionTiming"]>;
|
|
1378
1646
|
type PositionFailure = CamelizeKeys<Raw["CustomerPositionFailure"]>;
|
|
1379
1647
|
type CloseAttempt = CamelizeKeys<Raw["CustomerCloseAttempt"]>;
|
|
1648
|
+
type PendingOperation = CamelizeKeys<Raw["CustomerPendingOperation"]>;
|
|
1380
1649
|
type PositionUnwind = CamelizeKeys<Raw["CustomerPositionUnwind"]>;
|
|
1381
1650
|
type PositionUnwindList = CamelizeKeys<Raw["CustomerPositionUnwindList"]>;
|
|
1382
1651
|
type PositionTransactions = CamelizeKeys<Raw["PositionTransactions"]>;
|
|
1383
1652
|
type ContractInfo = CamelizeKeys<Raw["CustomerContractInfo"]>;
|
|
1384
1653
|
type CustomerLimit = CamelizeKeys<Raw["CustomerLimit"]>;
|
|
1385
1654
|
type CreateTokenResult = CamelizeKeys<Raw["CreateTokenResult"]>;
|
|
1386
|
-
|
|
1655
|
+
type FeeRatesOriginationTier = CamelizeKeys<Raw["CustomerOriginationFeeTier"]>;
|
|
1656
|
+
type FeeRatesMarket = CamelizeKeys<Raw["CustomerFeeRatesMarket"]>;
|
|
1657
|
+
type FeeRates = CamelizeKeys<Raw["CustomerFeeRates"]>;
|
|
1658
|
+
type FeeReport = CamelizeKeys<Raw["CustomerFeeReport"]>;
|
|
1659
|
+
interface CreateQuoteParams {
|
|
1387
1660
|
marketTicker: string;
|
|
1388
1661
|
effectiveSide: "yes" | "no";
|
|
1389
1662
|
leverageBps: number;
|
|
1390
1663
|
notionalAmountUsdPips: string;
|
|
1391
1664
|
slippageBps: number;
|
|
1392
1665
|
pmProvider?: "polymarket" | "kalshi";
|
|
1666
|
+
allowPartialFill?: boolean;
|
|
1667
|
+
minFillBps?: number;
|
|
1668
|
+
}
|
|
1669
|
+
/** @deprecated Renamed to {@link CreateQuoteParams}. Kept as an alias for backward compatibility. */
|
|
1670
|
+
type CreateOfferParams = CreateQuoteParams;
|
|
1671
|
+
interface FeeReportParams {
|
|
1672
|
+
marketTicker: string;
|
|
1673
|
+
effectiveSide: "yes" | "no";
|
|
1674
|
+
leverageBps: number;
|
|
1675
|
+
notionalAmountUsdPips: string;
|
|
1676
|
+
entryPriceUsdPips?: string;
|
|
1393
1677
|
}
|
|
1394
1678
|
declare function isOpenPosition(p: Position): p is OpenPosition;
|
|
1395
1679
|
declare function isClosedPosition(p: Position): p is ClosedPosition;
|
|
1396
1680
|
declare function leverageMaxBps(lev: MarketLeverage, side: "yes" | "no"): number;
|
|
1397
1681
|
|
|
1398
|
-
export {
|
|
1682
|
+
export { type PositionOpenFees as A, type PositionResult as B, type CreateQuoteParams as C, type PositionRisk as D, type PositionTiming as E, type FeeRates as F, type PositionUnwind as G, type PositionUnwindList as H, isClosedPosition as I, isOpenPosition as J, leverageMaxBps as K, type Market as M, type Offer as O, type Position as P, type Quote as Q, type MarketPolymarket as a, type MarketLeverage as b, type PositionTransactions as c, type ContractInfo as d, type CustomerLimit as e, type FeeReportParams as f, type FeeReport as g, type CamelizeKeys as h, type CloseAttempt as i, type ClosedPosition as j, type CreateOfferParams as k, type CreateTokenResult as l, type FeeRatesMarket as m, type FeeRatesOriginationTier as n, type MarketFees as o, type MarketMaxLeveragePerNotional as p, type MarketPrices as q, type MarketSidedEligibility as r, type MarketSidedMaxLeveragePerNotional as s, type OpenPosition as t, type OriginationTier as u, type PendingOperation as v, type PositionClosedFees as w, type PositionCurrent as x, type PositionEntry as y, type PositionFailure as z };
|
|
@@ -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 @@ var notificationCodes = {
|
|
|
25
29
|
|
|
26
30
|
|
|
27
31
|
exports.positionEventTypes = positionEventTypes; exports.marketEventTypes = marketEventTypes; exports.notificationCodes = notificationCodes;
|
|
28
|
-
//# sourceMappingURL=chunk-
|
|
32
|
+
//# sourceMappingURL=chunk-53U53KZ2.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/alexemery/bl/dimes-sdk/dist/chunk-53U53KZ2.cjs","../src/ws/types.ts"],"names":[],"mappings":"AAAA;ACEO,IAAM,mBAAA,EAAqB;AAAA,EAChC,oBAAA;AAAA,EACA,0BAAA;AAAA,EACA,iBAAA;AAAA,EACA,kBAAA;AAAA,EACA,wBAAA;AAAA,EACA,qBAAA;AAAA,EACA,iBAAA;AAAA,EACA,kBAAA;AAAA,EACA,kCAAA;AAAA,EACA,kCAAA;AAAA,EACA,yBAAA;AAAA,EACA,gCAAA;AAAA,EACA,mBAAA;AAAA,EACA;AACF,CAAA;AAkBO,IAAM,iBAAA,EAAmB;AAAA,EAC9B,mBAAA;AAAA,EACA,4BAAA;AAAA,EACA;AACF,CAAA;AA6CO,IAAM,kBAAA,EAAoB;AAAA,EAC/B,wBAAA,EAA0B;AAC5B,CAAA;AD7DA;AACA;AACE;AACA;AACA;AACF,4IAAC","file":"/Users/alexemery/bl/dimes-sdk/dist/chunk-53U53KZ2.cjs","sourcesContent":[null,"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"]}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import {
|
|
2
|
+
marketEventTypes,
|
|
3
|
+
positionEventTypes
|
|
4
|
+
} from "./chunk-PK2PRTQW.mjs";
|
|
5
|
+
|
|
6
|
+
// src/ws/position-socket.ts
|
|
7
|
+
import { camelizeKeys } from "humps";
|
|
8
|
+
import { io } from "socket.io-client";
|
|
9
|
+
var wsNamespace = "/v1/ws/prediction-markets/user-positions";
|
|
10
|
+
function camelizeEnvelope(envelope) {
|
|
11
|
+
return {
|
|
12
|
+
id: envelope.id,
|
|
13
|
+
type: envelope.type,
|
|
14
|
+
createdAt: envelope.created_at,
|
|
15
|
+
data: camelizeKeys(envelope.data)
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
var PositionSocket = class {
|
|
19
|
+
socket = null;
|
|
20
|
+
baseUrl;
|
|
21
|
+
getToken;
|
|
22
|
+
eventListeners = /* @__PURE__ */ new Map();
|
|
23
|
+
connectListeners = /* @__PURE__ */ new Set();
|
|
24
|
+
disconnectListeners = /* @__PURE__ */ new Set();
|
|
25
|
+
errorListeners = /* @__PURE__ */ new Set();
|
|
26
|
+
notificationListeners = /* @__PURE__ */ new Set();
|
|
27
|
+
constructor(options) {
|
|
28
|
+
this.baseUrl = options.baseUrl ?? "https://api.dimes.fi";
|
|
29
|
+
this.getToken = options.getToken;
|
|
30
|
+
}
|
|
31
|
+
get connected() {
|
|
32
|
+
return this.socket?.connected ?? false;
|
|
33
|
+
}
|
|
34
|
+
connect() {
|
|
35
|
+
if (this.socket?.connected) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
this.socket?.disconnect();
|
|
39
|
+
const token = this.getToken();
|
|
40
|
+
if (!token) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const getToken = this.getToken;
|
|
44
|
+
this.socket = io(`${this.baseUrl}${wsNamespace}`, {
|
|
45
|
+
auth: (cb) => cb({ token: getToken() }),
|
|
46
|
+
transports: ["websocket"],
|
|
47
|
+
reconnection: true,
|
|
48
|
+
reconnectionDelay: 1e3,
|
|
49
|
+
reconnectionDelayMax: 3e4
|
|
50
|
+
});
|
|
51
|
+
this.socket.on("connect", () => {
|
|
52
|
+
for (const cb of this.connectListeners) {
|
|
53
|
+
cb();
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
this.socket.on("disconnect", () => {
|
|
57
|
+
for (const cb of this.disconnectListeners) {
|
|
58
|
+
cb();
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
this.socket.on("error", (err) => {
|
|
62
|
+
for (const cb of this.errorListeners) {
|
|
63
|
+
cb(err);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
for (const eventType of positionEventTypes) {
|
|
67
|
+
this.socket.on(eventType, (envelope) => {
|
|
68
|
+
const event = camelizeEnvelope(envelope);
|
|
69
|
+
this.emit(eventType, event);
|
|
70
|
+
this.emit("*", event);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
this.socket.on("notification", (envelope) => {
|
|
74
|
+
const event = {
|
|
75
|
+
id: envelope.id,
|
|
76
|
+
type: "notification",
|
|
77
|
+
createdAt: envelope.created_at,
|
|
78
|
+
data: envelope.data
|
|
79
|
+
};
|
|
80
|
+
for (const cb of this.notificationListeners) {
|
|
81
|
+
cb(event);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
disconnect() {
|
|
86
|
+
this.socket?.disconnect();
|
|
87
|
+
this.socket = null;
|
|
88
|
+
}
|
|
89
|
+
reconnectWithToken() {
|
|
90
|
+
this.disconnect();
|
|
91
|
+
this.connect();
|
|
92
|
+
}
|
|
93
|
+
on(event, cb) {
|
|
94
|
+
let set = this.eventListeners.get(event);
|
|
95
|
+
if (!set) {
|
|
96
|
+
set = /* @__PURE__ */ new Set();
|
|
97
|
+
this.eventListeners.set(event, set);
|
|
98
|
+
}
|
|
99
|
+
set.add(cb);
|
|
100
|
+
return () => set.delete(cb);
|
|
101
|
+
}
|
|
102
|
+
onConnect(cb) {
|
|
103
|
+
this.connectListeners.add(cb);
|
|
104
|
+
return () => this.connectListeners.delete(cb);
|
|
105
|
+
}
|
|
106
|
+
onDisconnect(cb) {
|
|
107
|
+
this.disconnectListeners.add(cb);
|
|
108
|
+
return () => this.disconnectListeners.delete(cb);
|
|
109
|
+
}
|
|
110
|
+
onError(cb) {
|
|
111
|
+
this.errorListeners.add(cb);
|
|
112
|
+
return () => this.errorListeners.delete(cb);
|
|
113
|
+
}
|
|
114
|
+
onNotification(cb) {
|
|
115
|
+
this.notificationListeners.add(cb);
|
|
116
|
+
return () => this.notificationListeners.delete(cb);
|
|
117
|
+
}
|
|
118
|
+
emit(event, data) {
|
|
119
|
+
const set = this.eventListeners.get(event);
|
|
120
|
+
if (!set) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
for (const cb of set) {
|
|
124
|
+
cb(data);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
// src/ws/market-socket.ts
|
|
130
|
+
import { camelizeKeys as camelizeKeys2 } from "humps";
|
|
131
|
+
import { io as io2 } from "socket.io-client";
|
|
132
|
+
var wsNamespace2 = "/v1/ws/prediction-markets/user-markets";
|
|
133
|
+
function camelizeEnvelope2(envelope) {
|
|
134
|
+
return {
|
|
135
|
+
id: envelope.id,
|
|
136
|
+
type: envelope.type,
|
|
137
|
+
createdAt: envelope.created_at,
|
|
138
|
+
data: envelope.data.map((item) => camelizeKeys2(item))
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
var MarketSocket = class {
|
|
142
|
+
socket = null;
|
|
143
|
+
baseUrl;
|
|
144
|
+
getToken;
|
|
145
|
+
eventListeners = /* @__PURE__ */ new Map();
|
|
146
|
+
connectListeners = /* @__PURE__ */ new Set();
|
|
147
|
+
disconnectListeners = /* @__PURE__ */ new Set();
|
|
148
|
+
errorListeners = /* @__PURE__ */ new Set();
|
|
149
|
+
constructor(options) {
|
|
150
|
+
this.baseUrl = options.baseUrl ?? "https://api.dimes.fi";
|
|
151
|
+
this.getToken = options.getToken;
|
|
152
|
+
}
|
|
153
|
+
get connected() {
|
|
154
|
+
return this.socket?.connected ?? false;
|
|
155
|
+
}
|
|
156
|
+
connect() {
|
|
157
|
+
if (this.socket?.connected) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
this.socket?.disconnect();
|
|
161
|
+
const token = this.getToken();
|
|
162
|
+
if (!token) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const getToken = this.getToken;
|
|
166
|
+
this.socket = io2(`${this.baseUrl}${wsNamespace2}`, {
|
|
167
|
+
auth: (cb) => cb({ token: getToken() }),
|
|
168
|
+
transports: ["websocket"],
|
|
169
|
+
reconnection: true,
|
|
170
|
+
reconnectionDelay: 1e3,
|
|
171
|
+
reconnectionDelayMax: 3e4
|
|
172
|
+
});
|
|
173
|
+
this.socket.on("connect", () => {
|
|
174
|
+
for (const cb of this.connectListeners) {
|
|
175
|
+
cb();
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
this.socket.on("disconnect", () => {
|
|
179
|
+
for (const cb of this.disconnectListeners) {
|
|
180
|
+
cb();
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
this.socket.on("error", (err) => {
|
|
184
|
+
for (const cb of this.errorListeners) {
|
|
185
|
+
cb(err);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
for (const eventType of marketEventTypes) {
|
|
189
|
+
this.socket.on(eventType, (envelope) => {
|
|
190
|
+
const event = camelizeEnvelope2(envelope);
|
|
191
|
+
this.emit(eventType, event);
|
|
192
|
+
this.emit("*", event);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
disconnect() {
|
|
197
|
+
this.socket?.disconnect();
|
|
198
|
+
this.socket = null;
|
|
199
|
+
}
|
|
200
|
+
reconnectWithToken() {
|
|
201
|
+
this.disconnect();
|
|
202
|
+
this.connect();
|
|
203
|
+
}
|
|
204
|
+
on(event, cb) {
|
|
205
|
+
let set = this.eventListeners.get(event);
|
|
206
|
+
if (!set) {
|
|
207
|
+
set = /* @__PURE__ */ new Set();
|
|
208
|
+
this.eventListeners.set(event, set);
|
|
209
|
+
}
|
|
210
|
+
set.add(cb);
|
|
211
|
+
return () => set.delete(cb);
|
|
212
|
+
}
|
|
213
|
+
onConnect(cb) {
|
|
214
|
+
this.connectListeners.add(cb);
|
|
215
|
+
return () => this.connectListeners.delete(cb);
|
|
216
|
+
}
|
|
217
|
+
onDisconnect(cb) {
|
|
218
|
+
this.disconnectListeners.add(cb);
|
|
219
|
+
return () => this.disconnectListeners.delete(cb);
|
|
220
|
+
}
|
|
221
|
+
onError(cb) {
|
|
222
|
+
this.errorListeners.add(cb);
|
|
223
|
+
return () => this.errorListeners.delete(cb);
|
|
224
|
+
}
|
|
225
|
+
emit(event, data) {
|
|
226
|
+
const set = this.eventListeners.get(event);
|
|
227
|
+
if (!set) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
for (const cb of set) {
|
|
231
|
+
cb(data);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
export {
|
|
237
|
+
PositionSocket,
|
|
238
|
+
MarketSocket
|
|
239
|
+
};
|
|
240
|
+
//# sourceMappingURL=chunk-5VHDXPRV.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ws/position-socket.ts","../src/ws/market-socket.ts"],"sourcesContent":["import { camelizeKeys } from \"humps\";\nimport { io, type Socket } from \"socket.io-client\";\nimport type { Position } from \"../types\";\nimport {\n positionEventTypes,\n type NotificationEvent,\n type NotificationEventEnvelope,\n type PositionEvent,\n type PositionEventEnvelope,\n type PositionEventType,\n} from \"./types\";\n\nexport interface PositionSocketOptions {\n baseUrl?: string;\n getToken: () => string | null;\n}\n\ntype EventCallback = (event: PositionEvent) => void;\ntype NotificationCallback = (event: NotificationEvent) => void;\ntype ConnectionCallback = () => void;\ntype ErrorCallback = (error: unknown) => void;\n\nconst wsNamespace = \"/v1/ws/prediction-markets/user-positions\";\n\nfunction camelizeEnvelope(envelope: PositionEventEnvelope): PositionEvent {\n return {\n id: envelope.id,\n type: envelope.type,\n createdAt: envelope.created_at,\n data: camelizeKeys(envelope.data) as unknown as Position,\n };\n}\n\nexport class PositionSocket {\n private socket: Socket | null = null;\n\n private readonly baseUrl: string;\n\n private readonly getToken: () => string | null;\n\n private readonly eventListeners = new Map<string, Set<EventCallback>>();\n\n private readonly connectListeners = new Set<ConnectionCallback>();\n\n private readonly disconnectListeners = new Set<ConnectionCallback>();\n\n private readonly errorListeners = new Set<ErrorCallback>();\n\n private readonly notificationListeners = new Set<NotificationCallback>();\n\n constructor(options: PositionSocketOptions) {\n this.baseUrl = options.baseUrl ?? \"https://api.dimes.fi\";\n this.getToken = options.getToken;\n }\n\n public get connected(): boolean {\n return this.socket?.connected ?? false;\n }\n\n public connect(): void {\n if (this.socket?.connected) {\n return;\n }\n\n this.socket?.disconnect();\n\n const token = this.getToken();\n if (!token) {\n return;\n }\n\n const getToken = this.getToken;\n this.socket = io(`${this.baseUrl}${wsNamespace}`, {\n auth: (cb) => cb({ token: getToken() }),\n transports: [\"websocket\"],\n reconnection: true,\n reconnectionDelay: 1000,\n reconnectionDelayMax: 30000,\n });\n\n this.socket.on(\"connect\", () => {\n for (const cb of this.connectListeners) {\n cb();\n }\n });\n\n this.socket.on(\"disconnect\", () => {\n for (const cb of this.disconnectListeners) {\n cb();\n }\n });\n\n this.socket.on(\"error\", (err: unknown) => {\n for (const cb of this.errorListeners) {\n cb(err);\n }\n });\n\n for (const eventType of positionEventTypes) {\n this.socket.on(eventType, (envelope: PositionEventEnvelope) => {\n const event = camelizeEnvelope(envelope);\n this.emit(eventType, event);\n this.emit(\"*\", event);\n });\n }\n\n this.socket.on(\"notification\", (envelope: NotificationEventEnvelope) => {\n const event: NotificationEvent = {\n id: envelope.id,\n type: \"notification\",\n createdAt: envelope.created_at,\n data: envelope.data,\n };\n for (const cb of this.notificationListeners) {\n cb(event);\n }\n });\n }\n\n public disconnect(): void {\n this.socket?.disconnect();\n this.socket = null;\n }\n\n public reconnectWithToken(): void {\n this.disconnect();\n this.connect();\n }\n\n public on(event: PositionEventType | \"*\", cb: EventCallback): () => void {\n let set = this.eventListeners.get(event);\n if (!set) {\n set = new Set();\n this.eventListeners.set(event, set);\n }\n set.add(cb);\n return () => set.delete(cb);\n }\n\n public onConnect(cb: ConnectionCallback): () => void {\n this.connectListeners.add(cb);\n return () => this.connectListeners.delete(cb);\n }\n\n public onDisconnect(cb: ConnectionCallback): () => void {\n this.disconnectListeners.add(cb);\n return () => this.disconnectListeners.delete(cb);\n }\n\n public onError(cb: ErrorCallback): () => void {\n this.errorListeners.add(cb);\n return () => this.errorListeners.delete(cb);\n }\n\n public onNotification(cb: NotificationCallback): () => void {\n this.notificationListeners.add(cb);\n return () => this.notificationListeners.delete(cb);\n }\n\n private emit(event: string, data: PositionEvent): void {\n const set = this.eventListeners.get(event);\n if (!set) {\n return;\n }\n for (const cb of set) {\n cb(data);\n }\n }\n}\n","import { camelizeKeys } from \"humps\";\nimport { io, type Socket } from \"socket.io-client\";\nimport type { Market } from \"../types\";\nimport {\n marketEventTypes,\n type MarketDelta,\n type MarketEvent,\n type MarketEventEnvelope,\n type MarketEventType,\n} from \"./types\";\n\nexport interface MarketSocketOptions {\n baseUrl?: string;\n getToken: () => string | null;\n}\n\ntype EventCallback = (event: MarketEvent) => void;\ntype ConnectionCallback = () => void;\ntype ErrorCallback = (error: unknown) => void;\n\nconst wsNamespace = \"/v1/ws/prediction-markets/user-markets\";\n\nfunction camelizeEnvelope(envelope: MarketEventEnvelope): MarketEvent {\n return {\n id: envelope.id,\n type: envelope.type,\n createdAt: envelope.created_at,\n data: envelope.data.map((item) => camelizeKeys(item)) as unknown as Market[] | MarketDelta[],\n };\n}\n\nexport class MarketSocket {\n private socket: Socket | null = null;\n\n private readonly baseUrl: string;\n\n private readonly getToken: () => string | null;\n\n private readonly eventListeners = new Map<string, Set<EventCallback>>();\n\n private readonly connectListeners = new Set<ConnectionCallback>();\n\n private readonly disconnectListeners = new Set<ConnectionCallback>();\n\n private readonly errorListeners = new Set<ErrorCallback>();\n\n constructor(options: MarketSocketOptions) {\n this.baseUrl = options.baseUrl ?? \"https://api.dimes.fi\";\n this.getToken = options.getToken;\n }\n\n public get connected(): boolean {\n return this.socket?.connected ?? false;\n }\n\n public connect(): void {\n if (this.socket?.connected) {\n return;\n }\n\n this.socket?.disconnect();\n\n const token = this.getToken();\n if (!token) {\n return;\n }\n\n const getToken = this.getToken;\n this.socket = io(`${this.baseUrl}${wsNamespace}`, {\n auth: (cb) => cb({ token: getToken() }),\n transports: [\"websocket\"],\n reconnection: true,\n reconnectionDelay: 1000,\n reconnectionDelayMax: 30000,\n });\n\n this.socket.on(\"connect\", () => {\n for (const cb of this.connectListeners) {\n cb();\n }\n });\n\n this.socket.on(\"disconnect\", () => {\n for (const cb of this.disconnectListeners) {\n cb();\n }\n });\n\n this.socket.on(\"error\", (err: unknown) => {\n for (const cb of this.errorListeners) {\n cb(err);\n }\n });\n\n for (const eventType of marketEventTypes) {\n this.socket.on(eventType, (envelope: MarketEventEnvelope) => {\n const event = camelizeEnvelope(envelope);\n this.emit(eventType, event);\n this.emit(\"*\", event);\n });\n }\n }\n\n public disconnect(): void {\n this.socket?.disconnect();\n this.socket = null;\n }\n\n public reconnectWithToken(): void {\n this.disconnect();\n this.connect();\n }\n\n public on(event: MarketEventType | \"*\", cb: EventCallback): () => void {\n let set = this.eventListeners.get(event);\n if (!set) {\n set = new Set();\n this.eventListeners.set(event, set);\n }\n set.add(cb);\n return () => set.delete(cb);\n }\n\n public onConnect(cb: ConnectionCallback): () => void {\n this.connectListeners.add(cb);\n return () => this.connectListeners.delete(cb);\n }\n\n public onDisconnect(cb: ConnectionCallback): () => void {\n this.disconnectListeners.add(cb);\n return () => this.disconnectListeners.delete(cb);\n }\n\n public onError(cb: ErrorCallback): () => void {\n this.errorListeners.add(cb);\n return () => this.errorListeners.delete(cb);\n }\n\n private emit(event: string, data: MarketEvent): void {\n const set = this.eventListeners.get(event);\n if (!set) {\n return;\n }\n for (const cb of set) {\n cb(data);\n }\n }\n}\n"],"mappings":";;;;;;AAAA,SAAS,oBAAoB;AAC7B,SAAS,UAAuB;AAqBhC,IAAM,cAAc;AAEpB,SA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