1 |
|
2 | import WebSocket from 'isomorphic-ws';
|
3 | import EventEmitter from 'eventemitter3';
|
4 | import { Bar, Channel, DataSource, DefaultCredentials, Quote, Trade, TradeUpdate, Message, Endpoints } from './entities.js';
|
5 | export declare interface Events {
|
6 | open: (stream: AlpacaStream) => void;
|
7 | close: (stream: AlpacaStream) => void;
|
8 | authenticated: (stream: AlpacaStream) => void;
|
9 | success: (message: Message) => void;
|
10 | error: (message: WebSocket.ErrorEvent) => void;
|
11 | subscription: (message: Message) => void;
|
12 | message: (message: Object) => void;
|
13 | trade_updates: (update: TradeUpdate) => void;
|
14 | trade: (trade: Trade) => void;
|
15 | quote: (quote: Quote) => void;
|
16 | bar: (bar: Bar) => void;
|
17 | }
|
18 | export declare interface AlpacaStream {
|
19 | on<U extends keyof Events>(event: U, listener: Events[U]): this;
|
20 | once<U extends keyof Events>(event: U, listener: Events[U]): this;
|
21 | emit<U extends keyof Events>(event: U, ...args: Parameters<Events[U]>): boolean;
|
22 | }
|
23 | export declare class AlpacaStream extends EventEmitter<string | symbol | any> {
|
24 | protected params: {
|
25 | credentials: DefaultCredentials;
|
26 | type: 'account' | 'market_data';
|
27 | source?: DataSource;
|
28 | endpoints?: Endpoints | Map<keyof Endpoints, any>;
|
29 | };
|
30 | private host;
|
31 | private connection;
|
32 | private authenticated;
|
33 | private baseURLs;
|
34 | constructor(params: {
|
35 | credentials: DefaultCredentials;
|
36 | type: 'account' | 'market_data';
|
37 | source?: DataSource;
|
38 | endpoints?: Endpoints | Map<keyof Endpoints, any>;
|
39 | });
|
40 | /**
|
41 | * Retrieve the underlying WebSocket connection AlpacaStream uses.
|
42 | * Now callers can read and modify properties of the web socket
|
43 | * i.e., close the websocket with AlpacaStream.getConnection().close().
|
44 | * @returns a WebSocket object
|
45 | */
|
46 | getConnection(): WebSocket;
|
47 | /**
|
48 | * Subscribe to an account or data stream channel.
|
49 | * @param channel trades, quotes, bars, trade_updates
|
50 | * @param symbols only use with data stream ex. [ "AAPL", "TSLA", ... ]
|
51 | */
|
52 | subscribe(channel: Channel, symbols?: string[]): this;
|
53 | /**
|
54 | * Unsubscribe to an account or data stream channel.
|
55 | * @param channel trades, quotes, bars, trade_updates
|
56 | * @param symbols only use with data stream ex. [ "AAPL", "TSLA", ... ]
|
57 | */
|
58 | unsubscribe(channel: Channel, symbols?: string[]): this;
|
59 | private send;
|
60 | }
|