improved dlob ws rotation (#291)
* remove grpc impl, use sdk grpc OrderSubscriber * add log if both USE_WEBSOCKET and USE_GRPC are provided * Nour/improved rotation (#290) * improved rotation * fix bugs * only parse slot if necessary * add metrics for ws source * add select by recent slot to utils * fix solana web3.js version --------- Co-authored-by: wphan <william@drift.trade> --------- Co-authored-by: wphan <william@drift.trade>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import WebSocket from 'ws';
|
||||
const ws = new WebSocket('wss://dlob.drift.trade/ws');
|
||||
// const ws = new WebSocket('wss://dlob.drift.trade/ws');
|
||||
const ws = new WebSocket('http://localhost:3000/ws');
|
||||
import { sleep } from '../src/utils/utils';
|
||||
|
||||
ws.on('open', async () => {
|
||||
@@ -12,22 +13,26 @@ ws.on('open', async () => {
|
||||
ws.send(JSON.stringify({ type: 'subscribe', marketType: 'spot', channel: 'orderbook', market: 'SOL' }));
|
||||
await sleep(5000);
|
||||
|
||||
ws.send(JSON.stringify({ type: 'unsubscribe', marketType: 'perp', channel: 'orderbook', market: 'SOL-PERP' }));
|
||||
// ws.send(JSON.stringify({ type: 'unsubscribe', marketType: 'perp', channel: 'orderbook', market: 'SOL-PERP' }));
|
||||
console.log("####################");
|
||||
|
||||
|
||||
// Subscribe to trades data
|
||||
ws.send(JSON.stringify({ type: 'subscribe', marketType: 'perp', channel: 'trades', market: 'SOL-PERP' }));
|
||||
ws.send(JSON.stringify({ type: 'subscribe', marketType: 'spot', channel: 'trades', market: 'SOL' }));
|
||||
ws.send(JSON.stringify({ type: 'subscribe', marketType: 'spot', channel: 'trades', market: 'SOL' }));
|
||||
await sleep(5000);
|
||||
|
||||
ws.send(JSON.stringify({ type: 'unsubscribe', marketType: 'perp', channel: 'trades', market: 'SOL-PERP' }));
|
||||
// ws.send(JSON.stringify({ type: 'unsubscribe', marketType: 'perp', channel: 'trades', market: 'SOL-PERP' }));
|
||||
console.log("####################");
|
||||
});
|
||||
|
||||
ws.on('message', (data: WebSocket.Data) => {
|
||||
try {
|
||||
const message = JSON.parse(data.toString());
|
||||
if (!message.channel) {
|
||||
console.log(`Received data: ${JSON.stringify(message)}`);
|
||||
return;
|
||||
}
|
||||
console.log(`Received data from channel: ${JSON.stringify(message.channel)}`);
|
||||
// book and trades data is in message.data
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user