-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send parsed game events to events processor(untested)
- Loading branch information
1 parent
802133c
commit 3abd821
Showing
11 changed files
with
298 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { BaseGameEventsProcessor } from ".."; | ||
import { getConfig } from "../../.."; | ||
import { BetProvider } from "../../../bet_providers"; | ||
import { BetikaProvider } from "../../../bet_providers/betika"; | ||
import { RedisSingleton } from "../../../datastores/redis"; | ||
import { getRedisProcessedEventsChannelName } from "../../../utils/redis"; | ||
import { ProcessedGameEvents } from "../../../utils/types/common"; | ||
import { Result } from "../../../utils/types/result_type"; | ||
|
||
const {logger} = getConfig(); | ||
|
||
export class BetikaGameEventsProcessor extends BaseGameEventsProcessor { | ||
public override betProvider: BetProvider; | ||
|
||
constructor() { | ||
super(); | ||
this.betProvider = new BetikaProvider(); | ||
} | ||
|
||
public async subscribeToChannels(): Promise<Result<boolean, Error>> { | ||
const getBetProviderConfigResult = await this.betProvider.getConfig(); | ||
if (getBetProviderConfigResult.result === "error") { | ||
logger.error("Events processor failed to load config for provider: ", this.betProvider.name); | ||
return getBetProviderConfigResult; | ||
} | ||
|
||
const getRedisSubscriberResult = await RedisSingleton.getSubscriber(); | ||
if (getRedisSubscriberResult.result === "success") { | ||
const betProviderConfig = getBetProviderConfigResult.value; | ||
const results = betProviderConfig.games.map(async game => { | ||
await getRedisSubscriberResult.value.subscribe(getRedisProcessedEventsChannelName(this.betProvider, game.name, game.betType), message => { | ||
const parsedMessage = JSON.parse(message) as ProcessedGameEvents; | ||
logger.trace("redis subscriber message received. ", parsedMessage) | ||
}); | ||
}); | ||
await Promise.all(results); | ||
return {result: "success", value: true}; | ||
} else { | ||
logger.error("Events processor failed to connect to redis subscriber for provider: ", this.betProvider.name); | ||
return getRedisSubscriberResult; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { BetProvider } from "../../bet_providers"; | ||
|
||
export abstract class BaseGameEventsProcessor { | ||
public abstract betProvider: BetProvider | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
import { RedisClientType } from "redis"; | ||
import { BetProvider } from "../../bet_providers"; | ||
import { ProcessedGameEvents } from "../../utils/types/common"; | ||
|
||
export abstract class BaseParser { | ||
public abstract betProvider: BetProvider; | ||
|
||
protected async publishProcessedGameEvents( | ||
redisPublisher: RedisClientType, | ||
channelName: string, | ||
data: ProcessedGameEvents | ||
) { | ||
await redisPublisher.publish(channelName, JSON.stringify(data)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
src/datastores/postgres/queries/three_way_game_event/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { DataSource, InsertResult, UpdateResult } from "typeorm"; | ||
import { BetProviders } from "../../../../utils/types/common"; | ||
import { ThreeWayGameEvent } from "../../../../utils/types/db"; | ||
import { ThreeWayGameEventEntity } from "../../entities"; | ||
|
||
/** | ||
* Useful for checking whether a three way game event already exists for a provider. | ||
* It can then either be created if not exists, updated if the odds have changed, or ignored if no changes. | ||
* @param dataSource | ||
* @param betProviderId | ||
* @param betProviderName | ||
* @returns | ||
*/ | ||
export const getThreeWayGame = async ( | ||
dataSource: DataSource, | ||
betProviderId: string, | ||
betProviderName: BetProviders | ||
): Promise<ThreeWayGameEventEntity | null> => { | ||
return await dataSource.createQueryBuilder() | ||
.select("three_way_game_event") | ||
.from(ThreeWayGameEventEntity, "three_way_game_event") | ||
.where("bet_provider_id = :betProviderId", {betProviderId: betProviderId}) | ||
.andWhere("bet_provider_name = :betProviderName", {betProviderName}) | ||
.getOne(); | ||
}; | ||
|
||
export const insertThreeWayGameEvent = async ( | ||
dataSource: DataSource, | ||
data: ThreeWayGameEvent | ||
): Promise<InsertResult> => { | ||
const toDataBase = { | ||
bet_provider_id: data.betProviderId, | ||
bet_provider_name: data.betProviderName, | ||
club_a: data.clubA, | ||
club_b: data.clubB, | ||
odds_a_win: data.oddsAWin, | ||
odds_b_win: data.oddsBWin, | ||
game_name: data.gameName | ||
} | ||
return await dataSource.createQueryBuilder() | ||
.insert() | ||
.into(ThreeWayGameEventEntity) | ||
.values(toDataBase) | ||
.execute(); | ||
}; | ||
|
||
export const updateThreeWayGameEventOdds = async ( | ||
dataSource: DataSource, | ||
betProviderId: string, | ||
betProviderName: BetProviders, | ||
oddsAWin: number, | ||
oddsBWin: number, | ||
oddsDraw: number | ||
): Promise<UpdateResult> => { | ||
return await dataSource.createQueryBuilder() | ||
.update(ThreeWayGameEventEntity) | ||
.set({ | ||
odds_a_win: oddsAWin, | ||
odds_b_win: oddsBWin, | ||
odds_draw: oddsDraw | ||
}) | ||
.where("bet_provider_id = :betProviderId", {betProviderId: betProviderId}) | ||
.andWhere("bet_provider_name = :betProviderName", {betProviderName}) | ||
.execute(); | ||
}; |
63 changes: 63 additions & 0 deletions
63
src/datastores/postgres/queries/two_way_game_event/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { DataSource, InsertResult, UpdateResult } from "typeorm"; | ||
import { BetProviders } from "../../../../utils/types/common"; | ||
import { TwoWayGameEvent } from "../../../../utils/types/db"; | ||
import { TwoWayGameEventEntity } from "../../entities"; | ||
|
||
/** | ||
* Useful for checking whether a two way game event already exists for a provider. | ||
* It can then either be created if not exists, updated if the odds have changed, or ignored if no changes. | ||
* @param dataSource | ||
* @param betProviderId | ||
* @param betProviderName | ||
* @returns | ||
*/ | ||
export const getTwoWayGame = async ( | ||
dataSource: DataSource, | ||
betProviderId: string, | ||
betProviderName: BetProviders | ||
): Promise<TwoWayGameEventEntity | null> => { | ||
return await dataSource.createQueryBuilder() | ||
.select("two_way_game_event") | ||
.from(TwoWayGameEventEntity, "two_way_game_event") | ||
.where("bet_provider_id = :betProviderId", {betProviderId: betProviderId}) | ||
.andWhere("bet_provider_name = :betProviderName", {betProviderName}) | ||
.getOne(); | ||
}; | ||
|
||
export const insertTwoWayGameEvent = async ( | ||
dataSource: DataSource, | ||
data: TwoWayGameEvent | ||
): Promise<InsertResult> => { | ||
const toDataBase = { | ||
bet_provider_id: data.betProviderId, | ||
bet_provider_name: data.betProviderName, | ||
club_a: data.clubA, | ||
club_b: data.clubB, | ||
odds_a_win: data.oddsAWin, | ||
odds_b_win: data.oddsBWin, | ||
game_name: data.gameName | ||
}; | ||
return await dataSource.createQueryBuilder() | ||
.insert() | ||
.into(TwoWayGameEventEntity) | ||
.values(toDataBase) | ||
.execute(); | ||
}; | ||
|
||
export const updateTwoWayGameEventOdds = async ( | ||
dataSource: DataSource, | ||
betProviderId: string, | ||
betProviderName: BetProviders, | ||
oddsAWin: number, | ||
oddsBWin: number | ||
): Promise<UpdateResult> => { | ||
return await dataSource.createQueryBuilder() | ||
.update(TwoWayGameEventEntity) | ||
.set({ | ||
odds_a_win: oddsAWin, | ||
odds_b_win: oddsBWin | ||
}) | ||
.where("bet_provider_id = :betProviderId", {betProviderId: betProviderId}) | ||
.andWhere("bet_provider_name = :betProviderName", {betProviderName}) | ||
.execute(); | ||
}; |
Oops, something went wrong.