tardis-dev 14.2.0 → 14.2.2

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 (51) hide show
  1. package/dist/binarysplit.d.ts.map +1 -1
  2. package/dist/binarysplit.js +19 -16
  3. package/dist/binarysplit.js.map +1 -1
  4. package/dist/consts.d.ts +10 -12
  5. package/dist/consts.d.ts.map +1 -1
  6. package/dist/consts.js +30 -16
  7. package/dist/consts.js.map +1 -1
  8. package/dist/exchangedetails.d.ts +56 -16
  9. package/dist/exchangedetails.d.ts.map +1 -1
  10. package/dist/instrumentinfo.d.ts +29 -1
  11. package/dist/instrumentinfo.d.ts.map +1 -1
  12. package/dist/mappers/bybit.d.ts +2 -2
  13. package/dist/mappers/bybitspot.d.ts +1 -1
  14. package/dist/mappers/cryptocom.d.ts +5 -5
  15. package/dist/mappers/cryptocom.d.ts.map +1 -1
  16. package/dist/mappers/huobi.d.ts +3 -3
  17. package/dist/mappers/index.d.ts +0 -8
  18. package/dist/mappers/index.d.ts.map +1 -1
  19. package/dist/mappers/index.js +0 -8
  20. package/dist/mappers/index.js.map +1 -1
  21. package/dist/realtimefeeds/binance.d.ts +14 -1
  22. package/dist/realtimefeeds/binance.d.ts.map +1 -1
  23. package/dist/realtimefeeds/binance.js +150 -34
  24. package/dist/realtimefeeds/binance.js.map +1 -1
  25. package/dist/realtimefeeds/index.d.ts.map +1 -1
  26. package/dist/realtimefeeds/index.js +0 -3
  27. package/dist/realtimefeeds/index.js.map +1 -1
  28. package/dist/realtimefeeds/realtimefeed.d.ts +1 -0
  29. package/dist/realtimefeeds/realtimefeed.d.ts.map +1 -1
  30. package/dist/realtimefeeds/realtimefeed.js +9 -3
  31. package/dist/realtimefeeds/realtimefeed.js.map +1 -1
  32. package/package.json +3 -3
  33. package/src/binarysplit.ts +25 -16
  34. package/src/consts.ts +30 -18
  35. package/src/exchangedetails.ts +70 -14
  36. package/src/instrumentinfo.ts +29 -1
  37. package/src/mappers/cryptocom.ts +4 -4
  38. package/src/mappers/index.ts +0 -8
  39. package/src/realtimefeeds/binance.ts +226 -43
  40. package/src/realtimefeeds/index.ts +0 -3
  41. package/src/realtimefeeds/realtimefeed.ts +12 -4
  42. package/dist/mappers/binanceoptions.d.ts +0 -92
  43. package/dist/mappers/binanceoptions.d.ts.map +0 -1
  44. package/dist/mappers/binanceoptions.js +0 -177
  45. package/dist/mappers/binanceoptions.js.map +0 -1
  46. package/dist/realtimefeeds/binanceoptions.d.ts +0 -9
  47. package/dist/realtimefeeds/binanceoptions.d.ts.map +0 -1
  48. package/dist/realtimefeeds/binanceoptions.js +0 -34
  49. package/dist/realtimefeeds/binanceoptions.js.map +0 -1
  50. package/src/mappers/binanceoptions.ts +0 -265
  51. package/src/realtimefeeds/binanceoptions.ts +0 -37
@@ -1 +0,0 @@
1
- {"version":3,"file":"binanceoptions.d.ts","sourceRoot":"","sources":["../../src/realtimefeeds/binanceoptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAEjD,qBAAa,0BAA2B,SAAQ,gBAAgB;IAC9D,SAAS,CAAC,MAAM,SAAqC;IACrD,SAAS,CAAC,OAAO,SAAqC;IAEtD,SAAS,CAAC,sBAAsB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,GAAG,EAAE;IAsBlE,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO;CAOhD"}
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BinanceOptionsRealTimeFeed = void 0;
4
- const realtimefeed_1 = require("./realtimefeed");
5
- class BinanceOptionsRealTimeFeed extends realtimefeed_1.RealTimeFeedBase {
6
- wssURL = 'wss://vstream.binance.com/stream';
7
- httpURL = 'https://vapi.binance.com/vapi/v1';
8
- mapToSubscribeMessages(filters) {
9
- const payload = filters.map((filter, index) => {
10
- if (!filter.symbols || filter.symbols.length === 0) {
11
- throw new Error('BinanceOptionsRealTimeFeed requires explicitly specified symbols when subscribing to live feed');
12
- }
13
- return {
14
- method: 'SUBSCRIBE',
15
- params: filter.symbols.map((symbol) => `${symbol}@${filter.channel}`),
16
- id: index + 1
17
- };
18
- });
19
- const noBinary = {
20
- method: 'BINARY',
21
- params: ['false'],
22
- id: 0
23
- };
24
- return [noBinary, ...payload];
25
- }
26
- messageIsError(message) {
27
- if (message.data !== undefined && message.data.e === 'error') {
28
- return true;
29
- }
30
- return false;
31
- }
32
- }
33
- exports.BinanceOptionsRealTimeFeed = BinanceOptionsRealTimeFeed;
34
- //# sourceMappingURL=binanceoptions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"binanceoptions.js","sourceRoot":"","sources":["../../src/realtimefeeds/binanceoptions.ts"],"names":[],"mappings":";;;AACA,iDAAiD;AAEjD,MAAa,0BAA2B,SAAQ,+BAAgB;IACpD,MAAM,GAAG,kCAAkC,CAAA;IAC3C,OAAO,GAAG,kCAAkC,CAAA;IAE5C,sBAAsB,CAAC,OAAyB;QACxD,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;YAC5C,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACnD,MAAM,IAAI,KAAK,CAAC,gGAAgG,CAAC,CAAA;YACnH,CAAC;YAED,OAAO;gBACL,MAAM,EAAE,WAAW;gBACnB,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;gBACrE,EAAE,EAAE,KAAK,GAAG,CAAC;aACd,CAAA;QACH,CAAC,CAAC,CAAA;QAEF,MAAM,QAAQ,GAAG;YACf,MAAM,EAAE,QAAQ;YAChB,MAAM,EAAE,CAAC,OAAO,CAAC;YACjB,EAAE,EAAE,CAAC;SACN,CAAA;QAED,OAAO,CAAC,QAAQ,EAAE,GAAG,OAAO,CAAC,CAAA;IAC/B,CAAC;IAES,cAAc,CAAC,OAAY;QACnC,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC;YAC7D,OAAO,IAAI,CAAA;QACb,CAAC;QAED,OAAO,KAAK,CAAA;IACd,CAAC;CACF;AAjCD,gEAiCC"}
@@ -1,265 +0,0 @@
1
- import { asNumberIfValid, upperCaseSymbols } from '../handy'
2
- import { BookChange, OptionSummary, Trade } from '../types'
3
- import { Mapper } from './mapper'
4
-
5
- // https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md
6
-
7
- export class BinanceOptionsTradesMapper implements Mapper<'binance-options', Trade> {
8
- private readonly _lastTradeId = new Map<string, number>()
9
- canHandle(message: BinanceResponse<any>) {
10
- if (message.stream === undefined) {
11
- return false
12
- }
13
-
14
- return message.stream.endsWith('@TRADE')
15
- }
16
-
17
- getFilters(symbols?: string[]) {
18
- symbols = upperCaseSymbols(symbols)
19
-
20
- return [
21
- {
22
- channel: 'TRADE',
23
- symbols
24
- } as const
25
- ]
26
- }
27
-
28
- *map(binanceTradeResponse: BinanceResponse<BinanceOptionsTradeData>, localTimestamp: Date) {
29
- const symbol = binanceTradeResponse.data.s
30
- for (const optionsTrade of binanceTradeResponse.data.t) {
31
- // binance options does not only return real-time trade as it happens but just snapshot of last 'x' trades always
32
- // so we need to decide which are real-time trades and which are stale/already processed
33
-
34
- const timestamp = new Date(optionsTrade.T)
35
- const tradeIdNumeric = Number(optionsTrade.t)
36
-
37
- const lastProcessedTradeId = this._lastTradeId.get(symbol)
38
- const isAlreadyProcessed = lastProcessedTradeId !== undefined && lastProcessedTradeId >= tradeIdNumeric
39
- const isStaleTrade = localTimestamp.valueOf() - timestamp.valueOf() > 10000
40
-
41
- if (isAlreadyProcessed || isStaleTrade) {
42
- continue
43
- }
44
-
45
- this._lastTradeId.set(symbol, Number(optionsTrade.t))
46
- const trade: Trade = {
47
- type: 'trade',
48
- symbol,
49
- exchange: 'binance-options',
50
- id: optionsTrade.t,
51
- price: Number(optionsTrade.p),
52
- amount: Number(optionsTrade.q),
53
- side: optionsTrade.s === '-1' ? 'sell' : 'buy',
54
- timestamp,
55
- localTimestamp: localTimestamp
56
- }
57
-
58
- yield trade
59
- }
60
- }
61
- }
62
-
63
- export class BinanceOptionsBookChangeMapper implements Mapper<'binance-options', BookChange> {
64
- canHandle(message: BinanceResponse<any>) {
65
- if (message.stream === undefined) {
66
- return false
67
- }
68
-
69
- return message.stream.endsWith('@DEPTH100')
70
- }
71
-
72
- getFilters(symbols?: string[]) {
73
- symbols = upperCaseSymbols(symbols)
74
-
75
- return [
76
- {
77
- channel: 'DEPTH100',
78
- symbols
79
- } as const
80
- ]
81
- }
82
-
83
- *map(message: BinanceResponse<BinanceOptionsDepthData>, localTimestamp: Date) {
84
- const bookChange: BookChange = {
85
- type: 'book_change',
86
- symbol: message.data.s,
87
- exchange: 'binance-options',
88
- isSnapshot: true,
89
- bids: message.data.b.map(this.mapBookLevel),
90
- asks: message.data.a.map(this.mapBookLevel),
91
- timestamp: new Date(message.data.E),
92
- localTimestamp
93
- }
94
-
95
- yield bookChange
96
- }
97
-
98
- protected mapBookLevel(level: BinanceBookLevel) {
99
- const price = Number(level[0])
100
- const amount = Number(level[1])
101
- return { price, amount }
102
- }
103
- }
104
-
105
- export class BinanceOptionSummaryMapper implements Mapper<'binance-options', OptionSummary> {
106
- private readonly _indexPrices = new Map<string, number>()
107
- canHandle(message: BinanceResponse<any>) {
108
- if (message.stream === undefined) {
109
- return false
110
- }
111
-
112
- return message.stream.endsWith('@TICKER') || message.stream.endsWith('@INDEX')
113
- }
114
-
115
- getFilters(symbols?: string[]) {
116
- symbols = upperCaseSymbols(symbols)
117
-
118
- const indexes =
119
- symbols !== undefined
120
- ? symbols.map((s) => {
121
- const symbolParts = s.split('-')
122
- return `${symbolParts[0]}USDT`
123
- })
124
- : undefined
125
-
126
- return [
127
- {
128
- channel: 'TICKER',
129
- symbols
130
- } as const,
131
- {
132
- channel: 'INDEX',
133
- symbols: indexes
134
- } as const
135
- ]
136
- }
137
-
138
- *map(message: BinanceResponse<BinanceOptionsTickerData | BinanceOptionsIndexData>, localTimestamp: Date) {
139
- if (message.stream.endsWith('@INDEX')) {
140
- const lastIndexPrice = Number(message.data.p)
141
- if (lastIndexPrice > 0) {
142
- this._indexPrices.set(message.data.s, lastIndexPrice)
143
- }
144
- return
145
- }
146
-
147
- const optionInfo = message.data as BinanceOptionsTickerData
148
-
149
- const [base, expiryPart, strikePrice, optionType] = optionInfo.s.split('-')
150
-
151
- const expirationDate = new Date(`20${expiryPart.slice(0, 2)}-${expiryPart.slice(2, 4)}-${expiryPart.slice(4, 6)}Z`)
152
- expirationDate.setUTCHours(8)
153
-
154
- const isPut = optionType === 'P'
155
-
156
- const underlyingIndex = `${base}USDT`
157
-
158
- let bestBidPrice = asNumberIfValid(optionInfo.bo)
159
- if (bestBidPrice === 0) {
160
- bestBidPrice = undefined
161
- }
162
-
163
- let bestAskPrice = asNumberIfValid(optionInfo.ao)
164
- if (bestAskPrice === 0) {
165
- bestAskPrice = undefined
166
- }
167
-
168
- let bestBidIV = bestBidPrice !== undefined ? asNumberIfValid(optionInfo.b) : undefined
169
- if (bestBidIV === -1) {
170
- bestBidIV = undefined
171
- }
172
-
173
- let bestAskIV = bestAskPrice !== undefined ? asNumberIfValid(optionInfo.a) : undefined
174
- if (bestAskIV === -1) {
175
- bestAskIV = undefined
176
- }
177
-
178
- const optionSummary: OptionSummary = {
179
- type: 'option_summary',
180
- symbol: optionInfo.s,
181
- exchange: 'binance-options',
182
- optionType: isPut ? 'put' : 'call',
183
- strikePrice: Number(strikePrice),
184
- expirationDate,
185
-
186
- bestBidPrice,
187
- bestBidAmount: undefined,
188
- bestBidIV,
189
-
190
- bestAskPrice,
191
- bestAskAmount: undefined,
192
- bestAskIV,
193
-
194
- lastPrice: asNumberIfValid(optionInfo.c),
195
- openInterest: undefined,
196
-
197
- markPrice: asNumberIfValid(optionInfo.mp),
198
- markIV: undefined,
199
-
200
- delta: asNumberIfValid(optionInfo.d),
201
- gamma: asNumberIfValid(optionInfo.g),
202
- vega: asNumberIfValid(optionInfo.v),
203
- theta: asNumberIfValid(optionInfo.t),
204
- rho: undefined,
205
-
206
- underlyingPrice: this._indexPrices.get(underlyingIndex),
207
- underlyingIndex,
208
-
209
- timestamp: new Date(optionInfo.E),
210
- localTimestamp: localTimestamp
211
- }
212
-
213
- yield optionSummary
214
- }
215
- }
216
-
217
- type BinanceResponse<T> = {
218
- stream: string
219
- data: T
220
- }
221
-
222
- type BinanceOptionsTradeData = {
223
- e: 'trade'
224
- E: number
225
- s: string
226
- t: { t: string; p: string; q: string; T: number; s: '-1' | '1' }[]
227
- }
228
-
229
- type BinanceOptionsDepthData = {
230
- e: 'depth'
231
- E: number
232
- s: string
233
- b: BinanceBookLevel[]
234
- a: BinanceBookLevel[]
235
- }
236
-
237
- type BinanceOptionsTickerData = {
238
- e: 'ticker' // event type
239
- E: 1591677962357 // event time
240
- s: 'BTC-200630-9000-P' // Option trading pair
241
- o: '1000' // 24-hour opening price
242
- h: '1000' // Highest price
243
- l: '1000' // Lowest price
244
- c: '1000' // latest price
245
- V: '2' // Trading volume
246
- A: '0' // trade amount
247
- p: '0' // price change
248
- Q: '2000' // volume of last completed trade
249
- F: 1 // first trade ID
250
- L: 1 // last trade ID
251
- n: 1 // number of trades
252
- b: '0' // BuyImplied volatility
253
- a: '0' // SellImplied volatility
254
- d: '0' // delta
255
- t: '0' // theta
256
- g: '0' // gamma
257
- v: '0' // vega,
258
- bo: '3.1' // best bid price
259
- ao: '90.36' // best ask price
260
- mp: '6.96' // mark price
261
- }
262
-
263
- type BinanceOptionsIndexData = { e: 'index'; E: 1614556800182; s: 'BTCUSDT'; p: '45160.127864' }
264
-
265
- type BinanceBookLevel = [string, string]
@@ -1,37 +0,0 @@
1
- import { Filter } from '../types'
2
- import { RealTimeFeedBase } from './realtimefeed'
3
-
4
- export class BinanceOptionsRealTimeFeed extends RealTimeFeedBase {
5
- protected wssURL = 'wss://vstream.binance.com/stream'
6
- protected httpURL = 'https://vapi.binance.com/vapi/v1'
7
-
8
- protected mapToSubscribeMessages(filters: Filter<string>[]): any[] {
9
- const payload = filters.map((filter, index) => {
10
- if (!filter.symbols || filter.symbols.length === 0) {
11
- throw new Error('BinanceOptionsRealTimeFeed requires explicitly specified symbols when subscribing to live feed')
12
- }
13
-
14
- return {
15
- method: 'SUBSCRIBE',
16
- params: filter.symbols.map((symbol) => `${symbol}@${filter.channel}`),
17
- id: index + 1
18
- }
19
- })
20
-
21
- const noBinary = {
22
- method: 'BINARY',
23
- params: ['false'],
24
- id: 0
25
- }
26
-
27
- return [noBinary, ...payload]
28
- }
29
-
30
- protected messageIsError(message: any): boolean {
31
- if (message.data !== undefined && message.data.e === 'error') {
32
- return true
33
- }
34
-
35
- return false
36
- }
37
- }