45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
import {ohlcs, prices} from "./cache.js";
|
|
|
|
export function subPools( socket, chainId, addresses) {
|
|
for(const address of addresses) {
|
|
const room = `${chainId}|${address}`;
|
|
socket.join(room)
|
|
socket.emit('p', chainId, address, prices[address])
|
|
console.log('joined room', room)
|
|
}
|
|
}
|
|
|
|
export function unsubPools( socket, chainId, addresses ) {
|
|
for(const address of addresses) {
|
|
const room = `${chainId}|${address}`;
|
|
socket.leave(room)
|
|
console.log('left room', room)
|
|
}
|
|
}
|
|
|
|
|
|
export async function subOHLCs( socket, chainId, poolPeriods) {
|
|
console.log('subOHLCs', chainId, poolPeriods)
|
|
for(const key of poolPeriods) {
|
|
const room = `${chainId}|${key}`;
|
|
socket.join(room)
|
|
let ohlc = await ohlcs.get(chainId,key);
|
|
console.log('got ohlc', ohlc)
|
|
if (typeof(ohlc)==='string') {
|
|
ohlc = JSON.parse(ohlc)
|
|
}
|
|
socket.emit('ohlc', chainId, key, ohlc)
|
|
console.log('joined room', room)
|
|
}
|
|
}
|
|
|
|
export function unsubOHLCs( socket, chainId, poolPeriods ) {
|
|
console.log('unsubOHLCs', chainId, poolPeriods)
|
|
for(const key of poolPeriods) {
|
|
const room = `${chainId}|${key}`;
|
|
socket.leave(room)
|
|
console.log('left room', room)
|
|
}
|
|
}
|
|
|