@ganchrowsci/gs-sdk
v1.0.27
Published
Ganchrow Scientific SDK
Downloads
3
Readme
Getting started
Ganchrow Scientific provides a nodejs based library in order to consume different kinds of information.
Install
$npm install @ganchrowsci/gs-sdk -S
Import
import { GsSdk } from '@ganchrowsci/gs-sdk';
// or if you prefer:
const { GsSdk } = require('@ganchrowsci/gs-sdk');
Types and Interfaces importing for Typescript
import { GsSdk, Line, Event, Score } from '@ganchrowsci/gs-sdk';
Usage
let gsSdk = new GsSdk({
username: 'some.user',
password: '********',
url: 'ask for URL details'
});
await gsSdk.connect();
Once the sdk is connected set listeners for the different kinds of data:
gsSdk.addEventListener(ValidKinds.events, (event: Event) => {
// It will return an Event object
});
gsSdk.addEventListener(ValidKinds.lines, (line: Line) => {
// It will return a Line Object
});
gsSdk.addEventListener(ValidKinds.scores, (score: Score) => {
// It will return a Score Object
});
EVENTS
On first connection the sdk will sync state with the Ganchrow Scientific Cloud. It means that common data is going to be downloaded: eventStatuses, periods, wagertypes, countries, leagues etc. Once it's done current events, sports, leagues and wagertypes are stored in memory and can be accessed whenever it's necessary. When a new event arrives or it's updated the Event event is triggered and the event is cached in memory allowing lines and scores to have accessors to this Event. When an event is expired it will be marked as expired and will be removed after the configured expiration time is reached. (default 15m)
let events: Events = sdk.events();
// you can iterate all the events.
Object.entries(events).forEach(([rotation: Event['rotation'], event: Event]) => {
console.log(event.rotation);
});
Lines and scores provide accessors to event, league and country:
gsSdk.addEventListener(ValidKinds.lines, (line: Line) => {
// do whatever you want with the line
console.log(line.rotation)
let sport: Sport = line.event.sport;
let country: Country = line.event.country;
console.log(country.name)
});
gsSdk.addEventListener(ValidKinds.scores, (score: Score) => {
// do whatever you want with the score
console.log(score.rotation)
console.log(score.event.sport)
});
Expirations
Events that are no longer active are expired. An expiration message is emitted in order expirations can be handled on the client side. In case the client is disconnected a 24hs history of expirations is available. A timestamp can be provided to get all the expirations that happened between that timestamp and the current time.
let fromTimestamp = 1605630601500;
let expirations = await gsSdk.getExpirations(fromTimestamp);
License
Copyright (c) 2020 Ganchrow Scientific.