Code Samples

This section provides working code examples for connecting to the Hyper LiveScore Feed.


Node.js Example

const amqp = require('amqplib');

const config = {
  hostname: 'hyper-livescore.lsports.eu',
  port: 5671,
  username: 'YOUR_USERNAME',
  password: 'YOUR_PASSWORD',
  protocol: 'amqps'
};

const packageId = 'YOUR_PACKAGE_ID';
const queueName = `_${packageId}_`;

// Store for fixtures
const fixturesStore = new Map();

async function connectFixtures() {
  const conn = await amqp.connect({ ...config, vhost: 'Fixtures' });
  const channel = await conn.createChannel();
  
  await channel.prefetch(100);
  
  channel.consume(queueName, (msg) => {
    if (msg) {
      const message = JSON.parse(msg.content.toString());
      const fixture = message.body;
      
      // Store fixture by fixtureId
      fixturesStore.set(fixture.fixtureId, fixture);
      
      console.log(`Fixture update: ${fixture.fixtureId} - ${fixture.participants?.map(p => p.name).join(' vs ')}`);
      
      channel.ack(msg);
    }
  });
  
  console.log('Connected to Fixtures feed');
}

async function connectIncidents() {
  const conn = await amqp.connect({ ...config, vhost: 'Incidents' });
  const channel = await conn.createChannel();
  
  await channel.prefetch(100);
  
  channel.consume(queueName, (msg) => {
    if (msg) {
      const message = JSON.parse(msg.content.toString());
      const incident = message.body;
      
      // Get fixture context
      const fixture = fixturesStore.get(incident.fixtureId);
      
      console.log(`Incident: ${incident.name} (${incident.kind}) - Fixture: ${fixture?.participants?.map(p => p.name).join(' vs ') || incident.fixtureId}`);
      console.log(`  Confidence: ${(incident.confidence * 100).toFixed(0)}%`);
      
      if (incident.values) {
        console.log(`  Score: ${incident.values.map(v => v.value).join(' - ')}`);
      }
      
      channel.ack(msg);
    }
  });
  
  console.log('Connected to Incidents feed');
}

async function main() {
  try {
    await connectFixtures();
    await connectIncidents();
  } catch (error) {
    console.error('Connection error:', error);
    process.exit(1);
  }
}

main();

Python Example


C# Example


Best Practices

  1. Always store fixtures first — Incidents reference fixtures by fixtureId

  2. Handle reconnection — Implement automatic recovery for dropped connections

  3. Process asynchronously — Don't block the message consumption loop

  4. Monitor confidence scores — Use the confidence field to filter uncertain incidents

  5. Log message IDs — Track MessageId for debugging and deduplication


Last updated

Was this helpful?