ticket-odd-service
v1.4.0
Published
Real-time sports odds tracking service
Downloads
20
Maintainers
Readme
Ticket Odds Service
A service library for interacting with ODD_STREAM to manage ticket odds in real-time.
Requirements
- Node.js 10+
- TypeScript 4.5.5
Installation
npm install ticket-odd-serviceClasses
There are only 2 classes that you need to be aware of:
TicketOddService: The main service class to interact with ODD_STREAMTicketOdd: The data structure represents a message on the stream
Initialization
import {TicketOddService} from "ticket-odd-service";
const ticketService = new TicketOddService();
// After logged-in successfully, set ConfigFeed
ticketService.setConfig({
streamFinderUrl: "/api",
streamName: "ODD_STREAM",
feedScope: "fscope",
userName: username
});Lifecycle
Connect
await ticketService.connectOnce();Register TicketOddRequest
// Register a ticket to receive odds updates
const ticketRequest = {
matchId: "match123",
eventId: "event456",
recordId: "record789",
sportType: 1,
sources: ["SBO", "BETFAIR"]
};
var result = ticketService.registerTicket(ticketRequest);
// {ok: false, reason: `Maximum 3 tickets allowed`}
// {ok: false, reason: `Failed to register with odds feed: errorMessage`}
// {ok: true, ...}Deregister TicketOddRequest
// Stop receiving updates for a ticket
const ticketRequest = {
matchId: "match123",
eventId: "event456",
recordId: "record789",
sportType: 1,
sources: []
};
var result = ticketService.deregisterTicket(ticketRequest);
// {ok: false, reason: `Failed to deregister with odds feed: errorMessage`}
// {ok: false, reason: 'Ticket not found' }
// {ok: true }Disconnect
Event Listening
Socket Events
There are 2 socket connection events:
// Connection established successfully
ticketService.on('connected', () => {
console.log('Connected to ODD_STREAM');
});
// Connection failed
ticketService.on('connect_error', (error: Error) => {
console.error('Connection error:', error);
});Ticket Odd Events
There are 3 ticket events, and the data is TicketOdd:
// When a new ticket is added
ticketService.on('ticketodd_added', (ticket: TicketOdd) => {
console.log('Ticket added:', ticket);
});
// When a ticket is updated with new odds
ticketService.on('ticketodd_updated', (ticket: TicketOdd) => {
console.log('Ticket updated:', ticket);
});
// When a ticket is removed
ticketService.on('ticketodd_removed', (ticket: TicketOdd) => {
console.log('Ticket removed:', ticket);
});HOW to run locally
Build package
// build the pacakge
npm run build
// link to local repo
npm linkInstall the package on your project
// stand in your project
npm link ticket-odd-service