chart subscription fixes

This commit is contained in:
Tim
2024-03-20 23:41:32 -04:00
parent 8e1c21cf35
commit 30b83ddaaa
2 changed files with 33 additions and 19 deletions

View File

@@ -7,8 +7,10 @@ export const WIDE_PRICE_FORMAT = {decimals:38, width:512, signed:false}; // 38 d
export function subOHLC( chainId, pool, period ) {
const key = `${pool}|${period}`
const ckey = `${chainId}|${key}`
if (!(key in ohlcSubCounts) || ohlcSubCounts[ckey] === 0) {
// console.log('subOHLC', chainId, pool, period, ckey, ohlcSubCounts[ckey])
if (!(ckey in ohlcSubCounts) || ohlcSubCounts[ckey] === 0) {
ohlcSubCounts[ckey] = 1
console.log('subscribing OHLCs', chainId, key)
socket.emit('subOHLCs', chainId, [key])
} else
ohlcSubCounts[ckey]++
@@ -18,14 +20,17 @@ export function subOHLC( chainId, pool, period ) {
export function unsubOHLC( chainId, pool, period ) {
const key = `${pool}|${period}`
const ckey = `${chainId}|${key}`
// console.log('unsubOHLC', chainId, pool, period, ckey, ohlcSubCounts[ckey])
if (!(ckey in ohlcSubCounts) || ohlcSubCounts[ckey] === 0) {
console.error('overdecremented ohlc', pool, period)
ohlcSubCounts[ckey] = 1
} else {
ohlcSubCounts[ckey]--
if (ohlcSubCounts[key] === 0)
if (ohlcSubCounts[ckey] === 0) {
console.log('unsubscribing OHLCs', chainId, key)
// noinspection JSCheckFunctionSignatures
socket.emit('unsubOHLCs', chainId, [key])
}
}
}