@nevuamarkets/poly-websockets 0.0.4 → 0.1.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/dist/logger.js CHANGED
@@ -7,7 +7,7 @@ exports.logger = void 0;
7
7
  const winston_1 = __importDefault(require("winston"));
8
8
  // Override with LOG_LEVEL environment variable (e.g., LOG_LEVEL=info npm start)
9
9
  exports.logger = winston_1.default.createLogger({
10
- level: process.env.LOG_LEVEL || 'error',
10
+ level: process.env.LOG_LEVEL || 'warn',
11
11
  format: winston_1.default.format.combine(winston_1.default.format.timestamp(), winston_1.default.format.errors({ stack: true }), winston_1.default.format.colorize(), winston_1.default.format.printf(({ level, message, timestamp, ...rest }) => {
12
12
  // Ensure consistent order: timestamp, level, message, then rest of fields
13
13
  const restString = Object.keys(rest)
@@ -180,7 +180,7 @@ class GroupSocket {
180
180
  }
181
181
  }
182
182
  async handlePriceChangeEvents(priceChangeEvents) {
183
- var _a, _b, _c, _d, _e, _f, _g, _h;
183
+ var _a, _b, _c, _d;
184
184
  if (priceChangeEvents.length) {
185
185
  await ((_b = (_a = this.handlers).onPriceChange) === null || _b === void 0 ? void 0 : _b.call(_a, priceChangeEvents));
186
186
  for (const event of priceChangeEvents) {
@@ -189,10 +189,10 @@ class GroupSocket {
189
189
  }
190
190
  catch (err) {
191
191
  logger_1.logger.warn({
192
- message: `Skipping price_change: book not found for asset`,
192
+ message: `Skipping derived future price calculation price_change: book not found for asset`,
193
193
  asset_id: event.asset_id,
194
194
  event: event,
195
- error: err
195
+ error: err === null || err === void 0 ? void 0 : err.message
196
196
  });
197
197
  continue;
198
198
  }
@@ -202,12 +202,11 @@ class GroupSocket {
202
202
  }
203
203
  catch (err) {
204
204
  logger_1.logger.warn({
205
- message: 'Skipping price_change: error calculating spread',
205
+ message: 'Skipping derived future price calculation for price_change: error calculating spread',
206
206
  asset_id: event.asset_id,
207
207
  event: event,
208
- error: err
208
+ error: err === null || err === void 0 ? void 0 : err.message
209
209
  });
210
- await ((_d = (_c = this.handlers).onError) === null || _d === void 0 ? void 0 : _d.call(_c, err));
211
210
  continue;
212
211
  }
213
212
  if (!spreadOver10Cents) {
@@ -217,18 +216,17 @@ class GroupSocket {
217
216
  }
218
217
  catch (err) {
219
218
  logger_1.logger.warn({
220
- message: 'Skipping price_change: error calculating midpoint',
219
+ message: 'Skipping derived future price calculation for price_change: error calculating midpoint',
221
220
  asset_id: event.asset_id,
222
221
  event: event,
223
- error: err
222
+ error: err === null || err === void 0 ? void 0 : err.message
224
223
  });
225
- await ((_f = (_e = this.handlers).onError) === null || _f === void 0 ? void 0 : _f.call(_e, err));
226
224
  continue;
227
225
  }
228
226
  const bookEntry = this.bookCache.getBookEntry(event.asset_id);
229
227
  if (!bookEntry) {
230
228
  logger_1.logger.warn({
231
- message: 'Skipping price_change: book not found for asset',
229
+ message: 'Skipping derived future price calculation price_change: book not found for asset',
232
230
  asset_id: event.asset_id,
233
231
  event: event,
234
232
  });
@@ -246,14 +244,14 @@ class GroupSocket {
246
244
  midpoint: bookEntry.midpoint || '',
247
245
  spread: bookEntry.spread || '',
248
246
  };
249
- await ((_h = (_g = this.handlers).onPolymarketPriceUpdate) === null || _h === void 0 ? void 0 : _h.call(_g, [priceUpdateEvent]));
247
+ await ((_d = (_c = this.handlers).onPolymarketPriceUpdate) === null || _d === void 0 ? void 0 : _d.call(_c, [priceUpdateEvent]));
250
248
  }
251
249
  }
252
250
  }
253
251
  }
254
252
  }
255
253
  async handleLastTradeEvents(lastTradeEvents) {
256
- var _a, _b, _c, _d, _e, _f;
254
+ var _a, _b, _c, _d;
257
255
  if (lastTradeEvents.length) {
258
256
  /*
259
257
  Note: There is no need to edit the book here. According to the docs, a separate
@@ -269,12 +267,11 @@ class GroupSocket {
269
267
  }
270
268
  catch (err) {
271
269
  logger_1.logger.warn({
272
- message: 'Skipping last_trade_price: error calculating spread',
270
+ message: 'Skipping derived future price calculation for last_trade_price: error calculating spread',
273
271
  asset_id: event.asset_id,
274
272
  event: event,
275
- error: err
273
+ error: err === null || err === void 0 ? void 0 : err.message
276
274
  });
277
- await ((_d = (_c = this.handlers).onError) === null || _d === void 0 ? void 0 : _d.call(_c, err));
278
275
  continue;
279
276
  }
280
277
  if (spreadOver10Cents) {
@@ -283,7 +280,7 @@ class GroupSocket {
283
280
  const bookEntry = this.bookCache.getBookEntry(event.asset_id);
284
281
  if (!bookEntry) {
285
282
  logger_1.logger.warn({
286
- message: 'Skipping last_trade_price: book not found for asset',
283
+ message: 'Skipping derived future price calculation last_trade_price: book not found for asset',
287
284
  asset_id: event.asset_id,
288
285
  event: event,
289
286
  });
@@ -301,7 +298,7 @@ class GroupSocket {
301
298
  midpoint: bookEntry.midpoint || '',
302
299
  spread: bookEntry.spread || '',
303
300
  };
304
- await ((_f = (_e = this.handlers).onPolymarketPriceUpdate) === null || _f === void 0 ? void 0 : _f.call(_e, [priceUpdateEvent]));
301
+ await ((_d = (_c = this.handlers).onPolymarketPriceUpdate) === null || _d === void 0 ? void 0 : _d.call(_c, [priceUpdateEvent]));
305
302
  }
306
303
  }
307
304
  }
@@ -89,9 +89,9 @@ class OrderBookCache {
89
89
  if (!book)
90
90
  throw new Error(`Book for ${assetId} not cached`);
91
91
  if (book.asks.length === 0)
92
- throw new Error('No asks in book');
92
+ throw new Error(`No asks in book for ${assetId}`);
93
93
  if (book.bids.length === 0)
94
- throw new Error('No bids in book');
94
+ throw new Error(`No bids in book for ${assetId}`);
95
95
  /*
96
96
  * Polymarket book events are currently sorted as such:
97
97
  * - bids ascending
@@ -126,9 +126,9 @@ class OrderBookCache {
126
126
  if (!book)
127
127
  throw new Error(`Book for ${assetId} not cached`);
128
128
  if (book.asks.length === 0)
129
- throw new Error('No asks in book');
129
+ throw new Error(`No asks in book for ${assetId}`);
130
130
  if (book.bids.length === 0)
131
- throw new Error('No bids in book');
131
+ throw new Error(`No bids in book for ${assetId}`);
132
132
  /*
133
133
  * Polymarket book events are currently sorted as such:
134
134
  * - bids ascending
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nevuamarkets/poly-websockets",
3
- "version": "0.0.4",
3
+ "version": "0.1.0",
4
4
  "description": "Plug-and-play Polymarket WebSocket price alerts",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/logger.ts CHANGED
@@ -1,9 +1,8 @@
1
1
  import winston from 'winston';
2
2
 
3
-
4
3
  // Override with LOG_LEVEL environment variable (e.g., LOG_LEVEL=info npm start)
5
4
  export const logger = winston.createLogger({
6
- level: process.env.LOG_LEVEL || 'error',
5
+ level: process.env.LOG_LEVEL || 'warn',
7
6
  format: winston.format.combine(
8
7
  winston.format.timestamp(),
9
8
  winston.format.errors({ stack: true }),
@@ -212,12 +212,12 @@ export class GroupSocket {
212
212
  for (const event of priceChangeEvents) {
213
213
  try {
214
214
  this.bookCache.upsertPriceChange(event);
215
- } catch (err) {
215
+ } catch (err: any) {
216
216
  logger.warn({
217
- message: `Skipping price_change: book not found for asset`,
217
+ message: `Skipping derived future price calculation price_change: book not found for asset`,
218
218
  asset_id: event.asset_id,
219
219
  event: event,
220
- error: err
220
+ error: err?.message
221
221
  });
222
222
  continue;
223
223
  }
@@ -225,14 +225,13 @@ export class GroupSocket {
225
225
  let spreadOver10Cents: boolean;
226
226
  try {
227
227
  spreadOver10Cents = this.bookCache.spreadOver(event.asset_id, 0.1);
228
- } catch (err) {
228
+ } catch (err: any) {
229
229
  logger.warn({
230
- message: 'Skipping price_change: error calculating spread',
230
+ message: 'Skipping derived future price calculation for price_change: error calculating spread',
231
231
  asset_id: event.asset_id,
232
232
  event: event,
233
- error: err
233
+ error: err?.message
234
234
  });
235
- await this.handlers.onError?.(err as Error);
236
235
  continue;
237
236
  }
238
237
 
@@ -240,21 +239,20 @@ export class GroupSocket {
240
239
  let newPrice: string;
241
240
  try {
242
241
  newPrice = this.bookCache.midpoint(event.asset_id);
243
- } catch (err) {
242
+ } catch (err: any) {
244
243
  logger.warn({
245
- message: 'Skipping price_change: error calculating midpoint',
244
+ message: 'Skipping derived future price calculation for price_change: error calculating midpoint',
246
245
  asset_id: event.asset_id,
247
246
  event: event,
248
- error: err
247
+ error: err?.message
249
248
  });
250
- await this.handlers.onError?.(err as Error);
251
249
  continue;
252
250
  }
253
251
 
254
252
  const bookEntry: BookEntry | null = this.bookCache.getBookEntry(event.asset_id);
255
253
  if (!bookEntry) {
256
254
  logger.warn({
257
- message: 'Skipping price_change: book not found for asset',
255
+ message: 'Skipping derived future price calculation price_change: book not found for asset',
258
256
  asset_id: event.asset_id,
259
257
  event: event,
260
258
  });
@@ -294,14 +292,14 @@ export class GroupSocket {
294
292
  let spreadOver10Cents: boolean;
295
293
  try {
296
294
  spreadOver10Cents = this.bookCache.spreadOver(event.asset_id, 0.1);
297
- } catch (err) {
295
+ } catch (err: any) {
298
296
  logger.warn({
299
- message: 'Skipping last_trade_price: error calculating spread',
297
+ message: 'Skipping derived future price calculation for last_trade_price: error calculating spread',
300
298
  asset_id: event.asset_id,
301
299
  event: event,
302
- error: err
300
+ error: err?.message
303
301
  });
304
- await this.handlers.onError?.(err as Error);
302
+
305
303
  continue;
306
304
  }
307
305
  if (spreadOver10Cents) {
@@ -311,7 +309,7 @@ export class GroupSocket {
311
309
  const bookEntry: BookEntry | null = this.bookCache.getBookEntry(event.asset_id);
312
310
  if (!bookEntry) {
313
311
  logger.warn({
314
- message: 'Skipping last_trade_price: book not found for asset',
312
+ message: 'Skipping derived future price calculation last_trade_price: book not found for asset',
315
313
  asset_id: event.asset_id,
316
314
  event: event,
317
315
  });
@@ -113,8 +113,8 @@ export class OrderBookCache {
113
113
  public spreadOver(assetId: string, cents = 0.1): boolean {
114
114
  const book = this.bookCache[assetId];
115
115
  if (!book) throw new Error(`Book for ${assetId} not cached`);
116
- if (book.asks.length === 0) throw new Error('No asks in book');
117
- if (book.bids.length === 0) throw new Error('No bids in book');
116
+ if (book.asks.length === 0) throw new Error(`No asks in book for ${assetId}`);
117
+ if (book.bids.length === 0) throw new Error(`No bids in book for ${assetId}`);
118
118
 
119
119
  /*
120
120
  * Polymarket book events are currently sorted as such:
@@ -155,8 +155,8 @@ export class OrderBookCache {
155
155
  public midpoint(assetId: string): string {
156
156
  const book = this.bookCache[assetId];
157
157
  if (!book) throw new Error(`Book for ${assetId} not cached`);
158
- if (book.asks.length === 0) throw new Error('No asks in book');
159
- if (book.bids.length === 0) throw new Error('No bids in book');
158
+ if (book.asks.length === 0) throw new Error(`No asks in book for ${assetId}`);
159
+ if (book.bids.length === 0) throw new Error(`No bids in book for ${assetId}`);
160
160
 
161
161
  /*
162
162
  * Polymarket book events are currently sorted as such: