Skip to content

Commit 75d7e26

Browse files
committed
fix: fix ui anchor and use direct searchSymbols api
1 parent f7e8a72 commit 75d7e26

File tree

1 file changed

+26
-34
lines changed

1 file changed

+26
-34
lines changed

aggr.js

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -150,40 +150,33 @@ function resolveSymbol(market, forceOriginal = false) {
150150
}
151151

152152
if (!forceOriginal && AGGR_EXTENSION.ffs.normalizeMarkets) {
153-
query.exchange = 'BINANCE'
153+
query.exchange = 'CRYPTO'
154154
query.type = 'spot'
155-
query.local = query.local.replace(/^100+/, '')
155+
query.quote = 'USD'
156+
query.local = query.local.replace(/^100+/, '').replace(/USD$/, '')
156157
}
157158

158159
return new Promise((resolve) => {
159160
const type = query.type.replace('perp', 'swap')
160-
TradingViewApi._chartApiInstance.searchSymbols(
161-
query.local,
162-
query.exchange.replace(/_.*/, ''),
163-
'',
164-
'',
165-
'',
166-
'',
167-
'',
168-
'',
169-
'',
170-
(results) => {
171-
const match = results.find((a) => a.currency_code === query.quote && a.type === type)
172-
if (match) {
173-
const symbol = `${match.exchange}:${match.symbol}`
174-
AGGR_EXTENSION.resolvedSymbols[query.id] = symbol
175-
localStorage.setItem('aggr_symbols_cache', JSON.stringify(AGGR_EXTENSION.resolvedSymbols))
176-
177-
resolve(symbol)
161+
fetch(`https://symbol-search.tradingview.com/symbol_search/v3/?text=${query.local}&hl=1&exchange=${query.exchange}&lang=fr&search_type=crypto&domain=production&sort_by_country=US`)
162+
.then(res => res.json())
163+
.then(res => {
164+
const match = res.symbols.find((a) => a.currency_code === query.quote && a.type === type)
165+
if (match) {
166+
const symbol = `${match.exchange}:${match.symbol.replace(/<\/?[^>]+(>|$)/g, "")}`
167+
AGGR_EXTENSION.resolvedSymbols[query.id] = symbol
168+
localStorage.setItem('aggr_resolved_symbols', JSON.stringify(AGGR_EXTENSION.resolvedSymbols))
169+
170+
resolve(symbol)
171+
} else {
172+
if (!forceOriginal) {
173+
resolve(resolveSymbol(market, true))
178174
} else {
179-
if (!forceOriginal) {
180-
resolve(resolveSymbol(market, true))
181-
} else {
182-
resolve(null)
183-
}
175+
resolve(null)
184176
}
185177
}
186-
)
178+
})
179+
.catch(err => console.error('Error:', err));
187180
})
188181
}
189182

@@ -201,11 +194,11 @@ function setCrosshair(crosshair) {
201194
}
202195
const model = TradingViewApi._activeChartWidget()._model
203196
const index = model.model().timeScale().timePointToIndex(crosshair.timestamp)
204-
const currentPrice = +model.mainSeries().lastValueData().formattedPriceAbsolute
197+
const currentPrice = parseFloat(TradingViewApi._activeChartWidget()._model.mainSeries().lastValueData().formattedPriceAbsolute.replace(/\s/g, '').replace(/,/g, '.'))
205198
const price = currentPrice * (1 + crosshair.change)
206199
const crossHairSource = model.model().crossHairSource()
207200
crossHairSource.setPosition(index, price, model.model().mainPane())
208-
model.chartModel().lightUpdate()
201+
TradingViewApi._activeChartWidget()._model.model().lightUpdate()
209202
}
210203

211204
function listenForIncomingEvents() {
@@ -274,25 +267,24 @@ function isIframeReady() {
274267

275268
function listenToCrossHairChange() {
276269
const crossHairSource = TradingViewApi._activeChartWidget()._model.model().crossHairSource()
277-
crossHairSource.moved().subscribe(crossHairSource, ({ index, price }) => {
270+
crossHairSource.moved().subscribe(crossHairSource, (e) => {
278271
if (!isIframeReady()) {
279272
return
280273
}
281-
282-
const timestamp = TradingViewApi._activeChartWidget()._model.model().timeScale().indexToTimePoint(index)
283-
const currentPrice = +TradingViewApi._activeChartWidget()._model.mainSeries().lastValueData().formattedPriceAbsolute
274+
const timestamp = TradingViewApi._activeChartWidget()._model.model().timeScale().indexToTimePoint(e.index)
275+
const currentPrice = parseFloat(TradingViewApi._activeChartWidget()._model.mainSeries().lastValueData().formattedPriceAbsolute.replace(',', '.'))
284276

285277
postMessage('crosshair', {
286278
timestamp,
287-
change: (1 - price / currentPrice) * -1,
279+
change: (1 - e.price / currentPrice) * -1,
288280
})
289281
})
290282
}
291283

292284
// Initialization
293285
function initializeExtension() {
294286
const readyStateCheckInterval = setInterval(function (time) {
295-
const streamsButton = document.querySelector('[data-name="ideas_stream"]')
287+
const streamsButton = document.querySelector('[data-name="union_chats"]')
296288
if (streamsButton) {
297289
clearInterval(readyStateCheckInterval)
298290
createWidget()

0 commit comments

Comments
 (0)