@adaptic/utils 0.0.379 → 0.0.380

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/test.js CHANGED
@@ -6147,22 +6147,28 @@ class AlpacaMarketDataAPI extends EventEmitter {
6147
6147
  v1beta1url;
6148
6148
  stockStreamUrl = 'wss://stream.data.alpaca.markets/v2/sip'; // production values
6149
6149
  optionStreamUrl = 'wss://stream.data.alpaca.markets/v1beta3/options'; // production values
6150
+ cryptoStreamUrl = 'wss://stream.data.alpaca.markets/v1beta3/crypto/us'; // production values
6150
6151
  stockWs = null;
6151
6152
  optionWs = null;
6153
+ cryptoWs = null;
6152
6154
  stockSubscriptions = { trades: [], quotes: [], bars: [] };
6153
6155
  optionSubscriptions = { trades: [], quotes: [], bars: [] };
6156
+ cryptoSubscriptions = { trades: [], quotes: [], bars: [], dailyBars: [], updatedBars: [], orderbooks: [] };
6154
6157
  setMode(mode = 'production') {
6155
6158
  if (mode === 'sandbox') { // sandbox mode
6156
6159
  this.stockStreamUrl = 'wss://stream.data.sandbox.alpaca.markets/v2/sip';
6157
6160
  this.optionStreamUrl = 'wss://stream.data.sandbox.alpaca.markets/v1beta3/options';
6161
+ this.cryptoStreamUrl = 'wss://stream.data.sandbox.alpaca.markets/v1beta3/crypto/us';
6158
6162
  }
6159
6163
  else if (mode === 'test') { // test mode, can only use ticker FAKEPACA
6160
6164
  this.stockStreamUrl = 'wss://stream.data.alpaca.markets/v2/test';
6161
6165
  this.optionStreamUrl = 'wss://stream.data.alpaca.markets/v1beta3/options'; // there's no test mode for options
6166
+ this.cryptoStreamUrl = 'wss://stream.data.alpaca.markets/v1beta3/crypto/us'; // there's no test mode for crypto
6162
6167
  }
6163
6168
  else { // production
6164
6169
  this.stockStreamUrl = 'wss://stream.data.alpaca.markets/v2/sip';
6165
6170
  this.optionStreamUrl = 'wss://stream.data.alpaca.markets/v1beta3/options';
6171
+ this.cryptoStreamUrl = 'wss://stream.data.alpaca.markets/v1beta3/crypto/us';
6166
6172
  }
6167
6173
  }
6168
6174
  getMode() {
@@ -6204,14 +6210,17 @@ class AlpacaMarketDataAPI extends EventEmitter {
6204
6210
  return super.emit(event, ...args);
6205
6211
  }
6206
6212
  connect(streamType) {
6207
- const url = streamType === 'stock' ? this.stockStreamUrl : this.optionStreamUrl;
6213
+ const url = streamType === 'stock' ? this.stockStreamUrl : streamType === 'option' ? this.optionStreamUrl : this.cryptoStreamUrl;
6208
6214
  const ws = new WebSocket(url);
6209
6215
  if (streamType === 'stock') {
6210
6216
  this.stockWs = ws;
6211
6217
  }
6212
- else {
6218
+ else if (streamType === 'option') {
6213
6219
  this.optionWs = ws;
6214
6220
  }
6221
+ else {
6222
+ this.cryptoWs = ws;
6223
+ }
6215
6224
  ws.on('open', () => {
6216
6225
  log$1(`${streamType} stream connected`, { type: 'info' });
6217
6226
  const authMessage = {
@@ -6243,9 +6252,12 @@ class AlpacaMarketDataAPI extends EventEmitter {
6243
6252
  if (streamType === 'stock') {
6244
6253
  this.stockWs = null;
6245
6254
  }
6246
- else {
6255
+ else if (streamType === 'option') {
6247
6256
  this.optionWs = null;
6248
6257
  }
6258
+ else {
6259
+ this.cryptoWs = null;
6260
+ }
6249
6261
  // Optional: implement reconnect logic
6250
6262
  });
6251
6263
  ws.on('error', (error) => {
@@ -6253,19 +6265,31 @@ class AlpacaMarketDataAPI extends EventEmitter {
6253
6265
  });
6254
6266
  }
6255
6267
  sendSubscription(streamType) {
6256
- const ws = streamType === 'stock' ? this.stockWs : this.optionWs;
6257
- const subscriptions = streamType === 'stock' ? this.stockSubscriptions : this.optionSubscriptions;
6268
+ const ws = streamType === 'stock' ? this.stockWs : streamType === 'option' ? this.optionWs : this.cryptoWs;
6269
+ const subscriptions = streamType === 'stock' ? this.stockSubscriptions : streamType === 'option' ? this.optionSubscriptions : this.cryptoSubscriptions;
6258
6270
  if (ws && ws.readyState === WebSocket.OPEN) {
6259
6271
  const subMessagePayload = {};
6260
- if (subscriptions.trades.length > 0) {
6272
+ if (subscriptions.trades && subscriptions.trades.length > 0) {
6261
6273
  subMessagePayload.trades = subscriptions.trades;
6262
6274
  }
6263
- if (subscriptions.quotes.length > 0) {
6275
+ if (subscriptions.quotes && subscriptions.quotes.length > 0) {
6264
6276
  subMessagePayload.quotes = subscriptions.quotes;
6265
6277
  }
6266
- if (subscriptions.bars.length > 0) {
6278
+ if (subscriptions.bars && subscriptions.bars.length > 0) {
6267
6279
  subMessagePayload.bars = subscriptions.bars;
6268
6280
  }
6281
+ // Crypto-specific subscription types
6282
+ if (streamType === 'crypto') {
6283
+ if (subscriptions.dailyBars && subscriptions.dailyBars.length > 0) {
6284
+ subMessagePayload.dailyBars = subscriptions.dailyBars;
6285
+ }
6286
+ if (subscriptions.updatedBars && subscriptions.updatedBars.length > 0) {
6287
+ subMessagePayload.updatedBars = subscriptions.updatedBars;
6288
+ }
6289
+ if (subscriptions.orderbooks && subscriptions.orderbooks.length > 0) {
6290
+ subMessagePayload.orderbooks = subscriptions.orderbooks;
6291
+ }
6292
+ }
6269
6293
  if (Object.keys(subMessagePayload).length > 0) {
6270
6294
  const subMessage = {
6271
6295
  action: 'subscribe',
@@ -6295,8 +6319,18 @@ class AlpacaMarketDataAPI extends EventEmitter {
6295
6319
  this.optionWs.close();
6296
6320
  }
6297
6321
  }
6322
+ connectCryptoStream() {
6323
+ if (!this.cryptoWs) {
6324
+ this.connect('crypto');
6325
+ }
6326
+ }
6327
+ disconnectCryptoStream() {
6328
+ if (this.cryptoWs) {
6329
+ this.cryptoWs.close();
6330
+ }
6331
+ }
6298
6332
  subscribe(streamType, subscriptions) {
6299
- const currentSubscriptions = streamType === 'stock' ? this.stockSubscriptions : this.optionSubscriptions;
6333
+ const currentSubscriptions = streamType === 'stock' ? this.stockSubscriptions : streamType === 'option' ? this.optionSubscriptions : this.cryptoSubscriptions;
6300
6334
  Object.entries(subscriptions).forEach(([key, value]) => {
6301
6335
  if (value) {
6302
6336
  currentSubscriptions[key] = [...new Set([...(currentSubscriptions[key] || []), ...value])];
@@ -6305,7 +6339,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
6305
6339
  this.sendSubscription(streamType);
6306
6340
  }
6307
6341
  unsubscribe(streamType, subscriptions) {
6308
- const currentSubscriptions = streamType === 'stock' ? this.stockSubscriptions : this.optionSubscriptions;
6342
+ const currentSubscriptions = streamType === 'stock' ? this.stockSubscriptions : streamType === 'option' ? this.optionSubscriptions : this.cryptoSubscriptions;
6309
6343
  Object.entries(subscriptions).forEach(([key, value]) => {
6310
6344
  if (value) {
6311
6345
  currentSubscriptions[key] = (currentSubscriptions[key] || []).filter(s => !value.includes(s));
@@ -6315,7 +6349,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
6315
6349
  action: 'unsubscribe',
6316
6350
  ...subscriptions,
6317
6351
  };
6318
- const ws = streamType === 'stock' ? this.stockWs : this.optionWs;
6352
+ const ws = streamType === 'stock' ? this.stockWs : streamType === 'option' ? this.optionWs : this.cryptoWs;
6319
6353
  if (ws && ws.readyState === WebSocket.OPEN) {
6320
6354
  ws.send(JSON.stringify(unsubMessage));
6321
6355
  }