ohlc's
This commit is contained in:
48
src/blockchain/ohlcs.js
Normal file
48
src/blockchain/ohlcs.js
Normal file
@@ -0,0 +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 subOHLCs( chainId, poolPeriods ) {
|
||||
if( !poolPeriods.length )
|
||||
return
|
||||
const toSub = []
|
||||
for( const [pool,period] of poolPeriods ) {
|
||||
const key = `${pool}|${period}`
|
||||
if (!(key in ohlcSubCounts) || ohlcSubCounts[key] === 0) {
|
||||
ohlcSubCounts[key] = 1
|
||||
toSub.push(key)
|
||||
} else {
|
||||
ohlcSubCounts[key]++
|
||||
}
|
||||
}
|
||||
if( toSub.length )
|
||||
socket.emit('subOHLCs', chainId, toSub)
|
||||
}
|
||||
|
||||
export function unsubPrices( chainId, poolPeriods ) {
|
||||
const toUnsub = []
|
||||
for( const [pool,period] of poolPeriods ) {
|
||||
const key = `${pool}|${period}`
|
||||
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 )
|
||||
toUnsub.push(key)
|
||||
}
|
||||
}
|
||||
if( toUnsub.length )
|
||||
socket.emit('unsubOHLCs', chainId, toUnsub )
|
||||
}
|
||||
|
||||
// todo get history
|
||||
|
||||
@@ -4,6 +4,7 @@ import {Exchange} from "@/blockchain/orderlib.js";
|
||||
import {uniswapV3PoolAddress} from "@/blockchain/uniswap.js";
|
||||
import {ethers, FixedNumber} from "ethers";
|
||||
import {uniswapV3PoolAbi} from "@/blockchain/abi.js";
|
||||
import {subOHLCs} from "@/blockchain/ohlcs.js";
|
||||
|
||||
const subscriptionCounts = {} // 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
|
||||
|
||||
Reference in New Issue
Block a user