@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/index.cjs +45 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +45 -11
- package/dist/index.mjs.map +1 -1
- package/dist/test.js +45 -11
- package/dist/test.js.map +1 -1
- package/dist/types/alpaca-market-data-api.d.ts +16 -3
- package/dist/types/alpaca-market-data-api.d.ts.map +1 -1
- package/dist/types/types/alpaca-types.d.ts +94 -0
- package/dist/types/types/alpaca-types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -11478,22 +11478,28 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
|
|
|
11478
11478
|
v1beta1url;
|
|
11479
11479
|
stockStreamUrl = 'wss://stream.data.alpaca.markets/v2/sip'; // production values
|
|
11480
11480
|
optionStreamUrl = 'wss://stream.data.alpaca.markets/v1beta3/options'; // production values
|
|
11481
|
+
cryptoStreamUrl = 'wss://stream.data.alpaca.markets/v1beta3/crypto/us'; // production values
|
|
11481
11482
|
stockWs = null;
|
|
11482
11483
|
optionWs = null;
|
|
11484
|
+
cryptoWs = null;
|
|
11483
11485
|
stockSubscriptions = { trades: [], quotes: [], bars: [] };
|
|
11484
11486
|
optionSubscriptions = { trades: [], quotes: [], bars: [] };
|
|
11487
|
+
cryptoSubscriptions = { trades: [], quotes: [], bars: [], dailyBars: [], updatedBars: [], orderbooks: [] };
|
|
11485
11488
|
setMode(mode = 'production') {
|
|
11486
11489
|
if (mode === 'sandbox') { // sandbox mode
|
|
11487
11490
|
this.stockStreamUrl = 'wss://stream.data.sandbox.alpaca.markets/v2/sip';
|
|
11488
11491
|
this.optionStreamUrl = 'wss://stream.data.sandbox.alpaca.markets/v1beta3/options';
|
|
11492
|
+
this.cryptoStreamUrl = 'wss://stream.data.sandbox.alpaca.markets/v1beta3/crypto/us';
|
|
11489
11493
|
}
|
|
11490
11494
|
else if (mode === 'test') { // test mode, can only use ticker FAKEPACA
|
|
11491
11495
|
this.stockStreamUrl = 'wss://stream.data.alpaca.markets/v2/test';
|
|
11492
11496
|
this.optionStreamUrl = 'wss://stream.data.alpaca.markets/v1beta3/options'; // there's no test mode for options
|
|
11497
|
+
this.cryptoStreamUrl = 'wss://stream.data.alpaca.markets/v1beta3/crypto/us'; // there's no test mode for crypto
|
|
11493
11498
|
}
|
|
11494
11499
|
else { // production
|
|
11495
11500
|
this.stockStreamUrl = 'wss://stream.data.alpaca.markets/v2/sip';
|
|
11496
11501
|
this.optionStreamUrl = 'wss://stream.data.alpaca.markets/v1beta3/options';
|
|
11502
|
+
this.cryptoStreamUrl = 'wss://stream.data.alpaca.markets/v1beta3/crypto/us';
|
|
11497
11503
|
}
|
|
11498
11504
|
}
|
|
11499
11505
|
getMode() {
|
|
@@ -11535,14 +11541,17 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
|
|
|
11535
11541
|
return super.emit(event, ...args);
|
|
11536
11542
|
}
|
|
11537
11543
|
connect(streamType) {
|
|
11538
|
-
const url = streamType === 'stock' ? this.stockStreamUrl : this.optionStreamUrl;
|
|
11544
|
+
const url = streamType === 'stock' ? this.stockStreamUrl : streamType === 'option' ? this.optionStreamUrl : this.cryptoStreamUrl;
|
|
11539
11545
|
const ws = new WebSocket(url);
|
|
11540
11546
|
if (streamType === 'stock') {
|
|
11541
11547
|
this.stockWs = ws;
|
|
11542
11548
|
}
|
|
11543
|
-
else {
|
|
11549
|
+
else if (streamType === 'option') {
|
|
11544
11550
|
this.optionWs = ws;
|
|
11545
11551
|
}
|
|
11552
|
+
else {
|
|
11553
|
+
this.cryptoWs = ws;
|
|
11554
|
+
}
|
|
11546
11555
|
ws.on('open', () => {
|
|
11547
11556
|
log(`${streamType} stream connected`, { type: 'info' });
|
|
11548
11557
|
const authMessage = {
|
|
@@ -11574,9 +11583,12 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
|
|
|
11574
11583
|
if (streamType === 'stock') {
|
|
11575
11584
|
this.stockWs = null;
|
|
11576
11585
|
}
|
|
11577
|
-
else {
|
|
11586
|
+
else if (streamType === 'option') {
|
|
11578
11587
|
this.optionWs = null;
|
|
11579
11588
|
}
|
|
11589
|
+
else {
|
|
11590
|
+
this.cryptoWs = null;
|
|
11591
|
+
}
|
|
11580
11592
|
// Optional: implement reconnect logic
|
|
11581
11593
|
});
|
|
11582
11594
|
ws.on('error', (error) => {
|
|
@@ -11584,19 +11596,31 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
|
|
|
11584
11596
|
});
|
|
11585
11597
|
}
|
|
11586
11598
|
sendSubscription(streamType) {
|
|
11587
|
-
const ws = streamType === 'stock' ? this.stockWs : this.optionWs;
|
|
11588
|
-
const subscriptions = streamType === 'stock' ? this.stockSubscriptions : this.optionSubscriptions;
|
|
11599
|
+
const ws = streamType === 'stock' ? this.stockWs : streamType === 'option' ? this.optionWs : this.cryptoWs;
|
|
11600
|
+
const subscriptions = streamType === 'stock' ? this.stockSubscriptions : streamType === 'option' ? this.optionSubscriptions : this.cryptoSubscriptions;
|
|
11589
11601
|
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
11590
11602
|
const subMessagePayload = {};
|
|
11591
|
-
if (subscriptions.trades.length > 0) {
|
|
11603
|
+
if (subscriptions.trades && subscriptions.trades.length > 0) {
|
|
11592
11604
|
subMessagePayload.trades = subscriptions.trades;
|
|
11593
11605
|
}
|
|
11594
|
-
if (subscriptions.quotes.length > 0) {
|
|
11606
|
+
if (subscriptions.quotes && subscriptions.quotes.length > 0) {
|
|
11595
11607
|
subMessagePayload.quotes = subscriptions.quotes;
|
|
11596
11608
|
}
|
|
11597
|
-
if (subscriptions.bars.length > 0) {
|
|
11609
|
+
if (subscriptions.bars && subscriptions.bars.length > 0) {
|
|
11598
11610
|
subMessagePayload.bars = subscriptions.bars;
|
|
11599
11611
|
}
|
|
11612
|
+
// Crypto-specific subscription types
|
|
11613
|
+
if (streamType === 'crypto') {
|
|
11614
|
+
if (subscriptions.dailyBars && subscriptions.dailyBars.length > 0) {
|
|
11615
|
+
subMessagePayload.dailyBars = subscriptions.dailyBars;
|
|
11616
|
+
}
|
|
11617
|
+
if (subscriptions.updatedBars && subscriptions.updatedBars.length > 0) {
|
|
11618
|
+
subMessagePayload.updatedBars = subscriptions.updatedBars;
|
|
11619
|
+
}
|
|
11620
|
+
if (subscriptions.orderbooks && subscriptions.orderbooks.length > 0) {
|
|
11621
|
+
subMessagePayload.orderbooks = subscriptions.orderbooks;
|
|
11622
|
+
}
|
|
11623
|
+
}
|
|
11600
11624
|
if (Object.keys(subMessagePayload).length > 0) {
|
|
11601
11625
|
const subMessage = {
|
|
11602
11626
|
action: 'subscribe',
|
|
@@ -11626,8 +11650,18 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
|
|
|
11626
11650
|
this.optionWs.close();
|
|
11627
11651
|
}
|
|
11628
11652
|
}
|
|
11653
|
+
connectCryptoStream() {
|
|
11654
|
+
if (!this.cryptoWs) {
|
|
11655
|
+
this.connect('crypto');
|
|
11656
|
+
}
|
|
11657
|
+
}
|
|
11658
|
+
disconnectCryptoStream() {
|
|
11659
|
+
if (this.cryptoWs) {
|
|
11660
|
+
this.cryptoWs.close();
|
|
11661
|
+
}
|
|
11662
|
+
}
|
|
11629
11663
|
subscribe(streamType, subscriptions) {
|
|
11630
|
-
const currentSubscriptions = streamType === 'stock' ? this.stockSubscriptions : this.optionSubscriptions;
|
|
11664
|
+
const currentSubscriptions = streamType === 'stock' ? this.stockSubscriptions : streamType === 'option' ? this.optionSubscriptions : this.cryptoSubscriptions;
|
|
11631
11665
|
Object.entries(subscriptions).forEach(([key, value]) => {
|
|
11632
11666
|
if (value) {
|
|
11633
11667
|
currentSubscriptions[key] = [...new Set([...(currentSubscriptions[key] || []), ...value])];
|
|
@@ -11636,7 +11670,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
|
|
|
11636
11670
|
this.sendSubscription(streamType);
|
|
11637
11671
|
}
|
|
11638
11672
|
unsubscribe(streamType, subscriptions) {
|
|
11639
|
-
const currentSubscriptions = streamType === 'stock' ? this.stockSubscriptions : this.optionSubscriptions;
|
|
11673
|
+
const currentSubscriptions = streamType === 'stock' ? this.stockSubscriptions : streamType === 'option' ? this.optionSubscriptions : this.cryptoSubscriptions;
|
|
11640
11674
|
Object.entries(subscriptions).forEach(([key, value]) => {
|
|
11641
11675
|
if (value) {
|
|
11642
11676
|
currentSubscriptions[key] = (currentSubscriptions[key] || []).filter(s => !value.includes(s));
|
|
@@ -11646,7 +11680,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
|
|
|
11646
11680
|
action: 'unsubscribe',
|
|
11647
11681
|
...subscriptions,
|
|
11648
11682
|
};
|
|
11649
|
-
const ws = streamType === 'stock' ? this.stockWs : this.optionWs;
|
|
11683
|
+
const ws = streamType === 'stock' ? this.stockWs : streamType === 'option' ? this.optionWs : this.cryptoWs;
|
|
11650
11684
|
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
11651
11685
|
ws.send(JSON.stringify(unsubMessage));
|
|
11652
11686
|
}
|