@adaptic/utils 0.1.45 → 0.1.46

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.
Files changed (70) hide show
  1. package/README.md +153 -61
  2. package/dist/index.cjs +1929 -1443
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.mjs +1925 -1445
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/test.js +288 -170
  7. package/dist/test.js.map +1 -1
  8. package/dist/types/__tests__/financial-regression.test.d.ts +2 -0
  9. package/dist/types/__tests__/financial-regression.test.d.ts.map +1 -0
  10. package/dist/types/__tests__/price-utils.test.d.ts +2 -0
  11. package/dist/types/__tests__/price-utils.test.d.ts.map +1 -0
  12. package/dist/types/adaptic.d.ts +2 -2
  13. package/dist/types/adaptic.d.ts.map +1 -1
  14. package/dist/types/alpaca-functions.d.ts +21 -21
  15. package/dist/types/alpaca-functions.d.ts.map +1 -1
  16. package/dist/types/alpaca-market-data-api.d.ts +16 -3
  17. package/dist/types/alpaca-market-data-api.d.ts.map +1 -1
  18. package/dist/types/alpaca-trading-api.d.ts +11 -11
  19. package/dist/types/alpaca-trading-api.d.ts.map +1 -1
  20. package/dist/types/alphavantage.d.ts +1 -1
  21. package/dist/types/alphavantage.d.ts.map +1 -1
  22. package/dist/types/asset-allocation-algorithm.d.ts +1 -1
  23. package/dist/types/asset-allocation-algorithm.d.ts.map +1 -1
  24. package/dist/types/cache/stampede-protected-cache.d.ts.map +1 -1
  25. package/dist/types/crypto.d.ts +2 -2
  26. package/dist/types/crypto.d.ts.map +1 -1
  27. package/dist/types/display-manager.d.ts +1 -1
  28. package/dist/types/display-manager.d.ts.map +1 -1
  29. package/dist/types/examples/asset-allocation-example.d.ts.map +1 -1
  30. package/dist/types/format-tools.d.ts.map +1 -1
  31. package/dist/types/index.d.ts +23 -21
  32. package/dist/types/index.d.ts.map +1 -1
  33. package/dist/types/logging.d.ts +1 -1
  34. package/dist/types/logging.d.ts.map +1 -1
  35. package/dist/types/market-hours.d.ts.map +1 -1
  36. package/dist/types/market-time.d.ts +2 -2
  37. package/dist/types/market-time.d.ts.map +1 -1
  38. package/dist/types/metrics-calcs.d.ts.map +1 -1
  39. package/dist/types/misc-utils.d.ts +1 -1
  40. package/dist/types/misc-utils.d.ts.map +1 -1
  41. package/dist/types/performance-metrics.d.ts +2 -2
  42. package/dist/types/performance-metrics.d.ts.map +1 -1
  43. package/dist/types/polygon-indices.d.ts +1 -1
  44. package/dist/types/polygon-indices.d.ts.map +1 -1
  45. package/dist/types/polygon.d.ts +1 -1
  46. package/dist/types/polygon.d.ts.map +1 -1
  47. package/dist/types/price-utils.d.ts.map +1 -1
  48. package/dist/types/technical-analysis.d.ts +9 -9
  49. package/dist/types/technical-analysis.d.ts.map +1 -1
  50. package/dist/types/time-utils.d.ts.map +1 -1
  51. package/dist/types/trading-policy/defaults.d.ts +46 -0
  52. package/dist/types/trading-policy/defaults.d.ts.map +1 -0
  53. package/dist/types/trading-policy/index.d.ts +8 -0
  54. package/dist/types/trading-policy/index.d.ts.map +1 -0
  55. package/dist/types/types/alpaca-types.d.ts +177 -88
  56. package/dist/types/types/alpaca-types.d.ts.map +1 -1
  57. package/dist/types/types/alphavantage-types.d.ts +2 -2
  58. package/dist/types/types/asset-allocation-types.d.ts +11 -11
  59. package/dist/types/types/index.d.ts +8 -8
  60. package/dist/types/types/index.d.ts.map +1 -1
  61. package/dist/types/types/logging-types.d.ts +1 -1
  62. package/dist/types/types/logging-types.d.ts.map +1 -1
  63. package/dist/types/types/market-time-types.d.ts +4 -4
  64. package/dist/types/types/market-time-types.d.ts.map +1 -1
  65. package/dist/types/types/metrics-types.d.ts +4 -4
  66. package/dist/types/types/metrics-types.d.ts.map +1 -1
  67. package/dist/types/types/polygon-indices-types.d.ts +6 -6
  68. package/dist/types/types/polygon-types.d.ts +3 -3
  69. package/dist/types/types/ta-types.d.ts +3 -3
  70. package/package.json +6 -3
@@ -1,5 +1,5 @@
1
- import { ApolloClientType, NormalizedCacheObject } from '@adaptic/backend-legacy';
2
- import { types } from '@adaptic/backend-legacy';
1
+ import { ApolloClientType, NormalizedCacheObject } from "@adaptic/backend-legacy";
2
+ import { types } from "@adaptic/backend-legacy";
3
3
  /**
4
4
  * Represents the authentication details for Alpaca.
5
5
  */
@@ -7,7 +7,7 @@ export interface AlpacaAuth {
7
7
  adapticAccountId?: string;
8
8
  alpacaApiKey?: string;
9
9
  alpacaApiSecret?: string;
10
- type?: 'PAPER' | 'LIVE';
10
+ type?: "PAPER" | "LIVE";
11
11
  }
12
12
  /**
13
13
  * Options for fetching Alpaca account details.
@@ -15,7 +15,7 @@ export interface AlpacaAuth {
15
15
  export interface AlpacaAccountGetOptions {
16
16
  accountId?: string;
17
17
  client?: ApolloClientType<NormalizedCacheObject>;
18
- alpacaAccount?: types.AlpacaAccount;
18
+ alpacaAccount?: types.BrokerageAccount;
19
19
  }
20
20
  /**
21
21
  * Represents the configuration of an Alpaca account.
@@ -40,13 +40,13 @@ export interface AccountConfiguration {
40
40
  cryptoTradeAllocationPct?: number;
41
41
  autoAllocation?: boolean;
42
42
  allocation?: AllocationConfig;
43
- dtbp_check: 'both' | 'entry' | 'exit';
44
- trade_confirm_email: 'all' | 'none';
43
+ dtbp_check: "both" | "entry" | "exit";
44
+ trade_confirm_email: "all" | "none";
45
45
  no_shorting: boolean;
46
46
  fractional_trading: boolean;
47
- max_margin_multiplier: '1' | '2' | '4';
47
+ max_margin_multiplier: "1" | "2" | "4";
48
48
  max_options_trading_level?: 0 | 1 | 2 | 3;
49
- pdt_check: 'both' | 'entry' | 'exit';
49
+ pdt_check: "both" | "entry" | "exit";
50
50
  ptp_no_exception_entry: boolean;
51
51
  enablePortfolioTrailingStop?: boolean;
52
52
  portfolioTrailPercent?: number;
@@ -108,7 +108,7 @@ export type AlpacaPosition = {
108
108
  qty: string;
109
109
  qty_available: string;
110
110
  avg_entry_price: string;
111
- side: 'long' | 'short';
111
+ side: "long" | "short";
112
112
  market_value: string;
113
113
  cost_basis: string;
114
114
  unrealized_pl: string;
@@ -119,31 +119,31 @@ export type AlpacaPosition = {
119
119
  lastday_price: string;
120
120
  change_today: string;
121
121
  };
122
- export type OrderSide = 'buy' | 'sell';
122
+ export type OrderSide = "buy" | "sell";
123
123
  /**
124
124
  * Represents the type of order.
125
125
  */
126
- export type OrderType = 'market' | 'limit' | 'stop' | 'stop_limit' | 'trailing_stop';
126
+ export type OrderType = "market" | "limit" | "stop" | "stop_limit" | "trailing_stop";
127
127
  /**
128
128
  * Represents the time in force for an order.
129
129
  */
130
- export type TimeInForce = 'day' | 'gtc' | 'opg' | 'cls' | 'ioc' | 'fok';
130
+ export type TimeInForce = "day" | "gtc" | "opg" | "cls" | "ioc" | "fok";
131
131
  /**
132
132
  * Represents the class of an order.
133
133
  */
134
- export type OrderClass = 'simple' | 'oco' | 'oto' | 'bracket' | 'mleg';
134
+ export type OrderClass = "simple" | "oco" | "oto" | "bracket" | "mleg";
135
135
  /**
136
136
  * Represents the status of an order.
137
137
  */
138
- export type OrderStatus = 'new' | 'partially_filled' | 'filled' | 'done_for_day' | 'canceled' | 'expired' | 'replaced' | 'pending_cancel' | 'pending_replace' | 'accepted' | 'pending_new' | 'accepted_for_bidding' | 'stopped' | 'rejected' | 'suspended' | 'calculated';
138
+ export type OrderStatus = "new" | "partially_filled" | "filled" | "done_for_day" | "canceled" | "expired" | "replaced" | "pending_cancel" | "pending_replace" | "accepted" | "pending_new" | "accepted_for_bidding" | "stopped" | "rejected" | "suspended" | "calculated";
139
139
  /**
140
140
  * Represents the class of an asset.
141
141
  */
142
- export type AssetClass = 'us_equity' | 'us_option' | 'crypto';
142
+ export type AssetClass = "us_equity" | "us_option" | "crypto";
143
143
  /**
144
144
  * Represents the intent of a position.
145
145
  */
146
- export type PositionIntent = 'buy_to_open' | 'buy_to_close' | 'sell_to_open' | 'sell_to_close';
146
+ export type PositionIntent = "buy_to_open" | "buy_to_close" | "sell_to_open" | "sell_to_close";
147
147
  /**
148
148
  * Parameters for take profit orders.
149
149
  */
@@ -183,7 +183,7 @@ export interface CreateOrderParams {
183
183
  legs?: OrderLeg[];
184
184
  }
185
185
  export interface CreateMultiLegOrderParams {
186
- order_class: 'mleg';
186
+ order_class: "mleg";
187
187
  qty: string;
188
188
  type: OrderType;
189
189
  limit_price?: string;
@@ -199,11 +199,11 @@ export interface CreateMultiLegOrderParams {
199
199
  * Parameters for getting orders.
200
200
  */
201
201
  export interface GetOrdersParams {
202
- status?: 'open' | 'closed' | 'all';
202
+ status?: "open" | "closed" | "all";
203
203
  limit?: number;
204
204
  after?: string;
205
205
  until?: string;
206
- direction?: 'asc' | 'desc';
206
+ direction?: "asc" | "desc";
207
207
  nested?: boolean;
208
208
  symbols?: string[];
209
209
  side?: OrderSide;
@@ -256,7 +256,7 @@ export type AlpacaOrder = {
256
256
  extended_hours: boolean;
257
257
  legs: AlpacaOrder[] | null;
258
258
  };
259
- export type CryptoTimeframe = `${number}Min` | `${number}T` | `${number}Hour` | `${number}H` | '1Day' | '1D' | '1Week' | '1W' | `${1 | 2 | 3 | 4 | 6 | 12}Month` | `${1 | 2 | 3 | 4 | 6 | 12}M`;
259
+ export type CryptoTimeframe = `${number}Min` | `${number}T` | `${number}Hour` | `${number}H` | "1Day" | "1D" | "1Week" | "1W" | `${1 | 2 | 3 | 4 | 6 | 12}Month` | `${1 | 2 | 3 | 4 | 6 | 12}M`;
260
260
  /**
261
261
  * Represents a single bar of cryptocurrency market data.
262
262
  */
@@ -280,9 +280,9 @@ export interface CryptoBarsParams {
280
280
  end?: Date;
281
281
  limit?: number;
282
282
  page_token?: string;
283
- sort?: 'asc' | 'desc';
283
+ sort?: "asc" | "desc";
284
284
  }
285
- export type TimeFrame = '1Min' | '5Min' | '15Min' | '30Min' | '1Hour' | '2Hour' | '4Hour' | '1Day' | '1Week' | '1Month';
285
+ export type TimeFrame = "1Min" | "5Min" | "15Min" | "30Min" | "1Hour" | "2Hour" | "4Hour" | "1Day" | "1Week" | "1Month";
286
286
  /**
287
287
  * Response structure for fetching cryptocurrency bars.
288
288
  */
@@ -292,10 +292,10 @@ export interface CryptoBarsResponse {
292
292
  };
293
293
  next_page_token?: string;
294
294
  }
295
- export type BTCPairs = 'BCH/BTC' | 'ETH/BTC' | 'LTC/BTC' | 'UNI/BTC';
296
- export type USDTPairs = 'AAVE/USDT' | 'BCH/USDT' | 'BTC/USDT' | 'DOGE/USDT' | 'ETH/USDT' | 'LINK/USDT' | 'LTC/USDT' | 'SUSHI/USDT' | 'UNI/USDT' | 'YFI/USDT';
297
- export type USDCPairs = 'AAVE/USDC' | 'AVAX/USDC' | 'BAT/USDC' | 'BCH/USDC' | 'BTC/USDC' | 'CRV/USDC' | 'DOGE/USDC' | 'DOT/USDC' | 'ETH/USDC' | 'GRT/USDC' | 'LINK/USDC' | 'LTC/USDC' | 'MKR/USDC' | 'SHIB/USDC' | 'SUSHI/USDC' | 'UNI/USDC' | 'XTZ/USDC' | 'YFI/USDC';
298
- export type USDPairs = 'AAVE/USD' | 'AVAX/USD' | 'BAT/USD' | 'BCH/USD' | 'BTC/USD' | 'CRV/USD' | 'DOGE/USD' | 'DOT/USD' | 'ETH/USD' | 'GRT/USD' | 'LINK/USD' | 'LTC/USD' | 'MKR/USD' | 'SHIB/USD' | 'SUSHI/USD' | 'UNI/USD' | 'USDC/USD' | 'USDT/USD' | 'XTZ/USD' | 'YFI/USD';
295
+ export type BTCPairs = "BCH/BTC" | "ETH/BTC" | "LTC/BTC" | "UNI/BTC";
296
+ export type USDTPairs = "AAVE/USDT" | "BCH/USDT" | "BTC/USDT" | "DOGE/USDT" | "ETH/USDT" | "LINK/USDT" | "LTC/USDT" | "SUSHI/USDT" | "UNI/USDT" | "YFI/USDT";
297
+ export type USDCPairs = "AAVE/USDC" | "AVAX/USDC" | "BAT/USDC" | "BCH/USDC" | "BTC/USDC" | "CRV/USDC" | "DOGE/USDC" | "DOT/USDC" | "ETH/USDC" | "GRT/USDC" | "LINK/USDC" | "LTC/USDC" | "MKR/USDC" | "SHIB/USDC" | "SUSHI/USDC" | "UNI/USDC" | "XTZ/USDC" | "YFI/USDC";
298
+ export type USDPairs = "AAVE/USD" | "AVAX/USD" | "BAT/USD" | "BCH/USD" | "BTC/USD" | "CRV/USD" | "DOGE/USD" | "DOT/USD" | "ETH/USD" | "GRT/USD" | "LINK/USD" | "LTC/USD" | "MKR/USD" | "SHIB/USD" | "SUSHI/USD" | "UNI/USD" | "USDC/USD" | "USDT/USD" | "XTZ/USD" | "YFI/USD";
299
299
  /**
300
300
  * Represents a cryptocurrency trading pair.
301
301
  */
@@ -304,7 +304,7 @@ export type CryptoPair = BTCPairs | USDTPairs | USDCPairs | USDPairs;
304
304
  * Represents an image associated with a news article.
305
305
  */
306
306
  export interface NewsImage {
307
- size: 'large' | 'small' | 'thumb';
307
+ size: "large" | "small" | "thumb";
308
308
  url: string;
309
309
  }
310
310
  /**
@@ -350,13 +350,13 @@ export interface SimpleNews {
350
350
  */
351
351
  export interface PortfolioHistoryParams {
352
352
  period?: string;
353
- timeframe?: '1Min' | '5Min' | '15Min' | '1H' | '1D';
354
- intraday_reporting?: 'market_hours' | 'extended_hours' | 'continuous';
353
+ timeframe?: "1Min" | "5Min" | "15Min" | "1H" | "1D";
354
+ intraday_reporting?: "market_hours" | "extended_hours" | "continuous";
355
355
  start?: string;
356
356
  end?: string;
357
357
  date_end?: string;
358
358
  extended_hours?: boolean;
359
- pnl_reset?: 'per_day' | 'no_reset';
359
+ pnl_reset?: "per_day" | "no_reset";
360
360
  cashflow_types?: string;
361
361
  }
362
362
  /**
@@ -366,7 +366,7 @@ export interface FetchPortfolioHistoryProps {
366
366
  params: PortfolioHistoryParams;
367
367
  accountId?: string;
368
368
  client?: ApolloClientType<NormalizedCacheObject>;
369
- alpacaAccount?: types.AlpacaAccount;
369
+ alpacaAccount?: types.BrokerageAccount;
370
370
  }
371
371
  /**
372
372
  * Response structure for fetching portfolio history.
@@ -385,7 +385,7 @@ export interface PortfolioHistoryResponse {
385
385
  export interface FetchAccountDetailsProps {
386
386
  accountId?: string;
387
387
  client?: ApolloClientType<NormalizedCacheObject>;
388
- alpacaAccount?: types.AlpacaAccount;
388
+ alpacaAccount?: types.BrokerageAccount;
389
389
  }
390
390
  /**
391
391
  * Represents the details of an Alpaca account.
@@ -393,7 +393,7 @@ export interface FetchAccountDetailsProps {
393
393
  export interface AlpacaAccountDetails {
394
394
  id: string;
395
395
  account_number: string;
396
- status: 'ONBOARDING' | 'SUBMISSION_FAILED' | 'SUBMITTED' | 'ACCOUNT_UPDATED' | 'APPROVAL_PENDING' | 'ACTIVE' | 'REJECTED';
396
+ status: "ONBOARDING" | "SUBMISSION_FAILED" | "SUBMITTED" | "ACCOUNT_UPDATED" | "APPROVAL_PENDING" | "ACTIVE" | "REJECTED";
397
397
  currency: string;
398
398
  cash: string;
399
399
  portfolio_value: string;
@@ -412,7 +412,7 @@ export interface AlpacaAccountDetails {
412
412
  short_market_value: string;
413
413
  equity: string;
414
414
  last_equity: string;
415
- multiplier: '1' | '2' | '4';
415
+ multiplier: "1" | "2" | "4";
416
416
  buying_power: string;
417
417
  initial_margin: string;
418
418
  maintenance_margin: string;
@@ -433,11 +433,11 @@ export interface AlpacaAccountDetails {
433
433
  */
434
434
  export interface AlpacaAsset {
435
435
  id: string;
436
- class: 'us_equity' | 'us_option' | 'crypto';
436
+ class: "us_equity" | "us_option" | "crypto";
437
437
  exchange: string;
438
438
  symbol: string;
439
439
  name: string;
440
- status: 'active' | 'inactive';
440
+ status: "active" | "inactive";
441
441
  tradable: boolean;
442
442
  marginable: boolean;
443
443
  shortable: boolean;
@@ -454,7 +454,7 @@ export interface AlpacaAsset {
454
454
  export interface GetAssetParams {
455
455
  symbolOrAssetId: string;
456
456
  }
457
- export type DataFeed = 'sip' | 'iex' | 'delayed_sip';
457
+ export type DataFeed = "sip" | "iex" | "delayed_sip";
458
458
  export interface AlpacaQuote {
459
459
  t: string;
460
460
  ap: number;
@@ -506,13 +506,13 @@ export interface LatestQuotesResponse {
506
506
  currency: string;
507
507
  }
508
508
  export type OptionsTradingLevel = 0 | 1 | 2 | 3;
509
- export type OptionType = 'call' | 'put';
510
- export type OptionStyle = 'american' | 'european';
509
+ export type OptionType = "call" | "put";
510
+ export type OptionStyle = "american" | "european";
511
511
  export interface OptionContract {
512
512
  id: string;
513
513
  symbol: string;
514
514
  name: string;
515
- status: 'active' | 'inactive';
515
+ status: "active" | "inactive";
516
516
  tradable: boolean;
517
517
  expiration_date: string;
518
518
  root_symbol: string;
@@ -534,7 +534,7 @@ export interface GetOptionContractsParams {
534
534
  strike_price_gte?: string;
535
535
  strike_price_lte?: string;
536
536
  type?: OptionType;
537
- status?: 'active' | 'inactive';
537
+ status?: "active" | "inactive";
538
538
  limit?: number;
539
539
  page_token?: string;
540
540
  }
@@ -546,8 +546,8 @@ export interface OptionContractsResponse {
546
546
  export interface OrderLeg {
547
547
  symbol: string;
548
548
  ratio_qty: string;
549
- side: 'buy' | 'sell';
550
- position_intent: 'buy_to_open' | 'buy_to_close' | 'sell_to_open' | 'sell_to_close';
549
+ side: "buy" | "sell";
550
+ position_intent: "buy_to_open" | "buy_to_close" | "sell_to_open" | "sell_to_close";
551
551
  }
552
552
  export interface OptionGreeks {
553
553
  delta?: number;
@@ -634,7 +634,7 @@ export interface OptionsChainParams {
634
634
  * The source feed of the data. opra is the official OPRA feed, indicative is a free indicative feed
635
635
  * where trades are delayed and quotes are modified. Default: opra if the user has a subscription, otherwise indicative.
636
636
  */
637
- feed?: 'opra' | 'indicative';
637
+ feed?: "opra" | "indicative";
638
638
  /**
639
639
  * Number of maximum snapshots to return in a response (1 to 1000)
640
640
  * The limit applies to the total number of data points, not the number per symbol!
@@ -707,7 +707,7 @@ export interface HistoricalOptionsBarsParams {
707
707
  /** Pagination token for next page */
708
708
  page_token?: string;
709
709
  /** Sort order (asc or desc) */
710
- sort?: 'asc' | 'desc';
710
+ sort?: "asc" | "desc";
711
711
  }
712
712
  export interface HistoricalOptionsTradesParams {
713
713
  /** Comma-separated list of option contract symbols */
@@ -727,7 +727,7 @@ export interface HistoricalOptionsTradesParams {
727
727
  /** Pagination token for next page */
728
728
  page_token?: string;
729
729
  /** Sort order (asc or desc) */
730
- sort?: 'asc' | 'desc';
730
+ sort?: "asc" | "desc";
731
731
  }
732
732
  export interface OptionsSnapshotsParams {
733
733
  /** Comma-separated list of option contract symbols */
@@ -743,14 +743,14 @@ export interface OptionsConditionCodesResponse {
743
743
  export interface OptionsExchangeCodesResponse {
744
744
  [exchangeCode: string]: string;
745
745
  }
746
- export type OptionTickType = 'trade' | 'quote';
746
+ export type OptionTickType = "trade" | "quote";
747
747
  /**
748
748
  * Configuration for options spread trading strategies.
749
749
  * Now includes a field to target a predicted stock price movement (in percent, scale 100).
750
750
  */
751
751
  export interface OptionsSpreadConfig {
752
752
  /** Strategy type to use - only spreads allowed */
753
- strategy: 'call_spread' | 'put_spread';
753
+ strategy: "call_spread" | "put_spread";
754
754
  /** Days to expiration target (will find closest available) */
755
755
  daysToExpiration: number;
756
756
  /** Delta target for the long leg (0.1-0.9 range) */
@@ -769,7 +769,7 @@ export interface OptionsSpreadConfig {
769
769
  */
770
770
  targetMovePercent100?: number;
771
771
  }
772
- export type OptionActivityType = 'OPEXC' | 'OPASN' | 'OPEXP';
772
+ export type OptionActivityType = "OPEXC" | "OPASN" | "OPEXP";
773
773
  export interface OptionAccountActivity {
774
774
  id: string;
775
775
  activity_type: OptionActivityType;
@@ -779,19 +779,19 @@ export interface OptionAccountActivity {
779
779
  symbol: string;
780
780
  qty: string;
781
781
  price?: string;
782
- status: 'executed';
782
+ status: "executed";
783
783
  }
784
784
  export interface TradeUpdate {
785
- event: 'new' | 'fill' | 'partial_fill' | 'canceled' | 'expired' | 'pending_new' | 'pending_cancel' | 'pending_replace' | 'replaced' | 'done_for_day';
785
+ event: "new" | "fill" | "partial_fill" | "canceled" | "expired" | "pending_new" | "pending_cancel" | "pending_replace" | "replaced" | "done_for_day";
786
786
  price?: string;
787
787
  timestamp: string;
788
788
  qty?: string;
789
789
  position_qty?: string;
790
790
  order: AlpacaOrder;
791
791
  }
792
- export type AlpacaAccountType = 'PAPER' | 'LIVE';
793
- export type AlpacaOrderType = 'limit' | 'market' | 'options';
794
- export type EngineType = 'adaptic' | 'brain' | 'quant';
792
+ export type AlpacaAccountType = "PAPER" | "LIVE";
793
+ export type AlpacaOrderType = "limit" | "market" | "options";
794
+ export type EngineType = "adaptic" | "brain" | "quant";
795
795
  export interface AlpacaCredentials {
796
796
  accountName: string;
797
797
  apiKey: string;
@@ -800,8 +800,8 @@ export interface AlpacaCredentials {
800
800
  orderType: AlpacaOrderType;
801
801
  engine: EngineType;
802
802
  }
803
- export type { AlpacaTradingAPI } from '../alpaca-trading-api';
804
- export type { AlpacaMarketDataAPI } from '../alpaca-market-data-api';
803
+ export type { AlpacaTradingAPI } from "../alpaca-trading-api";
804
+ export type { AlpacaMarketDataAPI } from "../alpaca-market-data-api";
805
805
  /**
806
806
  * Base interface for all real-time stream messages from Alpaca.
807
807
  * All stream messages will have a 'T' (Type) and 'S' (Symbol) property.
@@ -815,7 +815,7 @@ export interface AlpacaStreamMessage {
815
815
  * @see https://docs.alpaca.markets/docs/real-time-stock-pricing-data#trades
816
816
  */
817
817
  export interface AlpacaTradeStream extends AlpacaStreamMessage {
818
- T: 't';
818
+ T: "t";
819
819
  i: number;
820
820
  x: string;
821
821
  p: number;
@@ -829,7 +829,7 @@ export interface AlpacaTradeStream extends AlpacaStreamMessage {
829
829
  * @see https://docs.alpaca.markets/docs/real-time-stock-pricing-data#quotes
830
830
  */
831
831
  export interface AlpacaQuoteStream extends AlpacaStreamMessage {
832
- T: 'q';
832
+ T: "q";
833
833
  ax: string;
834
834
  ap: number;
835
835
  as: number;
@@ -845,7 +845,7 @@ export interface AlpacaQuoteStream extends AlpacaStreamMessage {
845
845
  * @see https://docs.alpaca.markets/docs/real-time-stock-pricing-data#bars
846
846
  */
847
847
  export interface AlpacaBarStream extends AlpacaStreamMessage {
848
- T: 'b';
848
+ T: "b";
849
849
  o: number;
850
850
  h: number;
851
851
  l: number;
@@ -859,22 +859,22 @@ export interface AlpacaBarStream extends AlpacaStreamMessage {
859
859
  * Real-time daily stock bar message. (T: 'd')
860
860
  * @see https://docs.alpaca.markets/docs/real-time-stock-pricing-data#bars
861
861
  */
862
- export interface AlpacaDailyBarStream extends Omit<AlpacaBarStream, 'T'> {
863
- T: 'd';
862
+ export interface AlpacaDailyBarStream extends Omit<AlpacaBarStream, "T"> {
863
+ T: "d";
864
864
  }
865
865
  /**
866
866
  * Real-time updated stock bar message. (T: 'u')
867
867
  * @see https://docs.alpaca.markets/docs/real-time-stock-pricing-data#bars
868
868
  */
869
- export interface AlpacaUpdatedBarStream extends Omit<AlpacaBarStream, 'T'> {
870
- T: 'u';
869
+ export interface AlpacaUpdatedBarStream extends Omit<AlpacaBarStream, "T"> {
870
+ T: "u";
871
871
  }
872
872
  /**
873
873
  * Real-time trading status message. (T: 's')
874
874
  * @see https://docs.alpaca.markets/docs/real-time-stock-pricing-data#trading-status
875
875
  */
876
876
  export interface AlpacaTradingStatusStream extends AlpacaStreamMessage {
877
- T: 's';
877
+ T: "s";
878
878
  sc: string;
879
879
  sm: string;
880
880
  rc: string;
@@ -887,7 +887,7 @@ export interface AlpacaTradingStatusStream extends AlpacaStreamMessage {
887
887
  * @see https://docs.alpaca.markets/docs/real-time-stock-pricing-data#lulds
888
888
  */
889
889
  export interface AlpacaLULDStream extends AlpacaStreamMessage {
890
- T: 'l';
890
+ T: "l";
891
891
  ldp: number;
892
892
  lup: number;
893
893
  i: string;
@@ -899,7 +899,7 @@ export interface AlpacaLULDStream extends AlpacaStreamMessage {
899
899
  * @see https://docs.alpaca.markets/docs/real-time-stock-pricing-data#trade-corrections
900
900
  */
901
901
  export interface AlpacaTradeCorrectionStream extends AlpacaStreamMessage {
902
- T: 'c';
902
+ T: "c";
903
903
  oi: number;
904
904
  ci: number;
905
905
  ox: string;
@@ -918,7 +918,7 @@ export interface AlpacaTradeCorrectionStream extends AlpacaStreamMessage {
918
918
  * @see https://docs.alpaca.markets/docs/real-time-stock-pricing-data#trade-cancelserros
919
919
  */
920
920
  export interface AlpacaTradeCancelStream extends AlpacaStreamMessage {
921
- T: 'x';
921
+ T: "x";
922
922
  i: number;
923
923
  p: number;
924
924
  s: number;
@@ -930,7 +930,7 @@ export interface AlpacaTradeCancelStream extends AlpacaStreamMessage {
930
930
  * @see https://docs.alpaca.markets/docs/real-time-stock-pricing-data#order-imbalances
931
931
  */
932
932
  export interface AlpacaOrderImbalanceStream extends AlpacaStreamMessage {
933
- T: 'i';
933
+ T: "i";
934
934
  p: number;
935
935
  z: string;
936
936
  t: string;
@@ -940,7 +940,7 @@ export interface AlpacaOrderImbalanceStream extends AlpacaStreamMessage {
940
940
  * @see https://docs.alpaca.markets/docs/real-time-option-data#trades
941
941
  */
942
942
  export interface AlpacaOptionTradeStream extends AlpacaStreamMessage {
943
- T: 't';
943
+ T: "t";
944
944
  p: number;
945
945
  s: number;
946
946
  c: string[];
@@ -952,7 +952,7 @@ export interface AlpacaOptionTradeStream extends AlpacaStreamMessage {
952
952
  * @see https://docs.alpaca.markets/docs/real-time-option-data#quotes
953
953
  */
954
954
  export interface AlpacaOptionQuoteStream extends AlpacaStreamMessage {
955
- T: 'q';
955
+ T: "q";
956
956
  ap: number;
957
957
  as: number;
958
958
  ax: string;
@@ -966,7 +966,7 @@ export interface AlpacaOptionQuoteStream extends AlpacaStreamMessage {
966
966
  * @see https://docs.alpaca.markets/docs/real-time-option-data#bars
967
967
  */
968
968
  export interface AlpacaOptionBarStream extends AlpacaStreamMessage {
969
- T: 'b';
969
+ T: "b";
970
970
  o: number;
971
971
  h: number;
972
972
  l: number;
@@ -978,25 +978,114 @@ export interface AlpacaOptionBarStream extends AlpacaStreamMessage {
978
978
  }
979
979
  export type AlpacaStockStreamMessage = AlpacaTradeStream | AlpacaQuoteStream | AlpacaBarStream | AlpacaDailyBarStream | AlpacaUpdatedBarStream | AlpacaTradingStatusStream | AlpacaLULDStream | AlpacaTradeCorrectionStream | AlpacaTradeCancelStream | AlpacaOrderImbalanceStream;
980
980
  export type AlpacaOptionStreamMessage = AlpacaOptionTradeStream | AlpacaOptionQuoteStream | AlpacaOptionBarStream;
981
- export type StockStreamEventName = 'stock-t' | 'stock-q' | 'stock-b' | 'stock-d' | 'stock-u' | 'stock-s' | 'stock-l' | 'stock-c' | 'stock-x' | 'stock-i' | 'stock-data';
982
- export type OptionStreamEventName = 'option-t' | 'option-q' | 'option-b' | 'option-data';
981
+ export type StockStreamEventName = "stock-t" | "stock-q" | "stock-b" | "stock-d" | "stock-u" | "stock-s" | "stock-l" | "stock-c" | "stock-x" | "stock-i" | "stock-data";
982
+ export type OptionStreamEventName = "option-t" | "option-q" | "option-b" | "option-data";
983
983
  export interface StockStreamEventMap {
984
- 'stock-t': AlpacaTradeStream;
985
- 'stock-q': AlpacaQuoteStream;
986
- 'stock-b': AlpacaBarStream;
987
- 'stock-d': AlpacaDailyBarStream;
988
- 'stock-u': AlpacaUpdatedBarStream;
989
- 'stock-s': AlpacaTradingStatusStream;
990
- 'stock-l': AlpacaLULDStream;
991
- 'stock-c': AlpacaTradeCorrectionStream;
992
- 'stock-x': AlpacaTradeCancelStream;
993
- 'stock-i': AlpacaOrderImbalanceStream;
994
- 'stock-data': AlpacaStockStreamMessage;
984
+ "stock-t": AlpacaTradeStream;
985
+ "stock-q": AlpacaQuoteStream;
986
+ "stock-b": AlpacaBarStream;
987
+ "stock-d": AlpacaDailyBarStream;
988
+ "stock-u": AlpacaUpdatedBarStream;
989
+ "stock-s": AlpacaTradingStatusStream;
990
+ "stock-l": AlpacaLULDStream;
991
+ "stock-c": AlpacaTradeCorrectionStream;
992
+ "stock-x": AlpacaTradeCancelStream;
993
+ "stock-i": AlpacaOrderImbalanceStream;
994
+ "stock-data": AlpacaStockStreamMessage;
995
995
  }
996
996
  export interface OptionStreamEventMap {
997
- 'option-t': AlpacaOptionTradeStream;
998
- 'option-q': AlpacaOptionQuoteStream;
999
- 'option-b': AlpacaOptionBarStream;
1000
- 'option-data': AlpacaOptionStreamMessage;
997
+ "option-t": AlpacaOptionTradeStream;
998
+ "option-q": AlpacaOptionQuoteStream;
999
+ "option-b": AlpacaOptionBarStream;
1000
+ "option-data": AlpacaOptionStreamMessage;
1001
+ }
1002
+ /**
1003
+ * Crypto trade stream message from Alpaca WebSocket
1004
+ * Format: wss://stream.data.alpaca.markets/v1beta3/crypto/us
1005
+ */
1006
+ export interface AlpacaCryptoTradeStream {
1007
+ T: 't';
1008
+ S: string;
1009
+ p: number;
1010
+ s: number;
1011
+ t: string;
1012
+ i: number;
1013
+ tks: 'B' | 'S';
1014
+ }
1015
+ /**
1016
+ * Crypto quote stream message from Alpaca WebSocket
1017
+ */
1018
+ export interface AlpacaCryptoQuoteStream {
1019
+ T: 'q';
1020
+ S: string;
1021
+ bp: number;
1022
+ bs: number;
1023
+ ap: number;
1024
+ as: number;
1025
+ t: string;
1026
+ }
1027
+ /**
1028
+ * Crypto bar stream message from Alpaca WebSocket
1029
+ */
1030
+ export interface AlpacaCryptoBarStream {
1031
+ T: 'b';
1032
+ S: string;
1033
+ o: number;
1034
+ h: number;
1035
+ l: number;
1036
+ c: number;
1037
+ v: number;
1038
+ t: string;
1039
+ n: number;
1040
+ vw: number;
1041
+ }
1042
+ /**
1043
+ * Crypto daily bar stream message from Alpaca WebSocket
1044
+ */
1045
+ export interface AlpacaCryptoDailyBarStream {
1046
+ T: 'd';
1047
+ S: string;
1048
+ o: number;
1049
+ h: number;
1050
+ l: number;
1051
+ c: number;
1052
+ v: number;
1053
+ t: string;
1054
+ n: number;
1055
+ vw: number;
1056
+ }
1057
+ /**
1058
+ * Crypto updated bar stream message from Alpaca WebSocket
1059
+ */
1060
+ export interface AlpacaCryptoUpdatedBarStream {
1061
+ T: 'u';
1062
+ S: string;
1063
+ o: number;
1064
+ h: number;
1065
+ l: number;
1066
+ c: number;
1067
+ v: number;
1068
+ t: string;
1069
+ n: number;
1070
+ vw: number;
1071
+ }
1072
+ /**
1073
+ * Union type for all crypto stream messages
1074
+ */
1075
+ export type AlpacaCryptoStreamMessage = AlpacaCryptoTradeStream | AlpacaCryptoQuoteStream | AlpacaCryptoBarStream | AlpacaCryptoDailyBarStream | AlpacaCryptoUpdatedBarStream;
1076
+ /**
1077
+ * Type-safe event names for crypto market data streams
1078
+ */
1079
+ export type CryptoStreamEventName = 'crypto-t' | 'crypto-q' | 'crypto-b' | 'crypto-d' | 'crypto-u' | 'crypto-data';
1080
+ /**
1081
+ * Event payload mapping for crypto streams
1082
+ */
1083
+ export interface CryptoStreamEventMap {
1084
+ 'crypto-t': AlpacaCryptoTradeStream;
1085
+ 'crypto-q': AlpacaCryptoQuoteStream;
1086
+ 'crypto-b': AlpacaCryptoBarStream;
1087
+ 'crypto-d': AlpacaCryptoDailyBarStream;
1088
+ 'crypto-u': AlpacaCryptoUpdatedBarStream;
1089
+ 'crypto-data': AlpacaCryptoStreamMessage;
1001
1090
  }
1002
1091
  //# sourceMappingURL=alpaca-types.d.ts.map