1 | export interface Endpoints {
|
2 | rest: {
|
3 | beta: 'https://data.alpaca.markets/v1beta1';
|
4 | account: 'https://api.alpaca.markets/v2';
|
5 | market_data_v2: 'https://data.alpaca.markets/v2';
|
6 | market_data_v1: 'https://data.alpaca.markets/v1';
|
7 | };
|
8 | websocket: {
|
9 | account: 'wss://api.alpaca.markets/stream';
|
10 | market_data: (source: DataSource) => string;
|
11 | };
|
12 | }
|
13 |
|
14 | /**
|
15 | * Your Alpaca key id and secret.
|
16 | * Can be passed to the AlpacaClient and AlpacaStream.
|
17 | */
|
18 | export interface DefaultCredentials {
|
19 | key: string;
|
20 | secret: string;
|
21 | paper?: boolean;
|
22 | }
|
23 |
|
24 | /**
|
25 | * Client ID for Oauth requests on behalf of users.
|
26 | * Can be passed to the AlpacaClient.
|
27 | */
|
28 | export interface OAuthCredentials {
|
29 | access_token: String;
|
30 | paper?: boolean;
|
31 | }
|
32 |
|
33 | /**
|
34 | * The account information with unparsed types, exactly as Alpaca provides it.
|
35 | * We encourage you to use the Account interface, which has many of these fields parsed.
|
36 | */
|
37 | export interface RawAccount {
|
38 | account_blocked: boolean;
|
39 | account_number: string;
|
40 | buying_power: string;
|
41 | cash: string;
|
42 | created_at: string;
|
43 | currency: string;
|
44 | daytrade_count: number;
|
45 | daytrading_buying_power: string;
|
46 | equity: string;
|
47 | id: string;
|
48 | initial_margin: string;
|
49 | last_equity: string;
|
50 | last_maintenance_margin: string;
|
51 | long_market_value: string;
|
52 | maintenance_margin: string;
|
53 | multiplier: string;
|
54 | pattern_day_trader: boolean;
|
55 | portfolio_value: string;
|
56 | regt_buying_power: string;
|
57 | short_market_value: string;
|
58 | shorting_enabled: boolean;
|
59 | sma: string;
|
60 | status: string;
|
61 | trade_suspended_by_user: boolean;
|
62 | trading_blocked: boolean;
|
63 | transfers_blocked: boolean;
|
64 | }
|
65 |
|
66 | /**
|
67 | * The following are the possible account status values. Most likely, the account status
|
68 | * is ACTIVE unless there is any problem. The account status may get in ACCOUNT_UPDATED
|
69 | * when personal information is being updated from the dashboard, in which case you may
|
70 | * not be allowed trading for a short period of time until the change is approved.
|
71 | */
|
72 | export type AccountStatus =
|
73 | /**
|
74 | * The account is onboarding.
|
75 | */
|
76 | | 'ONBOARDING'
|
77 | /**
|
78 | * The account application submission failed for some reason.
|
79 | */
|
80 | | 'SUBMISSION_FAILED'
|
81 | /**
|
82 | * The account application has been submitted for review.
|
83 | */
|
84 | | 'SUBMITTED'
|
85 | /**
|
86 | * The account information is being updated.
|
87 | */
|
88 | | 'ACCOUNT_UPDATED'
|
89 | /**
|
90 | * The final account approval is pending.
|
91 | */
|
92 | | 'APPROVAL_PENDING'
|
93 | /**
|
94 | * The account is active for trading.
|
95 | */
|
96 | | 'ACTIVE'
|
97 | /**
|
98 | * The account application has been rejected.
|
99 | */
|
100 | | 'REJECTED';
|
101 |
|
102 | /**
|
103 | * Information related to an Alpaca account, such as account status, funds, and various
|
104 | * flags relevant to an account's ability to trade.
|
105 | */
|
106 | export interface Account {
|
107 | /**
|
108 | * Get the raw data, exactly as it came from Alpaca
|
109 | */
|
110 | raw(): RawAccount;
|
111 |
|
112 | /**
|
113 | * If true, the account activity by user is prohibited.
|
114 | */
|
115 | account_blocked: boolean;
|
116 |
|
117 | /**
|
118 | * Account number.
|
119 | */
|
120 | account_number: string;
|
121 |
|
122 | /**
|
123 | * Current available $ buying power; If multiplier = 4, this is your daytrade buying
|
124 | * power which is calculated as (last_equity - (last) maintenance_margin) * 4; If
|
125 | * multiplier = 2, buying_power = max(equity – initial_margin,0) * 2; If multiplier = 1,
|
126 | * buying_power = cash
|
127 | */
|
128 | buying_power: number;
|
129 |
|
130 | /**
|
131 | * Cash balance
|
132 | */
|
133 | cash: number;
|
134 |
|
135 | /**
|
136 | * Timestamp this account was created at
|
137 | */
|
138 | created_at: Date;
|
139 |
|
140 | /**
|
141 | * "USD"
|
142 | */
|
143 | currency: string;
|
144 |
|
145 | /**
|
146 | * The current number of daytrades that have been made in the last 5 trading days
|
147 | * (inclusive of today)
|
148 | */
|
149 | daytrade_count: number;
|
150 |
|
151 | /**
|
152 | * Your buying power for day trades (continuously updated value)
|
153 | */
|
154 | daytrading_buying_power: number;
|
155 |
|
156 | /**
|
157 | * Cash + long_market_value + short_market_value
|
158 | */
|
159 | equity: number;
|
160 |
|
161 | /**
|
162 | * Account ID.
|
163 | */
|
164 | id: string;
|
165 |
|
166 | /**
|
167 | * Reg T initial margin requirement (continuously updated value)
|
168 | */
|
169 | initial_margin: number;
|
170 |
|
171 | /**
|
172 | * Equity as of previous trading day at 16:00:00 ET
|
173 | */
|
174 | last_equity: number;
|
175 |
|
176 | /**
|
177 | * Your maintenance margin requirement on the previous trading day
|
178 | */
|
179 | last_maintenance_margin: number;
|
180 |
|
181 | /**
|
182 | * Real-time MtM value of all long positions held in the account
|
183 | */
|
184 | long_market_value: number;
|
185 |
|
186 | /**
|
187 | * Maintenance margin requirement (continuously updated value)
|
188 | */
|
189 | maintenance_margin: number;
|
190 |
|
191 | /**
|
192 | * Buying power multiplier that represents account margin classification; valid values 1
|
193 | * (standard limited margin account with 1x buying power), 2 (reg T margin account with
|
194 | * 2x intraday and overnight buying power; this is the default for all non-PDT accounts
|
195 | * with $2,000 or more equity), 4 (PDT account with 4x intraday buying power and 2x reg
|
196 | * T overnight buying power)
|
197 | */
|
198 | multiplier: number;
|
199 |
|
200 | /**
|
201 | * Whether or not the account has been flagged as a pattern day trader
|
202 | */
|
203 | pattern_day_trader: boolean;
|
204 |
|
205 | /**
|
206 | * Total value of cash + holding positions (This field is deprecated. It is equivalent
|
207 | * to the equity field.)
|
208 | */
|
209 | portfolio_value: number;
|
210 |
|
211 | /**
|
212 | * Your buying power under Regulation T (your excess equity - equity minus margin
|
213 | * value - times your margin multiplier)
|
214 | */
|
215 | regt_buying_power: number;
|
216 |
|
217 | /**
|
218 | * Real-time MtM value of all short positions held in the account
|
219 | */
|
220 | short_market_value: number;
|
221 |
|
222 | /**
|
223 | * Flag to denote whether or not the account is permitted to short
|
224 | */
|
225 | shorting_enabled: boolean;
|
226 |
|
227 | /**
|
228 | * Value of special memorandum account (will be used at a later date to provide
|
229 | * additional buying_power)
|
230 | */
|
231 | sma: number;
|
232 |
|
233 | /**
|
234 | * The following are the possible account status values. Most likely, the account status
|
235 | * is ACTIVE unless there is any problem. The account status may get in ACCOUNT_UPDATED
|
236 | * when personal information is being updated from the dashboard, in which case you may
|
237 | * not be allowed trading for a short period of time until the change is approved.
|
238 | */
|
239 | status: AccountStatus;
|
240 |
|
241 | /**
|
242 | * User setting. If true, the account is not allowed to place orders.
|
243 | */
|
244 | trade_suspended_by_user: boolean;
|
245 |
|
246 | /**
|
247 | * If true, the account is not allowed to place orders.
|
248 | */
|
249 | trading_blocked: boolean;
|
250 |
|
251 | /**
|
252 | * If true, the account is not allowed to request money transfers.
|
253 | */
|
254 | transfers_blocked: boolean;
|
255 | }
|
256 |
|
257 | export interface AccountConfigurations {
|
258 | /**
|
259 | * both, entry, or exit. Controls Day Trading Margin Call (DTMC) checks.
|
260 | */
|
261 | dtbp_check: 'both' | 'entry' | 'exit';
|
262 |
|
263 | /**
|
264 | * If true, account becomes long-only mode.
|
265 | */
|
266 | no_shorting: boolean;
|
267 |
|
268 | /**
|
269 | * If true, new orders are blocked.
|
270 | */
|
271 | suspend_trade: boolean;
|
272 |
|
273 | /**
|
274 | * all or none. If none, emails for order fills are not sent.
|
275 | */
|
276 | trade_confirm_email: 'all' | 'none';
|
277 | }
|
278 |
|
279 | export interface AccountUpdate {
|
280 | id: string;
|
281 | created_at: string;
|
282 | updated_at: string;
|
283 | deleted_at: any;
|
284 | status: string;
|
285 | currency: string;
|
286 | cash: string;
|
287 | cash_withdrawable: string;
|
288 | }
|
289 |
|
290 | export interface AggregateMinute {
|
291 | ev: string;
|
292 | T: string;
|
293 | v: number;
|
294 | av: number;
|
295 | op: number;
|
296 | vw: number;
|
297 | o: number;
|
298 | c: number;
|
299 | h: number;
|
300 | l: number;
|
301 | a: number;
|
302 | s: number;
|
303 | e: number;
|
304 | }
|
305 |
|
306 | export type AssetExchange =
|
307 | | 'AMEX'
|
308 | | 'ARCA'
|
309 | | 'BATS'
|
310 | | 'NYSE'
|
311 | | 'NASDAQ'
|
312 | | 'NYSEARCA';
|
313 |
|
314 | export type AssetStatus = 'active' | 'inactive';
|
315 |
|
316 | /**
|
317 | * The assets API serves as the master list of assets available for trade and data
|
318 | * consumption from Alpaca. Assets are sorted by asset class, exchange and symbol. Some
|
319 | * assets are only available for data consumption via Polygon, and are not tradable with
|
320 | * Alpaca. These assets will be marked with the flag tradable=false.
|
321 | */
|
322 | export interface Asset {
|
323 | /**
|
324 | * Asset ID
|
325 | */
|
326 | id: string;
|
327 |
|
328 | /**
|
329 | * "us_equity"
|
330 | */
|
331 | class: string;
|
332 |
|
333 | /**
|
334 | * AMEX, ARCA, BATS, NYSE, NASDAQ or NYSEARCA
|
335 | */
|
336 | exchange: AssetExchange;
|
337 |
|
338 | /**
|
339 | * Asset symbol
|
340 | */
|
341 | symbol: string;
|
342 |
|
343 | /**
|
344 | * active or inactive
|
345 | */
|
346 | status: AssetStatus;
|
347 |
|
348 | /**
|
349 | * Asset is tradable on Alpaca or not
|
350 | */
|
351 | tradable: boolean;
|
352 |
|
353 | /**
|
354 | * Asset is marginable or not
|
355 | */
|
356 | marginable: boolean;
|
357 |
|
358 | /**
|
359 | * Asset is shortable or not
|
360 | */
|
361 | shortable: boolean;
|
362 |
|
363 | /**
|
364 | * Asset is easy-to-borrow or not (filtering for easy_to_borrow = True is the best way
|
365 | * to check whether the name is currently available to short at Alpaca).
|
366 | */
|
367 | easy_to_borrow: boolean;
|
368 |
|
369 | /**
|
370 | * Asset is fractionable or not.
|
371 | */
|
372 | fractionable: boolean;
|
373 | }
|
374 |
|
375 | /**
|
376 | * Contains the time of open and close for a market on a particular day from 1970 to 2029
|
377 | */
|
378 | export interface Calendar {
|
379 | /**
|
380 | * Date string in YYYY-MM-DD format
|
381 | */
|
382 | date: string;
|
383 |
|
384 | /**
|
385 | * The time the market opens at on this date in HH:MM format
|
386 | */
|
387 | open: string;
|
388 |
|
389 | /**
|
390 | * The time the market closes at on this date in HH:MM format
|
391 | */
|
392 | close: string;
|
393 | }
|
394 |
|
395 | export interface RawClock {
|
396 | timestamp: string;
|
397 | is_open: boolean;
|
398 | next_open: string;
|
399 | next_close: string;
|
400 | }
|
401 |
|
402 | /**
|
403 | * The clock API serves the current market timestamp, whether or not the market is
|
404 | * currently open, as well as the times of the next market open and close.
|
405 | */
|
406 | export interface Clock {
|
407 | /**
|
408 | * Get the raw data, exactly as it came from Alpaca
|
409 | */
|
410 | raw(): RawClock;
|
411 |
|
412 | /**
|
413 | * Current timestamp
|
414 | */
|
415 | timestamp: Date;
|
416 |
|
417 | /**
|
418 | * Whether or not the market is open
|
419 | */
|
420 | is_open: boolean;
|
421 |
|
422 | /**
|
423 | * Next market open timestamp
|
424 | */
|
425 | next_open: Date;
|
426 |
|
427 | /**
|
428 | * Next market close timestamp
|
429 | */
|
430 | next_close: Date;
|
431 | }
|
432 |
|
433 | /** A trade which occurred. */
|
434 | export interface RawTrade {
|
435 | /** Trade symbol. */
|
436 | S: string;
|
437 | /** Timestamp in RFC-3339 format with nanosecond precision. */
|
438 | t: string;
|
439 | /** Exchange where the trade happened. */
|
440 | x: string;
|
441 | /** Trade price. */
|
442 | p: number;
|
443 | /** Trade size. */
|
444 | s: number;
|
445 | /** Trade conditions. */
|
446 | c: string[];
|
447 | /** Trade ID. */
|
448 | i: number;
|
449 | /** Tape. */
|
450 | z: string;
|
451 | }
|
452 |
|
453 | /** A page of one or many trades. */
|
454 | export interface RawPageOfTrades {
|
455 | /** Array of trades. */
|
456 | trades: RawTrade[];
|
457 | /** Symbol that was queried. */
|
458 | symbol: string;
|
459 | /** Token that can be used to query the next page. */
|
460 | next_page_token: string;
|
461 | }
|
462 |
|
463 | /** A trade which occurred. */
|
464 | export interface Trade {
|
465 | /** Get the raw data as it came from Alpaca. */
|
466 | raw(): RawTrade;
|
467 | /** Trade symbol. */
|
468 | S: string;
|
469 | /** Timestamp in RFC-3339 format with nanosecond precision. */
|
470 | t: Date;
|
471 | /** Exchange where the trade happened. */
|
472 | x: string;
|
473 | /** Trade price. */
|
474 | p: number;
|
475 | /** Trade size. */
|
476 | s: number;
|
477 | /** Trade conditions. */
|
478 | c: string[];
|
479 | /** Trade ID. */
|
480 | i: number;
|
481 | /** Tape. */
|
482 | z: string;
|
483 | }
|
484 |
|
485 | /** A page of one or many trades. */
|
486 | export interface PageOfTrades {
|
487 | /** Get the raw data as it came from Alpaca. */
|
488 | raw(): RawPageOfTrades;
|
489 | /** Array of trades. */
|
490 | trades: Trade[];
|
491 | /** Symbol that was queried. */
|
492 | symbol: string;
|
493 | /** Token that can be used to query the next page. */
|
494 | next_page_token: string;
|
495 | }
|
496 |
|
497 | /** A quote for a symbol. */
|
498 | export interface RawQuote {
|
499 | /** Quote symbol. */
|
500 | S: string;
|
501 | /** Timestamp in RFC-3339 format with nanosecond precision. */
|
502 | t: string;
|
503 | /** Ask exchange. */
|
504 | ax: string;
|
505 | /** Ask price. */
|
506 | ap: number;
|
507 | /** Ask size. */
|
508 | as: number;
|
509 | /** Bid exchange. */
|
510 | bx: string;
|
511 | /** Bid price. */
|
512 | bp: number;
|
513 | /** Bid size. */
|
514 | bs: number;
|
515 | /** Quote conditions. */
|
516 | c: string[];
|
517 | }
|
518 |
|
519 | /** A page of one or many quotes. */
|
520 | export interface RawPageOfQuotes {
|
521 | /** Array of quotes. */
|
522 | quotes: RawQuote[];
|
523 | /** Symbol that was queried. */
|
524 | symbol: string;
|
525 | /** Token that can be used to query the next page. */
|
526 | next_page_token: string;
|
527 | }
|
528 |
|
529 | /** A quote for a symbol. */
|
530 | export interface Quote {
|
531 | /** Get the raw data as it came from Alpaca. */
|
532 | raw(): RawQuote;
|
533 | /** Quote symbol. */
|
534 | S: string;
|
535 | /** Timestamp in Date format. */
|
536 | t: Date;
|
537 | /** Ask exchange. */
|
538 | ax: string;
|
539 | /** Ask price. */
|
540 | ap: number;
|
541 | /** Ask size. */
|
542 | as: number;
|
543 | /** Bid exchange. */
|
544 | bx: string;
|
545 | /** Bid price. */
|
546 | bp: number;
|
547 | /** Bid size. */
|
548 | bs: number;
|
549 | /** Quote conditions. */
|
550 | c: string[];
|
551 | }
|
552 |
|
553 | /** A page of one or many quotes. */
|
554 | export interface PageOfQuotes {
|
555 | /** Get the raw data as it came from Alpaca. */
|
556 | raw(): RawPageOfQuotes;
|
557 | /** Array of quotes. */
|
558 | quotes: Quote[];
|
559 | /** Symbol that was queried. */
|
560 | symbol: string;
|
561 | /** Token that can be used to query the next page. */
|
562 | next_page_token: string;
|
563 | }
|
564 |
|
565 | /** A bar for a symbol. */
|
566 | export interface RawBar {
|
567 | /** Bar symbol. */
|
568 | S: string;
|
569 | /** Timestamp in RFC-3339 format with nanosecond precision. */
|
570 | t: string;
|
571 | /** Open price. */
|
572 | o: number;
|
573 | /** High price. */
|
574 | h: number;
|
575 | /** Low price. */
|
576 | l: number;
|
577 | /** Close price. */
|
578 | c: number;
|
579 | /** Volume. */
|
580 | v: number;
|
581 | }
|
582 |
|
583 | /** A page of one or many bars. */
|
584 | export interface RawPageOfBars {
|
585 | /** Array of bars. */
|
586 | bars: RawBar[];
|
587 | /** Symbol that was queried. */
|
588 | symbol: string;
|
589 | /** Token that can be used to query the next page. */
|
590 | next_page_token: string;
|
591 | }
|
592 |
|
593 | /** A bar for a symbol. */
|
594 | export interface Bar {
|
595 | /** Get the raw data as it came from Alpaca. */
|
596 | raw(): RawBar;
|
597 | /** Bar symbol. */
|
598 | S: string;
|
599 | /** Timestamp in Date format. */
|
600 | t: Date;
|
601 | /** Open price. */
|
602 | o: number;
|
603 | /** High price. */
|
604 | h: number;
|
605 | /** Low price. */
|
606 | l: number;
|
607 | /** Close price. */
|
608 | c: number;
|
609 | /** Volume. */
|
610 | v: number;
|
611 | }
|
612 |
|
613 | /** A page of one or many bars. */
|
614 | export interface PageOfBars {
|
615 | /** Get the raw data as it came from Alpaca. */
|
616 | raw(): RawPageOfBars;
|
617 | /** Array of bars. */
|
618 | bars: Bar[];
|
619 | /** Symbol that was queried. */
|
620 | symbol: string;
|
621 | /** Token that can be used to query the next page. */
|
622 | next_page_token: string;
|
623 | }
|
624 |
|
625 | /**
|
626 | * The parsed result of an order cancelation request.
|
627 | */
|
628 | export interface OrderCancelation {
|
629 | id: string;
|
630 | status: number;
|
631 | order: Order;
|
632 | }
|
633 |
|
634 | /**
|
635 | * The id, http status code and order as part of the cancel all orders request.
|
636 | */
|
637 | export interface RawOrderCancelation {
|
638 | id: string;
|
639 | status: number;
|
640 | body: RawOrder;
|
641 | }
|
642 |
|
643 | /**
|
644 | * The order entity with unparsed fields, exactly as Alpaca provides it.
|
645 | * We encourage you to use the Order interface, which has many of these fields parsed.
|
646 | */
|
647 | export interface RawOrder {
|
648 | id: string;
|
649 | client_order_id: string;
|
650 | created_at: string;
|
651 | updated_at: string;
|
652 | submitted_at: string;
|
653 | filled_at: string;
|
654 | expired_at: string;
|
655 | canceled_at: string;
|
656 | failed_at: string;
|
657 | replaced_at: string;
|
658 | replaced_by: string;
|
659 | replaces: string;
|
660 | asset_id: string;
|
661 | symbol: string;
|
662 | asset_class: string;
|
663 | qty: string;
|
664 | filled_qty: string;
|
665 | type: string;
|
666 | side: string;
|
667 | time_in_force: string;
|
668 | limit_price: string;
|
669 | stop_price: string;
|
670 | filled_avg_price: string;
|
671 | status: string;
|
672 | extended_hours: boolean;
|
673 | legs: RawOrder[];
|
674 | trail_price: string;
|
675 | trail_percent: string;
|
676 | hwm: string;
|
677 | order_class?: OrderClass;
|
678 | }
|
679 |
|
680 | /**
|
681 | * Price and volume data during a particular time interval
|
682 | */
|
683 | export interface Bar_v1 {
|
684 | /**
|
685 | * the beginning time of this bar as a Unix epoch in seconds
|
686 | */
|
687 | t: number;
|
688 |
|
689 | /**
|
690 | * open price
|
691 | */
|
692 | o: number;
|
693 |
|
694 | /**
|
695 | * high price
|
696 | */
|
697 | h: number;
|
698 |
|
699 | /**
|
700 | * low price
|
701 | */
|
702 | l: number;
|
703 |
|
704 | /**
|
705 | * close price
|
706 | */
|
707 | c: number;
|
708 |
|
709 | /**
|
710 | * volume
|
711 | */
|
712 | v: number;
|
713 | }
|
714 |
|
715 | /**
|
716 | * Last quote details for a symbol
|
717 | */
|
718 | export interface LastQuote_v1 {
|
719 | status: string;
|
720 | symbol: string;
|
721 | last: {
|
722 | /**
|
723 | * the current ask price
|
724 | */
|
725 | askprice: number;
|
726 |
|
727 | /**
|
728 | * the current ask size
|
729 | */
|
730 | asksize: number;
|
731 |
|
732 | /**
|
733 | * the exchange code of the ask quote
|
734 | */
|
735 | askexchange: number;
|
736 |
|
737 | /**
|
738 | * the current bid price
|
739 | */
|
740 | bidprice: number;
|
741 |
|
742 | /**
|
743 | * the current bid size
|
744 | */
|
745 | bidsize: number;
|
746 |
|
747 | /**
|
748 | * the exchange code of the bid quote
|
749 | */
|
750 | bidexchange: number;
|
751 |
|
752 | /**
|
753 | * epoch timestamp in nanoseconds
|
754 | */
|
755 | timestamp: number;
|
756 | };
|
757 | }
|
758 |
|
759 | /**
|
760 | * Last trade details for a symbol
|
761 | */
|
762 | export interface LastTrade_v1 {
|
763 | status: string;
|
764 | symbol: string;
|
765 | last: {
|
766 | /**
|
767 | * last trade price
|
768 | */
|
769 | price: number;
|
770 |
|
771 | /**
|
772 | * last trade volume size
|
773 | */
|
774 | size: number;
|
775 |
|
776 | /**
|
777 | * exchange code where the last trade was made
|
778 | */
|
779 | exchange: number;
|
780 |
|
781 | /**
|
782 | * condition flag 1
|
783 | */
|
784 | cond1: number;
|
785 |
|
786 | /**
|
787 | * condition flag 2
|
788 | */
|
789 | cond2: number;
|
790 |
|
791 | /**
|
792 | * condition flag 3
|
793 | */
|
794 | cond3: number;
|
795 |
|
796 | /**
|
797 | * condition flag 4
|
798 | */
|
799 | cond4: number;
|
800 |
|
801 | /**
|
802 | * epoch timestamp in nanoseconds
|
803 | */
|
804 | timestamp: number;
|
805 | };
|
806 | }
|
807 |
|
808 | export interface RawSnapshot {
|
809 | symbol: string;
|
810 | latestTrade: {
|
811 | t: string;
|
812 | x: string;
|
813 | p: number;
|
814 | s: number;
|
815 | c?: string[] | null;
|
816 | i: number;
|
817 | z: string;
|
818 | };
|
819 | latestQuote: {
|
820 | t: string;
|
821 | ax: string;
|
822 | ap: number;
|
823 | as: number;
|
824 | bx: string;
|
825 | bp: number;
|
826 | bs: number;
|
827 | c?: string[] | null;
|
828 | };
|
829 | minuteBar: {
|
830 | t: string;
|
831 | o: number;
|
832 | h: number;
|
833 | l: number;
|
834 | c: number;
|
835 | v: number;
|
836 | };
|
837 | dailyBar: {
|
838 | t: string;
|
839 | o: number;
|
840 | h: number;
|
841 | l: number;
|
842 | c: number;
|
843 | v: number;
|
844 | };
|
845 | prevDailyBar: {
|
846 | t: string;
|
847 | o: number;
|
848 | h: number;
|
849 | l: number;
|
850 | c: number;
|
851 | v: number;
|
852 | };
|
853 | }
|
854 |
|
855 | export interface Snapshot {
|
856 | /** Get the raw data as it came from Alpaca. */
|
857 | raw(): RawSnapshot;
|
858 | symbol: string;
|
859 | latestTrade: {
|
860 | t: Date;
|
861 | x: string;
|
862 | p: number;
|
863 | s: number;
|
864 | c?: string[] | null;
|
865 | i: number;
|
866 | z: string;
|
867 | };
|
868 | latestQuote: {
|
869 | t: Date;
|
870 | ax: string;
|
871 | ap: number;
|
872 | as: number;
|
873 | bx: string;
|
874 | bp: number;
|
875 | bs: number;
|
876 | c?: string[] | null;
|
877 | };
|
878 | minuteBar: {
|
879 | t: Date;
|
880 | o: number;
|
881 | h: number;
|
882 | l: number;
|
883 | c: number;
|
884 | v: number;
|
885 | };
|
886 | dailyBar: {
|
887 | t: Date;
|
888 | o: number;
|
889 | h: number;
|
890 | l: number;
|
891 | c: number;
|
892 | v: number;
|
893 | };
|
894 | prevDailyBar: {
|
895 | t: Date;
|
896 | o: number;
|
897 | h: number;
|
898 | l: number;
|
899 | c: number;
|
900 | v: number;
|
901 | };
|
902 | }
|
903 |
|
904 | export type DataSource = 'iex' | 'sip';
|
905 |
|
906 | export type OrderType =
|
907 | | 'market'
|
908 | | 'limit'
|
909 | | 'stop'
|
910 | | 'stop_limit'
|
911 | | 'trailing_stop';
|
912 |
|
913 | export type OrderClass = 'simple' | 'bracket' | 'oto' | 'oco';
|
914 |
|
915 | export type OrderSide = 'buy' | 'sell';
|
916 |
|
917 | export type OrderTimeInForce =
|
918 | /**
|
919 | * A day order is eligible for execution only on the day it is live. By default, the
|
920 | * order is only valid during Regular Trading Hours (9:30am - 4:00pm ET). If unfilled
|
921 | * after the closing auction, it is automatically canceled. If submitted after the
|
922 | * close, it is queued and submitted the following trading day. However, if marked as
|
923 | * eligible for extended hours, the order can also execute during supported extended
|
924 | * hours.
|
925 | */
|
926 | | 'day'
|
927 |
|
928 | /**
|
929 | * The order is good until canceled. Non-marketable GTC limit orders are subject to
|
930 | * price adjustments to offset corporate actions affecting the issue. We do not
|
931 | * currently support Do Not Reduce(DNR) orders to opt out of such price adjustments.
|
932 | */
|
933 | | 'gtc'
|
934 |
|
935 | /**
|
936 | * Use this TIF with a market/limit order type to submit "market on open" (MOO) and
|
937 | * "limit on open" (LOO) orders. This order is eligible to execute only in the market
|
938 | * opening auction. Any unfilled orders after the open will be cancelled. OPG orders
|
939 | * submitted after 9:28am but before 7:00pm ET will be rejected. OPG orders submitted
|
940 | * after 7:00pm will be queued and routed to the following day's opening auction. On
|
941 | * open/on close orders are routed to the primary exchange. Such orders do not
|
942 | * necessarily execute exactly at 9:30am / 4:00pm ET but execute per the exchange's
|
943 | * auction rules.
|
944 | */
|
945 | | 'opg'
|
946 |
|
947 | /**
|
948 | * Use this TIF with a market/limit order type to submit "market on close" (MOC) and
|
949 | * "limit on close" (LOC) orders. This order is eligible to execute only in the market
|
950 | * closing auction. Any unfilled orders after the close will be cancelled. CLS orders
|
951 | * submitted after 3:50pm but before 7:00pm ET will be rejected. CLS orders submitted
|
952 | * after 7:00pm will be queued and routed to the following day's closing auction. Only
|
953 | * available with API v2.
|
954 | */
|
955 | | 'cls'
|
956 |
|
957 | /**
|
958 | * An Immediate Or Cancel (IOC) order requires all or part of the order to be executed
|
959 | * immediately. Any unfilled portion of the order is canceled. Only available with API
|
960 | * v2.
|
961 | */
|
962 | | 'ioc'
|
963 |
|
964 | /**
|
965 | * A Fill or Kill (FOK) order is only executed if the entire order quantity can be
|
966 | * filled, otherwise the order is canceled. Only available with API v2.
|
967 | */
|
968 | | 'fok';
|
969 |
|
970 | export type OrderStatus =
|
971 | /**
|
972 | * The order has been received by Alpaca, and routed to exchanges for execution. This
|
973 | * is the usual initial state of an order.
|
974 | */
|
975 | | 'new'
|
976 |
|
977 | /**
|
978 | * The order has been partially filled.
|
979 | */
|
980 | | 'partially_filled'
|
981 |
|
982 | /**
|
983 | * The order has been filled, and no further updates will occur for the order.
|
984 | */
|
985 | | 'filled'
|
986 |
|
987 | /**
|
988 | * The order is done executing for the day, and will not receive further updates until
|
989 | * the next trading day.
|
990 | */
|
991 | | 'done_for_day'
|
992 |
|
993 | /**
|
994 | * The order has been canceled, and no further updates will occur for the order. This
|
995 | * can be either due to a cancel request by the user, or the order has been canceled by
|
996 | * the exchanges due to its time-in-force.
|
997 | */
|
998 | | 'canceled'
|
999 |
|
1000 | /**
|
1001 | * The order has expired, and no further updates will occur for the order.
|
1002 | */
|
1003 | | 'expired'
|
1004 |
|
1005 | /**
|
1006 | * The order was replaced by another order, or was updated due to a market event such
|
1007 | * as corporate action.
|
1008 | */
|
1009 | | 'replaced'
|
1010 |
|
1011 | /**
|
1012 | * The order is waiting to be canceled.
|
1013 | */
|
1014 | | 'pending_cancel'
|
1015 |
|
1016 | /**
|
1017 | * The order is waiting to be replaced by another order. The order will reject cancel
|
1018 | * request while in this state.
|
1019 | */
|
1020 | | 'pending_replace'
|
1021 |
|
1022 | /**
|
1023 | * (Uncommon) The order has been received by Alpaca, but hasn't yet been routed to the
|
1024 | * execution venue. This could be seen often out side of trading session hours.
|
1025 | */
|
1026 | | 'accepted'
|
1027 |
|
1028 | /**
|
1029 | * (Uncommon) The order has been received by Alpaca, and routed to the exchanges, but
|
1030 | * has not yet been accepted for execution. This state only occurs on rare occasions.
|
1031 | */
|
1032 | | 'pending_new'
|
1033 |
|
1034 | /**
|
1035 | * (Uncommon) The order has been received by exchanges, and is evaluated for pricing.
|
1036 | * This state only occurs on rare occasions.
|
1037 | */
|
1038 | | 'accepted_for_bidding'
|
1039 |
|
1040 | /**
|
1041 | * (Uncommon) The order has been stopped, and a trade is guaranteed for the order,
|
1042 | * usually at a stated price or better, but has not yet occurred. This state only
|
1043 | * occurs on rare occasions.
|
1044 | */
|
1045 | | 'stopped'
|
1046 |
|
1047 | /**
|
1048 | * (Uncommon) The order has been rejected, and no further updates will occur for the
|
1049 | * order. This state occurs on rare occasions and may occur based on various conditions
|
1050 | * decided by the exchanges.
|
1051 | */
|
1052 | | 'rejected'
|
1053 |
|
1054 | /**
|
1055 | * (Uncommon) The order has been suspended, and is not eligible for trading. This state
|
1056 | * only occurs on rare occasions.
|
1057 | */
|
1058 | | 'suspended'
|
1059 |
|
1060 | /**
|
1061 | * (Uncommon) The order has been completed for the day (either filled or done for day),
|
1062 | * but remaining settlement calculations are still pending. This state only occurs on
|
1063 | * rare occasions.
|
1064 | */
|
1065 | | 'calculated';
|
1066 |
|
1067 | export interface RawLatestTrade {
|
1068 | symbol: string;
|
1069 | trade: {
|
1070 | t: string;
|
1071 | x: string;
|
1072 | p: number;
|
1073 | s: number;
|
1074 | c: string[];
|
1075 | i: number;
|
1076 | z: string;
|
1077 | };
|
1078 | }
|
1079 |
|
1080 | export interface LatestTrade {
|
1081 | raw(): RawLatestTrade;
|
1082 | symbol: string;
|
1083 | trade: {
|
1084 | t: Date;
|
1085 | x: string;
|
1086 | p: number;
|
1087 | s: number;
|
1088 | c: string[];
|
1089 | i: number;
|
1090 | z: string;
|
1091 | };
|
1092 | }
|
1093 |
|
1094 | /**
|
1095 | * An Order in Alpaca
|
1096 | */
|
1097 | export interface Order {
|
1098 | /**
|
1099 | * Get the raw data, exactly as it came from Alpaca
|
1100 | */
|
1101 | raw(): RawOrder;
|
1102 |
|
1103 | /**
|
1104 | * Order id
|
1105 | */
|
1106 | id: string;
|
1107 |
|
1108 | /**
|
1109 | * Client unique order id
|
1110 | */
|
1111 | client_order_id: string;
|
1112 |
|
1113 | /**
|
1114 | * When the order was created
|
1115 | */
|
1116 | created_at: Date;
|
1117 |
|
1118 | /**
|
1119 | * When the order was last updated
|
1120 | */
|
1121 | updated_at: Date;
|
1122 |
|
1123 | /**
|
1124 | * When the order was submitted
|
1125 | */
|
1126 | submitted_at: Date;
|
1127 |
|
1128 | /**
|
1129 | * When the order was filled
|
1130 | */
|
1131 | filled_at: Date;
|
1132 |
|
1133 | /**
|
1134 | * When the order expired
|
1135 | */
|
1136 | expired_at: Date;
|
1137 |
|
1138 | /**
|
1139 | * When the order was canceled
|
1140 | */
|
1141 | canceled_at: Date;
|
1142 |
|
1143 | /**
|
1144 | * When the order failed
|
1145 | */
|
1146 | failed_at: Date;
|
1147 |
|
1148 | /**
|
1149 | * When the order was last replaced
|
1150 | */
|
1151 | replaced_at: Date;
|
1152 |
|
1153 | /**
|
1154 | * The order ID that this order was replaced by
|
1155 | */
|
1156 | replaced_by: string;
|
1157 |
|
1158 | /**
|
1159 | * The order ID that this order replaces
|
1160 | */
|
1161 | replaces: string;
|
1162 |
|
1163 | /**
|
1164 | * Asset ID
|
1165 | */
|
1166 | asset_id: string;
|
1167 |
|
1168 | /**
|
1169 | * Asset symbol
|
1170 | */
|
1171 | symbol: string;
|
1172 |
|
1173 | /**
|
1174 | * Asset class
|
1175 | */
|
1176 | asset_class: string;
|
1177 |
|
1178 | /**
|
1179 | * Ordered quantity
|
1180 | */
|
1181 | qty: number;
|
1182 |
|
1183 | /**
|
1184 | * Filled quantity
|
1185 | */
|
1186 | filled_qty: number;
|
1187 |
|
1188 | /**
|
1189 | * Order type (market, limit, stop, stop_limit, trailing_stop)
|
1190 | */
|
1191 | type: OrderType;
|
1192 |
|
1193 | /**
|
1194 | * Buy or sell
|
1195 | */
|
1196 | side: OrderSide;
|
1197 |
|
1198 | /**
|
1199 | * Order Time in Force
|
1200 | */
|
1201 | time_in_force: OrderTimeInForce;
|
1202 |
|
1203 | /**
|
1204 | * Limit price
|
1205 | */
|
1206 | limit_price: number;
|
1207 |
|
1208 | /**
|
1209 | * Stop price
|
1210 | */
|
1211 | stop_price: number;
|
1212 |
|
1213 | /**
|
1214 | * Filled average price
|
1215 | */
|
1216 | filled_avg_price: number;
|
1217 |
|
1218 | /**
|
1219 | * The status of the order
|
1220 | */
|
1221 | status: OrderStatus;
|
1222 |
|
1223 | /**
|
1224 | * If true, eligible for execution outside regular trading hours.
|
1225 | */
|
1226 | extended_hours: boolean;
|
1227 |
|
1228 | /**
|
1229 | * When querying non-simple order_class orders in a nested style, an array of Order
|
1230 | * entities associated with this order. Otherwise, null.
|
1231 | */
|
1232 | legs: Order[];
|
1233 |
|
1234 | /**
|
1235 | * The dollar value away from the high water mark for trailing stop orders.
|
1236 | */
|
1237 | trail_price: number;
|
1238 |
|
1239 | /**
|
1240 | * The percent value away from the high water mark for trailing stop orders.
|
1241 | */
|
1242 | trail_percent: number;
|
1243 |
|
1244 | /**
|
1245 | * The highest (lowest) market price seen since the trailing stop order was submitted.
|
1246 | */
|
1247 | hwm: number;
|
1248 |
|
1249 | /**
|
1250 | * Mostly used for non-simple orders such as bracket, one-triggers-other, or one-cancels-other.
|
1251 | */
|
1252 | order_class: OrderClass;
|
1253 | }
|
1254 |
|
1255 | /**
|
1256 | * Timeseries data for equity and profit loss information of the account
|
1257 | */
|
1258 | export interface PortfolioHistory {
|
1259 | /**
|
1260 | * time of each data element, left-labeled (the beginning of time window)
|
1261 | */
|
1262 | timestamp: number[];
|
1263 |
|
1264 | /**
|
1265 | * equity value of the account in dollar amount as of the end of each time window
|
1266 | */
|
1267 | equity: number[];
|
1268 |
|
1269 | /**
|
1270 | * profit/loss in dollar from the base value
|
1271 | */
|
1272 | profit_loss: number[];
|
1273 |
|
1274 | /**
|
1275 | * profit/loss in percentage from the base value
|
1276 | */
|
1277 | profit_loss_pct: number[];
|
1278 |
|
1279 | /**
|
1280 | * basis in dollar of the profit loss calculation
|
1281 | */
|
1282 | base_value: number;
|
1283 |
|
1284 | /**
|
1285 | * time window size of each data element
|
1286 | */
|
1287 | timeframe: '1Min' | '5Min' | '15Min' | '1H' | '1D';
|
1288 | }
|
1289 |
|
1290 | /**
|
1291 | * A position with unparsed fields, exactly as Alpaca provides it.
|
1292 | * We encourage you to use the Position interface, which has many of these fields parsed.
|
1293 | */
|
1294 | export interface RawPosition {
|
1295 | asset_id: string;
|
1296 | symbol: string;
|
1297 | exchange: string;
|
1298 | asset_class: string;
|
1299 | avg_entry_price: string;
|
1300 | qty: string;
|
1301 | side: string;
|
1302 | market_value: string | null;
|
1303 | cost_basis: string;
|
1304 | unrealized_pl: string | null;
|
1305 | unrealized_plpc: string | null;
|
1306 | unrealized_intraday_pl: string | null;
|
1307 | unrealized_intraday_plpc: string | null;
|
1308 | current_price: string | null;
|
1309 | lastday_price: string | null;
|
1310 | change_today: string | null;
|
1311 | }
|
1312 |
|
1313 | export type PositionSide = 'long' | 'short';
|
1314 |
|
1315 | /**
|
1316 | * A position in Alpaca
|
1317 | */
|
1318 | export interface Position {
|
1319 | /**
|
1320 | * Get the raw data, exactly as it came from Alpaca
|
1321 | */
|
1322 | raw(): RawPosition;
|
1323 |
|
1324 | /**
|
1325 | * Asset ID
|
1326 | */
|
1327 | asset_id: string;
|
1328 |
|
1329 | /**
|
1330 | * Symbol name of the asset
|
1331 | */
|
1332 | symbol: string;
|
1333 |
|
1334 | /**
|
1335 | * Exchange name of the asset
|
1336 | */
|
1337 | exchange: string;
|
1338 |
|
1339 | /**
|
1340 | * Asset class name
|
1341 | */
|
1342 | asset_class: string;
|
1343 |
|
1344 | /**
|
1345 | * Average entry price of the position
|
1346 | */
|
1347 | avg_entry_price: number;
|
1348 |
|
1349 | /**
|
1350 | * The number of shares
|
1351 | */
|
1352 | qty: number;
|
1353 |
|
1354 | /**
|
1355 | * long or short
|
1356 | */
|
1357 | side: PositionSide;
|
1358 |
|
1359 | /**
|
1360 | * Total dollar amount of the position
|
1361 | */
|
1362 | market_value: number | null;
|
1363 |
|
1364 | /**
|
1365 | * Total cost basis in dollar
|
1366 | */
|
1367 | cost_basis: number;
|
1368 |
|
1369 | /**
|
1370 | * Unrealized profit/loss in dollars
|
1371 | */
|
1372 | unrealized_pl: number | null;
|
1373 |
|
1374 | /**
|
1375 | * Unrealized profit/loss percent (by a factor of 1)
|
1376 | */
|
1377 | unrealized_plpc: number | null;
|
1378 |
|
1379 | /**
|
1380 | * Unrealized profit/loss in dollars for the day
|
1381 | */
|
1382 | unrealized_intraday_pl: number | null;
|
1383 |
|
1384 | /**
|
1385 | * Unrealized profit/loss percent (by a factor of 1)
|
1386 | */
|
1387 | unrealized_intraday_plpc: number | null;
|
1388 |
|
1389 | /**
|
1390 | * Current asset price per share
|
1391 | */
|
1392 | current_price: number | null;
|
1393 |
|
1394 | /**
|
1395 | * Last day's asset price per share based on the closing value of the last trading day
|
1396 | */
|
1397 | lastday_price: number | null;
|
1398 |
|
1399 | /**
|
1400 | * Percent change from last day price (by a factor of 1)
|
1401 | */
|
1402 | change_today: number | null;
|
1403 | }
|
1404 |
|
1405 | export type ActivityType =
|
1406 | /**
|
1407 | * Order fills (both partial and full fills)
|
1408 | */
|
1409 | | 'FILL'
|
1410 |
|
1411 | /**
|
1412 | * Cash transactions (both CSD and CSR)
|
1413 | */
|
1414 | | 'TRANS'
|
1415 |
|
1416 | /**
|
1417 | * Miscellaneous or rarely used activity types (All types except those in TRANS, DIV,
|
1418 | * or FILL)
|
1419 | */
|
1420 | | 'MISC'
|
1421 |
|
1422 | /**
|
1423 | * ACATS IN/OUT (Cash)
|
1424 | */
|
1425 | | 'ACATC'
|
1426 |
|
1427 | /**
|
1428 | * ACATS IN/OUT (Securities)
|
1429 | */
|
1430 | | 'ACATS'
|
1431 |
|
1432 | /**
|
1433 | * Cash disbursement(+)
|
1434 | */
|
1435 | | 'CSD'
|
1436 |
|
1437 | /**
|
1438 | * Cash receipt(-)
|
1439 | */
|
1440 | | 'CSR'
|
1441 |
|
1442 | /**
|
1443 | * Dividends
|
1444 | */
|
1445 | | 'DIV'
|
1446 |
|
1447 | /**
|
1448 | * Dividend (capital gain long term)
|
1449 | */
|
1450 | | 'DIVCGL'
|
1451 |
|
1452 | /**
|
1453 | * Dividend (capital gain short term)
|
1454 | */
|
1455 | | 'DIVCGS'
|
1456 |
|
1457 | /**
|
1458 | * Dividend fee
|
1459 | */
|
1460 | | 'DIVFEE'
|
1461 |
|
1462 | /**
|
1463 | * Dividend adjusted (Foreign Tax Withheld)
|
1464 | */
|
1465 | | 'DIVFT'
|
1466 |
|
1467 | /**
|
1468 | * Dividend adjusted (NRA Withheld)
|
1469 | */
|
1470 | | 'DIVNRA'
|
1471 |
|
1472 | /**
|
1473 | * Dividend return of capital
|
1474 | */
|
1475 | | 'DIVROC'
|
1476 |
|
1477 | /**
|
1478 | * Dividend adjusted (Tefra Withheld)
|
1479 | */
|
1480 | | 'DIVTW'
|
1481 |
|
1482 | /**
|
1483 | * Dividend (tax exempt)
|
1484 | */
|
1485 | | 'DIVTXEX'
|
1486 |
|
1487 | /**
|
1488 | * Interest (credit/margin)
|
1489 | */
|
1490 | | 'INT'
|
1491 |
|
1492 | /**
|
1493 | * Interest adjusted (NRA Withheld)
|
1494 | */
|
1495 | | 'INTNRA'
|
1496 |
|
1497 | /**
|
1498 | * Interest adjusted (Tefra Withheld)
|
1499 | */
|
1500 | | 'INTTW'
|
1501 |
|
1502 | /**
|
1503 | * Journal entry
|
1504 | */
|
1505 | | 'JNL'
|
1506 |
|
1507 | /**
|
1508 | * Journal entry (cash)
|
1509 | */
|
1510 | | 'JNLC'
|
1511 |
|
1512 | /**
|
1513 | * Journal entry (stock)
|
1514 | */
|
1515 | | 'JNLS'
|
1516 |
|
1517 | /**
|
1518 | * Merger/Acquisition
|
1519 | */
|
1520 | | 'MA'
|
1521 |
|
1522 | /**
|
1523 | * Name change
|
1524 | */
|
1525 | | 'NC'
|
1526 |
|
1527 | /**
|
1528 | * Option assignment
|
1529 | */
|
1530 | | 'OPASN'
|
1531 |
|
1532 | /**
|
1533 | * Option expiration
|
1534 | */
|
1535 | | 'OPEXP'
|
1536 |
|
1537 | /**
|
1538 | * Option exercise
|
1539 | */
|
1540 | | 'OPXRC'
|
1541 |
|
1542 | /**
|
1543 | * Pass Thru Charge
|
1544 | */
|
1545 | | 'PTC'
|
1546 |
|
1547 | /**
|
1548 | * Pass Thru Rebate
|
1549 | */
|
1550 | | 'PTR'
|
1551 |
|
1552 | /**
|
1553 | * Reorg CA
|
1554 | */
|
1555 | | 'REORG'
|
1556 |
|
1557 | /**
|
1558 | * Symbol change
|
1559 | */
|
1560 | | 'SC'
|
1561 |
|
1562 | /**
|
1563 | * Stock spinoff
|
1564 | */
|
1565 | | 'SSO'
|
1566 |
|
1567 | /**
|
1568 | * Stock split
|
1569 | */
|
1570 | | 'SSP';
|
1571 |
|
1572 | export interface RawTradeActivity {
|
1573 | // Only FILL
|
1574 | activity_type: Extract<ActivityType, 'FILL'>;
|
1575 | cum_qty: string;
|
1576 | id: string;
|
1577 | leaves_qty: string;
|
1578 | price: string;
|
1579 | qty: string;
|
1580 | side: string;
|
1581 | symbol: string;
|
1582 | transaction_time: string;
|
1583 | order_id: string;
|
1584 | type: string;
|
1585 | }
|
1586 |
|
1587 | export interface RawNonTradeActivity {
|
1588 | // Everything except FILL
|
1589 | activity_type: Exclude<ActivityType, 'FILL'>;
|
1590 | id: string;
|
1591 | date: string;
|
1592 | net_amount: string;
|
1593 | symbol: string;
|
1594 | qty: string;
|
1595 | per_share_amount: string;
|
1596 | }
|
1597 |
|
1598 | export type TradeActivityType = 'fill' | 'partial_fill';
|
1599 | export type TradeActivitySide = 'buy' | 'sell';
|
1600 |
|
1601 | export interface TradeActivity {
|
1602 | /**
|
1603 | * Get the raw data, exactly as it came from Alpaca
|
1604 | */
|
1605 | raw(): RawTradeActivity;
|
1606 |
|
1607 | /**
|
1608 | * FILL
|
1609 | */
|
1610 | activity_type: Extract<ActivityType, 'FILL'>;
|
1611 |
|
1612 | /**
|
1613 | * The cumulative quantity of shares involved in the execution.
|
1614 | */
|
1615 | cum_qty: number;
|
1616 |
|
1617 | /**
|
1618 | * An id for the activity. Always in "::" format. Can be sent as page_token in requests
|
1619 | * to facilitate the paging of results.
|
1620 | */
|
1621 | id: string;
|
1622 |
|
1623 | /**
|
1624 | * For partially_filled orders, the quantity of shares that are left to be filled.
|
1625 | */
|
1626 | leaves_qty: number;
|
1627 |
|
1628 | /**
|
1629 | * The per-share price that the trade was executed at.
|
1630 | */
|
1631 | price: number;
|
1632 |
|
1633 | /**
|
1634 | * The number of shares involved in the trade execution.
|
1635 | */
|
1636 | qty: number;
|
1637 |
|
1638 | /**
|
1639 | * buy or sell
|
1640 | */
|
1641 | side: TradeActivitySide;
|
1642 |
|
1643 | /**
|
1644 | * The symbol of the security being traded.
|
1645 | */
|
1646 | symbol: string;
|
1647 |
|
1648 | /**
|
1649 | * The time at which the execution occurred.
|
1650 | */
|
1651 | transaction_time: string;
|
1652 |
|
1653 | /**
|
1654 | * The id for the order that filled.
|
1655 | */
|
1656 | order_id: string;
|
1657 |
|
1658 | /**
|
1659 | * fill or partial_fill
|
1660 | */
|
1661 | type: TradeActivityType;
|
1662 | }
|
1663 |
|
1664 | export interface NonTradeActivity {
|
1665 | /**
|
1666 | * Get the raw data, exactly as it came from Alpaca
|
1667 | */
|
1668 | raw(): RawNonTradeActivity;
|
1669 |
|
1670 | /**
|
1671 | * Activity type
|
1672 | */
|
1673 | activity_type: Exclude<ActivityType, 'FILL'>;
|
1674 |
|
1675 | /**
|
1676 | * An ID for the activity, always in "::" format. Can be sent as page_token in requests
|
1677 | * to facilitate the paging of results.
|
1678 | */
|
1679 | id: string;
|
1680 |
|
1681 | /**
|
1682 | * The date on which the activity occurred or on which the transaction associated with
|
1683 | * the activity settled.
|
1684 | */
|
1685 | date: string;
|
1686 |
|
1687 | /**
|
1688 | * The net amount of money (positive or negative) associated with the activity.
|
1689 | */
|
1690 | net_amount: number;
|
1691 |
|
1692 | /**
|
1693 | * The symbol of the security involved with the activity. Not present for all activity
|
1694 | * types.
|
1695 | */
|
1696 | symbol: string;
|
1697 |
|
1698 | /**
|
1699 | * For dividend activities, the number of shares that contributed to the payment. Not
|
1700 | * present for other activity types.
|
1701 | */
|
1702 | qty: number;
|
1703 |
|
1704 | /**
|
1705 | * For dividend activities, the average amount paid per share. Not present for other
|
1706 | * activity types.
|
1707 | */
|
1708 | per_share_amount: number;
|
1709 | }
|
1710 |
|
1711 | export type RawActivity = RawTradeActivity | RawNonTradeActivity;
|
1712 |
|
1713 | export type Activity = TradeActivity | NonTradeActivity;
|
1714 |
|
1715 | /**
|
1716 | * The following type mirrors OrderStatus almost exactly,
|
1717 | * but differs slightly in its wording for each event.
|
1718 | * See https://alpaca.markets/docs/api-references/broker-api/events/#trade-events
|
1719 | * for an updated list of these events and their detailed descriptions.
|
1720 | */
|
1721 | export type TradeUpdateEvent =
|
1722 | | 'new'
|
1723 | | 'fill'
|
1724 | | 'partial_fill'
|
1725 | | 'canceled'
|
1726 | | 'expired'
|
1727 | | 'done_for_day'
|
1728 | | 'replaced'
|
1729 | | 'rejected'
|
1730 | | 'pending_new'
|
1731 | | 'stopped'
|
1732 | | 'pending_cancel'
|
1733 | | 'pending_replace'
|
1734 | | 'calculated'
|
1735 | | 'suspended'
|
1736 | | 'order_replace_rejected'
|
1737 | | 'order_cancel_rejected';
|
1738 |
|
1739 | export interface RawTradeUpdate {
|
1740 | event: TradeUpdateEvent;
|
1741 | execution_id: string;
|
1742 | order: RawOrder;
|
1743 | event_id?: string;
|
1744 | at?: string;
|
1745 | timestamp?: string;
|
1746 | position_qty?: string;
|
1747 | price?: string;
|
1748 | qty?: string;
|
1749 | }
|
1750 |
|
1751 | export interface TradeUpdate {
|
1752 | /**
|
1753 | * Get the raw data, exactly as it came from Alpaca
|
1754 | */
|
1755 | raw: () => RawTradeUpdate;
|
1756 |
|
1757 | /**
|
1758 | * Trade update event type
|
1759 | */
|
1760 | event: TradeUpdateEvent;
|
1761 |
|
1762 | /**
|
1763 | * Corresponding execution of an order.
|
1764 | * If an order gets filled over two executions (a partial_fill for example),
|
1765 | * you will receive two events with different IDs.
|
1766 | */
|
1767 | execution_id: string;
|
1768 |
|
1769 | /**
|
1770 | * Monotonically increasing 64-bit integer.
|
1771 | * Haven't yet observed this property in practice, but it is
|
1772 | * on Alpaca's docs here: https://alpaca.markets/docs/api-references/broker-api/events/#trade-events,
|
1773 | * including for completeness.
|
1774 | */
|
1775 | event_id?: number;
|
1776 |
|
1777 | /**
|
1778 | * The associated order that a trade_update event comes with
|
1779 | */
|
1780 | order: Order;
|
1781 |
|
1782 | /**
|
1783 | * The timestamp of the trade update event.
|
1784 | * Alpaca docs at https://alpaca.markets/docs/api-references/broker-api/events/#trade-events
|
1785 | * are confusing. They say the 'at' property will contain the timestamp of
|
1786 | * the event, but currently as of 3/10/22 this is in the 'timestamp' property
|
1787 | * instead. Including both for completeness.
|
1788 | */
|
1789 | at?: Date;
|
1790 |
|
1791 | /**
|
1792 | * The timestamp of the trade update event.
|
1793 | * Alpaca docs at https://alpaca.markets/docs/api-references/broker-api/events/#trade-events
|
1794 | * are confusing. They say the 'at' property will contain the timestamp of
|
1795 | * the event, but currently as of 3/10/22 this is in the 'timestamp' property
|
1796 | * instead. Including both for completeness.
|
1797 | */
|
1798 | timestamp?: Date;
|
1799 |
|
1800 | /**
|
1801 | * The size of your total position, after a fill or partial fill event, in shares.
|
1802 | */
|
1803 | position_qty?: number;
|
1804 |
|
1805 | /**
|
1806 | * The average price per share at which the order was filled or partially filled
|
1807 | */
|
1808 | price?: number;
|
1809 |
|
1810 | /**
|
1811 | * The amount of shares that were filled in a trade update of type fill or partial_fill.
|
1812 | * Equivalent to the order.filled_qty property, which is preferred.
|
1813 | */
|
1814 | qty?: number;
|
1815 | }
|
1816 |
|
1817 | export interface Watchlist {
|
1818 | /**
|
1819 | * account ID
|
1820 | */
|
1821 | account_id: string;
|
1822 |
|
1823 | /**
|
1824 | * the content of this watchlist, in the order as registered by the client
|
1825 | */
|
1826 | assets: Asset[];
|
1827 |
|
1828 | /**
|
1829 | * When the watchlist was created
|
1830 | */
|
1831 | created_at: string;
|
1832 |
|
1833 | /**
|
1834 | * watchlist id
|
1835 | */
|
1836 | id: string;
|
1837 |
|
1838 | /**
|
1839 | * user-defined watchlist name (up to 64 characters)
|
1840 | */
|
1841 | name: string;
|
1842 |
|
1843 | /**
|
1844 | * When the watchlist was last updated
|
1845 | */
|
1846 | updated_at: string;
|
1847 | }
|
1848 |
|
1849 | export interface News {
|
1850 | id: number;
|
1851 | headline: string;
|
1852 | author: string;
|
1853 | created_at: Date;
|
1854 | updated_at: Date;
|
1855 | summary: string;
|
1856 | url: string;
|
1857 | images: any[];
|
1858 | symbols: string[];
|
1859 | source: string;
|
1860 | }
|
1861 |
|
1862 | export interface NewsPage {
|
1863 | news: News[];
|
1864 | next_page_token: string;
|
1865 | }
|
1866 |
|
1867 | export type Channel = 'trades' | 'quotes' | 'bars' | 'trade_updates';
|
1868 |
|
1869 | export interface Message {
|
1870 | T: 'success' | 'error' | 'subscription';
|
1871 | code?: number;
|
1872 | msg: string;
|
1873 | [key: string]: any;
|
1874 | }
|