INNER CODE UNIT · JavaScript

handleWarning

dearvn/tradovate-trading-bot · agents/frontend/index.js:133

  const handleWarning = (ws, message) => {
    ws.send(JSON.stringify({ result: false, type: 'notification', message: { type: 'warning', title: message } }));
  };

  wss.on('connection', ws => {
    ws.send(JSON.stringify({ result: true, type: 'connection_success', message: 'Connected.' }));

    ws.on('message', async rawMessage => {
      const clientIp = ws._socket.remoteAddress;
      const rateLimiterLogin = await loginLimiter.get(clientIp);

      if (config.get('authentication.enabled') && rateLimiterLogin && rateLimiterLogin.remainingPoints <= 0) {
        handleWarning(ws, `You are blocked until ${new Date(Date.now() + rateLimiterLogin.msBeforeNext)}.`);
        return;
      }

      let payload;
      try { payload = JSON.parse(rawMessage); } catch (e) { payload = null; }

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…