overtime-live-trading-utils 0.1.7 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/main.js CHANGED
@@ -1 +1 @@
1
- !function(r,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.thalesUtils=e():r.thalesUtils=e()}(this,(()=>(()=>{"use strict";var r={d:(e,a)=>{for(var t in a)r.o(a,t)&&!r.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:a[t]})},o:(r,e)=>Object.prototype.hasOwnProperty.call(r,e),r:r=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})}},e={};r.r(e),r.d(e,{adjustSpreadOnOdds:()=>q,allowGameSportWithPeriodConstraint:()=>G,allowGameSportWithResultConstraint:()=>W,allowSoccerGame:()=>I,calculateImpliedOddsDifference:()=>w,checkGameContraints:()=>x,checkOddsFromBookmakers:()=>c,extractOddsForGamePerProvider:()=>K,fetchResultInCurrentSet:()=>U,gamesDatesMatching:()=>z,getBookmakersArray:()=>u,getLeagueSport:()=>M,getSpreadData:()=>J,teamNamesMatching:()=>H}),"function"!=typeof Object.assign&&(Object.assign=function(r,e){if(null==r)throw new TypeError("Cannot convert undefined or null to object");for(var a=Object(r),t=1;t<arguments.length;t++){var o=arguments[t];if(null!=o)for(var i in o)Object.prototype.hasOwnProperty.call(o,i)&&(a[i]=o[i])}return a});var a=function(r){return parseFloat(r.toPrecision(12))};function t(r,e,a){return void 0===a||0==+a?Math[r](e):(e=+e,a=+a,isNaN(e)||"number"!=typeof a||a%1!=0?NaN:e<0?-t(r,-e,a):(e=e.toString().split("e"),+((e=(e=Math[r](+(e[0]+"e"+(e[1]?+e[1]-a:-a)))).toString().split("e"))[0]+"e"+(e[1]?+e[1]+a:a))))}var o,i,s={decimal:{from:function(r){if((r=parseFloat(r))<=1)throw new Error("Outside valid range.");return r},to:function(){return this.decimalValue}},moneyline:{from:function(r){return(r=parseFloat(r))>=0?r/100+1:100/-r+1},to:function(){return this.decimalValue>=2?a(100*(this.decimalValue-1)):a(-100/(this.decimalValue-1))}},hongKong:{from:function(r){if((r=parseFloat(r))<0)throw new Error("Outside valid range.");return r+1},to:function(){return a(this.decimalValue-1)}},impliedProbability:{from:function(r){if((r="string"==typeof r&&"%"==r.slice(-1)?parseFloat(r)/100:parseFloat(r))<=0||r>=1)throw new Error("Outside valid range");return 1/r},to:function(r){if(r.percentage){var e=a(100/this.decimalValue);return null!==r.precision&&(e=t("round",e,-r.precision)),e.toString()+"%"}return a(1/this.decimalValue)}},fractional:{from:function(r){var e,a=r.toString().split("/");if(r=parseFloat(a[0]),2===a.length)e=parseFloat(a[1]);else{if(1!==a.length)throw new Error("Invalid fraction");e=1}if(0===r||0===e||r/e<=0)throw new Error("Outside valid range");return 1+r/e},to:function(r){return function(r,e){for(var a,t=[0,1],o=[1,0],i=function(r){var e=null,a=r.toString().indexOf("E");-1==a&&(a=r.toString().indexOf("e"));var t=null,o=(e=-1==a?r.toString():r.toString().substring(0,a)).toString().indexOf(".");-1==o?t=e:0===o?t=e.substring(1,e.length):o<e.length&&(t=e.substring(0,o)+e.substring(o+1,e.length));var i=t,s=i.toString().length,n=r,l=n.toString().length;0===n&&(l=0);var d,u=s-l;for(d=u;d>0&&i%2==0;d--)i/=2;for(d=u;d>0&&i%5==0;d--)i/=5;return i}(r),s=r,n=Math.pow(10,-e)/2,l=2;l<1e3;l++){var d=Math.floor(s);if(t[l]=d*t[l-1]+t[l-2],Math.abs(t[l])>i)return;if(o[l]=d*o[l-1]+o[l-2],a=t[l]/o[l],Math.abs(a-r)<n||NaN==a)return t[l].toString()+"/"+o[l].toString();s=1/(s-d)}}(this.decimalValue-1,r.precision||12)}},malay:{from:function(r){if((r=parseFloat(r))<=-1||r>1)throw new Error("Outside valid range.");return r<0&&(r=-1/r),r+1},to:function(){return this.decimalValue<=2?a(this.decimalValue-1):a(-1/(this.decimalValue-1))}},indonesian:{from:function(r){if(0===(r=parseFloat(r)))throw new Error("Outside valid range.");return r>=1?r+1:-1/r+1},to:function(){return this.decimalValue<2?a(-1/(this.decimalValue-1)):a(this.decimalValue-1)}}},n=((i=function(r){if("number"!=typeof r||isNaN(r))throw new Error("Invalid odds");this.decimalValue=a(r)}).prototype=(o=function(){throw new Error("This constructor is private, please use the from* functions")}).prototype,o.from=function(r,e){if(!s.hasOwnProperty(r))throw new Error("Unknown format "+r+".");var a=s[r].from(e);return new i(a)},o);n.prototype.to=function(r,e){if(!s.hasOwnProperty(r))throw new Error("Unknown format "+r+".");e=Object.assign({precision:null,percentage:!1},e);var a=s[r].to.call(this,e);return"number"==typeof a&&null!==e.precision&&(a=t("round",a,-e.precision)),a};var l,d=n.from,u=function(r,e,a){var t=r.find((function(r){return Number(r.sportId)===Number(e)}));if(t){if(""==t.primaryBookmaker)return a;var o=[];return t.primaryBookmaker&&o.push(t.primaryBookmaker),t.secondaryBookmaker&&o.push(t.secondaryBookmaker),t.tertiaryBookmaker&&o.push(t.tertiaryBookmaker),o}return a},c=function(r,e,a,t,o){var i=e.some((function(e){var t=r.get(e);return!!t&&(0===t.homeOdds||0===t.awayOdds||!a&&0===t.drawOdds||1===t.homeOdds||1===t.awayOdds||!a&&1===t.drawOdds)}));if(1==e.length){if(i)return[{homeOdds:0,awayOdds:0,drawOdds:0}];var s=e[0],n=r.get(s);return[{homeOdds:n.homeOdds,awayOdds:n.awayOdds,drawOdds:a?0:n.drawOdds}]}if(i)return[{homeOdds:0,awayOdds:0,drawOdds:0}];var l=r.get(e[0]),u=l.homeOdds,c=l.awayOdds,p=l.drawOdds;if(e.slice(1).some((function(e){var i=r[e];if(i){var s=i.homeOdds,n=i.awayOdds,l=i.drawOdds,m=d("decimal",u).to("impliedProbability"),f=d("decimal",c).to("impliedProbability"),b=a?0:d("decimal",p).to("impliedProbability"),v=d("decimal",s).to("impliedProbability"),g=d("decimal",n).to("impliedProbability"),h=a?0:d("decimal",l).to("impliedProbability"),A=w(m,v),y=w(f,g),D=a?0:w(b,h);if(A>t&&m>o&&v>o||y>t&&f>o&&g>o||!a&&D>t&&b>o&&h>o)return!0}return!1})))return console.log("Returning zero odds due to percentage difference"),[{homeOdds:0,awayOdds:0,drawOdds:0}];var m=[];return e.forEach((function(e){return m.push(r.get(e))})),null!=m[0]?m.map((function(r){return{homeOdds:r.homeOdds,awayOdds:r.awayOdds,drawOdds:a?0:r.drawOdds}})):(console.log("Returning zero odds cause no matching bookmakers have been found"),[{homeOdds:0,awayOdds:0,drawOdds:0}])},w=function(r,e){var a=Math.abs(r-e)/r*100;return console.log("% diff: "+a),a},p="Soccer",m="Football",f="Basketball",b="Baseball",v="Hockey",g="Fighting",h="Tennis",A="eSports",y="Rugby",D="Volleyball",O="Handball",C="Cricket",S="Motosport",N="Golf",L=153,k=156,_=158,T=9977,P=9983,V=10138,B=100021,E=100121,F=[T,P,V,L,k,_,15312,15313,15314,15315,15316,15317,15318,15622,15623,15624,15625,15626,15627,15628,15632,15633,15634,15635,15636,15637,15638,15641,15642,15643,15644,15645,15646,15647,15648],j=((l={})[1]={sport:m,id:1,isDrawAvailable:!1},l[2]={sport:m,id:2,isDrawAvailable:!1},l[3]={sport:b,id:3,isDrawAvailable:!1},l[4]={sport:f,id:4,isDrawAvailable:!1},l[5]={sport:f,id:5,isDrawAvailable:!1},l[6]={sport:v,id:6,isDrawAvailable:!1},l[7]={sport:g,id:7,isDrawAvailable:!1},l[8]={sport:f,id:8,isDrawAvailable:!1},l[10]={sport:p,id:10,isDrawAvailable:!0},l[11]={sport:p,id:11,isDrawAvailable:!0},l[12]={sport:p,id:12,isDrawAvailable:!0},l[13]={sport:p,id:13,isDrawAvailable:!0},l[14]={sport:p,id:14,isDrawAvailable:!0},l[15]={sport:p,id:15,isDrawAvailable:!0},l[16]={sport:p,id:16,isDrawAvailable:!0},l[17]={sport:p,id:17,isDrawAvailable:!0},l[18]={sport:p,id:18,isDrawAvailable:!0},l[19]={sport:p,id:19,isDrawAvailable:!0},l[20]={sport:C,id:20,isDrawAvailable:!1},l[21]={sport:C,id:21,isDrawAvailable:!1},l[33]={sport:v,id:33,isDrawAvailable:!0},l[44]={sport:p,id:44,isDrawAvailable:!0},l[45]={sport:p,id:45,isDrawAvailable:!0},l[50]={sport:p,id:50,isDrawAvailable:!0},l[57]={sport:p,id:57,isDrawAvailable:!0},l[61]={sport:p,id:61,isDrawAvailable:!0},l[65]={sport:p,id:65,isDrawAvailable:!0},l[66]={sport:p,id:66,isDrawAvailable:!0},l[76]={sport:p,id:76,isDrawAvailable:!0},l[132]={sport:p,id:132,isDrawAvailable:!0},l[134]={sport:p,id:134,isDrawAvailable:!0},l[138]={sport:p,id:138,isDrawAvailable:!0},l[141]={sport:p,id:141,isDrawAvailable:!0},l[153]={sport:h,id:L,isDrawAvailable:!1},l[156]={sport:h,id:k,isDrawAvailable:!1},l[158]={sport:h,id:_,isDrawAvailable:!1},l[209]={sport:p,id:209,isDrawAvailable:!0},l[268]={sport:p,id:268,isDrawAvailable:!0},l[288]={sport:p,id:288,isDrawAvailable:!0},l[296]={sport:p,id:296,isDrawAvailable:!0},l[380]={sport:O,id:380,isDrawAvailable:!0},l[381]={sport:O,id:381,isDrawAvailable:!0},l[399]={sport:f,id:399,isDrawAvailable:!1},l[406]={sport:f,id:406,isDrawAvailable:!1},l[407]={sport:f,id:407,isDrawAvailable:!1},l[409]={sport:f,id:409,isDrawAvailable:!1},l[445]={sport:S,id:445,isDrawAvailable:!1},l[453]={sport:D,id:453,isDrawAvailable:!1},l[454]={sport:D,id:454,isDrawAvailable:!1},l[8910]={sport:"TableTennis",id:8910,isDrawAvailable:!1},l[497]={sport:S,id:497,isDrawAvailable:!1},l[536]={sport:p,id:536,isDrawAvailable:!0},l[8881]={sport:"Waterpolo",id:8881,isDrawAvailable:!0},l[8893]={sport:D,id:8893,isDrawAvailable:!1},l[8894]={sport:D,id:8894,isDrawAvailable:!1},l[9196]={sport:g,id:9196,isDrawAvailable:!1},l[9578]={sport:y,id:9578,isDrawAvailable:!0},l[9588]={sport:y,id:9588,isDrawAvailable:!0},l[9698]={sport:v,id:9698,isDrawAvailable:!0},l[9699]={sport:v,id:9699,isDrawAvailable:!0},l[9806]={sport:p,id:9806,isDrawAvailable:!0},l[9821]={sport:p,id:9821,isDrawAvailable:!0},l[9977]={sport:A,id:T,isDrawAvailable:!1},l[9983]={sport:A,id:P,isDrawAvailable:!1},l[10071]={sport:f,id:10071,isDrawAvailable:!1},l[10072]={sport:f,id:10072,isDrawAvailable:!1},l[10502]={sport:f,id:10502,isDrawAvailable:!1},l[10138]={sport:A,id:V,isDrawAvailable:!1},l[10199]={sport:p,id:10199,isDrawAvailable:!0},l[10216]={sport:p,id:10216,isDrawAvailable:!0},l[10595]={sport:g,id:10595,isDrawAvailable:!1},l[10611]={sport:p,id:10611,isDrawAvailable:!0},l[10613]={sport:p,id:10613,isDrawAvailable:!0},l[10615]={sport:p,id:10615,isDrawAvailable:!0},l[100021]={sport:N,id:B,isDrawAvailable:!1},l[100121]={sport:N,id:E,isDrawAvailable:!1},l[230]={sport:p,id:230,isDrawAvailable:!0},l),M=function(r){var e=j[r];return e?e.sport:""},x=function(r,e,a){var t=r.score_home_total,o=r.score_away_total,i=r.clock,s=r.period,n=r.status,l=r.home_team,d=r.away_team,u=parseInt(s),c=M(e);return"completed"==n.toLowerCase()?{allow:!1,message:"Blocking game ".concat(l," - ").concat(d," because it is no longer live.")}:c===f?G(l,d,u,a.get(f)):c===v?G(l,d,u,a.get(v)):c===b?G(l,d,u,a.get(b)):c===p?I(l,d,i,s,a.get(p)):c===h?W(r,l,d,s,t,o,e,c):c===D?W(r,l,d,u,t,o,e,c):{allow:!0,message:"The sport ".concat(e," does not have constraint")}},G=function(r,e,a,t){return!Number.isNaN(a)&&a>=t?{allow:!1,message:"Blocking game ".concat(r," - ").concat(e," due to period: ").concat(a,". period")}:{allow:!0,message:""}},I=function(r,e,a,t,o){var i=Number(a);return!Number.isNaN(i)&&i>=o||Number.isNaN(i)&&"HALF"!=t?{allow:!1,message:"Blocking game ".concat(r," - ").concat(e," due to clock: ").concat(a,"min")}:{allow:!0,message:""}},W=function(r,e,a,t,o,i,s,n){var l=Number(t),d=U(l,r),u="atp"==r.league.toLowerCase(),c={home:o,away:i};return n==D?R(e,a,d,c,2,5==l?10:20):s.toString().startsWith(L)&&u?R(e,a,d,c,2,5):s.toString().startsWith(L)&&!u||s.toString().startsWith(k)||s.toString().startsWith(_)?R(e,a,d,c,1,5):{allow:!0,message:"The sport ".concat(s," does not have result constraint")}},U=function(r,e){var a=0,t=0;switch(r){case 2:a=Number(e.score_home_period_2),t=Number(e.score_away_period_2);break;case 3:a=Number(e.score_home_period_3),t=Number(e.score_away_period_3);break;case 4:a=Number(e.score_home_period_4),t=Number(e.score_away_period_4);break;case 5:a=Number(e.score_home_period_5),t=Number(e.score_away_period_5)}return{home:a,away:t}},R=function(r,e,a,t,o,i){return Number(t.home)!=o&&Number(t.away)!=o||!(Number(t.home)==o&&a.home>=i||Number(t.away)==o&&a.away>=i)?{allow:!0,message:"",currentHomeGameScore:a.home,currentAwayGameScore:a.away}:{allow:!1,message:"Blocking game ".concat(r," - ").concat(e," due to current result: ").concat(t.home," - ").concat(t.away," (").concat(a.home," - ").concat(a.away,")")}},H=function(r,e,a,t,o,i){var s,n;if(F.includes(r)?(s=t.toLowerCase()==e.toLowerCase()||t.toLowerCase()==a.toLowerCase(),n=o.toLowerCase()==e.toLowerCase()||o.toLowerCase()==a.toLowerCase()):(s=t.toLowerCase()==e.toLowerCase(),n=o.toLowerCase()==a.toLowerCase()),!0!==s){var l=i.get(t.toLowerCase()),d=i.get(e.toLowerCase()),u=i.get(a.toLowerCase());if([l,d].some((function(r){return null==r})))return!1;s=F.includes(r)?l==d||l==u:l==d}if(!0!==n){var c=i.get(o.toLowerCase());if(d=i.get(e.toLowerCase()),[c,u=i.get(a.toLowerCase())].some((function(r){return null==r})))return!1;n=F.includes(r)&&c==d||c==u}return s&&n},z=function(r,e,a,t){var o;if(M(a)==h){var i=e.getTime(),s=r.getTime();o=Math.abs(s-i)<=Number(60*t*1e3)}else o=e.toUTCString()==r.toUTCString();return o},K=function(r,e,a,t,o){var i=new Map;return r.forEach((function(r){var s,n,l=e.odds.filter((function(e){return e.sports_book_name.toLowerCase()==r.toLowerCase()})),d=t.get(a.homeTeam.toLowerCase()),u=t.get(a.awayTeam.toLowerCase()),c=0;null!=(s=null==d?l.find((function(r){var e=t.get(r.name.toLowerCase());return null==e?r.name.toLowerCase()==a.homeTeam.toLowerCase():e==a.homeTeam.toLowerCase()})):l.find((function(r){var e=t.get(r.name.toLowerCase());return null==e?r.name.toLowerCase()==d:e==d})))&&(c=s.price);var w=0;null!=(n=null==u?l.find((function(r){var e=t.get(r.name.toLowerCase());return null==e?r.name.toLowerCase()==a.awayTeam.toLowerCase():e==a.awayTeam.toLowerCase()})):l.find((function(r){var e=t.get(r.name.toLowerCase());return null==e?r.name.toLowerCase()==u:e==u})))&&(w=n.price);var p=0;if(o){var m=l.find((function(r){return"draw"==r.name.toLowerCase()}));null!=m&&(p=m.price)}i.set(r.toLowerCase(),{homeOdds:c,awayOdds:w,drawOdds:p})})),i},q=function(r,e,a){if(r.some((function(r){return 0===r})))return r;var t=r.reduce((function(r,e){return r+e}),0);if(t<=1)return Array(r.length).fill(0);if(0===a){if(!(e>100*(t-1)))return r;a=e}var o=1+a/100,i=o/t,s=r.map((function(r){return r*i}));if(s.some((function(r){return r>=1})))return Array(r.length).fill(0);var n=s.reduce((function(r,e){return r+e}),0);if(n<1)return Array(r.length).fill(0);var l=o/n;return s.map((function(r){return r*l}))},J=function(r,e,a,t){var o=r.find((function(r){return Number(r.typeId)===Number(a)&&Number(r.sportId)===Number(e)}));return o?{minSpread:o.minSpread?Number(o.minSpread):t,targetSpread:o.targetSpread?Number(o.targetSpread):0}:{minSpread:t,targetSpread:0}};return e})()));
1
+ !function(r,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.thalesUtils=e():r.thalesUtils=e()}(this,(()=>(()=>{"use strict";var r={d:(e,a)=>{for(var t in a)r.o(a,t)&&!r.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:a[t]})},o:(r,e)=>Object.prototype.hasOwnProperty.call(r,e),r:r=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})}},e={};r.r(e),r.d(e,{adjustSpreadOnOdds:()=>q,allowGameSportWithPeriodConstraint:()=>G,allowGameSportWithResultConstraint:()=>W,allowSoccerGame:()=>I,calculateImpliedOddsDifference:()=>w,checkGameContraints:()=>x,checkOddsFromBookmakers:()=>c,extractOddsForGamePerProvider:()=>K,fetchResultInCurrentSet:()=>U,gamesDatesMatching:()=>z,getBookmakersArray:()=>u,getLeagueSport:()=>M,getSpreadData:()=>J,teamNamesMatching:()=>H}),"function"!=typeof Object.assign&&(Object.assign=function(r,e){if(null==r)throw new TypeError("Cannot convert undefined or null to object");for(var a=Object(r),t=1;t<arguments.length;t++){var i=arguments[t];if(null!=i)for(var o in i)Object.prototype.hasOwnProperty.call(i,o)&&(a[o]=i[o])}return a});var a=function(r){return parseFloat(r.toPrecision(12))};function t(r,e,a){return void 0===a||0==+a?Math[r](e):(e=+e,a=+a,isNaN(e)||"number"!=typeof a||a%1!=0?NaN:e<0?-t(r,-e,a):(e=e.toString().split("e"),+((e=(e=Math[r](+(e[0]+"e"+(e[1]?+e[1]-a:-a)))).toString().split("e"))[0]+"e"+(e[1]?+e[1]+a:a))))}var i,o,s={decimal:{from:function(r){if((r=parseFloat(r))<=1)throw new Error("Outside valid range.");return r},to:function(){return this.decimalValue}},moneyline:{from:function(r){return(r=parseFloat(r))>=0?r/100+1:100/-r+1},to:function(){return this.decimalValue>=2?a(100*(this.decimalValue-1)):a(-100/(this.decimalValue-1))}},hongKong:{from:function(r){if((r=parseFloat(r))<0)throw new Error("Outside valid range.");return r+1},to:function(){return a(this.decimalValue-1)}},impliedProbability:{from:function(r){if((r="string"==typeof r&&"%"==r.slice(-1)?parseFloat(r)/100:parseFloat(r))<=0||r>=1)throw new Error("Outside valid range");return 1/r},to:function(r){if(r.percentage){var e=a(100/this.decimalValue);return null!==r.precision&&(e=t("round",e,-r.precision)),e.toString()+"%"}return a(1/this.decimalValue)}},fractional:{from:function(r){var e,a=r.toString().split("/");if(r=parseFloat(a[0]),2===a.length)e=parseFloat(a[1]);else{if(1!==a.length)throw new Error("Invalid fraction");e=1}if(0===r||0===e||r/e<=0)throw new Error("Outside valid range");return 1+r/e},to:function(r){return function(r,e){for(var a,t=[0,1],i=[1,0],o=function(r){var e=null,a=r.toString().indexOf("E");-1==a&&(a=r.toString().indexOf("e"));var t=null,i=(e=-1==a?r.toString():r.toString().substring(0,a)).toString().indexOf(".");-1==i?t=e:0===i?t=e.substring(1,e.length):i<e.length&&(t=e.substring(0,i)+e.substring(i+1,e.length));var o=t,s=o.toString().length,n=r,l=n.toString().length;0===n&&(l=0);var d,u=s-l;for(d=u;d>0&&o%2==0;d--)o/=2;for(d=u;d>0&&o%5==0;d--)o/=5;return o}(r),s=r,n=Math.pow(10,-e)/2,l=2;l<1e3;l++){var d=Math.floor(s);if(t[l]=d*t[l-1]+t[l-2],Math.abs(t[l])>o)return;if(i[l]=d*i[l-1]+i[l-2],a=t[l]/i[l],Math.abs(a-r)<n||NaN==a)return t[l].toString()+"/"+i[l].toString();s=1/(s-d)}}(this.decimalValue-1,r.precision||12)}},malay:{from:function(r){if((r=parseFloat(r))<=-1||r>1)throw new Error("Outside valid range.");return r<0&&(r=-1/r),r+1},to:function(){return this.decimalValue<=2?a(this.decimalValue-1):a(-1/(this.decimalValue-1))}},indonesian:{from:function(r){if(0===(r=parseFloat(r)))throw new Error("Outside valid range.");return r>=1?r+1:-1/r+1},to:function(){return this.decimalValue<2?a(-1/(this.decimalValue-1)):a(this.decimalValue-1)}}},n=((o=function(r){if("number"!=typeof r||isNaN(r))throw new Error("Invalid odds");this.decimalValue=a(r)}).prototype=(i=function(){throw new Error("This constructor is private, please use the from* functions")}).prototype,i.from=function(r,e){if(!s.hasOwnProperty(r))throw new Error("Unknown format "+r+".");var a=s[r].from(e);return new o(a)},i);n.prototype.to=function(r,e){if(!s.hasOwnProperty(r))throw new Error("Unknown format "+r+".");e=Object.assign({precision:null,percentage:!1},e);var a=s[r].to.call(this,e);return"number"==typeof a&&null!==e.precision&&(a=t("round",a,-e.precision)),a};var l,d=n.from,u=function(r,e,a){var t=r.find((function(r){return Number(r.sportId)===Number(e)}));if(t){if(""==t.primaryBookmaker)return a;var i=[];return t.primaryBookmaker&&i.push(t.primaryBookmaker),t.secondaryBookmaker&&i.push(t.secondaryBookmaker),t.tertiaryBookmaker&&i.push(t.tertiaryBookmaker),i}return a},c=function(r,e,a,t,i){var o=e.some((function(e){var t=r.get(e);return!!t&&(0===t.homeOdds||0===t.awayOdds||!a&&0===t.drawOdds||1===t.homeOdds||1===t.awayOdds||!a&&1===t.drawOdds)}));if(1==e.length){if(o)return[{homeOdds:0,awayOdds:0,drawOdds:0}];var s=e[0],n=r.get(s);return[{homeOdds:n.homeOdds,awayOdds:n.awayOdds,drawOdds:a?0:n.drawOdds}]}if(o)return[{homeOdds:0,awayOdds:0,drawOdds:0}];var l=r.get(e[0]),u=l.homeOdds,c=l.awayOdds,p=l.drawOdds;if(e.slice(1).some((function(e){var o=r[e];if(o){var s=o.homeOdds,n=o.awayOdds,l=o.drawOdds,m=d("decimal",u).to("impliedProbability"),b=d("decimal",c).to("impliedProbability"),f=a?0:d("decimal",p).to("impliedProbability"),v=d("decimal",s).to("impliedProbability"),g=d("decimal",n).to("impliedProbability"),h=a?0:d("decimal",l).to("impliedProbability"),A=w(m,v),D=w(b,g),y=a?0:w(f,h);if(A>t&&m>i&&v>i||D>t&&b>i&&g>i||!a&&y>t&&f>i&&h>i)return!0}return!1})))return console.log("Returning zero odds due to percentage difference"),[{homeOdds:0,awayOdds:0,drawOdds:0}];var m=[];return e.forEach((function(e){return m.push(r.get(e))})),null!=m[0]?m.map((function(r){return{homeOdds:r.homeOdds,awayOdds:r.awayOdds,drawOdds:a?0:r.drawOdds}})):(console.log("Returning zero odds cause no matching bookmakers have been found"),[{homeOdds:0,awayOdds:0,drawOdds:0}])},w=function(r,e){var a=Math.abs(r-e)/r*100;return console.log("% diff: "+a),a},p="Soccer",m="Football",b="Basketball",f="Baseball",v="Hockey",g="Fighting",h="Tennis",A="eSports",D="Rugby",y="Volleyball",O="Handball",C="Cricket",N="Motosport",S="Golf",L=153,_=156,k=158,P=9977,T=9983,V=10138,B=100021,E=100121,F=[P,T,V,L,_,k,15312,15313,15314,15315,15316,15317,15318,15622,15623,15624,15625,15626,15627,15628,15632,15633,15634,15635,15636,15637,15638,15641,15642,15643,15644,15645,15646,15647,15648],j=((l={})[1]={sport:m,id:1,isDrawAvailable:!1},l[2]={sport:m,id:2,isDrawAvailable:!1},l[3]={sport:f,id:3,isDrawAvailable:!1},l[4]={sport:b,id:4,isDrawAvailable:!1},l[5]={sport:b,id:5,isDrawAvailable:!1},l[6]={sport:v,id:6,isDrawAvailable:!1},l[7]={sport:g,id:7,isDrawAvailable:!1},l[8]={sport:b,id:8,isDrawAvailable:!1},l[10]={sport:p,id:10,isDrawAvailable:!0},l[11]={sport:p,id:11,isDrawAvailable:!0},l[12]={sport:p,id:12,isDrawAvailable:!0},l[13]={sport:p,id:13,isDrawAvailable:!0},l[14]={sport:p,id:14,isDrawAvailable:!0},l[15]={sport:p,id:15,isDrawAvailable:!0},l[16]={sport:p,id:16,isDrawAvailable:!0},l[17]={sport:p,id:17,isDrawAvailable:!0},l[18]={sport:p,id:18,isDrawAvailable:!0},l[19]={sport:p,id:19,isDrawAvailable:!0},l[20]={sport:C,id:20,isDrawAvailable:!1},l[21]={sport:C,id:21,isDrawAvailable:!1},l[33]={sport:v,id:33,isDrawAvailable:!0},l[44]={sport:p,id:44,isDrawAvailable:!0},l[45]={sport:p,id:45,isDrawAvailable:!0},l[50]={sport:p,id:50,isDrawAvailable:!0},l[57]={sport:p,id:57,isDrawAvailable:!0},l[61]={sport:p,id:61,isDrawAvailable:!0},l[65]={sport:p,id:65,isDrawAvailable:!0},l[66]={sport:p,id:66,isDrawAvailable:!0},l[76]={sport:p,id:76,isDrawAvailable:!0},l[132]={sport:p,id:132,isDrawAvailable:!0},l[134]={sport:p,id:134,isDrawAvailable:!0},l[138]={sport:p,id:138,isDrawAvailable:!0},l[141]={sport:p,id:141,isDrawAvailable:!0},l[153]={sport:h,id:L,isDrawAvailable:!1},l[156]={sport:h,id:_,isDrawAvailable:!1},l[158]={sport:h,id:k,isDrawAvailable:!1},l[209]={sport:p,id:209,isDrawAvailable:!0},l[268]={sport:p,id:268,isDrawAvailable:!0},l[288]={sport:p,id:288,isDrawAvailable:!0},l[296]={sport:p,id:296,isDrawAvailable:!0},l[380]={sport:O,id:380,isDrawAvailable:!0},l[381]={sport:O,id:381,isDrawAvailable:!0},l[399]={sport:b,id:399,isDrawAvailable:!1},l[406]={sport:b,id:406,isDrawAvailable:!1},l[407]={sport:b,id:407,isDrawAvailable:!1},l[409]={sport:b,id:409,isDrawAvailable:!1},l[445]={sport:N,id:445,isDrawAvailable:!1},l[453]={sport:y,id:453,isDrawAvailable:!1},l[454]={sport:y,id:454,isDrawAvailable:!1},l[8910]={sport:"TableTennis",id:8910,isDrawAvailable:!1},l[497]={sport:N,id:497,isDrawAvailable:!1},l[536]={sport:p,id:536,isDrawAvailable:!0},l[8881]={sport:"Waterpolo",id:8881,isDrawAvailable:!0},l[8893]={sport:y,id:8893,isDrawAvailable:!1},l[8894]={sport:y,id:8894,isDrawAvailable:!1},l[9196]={sport:g,id:9196,isDrawAvailable:!1},l[9578]={sport:D,id:9578,isDrawAvailable:!0},l[9588]={sport:D,id:9588,isDrawAvailable:!0},l[9698]={sport:v,id:9698,isDrawAvailable:!0},l[9699]={sport:v,id:9699,isDrawAvailable:!0},l[9806]={sport:p,id:9806,isDrawAvailable:!0},l[9821]={sport:p,id:9821,isDrawAvailable:!0},l[9977]={sport:A,id:P,isDrawAvailable:!1},l[9983]={sport:A,id:T,isDrawAvailable:!1},l[10071]={sport:b,id:10071,isDrawAvailable:!1},l[10072]={sport:b,id:10072,isDrawAvailable:!1},l[10502]={sport:b,id:10502,isDrawAvailable:!1},l[10138]={sport:A,id:V,isDrawAvailable:!1},l[10199]={sport:p,id:10199,isDrawAvailable:!0},l[10216]={sport:p,id:10216,isDrawAvailable:!0},l[10595]={sport:g,id:10595,isDrawAvailable:!1},l[10611]={sport:p,id:10611,isDrawAvailable:!0},l[10613]={sport:p,id:10613,isDrawAvailable:!0},l[10615]={sport:p,id:10615,isDrawAvailable:!0},l[2e4]={sport:"Politics",id:2e4,isDrawAvailable:!1},l[20001]={sport:p,id:20001,isDrawAvailable:!0},l[20002]={sport:p,id:20002,isDrawAvailable:!0},l[20011]={sport:p,id:20011,isDrawAvailable:!0},l[100021]={sport:S,id:B,isDrawAvailable:!1},l[100121]={sport:S,id:E,isDrawAvailable:!1},l[230]={sport:p,id:230,isDrawAvailable:!0},l),M=function(r){var e=j[r];return e?e.sport:""},x=function(r,e,a){var t=r.score_home_total,i=r.score_away_total,o=r.clock,s=r.period,n=r.status,l=r.home_team,d=r.away_team,u=parseInt(s),c=M(e);return"completed"==n.toLowerCase()?{allow:!1,message:"Blocking game ".concat(l," - ").concat(d," because it is no longer live.")}:c===b?G(l,d,u,a.get(b)):c===v?G(l,d,u,a.get(v)):c===f?G(l,d,u,a.get(f)):c===p?I(l,d,o,s,a.get(p)):c===h?W(r,l,d,s,t,i,e,c):c===y?W(r,l,d,u,t,i,e,c):{allow:!0,message:"The sport ".concat(e," does not have constraint")}},G=function(r,e,a,t){return!Number.isNaN(a)&&a>=t?{allow:!1,message:"Blocking game ".concat(r," - ").concat(e," due to period: ").concat(a,". period")}:{allow:!0,message:""}},I=function(r,e,a,t,i){var o=Number(a);return!Number.isNaN(o)&&o>=i||Number.isNaN(o)&&"HALF"!=t?{allow:!1,message:"Blocking game ".concat(r," - ").concat(e," due to clock: ").concat(a,"min")}:{allow:!0,message:""}},W=function(r,e,a,t,i,o,s,n){var l=Number(t),d=U(l,r),u="atp"==r.league.toLowerCase(),c={home:i,away:o};return n==y?R(e,a,d,c,2,5==l?10:20):s.toString().startsWith(L)&&u?R(e,a,d,c,2,5):s.toString().startsWith(L)&&!u||s.toString().startsWith(_)||s.toString().startsWith(k)?R(e,a,d,c,1,5):{allow:!0,message:"The sport ".concat(s," does not have result constraint")}},U=function(r,e){var a=0,t=0;switch(r){case 1:a=Number(e.score_home_period_1),t=Number(e.score_away_period_1);break;case 2:a=Number(e.score_home_period_2),t=Number(e.score_away_period_2);break;case 3:a=Number(e.score_home_period_3),t=Number(e.score_away_period_3);break;case 4:a=Number(e.score_home_period_4),t=Number(e.score_away_period_4);break;case 5:a=Number(e.score_home_period_5),t=Number(e.score_away_period_5)}return{home:a,away:t}},R=function(r,e,a,t,i,o){return Number(t.home)!=i&&Number(t.away)!=i||!(Number(t.home)==i&&a.home>=o||Number(t.away)==i&&a.away>=o)?{allow:!0,message:"",currentHomeGameScore:a.home,currentAwayGameScore:a.away}:{allow:!1,message:"Blocking game ".concat(r," - ").concat(e," due to current result: ").concat(t.home," - ").concat(t.away," (").concat(a.home," - ").concat(a.away,")")}},H=function(r,e,a,t,i,o){var s,n;if(F.includes(r)?(s=t.toLowerCase()==e.toLowerCase()||t.toLowerCase()==a.toLowerCase(),n=i.toLowerCase()==e.toLowerCase()||i.toLowerCase()==a.toLowerCase()):(s=t.toLowerCase()==e.toLowerCase(),n=i.toLowerCase()==a.toLowerCase()),!0!==s){var l=o.get(t.toLowerCase()),d=o.get(e.toLowerCase()),u=o.get(a.toLowerCase());if([l,d].some((function(r){return null==r})))return!1;s=F.includes(r)?l==d||l==u:l==d}if(!0!==n){var c=o.get(i.toLowerCase());if(d=o.get(e.toLowerCase()),[c,u=o.get(a.toLowerCase())].some((function(r){return null==r})))return!1;n=F.includes(r)&&c==d||c==u}return s&&n},z=function(r,e,a,t){var i;if(M(a)==h){var o=e.getTime(),s=r.getTime();i=Math.abs(s-o)<=Number(60*t*1e3)}else i=e.toUTCString()==r.toUTCString();return i},K=function(r,e,a,t,i){var o=new Map;return r.forEach((function(r){var s,n,l=e.odds.filter((function(e){return e.sports_book_name.toLowerCase()==r.toLowerCase()})),d=t.get(a.homeTeam.toLowerCase()),u=t.get(a.awayTeam.toLowerCase()),c=0;null!=(s=null==d?l.find((function(r){var e=t.get(r.name.toLowerCase());return null==e?r.name.toLowerCase()==a.homeTeam.toLowerCase():e==a.homeTeam.toLowerCase()})):l.find((function(r){var e=t.get(r.name.toLowerCase());return null==e?r.name.toLowerCase()==d:e==d})))&&(c=s.price);var w=0;null!=(n=null==u?l.find((function(r){var e=t.get(r.name.toLowerCase());return null==e?r.name.toLowerCase()==a.awayTeam.toLowerCase():e==a.awayTeam.toLowerCase()})):l.find((function(r){var e=t.get(r.name.toLowerCase());return null==e?r.name.toLowerCase()==u:e==u})))&&(w=n.price);var p=0;if(i){var m=l.find((function(r){return"draw"==r.name.toLowerCase()}));null!=m&&(p=m.price)}o.set(r.toLowerCase(),{homeOdds:c,awayOdds:w,drawOdds:p})})),o},q=function(r,e,a){if(r.some((function(r){return 0===r})))return r;var t=r.reduce((function(r,e){return r+e}),0);if(t<=1)return Array(r.length).fill(0);if(0===a){if(!(e>100*(t-1)))return r;a=e}var i=1+a/100,o=i/t,s=r.map((function(r){return r*o}));if(s.some((function(r){return r>=1})))return Array(r.length).fill(0);var n=s.reduce((function(r,e){return r+e}),0);if(n<1)return Array(r.length).fill(0);var l=i/n;return s.map((function(r){return r*l}))},J=function(r,e,a,t){var i=r.find((function(r){return Number(r.typeId)===Number(a)&&Number(r.sportId)===Number(e)}));return i?{minSpread:i.minSpread?Number(i.minSpread):t,targetSpread:i.targetSpread?Number(i.targetSpread):0}:{minSpread:t,targetSpread:0}};return e})()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "overtime-live-trading-utils",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "",
5
5
  "main": "main.js",
6
6
  "scripts": {
@@ -374,6 +374,26 @@ export const LeagueMap: Record<number, any> = {
374
374
  id: League.UEFA_CONFERENCE_LEAGUE_QUALIFICATION,
375
375
  isDrawAvailable: true,
376
376
  },
377
+ [League.US_ELECTION]: {
378
+ sport: Sport.POLITICS,
379
+ id: League.US_ELECTION,
380
+ isDrawAvailable: false,
381
+ },
382
+ [League.UEFA_SUPER_CUP]: {
383
+ sport: Sport.SOCCER,
384
+ id: League.UEFA_SUPER_CUP,
385
+ isDrawAvailable: true,
386
+ },
387
+ [League.BRAZIL_CUP]: {
388
+ sport: Sport.SOCCER,
389
+ id: League.BRAZIL_CUP,
390
+ isDrawAvailable: true,
391
+ },
392
+ [League.ENGLAND_CHAMPIONSHIP]: {
393
+ sport: Sport.SOCCER,
394
+ id: League.ENGLAND_CHAMPIONSHIP,
395
+ isDrawAvailable: true,
396
+ },
377
397
  [League.GOLF_H2H]: {
378
398
  sport: Sport.GOLF,
379
399
  id: League.GOLF_H2H,
@@ -15,6 +15,7 @@ export const Sport = {
15
15
  MOTOSPORT: 'Motosport',
16
16
  GOLF: 'Golf',
17
17
  TABLE_TENNIS: 'TableTennis',
18
+ POLITICS: 'Politics',
18
19
  EMPTY: '',
19
20
  };
20
21
 
@@ -94,6 +95,10 @@ export const League = {
94
95
  UEFA_CHAMPIONS_LEAGUE_QUALIFICATION: 10611,
95
96
  UEFA_EUROPA_LEAGUE_QUALIFICATION: 10613,
96
97
  UEFA_CONFERENCE_LEAGUE_QUALIFICATION: 10615,
98
+ US_ELECTION: 20000,
99
+ UEFA_SUPER_CUP: 20001,
100
+ BRAZIL_CUP: 20002,
101
+ ENGLAND_CHAMPIONSHIP: 20011,
97
102
  GOLF_H2H: 100021,
98
103
  GOLF_WINNER: 100121,
99
104
  TENNIS_GRAND_SLAM_LIVE_MAPPING_V2_1: 15312,
@@ -190,6 +190,10 @@ export const fetchResultInCurrentSet = (currentSet: number, opticOddsScoresApiRe
190
190
  let currentHomeGameScore = 0;
191
191
  let currentAwayGameScore = 0;
192
192
  switch (currentSet) {
193
+ case 1:
194
+ currentHomeGameScore = Number(opticOddsScoresApiResponse.score_home_period_1);
195
+ currentAwayGameScore = Number(opticOddsScoresApiResponse.score_away_period_1);
196
+ break;
193
197
  case 2:
194
198
  currentHomeGameScore = Number(opticOddsScoresApiResponse.score_home_period_2);
195
199
  currentAwayGameScore = Number(opticOddsScoresApiResponse.score_away_period_2);