UNPKG

bb-api-platforma

Version:

API module for BetBooster Platform

492 lines (489 loc) 18 kB
const cTest = { "DomainName": "BR", "LoginName": "igrokus", "ShortUserName": "Us", "PointName": "Долларовые счета", "CurrencyName": "USD", "LanguageId": 0, "IsLongNames": false, "BillNumber": "643610470197", "LocSoftType": 0, "FiscalNumber": null, "Head": { "ID": 137461, "UserID": 55335, "DateID": "2024-08-14T22:44:11.597", "AmountIn": 1, "AmountOut": 26.63, "CashOutUserID": null, "DateOut": null, "ParentID": 0, "LiveType": 3, "BetStatus": 1, "TranID_In": 785114, "TranID_Return": null, "TranID_Calc": null, "SoftType": 1, "BetHash": "хеш ставки", "BetHeadFlags": 18, "CountEvents": 5, "AmountPosWin": 26.63, "StatusCode": 0 }, "Content": [ { "NameBet": null, "NameTurnir": null, "TurnirId": 0, "SportId": 0, "NameCom1": "Экспресс", "NameCom2": null, "Result": null, "CountResults": 0, "MainResult": null, "EventStatus": 0, "OddsDifference": "26.6305", "DateEvent": null, "OddsForDisplay": "26.631", "ID": 146814, "HeadID": 137461, "ParentID": null, "LinesID": 0, "BetFlags": 98, "Odds": 26.6305, "OddsOrig": 26.6305, "HandSize": null, "BetVarID": 0, "Add1": 5, "Add2": null, "BetStatus": 1, "AuthorOdds": 0, "SiteOdds": null, "AmountIn": 1, "AmountOut": 26.63, "AmountItem": null, "Score": "", "AuthorName": null, "IsNewRecord": false, "IsHeadsContent": true, "LiveFlagForCalcAdditionalBets": 64 }, { "NameBet": "П1", "NameTurnir": "Футбол. Суперкубок УЕФА", "TurnirId": 47, "SportId": 5, "NameCom1": "Реал Мадрид", "NameCom2": "Аталанта", "Result": "0:0 (0:0)", "CountResults": 0, "MainResult": null, "EventStatus": 2, "OddsDifference": "2.1000", "DateEvent": "2024-08-14T22:00:00", "OddsForDisplay": "2.10", "ID": 146815, "HeadID": 137461, "ParentID": 146814, "LinesID": 654886, "BetFlags": 67, "Odds": 2.1, "OddsOrig": 2.1, "HandSize": null, "BetVarID": 1, "Add1": null, "Add2": null, "BetStatus": 1, "AuthorOdds": 1, "SiteOdds": 11, "AmountIn": null, "AmountOut": 5.8587, "AmountItem": 0.22, "Score": "0:0 44`", "AuthorName": "admin", "IsNewRecord": false, "IsHeadsContent": false, "LiveFlagForCalcAdditionalBets": 32 }, { "NameBet": "П2", "NameTurnir": "Футбол. Суперкубок УЕФА. Статистика", "TurnirId": 2408, "SportId": 5, "NameCom1": "ЖК Реал Мадрид", "NameCom2": "ЖК Аталанта", "Result": "2:1 (2:1)", "CountResults": 0, "MainResult": null, "EventStatus": 2, "OddsDifference": "2.9800", "DateEvent": "2024-08-14T22:00:00", "OddsForDisplay": "2.98", "ID": 146816, "HeadID": 137461, "ParentID": 146814, "LinesID": 856037, "BetFlags": 67, "Odds": 2.98, "OddsOrig": 2.98, "HandSize": null, "BetVarID": 3, "Add1": null, "Add2": null, "BetStatus": 1, "AuthorOdds": 1, "SiteOdds": 11, "AmountIn": null, "AmountOut": 8.2555, "AmountItem": 0.31, "Score": "2:1 44`", "AuthorName": "admin", "IsNewRecord": false, "IsHeadsContent": false, "LiveFlagForCalcAdditionalBets": 32 }, { "NameBet": "П1", "NameTurnir": "Футбол. Суперкубок УЕФА. Статистика", "TurnirId": 2408, "SportId": 5, "NameCom1": "Реал Мадрид офсайды", "NameCom2": "Аталанта офсайды", "Result": "0:0 (0:0)", "CountResults": 0, "MainResult": null, "EventStatus": 2, "OddsDifference": "2.9800", "DateEvent": "2024-08-14T22:00:00", "OddsForDisplay": "2.98", "ID": 146817, "HeadID": 137461, "ParentID": 146814, "LinesID": 859490, "BetFlags": 67, "Odds": 2.98, "OddsOrig": 2.98, "HandSize": null, "BetVarID": 1, "Add1": null, "Add2": null, "BetStatus": 1, "AuthorOdds": 1, "SiteOdds": 11, "AmountIn": null, "AmountOut": 8.2555, "AmountItem": 0.31, "Score": "0:0 44`", "AuthorName": "admin", "IsNewRecord": false, "IsHeadsContent": false, "LiveFlagForCalcAdditionalBets": 32 }, { "NameBet": "П1", "NameTurnir": "Футбол. Суперкубок УЕФА. Статистика", "TurnirId": 2408, "SportId": 5, "NameCom1": "Реал Мадрид удары в створ", "NameCom2": "Аталанта удары в створ", "Result": "0:0 (0:0)", "CountResults": 0, "MainResult": null, "EventStatus": 2, "OddsDifference": "1.4000", "DateEvent": "2024-08-14T22:00:00", "OddsForDisplay": "1.40", "ID": 146818, "HeadID": 137461, "ParentID": 146814, "LinesID": 859491, "BetFlags": 67, "Odds": 1.4, "OddsOrig": 1.4, "HandSize": null, "BetVarID": 1, "Add1": null, "Add2": null, "BetStatus": 1, "AuthorOdds": 1, "SiteOdds": 11, "AmountIn": null, "AmountOut": 4.2609, "AmountItem": 0.16, "Score": "0:0 44`", "AuthorName": "admin", "IsNewRecord": false, "IsHeadsContent": false, "LiveFlagForCalcAdditionalBets": 32 }, { "NameBet": null, "NameTurnir": null, "TurnirId": 0, "SportId": 0, "NameCom1": "Бонус", "NameCom2": "Кол-во", "Result": null, "CountResults": 0, "MainResult": null, "EventStatus": 0, "OddsDifference": "1.0200", "DateEvent": null, "OddsForDisplay": "1.02", "ID": 146819, "HeadID": 137461, "ParentID": 146814, "LinesID": 0, "BetFlags": 50, "Odds": 1.02, "OddsOrig": 1.02, "HandSize": null, "BetVarID": 2, "Add1": null, "Add2": null, "BetStatus": 2, "AuthorOdds": 0, "SiteOdds": null, "AmountIn": null, "AmountOut": 0, "AmountItem": 0, "Score": "", "AuthorName": null, "IsNewRecord": false, "IsHeadsContent": true, "LiveFlagForCalcAdditionalBets": 32 } ], "PutBetErrors": 0, "PercentReturnMoney": 0, "AmaountOutPercent": 0, "PointId": 1, "PointGroupId": 57, "Coef": 26.6305, "CoefOrig": 26.6305 }; // function decomposeNumberIntoPowersOfTwo_(number: number, statuses: { [key: number]: string } = {}): { [key: number]: string } { // try { // if (typeof number !== 'number' || isNaN(number)) { // throw new Error('Входное значение должно быть числом.'); // } // let powers: number[] = []; // let currentNumber = number; // for (let i = 19; i >= 0; i--) { // let power = Math.pow(2, i); // if (power <= currentNumber) { // powers.push(power); // currentNumber -= power; // } // if (currentNumber === 0) break; // } // return powers.reverse().reduce((obj, item) => { // obj[item] = statuses[item] ?? ''; // return obj; // }, {} as { [key: number]: string }); // } catch (error) { // console.error('Ошибка при разложении числа на степени двойки:', error); // return {}; // } // } // function getStatuses_(number: number, name: 'BetHeadFlags' | 'BetStatus' | 'LiveType') { // const data = decomposeNumberIntoPowersOfTwo(number, sts[name]); // // console.log(data); // return { // [name+'Ids']: Object.keys(data), // [name+'Names']: Object.values(data).join(', '), // }; // } const sts = { "BetHeadFlags": { "0": "None", "1": "Single", "2": "Multi", "4": "System", "8": "Reinvested", "16": "Bonus", "32": "Ordinary", "64": "Live", "96": "Combined" }, "BetStatus": { "0": "Undefined", "1": "Not calculated", "2": "Win", "4": "Loss", "8": "Refund", "16": "Not calculated", "32": "Paid out", "64": "Office fund", "128": "Refund (handicap/total)", "256": "Partial refund (handicap/total)", "512": "Partial refund and win (handicap/total)", "1024": "Odds changed by bookmaker", "2048": "Bet placed after match start", "4096": "Cancelled by provider", "8192": "Cash bonus", "16384": "Removed via CashOut" }, "LiveType": { "0": "Undefined", "1": "Prematch bet", "2": "Inplay bet", "3": "Combined bet" }, }; // function convertBetslipDataDefault(asasas: any) { // // betSlipData = cc; // const currency = cc.CurrencyName; // // const Winning = cc.Head.AmountOut; // // const WinTax = Winning * 0; // // const PossibleWin = Winning - WinTax; // const first = cc.Content[0] || {}; // const placedAmount = (+(first.AmountIn || 0)).toFixed(2); // const totalOdds = (+first.OddsForDisplay || 0).toFixed(4); // const amountOut = (+(first.AmountOut || 0)).toFixed(2); // console.log('cc.Head.BetStatus', getStatuses(cc.Head.BetStatus, 'BetStatus')); // console.log('cc.Head.BetHeadFlags', getStatuses(cc.Head.BetHeadFlags, 'BetHeadFlags')); // console.log('cc.Head.BetHeadFlags', getStatuses(cc.Head.LiveType, 'LiveType')); // const forPrintData = { // header: { // "Point name": cc.PointName, // "Bet date": ['---', new Date(cc.Head.DateID).toLocaleString(), '---'].join(' '), // "Bet ID": cc.BillNumber, // // "Type": cc.Head.LiveType === 1 ? 'Pre-match' : 'Live', // "Type": decomposeNumberIntoPowersOfTwo(cc.Head.LiveType, sts.LiveType), // }, // bets: [], // footer: { // PlacedAmount: `Placed amount: ${placedAmount} ${currency}`, // "Total odds": `${totalOdds}`, // PossibleWin: `Possible Win: ${amountOut} ${currency}`, // }, // }; // const startDigit = cc.Content.length > 1 ? 1 : 0; // let num = 1; // for (let i = startDigit; i < cc.Content.length; i++) { // const bet: OddsContent = cc.Content[i]; // const isBonus = bet.BetVarID === 2; // const evDate = bet.DateEvent ? new Date(bet.DateEvent).toLocaleString() : ''; // const teams = !isBonus ? [bet.NameCom1, bet.NameCom2].join(' - ') : ''; // const tournament = !isBonus ? bet.NameTurnir : ''; // const odd = bet.OddsForDisplay; // const item = { // date: isBonus && bet.DateEvent === null ? `${num}) ${bet.NameCom1}` : `${num}) ${evDate}`, // ...(tournament ? { tournament } : {}), // ...(teams ? { teams } : {}), // betName: isBonus ? `${bet.NameCom1}: ${odd}` : `${bet.NameBet}: ${odd}`, // ...getStatuses(bet.BetFlags, 'BetHeadFlags'), // ...getStatuses(bet.BetStatus, 'BetStatus'), // // odd: bet.Coef.toFixed(2), // // isLive: bet.IsLive ? ' Live' : '', // // score: bet.Result || '', // // isBonus: bet.IsBonus, // } as never; // forPrintData.bets.push(item); // num++; // } // return forPrintData; // } export class Coupon { constructor(lang = 'en') { this.statusesDict = sts; console.log('Coupon class'); } decomposeNumberIntoPowersOfTwo(number, statuses = {}) { try { if (typeof number !== 'number' || isNaN(number)) { throw new Error('Входное значение должно быть числом.'); } let powers = []; let currentNumber = number; for (let i = 19; i >= 0; i--) { let power = Math.pow(2, i); if (power <= currentNumber) { powers.push(power); currentNumber -= power; } if (currentNumber === 0) break; } return powers.reverse().reduce((obj, item) => { var _a; obj[item] = (_a = statuses[item]) !== null && _a !== void 0 ? _a : ''; return obj; }, {}); } catch (error) { console.error('Ошибка при разложении числа на степени двойки:', error); return {}; } } getStatuses(number, name) { const data = this.decomposeNumberIntoPowersOfTwo(number, sts[name]); // console.log(data); return { [name + 'Ids']: Object.keys(data), [name + 'Names']: Object.values(data).join(', '), }; } convertBetslipDataDefault(bc) { // betSlipData = cc; const cc = bc !== null && bc !== void 0 ? bc : cTest; const currency = cc.CurrencyName; // const Winning = cc.Head.AmountOut; // const WinTax = Winning * 0; // const PossibleWin = Winning - WinTax; const first = cc.Content[0] || {}; const placedAmount = (+(first.AmountIn || 0)).toFixed(2); const totalOdds = (+first.OddsForDisplay || 0).toFixed(4); const amountOutFloat = +cc.Head.AmountOut || 0; const amountOut = amountOutFloat.toFixed(2); console.log('cc.Head.BetStatus', this.getStatuses(cc.Head.BetStatus, 'BetStatus')); console.log('cc.Head.BetHeadFlags', this.getStatuses(cc.Head.BetHeadFlags, 'BetHeadFlags')); console.log('cc.Head.BetHeadFlags', this.getStatuses(cc.Head.LiveType, 'LiveType')); const BetStatus = this.getStatuses(cc.Head.BetStatus, 'BetStatus'); const forPrintData = { data: Object.assign({}, BetStatus), header: { "Point name": cc.PointName, "Bet date": ['---', new Date(cc.Head.DateID).toLocaleString(), '---'].join(' '), "Bet ID": cc.BillNumber, "BetStatus": BetStatus.BetStatusNames, // ...this.getStatuses(cc.Head.LiveType, 'LiveType'), }, bets: [], footer: { PlacedAmount: `Placed amount: ${placedAmount} ${currency}`, "Total odds": `${totalOdds}`, // PossibleWin: `Possible Win: ${amountOut} ${currency}`, Win: `Win: ${amountOut} ${currency}`, // ...(amountOutFloat ? { "Win:": amountOutFloat } : {}), }, }; const startDigit = cc.Content.length > 1 ? 1 : 0; let num = 1; for (let i = startDigit; i < cc.Content.length; i++) { const bet = cc.Content[i]; const isBonus = bet.BetVarID === 2; const evDate = bet.DateEvent ? new Date(bet.DateEvent).toLocaleString() : ''; const teams = !isBonus ? [bet.NameCom1, bet.NameCom2].join(' - ') : ''; const tournament = !isBonus ? bet.NameTurnir : ''; const odd = bet.OddsForDisplay; const betStatusNames = this.getStatuses(bet.BetStatus, 'BetStatus').BetStatusNames; const item = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ date: isBonus && bet.DateEvent === null ? `${num}) ${bet.NameCom1}` : `${num}) ${evDate}` }, (tournament ? { tournament } : {})), (teams ? { teams } : {})), { betName: isBonus ? `${bet.NameCom1}: ${odd}` : `${bet.NameBet}: ${odd}` }), (bet.Result ? { result: bet.Result } : {})), { betStatusNames }); forPrintData.bets.push(item); num++; } const text = [ Object.values(forPrintData.header).join('\n'), forPrintData.bets.map((item) => Object.values(item).join('\n')).join('\n----------------\n'), Object.values(forPrintData.footer).join('\n'), ].join('\n====================\n'); return Object.assign(Object.assign({}, forPrintData), { text }); } } ; // const cc = new Coupon(); // console.log(cc.convertBetslipDataDefault(cTest)); /* node --no-warnings --loader ts-node/esm ./src/coupon.ts */