tardis-dev 13.15.1 → 13.17.0

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 (43) hide show
  1. package/dist/consts.d.ts +6 -5
  2. package/dist/consts.d.ts.map +1 -1
  3. package/dist/consts.js +16 -6
  4. package/dist/consts.js.map +1 -1
  5. package/dist/mappers/blockchaincom.d.ts +67 -0
  6. package/dist/mappers/blockchaincom.d.ts.map +1 -0
  7. package/dist/mappers/blockchaincom.js +63 -0
  8. package/dist/mappers/blockchaincom.js.map +1 -0
  9. package/dist/mappers/bybit.d.ts +1 -1
  10. package/dist/mappers/bybitspot.d.ts +1 -1
  11. package/dist/mappers/cryptocom.d.ts +1 -1
  12. package/dist/mappers/huobi.d.ts +3 -3
  13. package/dist/mappers/index.d.ts +2 -2
  14. package/dist/mappers/index.d.ts.map +1 -1
  15. package/dist/mappers/index.js +5 -2
  16. package/dist/mappers/index.js.map +1 -1
  17. package/dist/mappers/okex.d.ts +25 -1
  18. package/dist/mappers/okex.d.ts.map +1 -1
  19. package/dist/mappers/okex.js +44 -14
  20. package/dist/mappers/okex.js.map +1 -1
  21. package/dist/realtimefeeds/blockchaincom.d.ts +11 -0
  22. package/dist/realtimefeeds/blockchaincom.d.ts.map +1 -0
  23. package/dist/realtimefeeds/blockchaincom.js +44 -0
  24. package/dist/realtimefeeds/blockchaincom.js.map +1 -0
  25. package/dist/realtimefeeds/index.d.ts.map +1 -1
  26. package/dist/realtimefeeds/index.js +3 -1
  27. package/dist/realtimefeeds/index.js.map +1 -1
  28. package/dist/realtimefeeds/okex.d.ts.map +1 -1
  29. package/dist/realtimefeeds/okex.js +7 -0
  30. package/dist/realtimefeeds/okex.js.map +1 -1
  31. package/dist/realtimefeeds/realtimefeed.d.ts +1 -0
  32. package/dist/realtimefeeds/realtimefeed.d.ts.map +1 -1
  33. package/dist/realtimefeeds/realtimefeed.js +4 -0
  34. package/dist/realtimefeeds/realtimefeed.js.map +1 -1
  35. package/package.json +1 -1
  36. package/src/consts.ts +17 -6
  37. package/src/mappers/blockchaincom.ts +98 -0
  38. package/src/mappers/index.ts +5 -2
  39. package/src/mappers/okex.ts +60 -14
  40. package/src/realtimefeeds/blockchaincom.ts +44 -0
  41. package/src/realtimefeeds/index.ts +3 -1
  42. package/src/realtimefeeds/okex.ts +7 -0
  43. package/src/realtimefeeds/realtimefeed.ts +5 -0
@@ -28,6 +28,7 @@ import {
28
28
  } from './bitmex'
29
29
  import { BitnomialBookChangMapper, bitnomialTradesMapper } from './bitnomial'
30
30
  import { BitstampBookChangeMapper, bitstampTradesMapper } from './bitstamp'
31
+ import { BlockchainComBookChangeMapper, BlockchainComTradesMapper } from './blockchaincom'
31
32
  import { BybitBookChangeMapper, BybitDerivativeTickerMapper, BybitLiquidationsMapper, BybitTradesMapper } from './bybit'
32
33
  import { BybitSpotBookChangeMapper, BybitSpotBookTickerMapper, BybitSpotTradesMapper } from './bybitspot'
33
34
  import { CoinbaseBookChangMapper, coinbaseBookTickerMapper, coinbaseTradesMapper } from './coinbase'
@@ -193,7 +194,8 @@ const tradesMappers = {
193
194
  'crypto-com-derivatives': () => new CryptoComTradesMapper('crypto-com-derivatives'),
194
195
  kucoin: () => new KucoinTradesMapper('kucoin'),
195
196
  bitnomial: () => bitnomialTradesMapper,
196
- 'woo-x': () => wooxTradesMapper
197
+ 'woo-x': () => wooxTradesMapper,
198
+ 'blockchain-com': () => new BlockchainComTradesMapper()
197
199
  }
198
200
 
199
201
  const bookChangeMappers = {
@@ -268,7 +270,8 @@ const bookChangeMappers = {
268
270
  'crypto-com-derivatives': () => new CryptoComBookChangeMapper('crypto-com-derivatives'),
269
271
  kucoin: (localTimestamp: Date) => new KucoinBookChangeMapper('kucoin', isRealTime(localTimestamp) === false),
270
272
  bitnomial: () => new BitnomialBookChangMapper(),
271
- 'woo-x': () => new WooxBookChangeMapper()
273
+ 'woo-x': () => new WooxBookChangeMapper(),
274
+ 'blockchain-com': () => new BlockchainComBookChangeMapper()
272
275
  }
273
276
 
274
277
  const derivativeTickersMappers = {
@@ -97,6 +97,7 @@ export class OkexV5BookChangeMapper implements Mapper<OKEX_EXCHANGES, BookChange
97
97
  }
98
98
 
99
99
  *map(okexDepthDataMessage: OkexV5BookMessage, localTimestamp: Date): IterableIterator<BookChange> {
100
+ console.log(okexDepthDataMessage)
100
101
  for (const message of okexDepthDataMessage.data) {
101
102
  if (okexDepthDataMessage.action === 'update' && message.bids.length === 0 && message.asks.length === 0) {
102
103
  continue
@@ -344,13 +345,14 @@ export class OkexV5DerivativeTickerMapper implements Mapper<'okex-futures' | 'ok
344
345
  }
345
346
 
346
347
  export class OkexV5LiquidationsMapper implements Mapper<OKEX_EXCHANGES, Liquidation> {
348
+ private _isFirstMessage = true
347
349
  constructor(private readonly _exchange: Exchange) {}
348
350
 
349
351
  canHandle(message: any) {
350
352
  if (message.event !== undefined || message.arg === undefined) {
351
353
  return false
352
354
  }
353
- return message.arg.channel === 'liquidations'
355
+ return message.arg.channel === 'liquidations' || message.arg.channel === 'liquidation-orders'
354
356
  }
355
357
 
356
358
  getFilters(symbols?: string[]) {
@@ -360,24 +362,55 @@ export class OkexV5LiquidationsMapper implements Mapper<OKEX_EXCHANGES, Liquidat
360
362
  {
361
363
  channel: 'liquidations',
362
364
  symbols
365
+ } as any,
366
+ {
367
+ channel: 'liquidation-orders',
368
+ symbols
363
369
  } as any
364
370
  ]
365
371
  }
366
372
 
367
- *map(okexLiquidationMessage: OkexV5LiquidationMessage, localTimestamp: Date): IterableIterator<Liquidation> {
368
- for (const okexLiquidation of okexLiquidationMessage.data) {
369
- const liquidation: Liquidation = {
370
- type: 'liquidation',
371
- symbol: okexLiquidationMessage.arg.instId,
372
- exchange: this._exchange,
373
- id: undefined,
374
- price: Number(okexLiquidation.bkPx),
375
- amount: Number(okexLiquidation.sz),
376
- side: okexLiquidation.side === 'buy' ? 'buy' : 'sell',
377
- timestamp: new Date(Number(okexLiquidation.ts)),
378
- localTimestamp: localTimestamp
373
+ *map(
374
+ okexLiquidationMessage: OkexV5LiquidationMessage | OkexV5LiquidationOrderMessage,
375
+ localTimestamp: Date
376
+ ): IterableIterator<Liquidation> {
377
+ if (okexLiquidationMessage.arg.channel === 'liquidation-orders') {
378
+ if (this._isFirstMessage) {
379
+ this._isFirstMessage = false
380
+ return
381
+ }
382
+
383
+ for (const okexLiquidation of (okexLiquidationMessage as OkexV5LiquidationOrderMessage).data) {
384
+ for (const detail of okexLiquidation.details) {
385
+ const liquidation: Liquidation = {
386
+ type: 'liquidation',
387
+ symbol: okexLiquidation.instId,
388
+ exchange: this._exchange,
389
+ id: undefined,
390
+ price: Number(detail.bkPx),
391
+ amount: Number(detail.sz),
392
+ side: detail.side === 'buy' ? 'buy' : 'sell',
393
+ timestamp: new Date(Number(detail.ts)),
394
+ localTimestamp: localTimestamp
395
+ }
396
+ yield liquidation
397
+ }
398
+ }
399
+ } else {
400
+ for (const okexLiquidation of (okexLiquidationMessage as OkexV5LiquidationMessage).data) {
401
+ const liquidation: Liquidation = {
402
+ type: 'liquidation',
403
+ symbol: okexLiquidationMessage.arg.instId,
404
+ exchange: this._exchange,
405
+ id: undefined,
406
+ price: Number(okexLiquidation.bkPx),
407
+ amount: Number(okexLiquidation.sz),
408
+ side: okexLiquidation.side === 'buy' ? 'buy' : 'sell',
409
+ timestamp: new Date(Number(okexLiquidation.ts)),
410
+ localTimestamp: localTimestamp
411
+ }
412
+ yield liquidation
379
413
  }
380
- yield liquidation
381
414
  }
382
415
  }
383
416
  }
@@ -634,6 +667,19 @@ type OkexV5LiquidationMessage = {
634
667
  data: [{ bkLoss: '0'; bkPx: '49674.2'; ccy: ''; posSide: 'short'; side: 'buy'; sz: '40'; ts: '1640140211925' }]
635
668
  }
636
669
 
670
+ type OkexV5LiquidationOrderMessage = {
671
+ arg: { channel: 'liquidation-orders'; instType: 'FUTURES' }
672
+ data: [
673
+ {
674
+ details: [{ bkLoss: '0'; bkPx: '0.55205'; ccy: ''; posSide: 'short'; side: 'buy'; sz: '39'; ts: '1680173247614' }]
675
+ instFamily: 'XRP-USD'
676
+ instId: 'XRP-USD-230929'
677
+ instType: 'FUTURES'
678
+ uly: 'XRP-USD'
679
+ }
680
+ ]
681
+ }
682
+
637
683
  type OkexV5SummaryMessage = {
638
684
  arg: { channel: 'opt-summary'; uly: 'ETH-USD' }
639
685
  data: [
@@ -0,0 +1,44 @@
1
+ import { wait } from '../handy'
2
+ import { Filter } from '../types'
3
+ import { RealTimeFeedBase } from './realtimefeed'
4
+
5
+ export class BlockchainComRealTimeFeed extends RealTimeFeedBase {
6
+ protected readonly wssURL = 'wss://ws.blockchain.info/mercury-gateway/v1/ws'
7
+ protected readonly originHeader = 'https://exchange.blockchain.com'
8
+
9
+ protected mapToSubscribeMessages(filters: Filter<string>[]): any[] {
10
+ const subs = filters
11
+ .map((filter) => {
12
+ if (!filter.symbols || filter.symbols.length === 0) {
13
+ throw new Error('BlockchainComRealTimeFeed requires explicitly specified symbols when subscribing to live feed')
14
+ }
15
+
16
+ return filter.symbols.map((symbol) => {
17
+ return {
18
+ action: 'subscribe',
19
+ channel: filter.channel,
20
+ symbol
21
+ }
22
+ })
23
+ })
24
+ .flatMap((f) => f)
25
+
26
+ return subs
27
+ }
28
+
29
+ protected messageIsError(message: any): boolean {
30
+ return message.event === 'rejected'
31
+ }
32
+
33
+ protected messageIsHeartbeat(msg: any) {
34
+ return msg.channel === 'heartbeat'
35
+ }
36
+ protected async onConnected() {
37
+ this.send({
38
+ action: 'subscribe',
39
+ channel: 'heartbeat'
40
+ })
41
+
42
+ await wait(0)
43
+ }
44
+ }
@@ -46,6 +46,7 @@ import { CryptoComRealTimeFeed } from './cryptocom'
46
46
  import { KucoinRealTimeFeed } from './kucoin'
47
47
  import { BitnomialRealTimeFeed } from './bitnomial'
48
48
  import { WooxRealTimeFeed } from './woox'
49
+ import { BlockchainComRealTimeFeed } from './blockchaincom'
49
50
 
50
51
  export * from './realtimefeed'
51
52
 
@@ -100,7 +101,8 @@ const realTimeFeedsMap: {
100
101
  'crypto-com-derivatives': CryptoComRealTimeFeed,
101
102
  kucoin: KucoinRealTimeFeed,
102
103
  bitnomial: BitnomialRealTimeFeed,
103
- 'woo-x': WooxRealTimeFeed
104
+ 'woo-x': WooxRealTimeFeed,
105
+ 'blockchain-com': BlockchainComRealTimeFeed
104
106
  }
105
107
 
106
108
  export function getRealTimeFeedFactory(exchange: Exchange): RealTimeFeed {
@@ -36,12 +36,19 @@ export class OkexRealTimeFeed extends RealTimeFeedBase {
36
36
 
37
37
  protected mapToSubscribeMessages(filters: Filter<string>[]): any[] {
38
38
  const args = filters
39
+ .filter((f) => f.channel != 'liquidations')
39
40
  .map((filter) => {
40
41
  if (!filter.symbols || filter.symbols.length === 0) {
41
42
  throw new Error(`${this._exchange} RealTimeFeed requires explicitly specified symbols when subscribing to live feed`)
42
43
  }
43
44
 
44
45
  return filter.symbols.map((symbol) => {
46
+ if (filter.channel === 'liquidation-orders') {
47
+ return {
48
+ channel: filter.channel,
49
+ instType: symbol.endsWith('SWAP') ? 'SWAP' : 'FUTURES'
50
+ }
51
+ }
45
52
  return {
46
53
  channel: filter.channel,
47
54
  instId: symbol
@@ -33,6 +33,7 @@ export abstract class RealTimeFeedBase implements RealTimeFeedIterable {
33
33
  private _ws?: WebSocket
34
34
  private _connectionId = connectionCounter++
35
35
  private _wsClientOptions: WebSocket.ClientOptions | ClientRequestArgs
36
+ protected readonly originHeader: string | undefined = undefined
36
37
 
37
38
  constructor(
38
39
  protected readonly _exchange: string,
@@ -84,6 +85,10 @@ export abstract class RealTimeFeedBase implements RealTimeFeedIterable {
84
85
  subscribeMessages
85
86
  )
86
87
 
88
+ if (this.originHeader !== undefined) {
89
+ this._wsClientOptions.headers!.origin = this.originHeader
90
+ }
91
+
87
92
  this._ws = new WebSocket(finalWssUrl, this._wsClientOptions)
88
93
  this._ws.onopen = this._onConnectionEstabilished
89
94
  this._ws.onclose = this._onConnectionClosed