overtime-live-trading-utils 0.0.102 → 0.0.103

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 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[152]={sport:h,id:152,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})()));
1
+ !function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.thalesUtils=r():e.thalesUtils=r()}(this,(()=>(()=>{"use strict";var e={d:(r,a)=>{for(var t in a)e.o(a,t)&&!e.o(r,t)&&Object.defineProperty(r,t,{enumerable:!0,get:a[t]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},r={};e.r(r),e.d(r,{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(e,r){if(null==e)throw new TypeError("Cannot convert undefined or null to object");for(var a=Object(e),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(e){return parseFloat(e.toPrecision(12))};function t(e,r,a){return void 0===a||0==+a?Math[e](r):(r=+r,a=+a,isNaN(r)||"number"!=typeof a||a%1!=0?NaN:r<0?-t(e,-r,a):(r=r.toString().split("e"),+((r=(r=Math[e](+(r[0]+"e"+(r[1]?+r[1]-a:-a)))).toString().split("e"))[0]+"e"+(r[1]?+r[1]+a:a))))}var i,o,s={decimal:{from:function(e){if((e=parseFloat(e))<=1)throw new Error("Outside valid range.");return e},to:function(){return this.decimalValue}},moneyline:{from:function(e){return(e=parseFloat(e))>=0?e/100+1:100/-e+1},to:function(){return this.decimalValue>=2?a(100*(this.decimalValue-1)):a(-100/(this.decimalValue-1))}},hongKong:{from:function(e){if((e=parseFloat(e))<0)throw new Error("Outside valid range.");return e+1},to:function(){return a(this.decimalValue-1)}},impliedProbability:{from:function(e){if((e="string"==typeof e&&"%"==e.slice(-1)?parseFloat(e)/100:parseFloat(e))<=0||e>=1)throw new Error("Outside valid range");return 1/e},to:function(e){if(e.percentage){var r=a(100/this.decimalValue);return null!==e.precision&&(r=t("round",r,-e.precision)),r.toString()+"%"}return a(1/this.decimalValue)}},fractional:{from:function(e){var r,a=e.toString().split("/");if(e=parseFloat(a[0]),2===a.length)r=parseFloat(a[1]);else{if(1!==a.length)throw new Error("Invalid fraction");r=1}if(0===e||0===r||e/r<=0)throw new Error("Outside valid range");return 1+e/r},to:function(e){return function(e,r){for(var a,t=[0,1],i=[1,0],o=function(e){var r=null,a=e.toString().indexOf("E");-1==a&&(a=e.toString().indexOf("e"));var t=null,i=(r=-1==a?e.toString():e.toString().substring(0,a)).toString().indexOf(".");-1==i?t=r:0===i?t=r.substring(1,r.length):i<r.length&&(t=r.substring(0,i)+r.substring(i+1,r.length));var o=t,s=o.toString().length,n=e,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}(e),s=e,n=Math.pow(10,-r)/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-e)<n||NaN==a)return t[l].toString()+"/"+i[l].toString();s=1/(s-d)}}(this.decimalValue-1,e.precision||12)}},malay:{from:function(e){if((e=parseFloat(e))<=-1||e>1)throw new Error("Outside valid range.");return e<0&&(e=-1/e),e+1},to:function(){return this.decimalValue<=2?a(this.decimalValue-1):a(-1/(this.decimalValue-1))}},indonesian:{from:function(e){if(0===(e=parseFloat(e)))throw new Error("Outside valid range.");return e>=1?e+1:-1/e+1},to:function(){return this.decimalValue<2?a(-1/(this.decimalValue-1)):a(this.decimalValue-1)}}},n=((o=function(e){if("number"!=typeof e||isNaN(e))throw new Error("Invalid odds");this.decimalValue=a(e)}).prototype=(i=function(){throw new Error("This constructor is private, please use the from* functions")}).prototype,i.from=function(e,r){if(!s.hasOwnProperty(e))throw new Error("Unknown format "+e+".");var a=s[e].from(r);return new o(a)},i);n.prototype.to=function(e,r){if(!s.hasOwnProperty(e))throw new Error("Unknown format "+e+".");r=Object.assign({precision:null,percentage:!1},r);var a=s[e].to.call(this,r);return"number"==typeof a&&null!==r.precision&&(a=t("round",a,-r.precision)),a};var l,d=n.from,u=function(e,r,a){var t=e.find((function(e){return Number(e.sportId)===Number(r)}));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(e,r,a,t,i){var o=r.some((function(r){var t=e.get(r);return!!t&&(0===t.homeOdds||0===t.awayOdds||!a&&0===t.drawOdds||1===t.homeOdds||1===t.awayOdds||!a&&1===t.drawOdds)}));if(1==r.length){if(o)return[{homeOdds:0,awayOdds:0,drawOdds:0}];var s=r[0],n=e.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=e.get(r[0]),u=l.homeOdds,c=l.awayOdds,p=l.drawOdds;if(r.slice(1).some((function(r){var o=e[r];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 r.forEach((function(r){return m.push(e.get(r))})),null!=m[0]?m.map((function(e){return{homeOdds:e.homeOdds,awayOdds:e.awayOdds,drawOdds:a?0:e.drawOdds}})):(console.log("Returning zero odds cause no matching bookmakers have been found"),[{homeOdds:0,awayOdds:0,drawOdds:0}])},w=function(e,r){var a=Math.abs(e-r)/e*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,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: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[152]={sport:h,id:152,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:T,isDrawAvailable:!1},l[9983]={sport:A,id:P,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(e){var r=j[e];return r?r.sport:""},x=function(e,r,a){var t=e.score_home_total,i=e.score_away_total,o=e.clock,s=e.period,n=e.status,l=e.home_team,d=e.away_team,u=parseInt(s),c=M(r);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(e,l,d,s,t,i,r,c):c===y?W(e,l,d,u,t,i,r,c):{allow:!0,message:"The sport ".concat(r," does not have constraint")}},G=function(e,r,a,t){return!Number.isNaN(a)&&a>=t?{allow:!1,message:"Blocking game ".concat(e," - ").concat(r," due to period: ").concat(a,". period")}:{allow:!0,message:""}},I=function(e,r,a,t,i){var o=Number(a);return!Number.isNaN(o)&&o>=i||Number.isNaN(o)&&"HALF"!=t?{allow:!1,message:"Blocking game ".concat(e," - ").concat(r," due to clock: ").concat(a,"min")}:{allow:!0,message:""}},W=function(e,r,a,t,i,o,s,n){var l=Number(t),d=U(l,e),u="atp"==e.league.toLowerCase(),c={home:i,away:o};return n==y?R(r,a,d,c,2,5==l?10:20):s.toString().startsWith(L)&&u?R(r,a,d,c,2,5):s.toString().startsWith(L)&&!u||s.toString().startsWith(_)||s.toString().startsWith(k)?R(r,a,d,c,1,5):{allow:!0,message:"The sport ".concat(s," does not have result constraint")}},U=function(e,r){var a=0,t=0;switch(e){case 1:a=Number(r.score_home_period_1),t=Number(r.score_away_period_1);break;case 2:a=Number(r.score_home_period_2),t=Number(r.score_away_period_2);break;case 3:a=Number(r.score_home_period_3),t=Number(r.score_away_period_3);break;case 4:a=Number(r.score_home_period_4),t=Number(r.score_away_period_4);break;case 5:a=Number(r.score_home_period_5),t=Number(r.score_away_period_5)}return{home:a,away:t}},R=function(e,r,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(e," - ").concat(r," due to current result: ").concat(t.home," - ").concat(t.away," (").concat(a.home," - ").concat(a.away,")")}},H=function(e,r,a,t,i,o){var s,n;if(F.includes(e)?(s=t.toLowerCase()==r.toLowerCase()||t.toLowerCase()==a.toLowerCase(),n=i.toLowerCase()==r.toLowerCase()||i.toLowerCase()==a.toLowerCase()):(s=t.toLowerCase()==r.toLowerCase(),n=i.toLowerCase()==a.toLowerCase()),!0!==s){var l=o.get(t.toLowerCase()),d=o.get(r.toLowerCase()),u=o.get(a.toLowerCase());if([l,d].some((function(e){return null==e})))return!1;s=F.includes(e)?l==d||l==u:l==d}if(!0!==n){var c=o.get(i.toLowerCase());if(d=o.get(r.toLowerCase()),[c,u=o.get(a.toLowerCase())].some((function(e){return null==e})))return!1;n=F.includes(e)&&c==d||c==u}return s&&n},z=function(e,r,a,t,i){var o;if(M(a)==h){var s=r.getTime(),n=e.getTime(),l=Math.abs(n-s);i&&(console.log("opticOddsTimestamp: ",s),console.log("marketTimestamp: ",n),console.log("differenceBetweenDates: ",l),console.log("tennisDifferenceEnvVariable: ",t)),o=l<=Number(60*t*1e3)}else o=r.toUTCString()==e.toUTCString();return o},K=function(e,r,a,t,i){var o=new Map;return e.forEach((function(e){var s,n,l=r.odds.filter((function(r){return r.sports_book_name.toLowerCase()==e.toLowerCase()})),d=t.get(a.homeTeam.toLowerCase()),u=t.get(a.awayTeam.toLowerCase()),c=0;null!=(s=null==d?l.find((function(e){var r=t.get(e.name.toLowerCase());return null==r?e.name.toLowerCase()==a.homeTeam.toLowerCase():r==a.homeTeam.toLowerCase()})):l.find((function(e){var r=t.get(e.name.toLowerCase());return null==r?e.name.toLowerCase()==d:r==d})))&&(c=s.price);var w=0;null!=(n=null==u?l.find((function(e){var r=t.get(e.name.toLowerCase());return null==r?e.name.toLowerCase()==a.awayTeam.toLowerCase():r==a.awayTeam.toLowerCase()})):l.find((function(e){var r=t.get(e.name.toLowerCase());return null==r?e.name.toLowerCase()==u:r==u})))&&(w=n.price);var p=0;if(i){var m=l.find((function(e){return"draw"==e.name.toLowerCase()}));null!=m&&(p=m.price)}o.set(e.toLowerCase(),{homeOdds:c,awayOdds:w,drawOdds:p})})),o},q=function(e,r,a){if(e.some((function(e){return 0===e})))return e;var t=e.reduce((function(e,r){return e+r}),0);if(t<=1)return Array(e.length).fill(0);if(0===a){if(!(r>100*(t-1)))return e;a=r}var i=1+a/100,o=i/t,s=e.map((function(e){return e*o}));if(s.some((function(e){return e>=1})))return Array(e.length).fill(0);var n=s.reduce((function(e,r){return e+r}),0);if(n<1)return Array(e.length).fill(0);var l=i/n;return s.map((function(e){return e*l}))},J=function(e,r,a,t){var i=e.find((function(e){return Number(e.typeId)===Number(a)&&Number(e.sportId)===Number(r)}));return i?{minSpread:i.minSpread?Number(i.minSpread):t,targetSpread:i.targetSpread?Number(i.targetSpread):0}:{minSpread:t,targetSpread:0}};return r})()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "overtime-live-trading-utils",
3
- "version": "0.0.102",
3
+ "version": "0.0.103",
4
4
  "description": "",
5
5
  "main": "main.js",
6
6
  "scripts": {
@@ -66,7 +66,8 @@ export const gamesDatesMatching = (
66
66
  marketMaturityDate: Date,
67
67
  apiStartDate: Date,
68
68
  sportId: number,
69
- tennisDifferenceEnvVariable: number
69
+ tennisDifferenceEnvVariable: number,
70
+ areTeamNamesEqual?: boolean
70
71
  ) => {
71
72
  let datesMatch;
72
73
  const marketSport = getLeagueSport(sportId);
@@ -74,6 +75,12 @@ export const gamesDatesMatching = (
74
75
  const opticOddsTimestamp = apiStartDate.getTime();
75
76
  const marketTimestamp = marketMaturityDate.getTime();
76
77
  const differenceBetweenDates = Math.abs(marketTimestamp - opticOddsTimestamp);
78
+ if (areTeamNamesEqual) {
79
+ console.log('opticOddsTimestamp: ', opticOddsTimestamp);
80
+ console.log('marketTimestamp: ', marketTimestamp);
81
+ console.log('differenceBetweenDates: ', differenceBetweenDates);
82
+ console.log('tennisDifferenceEnvVariable: ', tennisDifferenceEnvVariable);
83
+ }
77
84
  if (differenceBetweenDates <= Number(tennisDifferenceEnvVariable * 60 * 1000)) {
78
85
  datesMatch = true;
79
86
  } else {