-
Notifications
You must be signed in to change notification settings - Fork 104
/
index.d.ts
853 lines (833 loc) · 24.9 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
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
declare module "@barchart/marketdata-api-js" {
class Logger {
/**
* Writes a log message.
*
* @public
*/
public log(): void;
/**
* Writes a log message, at "trace" level.
*
* @public
*/
public trace(): void;
/**
* Writes a log message, at "debug" level.
*
* @public
*/
public debug(): void;
/**
* Writes a log message, at "info" level.
*
* @public
*/
public info(): void;
/**
* Writes a log message, at "warn" level.
*
* @public
*/
public warn(): void;
/**
* Writes a log message, at "error" level.
*
* @public
*/
public error(): void;
}
class LoggerFactory {
/**
* Configures the library to write log messages to the console.
*
* @public
* @static
*/
public static configureForConsole(): void;
/**
* Configures the mute all log messages.
*
* @public
* @static
*/
public static configureForSilence(): void;
/**
* Configures the library to delegate any log messages to a custom
* implementation of the {@link LoggerProvider} interface.
*
* @public
* @static
* @param {LoggerProvider} provider
*/
public static configure(provider: LoggerProvider): void;
/**
* Returns an instance of {@link Logger} for a specific category.
*
* @public
* @static
* @param {String} category
* @return {Logger}
*/
public static getLogger(category: string): Logger;
}
class LoggerProvider {
/**
* Returns an instance of {@link Logger}.
*
* @public
* @param {String} category
* @returns {Logger}
*/
public getLogger(category: string): Logger;
}
class Connection extends ConnectionBase {
/**
* Connects to the given server with username and password.
*
* @public
* @param {string} server
* @param {string} username
* @param {string} password
* @param {WebSocketAdapterFactory=} webSocketAdapterFactory
*/
public connect(
server: string,
username: string,
password: string,
webSocketAdapterFactory?: WebSocketAdapterFactory
): void;
/**
* Forces a disconnect from the server.
*
* @public
*/
public disconnect(): void;
/**
* Causes the market state to stop updating. All subscriptions are maintained.
*
* @public
*/
public pause(): void;
/**
* Causes the market state to begin updating again (after {@link ConnectionBase#pause} has been called).
*
* @public
*/
public resume(): void;
/**
* Initiates a subscription to an {@link Subscription.EventType} and
* registers the callback for notifications.
*
* @public
* @param {Subscription.EventType} eventType
* @param {function} callback - notified each time the event occurs
* @param {String=} symbol - A symbol, if applicable, to the given {@link Subscription.EventType}
*/
public on(
eventType: Subscription.EventType,
callback: (...params: any[]) => any,
symbol?: string
): void;
/**
* Stops notification of the callback for the {@link Subscription.EventType}.
* See {@link ConnectionBase#on}.
*
* @public
* @param {Subscription.EventType} eventType - the {@link Subscription.EventType} which was passed to {@link ConnectionBase#on}
* @param {function} callback - the callback which was passed to {@link ConnectionBase#on}
* @param {String=} symbol - A symbol, if applicable, to the given {@link Subscription.EventType}
*/
public off(
eventType: Subscription.EventType,
callback: (...params: any[]) => any,
symbol?: string
): void;
/**
* The frequency, in milliseconds, used to poll for changes to {@link Quote}
* objects. A null value indicates streaming updates (default).
*
* @public
* @returns {number|null}
*/
public getPollingFrequency(): number | null;
/**
* Sets the polling frequency, in milliseconds. A null value indicates
* streaming market updates (where polling is not used).
*
* @public
* @param {number|null} pollingFrequency
*/
public setPollingFrequency(pollingFrequency: number | null): void;
/**
* Returns the {@link MarketState} singleton, used to access {@link Quote},
* {@link Profile}, and {@link CumulativeVolume} objects.
*
* @returns {MarketState}
*/
getMarketState(): MarketState;
/**
* @public
* @returns {null|string}
*/
public getServer(): null | string;
/**
* @public
* @returns {null|string}
*/
public getPassword(): null | string;
/**
* @public
* @returns {null|string}
*/
public getUsername(): null | string;
/**
* Get an unique identifier for the current instance.
*
* @protected
* @returns {Number}
*/
protected _getInstance(): number;
}
class ConnectionBase {
/**
* Connects to the given server with username and password.
*
* @public
* @param {string} server
* @param {string} username
* @param {string} password
* @param {WebSocketAdapterFactory=} webSocketAdapterFactory
*/
public connect(
server: string,
username: string,
password: string,
webSocketAdapterFactory?: WebSocketAdapterFactory
): void;
/**
* Forces a disconnect from the server.
*
* @public
*/
public disconnect(): void;
/**
* Causes the market state to stop updating. All subscriptions are maintained.
*
* @public
*/
public pause(): void;
/**
* Causes the market state to begin updating again (after {@link ConnectionBase#pause} has been called).
*
* @public
*/
public resume(): void;
/**
* Initiates a subscription to an {@link Subscription.EventType} and
* registers the callback for notifications.
*
* @public
* @param {Subscription.EventType} eventType
* @param {function} callback - notified each time the event occurs
* @param {String=} symbol - A symbol, if applicable, to the given {@link Subscription.EventType}
*/
public on(
eventType: Subscription.EventType,
callback: (...params: any[]) => any,
symbol?: string
): void;
/**
* Stops notification of the callback for the {@link Subscription.EventType}.
* See {@link ConnectionBase#on}.
*
* @public
* @param {Subscription.EventType} eventType - the {@link Subscription.EventType} which was passed to {@link ConnectionBase#on}
* @param {function} callback - the callback which was passed to {@link ConnectionBase#on}
* @param {String=} symbol - A symbol, if applicable, to the given {@link Subscription.EventType}
*/
public off(
eventType: Subscription.EventType,
callback: (...params: any[]) => any,
symbol?: string
): void;
/**
* The frequency, in milliseconds, used to poll for changes to {@link Quote}
* objects. A null value indicates streaming updates (default).
*
* @public
* @returns {number|null}
*/
public getPollingFrequency(): number | null;
/**
* Sets the polling frequency, in milliseconds. A null value indicates
* streaming market updates (where polling is not used).
*
* @public
* @param {number|null} pollingFrequency
*/
public setPollingFrequency(pollingFrequency: number | null): void;
/**
* Returns the {@link MarketState} singleton, used to access {@link Quote},
* {@link Profile}, and {@link CumulativeVolume} objects.
*
* @returns {MarketState}
*/
getMarketState(): MarketState;
/**
* @public
* @returns {null|string}
*/
public getServer(): null | string;
/**
* @public
* @returns {null|string}
*/
public getPassword(): null | string;
/**
* @public
* @returns {null|string}
*/
public getUsername(): null | string;
/**
* Get an unique identifier for the current instance.
*
* @protected
* @returns {Number}
*/
protected _getInstance(): number;
}
/**
* @namespace Subscription
*/
namespace Subscription {
/**
* A data feed type. See {@link ConnectionBase#on}.
*
* @public
* @memberof Subscription
* @enum {string}
* @readonly
*/
const enum EventType {
MarketDepth = "marketDepth",
MarketUpdate = "marketUpdate",
CumulativeVolume = "cumulativeVolume",
Timestamp = "timestamp",
Events = "events"
}
}
/**
* @typedef PriceLevel
* @inner
* @type Object
* @property {number} price
* @property {number} volume
*/
type PriceLevel = {
price: number;
volume: number;
};
class CumulativeVolume {
/**
* @property {string} symbol
*/
symbol: {
symbol: string;
};
/**
* Given a numeric price, returns the volume traded at that price level.
*
* @public
* @param {number} price
* @returns {number}
*/
public getVolume(price: number): number;
/**
* Returns an array of all price levels. This is an expensive operation. Observing
* an ongoing subscription is preferred (see {@link Connection#on}).
*
* @return {PriceLevel[]}
*/
toArray(): PriceLevel[];
}
class Exchange {
/**
* @property {string} id - the code used to identify the exchange
*/
id: {
id: string;
};
/**
* @property {string} name - the name of the exchange
*/
name: {
name: string;
};
/**
* @property {string} timezone - the timezone of the exchange (should conform to TZ database name)
*/
timezone: {
timezone: string;
};
}
/**
* @typedef Book
* @type Object
* @property {string} symbol
* @property {Object[]} bids
* @property {Object[]} asks
*/
type Book = {
symbol: string;
bids: object[];
asks: object[];
};
class MarketState {
/**
* @public
* @param {string} symbol
* @param {function=} callback - invoked when the {@link Profile} instance becomes available
* @returns {Promise<Profile>} The {@link Profile} instance, as a promise.
*/
public getProfile(
symbol: string,
callback?: (...params: any[]) => any
): Promise<Profile>;
/**
* @public
* @param {string} symbol
* @returns {Quote}
*/
public getQuote(symbol: string): Quote;
/**
* @public
* @param {string} symbol
* @returns {Book}
*/
public getBook(symbol: string): Book;
/**
* @public
* @param {string} symbol
* @param {function=} callback - invoked when the {@link CumulativeVolume} instance becomes available
* @returns {Promise<CumulativeVolume>} The {@link CumulativeVolume} instance, as a promise
*/
public getCumulativeVolume(
symbol: string,
callback?: (...params: any[]) => any
): Promise<CumulativeVolume>;
/**
* Returns the time the most recent market data message was received.
*
* @public
* @returns {Date}
*/
public getTimestamp(): Date;
}
class Profile {
/**
* @property {string} symbol - the symbol of the instrument.
*/
symbol: {
symbol: string;
};
/**
* @property {string} name - the name of the instrument.
*/
name: {
name: string;
};
/**
* @property {string} exchange - code of the listing exchange.
*/
exchange: {
exchange: string;
};
/**
* @property {string} unitCode - code indicating how a prices for the instrument should be formatted.
*/
unitCode: {
unitCode: string;
};
/**
* @property {string} pointValue - the change in value for a one point change in price.
*/
pointValue: {
pointValue: string;
};
/**
* @property {number} tickIncrement - the minimum price movement.
*/
tickIncrement: {
tickIncrement: number;
};
/**
* @property {undefined|string} root - the root symbol, if a future; otherwise undefined.
*/
root: {
root: undefined | string;
};
/**
* @property {undefined|string} month - the month code, if a future; otherwise undefined.
*/
month: {
month: undefined | string;
};
/**
* @property {undefined|number} year - the expiration year, if a symbol; otherwise undefined.
*/
year: {
year: undefined | number;
};
/**
* Given a numeric price, returns a human-readable price.
*
* @public
* @param {number} price
* @returns {string}
*/
public formatPrice(price: number): string;
/**
* Configures the logic used to format all prices using the {@link Profile#formatPrice} instance function.
*
* @public
* @param {string} fractionSeparator - usually a dash or a period
* @param {boolean} specialFractions - usually true
* @param {string=} thousandsSeparator - usually a comma
*/
public static setPriceFormatter(
fractionSeparator: string,
specialFractions: boolean,
thousandsSeparator?: string
): void;
/**
* Alias for {@link Profile.setPriceFormatter} function.
*
* @deprecated
* @public
* @see {@link Profile.setPriceFormatter}
*/
public static PriceFormatter(): void;
}
class Quote {
constructor(symbol?: string);
/**
* @property {string} symbol - the symbol of the quoted instrument.
*/
symbol: {
symbol: string;
};
/**
* @property {string} message - last DDF message that caused a mutation to this instance.
*/
message: {
message: string;
};
/**
* @property {string} flag - market status, will have one of three values: p, s, or undefined.
*/
flag: {
flag: string;
};
/**
* @property {string} day - one character code that indicates day of the month of the current trading session.
*/
day: {
day: string;
};
/**
* @property {number} dayNum - day of the month of the current trading session.
*/
dayNum: {
dayNum: number;
};
/**
* @property {Date|null} lastUpdate - the most recent refresh. this date instance stores the hours and minutes for the exchange time (without proper timezone adjustment). use caution.
*/
lastUpdate: {
lastUpdate: Date | null;
};
/**
* @property {number} bidPrice - top-of-book price on the buy side.
*/
bidPrice: {
bidPrice: number;
};
/**
* @property {number} bidSize - top-of-book quantity on the buy side.
*/
bidSize: {
bidSize: number;
};
/**
* @property {number} askPrice - top-of-book price on the sell side.
*/
askPrice: {
askPrice: number;
};
/**
* @property {number} askSize - top-of-book quantity on the sell side.
*/
askSize: {
askSize: number;
};
/**
* @property {number} lastPrice - most recent price (not necessarily a trade).
*/
lastPrice: {
lastPrice: number;
};
/**
* @property {number} tradePrice - most recent trade price.
*/
tradePrice: {
tradePrice: number;
};
/**
* @property {number} tradeSize - most recent trade quantity.
*/
tradeSize: {
tradeSize: number;
};
/**
* @property {number} blockTrade - most recent block trade price.
*/
blockTrade: {
blockTrade: number;
};
/**
* @property {number} settlementPrice
*/
settlementPrice: {
settlementPrice: number;
};
/**
* @property {number} previousPrice - price from the previous session.
*/
previousPrice: {
previousPrice: number;
};
/**
* @property {Profile|null} profile - metadata regarding the quoted instrument.
*/
profile: {
profile: Profile | null;
};
/**
* @property {Date|null} time - the most recent trade, quote, or refresh. this date instance stores the hours and minutes for the exchange time (without proper timezone adjustment). use caution.
*/
time: {
time: Date | null;
};
}
class WebSocketAdapter { }
class WebSocketAdapterFactory {
/**
* Returns a new {@link WebSocketAdapter} instance.
*
* @public
* @param {String} host
* @returns {null}
*/
public build(host: string): null;
}
class WebSocketAdapterFactoryForBrowsers extends WebSocketAdapterFactory {
/**
* Returns a new {@link WebSocketAdapter} instance.
*
* @public
* @param {String} host
* @returns {null}
*/
public build(host: string): null;
}
class WebSocketAdapterFactoryForNode extends WebSocketAdapterFactory {
/**
* Returns a new {@link WebSocketAdapter} instance.
*
* @public
* @param {String} host
* @returns {null}
*/
public build(host: string): null;
}
/**
* Gets a list of names in the tz database (see https://en.wikipedia.org/wiki/Tz_database
* and https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
*
* @public
* @static
* @returns {Array<String>}
*/
function getTimezones(): String[];
/**
* Attempts to guess the local timezone.
*
* @public
* @static
* @returns {String|null}
*/
function guessTimezone(): string | null;
class SymbolParser {
/**
* Returns a simple instrument definition with the terms that can be
* gleaned from a symbol. If no specifics can be determined from the
* symbol, a null value is returned.
*
* @public
* @static
* @param {String} symbol
* @returns {Object|null}
*/
public static parseInstrumentType(symbol: string): any | null;
/**
* Translates a symbol into a form suitable for use with JERQ (i.e. the quote "producer").
*
* @public
* @static
* @param {String} symbol
* @return {String|null}
*/
public static getProducerSymbol(symbol: string): string | null;
/**
* Attempts to convert database format of futures options to pipeline format
* (e.g. ZLF320Q -> ZLF9|320C)
*
* @public
* @static
* @param {String} symbol
* @returns {String|null}
*/
public static getFuturesOptionPipelineFormat(symbol: string): string | null;
/**
* Returns true if the symbol is not an alias to another symbol; otherwise
* false.
*
* @public
* @static
* @param {String} symbol
* @returns {Boolean}
*/
public static getIsConcrete(symbol: string): boolean;
/**
* Returns true if the symbol is an alias for another symbol; false otherwise.
*
* @public
* @static
* @param {String} symbol
* @returns {Boolean}
*/
public static getIsReference(symbol: string): boolean;
/**
* Returns true if the symbol represents futures contract; false otherwise.
*
* @public
* @static
* @param {String} symbol
* @returns {Boolean}
*/
public static getIsFuture(symbol: string): boolean;
/**
* Returns true if the symbol represents futures spread; false otherwise.
*
* @public
* @public
* @param {String} symbol
* @returns {Boolean}
*/
public static getIsFutureSpread(symbol: string): boolean;
/**
* Returns true if the symbol represents an option on a futures contract; false
* otherwise.
*
* @public
* @static
* @param {String} symbol
* @returns {Boolean}
*/
public static getIsFutureOption(symbol: string): boolean;
/**
* Returns true if the symbol represents a foreign exchange currency pair;
* false otherwise.
*
* @public
* @static
* @param {String} symbol
* @returns {Boolean}
*/
public static getIsForex(symbol: string): boolean;
/**
* Returns true if the symbol represents an external index (e.g. Dow Jones
* Industrials); false otherwise.
*
* @public
* @static
* @param {String} symbol
* @returns {Boolean}
*/
public static getIsIndex(symbol: string): boolean;
/**
* Returns true if the symbol represents an internally-calculated sector
* index; false otherwise.
*
* @public
* @static
* @param {String} symbol
* @returns {Boolean}
*/
public static getIsSector(symbol: string): boolean;
/**
* Returns true if the symbol represents an internally-calculated, cmdty-branded
* index; false otherwise.
*
* @public
* @static
* @param {String} symbol
* @returns {Boolean}
*/
public static getIsCmdty(symbol: string): boolean;
/**
* Returns true if the symbol is listed on the BATS exchange; false otherwise.
*
* @public
* @static
* @param {String} symbol
* @returns {Boolean}
*/
public static getIsBats(symbol: string): boolean;
/**
* Returns true if the symbol has an expiration and the symbol appears
* to be expired (e.g. a future for a past year).
*
* @public
* @static
* @param {String} symbol
* @returns {Boolean}
*/
public static getIsExpired(symbol: string): boolean;
/**
* Returns true if prices for the symbol should be represented as a percentage; false
* otherwise.
*
* @public
* @static
* @param {String} symbol
* @returns {Boolean}
*/
public static displayUsingPercent(symbol: string): boolean;
}
/**
* Exchange metadata
*
* @typedef ExchangeMetadata
* @type {Object}
* @property {String} id
* @property {String} description
* @property {String} timezone
*/
type ExchangeMetadata = {
id: string;
description: string;
timezone: string;
};
}