ohlcv-indicators 1.0.1 → 1.0.3

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.
@@ -1 +1 @@
1
- var OHLCV_INDICATORS;(()=>{"use strict";var e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};(()=>{e.r(t),e.d(t,{default:()=>S});const n=(e,t,n)=>{const r=e(2/(n+1)),i=t.length,s=[];if(r.isGreaterThan(1))return Array(i);if(r.isEqualTo(1))return[...t];let o=0,l=0;for(;l<i;l++){const e=t[l];if("object"==typeof e){s[l]=e,o=e,l++;break}}if(Array.isArray(r))for(;l<i;l++){const e=t[l];"object"==typeof e&&"object"==typeof r[l]?o=s[l]=r[l].multipliedBy(e).plus(r[l].minus(1).multipliedBy(o)):s[l]=s[l-1]}else{const n=e(1).minus(r);for(;l<i;l++){const e=t[l];o="object"==typeof e?r.multipliedBy(e).plus(n.multipliedBy(o)):s[l-1],s[l]=o}}return s},r=(e,t,n)=>{let r=[],i=e(0),s=[];for(let e=0;e<t.length;e++)s.push(t[e]),i=i.plus(t[e]),s.length>n&&(i=i.minus(s.shift())),e>=n-1?r.push(i.dividedBy(n)):r.push(i.dividedBy(s.length));return r},i=(e,t,n)=>{let r=new Array(t.length).fill(0),i=0;const s=new e(t[0]),o=new e(n[0]);s.isGreaterThan(o)?(i=1,r[0]=1):s.isLessThan(o)?(i=-1,r[0]=-1):(i=0,r[0]=0);for(let s=1;s<t.length;s++){const o=new e(t[s]),l=new e(n[s]),u=new e(t[s-1]),c=new e(n[s-1]);o.isGreaterThan(l)&&u.isLessThanOrEqualTo(c)?(i=1,r[s]=1):o.isLessThan(l)&&u.isGreaterThanOrEqualTo(c)?(i=-1,r[s]=-1):r[s]=1===i?r[s-1]+1:-1===i?r[s-1]-1:0}return r.map((t=>e(t)))},s=(e,t,n)=>{const i=new e(0),s=t.length,o=r(e,t,n),l=new Array(s).fill(i);for(let e=n-1;e<s;e++){let r=i;for(let i=e-n+1;i<=e;i++)r=r.plus(t[i].minus(o[e]).pow(2));l[e]=r.dividedBy(n).sqrt()}return l},o=(e,t,n,r)=>t.slice(r).map(((i,s)=>{const o=t.slice(s,s+r),l=n.slice(s,s+r);return e.maximum(...o).plus(e.minimum(...l)).dividedBy(2)})),l=(e,t,n,r)=>{const i=e.slice(n).map(((e,n)=>n<t.length?e.plus(t[n]).dividedBy(2):null)).filter((e=>null!==e));return i.slice(0,i.length-r+1)},u=(e,t,n,r,i)=>{let s=t.slice(r).map(((i,s)=>{const o=t.slice(s,s+r),l=n.slice(s,s+r);return e.maximum(...o).plus(e.minimum(...l)).dividedBy(2)}));return s.slice(0,s.length-i+1)},c=(e,t)=>e.slice(0,e.length-t);var f=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,a=Math.ceil,h=Math.floor,p="[BigNumber Error] ",g=p+"Number primitive has more than 15 significant digits: ",d=1e14,m=14,w=9007199254740991,v=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],b=1e7,y=1e9;function N(e){var t=0|e;return e>0||e===t?t:t-1}function O(e){for(var t,n,r=1,i=e.length,s=e[0]+"";r<i;){for(t=e[r++]+"",n=m-t.length;n--;t="0"+t);s+=t}for(i=s.length;48===s.charCodeAt(--i););return s.slice(0,i+1||1)}function B(e,t){var n,r,i=e.c,s=t.c,o=e.s,l=t.s,u=e.e,c=t.e;if(!o||!l)return null;if(n=i&&!i[0],r=s&&!s[0],n||r)return n?r?0:-l:o;if(o!=l)return o;if(n=o<0,r=u==c,!i||!s)return r?0:!i^n?1:-1;if(!r)return u>c^n?1:-1;for(l=(u=i.length)<(c=s.length)?u:c,o=0;o<l;o++)if(i[o]!=s[o])return i[o]>s[o]^n?1:-1;return u==c?0:u>c^n?1:-1}function E(e,t,n,r){if(e<t||e>n||e!==h(e))throw Error(p+(r||"Argument")+("number"==typeof e?e<t||e>n?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function A(e){var t=e.c.length-1;return N(e.e/m)==t&&e.c[t]%2!=0}function _(e,t){return(e.length>1?e.charAt(0)+"."+e.slice(1):e)+(t<0?"e":"e+")+t}function C(e,t,n){var r,i;if(t<0){for(i=n+".";++t;i+=n);e=i+e}else if(++t>(r=e.length)){for(i=n,t-=r;--t;i+=n);e+=i}else t<r&&(e=e.slice(0,t)+"."+e.slice(t));return e}const T=function e(t){var n,r,i,s,o,l,u,c,T,S,D=V.prototype={constructor:V,toString:null,valueOf:null},I=new V(1),P=20,M=4,L=-7,R=21,x=-1e7,$=1e7,U=!1,G=1,j=0,k={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},q="0123456789abcdefghijklmnopqrstuvwxyz",F=!0;function V(e,t){var n,s,o,l,u,c,a,p,d=this;if(!(d instanceof V))return new V(e,t);if(null==t){if(e&&!0===e._isBigNumber)return d.s=e.s,void(!e.c||e.e>$?d.c=d.e=null:e.e<x?d.c=[d.e=0]:(d.e=e.e,d.c=e.c.slice()));if((c="number"==typeof e)&&0*e==0){if(d.s=1/e<0?(e=-e,-1):1,e===~~e){for(l=0,u=e;u>=10;u/=10,l++);return void(l>$?d.c=d.e=null:(d.e=l,d.c=[e]))}p=String(e)}else{if(!f.test(p=String(e)))return i(d,p,c);d.s=45==p.charCodeAt(0)?(p=p.slice(1),-1):1}(l=p.indexOf("."))>-1&&(p=p.replace(".","")),(u=p.search(/e/i))>0?(l<0&&(l=u),l+=+p.slice(u+1),p=p.substring(0,u)):l<0&&(l=p.length)}else{if(E(t,2,q.length,"Base"),10==t&&F)return X(d=new V(e),P+d.e+1,M);if(p=String(e),c="number"==typeof e){if(0*e!=0)return i(d,p,c,t);if(d.s=1/e<0?(p=p.slice(1),-1):1,V.DEBUG&&p.replace(/^0\.0*|\./,"").length>15)throw Error(g+e)}else d.s=45===p.charCodeAt(0)?(p=p.slice(1),-1):1;for(n=q.slice(0,t),l=u=0,a=p.length;u<a;u++)if(n.indexOf(s=p.charAt(u))<0){if("."==s){if(u>l){l=a;continue}}else if(!o&&(p==p.toUpperCase()&&(p=p.toLowerCase())||p==p.toLowerCase()&&(p=p.toUpperCase()))){o=!0,u=-1,l=0;continue}return i(d,String(e),c,t)}c=!1,(l=(p=r(p,t,10,d.s)).indexOf("."))>-1?p=p.replace(".",""):l=p.length}for(u=0;48===p.charCodeAt(u);u++);for(a=p.length;48===p.charCodeAt(--a););if(p=p.slice(u,++a)){if(a-=u,c&&V.DEBUG&&a>15&&(e>w||e!==h(e)))throw Error(g+d.s*e);if((l=l-u-1)>$)d.c=d.e=null;else if(l<x)d.c=[d.e=0];else{if(d.e=l,d.c=[],u=(l+1)%m,l<0&&(u+=m),u<a){for(u&&d.c.push(+p.slice(0,u)),a-=m;u<a;)d.c.push(+p.slice(u,u+=m));u=m-(p=p.slice(u)).length}else u-=a;for(;u--;p+="0");d.c.push(+p)}}else d.c=[d.e=0]}function H(e,t,n,r){var i,s,o,l,u;if(null==n?n=M:E(n,0,8),!e.c)return e.toString();if(i=e.c[0],o=e.e,null==t)u=O(e.c),u=1==r||2==r&&(o<=L||o>=R)?_(u,o):C(u,o,"0");else if(s=(e=X(new V(e),t,n)).e,l=(u=O(e.c)).length,1==r||2==r&&(t<=s||s<=L)){for(;l<t;u+="0",l++);u=_(u,s)}else if(t-=o,u=C(u,s,"0"),s+1>l){if(--t>0)for(u+=".";t--;u+="0");}else if((t+=s-l)>0)for(s+1==l&&(u+=".");t--;u+="0");return e.s<0&&i?"-"+u:u}function z(e,t){for(var n,r,i=1,s=new V(e[0]);i<e.length;i++)(!(r=new V(e[i])).s||(n=B(s,r))===t||0===n&&s.s===t)&&(s=r);return s}function W(e,t,n){for(var r=1,i=t.length;!t[--i];t.pop());for(i=t[0];i>=10;i/=10,r++);return(n=r+n*m-1)>$?e.c=e.e=null:n<x?e.c=[e.e=0]:(e.e=n,e.c=t),e}function X(e,t,n,r){var i,s,o,l,u,c,f,p=e.c,g=v;if(p){e:{for(i=1,l=p[0];l>=10;l/=10,i++);if((s=t-i)<0)s+=m,o=t,u=p[c=0],f=h(u/g[i-o-1]%10);else if((c=a((s+1)/m))>=p.length){if(!r)break e;for(;p.length<=c;p.push(0));u=f=0,i=1,o=(s%=m)-m+1}else{for(u=l=p[c],i=1;l>=10;l/=10,i++);f=(o=(s%=m)-m+i)<0?0:h(u/g[i-o-1]%10)}if(r=r||t<0||null!=p[c+1]||(o<0?u:u%g[i-o-1]),r=n<4?(f||r)&&(0==n||n==(e.s<0?3:2)):f>5||5==f&&(4==n||r||6==n&&(s>0?o>0?u/g[i-o]:0:p[c-1])%10&1||n==(e.s<0?8:7)),t<1||!p[0])return p.length=0,r?(t-=e.e+1,p[0]=g[(m-t%m)%m],e.e=-t||0):p[0]=e.e=0,e;if(0==s?(p.length=c,l=1,c--):(p.length=c+1,l=g[m-s],p[c]=o>0?h(u/g[i-o]%g[o])*l:0),r)for(;;){if(0==c){for(s=1,o=p[0];o>=10;o/=10,s++);for(o=p[0]+=l,l=1;o>=10;o/=10,l++);s!=l&&(e.e++,p[0]==d&&(p[0]=1));break}if(p[c]+=l,p[c]!=d)break;p[c--]=0,l=1}for(s=p.length;0===p[--s];p.pop());}e.e>$?e.c=e.e=null:e.e<x&&(e.c=[e.e=0])}return e}function Y(e){var t,n=e.e;return null===n?e.toString():(t=O(e.c),t=n<=L||n>=R?_(t,n):C(t,n,"0"),e.s<0?"-"+t:t)}return V.clone=e,V.ROUND_UP=0,V.ROUND_DOWN=1,V.ROUND_CEIL=2,V.ROUND_FLOOR=3,V.ROUND_HALF_UP=4,V.ROUND_HALF_DOWN=5,V.ROUND_HALF_EVEN=6,V.ROUND_HALF_CEIL=7,V.ROUND_HALF_FLOOR=8,V.EUCLID=9,V.config=V.set=function(e){var t,n;if(null!=e){if("object"!=typeof e)throw Error(p+"Object expected: "+e);if(e.hasOwnProperty(t="DECIMAL_PLACES")&&(E(n=e[t],0,y,t),P=n),e.hasOwnProperty(t="ROUNDING_MODE")&&(E(n=e[t],0,8,t),M=n),e.hasOwnProperty(t="EXPONENTIAL_AT")&&((n=e[t])&&n.pop?(E(n[0],-y,0,t),E(n[1],0,y,t),L=n[0],R=n[1]):(E(n,-y,y,t),L=-(R=n<0?-n:n))),e.hasOwnProperty(t="RANGE"))if((n=e[t])&&n.pop)E(n[0],-y,-1,t),E(n[1],1,y,t),x=n[0],$=n[1];else{if(E(n,-y,y,t),!n)throw Error(p+t+" cannot be zero: "+n);x=-($=n<0?-n:n)}if(e.hasOwnProperty(t="CRYPTO")){if((n=e[t])!==!!n)throw Error(p+t+" not true or false: "+n);if(n){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw U=!n,Error(p+"crypto unavailable");U=n}else U=n}if(e.hasOwnProperty(t="MODULO_MODE")&&(E(n=e[t],0,9,t),G=n),e.hasOwnProperty(t="POW_PRECISION")&&(E(n=e[t],0,y,t),j=n),e.hasOwnProperty(t="FORMAT")){if("object"!=typeof(n=e[t]))throw Error(p+t+" not an object: "+n);k=n}if(e.hasOwnProperty(t="ALPHABET")){if("string"!=typeof(n=e[t])||/^.?$|[+\-.\s]|(.).*\1/.test(n))throw Error(p+t+" invalid: "+n);F="0123456789"==n.slice(0,10),q=n}}return{DECIMAL_PLACES:P,ROUNDING_MODE:M,EXPONENTIAL_AT:[L,R],RANGE:[x,$],CRYPTO:U,MODULO_MODE:G,POW_PRECISION:j,FORMAT:k,ALPHABET:q}},V.isBigNumber=function(e){if(!e||!0!==e._isBigNumber)return!1;if(!V.DEBUG)return!0;var t,n,r=e.c,i=e.e,s=e.s;e:if("[object Array]"=={}.toString.call(r)){if((1===s||-1===s)&&i>=-y&&i<=y&&i===h(i)){if(0===r[0]){if(0===i&&1===r.length)return!0;break e}if((t=(i+1)%m)<1&&(t+=m),String(r[0]).length==t){for(t=0;t<r.length;t++)if((n=r[t])<0||n>=d||n!==h(n))break e;if(0!==n)return!0}}}else if(null===r&&null===i&&(null===s||1===s||-1===s))return!0;throw Error(p+"Invalid BigNumber: "+e)},V.maximum=V.max=function(){return z(arguments,-1)},V.minimum=V.min=function(){return z(arguments,1)},V.random=(s=9007199254740992,o=Math.random()*s&2097151?function(){return h(Math.random()*s)}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(e){var t,n,r,i,s,l=0,u=[],c=new V(I);if(null==e?e=P:E(e,0,y),i=a(e/m),U)if(crypto.getRandomValues){for(t=crypto.getRandomValues(new Uint32Array(i*=2));l<i;)(s=131072*t[l]+(t[l+1]>>>11))>=9e15?(n=crypto.getRandomValues(new Uint32Array(2)),t[l]=n[0],t[l+1]=n[1]):(u.push(s%1e14),l+=2);l=i/2}else{if(!crypto.randomBytes)throw U=!1,Error(p+"crypto unavailable");for(t=crypto.randomBytes(i*=7);l<i;)(s=281474976710656*(31&t[l])+1099511627776*t[l+1]+4294967296*t[l+2]+16777216*t[l+3]+(t[l+4]<<16)+(t[l+5]<<8)+t[l+6])>=9e15?crypto.randomBytes(7).copy(t,l):(u.push(s%1e14),l+=7);l=i/7}if(!U)for(;l<i;)(s=o())<9e15&&(u[l++]=s%1e14);for(i=u[--l],e%=m,i&&e&&(s=v[m-e],u[l]=h(i/s)*s);0===u[l];u.pop(),l--);if(l<0)u=[r=0];else{for(r=-1;0===u[0];u.splice(0,1),r-=m);for(l=1,s=u[0];s>=10;s/=10,l++);l<m&&(r-=m-l)}return c.e=r,c.c=u,c}),V.sum=function(){for(var e=1,t=arguments,n=new V(t[0]);e<t.length;)n=n.plus(t[e++]);return n},r=function(){var e="0123456789";function t(e,t,n,r){for(var i,s,o=[0],l=0,u=e.length;l<u;){for(s=o.length;s--;o[s]*=t);for(o[0]+=r.indexOf(e.charAt(l++)),i=0;i<o.length;i++)o[i]>n-1&&(null==o[i+1]&&(o[i+1]=0),o[i+1]+=o[i]/n|0,o[i]%=n)}return o.reverse()}return function(r,i,s,o,l){var u,c,f,a,h,p,g,d,m=r.indexOf("."),w=P,v=M;for(m>=0&&(a=j,j=0,r=r.replace(".",""),p=(d=new V(i)).pow(r.length-m),j=a,d.c=t(C(O(p.c),p.e,"0"),10,s,e),d.e=d.c.length),f=a=(g=t(r,i,s,l?(u=q,e):(u=e,q))).length;0==g[--a];g.pop());if(!g[0])return u.charAt(0);if(m<0?--f:(p.c=g,p.e=f,p.s=o,g=(p=n(p,d,w,v,s)).c,h=p.r,f=p.e),m=g[c=f+w+1],a=s/2,h=h||c<0||null!=g[c+1],h=v<4?(null!=m||h)&&(0==v||v==(p.s<0?3:2)):m>a||m==a&&(4==v||h||6==v&&1&g[c-1]||v==(p.s<0?8:7)),c<1||!g[0])r=h?C(u.charAt(1),-w,u.charAt(0)):u.charAt(0);else{if(g.length=c,h)for(--s;++g[--c]>s;)g[c]=0,c||(++f,g=[1].concat(g));for(a=g.length;!g[--a];);for(m=0,r="";m<=a;r+=u.charAt(g[m++]));r=C(r,f,u.charAt(0))}return r}}(),n=function(){function e(e,t,n){var r,i,s,o,l=0,u=e.length,c=t%b,f=t/b|0;for(e=e.slice();u--;)l=((i=c*(s=e[u]%b)+(r=f*s+(o=e[u]/b|0)*c)%b*b+l)/n|0)+(r/b|0)+f*o,e[u]=i%n;return l&&(e=[l].concat(e)),e}function t(e,t,n,r){var i,s;if(n!=r)s=n>r?1:-1;else for(i=s=0;i<n;i++)if(e[i]!=t[i]){s=e[i]>t[i]?1:-1;break}return s}function n(e,t,n,r){for(var i=0;n--;)e[n]-=i,i=e[n]<t[n]?1:0,e[n]=i*r+e[n]-t[n];for(;!e[0]&&e.length>1;e.splice(0,1));}return function(r,i,s,o,l){var u,c,f,a,p,g,w,v,b,y,O,B,E,A,_,C,T,S=r.s==i.s?1:-1,D=r.c,I=i.c;if(!(D&&D[0]&&I&&I[0]))return new V(r.s&&i.s&&(D?!I||D[0]!=I[0]:I)?D&&0==D[0]||!I?0*S:S/0:NaN);for(b=(v=new V(S)).c=[],S=s+(c=r.e-i.e)+1,l||(l=d,c=N(r.e/m)-N(i.e/m),S=S/m|0),f=0;I[f]==(D[f]||0);f++);if(I[f]>(D[f]||0)&&c--,S<0)b.push(1),a=!0;else{for(A=D.length,C=I.length,f=0,S+=2,(p=h(l/(I[0]+1)))>1&&(I=e(I,p,l),D=e(D,p,l),C=I.length,A=D.length),E=C,O=(y=D.slice(0,C)).length;O<C;y[O++]=0);T=I.slice(),T=[0].concat(T),_=I[0],I[1]>=l/2&&_++;do{if(p=0,(u=t(I,y,C,O))<0){if(B=y[0],C!=O&&(B=B*l+(y[1]||0)),(p=h(B/_))>1)for(p>=l&&(p=l-1),w=(g=e(I,p,l)).length,O=y.length;1==t(g,y,w,O);)p--,n(g,C<w?T:I,w,l),w=g.length,u=1;else 0==p&&(u=p=1),w=(g=I.slice()).length;if(w<O&&(g=[0].concat(g)),n(y,g,O,l),O=y.length,-1==u)for(;t(I,y,C,O)<1;)p++,n(y,C<O?T:I,O,l),O=y.length}else 0===u&&(p++,y=[0]);b[f++]=p,y[0]?y[O++]=D[E]||0:(y=[D[E]],O=1)}while((E++<A||null!=y[0])&&S--);a=null!=y[0],b[0]||b.splice(0,1)}if(l==d){for(f=1,S=b[0];S>=10;S/=10,f++);X(v,s+(v.e=f+c*m-1)+1,o,a)}else v.e=c,v.r=+a;return v}}(),l=/^(-?)0([xbo])(?=\w[\w.]*$)/i,u=/^([^.]+)\.$/,c=/^\.([^.]+)$/,T=/^-?(Infinity|NaN)$/,S=/^\s*\+(?=[\w.])|^\s+|\s+$/g,i=function(e,t,n,r){var i,s=n?t:t.replace(S,"");if(T.test(s))e.s=isNaN(s)?null:s<0?-1:1;else{if(!n&&(s=s.replace(l,(function(e,t,n){return i="x"==(n=n.toLowerCase())?16:"b"==n?2:8,r&&r!=i?e:t})),r&&(i=r,s=s.replace(u,"$1").replace(c,"0.$1")),t!=s))return new V(s,i);if(V.DEBUG)throw Error(p+"Not a"+(r?" base "+r:"")+" number: "+t);e.s=null}e.c=e.e=null},D.absoluteValue=D.abs=function(){var e=new V(this);return e.s<0&&(e.s=1),e},D.comparedTo=function(e,t){return B(this,new V(e,t))},D.decimalPlaces=D.dp=function(e,t){var n,r,i,s=this;if(null!=e)return E(e,0,y),null==t?t=M:E(t,0,8),X(new V(s),e+s.e+1,t);if(!(n=s.c))return null;if(r=((i=n.length-1)-N(this.e/m))*m,i=n[i])for(;i%10==0;i/=10,r--);return r<0&&(r=0),r},D.dividedBy=D.div=function(e,t){return n(this,new V(e,t),P,M)},D.dividedToIntegerBy=D.idiv=function(e,t){return n(this,new V(e,t),0,1)},D.exponentiatedBy=D.pow=function(e,t){var n,r,i,s,o,l,u,c,f=this;if((e=new V(e)).c&&!e.isInteger())throw Error(p+"Exponent not an integer: "+Y(e));if(null!=t&&(t=new V(t)),o=e.e>14,!f.c||!f.c[0]||1==f.c[0]&&!f.e&&1==f.c.length||!e.c||!e.c[0])return c=new V(Math.pow(+Y(f),o?e.s*(2-A(e)):+Y(e))),t?c.mod(t):c;if(l=e.s<0,t){if(t.c?!t.c[0]:!t.s)return new V(NaN);(r=!l&&f.isInteger()&&t.isInteger())&&(f=f.mod(t))}else{if(e.e>9&&(f.e>0||f.e<-1||(0==f.e?f.c[0]>1||o&&f.c[1]>=24e7:f.c[0]<8e13||o&&f.c[0]<=9999975e7)))return s=f.s<0&&A(e)?-0:0,f.e>-1&&(s=1/s),new V(l?1/s:s);j&&(s=a(j/m+2))}for(o?(n=new V(.5),l&&(e.s=1),u=A(e)):u=(i=Math.abs(+Y(e)))%2,c=new V(I);;){if(u){if(!(c=c.times(f)).c)break;s?c.c.length>s&&(c.c.length=s):r&&(c=c.mod(t))}if(i){if(0===(i=h(i/2)))break;u=i%2}else if(X(e=e.times(n),e.e+1,1),e.e>14)u=A(e);else{if(0==(i=+Y(e)))break;u=i%2}f=f.times(f),s?f.c&&f.c.length>s&&(f.c.length=s):r&&(f=f.mod(t))}return r?c:(l&&(c=I.div(c)),t?c.mod(t):s?X(c,j,M,void 0):c)},D.integerValue=function(e){var t=new V(this);return null==e?e=M:E(e,0,8),X(t,t.e+1,e)},D.isEqualTo=D.eq=function(e,t){return 0===B(this,new V(e,t))},D.isFinite=function(){return!!this.c},D.isGreaterThan=D.gt=function(e,t){return B(this,new V(e,t))>0},D.isGreaterThanOrEqualTo=D.gte=function(e,t){return 1===(t=B(this,new V(e,t)))||0===t},D.isInteger=function(){return!!this.c&&N(this.e/m)>this.c.length-2},D.isLessThan=D.lt=function(e,t){return B(this,new V(e,t))<0},D.isLessThanOrEqualTo=D.lte=function(e,t){return-1===(t=B(this,new V(e,t)))||0===t},D.isNaN=function(){return!this.s},D.isNegative=function(){return this.s<0},D.isPositive=function(){return this.s>0},D.isZero=function(){return!!this.c&&0==this.c[0]},D.minus=function(e,t){var n,r,i,s,o=this,l=o.s;if(t=(e=new V(e,t)).s,!l||!t)return new V(NaN);if(l!=t)return e.s=-t,o.plus(e);var u=o.e/m,c=e.e/m,f=o.c,a=e.c;if(!u||!c){if(!f||!a)return f?(e.s=-t,e):new V(a?o:NaN);if(!f[0]||!a[0])return a[0]?(e.s=-t,e):new V(f[0]?o:3==M?-0:0)}if(u=N(u),c=N(c),f=f.slice(),l=u-c){for((s=l<0)?(l=-l,i=f):(c=u,i=a),i.reverse(),t=l;t--;i.push(0));i.reverse()}else for(r=(s=(l=f.length)<(t=a.length))?l:t,l=t=0;t<r;t++)if(f[t]!=a[t]){s=f[t]<a[t];break}if(s&&(i=f,f=a,a=i,e.s=-e.s),(t=(r=a.length)-(n=f.length))>0)for(;t--;f[n++]=0);for(t=d-1;r>l;){if(f[--r]<a[r]){for(n=r;n&&!f[--n];f[n]=t);--f[n],f[r]+=d}f[r]-=a[r]}for(;0==f[0];f.splice(0,1),--c);return f[0]?W(e,f,c):(e.s=3==M?-1:1,e.c=[e.e=0],e)},D.modulo=D.mod=function(e,t){var r,i,s=this;return e=new V(e,t),!s.c||!e.s||e.c&&!e.c[0]?new V(NaN):!e.c||s.c&&!s.c[0]?new V(s):(9==G?(i=e.s,e.s=1,r=n(s,e,0,3),e.s=i,r.s*=i):r=n(s,e,0,G),(e=s.minus(r.times(e))).c[0]||1!=G||(e.s=s.s),e)},D.multipliedBy=D.times=function(e,t){var n,r,i,s,o,l,u,c,f,a,h,p,g,w,v,y=this,O=y.c,B=(e=new V(e,t)).c;if(!(O&&B&&O[0]&&B[0]))return!y.s||!e.s||O&&!O[0]&&!B||B&&!B[0]&&!O?e.c=e.e=e.s=null:(e.s*=y.s,O&&B?(e.c=[0],e.e=0):e.c=e.e=null),e;for(r=N(y.e/m)+N(e.e/m),e.s*=y.s,(u=O.length)<(a=B.length)&&(g=O,O=B,B=g,i=u,u=a,a=i),i=u+a,g=[];i--;g.push(0));for(w=d,v=b,i=a;--i>=0;){for(n=0,h=B[i]%v,p=B[i]/v|0,s=i+(o=u);s>i;)n=((c=h*(c=O[--o]%v)+(l=p*c+(f=O[o]/v|0)*h)%v*v+g[s]+n)/w|0)+(l/v|0)+p*f,g[s--]=c%w;g[s]=n}return n?++r:g.splice(0,1),W(e,g,r)},D.negated=function(){var e=new V(this);return e.s=-e.s||null,e},D.plus=function(e,t){var n,r=this,i=r.s;if(t=(e=new V(e,t)).s,!i||!t)return new V(NaN);if(i!=t)return e.s=-t,r.minus(e);var s=r.e/m,o=e.e/m,l=r.c,u=e.c;if(!s||!o){if(!l||!u)return new V(i/0);if(!l[0]||!u[0])return u[0]?e:new V(l[0]?r:0*i)}if(s=N(s),o=N(o),l=l.slice(),i=s-o){for(i>0?(o=s,n=u):(i=-i,n=l),n.reverse();i--;n.push(0));n.reverse()}for((i=l.length)-(t=u.length)<0&&(n=u,u=l,l=n,t=i),i=0;t;)i=(l[--t]=l[t]+u[t]+i)/d|0,l[t]=d===l[t]?0:l[t]%d;return i&&(l=[i].concat(l),++o),W(e,l,o)},D.precision=D.sd=function(e,t){var n,r,i,s=this;if(null!=e&&e!==!!e)return E(e,1,y),null==t?t=M:E(t,0,8),X(new V(s),e,t);if(!(n=s.c))return null;if(r=(i=n.length-1)*m+1,i=n[i]){for(;i%10==0;i/=10,r--);for(i=n[0];i>=10;i/=10,r++);}return e&&s.e+1>r&&(r=s.e+1),r},D.shiftedBy=function(e){return E(e,-9007199254740991,w),this.times("1e"+e)},D.squareRoot=D.sqrt=function(){var e,t,r,i,s,o=this,l=o.c,u=o.s,c=o.e,f=P+4,a=new V("0.5");if(1!==u||!l||!l[0])return new V(!u||u<0&&(!l||l[0])?NaN:l?o:1/0);if(0==(u=Math.sqrt(+Y(o)))||u==1/0?(((t=O(l)).length+c)%2==0&&(t+="0"),u=Math.sqrt(+t),c=N((c+1)/2)-(c<0||c%2),r=new V(t=u==1/0?"5e"+c:(t=u.toExponential()).slice(0,t.indexOf("e")+1)+c)):r=new V(u+""),r.c[0])for((u=(c=r.e)+f)<3&&(u=0);;)if(s=r,r=a.times(s.plus(n(o,s,f,1))),O(s.c).slice(0,u)===(t=O(r.c)).slice(0,u)){if(r.e<c&&--u,"9999"!=(t=t.slice(u-3,u+1))&&(i||"4999"!=t)){+t&&(+t.slice(1)||"5"!=t.charAt(0))||(X(r,r.e+P+2,1),e=!r.times(r).eq(o));break}if(!i&&(X(s,s.e+P+2,0),s.times(s).eq(o))){r=s;break}f+=4,u+=4,i=1}return X(r,r.e+P+1,M,e)},D.toExponential=function(e,t){return null!=e&&(E(e,0,y),e++),H(this,e,t,1)},D.toFixed=function(e,t){return null!=e&&(E(e,0,y),e=e+this.e+1),H(this,e,t)},D.toFormat=function(e,t,n){var r,i=this;if(null==n)null!=e&&t&&"object"==typeof t?(n=t,t=null):e&&"object"==typeof e?(n=e,e=t=null):n=k;else if("object"!=typeof n)throw Error(p+"Argument not an object: "+n);if(r=i.toFixed(e,t),i.c){var s,o=r.split("."),l=+n.groupSize,u=+n.secondaryGroupSize,c=n.groupSeparator||"",f=o[0],a=o[1],h=i.s<0,g=h?f.slice(1):f,d=g.length;if(u&&(s=l,l=u,u=s,d-=s),l>0&&d>0){for(s=d%l||l,f=g.substr(0,s);s<d;s+=l)f+=c+g.substr(s,l);u>0&&(f+=c+g.slice(s)),h&&(f="-"+f)}r=a?f+(n.decimalSeparator||"")+((u=+n.fractionGroupSize)?a.replace(new RegExp("\\d{"+u+"}\\B","g"),"$&"+(n.fractionGroupSeparator||"")):a):f}return(n.prefix||"")+r+(n.suffix||"")},D.toFraction=function(e){var t,r,i,s,o,l,u,c,f,a,h,g,d=this,w=d.c;if(null!=e&&(!(u=new V(e)).isInteger()&&(u.c||1!==u.s)||u.lt(I)))throw Error(p+"Argument "+(u.isInteger()?"out of range: ":"not an integer: ")+Y(u));if(!w)return new V(d);for(t=new V(I),f=r=new V(I),i=c=new V(I),g=O(w),o=t.e=g.length-d.e-1,t.c[0]=v[(l=o%m)<0?m+l:l],e=!e||u.comparedTo(t)>0?o>0?t:f:u,l=$,$=1/0,u=new V(g),c.c[0]=0;a=n(u,t,0,1),1!=(s=r.plus(a.times(i))).comparedTo(e);)r=i,i=s,f=c.plus(a.times(s=f)),c=s,t=u.minus(a.times(s=t)),u=s;return s=n(e.minus(r),i,0,1),c=c.plus(s.times(f)),r=r.plus(s.times(i)),c.s=f.s=d.s,h=n(f,i,o*=2,M).minus(d).abs().comparedTo(n(c,r,o,M).minus(d).abs())<1?[f,i]:[c,r],$=l,h},D.toNumber=function(){return+Y(this)},D.toPrecision=function(e,t){return null!=e&&E(e,1,y),H(this,e,t,2)},D.toString=function(e){var t,n=this,i=n.s,s=n.e;return null===s?i?(t="Infinity",i<0&&(t="-"+t)):t="NaN":(null==e?t=s<=L||s>=R?_(O(n.c),s):C(O(n.c),s,"0"):10===e&&F?t=C(O((n=X(new V(n),P+s+1,M)).c),n.e,"0"):(E(e,2,q.length,"Base"),t=r(C(O(n.c),s,"0"),10,e,i,!0)),i<0&&n.c[0]&&(t="-"+t)),t},D.valueOf=D.toJSON=function(){return Y(this)},D._isBigNumber=!0,D[Symbol.toStringTag]="BigNumber",D[Symbol.for("nodejs.util.inspect.custom")]=D.valueOf,null!=t&&V.set(t),V}();class S{constructor(){this.addColumn=this.addColumn.bind(this),this.crossPairs=this.crossPairs.bind(this),this.BigNumber=T,this.EMA=this.EMA.bind(this),this.MA=this.SMA.bind(this),this.MACD=this.MACD.bind(this),this.BollingerBands=this.BollingerBands.bind(this),this.IchimokuCloud=this.IchimokuCloud.bind(this),this.RSI=this.RSI.bind(this),this.MFI=this.MFI.bind(this)}init(e){const{BigNumber:t}=this,n=e.map((({open:e,high:n,low:r,close:i,volume:s,timestamp:o})=>({open:t(e),high:t(n),low:t(r),close:t(i),volume:t(s),timestamp:o})));return this.ohlcv=n.reduce(((e,{open:t,high:n,low:r,close:i,volume:s,timestamp:o})=>(e.open.push(t),e.high.push(n),e.low.push(r),e.close.push(i),e.volume.push(s),e.timestamp.push(o),e)),{open:[],high:[],low:[],close:[],volume:[],timestamp:[]}),this}getData(){return this.ohlcv}addColumn(e,t){const n=this.ohlcv.open.length;if(t.length>n)throw new Error("Invalid column data: The length of the new column exceeds the length of the OHLCV data");for(;t.length<n;)t.unshift(NaN);this.ohlcv[e]=t.map((e=>isNaN(e)?e:e.toNumber()))}crossPairs(e){const t=this.getData();e.forEach((e=>{const{fast:n,slow:r}=e;if(n&&r)if([n,r].forEach((e=>{if(!t.hasOwnProperty(e)){const t=e.split("_");if(t.length>0){const e=t[0].toUpperCase(),n=t.slice(1);"function"==typeof this[e]&&n.length>0&&this[e](...n)}}})),t.hasOwnProperty(n)&&t.hasOwnProperty(r)){const e=i(this.BigNumber,t[n],t[r]);this.addColumn(`${n}_x_${r}`,e)}else console.error(`Missing ohlcv properties for ${n} or ${r}`)}))}EMA(e){return((e,t)=>{const r=e.getData().close,i=n(e.BigNumber,r,t);e.addColumn(`ema_${t}`,i)})(this,e),this}SMA(e){return((e,t)=>{const n=e.getData().close,i=r(e.BigNumber,n,t);e.addColumn(`sma_${t}`,i)})(this,e),this}MACD(e,t,r){return((e,t=12,r=26,s=9)=>{const o=e.getData().close,l=((e,t,r=12,s=26,o=9)=>{const l=n(e,t,r),u=n(e,t,s),c=l.map(((e,t)=>e.minus(u[t]))),f=n(e,c,o),a=c.map(((e,t)=>e.minus(f[t]))),h=i(e,c,f);return{diff:c,dea:f,histogram:a,crosses:h}})(e.BigNumber,o,t,r,s);for(let t in l)e.addColumn(`macd_${t}`,l[t])})(this,e,t,r),this}BollingerBands(e,t,n){return((e,t,n)=>{const i=e.getData().close,o=((e,t,n=20,i=2)=>{i=new e(i);const o=r(e,t,n),l=s(e,t,n).map((e=>e.times(i)));return{upper:o.map(((e,t)=>e.plus(l[t]))),mid:o,lower:o.map(((e,t)=>e.minus(l[t])))}})(e.BigNumber,i,t,n),{upper:l,mid:u,lower:c}=o;e.addColumn("bollinger_bands_upper",l),e.addColumn("bollinger_bands_mid",u),e.addColumn("bollinger_bands_lower",c)})(this,e,t),this}IchimokuCloud(e,t,n){return((e,t=9,n=26,r=52)=>{const i=t,s=n,f=s-i,a=r,{high:h,low:p,close:g}=e.getData(),d=o(e.BigNumber,h,p,i),m=o(e.BigNumber,h,p,s),w={conversion_line:d,base_line:m,leading_span_a:l(d,m,f,s),leading_span_b:u(e.BigNumber,h,p,a,s),lagging_span:c(g,s)};for(let t in w)console.log(`${t} [length ${w[t].length}] [lastValue ${w[t][w[t].length-1]}]`),e.addColumn(`ichimoku_${t}`,w[t])})(this,e,t,n),this}RSI(e,t){return((e,t=14,r=14)=>{const s=e.getData().close,o=((e,t,r=14,s=14)=>{if(t.length<r)return[];const o=new e(0),l=new e(100),u=new e(1);let c=[],f=o,a=o;for(let n=1;n<=r;n++){const r=new e(t[n]),i=new e(t[n-1]),s=r.minus(i);s.isLessThan(o)?a=a.plus(s.abs()):f=f.plus(s)}let h=f.dividedBy(r),p=a.dividedBy(r),g=p.isEqualTo(o)?o:h.dividedBy(p);c.push(l.minus(l.dividedBy(u.plus(g))));for(let n=r+1;n<t.length;n++){const i=new e(t[n]),s=new e(t[n-1]),d=i.minus(s);d.isLessThan(o)?(a=d.abs(),f=o):(f=d,a=o),h=h.times(r-1).plus(f).dividedBy(r),p=p.times(r-1).plus(a).dividedBy(r),g=p.isEqualTo(o)?o:h.dividedBy(p),c.push(l.minus(l.dividedBy(u.plus(g))))}const d=n(e,c,s);return{rsi:c,rsi_smoothed:d,rsi_crosses:i(e,c,d)}})(e.BigNumber,s,t,r),l=`${t}_${r}`;for(let t in o)e.addColumn(`${t}_${l}`,o[t])})(this,e,t),this}MFI(e){return((e,t=14)=>{const n=e.getData(),r=((e,t,n=14)=>{const{high:r,low:i,close:s,volume:o}=t,l=e(0),u=e(100),c=e(1),f=[],a=[],h=[],p=[],g=[],d=[];for(let e=0;e<s.length;e++){const t=r[e].plus(i[e]).plus(s[e]).dividedBy(3),n=t.times(o[e]);f.push(t),a.push(n)}for(let e=1;e<f.length;e++)f[e].isGreaterThan(f[e-1])?(h.push(a[e]),p.push(l)):f[e].isLessThan(f[e-1])?(h.push(l),p.push(a[e])):(h.push(l),p.push(l));for(let e=n;e<=h.length;e++){const t=h.slice(e-n,e),r=p.slice(e-n,e),i=t.reduce(((e,t)=>e.plus(t)),l),s=r.reduce(((e,t)=>e.plus(t)),l),o=i.dividedBy(s);g.push(o)}for(let e=0;e<g.length;e++){const t=u.minus(u.dividedBy(c.plus(g[e])));d.push(t)}return d})(e.BigNumber,n,t);e.addColumn(`mfi_${t}`,r)})(this,e),this}}})(),OHLCV_INDICATORS=t})();
1
+ var OHLCV_INDICATORS;(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};(()=>{e.r(t),e.d(t,{default:()=>P});var r=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,n=Math.ceil,i=Math.floor,s="[BigNumber Error] ",o=s+"Number primitive has more than 15 significant digits: ",l=1e14,u=14,c=9007199254740991,f=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],a=1e7,h=1e9;function p(e){var t=0|e;return e>0||e===t?t:t-1}function g(e){for(var t,r,n=1,i=e.length,s=e[0]+"";n<i;){for(t=e[n++]+"",r=u-t.length;r--;t="0"+t);s+=t}for(i=s.length;48===s.charCodeAt(--i););return s.slice(0,i+1||1)}function m(e,t){var r,n,i=e.c,s=t.c,o=e.s,l=t.s,u=e.e,c=t.e;if(!o||!l)return null;if(r=i&&!i[0],n=s&&!s[0],r||n)return r?n?0:-l:o;if(o!=l)return o;if(r=o<0,n=u==c,!i||!s)return n?0:!i^r?1:-1;if(!n)return u>c^r?1:-1;for(l=(u=i.length)<(c=s.length)?u:c,o=0;o<l;o++)if(i[o]!=s[o])return i[o]>s[o]^r?1:-1;return u==c?0:u>c^r?1:-1}function d(e,t,r,n){if(e<t||e>r||e!==i(e))throw Error(s+(n||"Argument")+("number"==typeof e?e<t||e>r?" out of range: ":" not an integer: ":" not a primitive number: ")+String(e))}function w(e){var t=e.c.length-1;return p(e.e/u)==t&&e.c[t]%2!=0}function v(e,t){return(e.length>1?e.charAt(0)+"."+e.slice(1):e)+(t<0?"e":"e+")+t}function y(e,t,r){var n,i;if(t<0){for(i=r+".";++t;i+=r);e=i+e}else if(++t>(n=e.length)){for(i=r,t-=n;--t;i+=r);e+=i}else t<n&&(e=e.slice(0,t)+"."+e.slice(t));return e}const b=function e(t){var b,N,O,B,E,_,A,T,C,D,S=F.prototype={constructor:F,toString:null,valueOf:null},L=new F(1),P=20,R=4,$=-7,I=21,M=-1e7,x=1e7,U=!1,G=1,V=0,j={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},k="0123456789abcdefghijklmnopqrstuvwxyz",q=!0;function F(e,t){var n,s,l,f,a,h,p,g,m=this;if(!(m instanceof F))return new F(e,t);if(null==t){if(e&&!0===e._isBigNumber)return m.s=e.s,void(!e.c||e.e>x?m.c=m.e=null:e.e<M?m.c=[m.e=0]:(m.e=e.e,m.c=e.c.slice()));if((h="number"==typeof e)&&0*e==0){if(m.s=1/e<0?(e=-e,-1):1,e===~~e){for(f=0,a=e;a>=10;a/=10,f++);return void(f>x?m.c=m.e=null:(m.e=f,m.c=[e]))}g=String(e)}else{if(!r.test(g=String(e)))return O(m,g,h);m.s=45==g.charCodeAt(0)?(g=g.slice(1),-1):1}(f=g.indexOf("."))>-1&&(g=g.replace(".","")),(a=g.search(/e/i))>0?(f<0&&(f=a),f+=+g.slice(a+1),g=g.substring(0,a)):f<0&&(f=g.length)}else{if(d(t,2,k.length,"Base"),10==t&&q)return X(m=new F(e),P+m.e+1,R);if(g=String(e),h="number"==typeof e){if(0*e!=0)return O(m,g,h,t);if(m.s=1/e<0?(g=g.slice(1),-1):1,F.DEBUG&&g.replace(/^0\.0*|\./,"").length>15)throw Error(o+e)}else m.s=45===g.charCodeAt(0)?(g=g.slice(1),-1):1;for(n=k.slice(0,t),f=a=0,p=g.length;a<p;a++)if(n.indexOf(s=g.charAt(a))<0){if("."==s){if(a>f){f=p;continue}}else if(!l&&(g==g.toUpperCase()&&(g=g.toLowerCase())||g==g.toLowerCase()&&(g=g.toUpperCase()))){l=!0,a=-1,f=0;continue}return O(m,String(e),h,t)}h=!1,(f=(g=N(g,t,10,m.s)).indexOf("."))>-1?g=g.replace(".",""):f=g.length}for(a=0;48===g.charCodeAt(a);a++);for(p=g.length;48===g.charCodeAt(--p););if(g=g.slice(a,++p)){if(p-=a,h&&F.DEBUG&&p>15&&(e>c||e!==i(e)))throw Error(o+m.s*e);if((f=f-a-1)>x)m.c=m.e=null;else if(f<M)m.c=[m.e=0];else{if(m.e=f,m.c=[],a=(f+1)%u,f<0&&(a+=u),a<p){for(a&&m.c.push(+g.slice(0,a)),p-=u;a<p;)m.c.push(+g.slice(a,a+=u));a=u-(g=g.slice(a)).length}else a-=p;for(;a--;g+="0");m.c.push(+g)}}else m.c=[m.e=0]}function H(e,t,r,n){var i,s,o,l,u;if(null==r?r=R:d(r,0,8),!e.c)return e.toString();if(i=e.c[0],o=e.e,null==t)u=g(e.c),u=1==n||2==n&&(o<=$||o>=I)?v(u,o):y(u,o,"0");else if(s=(e=X(new F(e),t,r)).e,l=(u=g(e.c)).length,1==n||2==n&&(t<=s||s<=$)){for(;l<t;u+="0",l++);u=v(u,s)}else if(t-=o,u=y(u,s,"0"),s+1>l){if(--t>0)for(u+=".";t--;u+="0");}else if((t+=s-l)>0)for(s+1==l&&(u+=".");t--;u+="0");return e.s<0&&i?"-"+u:u}function z(e,t){for(var r,n,i=1,s=new F(e[0]);i<e.length;i++)(!(n=new F(e[i])).s||(r=m(s,n))===t||0===r&&s.s===t)&&(s=n);return s}function W(e,t,r){for(var n=1,i=t.length;!t[--i];t.pop());for(i=t[0];i>=10;i/=10,n++);return(r=n+r*u-1)>x?e.c=e.e=null:r<M?e.c=[e.e=0]:(e.e=r,e.c=t),e}function X(e,t,r,s){var o,c,a,h,p,g,m,d=e.c,w=f;if(d){e:{for(o=1,h=d[0];h>=10;h/=10,o++);if((c=t-o)<0)c+=u,a=t,p=d[g=0],m=i(p/w[o-a-1]%10);else if((g=n((c+1)/u))>=d.length){if(!s)break e;for(;d.length<=g;d.push(0));p=m=0,o=1,a=(c%=u)-u+1}else{for(p=h=d[g],o=1;h>=10;h/=10,o++);m=(a=(c%=u)-u+o)<0?0:i(p/w[o-a-1]%10)}if(s=s||t<0||null!=d[g+1]||(a<0?p:p%w[o-a-1]),s=r<4?(m||s)&&(0==r||r==(e.s<0?3:2)):m>5||5==m&&(4==r||s||6==r&&(c>0?a>0?p/w[o-a]:0:d[g-1])%10&1||r==(e.s<0?8:7)),t<1||!d[0])return d.length=0,s?(t-=e.e+1,d[0]=w[(u-t%u)%u],e.e=-t||0):d[0]=e.e=0,e;if(0==c?(d.length=g,h=1,g--):(d.length=g+1,h=w[u-c],d[g]=a>0?i(p/w[o-a]%w[a])*h:0),s)for(;;){if(0==g){for(c=1,a=d[0];a>=10;a/=10,c++);for(a=d[0]+=h,h=1;a>=10;a/=10,h++);c!=h&&(e.e++,d[0]==l&&(d[0]=1));break}if(d[g]+=h,d[g]!=l)break;d[g--]=0,h=1}for(c=d.length;0===d[--c];d.pop());}e.e>x?e.c=e.e=null:e.e<M&&(e.c=[e.e=0])}return e}function Y(e){var t,r=e.e;return null===r?e.toString():(t=g(e.c),t=r<=$||r>=I?v(t,r):y(t,r,"0"),e.s<0?"-"+t:t)}return F.clone=e,F.ROUND_UP=0,F.ROUND_DOWN=1,F.ROUND_CEIL=2,F.ROUND_FLOOR=3,F.ROUND_HALF_UP=4,F.ROUND_HALF_DOWN=5,F.ROUND_HALF_EVEN=6,F.ROUND_HALF_CEIL=7,F.ROUND_HALF_FLOOR=8,F.EUCLID=9,F.config=F.set=function(e){var t,r;if(null!=e){if("object"!=typeof e)throw Error(s+"Object expected: "+e);if(e.hasOwnProperty(t="DECIMAL_PLACES")&&(d(r=e[t],0,h,t),P=r),e.hasOwnProperty(t="ROUNDING_MODE")&&(d(r=e[t],0,8,t),R=r),e.hasOwnProperty(t="EXPONENTIAL_AT")&&((r=e[t])&&r.pop?(d(r[0],-h,0,t),d(r[1],0,h,t),$=r[0],I=r[1]):(d(r,-h,h,t),$=-(I=r<0?-r:r))),e.hasOwnProperty(t="RANGE"))if((r=e[t])&&r.pop)d(r[0],-h,-1,t),d(r[1],1,h,t),M=r[0],x=r[1];else{if(d(r,-h,h,t),!r)throw Error(s+t+" cannot be zero: "+r);M=-(x=r<0?-r:r)}if(e.hasOwnProperty(t="CRYPTO")){if((r=e[t])!==!!r)throw Error(s+t+" not true or false: "+r);if(r){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw U=!r,Error(s+"crypto unavailable");U=r}else U=r}if(e.hasOwnProperty(t="MODULO_MODE")&&(d(r=e[t],0,9,t),G=r),e.hasOwnProperty(t="POW_PRECISION")&&(d(r=e[t],0,h,t),V=r),e.hasOwnProperty(t="FORMAT")){if("object"!=typeof(r=e[t]))throw Error(s+t+" not an object: "+r);j=r}if(e.hasOwnProperty(t="ALPHABET")){if("string"!=typeof(r=e[t])||/^.?$|[+\-.\s]|(.).*\1/.test(r))throw Error(s+t+" invalid: "+r);q="0123456789"==r.slice(0,10),k=r}}return{DECIMAL_PLACES:P,ROUNDING_MODE:R,EXPONENTIAL_AT:[$,I],RANGE:[M,x],CRYPTO:U,MODULO_MODE:G,POW_PRECISION:V,FORMAT:j,ALPHABET:k}},F.isBigNumber=function(e){if(!e||!0!==e._isBigNumber)return!1;if(!F.DEBUG)return!0;var t,r,n=e.c,o=e.e,c=e.s;e:if("[object Array]"=={}.toString.call(n)){if((1===c||-1===c)&&o>=-h&&o<=h&&o===i(o)){if(0===n[0]){if(0===o&&1===n.length)return!0;break e}if((t=(o+1)%u)<1&&(t+=u),String(n[0]).length==t){for(t=0;t<n.length;t++)if((r=n[t])<0||r>=l||r!==i(r))break e;if(0!==r)return!0}}}else if(null===n&&null===o&&(null===c||1===c||-1===c))return!0;throw Error(s+"Invalid BigNumber: "+e)},F.maximum=F.max=function(){return z(arguments,-1)},F.minimum=F.min=function(){return z(arguments,1)},F.random=(B=9007199254740992,E=Math.random()*B&2097151?function(){return i(Math.random()*B)}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(e){var t,r,o,l,c,a=0,p=[],g=new F(L);if(null==e?e=P:d(e,0,h),l=n(e/u),U)if(crypto.getRandomValues){for(t=crypto.getRandomValues(new Uint32Array(l*=2));a<l;)(c=131072*t[a]+(t[a+1]>>>11))>=9e15?(r=crypto.getRandomValues(new Uint32Array(2)),t[a]=r[0],t[a+1]=r[1]):(p.push(c%1e14),a+=2);a=l/2}else{if(!crypto.randomBytes)throw U=!1,Error(s+"crypto unavailable");for(t=crypto.randomBytes(l*=7);a<l;)(c=281474976710656*(31&t[a])+1099511627776*t[a+1]+4294967296*t[a+2]+16777216*t[a+3]+(t[a+4]<<16)+(t[a+5]<<8)+t[a+6])>=9e15?crypto.randomBytes(7).copy(t,a):(p.push(c%1e14),a+=7);a=l/7}if(!U)for(;a<l;)(c=E())<9e15&&(p[a++]=c%1e14);for(l=p[--a],e%=u,l&&e&&(c=f[u-e],p[a]=i(l/c)*c);0===p[a];p.pop(),a--);if(a<0)p=[o=0];else{for(o=-1;0===p[0];p.splice(0,1),o-=u);for(a=1,c=p[0];c>=10;c/=10,a++);a<u&&(o-=u-a)}return g.e=o,g.c=p,g}),F.sum=function(){for(var e=1,t=arguments,r=new F(t[0]);e<t.length;)r=r.plus(t[e++]);return r},N=function(){var e="0123456789";function t(e,t,r,n){for(var i,s,o=[0],l=0,u=e.length;l<u;){for(s=o.length;s--;o[s]*=t);for(o[0]+=n.indexOf(e.charAt(l++)),i=0;i<o.length;i++)o[i]>r-1&&(null==o[i+1]&&(o[i+1]=0),o[i+1]+=o[i]/r|0,o[i]%=r)}return o.reverse()}return function(r,n,i,s,o){var l,u,c,f,a,h,p,m,d=r.indexOf("."),w=P,v=R;for(d>=0&&(f=V,V=0,r=r.replace(".",""),h=(m=new F(n)).pow(r.length-d),V=f,m.c=t(y(g(h.c),h.e,"0"),10,i,e),m.e=m.c.length),c=f=(p=t(r,n,i,o?(l=k,e):(l=e,k))).length;0==p[--f];p.pop());if(!p[0])return l.charAt(0);if(d<0?--c:(h.c=p,h.e=c,h.s=s,p=(h=b(h,m,w,v,i)).c,a=h.r,c=h.e),d=p[u=c+w+1],f=i/2,a=a||u<0||null!=p[u+1],a=v<4?(null!=d||a)&&(0==v||v==(h.s<0?3:2)):d>f||d==f&&(4==v||a||6==v&&1&p[u-1]||v==(h.s<0?8:7)),u<1||!p[0])r=a?y(l.charAt(1),-w,l.charAt(0)):l.charAt(0);else{if(p.length=u,a)for(--i;++p[--u]>i;)p[u]=0,u||(++c,p=[1].concat(p));for(f=p.length;!p[--f];);for(d=0,r="";d<=f;r+=l.charAt(p[d++]));r=y(r,c,l.charAt(0))}return r}}(),b=function(){function e(e,t,r){var n,i,s,o,l=0,u=e.length,c=t%a,f=t/a|0;for(e=e.slice();u--;)l=((i=c*(s=e[u]%a)+(n=f*s+(o=e[u]/a|0)*c)%a*a+l)/r|0)+(n/a|0)+f*o,e[u]=i%r;return l&&(e=[l].concat(e)),e}function t(e,t,r,n){var i,s;if(r!=n)s=r>n?1:-1;else for(i=s=0;i<r;i++)if(e[i]!=t[i]){s=e[i]>t[i]?1:-1;break}return s}function r(e,t,r,n){for(var i=0;r--;)e[r]-=i,i=e[r]<t[r]?1:0,e[r]=i*n+e[r]-t[r];for(;!e[0]&&e.length>1;e.splice(0,1));}return function(n,s,o,c,f){var a,h,g,m,d,w,v,y,b,N,O,B,E,_,A,T,C,D=n.s==s.s?1:-1,S=n.c,L=s.c;if(!(S&&S[0]&&L&&L[0]))return new F(n.s&&s.s&&(S?!L||S[0]!=L[0]:L)?S&&0==S[0]||!L?0*D:D/0:NaN);for(b=(y=new F(D)).c=[],D=o+(h=n.e-s.e)+1,f||(f=l,h=p(n.e/u)-p(s.e/u),D=D/u|0),g=0;L[g]==(S[g]||0);g++);if(L[g]>(S[g]||0)&&h--,D<0)b.push(1),m=!0;else{for(_=S.length,T=L.length,g=0,D+=2,(d=i(f/(L[0]+1)))>1&&(L=e(L,d,f),S=e(S,d,f),T=L.length,_=S.length),E=T,O=(N=S.slice(0,T)).length;O<T;N[O++]=0);C=L.slice(),C=[0].concat(C),A=L[0],L[1]>=f/2&&A++;do{if(d=0,(a=t(L,N,T,O))<0){if(B=N[0],T!=O&&(B=B*f+(N[1]||0)),(d=i(B/A))>1)for(d>=f&&(d=f-1),v=(w=e(L,d,f)).length,O=N.length;1==t(w,N,v,O);)d--,r(w,T<v?C:L,v,f),v=w.length,a=1;else 0==d&&(a=d=1),v=(w=L.slice()).length;if(v<O&&(w=[0].concat(w)),r(N,w,O,f),O=N.length,-1==a)for(;t(L,N,T,O)<1;)d++,r(N,T<O?C:L,O,f),O=N.length}else 0===a&&(d++,N=[0]);b[g++]=d,N[0]?N[O++]=S[E]||0:(N=[S[E]],O=1)}while((E++<_||null!=N[0])&&D--);m=null!=N[0],b[0]||b.splice(0,1)}if(f==l){for(g=1,D=b[0];D>=10;D/=10,g++);X(y,o+(y.e=g+h*u-1)+1,c,m)}else y.e=h,y.r=+m;return y}}(),_=/^(-?)0([xbo])(?=\w[\w.]*$)/i,A=/^([^.]+)\.$/,T=/^\.([^.]+)$/,C=/^-?(Infinity|NaN)$/,D=/^\s*\+(?=[\w.])|^\s+|\s+$/g,O=function(e,t,r,n){var i,o=r?t:t.replace(D,"");if(C.test(o))e.s=isNaN(o)?null:o<0?-1:1;else{if(!r&&(o=o.replace(_,(function(e,t,r){return i="x"==(r=r.toLowerCase())?16:"b"==r?2:8,n&&n!=i?e:t})),n&&(i=n,o=o.replace(A,"$1").replace(T,"0.$1")),t!=o))return new F(o,i);if(F.DEBUG)throw Error(s+"Not a"+(n?" base "+n:"")+" number: "+t);e.s=null}e.c=e.e=null},S.absoluteValue=S.abs=function(){var e=new F(this);return e.s<0&&(e.s=1),e},S.comparedTo=function(e,t){return m(this,new F(e,t))},S.decimalPlaces=S.dp=function(e,t){var r,n,i,s=this;if(null!=e)return d(e,0,h),null==t?t=R:d(t,0,8),X(new F(s),e+s.e+1,t);if(!(r=s.c))return null;if(n=((i=r.length-1)-p(this.e/u))*u,i=r[i])for(;i%10==0;i/=10,n--);return n<0&&(n=0),n},S.dividedBy=S.div=function(e,t){return b(this,new F(e,t),P,R)},S.dividedToIntegerBy=S.idiv=function(e,t){return b(this,new F(e,t),0,1)},S.exponentiatedBy=S.pow=function(e,t){var r,o,l,c,f,a,h,p,g=this;if((e=new F(e)).c&&!e.isInteger())throw Error(s+"Exponent not an integer: "+Y(e));if(null!=t&&(t=new F(t)),f=e.e>14,!g.c||!g.c[0]||1==g.c[0]&&!g.e&&1==g.c.length||!e.c||!e.c[0])return p=new F(Math.pow(+Y(g),f?e.s*(2-w(e)):+Y(e))),t?p.mod(t):p;if(a=e.s<0,t){if(t.c?!t.c[0]:!t.s)return new F(NaN);(o=!a&&g.isInteger()&&t.isInteger())&&(g=g.mod(t))}else{if(e.e>9&&(g.e>0||g.e<-1||(0==g.e?g.c[0]>1||f&&g.c[1]>=24e7:g.c[0]<8e13||f&&g.c[0]<=9999975e7)))return c=g.s<0&&w(e)?-0:0,g.e>-1&&(c=1/c),new F(a?1/c:c);V&&(c=n(V/u+2))}for(f?(r=new F(.5),a&&(e.s=1),h=w(e)):h=(l=Math.abs(+Y(e)))%2,p=new F(L);;){if(h){if(!(p=p.times(g)).c)break;c?p.c.length>c&&(p.c.length=c):o&&(p=p.mod(t))}if(l){if(0===(l=i(l/2)))break;h=l%2}else if(X(e=e.times(r),e.e+1,1),e.e>14)h=w(e);else{if(0==(l=+Y(e)))break;h=l%2}g=g.times(g),c?g.c&&g.c.length>c&&(g.c.length=c):o&&(g=g.mod(t))}return o?p:(a&&(p=L.div(p)),t?p.mod(t):c?X(p,V,R,void 0):p)},S.integerValue=function(e){var t=new F(this);return null==e?e=R:d(e,0,8),X(t,t.e+1,e)},S.isEqualTo=S.eq=function(e,t){return 0===m(this,new F(e,t))},S.isFinite=function(){return!!this.c},S.isGreaterThan=S.gt=function(e,t){return m(this,new F(e,t))>0},S.isGreaterThanOrEqualTo=S.gte=function(e,t){return 1===(t=m(this,new F(e,t)))||0===t},S.isInteger=function(){return!!this.c&&p(this.e/u)>this.c.length-2},S.isLessThan=S.lt=function(e,t){return m(this,new F(e,t))<0},S.isLessThanOrEqualTo=S.lte=function(e,t){return-1===(t=m(this,new F(e,t)))||0===t},S.isNaN=function(){return!this.s},S.isNegative=function(){return this.s<0},S.isPositive=function(){return this.s>0},S.isZero=function(){return!!this.c&&0==this.c[0]},S.minus=function(e,t){var r,n,i,s,o=this,c=o.s;if(t=(e=new F(e,t)).s,!c||!t)return new F(NaN);if(c!=t)return e.s=-t,o.plus(e);var f=o.e/u,a=e.e/u,h=o.c,g=e.c;if(!f||!a){if(!h||!g)return h?(e.s=-t,e):new F(g?o:NaN);if(!h[0]||!g[0])return g[0]?(e.s=-t,e):new F(h[0]?o:3==R?-0:0)}if(f=p(f),a=p(a),h=h.slice(),c=f-a){for((s=c<0)?(c=-c,i=h):(a=f,i=g),i.reverse(),t=c;t--;i.push(0));i.reverse()}else for(n=(s=(c=h.length)<(t=g.length))?c:t,c=t=0;t<n;t++)if(h[t]!=g[t]){s=h[t]<g[t];break}if(s&&(i=h,h=g,g=i,e.s=-e.s),(t=(n=g.length)-(r=h.length))>0)for(;t--;h[r++]=0);for(t=l-1;n>c;){if(h[--n]<g[n]){for(r=n;r&&!h[--r];h[r]=t);--h[r],h[n]+=l}h[n]-=g[n]}for(;0==h[0];h.splice(0,1),--a);return h[0]?W(e,h,a):(e.s=3==R?-1:1,e.c=[e.e=0],e)},S.modulo=S.mod=function(e,t){var r,n,i=this;return e=new F(e,t),!i.c||!e.s||e.c&&!e.c[0]?new F(NaN):!e.c||i.c&&!i.c[0]?new F(i):(9==G?(n=e.s,e.s=1,r=b(i,e,0,3),e.s=n,r.s*=n):r=b(i,e,0,G),(e=i.minus(r.times(e))).c[0]||1!=G||(e.s=i.s),e)},S.multipliedBy=S.times=function(e,t){var r,n,i,s,o,c,f,h,g,m,d,w,v,y,b,N=this,O=N.c,B=(e=new F(e,t)).c;if(!(O&&B&&O[0]&&B[0]))return!N.s||!e.s||O&&!O[0]&&!B||B&&!B[0]&&!O?e.c=e.e=e.s=null:(e.s*=N.s,O&&B?(e.c=[0],e.e=0):e.c=e.e=null),e;for(n=p(N.e/u)+p(e.e/u),e.s*=N.s,(f=O.length)<(m=B.length)&&(v=O,O=B,B=v,i=f,f=m,m=i),i=f+m,v=[];i--;v.push(0));for(y=l,b=a,i=m;--i>=0;){for(r=0,d=B[i]%b,w=B[i]/b|0,s=i+(o=f);s>i;)r=((h=d*(h=O[--o]%b)+(c=w*h+(g=O[o]/b|0)*d)%b*b+v[s]+r)/y|0)+(c/b|0)+w*g,v[s--]=h%y;v[s]=r}return r?++n:v.splice(0,1),W(e,v,n)},S.negated=function(){var e=new F(this);return e.s=-e.s||null,e},S.plus=function(e,t){var r,n=this,i=n.s;if(t=(e=new F(e,t)).s,!i||!t)return new F(NaN);if(i!=t)return e.s=-t,n.minus(e);var s=n.e/u,o=e.e/u,c=n.c,f=e.c;if(!s||!o){if(!c||!f)return new F(i/0);if(!c[0]||!f[0])return f[0]?e:new F(c[0]?n:0*i)}if(s=p(s),o=p(o),c=c.slice(),i=s-o){for(i>0?(o=s,r=f):(i=-i,r=c),r.reverse();i--;r.push(0));r.reverse()}for((i=c.length)-(t=f.length)<0&&(r=f,f=c,c=r,t=i),i=0;t;)i=(c[--t]=c[t]+f[t]+i)/l|0,c[t]=l===c[t]?0:c[t]%l;return i&&(c=[i].concat(c),++o),W(e,c,o)},S.precision=S.sd=function(e,t){var r,n,i,s=this;if(null!=e&&e!==!!e)return d(e,1,h),null==t?t=R:d(t,0,8),X(new F(s),e,t);if(!(r=s.c))return null;if(n=(i=r.length-1)*u+1,i=r[i]){for(;i%10==0;i/=10,n--);for(i=r[0];i>=10;i/=10,n++);}return e&&s.e+1>n&&(n=s.e+1),n},S.shiftedBy=function(e){return d(e,-9007199254740991,c),this.times("1e"+e)},S.squareRoot=S.sqrt=function(){var e,t,r,n,i,s=this,o=s.c,l=s.s,u=s.e,c=P+4,f=new F("0.5");if(1!==l||!o||!o[0])return new F(!l||l<0&&(!o||o[0])?NaN:o?s:1/0);if(0==(l=Math.sqrt(+Y(s)))||l==1/0?(((t=g(o)).length+u)%2==0&&(t+="0"),l=Math.sqrt(+t),u=p((u+1)/2)-(u<0||u%2),r=new F(t=l==1/0?"5e"+u:(t=l.toExponential()).slice(0,t.indexOf("e")+1)+u)):r=new F(l+""),r.c[0])for((l=(u=r.e)+c)<3&&(l=0);;)if(i=r,r=f.times(i.plus(b(s,i,c,1))),g(i.c).slice(0,l)===(t=g(r.c)).slice(0,l)){if(r.e<u&&--l,"9999"!=(t=t.slice(l-3,l+1))&&(n||"4999"!=t)){+t&&(+t.slice(1)||"5"!=t.charAt(0))||(X(r,r.e+P+2,1),e=!r.times(r).eq(s));break}if(!n&&(X(i,i.e+P+2,0),i.times(i).eq(s))){r=i;break}c+=4,l+=4,n=1}return X(r,r.e+P+1,R,e)},S.toExponential=function(e,t){return null!=e&&(d(e,0,h),e++),H(this,e,t,1)},S.toFixed=function(e,t){return null!=e&&(d(e,0,h),e=e+this.e+1),H(this,e,t)},S.toFormat=function(e,t,r){var n,i=this;if(null==r)null!=e&&t&&"object"==typeof t?(r=t,t=null):e&&"object"==typeof e?(r=e,e=t=null):r=j;else if("object"!=typeof r)throw Error(s+"Argument not an object: "+r);if(n=i.toFixed(e,t),i.c){var o,l=n.split("."),u=+r.groupSize,c=+r.secondaryGroupSize,f=r.groupSeparator||"",a=l[0],h=l[1],p=i.s<0,g=p?a.slice(1):a,m=g.length;if(c&&(o=u,u=c,c=o,m-=o),u>0&&m>0){for(o=m%u||u,a=g.substr(0,o);o<m;o+=u)a+=f+g.substr(o,u);c>0&&(a+=f+g.slice(o)),p&&(a="-"+a)}n=h?a+(r.decimalSeparator||"")+((c=+r.fractionGroupSize)?h.replace(new RegExp("\\d{"+c+"}\\B","g"),"$&"+(r.fractionGroupSeparator||"")):h):a}return(r.prefix||"")+n+(r.suffix||"")},S.toFraction=function(e){var t,r,n,i,o,l,c,a,h,p,m,d,w=this,v=w.c;if(null!=e&&(!(c=new F(e)).isInteger()&&(c.c||1!==c.s)||c.lt(L)))throw Error(s+"Argument "+(c.isInteger()?"out of range: ":"not an integer: ")+Y(c));if(!v)return new F(w);for(t=new F(L),h=r=new F(L),n=a=new F(L),d=g(v),o=t.e=d.length-w.e-1,t.c[0]=f[(l=o%u)<0?u+l:l],e=!e||c.comparedTo(t)>0?o>0?t:h:c,l=x,x=1/0,c=new F(d),a.c[0]=0;p=b(c,t,0,1),1!=(i=r.plus(p.times(n))).comparedTo(e);)r=n,n=i,h=a.plus(p.times(i=h)),a=i,t=c.minus(p.times(i=t)),c=i;return i=b(e.minus(r),n,0,1),a=a.plus(i.times(h)),r=r.plus(i.times(n)),a.s=h.s=w.s,m=b(h,n,o*=2,R).minus(w).abs().comparedTo(b(a,r,o,R).minus(w).abs())<1?[h,n]:[a,r],x=l,m},S.toNumber=function(){return+Y(this)},S.toPrecision=function(e,t){return null!=e&&d(e,1,h),H(this,e,t,2)},S.toString=function(e){var t,r=this,n=r.s,i=r.e;return null===i?n?(t="Infinity",n<0&&(t="-"+t)):t="NaN":(null==e?t=i<=$||i>=I?v(g(r.c),i):y(g(r.c),i,"0"):10===e&&q?t=y(g((r=X(new F(r),P+i+1,R)).c),r.e,"0"):(d(e,2,k.length,"Base"),t=N(y(g(r.c),i,"0"),10,e,n,!0)),n<0&&r.c[0]&&(t="-"+t)),t},S.valueOf=S.toJSON=function(){return Y(this)},S._isBigNumber=!0,S[Symbol.toStringTag]="BigNumber",S[Symbol.for("nodejs.util.inspect.custom")]=S.valueOf,null!=t&&F.set(t),F}(),N=(e,t,r)=>{const n=e(2/(r+1)),i=t.length,s=[];if(n.isGreaterThan(1))return Array(i);if(n.isEqualTo(1))return[...t];let o=0,l=0;for(;l<i;l++){const e=t[l];if("object"==typeof e){s[l]=e,o=e,l++;break}}if(Array.isArray(n))for(;l<i;l++){const e=t[l];"object"==typeof e&&"object"==typeof n[l]?o=s[l]=n[l].multipliedBy(e).plus(n[l].minus(1).multipliedBy(o)):s[l]=s[l-1]}else{const r=e(1).minus(n);for(;l<i;l++){const e=t[l];o="object"==typeof e?n.multipliedBy(e).plus(r.multipliedBy(o)):s[l-1],s[l]=o}}return s},O=(e,t,r)=>{let n=[],i=e(0),s=[];for(let e=0;e<t.length;e++)s.push(t[e]),i=i.plus(t[e]),s.length>r&&(i=i.minus(s.shift())),e>=r-1?n.push(i.dividedBy(r)):n.push(i.dividedBy(s.length));return n},B=(e,t,r)=>{let n=new Array(t.length).fill(0),i=0;const s=new e(t[0]),o=new e(r[0]);s.isGreaterThan(o)?(i=1,n[0]=1):s.isLessThan(o)?(i=-1,n[0]=-1):(i=0,n[0]=0);for(let s=1;s<t.length;s++){const o=new e(t[s]),l=new e(r[s]),u=new e(t[s-1]),c=new e(r[s-1]);o.isGreaterThan(l)&&u.isLessThanOrEqualTo(c)?(i=1,n[s]=1):o.isLessThan(l)&&u.isGreaterThanOrEqualTo(c)?(i=-1,n[s]=-1):n[s]=1===i?n[s-1]+1:-1===i?n[s-1]-1:0}return n.map((t=>e(t)))},E=(e,t,r)=>{const n=new e(0),i=t.length,s=O(e,t,r),o=new Array(i).fill(n);for(let e=r-1;e<i;e++){let i=n;for(let n=e-r+1;n<=e;n++)i=i.plus(t[n].minus(s[e]).pow(2));o[e]=i.dividedBy(r).sqrt()}return o},_=(e,t)=>{let{upper:r,lower:n}=t;const i=r.map(((e,t)=>e.minus(n[t])));return e.map(((e,t)=>e.minus(n[t]).dividedBy(i[t]).times(100)))},A=(e,t,r,n)=>t.slice(n).map(((i,s)=>{const o=t.slice(s,s+n),l=r.slice(s,s+n);return e.maximum(...o).plus(e.minimum(...l)).dividedBy(2)})),T=(e,t,r,n)=>{const i=e.slice(r).map(((e,r)=>r<t.length?e.plus(t[r]).dividedBy(2):null)).filter((e=>null!==e));return i.slice(0,i.length-n+1)},C=(e,t,r,n,i)=>{let s=t.slice(n).map(((i,s)=>{const o=t.slice(s,s+n),l=r.slice(s,s+n);return e.maximum(...o).plus(e.minimum(...l)).dividedBy(2)}));return s.slice(0,s.length-i+1)},D=(e,t)=>e.slice(0,e.length-t),S={getSMA:O,getEMA:N},L=(e,t,r=10)=>{const{open:n,high:i,low:s,close:o,volume:l}=t,u=e.min(...s),c=e.max(...i).minus(u).dividedBy(r),f=Array.from({length:r},((t,r)=>({price:u.plus(c.multipliedBy(r)),upVolume:new e(0),downVolume:new e(0)}))),a=new e(1).dividedBy(c),h=o.length;for(let t=0;t<h;t++){const c=n[t],h=i[t],p=s[t],g=o[t],m=l[t],d=g.isGreaterThanOrEqualTo(c)?m:new e(0),w=g.isLessThan(c)?m:new e(0),v=p.minus(u).multipliedBy(a).integerValue(e.ROUND_FLOOR).toNumber(),y=h.minus(u).multipliedBy(a).integerValue(e.ROUND_CEIL).toNumber();for(let e=Math.max(v,0);e<Math.min(y,r);e++)f[e].upVolume=f[e].upVolume.plus(d),f[e].downVolume=f[e].downVolume.plus(w)}return f};class P{constructor(){this.BigNumber=b,this.VolumeProfile=L}init(e){const{BigNumber:t}=this,r=e.map((({open:e,high:r,low:n,close:i,volume:s,...o})=>({open:t(e),high:t(r),low:t(n),close:t(i),volume:t(s),...o})));return this.ohlcv=r.reduce(((e,{open:t,high:r,low:n,close:i,volume:s,...o})=>(e.open.push(t),e.high.push(r),e.low.push(n),e.close.push(i),e.volume.push(s),Object.keys(o).forEach((t=>{e[t]||(e[t]=[]),e[t].push(o[t])})),e)),{open:[],high:[],low:[],close:[],volume:[]}),this}getHeaders(){return Object.keys(this.getData())}getData(){return this.ohlcv}getLastValues(){const e={};for(let t in this.ohlcv){const r=this.ohlcv[t];e[t]=r[r.length-1]}return e}addColumn(e,t){const r=this.ohlcv.open.length;if(t.length>r)throw new Error("Invalid column data: The length of the new column exceeds the length of the OHLCV data");for(;t.length<r;)t.unshift(NaN);this.ohlcv[e]=t.map((e=>isNaN(e)?e:e.toNumber()))}crossPairs(e){const t=this.getData();let r=[];e.forEach((e=>{const{fast:n,slow:i}=e;if(n&&i)if([n,i].forEach(((e,n)=>{if(t.hasOwnProperty(e)||"string"!=typeof e)"number"==typeof e&&1===n&&(r=t.close.map((e=>30)));else{const t=e.split("_");if(t.length>0){const e=t[0].toUpperCase(),r=t.slice(1);"function"==typeof this[e]&&r.length>0&&this[e](...r)}}})),t.hasOwnProperty(n)&&t.hasOwnProperty(i)){const e=B(this.BigNumber,t[n],t[i]);this.addColumn(`${n}_x_${i}`,e)}else if(t.hasOwnProperty(n)&&r.length>0){const e=B(this.BigNumber,t[n],r);this.addColumn(`${n}_x_${i}`,e)}else console.error(`Missing ohlcv properties for ${n} or ${i}`)}))}EMA(e){return((e,t)=>{const r=e.getData().close,n=N(e.BigNumber,r,t);e.addColumn(`ema_${t}`,n)})(this,e),this}SMA(e){return((e,t)=>{const r=e.getData().close,n=O(e.BigNumber,r,t);e.addColumn(`sma_${t}`,n)})(this,e),this}MACD(e,t,r){return((e,t=12,r=26,n=9)=>{const i=e.getData().close,s=((e,t,r=12,n=26,i=9)=>{const s=N(e,t,r),o=N(e,t,n),l=s.map(((e,t)=>e.minus(o[t]))),u=N(e,l,i),c=l.map(((e,t)=>e.minus(u[t]))),f=B(e,l,u);return{diff:l,dea:u,histogram:c,crosses:f}})(e.BigNumber,i,t,r,n);for(let t in s)e.addColumn(`macd_${t}`,s[t])})(this,e,t,r),this}BollingerBands(e,t,r){return((e,t,r)=>{const n=e.getData().close,i=((e,t,r=20,n=2)=>{n=new e(n);const i=O(e,t,r),s=E(e,t,r).map((e=>e.times(n)));let o=i.map(((e,t)=>e.plus(s[t]))),l=i,u=i.map(((e,t)=>e.minus(s[t])));return{upper:o,mid:l,lower:u,range:_(t,{upper:o,lower:u})}})(e.BigNumber,n,t,r);for(let t in i)e.addColumn(`bollinger_bands_${t}`,i[t])})(this,e,t),this}IchimokuCloud(e,t,r){return((e,t,r,n)=>{const i=e.getData(),s=((e,t,r=9,n=26,i=52)=>{const s=r,o=n,l=o-s,u=i,{high:c,low:f,close:a}=t,h=A(e,c,f,s),p=A(e,c,f,o);return{conversion_line:h,base_line:p,leading_span_a:T(h,p,l,o),leading_span_b:C(e,c,f,u,o),lagging_span:D(a,o)}})(e.BigNumber,i,t,r,n);for(let t in s)console.log(`${t} [length ${s[t].length}] [lastValue ${s[t][s[t].length-1]}]`),e.addColumn(`ichimoku_${t}`,s[t])})(this,e,t,r),this}RSI(e,t,r){return((e,t,r,n)=>{const i=e.getData().close,s=((e,t,r=14,n="SMA",i=14)=>{if(t.length<r)return[];const s=new e(0),o=new e(100),l=new e(1);let u=[],c=s,f=s;for(let n=1;n<=r;n++){const r=new e(t[n]),i=new e(t[n-1]),o=r.minus(i);o.isLessThan(s)?f=f.plus(o.abs()):c=c.plus(o)}let a=c.dividedBy(r),h=f.dividedBy(r),p=h.isEqualTo(s)?s:a.dividedBy(h);u.push(o.minus(o.dividedBy(l.plus(p))));for(let n=r+1;n<t.length;n++){const i=new e(t[n]),g=new e(t[n-1]),m=i.minus(g);m.isLessThan(s)?(f=m.abs(),c=s):(c=m,f=s),a=a.times(r-1).plus(c).dividedBy(r),h=h.times(r-1).plus(f).dividedBy(r),p=h.isEqualTo(s)?s:a.dividedBy(h),u.push(o.minus(o.dividedBy(l.plus(p))))}let g={rsi:u};if("string"==typeof n&&"number"==typeof i&&S.hasOwnProperty(`get${n}`)){const t=S[`get${n}`](e,u,i);g[`rsi_${n}`]=t,g[`rsi_x_rsi_${n}`]=B(e,u,t)}return g})(e.BigNumber,i,t,r,n),o=`${t}`;for(let t in s)e.addColumn(`${t}_${o}`.toLowerCase(),s[t])})(this,e,t,r),this}MFI(e){return((e,t=14)=>{const r=e.getData(),n=((e,t,r=14)=>{const{high:n,low:i,close:s,volume:o}=t,l=e(0),u=e(100),c=e(1),f=[],a=[],h=[],p=[],g=[],m=[];for(let e=0;e<s.length;e++){const t=n[e].plus(i[e]).plus(s[e]).dividedBy(3),r=t.times(o[e]);f.push(t),a.push(r)}for(let e=1;e<f.length;e++)f[e].isGreaterThan(f[e-1])?(h.push(a[e]),p.push(l)):f[e].isLessThan(f[e-1])?(h.push(l),p.push(a[e])):(h.push(l),p.push(l));for(let e=r;e<=h.length;e++){const t=h.slice(e-r,e),n=p.slice(e-r,e),i=t.reduce(((e,t)=>e.plus(t)),l),s=n.reduce(((e,t)=>e.plus(t)),l),o=i.dividedBy(s);g.push(o)}for(let e=0;e<g.length;e++){const t=u.minus(u.dividedBy(c.plus(g[e])));m.push(t)}return m})(e.BigNumber,r,t);e.addColumn(`mfi_${t}`,n)})(this,e),this}RelativeVolume(e){return((e,t)=>{const r=e.getData().volume,n=((e,t,r=10)=>{const n=O(e,t,r);return t.map(((e,t)=>0!==t&&n[t-2]?n[t-2].isZero()?NaN:e.dividedBy(n[t-2]):NaN)).filter((e=>!Number.isNaN(e)))})(e.BigNumber,r,t);e.addColumn(`relative_volume_${t}`,n)})(this,e),this}}})(),OHLCV_INDICATORS=t})();
package/index.js CHANGED
@@ -7,11 +7,13 @@ import { IchimokuCloud } from './src/moving-averages/ichimokuCloud.js'
7
7
  import { RSI} from './src/oscillators/rsi.js'
8
8
  import { MFI} from './src/oscillators/mfi.js'
9
9
  import { RelativeVolume} from './src/moving-averages/relativeVolume.js'
10
- import { findCrosses} from './src/utilities.js'
10
+ import { VolumeProfile } from './src/studies/volumeProfile.js'
11
+ import {findCrosses} from './src/utilities.js'
11
12
 
12
13
  export default class OHLCV_INDICATORS {
13
14
  constructor() {
14
15
  this.BigNumber = BigNumber
16
+ this.VolumeProfile = VolumeProfile
15
17
  }
16
18
 
17
19
  init(ohlcv) {
@@ -83,6 +85,7 @@ export default class OHLCV_INDICATORS {
83
85
 
84
86
  //crossing single column pairs
85
87
  const ohlcv = this.getData()
88
+ let slowNumArr = []
86
89
 
87
90
  //each parameter [{fast, slow}, {fast, slow}]
88
91
 
@@ -97,8 +100,8 @@ export default class OHLCV_INDICATORS {
97
100
 
98
101
  //if the column does not exist, will try to create a new one
99
102
  //this code can only add single column output indicators such as SMA and EMA
100
- [fast, slow].forEach(v => {
101
- if (!ohlcv.hasOwnProperty(v)) {
103
+ [fast, slow].forEach((v, i) => {
104
+ if (!ohlcv.hasOwnProperty(v) && typeof v === 'string') {
102
105
  const arr = v.split('_')
103
106
  if (arr.length > 0) {
104
107
  const funcName = arr[0].toUpperCase()
@@ -109,13 +112,23 @@ export default class OHLCV_INDICATORS {
109
112
  }
110
113
  }
111
114
  }
115
+ else if(typeof v === 'number' && i === 1)
116
+ {
117
+ slowNumArr = ohlcv.close.map(o => 30)
118
+ }
112
119
  })
113
120
 
114
121
  //finds the cross and adds is to the columns
115
122
  if (ohlcv.hasOwnProperty(fast) && ohlcv.hasOwnProperty(slow)) {
116
123
  const cross = findCrosses(this.BigNumber, ohlcv[fast], ohlcv[slow])
117
124
  this.addColumn(`${fast}_x_${slow}`, cross)
118
- } else {
125
+ }
126
+ else if(ohlcv.hasOwnProperty(fast) && slowNumArr.length > 0)
127
+ {
128
+ const cross = findCrosses(this.BigNumber, ohlcv[fast], slowNumArr)
129
+ this.addColumn(`${fast}_x_${slow}`, cross)
130
+ }
131
+ else {
119
132
  console.error(`Missing ohlcv properties for ${fast} or ${slow}`)
120
133
  }
121
134
  })
@@ -144,9 +157,9 @@ export default class OHLCV_INDICATORS {
144
157
  IchimokuCloud(this, tenkan, kijun, senkou)
145
158
  return this
146
159
  }
147
- RSI(period, smoothingPeriod)
160
+ RSI(period, movingAverage, movingAveragePeriod)
148
161
  {
149
- RSI(this, period, smoothingPeriod)
162
+ RSI(this, period, movingAverage, movingAveragePeriod)
150
163
  return this
151
164
  }
152
165
  MFI(period)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ohlcv-indicators",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "A JavaScript library featuring optimized trading indicators for OHLCV arrays [{open, high, low, close, value}], utilizing BigNumber precision for enhanced accuracy.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -11,7 +11,9 @@
11
11
  "author": "https://jaimelias.com/",
12
12
  "license": "ISC",
13
13
  "dependencies": {
14
- "bignumber.js": "^9.1.2",
14
+ "bignumber.js": "^9.1.2"
15
+ },
16
+ "devDependencies": {
15
17
  "webpack": "^5.92.1",
16
18
  "webpack-cli": "^5.1.4"
17
19
  }
@@ -3,13 +3,13 @@ import { getSMA } from "./sma.js";
3
3
 
4
4
  export const BollingerBands = (main, size, times) => {
5
5
  const ohlcv = main.getData()
6
- const suffix = `${size}_${times}`
7
6
  const data = ohlcv['close'];
8
7
  const bb = getBollingerBands(main.BigNumber, data, size, times)
9
- const {upper, mid, lower} = bb
10
- main.addColumn(`bollinger_bands_upper`, upper)
11
- main.addColumn(`bollinger_bands_mid`, mid)
12
- main.addColumn(`bollinger_bands_lower`, lower)
8
+
9
+ for(let k in bb)
10
+ {
11
+ main.addColumn(`bollinger_bands_${k}`, bb[k])
12
+ }
13
13
  }
14
14
 
15
15
 
@@ -28,8 +28,9 @@ export const getBollingerBands = (BigNumber, data, size = 20, times = 2) => {
28
28
  let upper = avg.map((o, i) => o.plus(timesSd[i]))
29
29
  let mid = avg
30
30
  let lower = avg.map((o, i) => o.minus(timesSd[i]))
31
+ let range = bollingerBandsRange(data, {upper, lower})
31
32
 
32
- return { upper, mid, lower }
33
+ return { upper, mid, lower, range }
33
34
  };
34
35
 
35
36
  const deviation = (BigNumber, data, size) => {
@@ -49,5 +50,15 @@ export const getBollingerBands = (BigNumber, data, size = 20, times = 2) => {
49
50
  }
50
51
 
51
52
  return ret
52
- };
53
-
53
+ }
54
+
55
+
56
+ const bollingerBandsRange = (data, bollingerBands) => {
57
+ let {upper, lower} = bollingerBands;
58
+
59
+ const range = upper.map((v, i) => v.minus(lower[i]))
60
+
61
+ const output = data.map((v, i) => (v.minus(lower[i]).dividedBy(range[i])).times(100))
62
+
63
+ return output
64
+ }
@@ -11,7 +11,9 @@ export const getRelativeVolume = (BigNumber, data, size = 10) => {
11
11
  const sma = getSMA(BigNumber, data, size)
12
12
 
13
13
  return data.map((v, i) => {
14
- if (i === 0 || !sma[i - 2]) return NaN // or handle the edge case appropriately
14
+ if (i === 0 || !sma[i - 2]) return NaN
15
+ // Avoid division by zero
16
+ if (sma[i - 2].isZero()) return NaN
15
17
  return v.dividedBy(sma[i - 2])
16
- }).filter(v => v !== NaN) // remove null values if necessary
18
+ }).filter(v => !Number.isNaN(v))
17
19
  }
@@ -1,28 +1,30 @@
1
+ import { getSMA } from "../moving-averages/sma.js";
1
2
  import { getEMA } from "../moving-averages/ema.js";
2
3
  import { findCrosses } from "../utilities.js";
3
4
 
4
- export const RSI = (main, period = 14, smoothingPeriod = 14) => {
5
+ const ma = {getSMA, getEMA}
6
+
7
+ export const RSI = (main, period, movingAverage, movingAveragePeriod) => {
5
8
 
6
9
  const ohlcv = main.getData()
7
- const data = ohlcv['close'];
8
- const rsi = getRSI(main.BigNumber, data, period, smoothingPeriod)
9
- const suffix = `${period}_${smoothingPeriod}`
10
+ const data = ohlcv['close']
11
+ const rsi = getRSI(main.BigNumber, data, period, movingAverage, movingAveragePeriod)
12
+ const suffix = `${period}`
10
13
 
11
14
  for(let k in rsi)
12
15
  {
13
- main.addColumn(`${k}_${suffix}`, rsi[k]);
16
+ main.addColumn(`${k}_${suffix}`.toLowerCase(), rsi[k])
14
17
  }
15
-
16
18
  }
17
19
 
18
- export const getRSI = (BigNumber, data, period = 14, smoothingPeriod = 14) => {
20
+ export const getRSI = (BigNumber, data, period = 14, movingAverage = 'SMA', movingAveragePeriod = 14) => {
19
21
  if (data.length < period) {
20
22
  return [];
21
23
  }
22
24
 
23
- const zero = new BigNumber(0);
24
- const hundred = new BigNumber(100);
25
- const one = new BigNumber(1);
25
+ const zero = new BigNumber(0)
26
+ const hundred = new BigNumber(100)
27
+ const one = new BigNumber(1)
26
28
 
27
29
  let rsi = [];
28
30
  let gain = zero;
@@ -30,45 +32,54 @@ export const getRSI = (BigNumber, data, period = 14, smoothingPeriod = 14) => {
30
32
 
31
33
  // Calculate the initial gain and loss
32
34
  for (let i = 1; i <= period; i++) {
33
- const thisVal = new BigNumber(data[i]);
34
- const prevVal = new BigNumber(data[i - 1]);
35
- const change = thisVal.minus(prevVal);
35
+ const thisVal = new BigNumber(data[i])
36
+ const prevVal = new BigNumber(data[i - 1])
37
+ const change = thisVal.minus(prevVal)
36
38
 
37
39
  if (change.isLessThan(zero)) {
38
- loss = loss.plus(change.abs());
40
+ loss = loss.plus(change.abs())
39
41
  } else {
40
- gain = gain.plus(change);
42
+ gain = gain.plus(change)
41
43
  }
42
44
  }
43
45
 
44
46
  // Calculate the first RSI value
45
- let avgGain = gain.dividedBy(period);
46
- let avgLoss = loss.dividedBy(period);
47
- let rs = avgLoss.isEqualTo(zero) ? zero : avgGain.dividedBy(avgLoss);
48
- rsi.push(hundred.minus(hundred.dividedBy(one.plus(rs))));
47
+ let avgGain = gain.dividedBy(period)
48
+ let avgLoss = loss.dividedBy(period)
49
+ let rs = avgLoss.isEqualTo(zero) ? zero : avgGain.dividedBy(avgLoss)
50
+ rsi.push(hundred.minus(hundred.dividedBy(one.plus(rs))))
49
51
 
50
52
  // Calculate subsequent RSI values
51
53
  for (let i = period + 1; i < data.length; i++) {
52
- const thisVal = new BigNumber(data[i]);
53
- const prevVal = new BigNumber(data[i - 1]);
54
- const change = thisVal.minus(prevVal);
54
+ const thisVal = new BigNumber(data[i])
55
+ const prevVal = new BigNumber(data[i - 1])
56
+ const change = thisVal.minus(prevVal)
55
57
 
56
58
  if (change.isLessThan(zero)) {
57
- loss = change.abs();
58
- gain = zero;
59
+ loss = change.abs()
60
+ gain = zero
59
61
  } else {
60
- gain = change;
61
- loss = zero;
62
+ gain = change
63
+ loss = zero
62
64
  }
63
65
 
64
- avgGain = avgGain.times(period - 1).plus(gain).dividedBy(period);
65
- avgLoss = avgLoss.times(period - 1).plus(loss).dividedBy(period);
66
- rs = avgLoss.isEqualTo(zero) ? zero : avgGain.dividedBy(avgLoss);
67
- rsi.push(hundred.minus(hundred.dividedBy(one.plus(rs))));
66
+ avgGain = avgGain.times(period - 1).plus(gain).dividedBy(period)
67
+ avgLoss = avgLoss.times(period - 1).plus(loss).dividedBy(period)
68
+ rs = avgLoss.isEqualTo(zero) ? zero : avgGain.dividedBy(avgLoss)
69
+ rsi.push(hundred.minus(hundred.dividedBy(one.plus(rs))))
68
70
  }
69
71
 
70
- const rsi_smoothed = getEMA(BigNumber, rsi, smoothingPeriod);
71
- const rsi_crosses = findCrosses(BigNumber, rsi, rsi_smoothed);
72
+ let output = {rsi}
72
73
 
73
- return { rsi, rsi_smoothed, rsi_crosses};
74
- };
74
+ if(typeof movingAverage === 'string' && typeof movingAveragePeriod === 'number')
75
+ {
76
+ if(ma.hasOwnProperty(`get${movingAverage}`))
77
+ {
78
+ const rsi_smoothed = ma[`get${movingAverage}`](BigNumber, rsi, movingAveragePeriod)
79
+ output[`rsi_${movingAverage}`] = rsi_smoothed
80
+ output[`rsi_x_rsi_${movingAverage}`] = findCrosses(BigNumber, rsi, rsi_smoothed)
81
+ }
82
+ }
83
+
84
+ return output
85
+ }
@@ -0,0 +1,45 @@
1
+ //volume profile can not be concatenated to the main class
2
+
3
+ export const VolumeProfile = (BigNumber, ohlcv, numBins = 10) => {
4
+
5
+ const { open, high, low, close, volume } = ohlcv;
6
+
7
+ // Determine the range of prices
8
+ const lowPrice = BigNumber.min(...low);
9
+ const highPrice = BigNumber.max(...high);
10
+ const binSize = highPrice.minus(lowPrice).dividedBy(numBins);
11
+
12
+ // Initialize bins
13
+ const bins = Array.from({ length: numBins }, (_, i) => ({
14
+ price: lowPrice.plus(binSize.multipliedBy(i)),
15
+ upVolume: new BigNumber(0),
16
+ downVolume: new BigNumber(0)
17
+ }));
18
+
19
+ // Precompute binSize inversely to use multiplication instead of division in the loop
20
+ const inverseBinSize = new BigNumber(1).dividedBy(binSize);
21
+
22
+ // Distribute volume into bins
23
+ const numDataPoints = close.length;
24
+ for (let i = 0; i < numDataPoints; i++) {
25
+ const currentOpen = open[i];
26
+ const currentHigh = high[i];
27
+ const currentLow = low[i];
28
+ const currentClose = close[i];
29
+ const currentVolume = volume[i];
30
+
31
+ const upVolume = currentClose.isGreaterThanOrEqualTo(currentOpen) ? currentVolume : new BigNumber(0);
32
+ const downVolume = currentClose.isLessThan(currentOpen) ? currentVolume : new BigNumber(0);
33
+
34
+ const lowIndex = currentLow.minus(lowPrice).multipliedBy(inverseBinSize).integerValue(BigNumber.ROUND_FLOOR).toNumber();
35
+ const highIndex = currentHigh.minus(lowPrice).multipliedBy(inverseBinSize).integerValue(BigNumber.ROUND_CEIL).toNumber();
36
+
37
+ for (let j = Math.max(lowIndex, 0); j < Math.min(highIndex, numBins); j++) {
38
+ bins[j].upVolume = bins[j].upVolume.plus(upVolume);
39
+ bins[j].downVolume = bins[j].downVolume.plus(downVolume);
40
+ }
41
+ }
42
+
43
+ return bins
44
+
45
+ }
@@ -22,8 +22,7 @@ const getOneDayOHLCV = async (symbol, limit) => {
22
22
  high: convertCurrencyToFloat(z.high),
23
23
  low: convertCurrencyToFloat(z.low),
24
24
  close: convertCurrencyToFloat(z.close),
25
- volume: convertCurrencyToFloat(z.volume),
26
- ...convertNyMillisecondsToUtc(x) //{utcTimestamp, utcDate}
25
+ volume: convertCurrencyToFloat(z.volume)
27
26
  }))
28
27
 
29
28
  return ohlcv
@@ -41,8 +40,7 @@ export const getLatestOHLCV = async (symbol) => {
41
40
  high: Math.max(...allValues),
42
41
  low: Math.min(...allValues),
43
42
  close: convertCurrencyToFloat(lastSalePrice),
44
- volume: convertCurrencyToFloat(volume),
45
- ...convertNyMillisecondsToUtc(chart[chart.length -1].x)
43
+ volume: convertCurrencyToFloat(volume)
46
44
  }]
47
45
  }
48
46
 
@@ -54,130 +52,4 @@ const getDateRange = limit => {
54
52
  const fromDateFormatted = fromDate.toISOString().slice(0, 10) // Get the date limit number of days ago in yyyy-mm-dd format
55
53
 
56
54
  return { fromDate: fromDateFormatted, toDate }
57
- };
58
-
59
-
60
- export const fetchHistoricalOHLCV = async ({symbol, days}) => {
61
-
62
- //this function removes the lates "today result from output"
63
-
64
- const response = await fetch(`https://charting.nasdaq.com/data/charting/intraday?symbol=${symbol}&mostRecent=${days}&includeLatestIntradayData=1&`, {
65
- referrer: "https://charting.nasdaq.com/dynamic/chart.html"
66
- })
67
-
68
- const data = await response.json()
69
- const {marketData} = data
70
-
71
-
72
- const parsedData = marketData.map(o => ({
73
- value: o.Value,
74
- volume: o.Volume,
75
- data: o.Date,
76
- ...convertNYDateStringToUTC(o.Date)
77
- }))
78
-
79
- const lastItem = parsedData[parsedData.length - 1]
80
- const lastDay = new Date(lastItem.utcTimestamp);
81
- lastDay.setUTCHours(0, 0, 0, 0)
82
- const lastTimeStamp = lastDay.getTime()
83
-
84
- const filteredData = parsedData.filter(o => o.utcTimestamp < lastTimeStamp)
85
-
86
- return filteredData;
87
- }
88
-
89
-
90
- const convertNyMillisecondsToUtc = milliseconds => {
91
- // Create a new Date object using the milliseconds
92
- const nyDate = new Date(milliseconds);
93
-
94
- // Calculate the timezone offset in milliseconds (New York is UTC-5 or UTC-4 during Daylight Saving Time)
95
- const offset = nyDate.getTimezoneOffset() * 60000;
96
-
97
- // Create a new Date object in UTC by subtracting the offset
98
- const utcDate = new Date(milliseconds + offset);
99
-
100
- // Get the UTC milliseconds
101
- const utcMilliseconds = utcDate.getTime();
102
-
103
- // Get individual components of the date
104
- const year = utcDate.getUTCFullYear();
105
- const month = String(utcDate.getUTCMonth() + 1).padStart(2, '0'); // Months are zero-indexed, so add 1
106
- const day = String(utcDate.getUTCDate()).padStart(2, '0');
107
- const hours = String(utcDate.getUTCHours()).padStart(2, '0');
108
- const minutes = String(utcDate.getUTCMinutes()).padStart(2, '0');
109
- const seconds = String(utcDate.getUTCSeconds()).padStart(2, '0');
110
-
111
- // Format the date string
112
- const utcDateString = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
113
-
114
- // Return the result as an object
115
- return {
116
- utcTimestamp: utcMilliseconds,
117
- utcDate: utcDateString
118
- };
119
- }
120
-
121
-
122
- function convertNYDateStringToUTC(dateString) {
123
- // Create a date object in the New York timezone
124
- const nyDate = new Date(dateString + ' GMT-0400');
125
-
126
- // Get the UTC date string
127
- const utcDateString = nyDate.toISOString().replace('T', ' ').substring(0, 19);
128
-
129
- // Get the UTC timestamp
130
- const utcTimestamp = nyDate.getTime();
131
-
132
- return {
133
- utcDateString: utcDateString,
134
- utcTimestamp: utcTimestamp
135
- };
136
- }
137
-
138
-
139
- export const convertToOHLCV = (data, intervalMinutes) => {
140
- const validMinuteIntervals = [5, 10, 15, 30, 45, 60, 120, 180, 240];
141
-
142
- if (!validMinuteIntervals.includes(intervalMinutes)) {
143
- const errMessage = `Invalid interval. Please use any of the following intervals: ${validMinuteIntervals.join(", ")}`;
144
- throw Error(errMessage);
145
- }
146
-
147
- const result = [];
148
- let tempGroup = [];
149
- let currentIntervalStart = null;
150
-
151
- data.forEach(item => {
152
- if (!currentIntervalStart) {
153
- currentIntervalStart = item.utcTimestamp;
154
- }
155
-
156
- if ((item.utcTimestamp - currentIntervalStart) < intervalMinutes * 60000) {
157
- tempGroup.push(item);
158
- } else {
159
- result.push(calculateOHLCV(tempGroup));
160
- tempGroup = [item];
161
- currentIntervalStart = item.utcTimestamp;
162
- }
163
- });
164
-
165
- if (tempGroup.length) {
166
- result.push(calculateOHLCV(tempGroup));
167
- }
168
-
169
- return result;
170
- };
171
-
172
- const calculateOHLCV = (group) => {
173
- const open = group[0].value;
174
- const close = group[group.length - 1].value;
175
- const high = Math.max(...group.map(item => item.value));
176
- const low = Math.min(...group.map(item => item.value));
177
- const volume = group[group.length - 1].volume;
178
- const utcDateString = group[group.length - 1].utcDateString;
179
- const utcTimestamp = group[group.length - 1].utcTimestamp;
180
-
181
- return { open, high, low, close, volume, utcDateString, utcTimestamp };
182
- };
183
-
55
+ }
package/test/test.js CHANGED
@@ -1,39 +1,32 @@
1
1
  import OHLCV_INDICATORS from '../index.js'
2
- import { getOHLCV, fetchHistoricalOHLCV , getLatestOHLCV, convertToOHLCV} from './fetchLiveData.js'
2
+ import { getOHLCV } from './fetchLiveData.js'
3
3
 
4
4
  const indicators = new OHLCV_INDICATORS();
5
- const {BigNumber} = indicators
5
+ const {BigNumber, VolumeProfile} = indicators
6
6
 
7
7
  const TEST = async () => {
8
8
 
9
-
10
-
11
- //console.log(await getLatestOHLCV('NVDA'))
12
-
13
- //const historical = convertToOHLCV(await fetchHistoricalOHLCV({symbol: 'NVDA', days: 15}), 5)
14
- //console.log(historical.length)
15
- //console.log(historical[0])
16
- //console.log(historical[historical.length - 1])
17
- //return
18
-
19
-
20
9
  const ohlcv = await getOHLCV('AAPL', 230)
21
10
 
22
11
  indicators
23
12
  .init(ohlcv)
24
- .EMA(21)
25
- .EMA(9, 'ema21')
26
- .SMA(200)
27
- .SMA(100, 'sma_200')
28
- .MACD(12, 26, 9)
29
- .BollingerBands(20, 2)
30
- .IchimokuCloud(9, 26, 52)
31
- .RSI(14, 14)
32
- .MFI(14)
33
- .RelativeVolume(10)
34
- .crossPairs([{fast: 'ema_9', slow: 'ema_21'}, {fast: 'close', slow: 'sma_200'}])
13
+ //.EMA(21)
14
+ //.EMA(9, 'ema21')
15
+ //.SMA(200)
16
+ //.SMA(100, 'sma_200')
17
+ //.MACD(12, 26, 9)
18
+ //.BollingerBands(20, 2)
19
+ //.IchimokuCloud(9, 26, 52)
20
+ //.RSI(14)
21
+ //.MFI(14)
22
+ //.RelativeVolume(10)
23
+ //.RelativeVolume(20)
24
+ //.crossPairs([{fast: 'ema_9', slow: 'ema_21'}, {fast: 'close', slow: 'sma_200'}, {fast: 'rsi_14', slow: 30}])
35
25
 
36
26
  const dataSet = indicators.getData()
27
+ const vp = VolumeProfile(BigNumber, dataSet)
28
+
29
+ console.log(vp)
37
30
 
38
31
 
39
32
  for(let k in dataSet)
@@ -58,7 +51,7 @@ const TEST = async () => {
58
51
  //console.log('<<<<<<<<<< HEADERS >>>>>>>>>>')
59
52
  //console.log(indicators.getHeaders())
60
53
 
61
- console.log(indicators.getLastValues())
54
+ //console.log(indicators.getLastValues())
62
55
  }
63
56
 
64
57
  TEST()