pinets 0.1.34 → 0.2.1
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/README.md +12 -5
- package/dist/pinets.dev.browser.js +639 -484
- package/dist/pinets.dev.cjs +639 -484
- package/dist/pinets.dev.cjs.map +1 -1
- package/dist/pinets.dev.es.js +637 -482
- package/dist/pinets.dev.es.js.map +1 -1
- package/dist/pinets.min.browser.js +12 -12
- package/dist/pinets.min.cjs +12 -12
- package/dist/pinets.min.es.js +2 -2
- package/dist/types/Context.class.d.ts +1 -0
- package/dist/types/PineTS.class.d.ts +0 -3
- package/dist/types/marketData/Binance/BinanceProvider.class.d.ts +4 -0
- package/dist/types/namespaces/PineMath.d.ts +1 -0
- package/dist/types/namespaces/TechnicalAnalysis.d.ts +19 -19
- package/dist/types/transpiler/ScopeManager.class.d.ts +3 -0
- package/package.json +1 -1
package/dist/pinets.min.es.js
CHANGED
|
@@ -15,5 +15,5 @@
|
|
|
15
15
|
* You should have received a copy of the GNU Affero General Public License
|
|
16
16
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
|
-
import*as
|
|
19
|
-
const b="$",B={type:"Identifier",name:"undefined"};function C(n,e){if(n.computed&&n.property.type==="Identifier"){if(e.isLoopVariable(n.property.name))return;if(!e.isContextBound(n.property.name)){const[t,r]=e.getVariable(n.property.name);n.property={type:"MemberExpression",object:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:r},computed:!1},property:{type:"Identifier",name:t},computed:!1},n.property={type:"MemberExpression",object:n.property,property:{type:"Literal",value:0},computed:!0}}}if(n.computed&&n.object.type==="Identifier"){if(e.isLoopVariable(n.object.name))return;if(!e.isContextBound(n.object.name)){const[t,r]=e.getVariable(n.object.name);n.object={type:"MemberExpression",object:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:r},computed:!1},property:{type:"Identifier",name:t},computed:!1}}if(n.property.type==="MemberExpression"){const t=n.property;t._indexTransformed||(C(t,e),t._indexTransformed=!0)}}}function N(n,e,t){if(n.object&&n.object.type==="Identifier"&&n.object.name==="Math")return;const r=t.getCurrentScopeType()=="if",a=t.getCurrentScopeType()=="els",i=t.getCurrentScopeType()=="for";!r&&!a&&!i&&n.object&&n.object.type==="Identifier"&&t.isContextBound(n.object.name)&&!t.isRootParam(n.object.name)||n._indexTransformed||(C(n,t),n._indexTransformed=!0)}function O(n,e){n.declarations.forEach(t=>{t.init.name=="na"&&(t.init.name="NaN");const r=t.init&&t.init.type==="MemberExpression"&&t.init.object&&(t.init.object.name==="context"||t.init.object.name===b||t.init.object.name==="context2"),a=t.init&&t.init.type==="MemberExpression"&&t.init.object?.object&&(t.init.object.object.name==="context"||t.init.object.object.name===b||t.init.object.object.name==="context2"),i=t.init&&t.init.type==="ArrowFunctionExpression";if(r){t.id.name&&e.addContextBoundVar(t.id.name),t.id.properties&&t.id.properties.forEach(p=>{p.key.name&&e.addContextBoundVar(p.key.name)}),t.init.object.name=b;return}if(a){t.id.name&&e.addContextBoundVar(t.id.name),t.id.properties&&t.id.properties.forEach(p=>{p.key.name&&e.addContextBoundVar(p.key.name)}),t.init.object.object.name=b;return}i&&t.init.params.forEach(p=>{p.type==="Identifier"&&e.addContextBoundVar(p.name)});const s=e.addVariable(t.id.name,n.kind),o=n.kind;t.init&&!i&&(t.init.type==="CallExpression"&&t.init.callee.type==="MemberExpression"&&t.init.callee.object&&t.init.callee.object.type==="Identifier"&&e.isContextBound(t.init.callee.object.name)?I(t.init,e):g.recursive(t.init,{parent:t.init},{Identifier(p,u){p.parent=u.parent,w(p,e);const f=p.parent&&p.parent.type==="BinaryExpression",m=p.parent&&p.parent.type==="ConditionalExpression";p.type==="Identifier"&&(f||m)&&Object.assign(p,{type:"MemberExpression",object:{type:"Identifier",name:p.name},property:{type:"Literal",value:0},computed:!0})},CallExpression(p,u,f){p.callee.type==="Identifier"&&(p.callee.parent=p),p.arguments.forEach(m=>{m.type==="Identifier"&&(m.parent=p)}),I(p,e),p.arguments.forEach(m=>f(m,{parent:p}))},BinaryExpression(p,u,f){p.left.type==="Identifier"&&(p.left.parent=p),p.right.type==="Identifier"&&(p.right.parent=p),f(p.left,{parent:p}),f(p.right,{parent:p})},MemberExpression(p,u,f){p.object.type==="Identifier"&&(p.object.parent=p),p.property.type==="Identifier"&&(p.property.parent=p),C(p,e),p.object&&f(p.object,{parent:p})}}));const c={type:"MemberExpression",object:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:o},computed:!1},property:{type:"Identifier",name:s},computed:!1},l=e.isArrayPatternElement(t.id.name),y=!l&&t.init&&t.init.type==="MemberExpression"&&t.init.computed&&t.init.property&&(t.init.property.type==="Literal"||t.init.property.type==="MemberExpression");t.init?.property?.type==="MemberExpression"&&(t.init.property._indexTransformed||(C(t.init.property,e),t.init.property._indexTransformed=!0));const h={type:"ExpressionStatement",expression:{type:"AssignmentExpression",operator:"=",left:c,right:t.init?i||l?t.init:{type:"CallExpression",callee:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:"init"},computed:!1},arguments:y?[c,t.init.object,t.init.property]:[c,t.init]}:{type:"Identifier",name:"undefined"}}};if(l){h.expression.right.object.property.name+=`?.[0][${t.init.property.value}]`;const p=h.expression.right.object;h.expression.right={type:"CallExpression",callee:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:"init"},computed:!1},arguments:[c,p]}}i&&(e.pushScope("fn"),g.recursive(t.init.body,e,{BlockStatement(p,u,f){p.body.forEach(m=>f(m,u))},IfStatement(p,u,f){u.pushScope("if"),f(p.consequent,u),p.alternate&&(u.pushScope("els"),f(p.alternate,u),u.popScope()),u.popScope()},VariableDeclaration(p,u){O(p,u)},Identifier(p,u){w(p,u)},AssignmentExpression(p,u){L(p,u)}}),e.popScope()),Object.assign(n,h)})}function w(n,e){if(n.name!==b){if(n.name==="Math"||n.name==="NaN"||n.name==="undefined"||n.name==="Infinity"||n.name==="null"||n.name.startsWith("'")&&n.name.endsWith("'")||n.name.startsWith('"')&&n.name.endsWith('"')||n.name.startsWith("`")&&n.name.endsWith("`")||e.isLoopVariable(n.name)||e.isContextBound(n.name)&&!e.isRootParam(n.name))return;const t=n.parent&&n.parent.type==="MemberExpression"&&n.parent.object===n&&e.isContextBound(n.name),r=n.parent&&n.parent.type==="CallExpression"&&n.parent.callee&&n.parent.callee.type==="MemberExpression"&&n.parent.callee.property.name==="param";n.parent&&n.parent.type==="AssignmentExpression"&&n.parent.left;const a=n.parent&&n.parent.type==="CallExpression"&&n.parent.callee&&n.parent.callee.type==="MemberExpression"&&e.isContextBound(n.parent.callee.object.name),i=n.parent&&n.parent.type==="MemberExpression"&&n.parent.computed,s=n.parent&&n.parent.type==="MemberExpression"&&n.parent.computed&&n.parent.property===n&&n.parent.parent&&n.parent.parent.type==="CallExpression"&&n.parent.parent.callee&&n.parent.parent.callee.type==="MemberExpression"&&e.isContextBound(n.parent.parent.callee.object.name),o=n.parent&&n.parent.type==="CallExpression"&&n.parent.callee===n;if(t||r||a||s||o){if(o)return;const[h,p]=e.getVariable(n.name);Object.assign(n,{type:"MemberExpression",object:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:p},computed:!1},property:{type:"Identifier",name:h},computed:!1});return}const[c,l]=e.getVariable(n.name),y={type:"MemberExpression",object:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:l},computed:!1},property:{type:"Identifier",name:c},computed:!1};!(n.parent&&n.parent.type==="MemberExpression"&&n.parent.computed&&n.parent.object===n)&&!i?Object.assign(n,{type:"MemberExpression",object:y,property:{type:"Literal",value:0},computed:!0}):Object.assign(n,y)}}function L(n,e){if(n.left.type==="Identifier"){const[t,r]=e.getVariable(n.left.name),a={type:"MemberExpression",object:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:r},computed:!1},property:{type:"Identifier",name:t},computed:!1};n.left={type:"MemberExpression",object:a,property:{type:"Literal",value:0},computed:!0}}g.recursive(n.right,{parent:n.right,inNamespaceCall:!1},{Identifier(t,r,a){t.name=="na"&&(t.name="NaN"),t.parent=r.parent,w(t,e);const i=t.parent&&t.parent.type==="BinaryExpression",s=t.parent&&t.parent.type==="ConditionalExpression",o=e.isContextBound(t.name)&&!e.isRootParam(t.name),c=t.parent&&t.parent.type==="MemberExpression"&&t.parent.computed&&t.parent.object===t,l=t.parent&&t.parent._isParamCall,y=t.parent&&t.parent.type==="MemberExpression",h=t.name==="NaN";(o||s||i)&&(t.type==="MemberExpression"?C(t,e):t.type==="Identifier"&&!y&&!c&&!l&&!h&&$(t))},MemberExpression(t,r,a){C(t,e),t.object&&a(t.object,{parent:t,inNamespaceCall:r.inNamespaceCall})},CallExpression(t,r,a){const i=t.callee&&t.callee.type==="MemberExpression"&&t.callee.object&&t.callee.object.type==="Identifier"&&e.isContextBound(t.callee.object.name);I(t,e),t.arguments.forEach(s=>a(s,{parent:t,inNamespaceCall:i||r.inNamespaceCall}))}})}function ee(n,e,t=!1){n.params.forEach(r=>{r.type==="Identifier"&&e.addContextBoundVar(r.name,t)})}function W(n,e){const t=e.getCurrentScopeType();if(n.argument){if(n.argument.type==="ArrayExpression")n.argument.elements=n.argument.elements.map(r=>{if(r.type==="Identifier"){if(e.isContextBound(r.name)&&!e.isRootParam(r.name))return{type:"MemberExpression",object:r,property:{type:"Literal",value:0},computed:!0};const[a,i]=e.getVariable(r.name);return{type:"MemberExpression",object:{type:"MemberExpression",object:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:i},computed:!1},property:{type:"Identifier",name:a},computed:!1},property:{type:"Literal",value:0},computed:!0}}else if(r.type==="MemberExpression")return r.computed&&r.object.type==="Identifier"&&e.isContextBound(r.object.name)&&!e.isRootParam(r.object.name)||N(r,"",e),r;return r}),n.argument={type:"ArrayExpression",elements:[n.argument]};else if(n.argument.type==="BinaryExpression")g.recursive(n.argument,e,{Identifier(r,a){w(r,a),r.type==="Identifier"&&$(r)},MemberExpression(r){N(r,"",e)}});else if(n.argument.type==="ObjectExpression")n.argument.properties=n.argument.properties.map(r=>{if(r.shorthand){const[a,i]=e.getVariable(r.value.name);return{type:"Property",key:{type:"Identifier",name:r.key.name},value:{type:"MemberExpression",object:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:i},computed:!1},property:{type:"Identifier",name:a},computed:!1},kind:"init",method:!1,shorthand:!1,computed:!1}}return r});else if(n.argument.type==="Identifier"){const[r,a]=e.getVariable(n.argument.name);n.argument={type:"MemberExpression",object:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:a},computed:!1},property:{type:"Identifier",name:r},computed:!1},n.argument={type:"MemberExpression",object:n.argument,property:{type:"Literal",value:0},computed:!0}}t==="fn"&&(n.argument={type:"CallExpression",callee:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:"precision"}},arguments:[n.argument]})}}function V(n,e){if(n.type==="Identifier"){if(n.name==="na")return n.name="NaN",n;if(e.isLoopVariable(n.name))return n;if(e.isRootParam(n.name)){const[a,i]=e.getVariable(n.name);return{type:"MemberExpression",object:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:i},computed:!1},property:{type:"Identifier",name:a},computed:!1}}if(e.isContextBound(n.name))return n;const[t,r]=e.getVariable(n.name);return{type:"MemberExpression",object:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:r},computed:!1},property:{type:"Identifier",name:t},computed:!1}}return n}function U(n,e,t){const r=k(n.argument,e,t);return{type:"UnaryExpression",operator:n.operator,prefix:n.prefix,argument:r,start:n.start,end:n.end}}function k(n,e,t=""){switch(n.type){case"BinaryExpression":return z(n,e,t);case"MemberExpression":return{type:"MemberExpression",object:n.object.type==="Identifier"?V(n.object,e):n.object,property:n.property,computed:n.computed};case"Identifier":return e.isLoopVariable(n.name)||n.parent&&n.parent.type==="MemberExpression"&&n.parent.property===n?n:{type:"MemberExpression",object:V(n,e),property:{type:"Literal",value:0},computed:!0};case"UnaryExpression":return U(n,e,t)}return n}function z(n,e,t){const r=k(n.left,e,t),a=k(n.right,e,t),i={type:"BinaryExpression",operator:n.operator,left:r,right:a,start:n.start,end:n.end};return g.recursive(i,e,{CallExpression(s,o){s._transformed||I(s,o)},MemberExpression(s){N(s,"",e)}}),i}function te(n,e,t){const r=k(n.left,e,t),a=k(n.right,e,t),i={type:"LogicalExpression",operator:n.operator,left:r,right:a,start:n.start,end:n.end};return g.recursive(i,e,{CallExpression(s,o){s._transformed||I(s,o)}}),i}function re(n,e,t){return g.recursive(n,{parent:n,inNamespaceCall:!1},{Identifier(r,a,i){if(r.name=="NaN")return;if(r.name=="na"){r.name="NaN";return}r.parent=a.parent,w(r,e);const s=r.parent&&r.parent.type==="BinaryExpression";(r.parent&&r.parent.type==="ConditionalExpression"||s)&&(r.type==="MemberExpression"?C(r,e):r.type==="Identifier"&&$(r))},MemberExpression(r,a,i){C(r,e),r.object&&i(r.object,{parent:r,inNamespaceCall:a.inNamespaceCall})},CallExpression(r,a,i){const s=r.callee&&r.callee.type==="MemberExpression"&&r.callee.object&&r.callee.object.type==="Identifier"&&e.isContextBound(r.callee.object.name);I(r,e),r.arguments.forEach(o=>i(o,{parent:r,inNamespaceCall:s||a.inNamespaceCall}))}}),{type:"CallExpression",callee:{type:"MemberExpression",object:{type:"Identifier",name:t},property:{type:"Identifier",name:"param"}},arguments:[n,B,e.nextParamIdArg],_transformed:!0,_isParamCall:!0}}function F(n,e,t){switch(n?.type){case"BinaryExpression":n=z(n,t,e);break;case"LogicalExpression":n=te(n,t,e);break;case"ConditionalExpression":return re(n,t,e);case"UnaryExpression":n=U(n,t,e);break}if(n.type==="MemberExpression"&&n.computed&&n.property){const r=n.object.type==="Identifier"&&t.isContextBound(n.object.name)&&!t.isRootParam(n.object.name)?n.object:V(n.object,t),a=n.property.type==="Identifier"&&!t.isContextBound(n.property.name)&&!t.isLoopVariable(n.property.name)?V(n.property,t):n.property;return{type:"CallExpression",callee:{type:"MemberExpression",object:{type:"Identifier",name:e},property:{type:"Identifier",name:"param"},computed:!1},arguments:[r,a,t.nextParamIdArg],_transformed:!0,_isParamCall:!0}}if(n.type==="ObjectExpression"&&(n.properties=n.properties.map(r=>{if(r.value.name){const[a,i]=t.getVariable(r.value.name);return{type:"Property",key:{type:"Identifier",name:r.key.name},value:{type:"MemberExpression",object:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:i},computed:!1},property:{type:"Identifier",name:a},computed:!1},kind:"init",method:!1,shorthand:!1,computed:!1}}return r})),n.type==="Identifier"){if(n.name==="na")return n.name="NaN",n;if(t.isContextBound(n.name)&&!t.isRootParam(n.name))return{type:"CallExpression",callee:{type:"MemberExpression",object:{type:"Identifier",name:e},property:{type:"Identifier",name:"param"},computed:!1},arguments:[n,B,t.nextParamIdArg],_transformed:!0,_isParamCall:!0}}return n?.type==="CallExpression"&&I(n,t),{type:"CallExpression",callee:{type:"MemberExpression",object:{type:"Identifier",name:e},property:{type:"Identifier",name:"param"},computed:!1},arguments:[n.type==="Identifier"?V(n,t):n,B,t.nextParamIdArg],_transformed:!0,_isParamCall:!0}}function I(n,e,t){if(!n._transformed){if(n.callee&&n.callee.type==="MemberExpression"&&n.callee.object&&n.callee.object.type==="Identifier"&&(e.isContextBound(n.callee.object.name)||n.callee.object.name==="math"||n.callee.object.name==="ta")){const r=n.callee.object.name;n.arguments=n.arguments.map(a=>a._isParamCall?a:F(a,r,e)),n._transformed=!0}else n.callee&&n.callee.type==="Identifier"&&(n.arguments=n.arguments.map(r=>r._isParamCall?r:F(r,b,e)),n._transformed=!0);n.arguments.forEach(r=>{g.recursive(r,e,{Identifier(a,i,s){a.parent=i.parent,w(a,e);const o=a.parent&&a.parent.type==="BinaryExpression";(a.parent&&a.parent.type==="ConditionalExpression"||o)&&(a.type==="MemberExpression"?C(a,e):a.type==="Identifier"&&$(a))},CallExpression(a,i,s){a._transformed||I(a,i)},MemberExpression(a,i,s){N(a,"",e),a.object&&s(a.object,{parent:a,inNamespaceCall:i.inNamespaceCall})}})})}}function ne(n,e){n.params.forEach(t=>{t.type==="Identifier"&&e.addContextBoundVar(t.name,!1)}),n.body&&n.body.type==="BlockStatement"&&(e.pushScope("fn"),g.recursive(n.body,e,{BlockStatement(t,r,a){t.body.forEach(i=>a(i,r))},ReturnStatement(t,r){W(t,r)},VariableDeclaration(t,r){O(t,r)},Identifier(t,r){w(t,r)},CallExpression(t,r){I(t,r),t.arguments.forEach(a=>{a.type==="BinaryExpression"&&g.recursive(a,r,{CallExpression(i,s){I(i,s)},MemberExpression(i){N(i,"",r)}})})},MemberExpression(t){N(t,"",e)},AssignmentExpression(t,r){L(t,r)},ForStatement(t,r,a){K(t,r,a)},IfStatement(t,r,a){H(t,r,a)},BinaryExpression(t,r,a){g.recursive(t,r,{CallExpression(i,s){I(i,s)},MemberExpression(i){N(i,"",r)}})}}),e.popScope())}function $(n,e){Object.assign(n,{type:"MemberExpression",object:{type:"Identifier",name:n.name,start:n.start,end:n.end},property:{type:"Literal",value:0},computed:!0,_indexTransformed:!0})}function K(n,e,t){if(n.init&&n.init.type==="VariableDeclaration"){const r=n.init.declarations[0],a=r.id.name;e.addLoopVariable(a,a),n.init={type:"VariableDeclaration",kind:n.init.kind,declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:a},init:r.init}]},r.init&&g.recursive(r.init,e,{Identifier(i,s){e.isLoopVariable(i.name)||(e.pushScope("for"),w(i,s),e.popScope())},MemberExpression(i){e.pushScope("for"),N(i,"",e),e.popScope()}})}n.test&&g.recursive(n.test,e,{Identifier(r,a){!e.isLoopVariable(r.name)&&!r.computed&&(e.pushScope("for"),w(r,a),r.type==="Identifier"&&(r.computed=!0,$(r)),e.popScope())},MemberExpression(r){e.pushScope("for"),N(r,"",e),e.popScope()}}),n.update&&g.recursive(n.update,e,{Identifier(r,a){e.isLoopVariable(r.name)||(e.pushScope("for"),w(r,a),e.popScope())}}),e.pushScope("for"),t(n.body,e),e.popScope()}function ae(n,e){g.recursive(n,e,{MemberExpression(t){N(t,"",e)},CallExpression(t,r){I(t,r)},Identifier(t,r){w(t,r);const a=e.getCurrentScopeType()==="if";e.isContextBound(t.name)&&!e.isRootParam(t.name)&&a&&$(t)}})}function H(n,e,t){n.test&&(e.pushScope("if"),ae(n.test,e),e.popScope()),e.pushScope("if"),t(n.consequent,e),e.popScope(),n.alternate&&(e.pushScope("els"),t(n.alternate,e),e.popScope())}function ie(n){g.recursive(n,null,{VariableDeclaration(e,t,r){e.declarations&&e.declarations.length>0&&e.declarations.forEach(a=>{if(a.init&&a.init.type==="ArrowFunctionExpression"&&a.init.start!==0){const i={type:"FunctionDeclaration",id:a.id,params:a.init.params,body:a.init.body.type==="BlockStatement"?a.init.body:{type:"BlockStatement",body:[{type:"ReturnStatement",argument:a.init.body}]},async:a.init.async,generator:!1};Object.assign(e,i)}}),e.body&&e.body.body&&e.body.body.forEach(a=>r(a,t))}})}function se(n,e){g.simple(n,{VariableDeclaration(t){t.declarations.forEach(r=>{const a=r.init&&r.init.type==="MemberExpression"&&r.init.object&&(r.init.object.name==="context"||r.init.object.name===b||r.init.object.name==="context2"),i=r.init&&r.init.type==="MemberExpression"&&r.init.object?.object&&(r.init.object.object.name==="context"||r.init.object.object.name===b||r.init.object.object.name==="context2");(a||i)&&(r.id.name&&e.addContextBoundVar(r.id.name),r.id.properties&&r.id.properties.forEach(s=>{s.key.name&&e.addContextBoundVar(s.key.name)}))})}})}function oe(n){let e=typeof n=="function"?n.toString():n;const t=X.parse(e.trim(),{ecmaVersion:"latest",sourceType:"module"});ie(t);const r=new Z;let a;se(t,r),g.simple(t,{FunctionDeclaration(s){ne(s,r)},ArrowFunctionExpression(s){const o=s.start===0;o&&s.params&&s.params.length>0&&(a=s.params[0].name,s.params[0].name=b),ee(s,r,o)},VariableDeclaration(s){s.declarations.forEach(o=>{if(o.id.type==="ArrayPattern"){const c=r.generateTempVar(),l={type:"VariableDeclaration",kind:s.kind,declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:c},init:o.init}]};o.id.elements?.forEach(h=>{h.type==="Identifier"&&r.addArrayPatternElement(h.name)});const y=o.id.elements.map((h,p)=>({type:"VariableDeclaration",kind:s.kind,declarations:[{type:"VariableDeclarator",id:h,init:{type:"MemberExpression",object:{type:"Identifier",name:c},property:{type:"Literal",value:p},computed:!0}}]}));Object.assign(s,{type:"BlockStatement",body:[l,...y]})}})},ForStatement(s){}}),g.recursive(t,r,{BlockStatement(s,o,c){s.body.forEach(l=>c(l,o))},ReturnStatement(s,o){W(s,o)},VariableDeclaration(s,o){O(s,o)},Identifier(s,o){w(s,o)},CallExpression(s,o){I(s,o)},MemberExpression(s){N(s,a,r)},AssignmentExpression(s,o){L(s,o)},FunctionDeclaration(s,o){},ForStatement(s,o,c){K(s,o,c)},IfStatement(s,o,c){H(s,o,c)}});const i=Y.generate(t);return new Function("",`return ${i}`)(this)}var pe=Object.defineProperty,ce=(n,e,t)=>e in n?pe(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,A=(n,e,t)=>ce(n,typeof e!="symbol"?e+"":e,t);class le{constructor(e,t,r,a,i,s){this.source=e,this.tickerId=t,this.timeframe=r,this.limit=a,this.sDate=i,this.eDate=s,A(this,"data",[]),A(this,"open",[]),A(this,"high",[]),A(this,"low",[]),A(this,"close",[]),A(this,"volume",[]),A(this,"hl2",[]),A(this,"hlc3",[]),A(this,"ohlc4",[]),A(this,"openTime",[]),A(this,"closeTime",[]),A(this,"_periods"),A(this,"_readyPromise",null),A(this,"_ready",!1),this._readyPromise=new Promise(o=>{this.loadMarketData(e,t,r,a,i,s).then(c=>{const l=c.reverse();this._periods=l.length,this.data=l;const y=l.map(d=>d.open),h=l.map(d=>d.close),p=l.map(d=>d.high),u=l.map(d=>d.low),f=l.map(d=>d.volume),m=l.map(d=>(d.high+d.low+d.close)/3),v=l.map(d=>(d.high+d.low)/2),j=l.map(d=>(d.high+d.low+d.open+d.close)/4),P=l.map(d=>d.openTime),S=l.map(d=>d.closeTime);this.open=y,this.close=h,this.high=p,this.low=u,this.volume=f,this.hl2=v,this.hlc3=m,this.ohlc4=j,this.openTime=P,this.closeTime=S,this._ready=!0,o(!0)})})}get periods(){return this._periods}async loadMarketData(e,t,r,a,i,s){return Array.isArray(e)?e:e.getMarketData(t,r,a,i,s)}async ready(){if(this._ready)return!0;if(!this._readyPromise)throw new Error("PineTS is not ready");return this._readyPromise}async run(e,t,r){await this.ready(),t||(t=this._periods);const a=new Ye({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate});a.pineTSCode=e,a.useTACache=r;let i=oe.bind(this)(e);const s=["const","var","let","params"];for(let o=this._periods-t,c=t-1;o<this._periods;o++,c--){a.idx=o,a.data.close=this.close.slice(c),a.data.open=this.open.slice(c),a.data.high=this.high.slice(c),a.data.low=this.low.slice(c),a.data.volume=this.volume.slice(c),a.data.hl2=this.hl2.slice(c),a.data.hlc3=this.hlc3.slice(c),a.data.ohlc4=this.ohlc4.slice(c),a.data.openTime=this.openTime.slice(c),a.data.closeTime=this.closeTime.slice(c);const l=await i(a);if(typeof l=="object"){typeof a.result!="object"&&(a.result={});for(let y in l){a.result[y]===void 0&&(a.result[y]=[]);const h=Array.isArray(l[y])?l[y][0]:l[y];a.result[y].push(h)}}else Array.isArray(a.result)||(a.result=[]),a.result.push(l);for(let y of s)for(let h in a[y])if(Array.isArray(a[y][h])){const p=a[y][h][0];a[y][h].unshift(p)}}return a}}var me=Object.defineProperty,ye=(n,e,t)=>e in n?me(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,he=(n,e,t)=>ye(n,typeof e!="symbol"?e+"":e,t);class ue{constructor(e){this.context=e,he(this,"color",{param:(t,r=0)=>Array.isArray(t)?t[r]:t,rgb:(t,r,a,i)=>i?`rgba(${t}, ${r}, ${a}, ${i})`:`rgb(${t}, ${r}, ${a})`,new:(t,r)=>{if(t&&t.startsWith("#")){const a=t.slice(1),i=parseInt(a.slice(0,2),16),s=parseInt(a.slice(2,4),16),o=parseInt(a.slice(4,6),16);return r?`rgba(${i}, ${s}, ${o}, ${r})`:`rgb(${i}, ${s}, ${o})`}return r?`rgba(${t}, ${r})`:t},white:"white",lime:"lime",green:"green",red:"red",maroon:"maroon",black:"black",gray:"gray",blue:"blue"})}extractPlotOptions(e){const t={};for(let r in e)Array.isArray(e[r])?t[r]=e[r][0]:t[r]=e[r];return t}indicator(e,t,r){}plotchar(e,t,r){this.context.plots[t]||(this.context.plots[t]={data:[],options:this.extractPlotOptions(r),title:t}),this.context.plots[t].data.push({time:this.context.marketData[this.context.marketData.length-this.context.idx-1].openTime,value:e[0],options:{...this.extractPlotOptions(r),style:"char"}})}plot(e,t,r){this.context.plots[t]||(this.context.plots[t]={data:[],options:this.extractPlotOptions(r),title:t}),this.context.plots[t].data.push({time:this.context.marketData[this.context.marketData.length-this.context.idx-1].openTime,value:e[0],options:this.extractPlotOptions(r)})}na(e){return Array.isArray(e)?isNaN(e[0]):isNaN(e)}nz(e,t=0){const r=Array.isArray(e)?e[0]:e,a=Array.isArray(e)?t[0]:t;return isNaN(r)?a:r}}class de{constructor(e){this.context=e}param(e,t=0){return Array.isArray(e)?[e[t]]:[e]}any(e,{title:t,group:r}={}){return Array.isArray(e)?e[0]:e}int(e,{title:t,group:r}={}){return Array.isArray(e)?e[0]:e}float(e,{title:t,group:r}={}){return Array.isArray(e)?e[0]:e}bool(e,{title:t,group:r}={}){return Array.isArray(e)?e[0]:e}string(e,{title:t,group:r}={}){return Array.isArray(e)?e[0]:e}timeframe(e,{title:t,group:r}={}){return Array.isArray(e)?e[0]:e}time(e,{title:t,group:r}={}){return Array.isArray(e)?e[0]:e}price(e,{title:t,group:r}={}){return Array.isArray(e)?e[0]:e}session(e,{title:t,group:r}={}){return Array.isArray(e)?e[0]:e}source(e,{title:t,group:r}={}){return Array.isArray(e)?e[0]:e}symbol(e,{title:t,group:r}={}){return Array.isArray(e)?e[0]:e}text_area(e,{title:t,group:r}={}){return Array.isArray(e)?e[0]:e}enum(e,{title:t,group:r}={}){return Array.isArray(e)?e[0]:e}color(e,{title:t,group:r}={}){return Array.isArray(e)?e[0]:e}}var fe=Object.defineProperty,xe=(n,e,t)=>e in n?fe(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,be=(n,e,t)=>xe(n,typeof e!="symbol"?e+"":e,t);class ge{constructor(e){this.context=e,be(this,"_cache",{})}param(e,t,r){return this.context.params[r]||(this.context.params[r]=[]),Array.isArray(e)?t?(this.context.params[r]=e.slice(t),this.context.params[r].length=e.length,this.context.params[r]):(this.context.params[r]=e.slice(0),this.context.params[r]):(this.context.params[r][0]=e,this.context.params[r])}abs(e){return Math.abs(e[0])}pow(e,t){return Math.pow(e[0],t[0])}sqrt(e){return Math.sqrt(e[0])}log(e){return Math.log(e[0])}ln(e){return Math.log(e[0])}exp(e){return Math.exp(e[0])}floor(e){return Math.floor(e[0])}ceil(e){return Math.ceil(e[0])}round(e){return Math.round(e[0])}random(){return Math.random()}max(...e){const t=e.map(r=>Array.isArray(r)?r[0]:r);return Math.max(...t)}min(...e){const t=e.map(r=>Array.isArray(r)?r[0]:r);return Math.min(...t)}sum(e,t){const r=Array.isArray(t)?t[0]:t;return Array.isArray(e)?e.slice(0,r).reduce((a,i)=>a+i,0):e}sin(e){return Math.sin(e[0])}cos(e){return Math.cos(e[0])}tan(e){return Math.tan(e[0])}acos(e){return Math.acos(e[0])}asin(e){return Math.asin(e[0])}atan(e){return Math.atan(e[0])}avg(...e){const t=e.map(r=>Array.isArray(r)?r[0]:r);return t.reduce((r,a)=>{const i=Array.isArray(r)?r[0]:r,s=Array.isArray(a)?a[0]:a;return i+s},0)/t.length}}var Ae=Object.defineProperty,Ee=(n,e,t)=>e in n?Ae(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,ve=(n,e,t)=>Ee(n,typeof e!="symbol"?e+"":e,t);const R=["1","3","5","15","30","45","60","120","180","240","D","W","M"];class je{constructor(e){this.context=e,ve(this,"_cache",{})}param(e,t,r){return this.context.params[r]||(this.context.params[r]=[]),Array.isArray(e)?(t?this.context.params[r]=e.slice(t):this.context.params[r]=e.slice(0),[e[t],r]):(this.context.params[r][0]=e,[e,r])}async security(e,t,r,a=!1,i=!1,s=!1,o=null,c=null){const l=e[0],y=t[0],h=r[0],p=r[1],u=R.indexOf(this.context.timeframe),f=R.indexOf(y);if(u==-1||f==-1)throw new Error("Invalid timeframe");if(u>f)throw new Error("Only higher timeframes are supported for now");if(u===f)return h;const m=this.context.data.openTime[0],v=this.context.data.closeTime[0];if(this.context.cache[p]){const S=this.context.cache[p],d=this._findSecContextIdx(m,v,S.data.openTime,S.data.closeTime,i);return d==-1?NaN:S.params[p][d]}const j=await new le(this.context.source,l,y,this.context.limit||1e3,this.context.sDate,this.context.eDate).run(this.context.pineTSCode);this.context.cache[p]=j;const P=this._findSecContextIdx(m,v,j.data.openTime,j.data.closeTime,i);return P==-1?NaN:j.params[p][P]}_findSecContextIdx(e,t,r,a,i=!1){for(let s=0;s<r.length;s++)if(r[s]<=e&&t<=a[s])return s+(i?1:2);return-1}}class Ie{constructor(e){this.context=e}get tr(){return this.context.math.max(this.context.data.high[0]-this.context.data.low[0],this.context.math.abs(this.context.data.high[0]-this.context.data.close[1]),this.context.math.abs(this.context.data.low[0]-this.context.data.close[1]))}param(e,t,r){return this.context.params[r]||(this.context.params[r]=[]),Array.isArray(e)?t?(this.context.params[r]=e.slice(t),this.context.params[r].length=e.length,this.context.params[r]):(this.context.params[r]=e.slice(0),this.context.params[r]):(this.context.params[r][0]=e,this.context.params[r])}ema(e,t){const r=Array.isArray(t)?t[0]:t,a=Me(e.slice(0).reverse(),r),i=this.context.idx;return this.context.precision(a[i])}sma(e,t,r){const a=Array.isArray(t)?t[0]:t,i=e.slice(0).reverse();if(this.context.useTACache&&r){this.context.cache[r]||(this.context.cache[r]={});const c=this.context.cache[r];if(c){const l=Ce(i,a,c),y=this.context.idx;return this.context.precision(l[y])}}const s=D(i,a),o=this.context.idx;return this.context.precision(s[o])}vwma(e,t){const r=Array.isArray(t)?t[0]:t,a=this.context.data.volume,i=$e(e.slice(0).reverse(),a.slice(0).reverse(),r),s=this.context.idx;return this.context.precision(i[s])}wma(e,t){const r=Array.isArray(t)?t[0]:t,a=T(e.slice(0).reverse(),r),i=this.context.idx;return this.context.precision(a[i])}hma(e,t){const r=Array.isArray(t)?t[0]:t,a=Se(e.slice(0).reverse(),r),i=this.context.idx;return this.context.precision(a[i])}rma(e,t){const r=Array.isArray(t)?t[0]:t,a=Ne(e.slice(0).reverse(),r),i=this.context.idx;return this.context.precision(a[i])}change(e,t=1){const r=Array.isArray(t)?t[0]:t,a=Ve(e.slice(0).reverse(),r),i=this.context.idx;return this.context.precision(a[i])}rsi(e,t){const r=Array.isArray(t)?t[0]:t,a=we(e.slice(0).reverse(),r),i=this.context.idx;return this.context.precision(a[i])}atr(e){const t=Array.isArray(e)?e[0]:e,r=this.context.data.high.slice().reverse(),a=this.context.data.low.slice().reverse(),i=this.context.data.close.slice().reverse(),s=Q(r,a,i,t),o=this.context.idx;return this.context.precision(s[o])}mom(e,t){const r=Array.isArray(t)?t[0]:t,a=ke(e.slice(0).reverse(),r),i=this.context.idx;return this.context.precision(a[i])}roc(e,t){const r=Array.isArray(t)?t[0]:t,a=Pe(e.slice(0).reverse(),r),i=this.context.idx;return this.context.precision(a[i])}dev(e,t){const r=Array.isArray(t)?t[0]:t,a=Te(e.slice(0).reverse(),r),i=this.context.idx;return this.context.precision(a[i])}variance(e,t){const r=Array.isArray(t)?t[0]:t,a=De(e.slice(0).reverse(),r),i=this.context.idx;return this.context.precision(a[i])}highest(e,t){const r=Array.isArray(t)?t[0]:t,a=Be(e.slice(0).reverse(),r),i=this.context.idx;return this.context.precision(a[i])}lowest(e,t){const r=Array.isArray(t)?t[0]:t,a=_e(e.slice(0).reverse(),r),i=this.context.idx;return this.context.precision(a[i])}median(e,t){const r=Array.isArray(t)?t[0]:t,a=Oe(e.slice(0).reverse(),r),i=this.context.idx;return this.context.precision(a[i])}stdev(e,t,r=!0){const a=Array.isArray(t)?t[0]:t,i=Array.isArray(r)?r[0]:r,s=Le(e.slice(0).reverse(),a,i),o=this.context.idx;return this.context.precision(s[o])}linreg(e,t,r){const a=Array.isArray(t)?t[0]:t,i=Array.isArray(r)?r[0]:r,s=Fe(e.slice(0).reverse(),a,i),o=this.context.idx;return this.context.precision(s[o])}supertrend(e,t){const r=Array.isArray(e)?e[0]:e,a=Array.isArray(t)?t[0]:t,i=this.context.data.high.slice().reverse(),s=this.context.data.low.slice().reverse(),o=this.context.data.close.slice().reverse(),[c,l]=Re(i,s,o,r,a),y=this.context.idx;return[[this.context.precision(c[y]),l[y]]]}crossover(e,t){const r=Array.isArray(e)?e[0]:e,a=Array.isArray(t)?t[0]:t,i=Array.isArray(e)?e[1]:this.context.data.series[e][1],s=Array.isArray(t)?t[1]:this.context.data.series[t][1];return i<s&&r>a}crossunder(e,t){const r=Array.isArray(e)?e[0]:e,a=Array.isArray(t)?t[0]:t,i=Array.isArray(e)?e[1]:this.context.data.series[e][1],s=Array.isArray(t)?t[1]:this.context.data.series[t][1];return i>s&&r<a}pivothigh(e,t,r){r==null&&(r=t,t=e,e=this.context.data.high);const a=Array.isArray(t)?t[0]:t,i=Array.isArray(r)?r[0]:r,s=qe(e.slice(0).reverse(),a,i),o=this.context.idx;return this.context.precision(s[o])}pivotlow(e,t,r){r==null&&(r=t,t=e,e=this.context.data.low);const a=Array.isArray(t)?t[0]:t,i=Array.isArray(r)?r[0]:r,s=We(e.slice(0).reverse(),a,i),o=this.context.idx;return this.context.precision(s[o])}}function Q(n,e,t,r){const a=new Array(n.length);a[0]=n[0]-e[0];for(let o=1;o<n.length;o++){const c=n[o]-e[o],l=Math.abs(n[o]-t[o-1]),y=Math.abs(e[o]-t[o-1]);a[o]=Math.max(c,l,y)}const i=new Array(n.length).fill(NaN);let s=0;for(let o=0;o<r;o++)s+=a[o];i[r-1]=s/r;for(let o=r;o<a.length;o++)i[o]=(i[o-1]*(r-1)+a[o])/r;return i}function Me(n,e){const t=new Array(n.length).fill(NaN),r=2/(e+1);let a=0;for(let i=0;i<e;i++)a+=n[i]||0;t[e-1]=a/e;for(let i=e;i<n.length;i++)t[i]=n[i]*r+t[i-1]*(1-r);return t}function we(n,e){const t=new Array(n.length).fill(NaN),r=new Array(n.length).fill(0),a=new Array(n.length).fill(0);for(let o=1;o<n.length;o++){const c=n[o]-n[o-1];r[o]=c>0?c:0,a[o]=c<0?-c:0}let i=0,s=0;for(let o=1;o<=e;o++)i+=r[o],s+=a[o];i/=e,s/=e,t[e]=s===0?100:100-100/(1+i/s);for(let o=e+1;o<n.length;o++)i=(i*(e-1)+r[o])/e,s=(s*(e-1)+a[o])/e,t[o]=s===0?100:100-100/(1+i/s);return t}function Ne(n,e){const t=new Array(n.length).fill(NaN),r=1/e;let a=0;for(let i=0;i<e;i++)a+=n[i]||0;t[e-1]=a/e;for(let i=e;i<n.length;i++){const s=n[i]||0;t[i]=s*r+t[i-1]*(1-r)}return t}function Ce(n,e,t){const r=t.previousResult||new Array(n.length).fill(NaN),a=t.lastProcessedIndex||-1;let i=t.previousSum||0;if(a===-1||n.length!==a+1){i=0;for(let s=0;s<e;s++)i+=n[s]||0;r[e-1]=i/e;for(let s=0;s<e-1;s++)r[s]=NaN;for(let s=e;s<n.length;s++)i=i-(n[s-e]||0)+(n[s]||0),r[s]=i/e}else if(n.length===a+2){const s=n.length-1;i=i-(n[s-e]||0)+(n[s]||0),r[s]=i/e}else return D(n,e);return t.previousSum=i,t.lastProcessedIndex=n.length-1,t.previousResult=r,r}function D(n,e){const t=new Array(n.length).fill(NaN);for(let r=e-1;r<n.length;r++){let a=0;for(let i=0;i<e;i++)a+=n[r-i]||0;t[r]=a/e}return t}function $e(n,e,t){const r=new Array(n.length).fill(NaN);for(let a=t-1;a<n.length;a++){let i=0,s=0;for(let o=0;o<t;o++)i+=e[a-o],s+=n[a-o]*e[a-o];r[a]=s/i}return r}function Se(n,e){const t=Math.floor(e/2),r=T(n,t),a=T(n,e),i=r.map((o,c)=>2*o-a[c]),s=Math.floor(Math.sqrt(e));return T(i,s)}function T(n,e){const t=new Array(n.length);for(let r=e-1;r<n.length;r++){let a=0,i=0;for(let s=0;s<e;s++)a+=n[r-s]*(e-s),i+=e-s;t[r]=a/i}for(let r=0;r<e-1;r++)t[r]=NaN;return t}function Ve(n,e=1){const t=new Array(n.length).fill(NaN);for(let r=e;r<n.length;r++)t[r]=n[r]-n[r-e];return t}function ke(n,e){const t=new Array(n.length).fill(NaN);for(let r=e;r<n.length;r++)t[r]=n[r]-n[r-e];return t}function Pe(n,e){const t=new Array(n.length).fill(NaN);for(let r=e;r<n.length;r++)t[r]=(n[r]-n[r-e])/n[r-e]*100;return t}function Te(n,e){const t=new Array(n.length).fill(NaN),r=D(n,e);for(let a=e-1;a<n.length;a++){let i=0;for(let s=0;s<e;s++)i+=Math.abs(n[a-s]-r[a]);t[a]=i/e}return t}function De(n,e){const t=new Array(n.length).fill(NaN);for(let r=e-1;r<n.length;r++){let a=0,i=0;for(let o=0;o<e;o++)a+=n[r-o],i+=n[r-o]*n[r-o];const s=a/e;t[r]=i/e-s*s}return t}function Be(n,e){const t=new Array(n.length).fill(NaN);for(let r=e-1;r<n.length;r++){let a=-1/0;for(let i=0;i<e;i++){const s=n[r-i];isNaN(s)?a=a===-1/0?NaN:a:a=Math.max(a,s)}t[r]=a}return t}function _e(n,e){const t=new Array(n.length).fill(NaN);for(let r=e-1;r<n.length;r++){let a=1/0;for(let i=0;i<e;i++){const s=n[r-i];isNaN(s)||s===void 0?a=a===1/0?NaN:a:a=Math.min(a,s)}t[r]=a}return t}function Oe(n,e){const t=new Array(n.length).fill(NaN);for(let r=e-1;r<n.length;r++){const a=n.slice(r-e+1,r+1).slice().sort((s,o)=>s-o),i=Math.floor(e/2);t[r]=e%2===0?(a[i-1]+a[i])/2:a[i]}return t}function Le(n,e,t=!0){const r=new Array(n.length).fill(NaN),a=D(n,e);for(let i=e-1;i<n.length;i++){let s=0;for(let c=0;c<e;c++)s+=Math.pow(n[i-c]-a[i],2);const o=t?e:e-1;r[i]=Math.sqrt(s/o)}return r}function Fe(n,e,t){const r=n.length,a=new Array(r).fill(NaN);for(let i=e-1;i<r;i++){let s=0,o=0,c=0,l=0;const y=e;for(let f=0;f<e;f++){const m=f,v=n[i-e+1+f];s+=m,o+=v,c+=m*v,l+=m*m}const h=y*l-s*s;if(h===0){a[i]=NaN;continue}const p=(y*c-s*o)/h,u=(o-p*s)/y+p*(e-1-t);a[i]=u}return a}function Re(n,e,t,r,a){const i=n.length,s=new Array(i).fill(NaN),o=new Array(i).fill(0),c=Q(n,e,t,a),l=new Array(i).fill(NaN),y=new Array(i).fill(NaN);for(let m=0;m<i;m++){const v=(n[m]+e[m])/2,j=c[m];isNaN(j)||(l[m]=v+r*j,y[m]=v-r*j)}let h=l[a],p=y[a],u=t[a]<=h?h:p,f=t[a]<=h?-1:1;s[a]=u,o[a]=f;for(let m=a+1;m<i;m++){let v=l[m];v<h||t[m-1]>h?l[m]=v:l[m]=h;let j=y[m];j>p||t[m-1]<p?y[m]=j:y[m]=p,u===h?t[m]>l[m]?(o[m]=1,s[m]=y[m]):(o[m]=-1,s[m]=l[m]):t[m]<y[m]?(o[m]=-1,s[m]=l[m]):(o[m]=1,s[m]=y[m]),h=l[m],p=y[m],u=s[m]}return[s,o]}function qe(n,e,t){const r=new Array(n.length).fill(NaN);for(let a=e+t;a<n.length;a++){const i=n[a-t];let s=!0;for(let o=1;o<=e;o++)if(n[a-t-o]>=i){s=!1;break}if(s){for(let o=1;o<=t;o++)if(n[a-t+o]>=i){s=!1;break}}s&&(r[a]=i)}return r}function We(n,e,t){const r=new Array(n.length).fill(NaN);for(let a=e+t;a<n.length;a++){const i=n[a-t];let s=!0;for(let o=1;o<=e;o++)if(n[a-t-o]<=i){s=!1;break}if(s){for(let o=1;o<=t;o++)if(n[a-t+o]<=i){s=!1;break}}s&&(r[a]=i)}return r}var Ue=Object.defineProperty,ze=(n,e,t)=>e in n?Ue(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Ke=(n,e,t)=>ze(n,typeof e!="symbol"?e+"":e,t);class E{constructor(e){this.array=e}}class He{constructor(e){this.context=e,Ke(this,"_cache",{})}param(e,t=0){return Array.isArray(e)?e[t]:e}get(e,t){return e.array[t]}set(e,t,r){e.array[t]=r}push(e,t){e.array.push(t)}sum(e){return e.array.reduce((t,r)=>t+(isNaN(r)?0:r),0)}avg(e){return this.sum(e)/e.array.length}min(e,t=0){return[...e.array].sort((r,a)=>r-a)[t]??this.context.NA}max(e,t=0){return[...e.array].sort((r,a)=>a-r)[t]??this.context.NA}size(e){return e.array.length}new_bool(e,t=!1){return new E(Array(e).fill(t))}new_float(e,t=NaN){return new E(Array(e).fill(t))}new_int(e,t=0){return new E(Array(e).fill(Math.round(t)))}new_string(e,t=""){return new E(Array(e).fill(t))}new(e,t){return new E(Array(e).fill(t))}slice(e,t,r){const a=r!==void 0?r+1:void 0;return new E(e.array.slice(t,a))}reverse(e){e.array.reverse()}includes(e,t){return e.array.includes(t)}indexof(e,t){return e.array.indexOf(t)}lastindexof(e,t){return e.array.lastIndexOf(t)}stdev(e,t=!0){const r=this.avg(e),a=e.array.map(s=>Math.pow(s-r,2)),i=t?e.array.length:e.array.length-1;return Math.sqrt(this.sum(new E(a))/i)}variance(e,t=!0){const r=this.avg(e),a=e.array.map(s=>Math.pow(s-r,2)),i=t?e.array.length:e.array.length-1;return this.sum(new E(a))/i}covariance(e,t,r=!0){if(e.array.length!==t.array.length||e.array.length<2)return NaN;const a=r?e.array.length:e.array.length-1,i=this.avg(e),s=this.avg(t);let o=0;for(let c=0;c<e.array.length;c++)o+=(e.array[c]-i)*(t.array[c]-s);return o/a}first(e){return e.array.length>0?e.array[0]:this.context.NA}last(e){return e.array.length>0?e.array[e.array.length-1]:this.context.NA}clear(e){e.array.length=0}join(e,t=","){return e.array.join(t)}abs(e){return new E(e.array.map(t=>Math.abs(t)))}concat(e,t){return e.array.push(...t.array),e}copy(e){return new E([...e.array])}every(e,t){return e.array.every(t)}fill(e,t,r=0,a){const i=e.array.length,s=a!==void 0?Math.min(a,i):i;for(let o=r;o<s;o++)e.array[o]=t}from(e){return new E([...e])}insert(e,t,r){e.array.splice(t,0,r)}pop(e){return e.array.pop()}range(e){return this.max(e)-this.min(e)}remove(e,t){return t>=0&&t<e.array.length?e.array.splice(t,1)[0]:this.context.NA}shift(e){return e.array.shift()}sort(e,t="asc"){e.array.sort((r,a)=>t==="asc"?r-a:a-r)}sort_indices(e,t){const r=e.array.map((a,i)=>i);return r.sort((a,i)=>{const s=e.array[a],o=e.array[i];return t?t(s,o):s-o}),new E(r)}standardize(e){const t=this.avg(e),r=this.stdev(e);return r===0?new E(e.array.map(()=>0)):new E(e.array.map(a=>(a-t)/r))}unshift(e,t){e.array.unshift(t)}some(e,t){return e.array.some(t)}}var Qe=Object.defineProperty,Xe=(n,e,t)=>e in n?Qe(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,x=(n,e,t)=>Xe(n,typeof e!="symbol"?e+"":e,t);class Ye{constructor({marketData:e,source:t,tickerId:r,timeframe:a,limit:i,sDate:s,eDate:o}){x(this,"data",{open:[],high:[],low:[],close:[],volume:[],hl2:[],hlc3:[],ohlc4:[]}),x(this,"cache",{}),x(this,"useTACache",!1),x(this,"NA",NaN),x(this,"math"),x(this,"ta"),x(this,"input"),x(this,"request"),x(this,"array"),x(this,"core"),x(this,"lang"),x(this,"idx",0),x(this,"params",{}),x(this,"const",{}),x(this,"var",{}),x(this,"let",{}),x(this,"result"),x(this,"plots",{}),x(this,"marketData"),x(this,"source"),x(this,"tickerId"),x(this,"timeframe",""),x(this,"limit"),x(this,"sDate"),x(this,"eDate"),x(this,"pineTSCode"),this.marketData=e,this.source=t,this.tickerId=r,this.timeframe=a,this.limit=i,this.sDate=s,this.eDate=o,this.math=new ge(this),this.ta=new Ie(this),this.input=new de(this),this.request=new je(this),this.array=new He(this);const c=new ue(this);this.core={plotchar:c.plotchar.bind(c),na:c.na.bind(c),color:c.color,plot:c.plot.bind(c),nz:c.nz.bind(c)}}init(e,t,r=0){return e?!Array.isArray(t)||Array.isArray(t[0])?e[0]=Array.isArray(t?.[0])?t[0]:this.precision(t):e[0]=this.precision(t[t.length-this.idx-1+r]):Array.isArray(t)?e=[this.precision(t[t.length-this.idx-1+r])]:e=[this.precision(t)],e}precision(e,t=10){return typeof e!="number"||isNaN(e)?e:Number(e.toFixed(t))}param(e,t,r){return typeof e=="string"||!Array.isArray(e)&&typeof e=="object"?e:(this.params[r]||(this.params[r]=[]),Array.isArray(e)?t?(this.params[r]=e.slice(t),this.params[r].length=e.length,this.params[r]):(this.params[r]=e.slice(0),this.params[r]):(this.params[r][0]=e,this.params[r]))}}var Ge=Object.defineProperty,Je=(n,e,t)=>e in n?Ge(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,_=(n,e,t)=>Je(n,typeof e!="symbol"?e+"":e,t);const Ze="https://api.binance.com/api/v3",q={1:"1m",3:"3m",5:"5m",15:"15m",30:"30m",45:null,60:"1h",120:"2h",180:null,240:"4h","4H":"4h","1D":"1d",D:"1d","1W":"1w",W:"1w","1M":"1M",M:"1M"};class et{constructor(e=5*60*1e3){_(this,"cache"),_(this,"cacheDuration"),this.cache=new Map,this.cacheDuration=e}generateKey(e){return Object.entries(e).filter(([t,r])=>r!==void 0).map(([t,r])=>`${t}:${r}`).join("|")}get(e){const t=this.generateKey(e),r=this.cache.get(t);return r?Date.now()-r.timestamp>this.cacheDuration?(this.cache.delete(t),null):r.data:null}set(e,t){const r=this.generateKey(e);this.cache.set(r,{data:t,timestamp:Date.now()})}clear(){this.cache.clear()}cleanup(){const e=Date.now();for(const[t,r]of this.cache.entries())e-r.timestamp>this.cacheDuration&&this.cache.delete(t)}}class tt{constructor(){_(this,"cacheManager"),this.cacheManager=new et(5*60*1e3)}async getMarketDataInterval(e,t,r,a){try{const i=q[t.toUpperCase()];if(!i)return console.error(`Unsupported timeframe: ${t}`),[];const s={"1m":60*1e3,"3m":3*60*1e3,"5m":5*60*1e3,"15m":15*60*1e3,"30m":30*60*1e3,"1h":60*60*1e3,"2h":2*60*60*1e3,"4h":4*60*60*1e3,"1d":24*60*60*1e3,"1w":7*24*60*60*1e3,"1M":30*24*60*60*1e3};let o=[],c=r;const l=a,y=s[i];if(!y)return console.error(`Duration not defined for interval: ${i}`),[];for(;c<l;){const h=Math.min(c+1e3*y,l),p=await this.getMarketData(e,t,1e3,c,h);if(p.length===0||(o=o.concat(p),c=p[p.length-1].closeTime+1,p.length<1e3))break}return o}catch(i){return console.error("Error in getMarketDataInterval:",i),[]}}async getMarketData(e,t,r,a,i){try{const s={tickerId:e,timeframe:t,limit:r,sDate:a,eDate:i},o=this.cacheManager.get(s);if(o)return console.log("cache hit",e,t,r,a,i),o;const c=q[t.toUpperCase()];if(!c)return console.error(`Unsupported timeframe: ${t}`),[];let l=`${Ze}/klines?symbol=${e}&interval=${c}`;if(!r&&a&&i)return this.getMarketDataInterval(e,t,a,i);r&&(l+=`&limit=${r}`),a&&(l+=`&startTime=${a}`),i&&(l+=`&endTime=${i}`);const y=await fetch(l);if(!y.ok)throw new Error(`HTTP error! status: ${y.status}`);const h=(await y.json()).map(p=>({openTime:parseInt(p[0]),open:parseFloat(p[1]),high:parseFloat(p[2]),low:parseFloat(p[3]),close:parseFloat(p[4]),volume:parseFloat(p[5]),closeTime:parseInt(p[6]),quoteAssetVolume:parseFloat(p[7]),numberOfTrades:parseInt(p[8]),takerBuyBaseAssetVolume:parseFloat(p[9]),takerBuyQuoteAssetVolume:parseFloat(p[10]),ignore:p[11]}));return this.cacheManager.set(s,h),h}catch(s){return console.error("Error in binance.klines:",s),[]}}}const rt={Binance:new tt};export{Ye as Context,le as PineTS,rt as Provider};
|
|
18
|
+
import*as K from"acorn";import*as g from"acorn-walk";import*as z from"astring";var H=Object.defineProperty,Q=(r,t,e)=>t in r?H(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,j=(r,t,e)=>Q(r,typeof t!="symbol"?t+"":t,e);class J{constructor(){j(this,"scopes",[]),j(this,"scopeTypes",[]),j(this,"scopeCounts",new Map),j(this,"contextBoundVars",new Set),j(this,"arrayPatternElements",new Set),j(this,"rootParams",new Set),j(this,"varKinds",new Map),j(this,"loopVars",new Set),j(this,"loopVarNames",new Map),j(this,"paramIdCounter",0),j(this,"cacheIdCounter",0),j(this,"tempVarCounter",0),j(this,"taCallIdCounter",0),this.pushScope("glb")}get nextParamIdArg(){return{type:"Identifier",name:`'p${this.paramIdCounter++}'`}}get nextCacheIdArg(){return{type:"Identifier",name:`'cache_${this.cacheIdCounter++}'`}}getNextTACallId(){return{type:"Literal",value:`_ta${this.taCallIdCounter++}`}}pushScope(t){this.scopes.push(new Map),this.scopeTypes.push(t),this.scopeCounts.set(t,(this.scopeCounts.get(t)||0)+1)}popScope(){this.scopes.pop(),this.scopeTypes.pop()}getCurrentScopeType(){return this.scopeTypes[this.scopeTypes.length-1]}getCurrentScopeCount(){return this.scopeCounts.get(this.getCurrentScopeType())||1}addContextBoundVar(t,e=!1){this.contextBoundVars.add(t),e&&this.rootParams.add(t)}removeContextBoundVar(t){this.contextBoundVars.has(t)&&(this.contextBoundVars.delete(t),this.rootParams.has(t)&&this.rootParams.delete(t))}addArrayPatternElement(t){this.arrayPatternElements.add(t)}isContextBound(t){return this.contextBoundVars.has(t)}isArrayPatternElement(t){return this.arrayPatternElements.has(t)}isRootParam(t){return this.rootParams.has(t)}addLoopVariable(t,e){this.loopVars.add(t),this.loopVarNames.set(t,e)}getLoopVariableName(t){return this.loopVarNames.get(t)}isLoopVariable(t){return this.loopVars.has(t)}addVariable(t,e){if(this.isContextBound(t))return t;const n=this.scopes[this.scopes.length-1],a=this.scopeTypes[this.scopeTypes.length-1],o=this.scopeCounts.get(a)||1,i=`${a}${o}_${t}`;return n.set(t,i),this.varKinds.set(i,e),i}getVariable(t){if(this.loopVars.has(t)){const e=this.loopVarNames.get(t);if(e)return[e,"let"]}if(this.isContextBound(t))return[t,"let"];for(let e=this.scopes.length-1;e>=0;e--){const n=this.scopes[e];if(n.has(t)){const a=n.get(t),o=this.varKinds.get(a)||"let";return[a,o]}}return[t,"let"]}generateTempVar(){return`temp_${++this.tempVarCounter}`}}//!!!Warning!!! this code is not clean, it was initially written as a PoC then used as transpiler for PineTS
|
|
19
|
+
const b="$",k={type:"Identifier",name:"undefined"};function N(r,t){if(r.computed&&r.property.type==="Identifier"){if(t.isLoopVariable(r.property.name))return;if(!t.isContextBound(r.property.name)){const[e,n]=t.getVariable(r.property.name);r.property={type:"MemberExpression",object:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:n},computed:!1},property:{type:"Identifier",name:e},computed:!1},r.property={type:"MemberExpression",object:r.property,property:{type:"Literal",value:0},computed:!0}}}if(r.computed&&r.object.type==="Identifier"){if(t.isLoopVariable(r.object.name))return;if(!t.isContextBound(r.object.name)){const[e,n]=t.getVariable(r.object.name);r.object={type:"MemberExpression",object:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:n},computed:!1},property:{type:"Identifier",name:e},computed:!1}}if(r.property.type==="MemberExpression"){const e=r.property;e._indexTransformed||(N(e,t),e._indexTransformed=!0)}}}function I(r,t,e){if(r.object&&r.object.type==="Identifier"&&r.object.name==="Math")return;const n=e.getCurrentScopeType()=="if",a=e.getCurrentScopeType()=="els",o=e.getCurrentScopeType()=="for";!n&&!a&&!o&&r.object&&r.object.type==="Identifier"&&e.isContextBound(r.object.name)&&!e.isRootParam(r.object.name)||r._indexTransformed||(N(r,e),r._indexTransformed=!0)}function D(r,t){r.declarations.forEach(e=>{e.init.name=="na"&&(e.init.name="NaN");const n=e.init&&e.init.type==="MemberExpression"&&e.init.object&&(e.init.object.name==="context"||e.init.object.name===b||e.init.object.name==="context2"),a=e.init&&e.init.type==="MemberExpression"&&e.init.object?.object&&(e.init.object.object.name==="context"||e.init.object.object.name===b||e.init.object.object.name==="context2"),o=e.init&&e.init.type==="ArrowFunctionExpression";if(n){e.id.name&&t.addContextBoundVar(e.id.name),e.id.properties&&e.id.properties.forEach(p=>{p.key.name&&t.addContextBoundVar(p.key.name)}),e.init.object.name=b;return}if(a){e.id.name&&t.addContextBoundVar(e.id.name),e.id.properties&&e.id.properties.forEach(p=>{p.key.name&&t.addContextBoundVar(p.key.name)}),e.init.object.object.name=b;return}o&&e.init.params.forEach(p=>{p.type==="Identifier"&&t.addContextBoundVar(p.name)});const i=t.addVariable(e.id.name,r.kind),s=r.kind;e.init&&!o&&(e.init.type==="CallExpression"&&e.init.callee.type==="MemberExpression"&&e.init.callee.object&&e.init.callee.object.type==="Identifier"&&t.isContextBound(e.init.callee.object.name)?S(e.init,t):g.recursive(e.init,{parent:e.init},{Identifier(p,u){p.parent=u.parent,E(p,t);const y=p.parent&&p.parent.type==="BinaryExpression",x=p.parent&&p.parent.type==="ConditionalExpression";p.type==="Identifier"&&(y||x)&&Object.assign(p,{type:"MemberExpression",object:{type:"Identifier",name:p.name},property:{type:"Literal",value:0},computed:!0})},CallExpression(p,u,y){p.callee.type==="Identifier"&&(p.callee.parent=p),p.arguments.forEach(x=>{x.type==="Identifier"&&(x.parent=p)}),S(p,t),p.arguments.forEach(x=>y(x,{parent:p}))},BinaryExpression(p,u,y){p.left.type==="Identifier"&&(p.left.parent=p),p.right.type==="Identifier"&&(p.right.parent=p),y(p.left,{parent:p}),y(p.right,{parent:p})},MemberExpression(p,u,y){p.object.type==="Identifier"&&(p.object.parent=p),p.property.type==="Identifier"&&(p.property.parent=p),N(p,t),p.object&&y(p.object,{parent:p})}}));const c={type:"MemberExpression",object:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:s},computed:!1},property:{type:"Identifier",name:i},computed:!1},l=t.isArrayPatternElement(e.id.name),m=!l&&e.init&&e.init.type==="MemberExpression"&&e.init.computed&&e.init.property&&(e.init.property.type==="Literal"||e.init.property.type==="MemberExpression");e.init?.property?.type==="MemberExpression"&&(e.init.property._indexTransformed||(N(e.init.property,t),e.init.property._indexTransformed=!0));const h={type:"ExpressionStatement",expression:{type:"AssignmentExpression",operator:"=",left:c,right:e.init?o||l?e.init:{type:"CallExpression",callee:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:"init"},computed:!1},arguments:m?[c,e.init.object,e.init.property]:[c,e.init]}:{type:"Identifier",name:"undefined"}}};if(l){h.expression.right.object.property.name+=`?.[0][${e.init.property.value}]`;const p=h.expression.right.object;h.expression.right={type:"CallExpression",callee:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:"init"},computed:!1},arguments:[c,p]}}o&&(t.pushScope("fn"),g.recursive(e.init.body,t,{BlockStatement(p,u,y){p.body.forEach(x=>y(x,u))},IfStatement(p,u,y){u.pushScope("if"),y(p.consequent,u),p.alternate&&(u.pushScope("els"),y(p.alternate,u),u.popScope()),u.popScope()},VariableDeclaration(p,u){D(p,u)},Identifier(p,u){E(p,u)},AssignmentExpression(p,u){L(p,u)}}),t.popScope()),Object.assign(r,h)})}function E(r,t){if(r.name!==b){if(r.name==="Math"||r.name==="NaN"||r.name==="undefined"||r.name==="Infinity"||r.name==="null"||r.name.startsWith("'")&&r.name.endsWith("'")||r.name.startsWith('"')&&r.name.endsWith('"')||r.name.startsWith("`")&&r.name.endsWith("`")||t.isLoopVariable(r.name)||t.isContextBound(r.name)&&!t.isRootParam(r.name))return;const e=r.parent&&r.parent.type==="MemberExpression"&&r.parent.object===r&&t.isContextBound(r.name),n=r.parent&&r.parent.type==="CallExpression"&&r.parent.callee&&r.parent.callee.type==="MemberExpression"&&r.parent.callee.property.name==="param";r.parent&&r.parent.type==="AssignmentExpression"&&r.parent.left;const a=r.parent&&r.parent.type==="CallExpression"&&r.parent.callee&&r.parent.callee.type==="MemberExpression"&&t.isContextBound(r.parent.callee.object.name),o=r.parent&&r.parent.type==="MemberExpression"&&r.parent.computed,i=r.parent&&r.parent.type==="MemberExpression"&&r.parent.computed&&r.parent.property===r&&r.parent.parent&&r.parent.parent.type==="CallExpression"&&r.parent.parent.callee&&r.parent.parent.callee.type==="MemberExpression"&&t.isContextBound(r.parent.parent.callee.object.name),s=r.parent&&r.parent.type==="CallExpression"&&r.parent.callee===r;if(e||n||a||i||s){if(s)return;const[h,p]=t.getVariable(r.name);Object.assign(r,{type:"MemberExpression",object:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:p},computed:!1},property:{type:"Identifier",name:h},computed:!1});return}const[c,l]=t.getVariable(r.name),m={type:"MemberExpression",object:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:l},computed:!1},property:{type:"Identifier",name:c},computed:!1};!(r.parent&&r.parent.type==="MemberExpression"&&r.parent.computed&&r.parent.object===r)&&!o?Object.assign(r,{type:"MemberExpression",object:m,property:{type:"Literal",value:0},computed:!0}):Object.assign(r,m)}}function L(r,t){if(r.left.type==="Identifier"){const[e,n]=t.getVariable(r.left.name),a={type:"MemberExpression",object:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:n},computed:!1},property:{type:"Identifier",name:e},computed:!1};r.left={type:"MemberExpression",object:a,property:{type:"Literal",value:0},computed:!0}}g.recursive(r.right,{parent:r.right,inNamespaceCall:!1},{Identifier(e,n,a){e.name=="na"&&(e.name="NaN"),e.parent=n.parent,E(e,t);const o=e.parent&&e.parent.type==="BinaryExpression",i=e.parent&&e.parent.type==="ConditionalExpression",s=t.isContextBound(e.name)&&!t.isRootParam(e.name),c=e.parent&&e.parent.type==="MemberExpression"&&e.parent.computed&&e.parent.object===e,l=e.parent&&e.parent._isParamCall,m=e.parent&&e.parent.type==="MemberExpression",h=e.name==="NaN";(s||i||o)&&(e.type==="MemberExpression"?N(e,t):e.type==="Identifier"&&!m&&!c&&!l&&!h&&$(e))},MemberExpression(e,n,a){N(e,t),e.object&&a(e.object,{parent:e,inNamespaceCall:n.inNamespaceCall})},CallExpression(e,n,a){const o=e.callee&&e.callee.type==="MemberExpression"&&e.callee.object&&e.callee.object.type==="Identifier"&&t.isContextBound(e.callee.object.name);S(e,t),e.arguments.forEach(i=>a(i,{parent:e,inNamespaceCall:o||n.inNamespaceCall}))}})}function X(r,t,e=!1){r.params.forEach(n=>{n.type==="Identifier"&&t.addContextBoundVar(n.name,e)})}function F(r,t){const e=t.getCurrentScopeType();r.argument&&(r.argument.type==="ArrayExpression"?(r.argument.elements=r.argument.elements.map(n=>{if(n.type==="Identifier"){if(t.isContextBound(n.name)&&!t.isRootParam(n.name))return{type:"MemberExpression",object:n,property:{type:"Literal",value:0},computed:!0};const[a,o]=t.getVariable(n.name);return{type:"MemberExpression",object:{type:"MemberExpression",object:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:o},computed:!1},property:{type:"Identifier",name:a},computed:!1},property:{type:"Literal",value:0},computed:!0}}else if(n.type==="MemberExpression")return n.computed&&n.object.type==="Identifier"&&t.isContextBound(n.object.name)&&!t.isRootParam(n.object.name)||I(n,"",t),n;return n}),r.argument={type:"ArrayExpression",elements:[r.argument]}):r.argument.type==="BinaryExpression"?g.recursive(r.argument,t,{Identifier(n,a){E(n,a),n.type==="Identifier"&&$(n)},MemberExpression(n){I(n,"",t)}}):r.argument.type==="ObjectExpression"?r.argument.properties=r.argument.properties.map(n=>{if(n.shorthand){const[a,o]=t.getVariable(n.value.name);return{type:"Property",key:{type:"Identifier",name:n.key.name},value:{type:"MemberExpression",object:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:o},computed:!1},property:{type:"Identifier",name:a},computed:!1},kind:"init",method:!1,shorthand:!1,computed:!1}}return n}):r.argument.type==="Identifier"&&(E(r.argument,t),r.argument.type==="Identifier"&&$(r.argument)),e==="fn"&&(r.argument.type==="Identifier"&&t.isContextBound(r.argument.name)&&!t.isRootParam(r.argument.name)?r.argument={type:"MemberExpression",object:r.argument,property:{type:"Literal",value:0},computed:!0}:r.argument.type==="MemberExpression"?r.argument.object.type==="Identifier"&&t.isContextBound(r.argument.object.name)&&!t.isRootParam(r.argument.object.name)&&(r.argument._indexTransformed||(N(r.argument,t),r.argument._indexTransformed=!0)):(r.argument.type==="BinaryExpression"||r.argument.type==="LogicalExpression"||r.argument.type==="ConditionalExpression"||r.argument.type==="CallExpression")&&g.recursive(r.argument,t,{Identifier(n,a){E(n,a),n.type==="Identifier"&&!n._arrayAccessed&&($(n),n._arrayAccessed=!0)},MemberExpression(n){I(n,"",t)},CallExpression(n,a){S(n,a)}}),r.argument={type:"CallExpression",callee:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:"precision"}},arguments:[r.argument]}))}function V(r,t){if(r.type==="Identifier"){if(r.name==="na")return r.name="NaN",r;if(t.isLoopVariable(r.name))return r;if(t.isRootParam(r.name)){const[a,o]=t.getVariable(r.name);return{type:"MemberExpression",object:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:o},computed:!1},property:{type:"Identifier",name:a},computed:!1}}if(t.isContextBound(r.name))return r;const[e,n]=t.getVariable(r.name);return{type:"MemberExpression",object:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:n},computed:!1},property:{type:"Identifier",name:e},computed:!1}}return r}function U(r,t,e){const n=B(r.argument,t,e);return{type:"UnaryExpression",operator:r.operator,prefix:r.prefix,argument:n,start:r.start,end:r.end}}function B(r,t,e=""){switch(r.type){case"BinaryExpression":return W(r,t,e);case"MemberExpression":return{type:"MemberExpression",object:r.object.type==="Identifier"?V(r.object,t):r.object,property:r.property,computed:r.computed};case"Identifier":return t.isLoopVariable(r.name)||r.parent&&r.parent.type==="MemberExpression"&&r.parent.property===r?r:{type:"MemberExpression",object:V(r,t),property:{type:"Literal",value:0},computed:!0};case"UnaryExpression":return U(r,t,e)}return r}function W(r,t,e){const n=B(r.left,t,e),a=B(r.right,t,e),o={type:"BinaryExpression",operator:r.operator,left:n,right:a,start:r.start,end:r.end};return g.recursive(o,t,{CallExpression(i,s){i._transformed||S(i,s)},MemberExpression(i){I(i,"",t)}}),o}function Y(r,t,e){const n=B(r.left,t,e),a=B(r.right,t,e),o={type:"LogicalExpression",operator:r.operator,left:n,right:a,start:r.start,end:r.end};return g.recursive(o,t,{CallExpression(i,s){i._transformed||S(i,s)}}),o}function Z(r,t,e){return g.recursive(r,{parent:r,inNamespaceCall:!1},{Identifier(n,a,o){if(n.name=="NaN")return;if(n.name=="na"){n.name="NaN";return}n.parent=a.parent,E(n,t);const i=n.parent&&n.parent.type==="BinaryExpression";(n.parent&&n.parent.type==="ConditionalExpression"||i)&&(n.type==="MemberExpression"?N(n,t):n.type==="Identifier"&&$(n))},MemberExpression(n,a,o){N(n,t),n.object&&o(n.object,{parent:n,inNamespaceCall:a.inNamespaceCall})},CallExpression(n,a,o){const i=n.callee&&n.callee.type==="MemberExpression"&&n.callee.object&&n.callee.object.type==="Identifier"&&t.isContextBound(n.callee.object.name);S(n,t),n.arguments.forEach(s=>o(s,{parent:n,inNamespaceCall:i||a.inNamespaceCall}))}}),{type:"CallExpression",callee:{type:"MemberExpression",object:{type:"Identifier",name:e},property:{type:"Identifier",name:"param"}},arguments:[r,k,t.nextParamIdArg],_transformed:!0,_isParamCall:!0}}function O(r,t,e){switch(r?.type){case"BinaryExpression":r=W(r,e,t);break;case"LogicalExpression":r=Y(r,e,t);break;case"ConditionalExpression":return Z(r,e,t);case"UnaryExpression":r=U(r,e,t);break}if(r.type==="MemberExpression"&&r.computed&&r.property){const n=r.object.type==="Identifier"&&e.isContextBound(r.object.name)&&!e.isRootParam(r.object.name)?r.object:V(r.object,e),a=r.property.type==="Identifier"&&!e.isContextBound(r.property.name)&&!e.isLoopVariable(r.property.name)?V(r.property,e):r.property;return{type:"CallExpression",callee:{type:"MemberExpression",object:{type:"Identifier",name:t},property:{type:"Identifier",name:"param"},computed:!1},arguments:[n,a,e.nextParamIdArg],_transformed:!0,_isParamCall:!0}}if(r.type==="ObjectExpression"&&(r.properties=r.properties.map(n=>{if(n.value.name){const[a,o]=e.getVariable(n.value.name);return{type:"Property",key:{type:"Identifier",name:n.key.name},value:{type:"MemberExpression",object:{type:"MemberExpression",object:{type:"Identifier",name:b},property:{type:"Identifier",name:o},computed:!1},property:{type:"Identifier",name:a},computed:!1},kind:"init",method:!1,shorthand:!1,computed:!1}}return n})),r.type==="Identifier"){if(r.name==="na")return r.name="NaN",r;if(e.isContextBound(r.name)&&!e.isRootParam(r.name))return{type:"CallExpression",callee:{type:"MemberExpression",object:{type:"Identifier",name:t},property:{type:"Identifier",name:"param"},computed:!1},arguments:[r,k,e.nextParamIdArg],_transformed:!0,_isParamCall:!0}}return r?.type==="CallExpression"&&S(r,e),{type:"CallExpression",callee:{type:"MemberExpression",object:{type:"Identifier",name:t},property:{type:"Identifier",name:"param"},computed:!1},arguments:[r.type==="Identifier"?V(r,e):r,k,e.nextParamIdArg],_transformed:!0,_isParamCall:!0}}function S(r,t,e){if(!r._transformed){if(r.callee&&r.callee.type==="MemberExpression"&&r.callee.object&&r.callee.object.type==="Identifier"&&(t.isContextBound(r.callee.object.name)||r.callee.object.name==="math"||r.callee.object.name==="ta")){const n=r.callee.object.name;r.arguments=r.arguments.map(a=>a._isParamCall?a:O(a,n,t)),n==="ta"&&r.arguments.push(t.getNextTACallId()),r._transformed=!0}else r.callee&&r.callee.type==="Identifier"&&(r.arguments=r.arguments.map(n=>n._isParamCall?n:O(n,b,t)),r._transformed=!0);r.arguments.forEach(n=>{g.recursive(n,t,{Identifier(a,o,i){a.parent=o.parent,E(a,t);const s=a.parent&&a.parent.type==="BinaryExpression";(a.parent&&a.parent.type==="ConditionalExpression"||s)&&(a.type==="MemberExpression"?N(a,t):a.type==="Identifier"&&$(a))},CallExpression(a,o,i){a._transformed||S(a,o)},MemberExpression(a,o,i){I(a,"",t),a.object&&i(a.object,{parent:a,inNamespaceCall:o.inNamespaceCall})}})})}}function tt(r,t){const e=[];r.params.forEach(n=>{n.type==="Identifier"&&(t.addContextBoundVar(n.name,!1),e.push(n.name))}),r.body&&r.body.type==="BlockStatement"&&(t.pushScope("fn"),g.recursive(r.body,t,{BlockStatement(n,a,o){n.body.forEach(i=>o(i,a))},ReturnStatement(n,a){F(n,a)},VariableDeclaration(n,a){D(n,a)},Identifier(n,a){E(n,a)},CallExpression(n,a){S(n,a),n.arguments.forEach(o=>{o.type==="BinaryExpression"&&g.recursive(o,a,{CallExpression(i,s){S(i,s)},MemberExpression(i){I(i,"",a)}})})},MemberExpression(n){I(n,"",t)},AssignmentExpression(n,a){L(n,a)},ForStatement(n,a,o){q(n,a,o)},IfStatement(n,a,o){G(n,a,o)},BinaryExpression(n,a,o){g.recursive(n,a,{CallExpression(i,s){S(i,s)},MemberExpression(i){I(i,"",a)}})}}),t.popScope())}function $(r,t){Object.assign(r,{type:"MemberExpression",object:{type:"Identifier",name:r.name,start:r.start,end:r.end},property:{type:"Literal",value:0},computed:!0,_indexTransformed:!0})}function q(r,t,e){if(r.init&&r.init.type==="VariableDeclaration"){const n=r.init.declarations[0],a=n.id.name;t.addLoopVariable(a,a),r.init={type:"VariableDeclaration",kind:r.init.kind,declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:a},init:n.init}]},n.init&&g.recursive(n.init,t,{Identifier(o,i){t.isLoopVariable(o.name)||(t.pushScope("for"),E(o,i),t.popScope())},MemberExpression(o){t.pushScope("for"),I(o,"",t),t.popScope()}})}r.test&&g.recursive(r.test,t,{Identifier(n,a){!t.isLoopVariable(n.name)&&!n.computed&&(t.pushScope("for"),E(n,a),n.type==="Identifier"&&(n.computed=!0,$(n)),t.popScope())},MemberExpression(n){t.pushScope("for"),I(n,"",t),t.popScope()}}),r.update&&g.recursive(r.update,t,{Identifier(n,a){t.isLoopVariable(n.name)||(t.pushScope("for"),E(n,a),t.popScope())}}),t.pushScope("for"),e(r.body,t),t.popScope()}function et(r,t){g.recursive(r,t,{MemberExpression(e){I(e,"",t)},CallExpression(e,n){S(e,n)},Identifier(e,n){E(e,n);const a=t.getCurrentScopeType()==="if";t.isContextBound(e.name)&&!t.isRootParam(e.name)&&a&&$(e)}})}function G(r,t,e){r.test&&(t.pushScope("if"),et(r.test,t),t.popScope()),t.pushScope("if"),e(r.consequent,t),t.popScope(),r.alternate&&(t.pushScope("els"),e(r.alternate,t),t.popScope())}function nt(r){g.recursive(r,null,{VariableDeclaration(t,e,n){t.declarations&&t.declarations.length>0&&t.declarations.forEach(a=>{if(a.init&&a.init.type==="ArrowFunctionExpression"&&a.init.start!==0){const o={type:"FunctionDeclaration",id:a.id,params:a.init.params,body:a.init.body.type==="BlockStatement"?a.init.body:{type:"BlockStatement",body:[{type:"ReturnStatement",argument:a.init.body}]},async:a.init.async,generator:!1};Object.assign(t,o)}}),t.body&&t.body.body&&t.body.body.forEach(a=>n(a,e))}})}function rt(r,t){g.simple(r,{VariableDeclaration(e){e.declarations.forEach(n=>{const a=n.init&&n.init.type==="MemberExpression"&&n.init.object&&(n.init.object.name==="context"||n.init.object.name===b||n.init.object.name==="context2"),o=n.init&&n.init.type==="MemberExpression"&&n.init.object?.object&&(n.init.object.object.name==="context"||n.init.object.object.name===b||n.init.object.object.name==="context2");(a||o)&&(n.id.name&&t.addContextBoundVar(n.id.name),n.id.properties&&n.id.properties.forEach(i=>{i.key.name&&t.addContextBoundVar(i.key.name)}))})}})}function at(r){let t=typeof r=="function"?r.toString():r;const e=K.parse(t.trim(),{ecmaVersion:"latest",sourceType:"module"});nt(e);const n=new J;let a;rt(e,n),g.simple(e,{FunctionDeclaration(i){tt(i,n)},ArrowFunctionExpression(i){const s=i.start===0;s&&i.params&&i.params.length>0&&(a=i.params[0].name,i.params[0].name=b),X(i,n,s)},VariableDeclaration(i){i.declarations.forEach(s=>{if(s.id.type==="ArrayPattern"){const c=n.generateTempVar(),l={type:"VariableDeclaration",kind:i.kind,declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:c},init:s.init}]};s.id.elements?.forEach(h=>{h.type==="Identifier"&&n.addArrayPatternElement(h.name)});const m=s.id.elements.map((h,p)=>({type:"VariableDeclaration",kind:i.kind,declarations:[{type:"VariableDeclarator",id:h,init:{type:"MemberExpression",object:{type:"Identifier",name:c},property:{type:"Literal",value:p},computed:!0}}]}));Object.assign(i,{type:"BlockStatement",body:[l,...m]})}})},ForStatement(i){}}),g.recursive(e,n,{BlockStatement(i,s,c){i.body.forEach(l=>c(l,s))},ReturnStatement(i,s){F(i,s)},VariableDeclaration(i,s){D(i,s)},Identifier(i,s){E(i,s)},CallExpression(i,s){S(i,s)},MemberExpression(i){I(i,a,n)},AssignmentExpression(i,s){L(i,s)},FunctionDeclaration(i,s){},ForStatement(i,s,c){q(i,s,c)},IfStatement(i,s,c){G(i,s,c)}}),it(e);const o=z.generate(e);return new Function("",`return ${o}`)(this)}function it(r){g.simple(r,{BinaryExpression(t){if(t.operator==="=="||t.operator==="==="){const e=t.left,n=t.right;Object.assign(t,{type:"CallExpression",callee:{type:"MemberExpression",object:{type:"Identifier",name:"$.math"},property:{type:"Identifier",name:"__eq"},computed:!1},arguments:[e,n],_transformed:!0})}}})}var ot=Object.defineProperty,st=(r,t,e)=>t in r?ot(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,A=(r,t,e)=>st(r,typeof t!="symbol"?t+"":t,e);const pt=5e3;class ct{constructor(t,e,n,a,o,i){this.source=t,this.tickerId=e,this.timeframe=n,this.limit=a,this.sDate=o,this.eDate=i,A(this,"data",[]),A(this,"open",[]),A(this,"high",[]),A(this,"low",[]),A(this,"close",[]),A(this,"volume",[]),A(this,"hl2",[]),A(this,"hlc3",[]),A(this,"ohlc4",[]),A(this,"openTime",[]),A(this,"closeTime",[]),A(this,"_periods"),A(this,"_readyPromise",null),A(this,"_ready",!1),this._readyPromise=new Promise(s=>{this.loadMarketData(t,e,n,a,o,i).then(c=>{const l=c.slice(0,pt);this._periods=l.length,this.data=l;const m=l.map(d=>d.open),h=l.map(d=>d.close),p=l.map(d=>d.high),u=l.map(d=>d.low),y=l.map(d=>d.volume),x=l.map(d=>(d.high+d.low+d.close)/3),w=l.map(d=>(d.high+d.low)/2),M=l.map(d=>(d.high+d.low+d.open+d.close)/4),_=l.map(d=>d.openTime),C=l.map(d=>d.closeTime);this.open=m,this.close=h,this.high=p,this.low=u,this.volume=y,this.hl2=w,this.hlc3=x,this.ohlc4=M,this.openTime=_,this.closeTime=C,this._ready=!0,s(!0)})})}get periods(){return this._periods}async loadMarketData(t,e,n,a,o,i){return Array.isArray(t)?t:t.getMarketData(e,n,a,o,i)}async ready(){if(this._ready)return!0;if(!this._readyPromise)throw new Error("PineTS is not ready");return this._readyPromise}async run(t,e,n){await this.ready(),e||(e=this._periods);const a=new Vt({marketData:this.data,source:this.source,tickerId:this.tickerId,timeframe:this.timeframe,limit:this.limit,sDate:this.sDate,eDate:this.eDate});a.pineTSCode=t,a.useTACache=n;let o=at.bind(this)(t);a.data.close=[],a.data.open=[],a.data.high=[],a.data.low=[],a.data.volume=[],a.data.hl2=[],a.data.hlc3=[],a.data.ohlc4=[],a.data.openTime=[],a.data.closeTime=[];const i=["const","var","let","params"];for(let s=this._periods-e;s<this._periods;s++){a.idx=s,a.data.close.unshift(this.close[s]),a.data.open.unshift(this.open[s]),a.data.high.unshift(this.high[s]),a.data.low.unshift(this.low[s]),a.data.volume.unshift(this.volume[s]),a.data.hl2.unshift(this.hl2[s]),a.data.hlc3.unshift(this.hlc3[s]),a.data.ohlc4.unshift(this.ohlc4[s]),a.data.openTime.unshift(this.openTime[s]);const c=await o(a);if(typeof c=="object"){typeof a.result!="object"&&(a.result={});for(let l in c){a.result[l]===void 0&&(a.result[l]=[]);const m=Array.isArray(c[l])?c[l][0]:c[l];a.result[l].push(m)}}else Array.isArray(a.result)||(a.result=[]),a.result.push(c);for(let l of i)for(let m in a[l])if(Array.isArray(a[l][m])){const h=a[l][m][0];a[l][m].unshift(h)}}return a}}var lt=Object.defineProperty,mt=(r,t,e)=>t in r?lt(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,ht=(r,t,e)=>mt(r,typeof t!="symbol"?t+"":t,e);class ut{constructor(t){this.context=t,ht(this,"color",{param:(e,n=0)=>Array.isArray(e)?e[n]:e,rgb:(e,n,a,o)=>o?`rgba(${e}, ${n}, ${a}, ${o})`:`rgb(${e}, ${n}, ${a})`,new:(e,n)=>{if(e&&e.startsWith("#")){const a=e.slice(1),o=parseInt(a.slice(0,2),16),i=parseInt(a.slice(2,4),16),s=parseInt(a.slice(4,6),16);return n?`rgba(${o}, ${i}, ${s}, ${n})`:`rgb(${o}, ${i}, ${s})`}return n?`rgba(${e}, ${n})`:e},white:"white",lime:"lime",green:"green",red:"red",maroon:"maroon",black:"black",gray:"gray",blue:"blue"})}extractPlotOptions(t){const e={};for(let n in t)Array.isArray(t[n])?e[n]=t[n][0]:e[n]=t[n];return e}indicator(t,e,n){}plotchar(t,e,n){this.context.plots[e]||(this.context.plots[e]={data:[],options:this.extractPlotOptions(n),title:e}),this.context.plots[e].data.push({time:this.context.marketData[this.context.marketData.length-this.context.idx-1].openTime,value:t[0],options:{...this.extractPlotOptions(n),style:"char"}})}plot(t,e,n){this.context.plots[e]||(this.context.plots[e]={data:[],options:this.extractPlotOptions(n),title:e}),this.context.plots[e].data.push({time:this.context.marketData[this.context.marketData.length-this.context.idx-1].openTime,value:t[0],options:this.extractPlotOptions(n)})}na(t){return Array.isArray(t)?isNaN(t[0]):isNaN(t)}nz(t,e=0){const n=Array.isArray(t)?t[0]:t,a=Array.isArray(t)?e[0]:e;return isNaN(n)?a:n}}class yt{constructor(t){this.context=t}param(t,e=0){return Array.isArray(t)?[t[e]]:[t]}any(t,{title:e,group:n}={}){return Array.isArray(t)?t[0]:t}int(t,{title:e,group:n}={}){return Array.isArray(t)?t[0]:t}float(t,{title:e,group:n}={}){return Array.isArray(t)?t[0]:t}bool(t,{title:e,group:n}={}){return Array.isArray(t)?t[0]:t}string(t,{title:e,group:n}={}){return Array.isArray(t)?t[0]:t}timeframe(t,{title:e,group:n}={}){return Array.isArray(t)?t[0]:t}time(t,{title:e,group:n}={}){return Array.isArray(t)?t[0]:t}price(t,{title:e,group:n}={}){return Array.isArray(t)?t[0]:t}session(t,{title:e,group:n}={}){return Array.isArray(t)?t[0]:t}source(t,{title:e,group:n}={}){return Array.isArray(t)?t[0]:t}symbol(t,{title:e,group:n}={}){return Array.isArray(t)?t[0]:t}text_area(t,{title:e,group:n}={}){return Array.isArray(t)?t[0]:t}enum(t,{title:e,group:n}={}){return Array.isArray(t)?t[0]:t}color(t,{title:e,group:n}={}){return Array.isArray(t)?t[0]:t}}var dt=Object.defineProperty,xt=(r,t,e)=>t in r?dt(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,ft=(r,t,e)=>xt(r,typeof t!="symbol"?t+"":t,e);class bt{constructor(t){this.context=t,ft(this,"_cache",{})}param(t,e,n){return this.context.params[n]||(this.context.params[n]=[]),Array.isArray(t)?e?(this.context.params[n]=t.slice(e),this.context.params[n].length=t.length,this.context.params[n]):(this.context.params[n]=t.slice(0),this.context.params[n]):(this.context.params[n][0]=t,this.context.params[n])}__eq(t,e){return Math.abs(t-e)<1e-8}abs(t){return Math.abs(t[0])}pow(t,e){return Math.pow(t[0],e[0])}sqrt(t){return Math.sqrt(t[0])}log(t){return Math.log(t[0])}ln(t){return Math.log(t[0])}exp(t){return Math.exp(t[0])}floor(t){return Math.floor(t[0])}ceil(t){return Math.ceil(t[0])}round(t){return Math.round(t[0])}random(){return Math.random()}max(...t){const e=t.map(n=>Array.isArray(n)?n[0]:n);return Math.max(...e)}min(...t){const e=t.map(n=>Array.isArray(n)?n[0]:n);return Math.min(...e)}sum(t,e){const n=Array.isArray(e)?e[0]:e;return Array.isArray(t)?t.slice(0,n).reduce((a,o)=>a+o,0):t}sin(t){return Math.sin(t[0])}cos(t){return Math.cos(t[0])}tan(t){return Math.tan(t[0])}acos(t){return Math.acos(t[0])}asin(t){return Math.asin(t[0])}atan(t){return Math.atan(t[0])}avg(...t){const e=t.map(n=>Array.isArray(n)?n[0]:n);return e.reduce((n,a)=>{const o=Array.isArray(n)?n[0]:n,i=Array.isArray(a)?a[0]:a;return o+i},0)/e.length}}var gt=Object.defineProperty,wt=(r,t,e)=>t in r?gt(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,At=(r,t,e)=>wt(r,typeof t!="symbol"?t+"":t,e);const R=["1","3","5","15","30","45","60","120","180","240","D","W","M"];class vt{constructor(t){this.context=t,At(this,"_cache",{})}param(t,e,n){return this.context.params[n]||(this.context.params[n]=[]),Array.isArray(t)?(e?this.context.params[n]=t.slice(e):this.context.params[n]=t.slice(0),[t[e],n]):(this.context.params[n][0]=t,[t,n])}async security(t,e,n,a=!1,o=!1,i=!1,s=null,c=null){const l=t[0],m=e[0],h=n[0],p=n[1],u=R.indexOf(this.context.timeframe),y=R.indexOf(m);if(u==-1||y==-1)throw new Error("Invalid timeframe");if(u>y)throw new Error("Only higher timeframes are supported for now");if(u===y)return h;const x=this.context.data.openTime[0],w=this.context.data.closeTime[0];if(this.context.cache[p]){const C=this.context.cache[p],d=this._findSecContextIdx(x,w,C.data.openTime,C.data.closeTime,o);return d==-1?NaN:C.params[p][d]}const M=await new ct(this.context.source,l,m,this.context.limit||1e3,this.context.sDate,this.context.eDate).run(this.context.pineTSCode);this.context.cache[p]=M;const _=this._findSecContextIdx(x,w,M.data.openTime,M.data.closeTime,o);return _==-1?NaN:M.params[p][_]}_findSecContextIdx(t,e,n,a,o=!1){for(let i=0;i<n.length;i++)if(n[i]<=t&&e<=a[i])return i+(o?1:2);return-1}}class Et{constructor(t){this.context=t}get tr(){return this.context.math.max(this.context.data.high[0]-this.context.data.low[0],this.context.math.abs(this.context.data.high[0]-this.context.data.close[1]),this.context.math.abs(this.context.data.low[0]-this.context.data.close[1]))}param(t,e,n){return this.context.params[n]||(this.context.params[n]=[]),Array.isArray(t)?e?(this.context.params[n]=t.slice(e),this.context.params[n].length=t.length,this.context.params[n]):(this.context.params[n]=t.slice(0),this.context.params[n]):(this.context.params[n][0]=t,this.context.params[n])}ema(t,e,n){const a=Array.isArray(e)?e[0]:e;this.context.taState||(this.context.taState={});const o=n||`ema_${a}`;this.context.taState[o]||(this.context.taState[o]={prevEma:null,initSum:0,initCount:0});const i=this.context.taState[o],s=t[0];if(i.initCount<a)return i.initSum+=s,i.initCount++,i.initCount===a?(i.prevEma=i.initSum/a,this.context.precision(i.prevEma)):NaN;const c=2/(a+1),l=s*c+i.prevEma*(1-c);return i.prevEma=l,this.context.precision(l)}sma(t,e,n){const a=Array.isArray(e)?e[0]:e;this.context.taState||(this.context.taState={});const o=n||`sma_${a}`;this.context.taState[o]||(this.context.taState[o]={window:[],sum:0});const i=this.context.taState[o],s=t[0]||0;if(i.window.unshift(s),i.sum+=s,i.window.length<a)return NaN;if(i.window.length>a){const l=i.window.pop();i.sum-=l}const c=i.sum/a;return this.context.precision(c)}vwma(t,e,n){const a=Array.isArray(e)?e[0]:e;this.context.taState||(this.context.taState={});const o=n||`vwma_${a}`;this.context.taState[o]||(this.context.taState[o]={window:[],volumeWindow:[]});const i=this.context.taState[o],s=t[0],c=this.context.data.volume[0];if(i.window.unshift(s),i.volumeWindow.unshift(c),i.window.length<a)return NaN;i.window.length>a&&(i.window.pop(),i.volumeWindow.pop());let l=0,m=0;for(let p=0;p<a;p++)l+=i.window[p]*i.volumeWindow[p],m+=i.volumeWindow[p];const h=l/m;return this.context.precision(h)}wma(t,e,n){const a=Array.isArray(e)?e[0]:e;this.context.taState||(this.context.taState={});const o=n||`wma_${a}`;this.context.taState[o]||(this.context.taState[o]={window:[]});const i=this.context.taState[o],s=t[0];if(i.window.unshift(s),i.window.length<a)return NaN;i.window.length>a&&i.window.pop();let c=0,l=0;for(let h=0;h<a;h++){const p=a-h;c+=i.window[h]*p,l+=p}const m=c/l;return this.context.precision(m)}hma(t,e,n){const a=Array.isArray(e)?e[0]:e,o=Math.floor(a/2),i=Math.floor(Math.sqrt(a)),s=this.wma(t,o,n?`${n}_wma1`:void 0),c=this.wma(t,a,n?`${n}_wma2`:void 0);if(isNaN(s)||isNaN(c))return NaN;this.context.taState||(this.context.taState={});const l=n||`hma_raw_${a}`;this.context.taState[l]||(this.context.taState[l]=[]);const m=2*s-c;this.context.taState[l].unshift(m);const h=n?`${n}_hma_final`:`hma_final_${a}`;this.context.taState[h]||(this.context.taState[h]={window:[]});const p=this.context.taState[h];if(p.window.unshift(m),p.window.length<i)return NaN;p.window.length>i&&p.window.pop();let u=0,y=0;for(let w=0;w<i;w++){const M=i-w;u+=p.window[w]*M,y+=M}const x=u/y;return this.context.precision(x)}rma(t,e,n){const a=Array.isArray(e)?e[0]:e;this.context.taState||(this.context.taState={});const o=n||`rma_${a}`;this.context.taState[o]||(this.context.taState[o]={prevRma:null,initSum:0,initCount:0});const i=this.context.taState[o],s=t[0]||0;if(i.initCount<a)return i.initSum+=s,i.initCount++,i.initCount===a?(i.prevRma=i.initSum/a,this.context.precision(i.prevRma)):NaN;const c=1/a,l=s*c+i.prevRma*(1-c);return i.prevRma=l,this.context.precision(l)}change(t,e=1,n){const a=Array.isArray(e)?e[0]:e;this.context.taState||(this.context.taState={});const o=n||`change_${a}`;this.context.taState[o]||(this.context.taState[o]={window:[]});const i=this.context.taState[o],s=t[0];if(i.window.unshift(s),i.window.length<=a)return NaN;i.window.length>a+1&&i.window.pop();const c=s-i.window[a];return this.context.precision(c)}rsi(t,e,n){const a=Array.isArray(e)?e[0]:e;this.context.taState||(this.context.taState={});const o=n||`rsi_${a}`;this.context.taState[o]||(this.context.taState[o]={prevValue:null,avgGain:0,avgLoss:0,initGains:[],initLosses:[]});const i=this.context.taState[o],s=t[0];if(i.prevValue!==null){const c=s-i.prevValue,l=c>0?c:0,m=c<0?-c:0;if(i.initGains.length<a){if(i.initGains.push(l),i.initLosses.push(m),i.initGains.length===a){i.avgGain=i.initGains.reduce((u,y)=>u+y,0)/a,i.avgLoss=i.initLosses.reduce((u,y)=>u+y,0)/a,i.prevValue=s;const p=i.avgLoss===0?100:100-100/(1+i.avgGain/i.avgLoss);return this.context.precision(p)}return i.prevValue=s,NaN}i.avgGain=(i.avgGain*(a-1)+l)/a,i.avgLoss=(i.avgLoss*(a-1)+m)/a;const h=i.avgLoss===0?100:100-100/(1+i.avgGain/i.avgLoss);return i.prevValue=s,this.context.precision(h)}return i.prevValue=s,NaN}atr(t,e){const n=Array.isArray(t)?t[0]:t;this.context.taState||(this.context.taState={});const a=e||`atr_${n}`;this.context.taState[a]||(this.context.taState[a]={prevAtr:null,initSum:0,initCount:0,prevClose:null});const o=this.context.taState[a],i=this.context.data.high[0],s=this.context.data.low[0],c=this.context.data.close[0];let l;if(o.prevClose!==null){const h=i-s,p=Math.abs(i-o.prevClose),u=Math.abs(s-o.prevClose);l=Math.max(h,p,u)}else l=i-s;if(o.prevClose=c,o.initCount<n)return o.initSum+=l,o.initCount++,o.initCount===n?(o.prevAtr=o.initSum/n,this.context.precision(o.prevAtr)):NaN;const m=(o.prevAtr*(n-1)+l)/n;return o.prevAtr=m,this.context.precision(m)}mom(t,e,n){const a=Array.isArray(e)?e[0]:e;return this.change(t,a)}roc(t,e,n){const a=Array.isArray(e)?e[0]:e;this.context.taState||(this.context.taState={});const o=n||`roc_${a}`;this.context.taState[o]||(this.context.taState[o]={window:[]});const i=this.context.taState[o],s=t[0];if(i.window.unshift(s),i.window.length<=a)return NaN;i.window.length>a+1&&i.window.pop();const c=i.window[a],l=(s-c)/c*100;return this.context.precision(l)}dev(t,e,n){const a=Array.isArray(e)?e[0]:e;this.context.taState||(this.context.taState={});const o=n||`dev_${a}`;this.context.taState[o]||(this.context.taState[o]={window:[],sum:0});const i=this.context.taState[o],s=t[0]||0;if(i.window.unshift(s),i.sum+=s,i.window.length<a)return NaN;if(i.window.length>a){const h=i.window.pop();i.sum-=h}const c=i.sum/a;let l=0;for(let h=0;h<a;h++)l+=Math.abs(i.window[h]-c);const m=l/a;return this.context.precision(m)}variance(t,e,n){const a=Array.isArray(e)?e[0]:e;this.context.taState||(this.context.taState={});const o=n||`variance_${a}`;this.context.taState[o]||(this.context.taState[o]={window:[]});const i=this.context.taState[o],s=t[0];if(i.window.unshift(s),i.window.length<a)return NaN;i.window.length>a&&i.window.pop();let c=0,l=0;for(let p=0;p<a;p++)c+=i.window[p],l+=i.window[p]*i.window[p];const m=c/a,h=l/a-m*m;return this.context.precision(h)}highest(t,e,n){const a=Array.isArray(e)?e[0]:e;this.context.taState||(this.context.taState={});const o=n||`highest_${a}`;this.context.taState[o]||(this.context.taState[o]={window:[]});const i=this.context.taState[o],s=t[0];if(i.window.unshift(s),i.window.length<a)return NaN;i.window.length>a&&i.window.pop();const c=Math.max(...i.window.filter(l=>!isNaN(l)));return this.context.precision(c)}lowest(t,e,n){const a=Array.isArray(e)?e[0]:e;this.context.taState||(this.context.taState={});const o=n||`lowest_${a}`;this.context.taState[o]||(this.context.taState[o]={window:[]});const i=this.context.taState[o],s=t[0];if(i.window.unshift(s),i.window.length<a)return NaN;i.window.length>a&&i.window.pop();const c=i.window.filter(m=>!isNaN(m)&&m!==void 0),l=c.length>0?Math.min(...c):NaN;return this.context.precision(l)}median(t,e,n){const a=Array.isArray(e)?e[0]:e;this.context.taState||(this.context.taState={});const o=n||`median_${a}`;this.context.taState[o]||(this.context.taState[o]={window:[]});const i=this.context.taState[o],s=t[0];if(i.window.unshift(s),i.window.length<a)return NaN;i.window.length>a&&i.window.pop();const c=i.window.slice().sort((h,p)=>h-p),l=Math.floor(a/2),m=a%2===0?(c[l-1]+c[l])/2:c[l];return this.context.precision(m)}stdev(t,e,n=!0,a){const o=Array.isArray(e)?e[0]:e,i=Array.isArray(n)?n[0]:n;this.context.taState||(this.context.taState={});const s=a||`stdev_${o}_${i}`;this.context.taState[s]||(this.context.taState[s]={window:[],sum:0});const c=this.context.taState[s],l=t[0];if(c.window.unshift(l),c.sum+=l,c.window.length<o)return NaN;if(c.window.length>o){const y=c.window.pop();c.sum-=y}const m=c.sum/o;let h=0;for(let y=0;y<o;y++)h+=Math.pow(c.window[y]-m,2);const p=i?o:o-1,u=Math.sqrt(h/p);return this.context.precision(u)}linreg(t,e,n,a){const o=Array.isArray(e)?e[0]:e,i=Array.isArray(n)?n[0]:n;this.context.taState||(this.context.taState={});const s=a||`linreg_${o}_${i}`;this.context.taState[s]||(this.context.taState[s]={window:[]});const c=this.context.taState[s],l=t[0];if(c.window.unshift(l),c.window.length<o)return NaN;c.window.length>o&&c.window.pop();let m=0,h=0,p=0,u=0;const y=o;for(let _=0;_<o;_++){const C=o-1-_,d=c.window[_];m+=C,h+=d,p+=C*d,u+=C*C}const x=y*u-m*m;if(x===0)return NaN;const w=(y*p-m*h)/x,M=(h-w*m)/y+w*(o-1-i);return this.context.precision(M)}supertrend(t,e,n){const a=Array.isArray(t)?t[0]:t,o=Array.isArray(e)?e[0]:e;this.context.taState||(this.context.taState={});const i=`supertrend_${a}_${o}`;this.context.taState[i]||(this.context.taState[i]={prevUpperBand:null,prevLowerBand:null,prevSupertrend:null,prevDirection:null});const s=this.context.taState[i],c=this.context.data.high[0],l=this.context.data.low[0],m=this.context.data.close[0],h=this.atr(o,n?`${n}_atr`:void 0);if(isNaN(h))return[[NaN,0]];const p=(c+l)/2;let u=p+a*h,y=p-a*h;s.prevUpperBand!==null&&(u<s.prevUpperBand||this.context.data.close[1]>s.prevUpperBand?u=u:u=s.prevUpperBand,y>s.prevLowerBand||this.context.data.close[1]<s.prevLowerBand?y=y:y=s.prevLowerBand);let x,w;return s.prevSupertrend===null?(x=m<=u?-1:1,w=x===-1?u:y):s.prevSupertrend===s.prevUpperBand?m>u?(x=1,w=y):(x=-1,w=u):m<y?(x=-1,w=u):(x=1,w=y),s.prevUpperBand=u,s.prevLowerBand=y,s.prevSupertrend=w,s.prevDirection=x,[[this.context.precision(w),x]]}crossover(t,e){const n=Array.isArray(t)?t[0]:t,a=Array.isArray(e)?e[0]:e,o=Array.isArray(t)?t[1]:this.context.data.series[t][1],i=Array.isArray(e)?e[1]:this.context.data.series[e][1];return o<i&&n>a}crossunder(t,e){const n=Array.isArray(t)?t[0]:t,a=Array.isArray(e)?e[0]:e,o=Array.isArray(t)?t[1]:this.context.data.series[t][1],i=Array.isArray(e)?e[1]:this.context.data.series[e][1];return o>i&&n<a}pivothigh(t,e,n){n==null&&(n=e,e=t,t=this.context.data.high);const a=Array.isArray(e)?e[0]:e,o=Array.isArray(n)?n[0]:n,i=St(t.slice(0).reverse(),a,o),s=this.context.idx;return this.context.precision(i[s])}pivotlow(t,e,n){n==null&&(n=e,e=t,t=this.context.data.low);const a=Array.isArray(e)?e[0]:e,o=Array.isArray(n)?n[0]:n,i=jt(t.slice(0).reverse(),a,o),s=this.context.idx;return this.context.precision(i[s])}}function St(r,t,e){const n=new Array(r.length).fill(NaN);for(let a=t+e;a<r.length;a++){const o=r[a-e];let i=!0;for(let s=1;s<=t;s++)if(r[a-e-s]>=o){i=!1;break}if(i){for(let s=1;s<=e;s++)if(r[a-e+s]>=o){i=!1;break}}i&&(n[a]=o)}return n}function jt(r,t,e){const n=new Array(r.length).fill(NaN);for(let a=t+e;a<r.length;a++){const o=r[a-e];let i=!0;for(let s=1;s<=t;s++)if(r[a-e-s]<=o){i=!1;break}if(i){for(let s=1;s<=e;s++)if(r[a-e+s]<=o){i=!1;break}}i&&(n[a]=o)}return n}var It=Object.defineProperty,Mt=(r,t,e)=>t in r?It(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Ct=(r,t,e)=>Mt(r,typeof t!="symbol"?t+"":t,e);class v{constructor(t){this.array=t}}class Nt{constructor(t){this.context=t,Ct(this,"_cache",{})}param(t,e=0){return Array.isArray(t)?t[e]:t}get(t,e){return t.array[e]}set(t,e,n){t.array[e]=n}push(t,e){t.array.push(e)}sum(t){return t.array.reduce((e,n)=>e+(isNaN(n)?0:n),0)}avg(t){return this.sum(t)/t.array.length}min(t,e=0){return[...t.array].sort((n,a)=>n-a)[e]??this.context.NA}max(t,e=0){return[...t.array].sort((n,a)=>a-n)[e]??this.context.NA}size(t){return t.array.length}new_bool(t,e=!1){return new v(Array(t).fill(e))}new_float(t,e=NaN){return new v(Array(t).fill(e))}new_int(t,e=0){return new v(Array(t).fill(Math.round(e)))}new_string(t,e=""){return new v(Array(t).fill(e))}new(t,e){return new v(Array(t).fill(e))}slice(t,e,n){const a=n!==void 0?n+1:void 0;return new v(t.array.slice(e,a))}reverse(t){t.array.reverse()}includes(t,e){return t.array.includes(e)}indexof(t,e){return t.array.indexOf(e)}lastindexof(t,e){return t.array.lastIndexOf(e)}stdev(t,e=!0){const n=this.avg(t),a=t.array.map(i=>Math.pow(i-n,2)),o=e?t.array.length:t.array.length-1;return Math.sqrt(this.sum(new v(a))/o)}variance(t,e=!0){const n=this.avg(t),a=t.array.map(i=>Math.pow(i-n,2)),o=e?t.array.length:t.array.length-1;return this.sum(new v(a))/o}covariance(t,e,n=!0){if(t.array.length!==e.array.length||t.array.length<2)return NaN;const a=n?t.array.length:t.array.length-1,o=this.avg(t),i=this.avg(e);let s=0;for(let c=0;c<t.array.length;c++)s+=(t.array[c]-o)*(e.array[c]-i);return s/a}first(t){return t.array.length>0?t.array[0]:this.context.NA}last(t){return t.array.length>0?t.array[t.array.length-1]:this.context.NA}clear(t){t.array.length=0}join(t,e=","){return t.array.join(e)}abs(t){return new v(t.array.map(e=>Math.abs(e)))}concat(t,e){return t.array.push(...e.array),t}copy(t){return new v([...t.array])}every(t,e){return t.array.every(e)}fill(t,e,n=0,a){const o=t.array.length,i=a!==void 0?Math.min(a,o):o;for(let s=n;s<i;s++)t.array[s]=e}from(t){return new v([...t])}insert(t,e,n){t.array.splice(e,0,n)}pop(t){return t.array.pop()}range(t){return this.max(t)-this.min(t)}remove(t,e){return e>=0&&e<t.array.length?t.array.splice(e,1)[0]:this.context.NA}shift(t){return t.array.shift()}sort(t,e="asc"){t.array.sort((n,a)=>e==="asc"?n-a:a-n)}sort_indices(t,e){const n=t.array.map((a,o)=>o);return n.sort((a,o)=>{const i=t.array[a],s=t.array[o];return e?e(i,s):i-s}),new v(n)}standardize(t){const e=this.avg(t),n=this.stdev(t);return n===0?new v(t.array.map(()=>0)):new v(t.array.map(a=>(a-e)/n))}unshift(t,e){t.array.unshift(e)}some(t,e){return t.array.some(e)}}var _t=Object.defineProperty,$t=(r,t,e)=>t in r?_t(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,f=(r,t,e)=>$t(r,typeof t!="symbol"?t+"":t,e);class Vt{constructor({marketData:t,source:e,tickerId:n,timeframe:a,limit:o,sDate:i,eDate:s}){f(this,"data",{open:[],high:[],low:[],close:[],volume:[],hl2:[],hlc3:[],ohlc4:[]}),f(this,"cache",{}),f(this,"taState",{}),f(this,"useTACache",!1),f(this,"NA",NaN),f(this,"math"),f(this,"ta"),f(this,"input"),f(this,"request"),f(this,"array"),f(this,"core"),f(this,"lang"),f(this,"idx",0),f(this,"params",{}),f(this,"const",{}),f(this,"var",{}),f(this,"let",{}),f(this,"result"),f(this,"plots",{}),f(this,"marketData"),f(this,"source"),f(this,"tickerId"),f(this,"timeframe",""),f(this,"limit"),f(this,"sDate"),f(this,"eDate"),f(this,"pineTSCode"),this.marketData=t,this.source=e,this.tickerId=n,this.timeframe=a,this.limit=o,this.sDate=i,this.eDate=s,this.math=new bt(this),this.ta=new Et(this),this.input=new yt(this),this.request=new vt(this),this.array=new Nt(this);const c=new ut(this);this.core={plotchar:c.plotchar.bind(c),na:c.na.bind(c),color:c.color,plot:c.plot.bind(c),nz:c.nz.bind(c)}}init(t,e,n=0){return t?!Array.isArray(e)||Array.isArray(e[0])?t[0]=Array.isArray(e?.[0])?e[0]:this.precision(e):t[0]=this.precision(e[e.length-this.idx-1+n]):Array.isArray(e)?t=[this.precision(e[e.length-this.idx-1+n])]:t=[this.precision(e)],t}precision(t,e=10){return typeof t!="number"||isNaN(t)?t:Number(t.toFixed(e))}param(t,e,n){return typeof t=="string"||!Array.isArray(t)&&typeof t=="object"?t:(this.params[n]||(this.params[n]=[]),Array.isArray(t)?e?(this.params[n]=t.slice(e),this.params[n].length=t.length,this.params[n]):(this.params[n]=t.slice(0),this.params[n]):(this.params[n][0]=t,this.params[n]))}}var Bt=Object.defineProperty,Pt=(r,t,e)=>t in r?Bt(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,T=(r,t,e)=>Pt(r,typeof t!="symbol"?t+"":t,e);const kt="https://api.binance.com/api/v3",P={1:"1m",3:"3m",5:"5m",15:"15m",30:"30m",45:null,60:"1h",120:"2h",180:null,240:"4h","4H":"4h","1D":"1d",D:"1d","1W":"1w",W:"1w","1M":"1M",M:"1M"};class Tt{constructor(t=5*60*1e3){T(this,"cache"),T(this,"cacheDuration"),this.cache=new Map,this.cacheDuration=t}generateKey(t){return Object.entries(t).filter(([e,n])=>n!==void 0).map(([e,n])=>`${e}:${n}`).join("|")}get(t){const e=this.generateKey(t),n=this.cache.get(e);return n?Date.now()-n.timestamp>this.cacheDuration?(this.cache.delete(e),null):n.data:null}set(t,e){const n=this.generateKey(t);this.cache.set(n,{data:e,timestamp:Date.now()})}clear(){this.cache.clear()}cleanup(){const t=Date.now();for(const[e,n]of this.cache.entries())t-n.timestamp>this.cacheDuration&&this.cache.delete(e)}}class Dt{constructor(){T(this,"cacheManager"),this.cacheManager=new Tt(5*60*1e3)}async getMarketDataInterval(t,e,n,a){try{const o=P[e.toUpperCase()];if(!o)return console.error(`Unsupported timeframe: ${e}`),[];const i={"1m":60*1e3,"3m":3*60*1e3,"5m":5*60*1e3,"15m":15*60*1e3,"30m":30*60*1e3,"1h":60*60*1e3,"2h":2*60*60*1e3,"4h":4*60*60*1e3,"1d":24*60*60*1e3,"1w":7*24*60*60*1e3,"1M":30*24*60*60*1e3};let s=[],c=n;const l=a,m=i[o];if(!m)return console.error(`Duration not defined for interval: ${o}`),[];for(;c<l;){const h=Math.min(c+1e3*m,l),p=await this.getMarketData(t,e,1e3,c,h);if(p.length===0)break;s=s.concat(p),c=p[p.length-1].closeTime+1}return s}catch(o){return console.error("Error in getMarketDataInterval:",o),[]}}async getMarketData(t,e,n,a,o){try{const i={tickerId:t,timeframe:e,limit:n,sDate:a,eDate:o},s=this.cacheManager.get(i);if(s)return console.log("cache hit",t,e,n,a,o),s;const c=P[e.toUpperCase()];if(!c)return console.error(`Unsupported timeframe: ${e}`),[];if(this.shouldPaginate(e,n,a,o)&&a&&o){const p=await this.getMarketDataInterval(t,e,a,o),u=n?p.slice(0,n):p;return this.cacheManager.set(i,u),u}let l=`${kt}/klines?symbol=${t}&interval=${c}`;n&&(l+=`&limit=${Math.min(n,1e3)}`),a&&(l+=`&startTime=${a}`),o&&(l+=`&endTime=${o}`);const m=await fetch(l);if(!m.ok)throw new Error(`HTTP error! status: ${m.status}`);const h=(await m.json()).map(p=>({openTime:parseInt(p[0]),open:parseFloat(p[1]),high:parseFloat(p[2]),low:parseFloat(p[3]),close:parseFloat(p[4]),volume:parseFloat(p[5]),closeTime:parseInt(p[6]),quoteAssetVolume:parseFloat(p[7]),numberOfTrades:parseInt(p[8]),takerBuyBaseAssetVolume:parseFloat(p[9]),takerBuyQuoteAssetVolume:parseFloat(p[10]),ignore:p[11]}));return this.cacheManager.set(i,h),h}catch(i){return console.error("Error in binance.klines:",i),[]}}shouldPaginate(t,e,n,a){if(e&&e>1e3)return!0;if(n&&a){const o=P[t.toUpperCase()],i={"1m":60*1e3,"3m":3*60*1e3,"5m":5*60*1e3,"15m":15*60*1e3,"30m":30*60*1e3,"1h":60*60*1e3,"2h":2*60*60*1e3,"4h":4*60*60*1e3,"1d":24*60*60*1e3,"1w":7*24*60*60*1e3,"1M":30*24*60*60*1e3}[o];if(i)return Math.ceil((a-n)/i)>1e3}return!1}}const Lt={Binance:new Dt};export{Vt as Context,ct as PineTS,Lt as Provider};
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { Context } from '@pinets/index';
|
|
2
2
|
import { IProvider } from '@pinets/marketData/IProvider';
|
|
3
|
-
/**
|
|
4
|
-
* This class is a wrapper for the Pine Script language, it allows to run Pine Script code in a JavaScript environment
|
|
5
|
-
*/
|
|
6
3
|
export declare class PineTS {
|
|
7
4
|
private source;
|
|
8
5
|
private tickerId?;
|
|
@@ -4,4 +4,8 @@ export declare class BinanceProvider implements IProvider {
|
|
|
4
4
|
constructor();
|
|
5
5
|
getMarketDataInterval(tickerId: string, timeframe: string, sDate: number, eDate: number): Promise<any>;
|
|
6
6
|
getMarketData(tickerId: string, timeframe: string, limit?: number, sDate?: number, eDate?: number): Promise<any>;
|
|
7
|
+
/**
|
|
8
|
+
* Determines if pagination is needed based on the parameters
|
|
9
|
+
*/
|
|
10
|
+
private shouldPaginate;
|
|
7
11
|
}
|
|
@@ -3,6 +3,7 @@ export declare class PineMath {
|
|
|
3
3
|
private _cache;
|
|
4
4
|
constructor(context: any);
|
|
5
5
|
param(source: any, index: any, name?: string): any;
|
|
6
|
+
__eq(a: number, b: number): boolean;
|
|
6
7
|
abs(source: number[]): number;
|
|
7
8
|
pow(source: number[], power: number[]): number;
|
|
8
9
|
sqrt(source: number[]): number;
|
|
@@ -3,25 +3,25 @@ export declare class TechnicalAnalysis {
|
|
|
3
3
|
constructor(context: any);
|
|
4
4
|
get tr(): any;
|
|
5
5
|
param(source: any, index: any, name?: string): any;
|
|
6
|
-
ema(source: any, _period: any): any;
|
|
7
|
-
sma(source: any, _period: any,
|
|
8
|
-
vwma(source: any, _period: any): any;
|
|
9
|
-
wma(source: any, _period: any): any;
|
|
10
|
-
hma(source: any, _period: any): any;
|
|
11
|
-
rma(source: any, _period: any): any;
|
|
12
|
-
change(source: any, _length?: number): any;
|
|
13
|
-
rsi(source: any, _period: any): any;
|
|
14
|
-
atr(_period: any): any;
|
|
15
|
-
mom(source: any, _length: any): any;
|
|
16
|
-
roc(source: any, _length: any): any;
|
|
17
|
-
dev(source: any, _length: any): any;
|
|
18
|
-
variance(source: any, _length: any): any;
|
|
19
|
-
highest(source: any, _length: any): any;
|
|
20
|
-
lowest(source: any, _length: any): any;
|
|
21
|
-
median(source: any, _length: any): any;
|
|
22
|
-
stdev(source: any, _length: any, _bias?: boolean): any;
|
|
23
|
-
linreg(source: any, _length: any, _offset: any): any;
|
|
24
|
-
supertrend(_factor: any, _atrPeriod: any): any[][];
|
|
6
|
+
ema(source: any, _period: any, _callId?: any): any;
|
|
7
|
+
sma(source: any, _period: any, _callId?: any): any;
|
|
8
|
+
vwma(source: any, _period: any, _callId?: any): any;
|
|
9
|
+
wma(source: any, _period: any, _callId?: any): any;
|
|
10
|
+
hma(source: any, _period: any, _callId?: any): any;
|
|
11
|
+
rma(source: any, _period: any, _callId?: any): any;
|
|
12
|
+
change(source: any, _length?: number, _callId?: any): any;
|
|
13
|
+
rsi(source: any, _period: any, _callId?: any): any;
|
|
14
|
+
atr(_period: any, _callId?: any): any;
|
|
15
|
+
mom(source: any, _length: any, _callId?: any): any;
|
|
16
|
+
roc(source: any, _length: any, _callId?: any): any;
|
|
17
|
+
dev(source: any, _length: any, _callId?: any): any;
|
|
18
|
+
variance(source: any, _length: any, _callId?: any): any;
|
|
19
|
+
highest(source: any, _length: any, _callId?: any): any;
|
|
20
|
+
lowest(source: any, _length: any, _callId?: any): any;
|
|
21
|
+
median(source: any, _length: any, _callId?: any): any;
|
|
22
|
+
stdev(source: any, _length: any, _bias?: boolean, _callId?: any): any;
|
|
23
|
+
linreg(source: any, _length: any, _offset: any, _callId?: any): any;
|
|
24
|
+
supertrend(_factor: any, _atrPeriod: any, _callId?: any): any[][];
|
|
25
25
|
crossover(source1: any, source2: any): boolean;
|
|
26
26
|
crossunder(source1: any, source2: any): boolean;
|
|
27
27
|
pivothigh(source: any, _leftbars: any, _rightbars: any): any;
|
|
@@ -11,14 +11,17 @@ export declare class ScopeManager {
|
|
|
11
11
|
private paramIdCounter;
|
|
12
12
|
private cacheIdCounter;
|
|
13
13
|
private tempVarCounter;
|
|
14
|
+
private taCallIdCounter;
|
|
14
15
|
get nextParamIdArg(): any;
|
|
15
16
|
get nextCacheIdArg(): any;
|
|
17
|
+
getNextTACallId(): any;
|
|
16
18
|
constructor();
|
|
17
19
|
pushScope(type: string): void;
|
|
18
20
|
popScope(): void;
|
|
19
21
|
getCurrentScopeType(): string;
|
|
20
22
|
getCurrentScopeCount(): number;
|
|
21
23
|
addContextBoundVar(name: string, isRootParam?: boolean): void;
|
|
24
|
+
removeContextBoundVar(name: any): void;
|
|
22
25
|
addArrayPatternElement(name: string): void;
|
|
23
26
|
isContextBound(name: string): boolean;
|
|
24
27
|
isArrayPatternElement(name: string): boolean;
|