tardis-dev 13.31.2 → 13.32.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.
@@ -0,0 +1,60 @@
1
+ import crypto from 'crypto'
2
+ import { Filter } from '../types'
3
+ import { RealTimeFeedBase } from './realtimefeed'
4
+
5
+ export class CoinbaseInternationalRealTimeFeed extends RealTimeFeedBase {
6
+ private _hasCredentials =
7
+ process.env.COINBASE_INTERNATIONAL_API_KEY !== undefined &&
8
+ process.env.COINBASE_INTERNATIONAL_API_SECRET !== undefined &&
9
+ process.env.COINBASE_INTERNATIONAL_API_PASSPHRASE !== undefined
10
+
11
+ protected get wssURL() {
12
+ return 'wss://ws-md.international.coinbase.com'
13
+ }
14
+
15
+ protected mapToSubscribeMessages(filters: Filter<string>[]): any[] {
16
+ if (this._hasCredentials == false) {
17
+ throw new Error(
18
+ 'CoinbaseInternationalRealTimeFeed requires auth credentials env vars set(COINBASE_INTERNATIONAL_API_KEY, COINBASE_INTERNATIONAL_API_SECRET, COINBASE_INTERNATIONAL_API_PASSPHRASE)'
19
+ )
20
+ }
21
+
22
+ const authParams = this.getAuthParams()
23
+
24
+ return filters.map((filter) => {
25
+ if (!filter.symbols || filter.symbols.length === 0) {
26
+ throw new Error('CoinbaseInternationalRealTimeFeed requires explicitly specified symbols when subscribing to live feed')
27
+ }
28
+
29
+ return {
30
+ type: 'SUBSCRIBE',
31
+ product_ids: filter.symbols,
32
+ channels: [filter.channel],
33
+ signature: authParams.signature,
34
+ key: authParams.key,
35
+ time: authParams.time,
36
+ passphrase: authParams.passphrase
37
+ }
38
+ })
39
+ }
40
+
41
+ private getAuthParams() {
42
+ const time = Date.now().valueOf() / 1000
43
+ const apiSecret = process.env.COINBASE_INTERNATIONAL_API_SECRET!
44
+ const message = `${time}${process.env.COINBASE_INTERNATIONAL_API_KEY}CBINTLMD${process.env.COINBASE_INTERNATIONAL_API_PASSPHRASE}`
45
+
46
+ const hmac = crypto.createHmac('sha256', Buffer.from(apiSecret, 'base64'))
47
+ const signature = hmac.update(message).digest('base64')
48
+
49
+ return {
50
+ signature,
51
+ key: process.env.COINBASE_INTERNATIONAL_API_KEY!,
52
+ passphrase: process.env.COINBASE_INTERNATIONAL_API_PASSPHRASE!,
53
+ time
54
+ }
55
+ }
56
+
57
+ protected messageIsError(message: any): boolean {
58
+ return message.type === 'REJECT'
59
+ }
60
+ }
@@ -51,6 +51,7 @@ import { OkexSpreadsRealTimeFeed } from './okexspreads'
51
51
  import { KucoinFuturesRealTimeFeed } from './kucoinfutures'
52
52
  import { DydxV4RealTimeFeed } from './dydx_v4'
53
53
  import { BitgetFuturesRealTimeFeed, BitgetRealTimeFeed } from './bitget'
54
+ import { CoinbaseInternationalRealTimeFeed } from './coinbaseinternational'
54
55
 
55
56
  export * from './realtimefeed'
56
57
 
@@ -113,7 +114,8 @@ const realTimeFeedsMap: {
113
114
  'kucoin-futures': KucoinFuturesRealTimeFeed,
114
115
  'dydx-v4': DydxV4RealTimeFeed,
115
116
  bitget: BitgetRealTimeFeed,
116
- 'bitget-futures': BitgetFuturesRealTimeFeed
117
+ 'bitget-futures': BitgetFuturesRealTimeFeed,
118
+ 'coinbase-international': CoinbaseInternationalRealTimeFeed
117
119
  }
118
120
 
119
121
  export function getRealTimeFeedFactory(exchange: Exchange): RealTimeFeed {