This repository has been archived by the owner on May 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
index.d.ts
450 lines (388 loc) · 13.8 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
type AuthTokens = {
access: string,
refresh: string,
expires: number
};
// Supported exchanges
type Exchange = 'NYSE' | 'NASDAQ' | 'TSX' | 'TSX-V' | 'NEO' | 'CC';
/**
* A ticker may be provided to the API as a string or an object with
* well-defined attributes of symbol, exchange, or id.
*
* @param {string} symbol symbol that the security trades under.
* @param {string} [exchange] exchange under which the security trades in
* @param {string} [id] The internal Wealthsimple Trade security id
*/
type Ticker = string | {
symbol: string,
exchange?: Exchange,
id?: string
};
export namespace auth {
/**
* Supported Auth Events at this time.
*/
type AuthEvent = 'otp' | 'refresh';
/**
* Supported auth events:
*
* 'otp':
* - Invoked during a login attempt to retrieve an OTP code
* - Handler type:
* - A function: If you provide a function, this function is triggered whenever the event associated
* with it occurs.
* - A string: Appropriate for simple value passing (e.g., providing OTP manually for logging in)
*
* 'refresh':
* - Invoked when the authentication state has been successfully refreshed.
* - Handler type:
* - A function: Receives `tokens` as an argument and is not expected to return anything
**/
type OTPEvent = string | (() => string | Promise<string>);
type RefreshEvent = ((tokens: AuthTokens) => Promise<void>);
type AuthEventHandler = OTPEvent | RefreshEvent;
/**
* One-Time Passwords (OTP) are mandatory to login to your Wealthsimple Trade account.
* However, wstrade-api does not have the ability to get the OTP token for you (for obvious reasons).
* So, in order to successfuly login, you must provide the OTP code that wstrade-api can use to
* complete a successful login.
*/
const otp: AuthEventHandler;
/**
* Attach a handler for the event.
*
* @param event authentication event to handle
* @param handler Handler for the authentication event
*/
function on(event: AuthEvent, handler: AuthEventHandler): void;
/**
* Initialize the auth module with an existing state of tokens.
* The state provided should contain access, refresh, and expires properties.
*
* @param state Pre-existing authentication state
*/
function use(state: AuthTokens): void;
/**
* Snapshot of the current authentication tokens.
*/
function tokens(): AuthTokens;
/**
* Attempt a login with the email and password combination. A successful login
* will populate the auth.tokens object.
*
* @param email Account email
* @param password Account password
*/
function login(email: string, password: string): Promise<void>;
/**
* Refreshes the set of tokens for the auth module
*
* The refresh token must be present for this refresh call
* to succeed.
*/
function refresh(): Promise<void>;
}
export namespace headers {
/**
* Appends a header name-value pair to all requests.
*
* @param {*} name Header key
* @param {*} value Header value
*/
function add(name: string, value: string): void;
/**
* Removes a custom header from all requests.
*
* @param {*} name Header key
*/
function remove(name: string): void;
/**
* Clears all custom headers.
*/
function clear(): void;
/**
* Produces a list of custom headers.
*/
function values(): Array<String>;
}
export namespace accounts {
/**
* A Wealthsimple Trade account can have 4 underlying asset accounts: Personal, TFSA, RRSP, and Crypto.
* AccountList is the object returned by the accounts.all(), associating any open account types
* with their ids.
*
* You will need these account ids to perform certain API calls like checking the positions in a specific
* account.
*/
type AccountList = {
personal?: string,
tfsa?: string,
rrsp?: string,
crypto?: string,
};
// supported activity types
type ActivityType = 'sell' | 'buy' | 'deposit' | 'withdrawal' | 'dividend' | 'institutional_transfer' |
'internal_transfer' | 'refund' | 'referral_bonus' | 'affiliate';
// filters that can be provided to the activities() API.
type ActivitiesFilters = {
limit?: number,
accounts?: String[],
type?: ActivityType[]
};
/**
* The set of time intervals that are supported by the accounts.history() API call.
*/
type HistoryInterval = '1d' | '1w' | '1m' | '3m' | '1y' | 'all';
/**
* Retrieves all open account ids under this Wealthsimple Trade account.
*/
function all(): Promise<AccountList>;
/**
* Retrieves the top-level data of the account, including Wealthsimple Trade account id, account types,
* account values, and more.
*/
function data(): Promise<any>;
/**
* Retrieves some surface information about you like your name and email, account
* signatures, and other metadata.
*/
function me(): Promise<any>;
/**
* Detailed information about you that you provided on signup, like residential and
* mailing addresses, employment, phone numbers, and so on.
*/
function person(): Promise<any>;
/**
* Query the history of the account within a certain time interval.
*
* @param {*} interval The time interval for the history query
* @param {*} accountId The account to grab history for
*/
function history(interval: HistoryInterval, accountId: string): Promise<any>;
/**
* Fetches activities on your Wealthsimnple Trade account. You can limit number of activities
* to fetch or refine what activities are fetched based on activity type (e.g., buy, sell),
* account (e.g., tfsa, rrsp).
*/
function activities(filters?: ActivitiesFilters): Promise<any>;
/**
* Retrieves all bank accounts linked to the Wealthsimple Trade account.
*/
function getBankAccounts(): Promise<any>;
/**
* Grab all deposit records on the Wealthsimple Trade account.
*/
function deposits(): Promise<any>;
/**
* Lists all positions in the specified trading account under the Wealthsimple Trade Account.
*
* @param {*} accountId The specific account in the Wealthsimple Trade account
*/
function positions(accountId: string): Promise<any>;
}
export namespace orders {
/**
* Collects orders (filled, pending, cancelled) for the provided page and
* account id.
*
* @param {*} accountId The specific account in the Wealthsimple Trade account
* @param {*} page The orders page index to seek to
*/
function page(accountId: string, page: number): Promise<any>;
/**
* Collects all orders (filled, pending, cancelled) for the specific account.
*
* @param {*} accountId The specific account in the Wealthsimple Trade account
*/
function all(accountId: string): Promise<any>;
/**
* Retrieves pending orders for the specified security in the account.
*
* @param {*} accountId The specific account in the Wealthsimple Trade account
* @param {*} ticker (optional) The security symbol
*/
function pending(accountId: string, ticker?: Ticker): Promise<any>;
/**
* Retrieves filled orders for the specified security in the account.
*
* @param {*} accountId The specific account in the Wealthsimple Trade account
* @param {*} ticker (optional) The security symbol
*/
function filled(accountId: string, ticker?: Ticker): Promise<any>;
/**
* Retrieves cancelled orders for the specified security in the account.
*
* @param {*} accountId The specific account in the Wealthsimple Trade account
* @param {*} ticker (optional) The security symbol
*/
function cancelled(accountId: string, ticker?: Ticker): Promise<any>;
/**
* Cancels the pending order specified by the order id.
*
* @param {*} orderId The pending order to cancel
*/
function cancel(orderId: string): Promise<any>;
/**
* Cancels all pending orders under the open account specified by accountId.
*
* @param {*} accountId The specific account in the Wealthsimple Trade account
*/
function cancelPending(accountId: string): Promise<any>;
/**
* Purchase a security with a market order.
*
* @param {*} accountId The account to make the transaction from
* @param {*} ticker The security symbol
* @param {*} quantity The number of securities to purchase
*/
function marketBuy(accountId: string, ticker: Ticker, quantity: number): Promise<any>;
/**
* Purchase a security with a limit order.
*
* @param {*} accountId The account to make the transaction from
* @param {*} ticker The security symbol
* @param {*} limit The maximum price to purchase the security at
* @param {*} quantity The number of securities to purchase
*/
function limitBuy(accountId: string, ticker: Ticker, limit: number, quantity: number): Promise<any>;
/**
* Purchase a security with a stop limit order.
*
* @param {*} accountId The account to make the transaction from
* @param {*} ticker The security symbol
* @param {*} stop The price at which the order converts to a limit order
* @param {*} limit The maximum price to purchase the security at
* @param {*} quantity The number of securities to purchase
*/
function stopLimitBuy(accountId: string, ticker: Ticker, stop: number, limit: number, quantity: number): Promise<any>;
/**
* Sell a security with a market order.
*
* @param {*} accountId The account to make the transaction from
* @param {*} ticker The security symbol
* @param {*} quantity The number of securities to purchase
*/
function marketSell(accountId: string, ticker: Ticker, quantity: number): Promise<any>;
/**
* Sell a security with a limit order.
*
* @param {*} accountId The account to make the transaction from
* @param {*} ticker The security symbol
* @param {*} limit The minimum price to sell the security at
* @param {*} quantity The number of securities to sell
*/
function limitSell(accountId: string, ticker: Ticker, limit: number, quantity: number): Promise<any>;
/**
* Sell a security with a stop limit order.
*
* @param {*} accountId The account to make the transaction from
* @param {*} ticker The security symbol
* @param {*} stop The price at which the order converts to a limit order
* @param {*} limit The minimum price to sell the security at
* @param {*} quantity The number of securities to sell
*/
function stopLimitSell(accountId: string, ticker: Ticker, stop: number, limit: number, quantity: number): Promise<any>;
}
export namespace quotes {
/**
* The quotes module provides support for customizing the source of quotes
* for specified exchanges through the QuoteProvider type.
*
* Pass a QuoteProvider object to quotes.use(), and your custom quote provider
* will be used for the exchange you enable it for.
*/
type QuoteProvider = {
quote: (ticker: Ticker) => Promise<number>;
};
// Historical intervals for quotes
type QuotesInterval = '1d' | '1w' | '1m' | '3m' | '1y' | '5y';
/**
* Wealthsimple Trade is our default quote provider for all exchanges,
* despite having a 15-minute delay.
*/
const defaultProvider: QuoteProvider;
/**
* Load a custom provider for the exchange.
*
* @param {*} exchange The exchange that the provider fetches quotes for
* @param {*} provider The provider object containing the quote() implementation.
*/
function use(exchange: Exchange, provider: QuoteProvider): void;
/**
* Obtains a quote for the ticker. The source of the quote may be a custom
* provider if a valid provider is registered for the exchange that the
* ticker trades on.
*
* @param {*} ticker The security to get a quote for.
*/
function get(ticker: Ticker): Promise<number>;
/**
* Retrieves the historical quotes within a specified interval for the ticker.
* The source of the historical data is not customizable at this time because
* there is no need for it to be so.
*
* @param {*} ticker The ticker to search historical quotes for
* @param {*} interval The time range of the quotes
*/
function history(ticker: Ticker, interval: QuotesInterval): Promise<Array<any>>;
}
export namespace data {
/**
* A snapshot of the current USD/CAD exchange rates on the Wealthsimple Trade
* platform.
*/
function exchangeRates(): Promise<any>;
/**
* Information about a security on the Wealthsimple Trade Platform.
*
* @param {Ticker} ticker The security symbol.
* @param {boolean} extensive Pulls a more detailed report of the security using the /securities/{id} API
*/
function getSecurity(ticker: Ticker, extensive?: boolean): Promise<any>;
/**
* Fetches a mapping of all security groups (available on the Trade platform) to
* their group ids.
*/
function securityGroups(): Promise<any>;
/**
* Retrieves all securities associated with the group name or id.
*
* - If you provide the group name, we will automatically do a lookup
* from the Trade servers to get its identifier.
*
* - Alternatively, You can get a list of all groups (with their group ids) from
* data.groups() and provide the group identifier directly.
*
* @param {*} group The security group name or identifier
*/
function getSecurityGroup(group: string): Promise<Array<any>>;
}
/**
* Enable or disable an optional feature within wstrade-api.
*
* Examples:
* ---
* config('implicit_token_refresh')
* Enables implicit refreshing of tokens.
*
* config('no_implicit_token_refresh')
* Disables implicit refreshing of tokens.
*
* @param {*} feature The string identifier for the feature, starting with "no_" if
* you wish to disable it.
*/
export function config(feature: string): void;
type TradeAPI = {
auth: typeof auth,
headers: typeof headers,
accounts: typeof accounts,
orders: typeof orders,
quotes: typeof quotes,
data: typeof data,
config: typeof config
};
/**
* Create a new Trade API object with its own authentication state.
* This is useful if you are managing several Trade accounts.
*/
export function Session(): TradeAPI;