Skip to content

Commit dbf57b8

Browse files
Tucskyadeacetis
authored andcommitted
fix mexc spot listing fix bitfinex swapping pair id recover okex liquidations
1 parent e79c5ed commit dbf57b8

File tree

9 files changed

+197
-209
lines changed

9 files changed

+197
-209
lines changed

scripts/coinalize/utils.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,21 @@ const COINALIZE_REQ_KEY_PATH = 'products/coinalize.key'
2929
const BARS_PER_REQUEST = 300
3030

3131
const baseHeaders = {
32-
accept: '*/*',
33-
'accept-language': 'en-US,en;q=0.9,fr-FR;q=0.8,fr;q=0.7',
34-
'cache-control': 'no-cache',
35-
pragma: 'no-cache',
36-
'sec-ch-ua': '" Not;A Brand";v="99", "Google Chrome";v="97", "Chromium";v="97"',
37-
'sec-ch-ua-mobile': '?0',
38-
'sec-ch-ua-platform': '"Windows"',
39-
'sec-fetch-dest': 'empty',
40-
'sec-fetch-mode': 'cors',
41-
'sec-fetch-site': 'same-origin',
42-
cookie: 'p_sid=s%3ARY_H7HfwdvenT8Pz2XjPjBq-mHVLMsmL.ONSYPlNqShlYwQoVZ4Ez8igcJZ1r1wAG6pw7HQ%2FJ2WE',
43-
Referer: 'https://coinalyze.net/bitcoin/usd/binance/btcusd_perp/price-chart-live/',
44-
'Referrer-Policy': 'strict-origin-when-cross-origin',
32+
"accept": "*/*",
33+
"accept-language": "en-US,en;q=0.9",
34+
"cache-control": "no-cache",
35+
"content-type": "application/json",
36+
"pragma": "no-cache",
37+
"sec-ch-ua": "\"Not.A/Brand\";v=\"8\", \"Chromium\";v=\"114\", \"Google Chrome\";v=\"114\"",
38+
"sec-ch-ua-mobile": "?0",
39+
"sec-ch-ua-platform": "\"Windows\"",
40+
"sec-fetch-dest": "empty",
41+
"sec-fetch-mode": "cors",
42+
"sec-fetch-site": "same-origin",
43+
"x-requested-with": "XMLHttpRequest",
44+
"cookie": "cookies_accepted=1; p_sid=s%3A944WOtc4HxnJXvGuR5KtvuG1yIpHEYeT.r3vU6rPl3k4tjB4xGW472GoQPOjJi%2FbfMIyW0R1bRkM",
45+
"Referer": "https://coinalyze.net/bitcoin/usd/binance/btcusd_perp/price-chart-live/",
46+
"Referrer-Policy": "strict-origin-when-cross-origin"
4547
}
4648

4749
const baseJSONHeaders = {

src/config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,9 @@ if (process.argv.length > 2) {
234234
let userSettings = {}
235235

236236
let configPath =
237-
commandSettings?.config ||
238-
commandSettings?.configFile ||
239-
commandSettings?.configPath ||
237+
commandSettings.config ||
238+
commandSettings.configFile ||
239+
commandSettings.configPath ||
240240
'config.json'
241241

242242
try {

src/exchanges/binance.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ class Binance extends Exchange {
1111
this.subscriptions = {}
1212

1313
this.endpoints = {
14-
PRODUCTS: 'https://data.binance.com/api/v3/exchangeInfo'
14+
PRODUCTS: 'https://data-api.binance.vision/api/v3/exchangeInfo',
1515
}
1616

17-
this.url = () => `wss://data-stream.binance.com:9443/ws`
17+
this.url = () => `wss://data-stream.binance.vision:9443/ws`
1818
}
1919

2020
formatProducts(data) {
@@ -98,10 +98,12 @@ class Binance extends Exchange {
9898
const startTime = range.from
9999
const below1HEndTime = Math.min(range.to, startTime + 1000 * 60 * 60)
100100

101-
const endpoint = `https://data.binance.com/api/v3/aggTrades?symbol=${range.pair.toUpperCase()}&startTime=${
101+
const endpoint = `https://data-api.binance.vision/api/v3/aggTrades?symbol=${range.pair.toUpperCase()}&startTime=${
102102
startTime + 1
103103
}&endTime=${below1HEndTime}&limit=1000`
104104

105+
console.log(endpoint)
106+
105107
return axios
106108
.get(endpoint)
107109
.then(response => {

src/exchanges/bitfinex.js

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ class Bitfinex extends Exchange {
6363
}
6464

6565
if (api._connected.length === 0) {
66-
const chanId = Object.keys(this.channels).find(
67-
id => this.channels[id].name === 'status'
68-
)
66+
const chanId = Object.keys(this.channels[api.id]).find((chanId) => this.channels[api.id][chanId].name === 'status')
6967

7068
if (chanId) {
7169
api.send(
@@ -75,13 +73,12 @@ class Bitfinex extends Exchange {
7573
})
7674
)
7775

78-
delete this.channels[chanId]
76+
delete this.channels[api.id][chanId]
7977
}
8078
}
8179

82-
const channelsToUnsubscribe = Object.keys(this.channels).filter(
83-
id =>
84-
this.channels[id].pair === pair && this.channels[id].apiId === api.id
80+
const channelsToUnsubscribe = Object.keys(this.channels[api.id]).filter(
81+
(chanId) => this.channels[api.id][chanId].pair === pair
8582
)
8683

8784
if (!channelsToUnsubscribe.length) {
@@ -92,35 +89,36 @@ class Bitfinex extends Exchange {
9289
return
9390
}
9491

95-
for (let id of channelsToUnsubscribe) {
92+
for (let chanId of channelsToUnsubscribe) {
9693
api.send(
9794
JSON.stringify({
9895
event: 'unsubscribe',
99-
chanId: id
96+
chanId,
10097
})
10198
)
102-
delete this.channels[id]
99+
delete this.channels[api.id][chanId]
103100
}
104101
}
105102

106103
onMessage(event, api) {
107104
const json = JSON.parse(event.data)
108105

109106
if (json.event === 'subscribed' && json.chanId) {
110-
// console.debug(`[${this.id}] register channel ${json.chanId} (${json.channel}:${json.pair})`)
111-
this.channels[json.chanId] = {
107+
// console.debug(`[${this.id}.${api.id}] register channel ${json.chanId} (${json.channel}:${json.pair})`)
108+
this.channels[api.id][json.chanId] = {
112109
name: json.channel,
113-
pair: json.pair,
114-
apiId: api.id
110+
pair: json.pair
115111
}
116112
return
117113
}
118114

119-
if (!this.channels[json[0]] || json[1] === 'hb') {
115+
const chanId = json[0]
116+
117+
if (!this.channels[api.id][chanId] || json[1] === 'hb') {
120118
return
121119
}
122120

123-
const channel = this.channels[json[0]]
121+
const channel = this.channels[api.id][chanId]
124122

125123
if (!channel.hasSentInitialMessage) {
126124
// console.debug(`[${this.id}] skip first payload ${channel.name}:${channel.pair}`)
@@ -240,18 +238,12 @@ class Bitfinex extends Exchange {
240238
})
241239
}
242240

243-
onApiRemoved(api) {
244-
console.log(
245-
`[${this.id}] has ${Object.keys(this.channels).length} channels`
246-
)
247-
248-
const apiChannels = Object.keys(this.channels).filter(
249-
id => this.channels[id].apiId === api.id
250-
)
241+
onApiCreated(api) {
242+
this.channels[api.id] = {}
243+
}
251244

252-
for (const id of apiChannels) {
253-
delete this.channels[id]
254-
}
245+
onApiRemoved(api) {
246+
delete this.channels[api.id]
255247
}
256248
}
257249

src/exchanges/huobi.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ class Huobi extends Exchange {
183183
return {
184184
exchange: this.id,
185185
pair: pair,
186-
timestamp: +new Date(),
187-
price: this.prices[pair] || trade.price,
186+
timestamp: trade.created_at,
187+
price: +trade.price || this.prices[pair],
188188
size: +trade.amount,
189189
side: trade.direction,
190190
liquidation: true

src/exchanges/mexc.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ class Mexc extends Exchange {
1111

1212
this.endpoints = {
1313
PRODUCTS: [
14-
'https://api.mexc.com/api/v3/defaultSymbols',
15-
'https://contract.mexc.com/api/v1/contract/detail'
16-
]
14+
'https://api.mexc.com/api/v3/exchangeInfo',
15+
'https://contract.mexc.com/api/v1/contract/detail']
1716
}
1817

1918
this.url = pair => {
@@ -29,18 +28,19 @@ class Mexc extends Exchange {
2928
const products = []
3029
const contractSizes = {}
3130
const inversed = {}
31+
const [spot, perp] = responses
3232

33-
for (const response of responses) {
34-
const type = ['spot', 'contract'][responses.indexOf(response)]
35-
36-
for (const product of response.data) {
37-
if (type === 'contract') {
38-
products.push(product.symbol)
39-
contractSizes[product.symbol] = product.contractSize
40-
inversed[product.symbol] = product.quoteCoin === product.settleCoin
41-
} else {
42-
products.push(product)
43-
}
33+
if (spot) {
34+
for (const product of spot.symbols) {
35+
products.push(product.symbol)
36+
}
37+
}
38+
39+
if (perp) {
40+
for (const product of perp.data) {
41+
products.push(product.symbol)
42+
contractSizes[product.symbol] = product.contractSize
43+
inversed[product.symbol] = product.quoteCoin === product.settleCoin
4444
}
4545
}
4646

0 commit comments

Comments
 (0)