pool fee selection; ohlc subs
This commit is contained in:
@@ -1,14 +1,48 @@
|
||||
import {socket} from "@/socket.js";
|
||||
import {useStore} from "@/store/store.js";
|
||||
import {Exchange} from "@/blockchain/orderlib.js";
|
||||
import {uniswapV3PoolAddress} from "@/blockchain/uniswap.js";
|
||||
import {ethers, FixedNumber} from "ethers";
|
||||
import {uniswapV3PoolAbi} from "@/blockchain/abi.js";
|
||||
|
||||
const ohlcSubCounts = {} // key is route and value is a subscription counter
|
||||
export const WIDE_PRICE_FORMAT = {decimals:38, width:512, signed:false}; // 38 decimals is 127 bits
|
||||
|
||||
|
||||
export function subOHLC( chainId, pool, period ) {
|
||||
const key = `${pool}|${period}`
|
||||
const ckey = `${chainId}|${key}`
|
||||
if (!(key in ohlcSubCounts) || ohlcSubCounts[ckey] === 0) {
|
||||
ohlcSubCounts[ckey] = 1
|
||||
socket.emit('subOHLCs', chainId, [key])
|
||||
} else
|
||||
ohlcSubCounts[ckey]++
|
||||
}
|
||||
|
||||
|
||||
export function unsubOHLC( chainId, pool, period ) {
|
||||
for( const [pool,period] of poolPeriods ) {
|
||||
const key = `${pool}|${period}`
|
||||
const ckey = `${chainId}|${key}`
|
||||
if (!(ckey in ohlcSubCounts) || ohlcSubCounts[ckey] === 0) {
|
||||
console.error('overdecremented ohlc', pool, period)
|
||||
ohlcSubCounts[ckey] = 1
|
||||
} else {
|
||||
ohlcSubCounts[ckey]--
|
||||
if (ohlcSubCounts[key] === 0)
|
||||
socket.emit('unsubOHLCs', chainId, [key])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function unsubAllOHLCs( chainId ) {
|
||||
const chainStr = chainId.toString() + '|'
|
||||
const toUnsub = []
|
||||
for( const k of Object.keys(ohlcSubCounts) ) {
|
||||
if (k.startsWith(chainStr))
|
||||
toUnsub.push(k.slice(chainStr.length))
|
||||
}
|
||||
if( toUnsub.length )
|
||||
socket.emit('unsubOHLCs', chainId, toUnsub )
|
||||
}
|
||||
|
||||
|
||||
export function subOHLCs( chainId, poolPeriods ) {
|
||||
if( !poolPeriods.length )
|
||||
return
|
||||
@@ -18,9 +52,8 @@ export function subOHLCs( chainId, poolPeriods ) {
|
||||
if (!(key in ohlcSubCounts) || ohlcSubCounts[key] === 0) {
|
||||
ohlcSubCounts[key] = 1
|
||||
toSub.push(key)
|
||||
} else {
|
||||
} else
|
||||
ohlcSubCounts[key]++
|
||||
}
|
||||
}
|
||||
if( toSub.length )
|
||||
socket.emit('subOHLCs', chainId, toSub)
|
||||
@@ -33,16 +66,12 @@ export function unsubOHLCs( chainId, poolPeriods ) {
|
||||
if (!(key in ohlcSubCounts) || ohlcSubCounts[key] === 0) {
|
||||
console.error('overdecremented',pool,period)
|
||||
ohlcSubCounts[key] = 1
|
||||
toSub.push(key)
|
||||
} else {
|
||||
ohlcSubCounts[key]--
|
||||
if( ohlcSubCounts[key] == 0 )
|
||||
if( ohlcSubCounts[key] === 0 )
|
||||
toUnsub.push(key)
|
||||
}
|
||||
}
|
||||
if( toUnsub.length )
|
||||
socket.emit('unsubOHLCs', chainId, toUnsub )
|
||||
}
|
||||
|
||||
// todo get history
|
||||
|
||||
|
||||
Reference in New Issue
Block a user