@kodiak-finance/orderly-ui-tradingview 2.8.18 → 2.8.19-rc.0
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/dist/index.js +4369 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4366 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -11
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
-
var
|
|
4
|
+
var React3 = require('react');
|
|
5
5
|
var orderlyI18n = require('@kodiak-finance/orderly-i18n');
|
|
6
6
|
var orderlyUi = require('@kodiak-finance/orderly-ui');
|
|
7
7
|
var orderlyHooks = require('@kodiak-finance/orderly-hooks');
|
|
@@ -11,12 +11,4375 @@ var dateFns = require('date-fns');
|
|
|
11
11
|
|
|
12
12
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var React3__default = /*#__PURE__*/_interopDefault(React3);
|
|
15
15
|
|
|
16
|
-
var ei=Object.defineProperty;var K=(r,e)=>()=>(r&&(e=r(r=0)),e);var Be=(r,e)=>{for(var t in e)ei(r,t,{get:e[t],enumerable:true});};var $,Ee,st,cr,ur,dr,pr,mr,gr,hr,fr,br,Z=K(()=>{$=r=>jsxRuntime.jsx("svg",{viewBox:"0 0 12 12",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",...r,children:jsxRuntime.jsx("g",{id:"Caret-down",children:jsxRuntime.jsx("path",{id:"Vector",d:"M3.00349 3.9978C2.59149 3.9978 2.36564 4.4653 2.61289 4.7948C2.98789 5.2948 5.23784 8.29479 5.61289 8.79479C5.81289 9.06128 6.20974 9.06128 6.40974 8.79479L9.40974 4.7948C9.65694 4.4653 9.41554 3.9978 9.00349 3.9978H3.00349Z"})})}),Ee=r=>jsxRuntime.jsx("svg",{viewBox:"0 0 18 18",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",...r,children:jsxRuntime.jsx("g",{id:"Display settings",children:jsxRuntime.jsx("path",{id:"Union",fillRule:"evenodd",clipRule:"evenodd",d:"M15.0571 10.9856L11.6295 5.06523L8.71377 10.8968C8.38933 11.5456 7.54464 11.7223 6.98733 11.2579L5.75311 10.2294L2.83709 14.7654L1.57532 13.9543L4.49134 9.41824C4.97892 8.65978 6.0207 8.49981 6.71338 9.07705L7.58387 9.80246L10.5991 3.77192C10.9997 2.97082 12.1302 2.93624 12.579 3.71137L14.6517 7.29147C14.7714 7.03643 15.0305 6.85983 15.3309 6.85983C15.7451 6.85983 16.0809 7.19562 16.0809 7.60983C16.0809 8.02405 15.7451 8.35983 15.3309 8.35983C15.31 8.35983 15.2892 8.35897 15.2687 8.35729L16.3553 10.2341L15.0571 10.9856ZM2.58093 6.85983C2.16672 6.85983 1.83093 7.19562 1.83093 7.60983C1.83093 8.02405 2.16672 8.35983 2.58093 8.35983C2.99515 8.35983 3.33093 8.02405 3.33093 7.60983C3.33093 7.19562 2.99515 6.85983 2.58093 6.85983ZM4.83093 6.85983C4.41672 6.85983 4.08093 7.19562 4.08093 7.60983C4.08093 8.02405 4.41672 8.35983 4.83093 8.35983C5.24515 8.35983 5.58093 8.02405 5.58093 7.60983C5.58093 7.19562 5.24515 6.85983 4.83093 6.85983ZM6.33093 7.60983C6.33093 7.19562 6.66672 6.85983 7.08093 6.85983C7.49515 6.85983 7.83093 7.19562 7.83093 7.60983C7.83093 8.02405 7.49515 8.35983 7.08093 8.35983C6.66672 8.35983 6.33093 8.02405 6.33093 7.60983ZM11.5809 6.85983C11.1667 6.85983 10.8309 7.19562 10.8309 7.60983C10.8309 8.02405 11.1667 8.35983 11.5809 8.35983C11.9951 8.35983 12.3309 8.02405 12.3309 7.60983C12.3309 7.19562 11.9951 6.85983 11.5809 6.85983Z"})})}),st=r=>jsxRuntime.jsx("svg",{viewBox:"0 0 18 18",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",...r,children:jsxRuntime.jsx("g",{id:"Indicators",children:jsxRuntime.jsx("path",{id:"Union",fillRule:"evenodd",clipRule:"evenodd",d:"M9.74483 2.25C8.96145 2.25 8.26885 2.76459 8.04549 3.51818L7.46202 5.48254H5.06262V7.08339H6.98652L5.00539 13.7532L4.31554 13.1112L3.22498 14.2831L4.4777 15.4489C5.08739 16.015 6.08317 15.7469 6.32134 14.945L8.65649 7.08339H11.6032V5.48254H9.13198L9.58033 3.97311C9.60167 3.90112 9.66833 3.85084 9.74483 3.85084H11.69V2.25H9.74483ZM10.6234 11.2354L10.2638 11.5172C10.0153 11.712 9.65591 11.6684 9.46115 11.4199C9.26639 11.1713 9.30998 10.812 9.55852 10.6172L10.1451 10.1575C10.5693 9.82514 11.1868 9.94011 11.4642 10.4005L11.4682 10.407L12.1304 11.5752L13.4594 10.3111C13.6882 10.0935 14.05 10.1025 14.2677 10.3313C14.4853 10.5601 14.4763 10.922 14.2475 11.1396L12.7116 12.6006L13.3897 13.797L13.6482 13.4503C13.8369 13.1972 14.1951 13.145 14.4483 13.3337C14.7014 13.5225 14.7536 13.8807 14.5649 14.1338L13.9917 14.9025L13.94 14.9457C13.5178 15.2981 12.8837 15.1886 12.6003 14.7226L12.5958 14.7151L11.8576 13.4129L10.3563 14.841C10.1275 15.0586 9.76561 15.0495 9.54798 14.8208C9.33036 14.592 9.3394 14.2301 9.56819 14.0125L11.2764 12.3875L10.6234 11.2354Z"})})}),cr=r=>jsxRuntime.jsx("svg",{viewBox:"0 0 18 18",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",...r,children:jsxRuntime.jsx("g",{id:"Setting",children:jsxRuntime.jsx("path",{id:"Vector",d:"M6.72589 1.84154C5.66239 2.17904 4.74515 2.72954 3.93665 3.48254C3.6869 3.71504 3.6104 4.09604 3.7724 4.39604C4.37315 5.50679 3.74464 6.69554 2.38939 6.76379C2.05789 6.78029 1.76465 7.0263 1.68665 7.34955C1.5524 7.9083 1.49915 8.37629 1.49915 8.98979C1.49915 9.50504 1.55464 10.0885 1.66339 10.6075C1.73089 10.9315 2.0129 11.1648 2.3429 11.1933C3.7064 11.311 4.3814 12.3513 3.7724 13.6773C3.6374 13.972 3.6989 14.3245 3.93665 14.545C4.73315 15.2815 5.64814 15.8013 6.72589 16.1388C7.03339 16.2348 7.38064 16.1185 7.56964 15.8575C8.40364 14.7033 9.6134 14.6995 10.4054 15.8575C10.5921 16.1298 10.9341 16.261 11.2491 16.162C12.2894 15.8343 13.2584 15.277 14.0616 14.545C14.3091 14.3193 14.3744 13.954 14.2259 13.654C13.6019 12.3948 14.3197 11.239 15.6082 11.2165C15.9502 11.2105 16.2547 10.9863 16.3349 10.654C16.4647 10.1163 16.4991 9.64829 16.4991 8.98979C16.4991 8.42429 16.4324 7.86704 16.3116 7.32629C16.2351 6.98354 15.9359 6.74054 15.5849 6.73979C14.3167 6.73754 13.6056 5.49104 14.2259 4.39604C14.3984 4.09154 14.3444 3.71804 14.0849 3.48254C13.2674 2.74004 12.2706 2.15954 11.2259 1.84154C10.9049 1.74404 10.5636 1.86404 10.3821 2.14604C9.65764 3.27179 8.30465 3.29129 7.5929 2.17004C7.41065 1.88204 7.04989 1.73879 6.72589 1.84154ZM11.2844 3.43455C11.7966 3.64905 12.2009 3.8733 12.6651 4.22505C12.1206 5.9478 13.0439 7.73729 14.9564 8.17304C15.0036 8.48279 14.9991 8.67029 14.9991 8.98979C14.9991 9.37154 15.0044 9.50579 14.9609 9.78179C13.0566 10.1763 12.1146 11.9155 12.6449 13.7538C12.1889 14.0845 11.8626 14.314 11.2904 14.5353C9.94639 13.1673 8.0804 13.1073 6.7079 14.5443C6.1724 14.3088 5.76066 14.0995 5.34441 13.7478C5.86041 11.881 4.98815 10.2693 3.05165 9.7803C2.9654 9.4383 2.9999 8.4723 3.0494 8.17905C5.0519 7.69905 5.8409 5.92679 5.34365 4.21979C5.78315 3.88904 6.1784 3.6483 6.69215 3.4398C7.9859 4.75605 9.92839 4.8873 11.2844 3.43455ZM8.99915 5.98979C7.3424 5.98979 5.99915 7.33304 5.99915 8.98979C5.99915 10.6473 7.3424 11.9898 8.99915 11.9898C10.6559 11.9898 11.9991 10.6473 11.9991 8.98979C11.9991 7.33304 10.6559 5.98979 8.99915 5.98979ZM8.99915 7.48979C9.8279 7.48979 10.4991 8.16179 10.4991 8.98979C10.4991 9.81855 9.8279 10.4898 8.99915 10.4898C8.1704 10.4898 7.49915 9.81855 7.49915 8.98979C7.49915 8.16179 8.1704 7.48979 8.99915 7.48979Z"})})}),ur=r=>jsxRuntime.jsx("svg",{viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",...r,children:jsxRuntime.jsx("g",{id:"Bars",children:jsxRuntime.jsx("path",{id:"Union",fillRule:"evenodd",clipRule:"evenodd",d:"M12.5 15.5C12.5 15.7761 12.7239 16 13 16H14C14.2761 16 14.5 15.7761 14.5 15.5V14H16C16.2761 14 16.5 13.7761 16.5 13.5V12.5C16.5 12.2239 16.2761 12 16 12H14.5V2.5C14.5 2.22386 14.2761 2 14 2H13C12.7239 2 12.5 2.22386 12.5 2.5V4H11C10.7239 4 10.5 4.22386 10.5 4.5V5.5C10.5 5.77614 10.7239 6 11 6H12.5V15.5ZM5.5 17.5C5.5 17.7761 5.72386 18 6 18H7C7.27614 18 7.5 17.7761 7.5 17.5V10H9C9.27614 10 9.5 9.77614 9.5 9.5V8.5C9.5 8.22386 9.27614 8 9 8H7.5V4.5C7.5 4.22386 7.27614 4 7 4H6C5.72386 4 5.5 4.22386 5.5 4.5V14H4C3.72386 14 3.5 14.2239 3.5 14.5V15.5C3.5 15.7761 3.72386 16 4 16H5.5V17.5Z"})})}),dr=r=>jsxRuntime.jsx("svg",{viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",...r,children:jsxRuntime.jsx("g",{id:"Candles",children:jsxRuntime.jsx("path",{id:"Union",fillRule:"evenodd",clipRule:"evenodd",d:"M7.25 2.5V4H8.5C8.77614 4 9 4.22386 9 4.5V15.5C9 15.7761 8.77614 16 8.5 16H7.25V17.5C7.25 17.7761 7.02614 18 6.75 18H6.25C5.97386 18 5.75 17.7761 5.75 17.5V16H4.5C4.22386 16 4 15.7761 4 15.5V4.5C4 4.22386 4.22386 4 4.5 4H5.75V2.5C5.75 2.22386 5.97386 2 6.25 2H6.75C7.02614 2 7.25 2.22386 7.25 2.5ZM5.5 5.5V14.5H7.5V5.5H5.5ZM14.25 4.5V7H15.5C15.7761 7 16 7.22386 16 7.5V15.5C16 15.7761 15.7761 16 15.5 16H14.25V17.5C14.25 17.7761 14.0261 18 13.75 18H13.25C12.9739 18 12.75 17.7761 12.75 17.5V16H11.5C11.2239 16 11 15.7761 11 15.5V7.5C11 7.22386 11.2239 7 11.5 7H12.75V4.5C12.75 4.22386 12.9739 4 13.25 4H13.75C14.0261 4 14.25 4.22386 14.25 4.5ZM12.5 8.5V14.5H14.5V8.5H12.5Z"})})}),pr=r=>jsxRuntime.jsx("svg",{viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",...r,children:jsxRuntime.jsxs("g",{id:"Hollow Candles",children:[jsxRuntime.jsx("path",{id:"Subtract",fillRule:"evenodd",clipRule:"evenodd",d:"M5.5 14.5V5.5H7.5V14.5H5.5Z",fill:"white",fillOpacity:"0.12"}),jsxRuntime.jsx("path",{id:"Union",fillRule:"evenodd",clipRule:"evenodd",d:"M7.25 2.5V4H8.5C8.77614 4 9 4.22386 9 4.5V15.5C9 15.7761 8.77614 16 8.5 16H7.25V17.5C7.25 17.7761 7.02614 18 6.75 18H6.25C5.97386 18 5.75 17.7761 5.75 17.5V16H4.5C4.22386 16 4 15.7761 4 15.5V4.5C4 4.22386 4.22386 4 4.5 4H5.75V2.5C5.75 2.22386 5.97386 2 6.25 2H6.75C7.02614 2 7.25 2.22386 7.25 2.5ZM5.5 5.5V14.5H7.5V5.5H5.5ZM14.25 4.5V7H15.5C15.7761 7 16 7.22386 16 7.5V15.5C16 15.7761 15.7761 16 15.5 16H14.25V17.5C14.25 17.7761 14.0261 18 13.75 18H13.25C12.9739 18 12.75 17.7761 12.75 17.5V16H11.5C11.2239 16 11 15.7761 11 15.5V7.5C11 7.22386 11.2239 7 11.5 7H12.75V4.5C12.75 4.22386 12.9739 4 13.25 4H13.75C14.0261 4 14.25 4.22386 14.25 4.5ZM12.5 8.5V14.5H14.5V8.5H12.5Z"})]})}),mr=r=>jsxRuntime.jsx("svg",{viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",...r,children:jsxRuntime.jsx("g",{id:"Line",children:jsxRuntime.jsx("path",{id:"Vector 16 (Stroke)",fillRule:"evenodd",clipRule:"evenodd",d:"M18.3 2.72288C18.542 2.85596 18.6303 3.15999 18.4972 3.40195L13.495 12.4968C13.0776 13.2557 12.1061 13.5044 11.3754 13.0394L7.19878 10.3816L2.97738 17.558C2.83737 17.796 2.53092 17.8754 2.2929 17.7354L1.43097 17.2284C1.19295 17.0884 1.1135 16.7819 1.25351 16.5439L5.73746 8.92122C6.16792 8.18943 7.1194 7.96045 7.83567 8.41626L11.9995 11.0659L16.7448 2.43811C16.8778 2.19615 17.1819 2.10788 17.4238 2.24096L18.3 2.72288Z"})})}),gr=r=>jsxRuntime.jsx("svg",{viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",...r,children:jsxRuntime.jsxs("g",{id:"Area",children:[jsxRuntime.jsx("path",{id:"Vector 16 (Stroke)",fillRule:"evenodd",clipRule:"evenodd",d:"M18.3 2.72288C18.542 2.85596 18.6303 3.15999 18.4972 3.40195L13.495 12.4968C13.0776 13.2557 12.1061 13.5044 11.3754 13.0394L7.19878 10.3816L2.97738 17.558C2.83737 17.796 2.53092 17.8754 2.2929 17.7354L1.43097 17.2284C1.19295 17.0884 1.1135 16.7819 1.25351 16.5439L5.73746 8.92122C6.16792 8.18943 7.1194 7.96045 7.83567 8.41626L11.9995 11.0659L16.7448 2.43811C16.8778 2.19615 17.1819 2.10788 17.4238 2.24096L18.3 2.72288Z"}),jsxRuntime.jsx("path",{id:"Subtract",fillRule:"evenodd",clipRule:"evenodd",d:"M2.7608 17.7562C2.84602 17.899 3.00106 18 3.19016 18H16.362C17.4665 18 18.362 17.1046 18.362 16V3.94663C18.362 3.86618 18.3453 3.79397 18.3162 3.73108L13.495 12.4968C13.0776 13.2557 12.1061 13.5044 11.3754 13.0394L7.19881 10.3816L2.9774 17.558C2.92465 17.6477 2.84826 17.7148 2.7608 17.7562Z",fill:"white",fillOpacity:"0.12"})]})}),hr=r=>jsxRuntime.jsx("svg",{viewBox:"0 0 20 20",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",...r,children:jsxRuntime.jsx("g",{id:"Baseline",children:jsxRuntime.jsx("path",{id:"Union",fillRule:"evenodd",clipRule:"evenodd",d:"M6.05938 2.93544C6.55642 1.71198 8.27766 1.68139 8.81785 2.88642L11.4361 8.72723H9.24438L7.4717 4.77279L5.86521 8.72723H3.70647L6.05938 2.93544ZM13.9282 14.2865L13.0051 12.2272H10.8133L12.5586 16.1204C13.088 17.3014 14.7641 17.3026 15.2952 16.1224L17.048 12.2272H14.8549L13.9282 14.2865ZM2.28459 12.2272H4.44333L1.85293 18.6036L0 17.8509L2.28459 12.2272ZM16.4299 8.72723H18.623L19.3384 7.13759L17.5145 6.31686L16.4299 8.72723ZM1.42645 10.2272C1.42645 9.95109 1.65031 9.72723 1.92645 9.72723H2.92645C3.20259 9.72723 3.42645 9.95109 3.42645 10.2272V10.7272C3.42645 11.0034 3.20259 11.2272 2.92645 11.2272H1.92645C1.65031 11.2272 1.42645 11.0034 1.42645 10.7272V10.2272ZM4.42645 10.2272C4.42645 9.95109 4.65031 9.72723 4.92645 9.72723H5.92645C6.20259 9.72723 6.42645 9.95109 6.42645 10.2272V10.7272C6.42645 11.0034 6.20259 11.2272 5.92645 11.2272H4.92645C4.65031 11.2272 4.42645 11.0034 4.42645 10.7272V10.2272ZM7.92645 9.72723C7.65031 9.72723 7.42645 9.95109 7.42645 10.2272V10.7272C7.42645 11.0034 7.65031 11.2272 7.92645 11.2272H8.92645C9.20259 11.2272 9.42645 11.0034 9.42645 10.7272V10.2272C9.42645 9.95109 9.20259 9.72723 8.92645 9.72723H7.92645ZM10.4265 10.2272C10.4265 9.95109 10.6503 9.72723 10.9265 9.72723H11.9265C12.2026 9.72723 12.4265 9.95109 12.4265 10.2272V10.7272C12.4265 11.0034 12.2026 11.2272 11.9265 11.2272H10.9265C10.6503 11.2272 10.4265 11.0034 10.4265 10.7272V10.2272ZM13.9265 9.72723C13.6503 9.72723 13.4265 9.95109 13.4265 10.2272V10.7272C13.4265 11.0034 13.6503 11.2272 13.9265 11.2272H14.9265C15.2026 11.2272 15.4265 11.0034 15.4265 10.7272V10.2272C15.4265 9.95109 15.2026 9.72723 14.9265 9.72723H13.9265ZM16.4265 10.2272C16.4265 9.95109 16.6503 9.72723 16.9265 9.72723H17.9265C18.2026 9.72723 18.4265 9.95109 18.4265 10.2272V10.7272C18.4265 11.0034 18.2026 11.2272 17.9265 11.2272H16.9265C16.6503 11.2272 16.4265 11.0034 16.4265 10.7272V10.2272Z"})})}),fr=r=>jsxRuntime.jsx("svg",{viewBox:"0 0 12 12",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",...r,children:jsxRuntime.jsx("g",{id:"Unselected",children:jsxRuntime.jsx("path",{id:"Vector",d:"M6.00684 0.999023C3.24544 0.999023 1.00684 3.23752 1.00684 5.99902C1.00684 8.76051 3.24544 10.999 6.00684 10.999C8.76834 10.999 11.0068 8.76051 11.0068 5.99902C11.0068 3.23752 8.76834 0.999023 6.00684 0.999023ZM6.00684 1.99902C8.21584 1.99902 10.0068 3.79002 10.0068 5.99902C10.0068 8.20801 8.21584 9.99901 6.00684 9.99901C3.79769 9.99901 2.00684 8.20801 2.00684 5.99902C2.00684 3.79002 3.79769 1.99902 6.00684 1.99902Z",fill:"white",fillOpacity:"0.2"})})}),br=r=>jsxRuntime.jsx("svg",{viewBox:"0 0 12 12",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg",...r,children:jsxRuntime.jsx("g",{id:"Selected-Multiple Choices-fill",children:jsxRuntime.jsx("path",{id:"Subtract",fillRule:"evenodd",clipRule:"evenodd",d:"M1.00684 5.99902C1.00684 3.23752 3.24544 0.999023 6.00684 0.999023C8.76834 0.999023 11.0068 3.23752 11.0068 5.99902C11.0068 8.76051 8.76834 10.999 6.00684 10.999C3.24544 10.999 1.00684 8.76051 1.00684 5.99902ZM8.49243 3.65563C8.60602 3.54726 8.76156 3.49957 8.91068 3.49957C9.05981 3.49957 9.21534 3.54726 9.32893 3.65563C9.5567 3.87231 9.5567 4.23649 9.32893 4.45317L5.25362 8.33706C5.02644 8.55374 4.6443 8.55374 4.41712 8.33706L2.67014 6.67253C2.44296 6.45585 2.44296 6.09161 2.67014 5.87499C2.89791 5.65831 3.28004 5.65831 3.50722 5.87499L4.83537 7.1407L8.49243 3.65563Z",fill:"#608CFF"})})});});var Pr={};Be(Pr,{default:()=>Po});var Oo,Po,xr=K(()=>{Z();Oo=r=>{let[e,t]=R.useState(false),{t:i}=orderlyI18n.useTranslation(),o=R.useMemo(()=>[{icon:jsxRuntime.jsx(ur,{fill:"currentColor",className:"oui-w-5 oui-h-5"}),label:i("tradingView.lineType.bars"),value:"0"},{icon:jsxRuntime.jsx(dr,{fill:"currentColor",className:"oui-w-5 oui-h-5"}),label:i("tradingView.lineType.candles"),value:"1"},{icon:jsxRuntime.jsx(pr,{fill:"currentColor",className:"oui-w-5 oui-h-5"}),label:i("tradingView.lineType.hollowCandles"),value:"9"},{icon:jsxRuntime.jsx(mr,{fill:"currentColor",className:"oui-w-5 oui-h-5"}),label:i("tradingView.lineType.line"),value:"2"},{icon:jsxRuntime.jsx(gr,{fill:"currentColor",className:"oui-w-5 oui-h-5"}),label:i("tradingView.lineType.area"),value:"3"},{icon:jsxRuntime.jsx(hr,{fill:"currentColor",className:"oui-w-5 oui-h-5"}),label:i("tradingView.lineType.baseline"),value:"10"}],[i]),s=R.useMemo(()=>{let n=o.find(a=>a.value===r.lineType);return n?n.icon:o[1].icon},[r.lineType]);return jsxRuntime.jsxs(orderlyUi.DropdownMenuRoot,{open:e,onOpenChange:t,children:[jsxRuntime.jsx(orderlyUi.DropdownMenuTrigger,{asChild:true,children:jsxRuntime.jsx(orderlyUi.Box,{className:orderlyUi.cn("oui-w-[18px] oui-h-[18px] oui-cursor-pointer oui-text-base-contrast-36 hover:oui-text-base-contrast-80",e&&"oui-text-base-contrast-80"),children:s})}),jsxRuntime.jsx(orderlyUi.DropdownMenuPortal,{children:jsxRuntime.jsx(orderlyUi.DropdownMenuContent,{onCloseAutoFocus:n=>n.preventDefault(),onClick:n=>n.stopPropagation(),align:"start",sideOffset:20,className:"oui-bg-base-8",children:jsxRuntime.jsx(orderlyUi.Flex,{direction:"column",gap:4,px:5,py:5,width:240,justify:"start",itemAlign:"start",children:o.map(n=>jsxRuntime.jsxs(orderlyUi.Flex,{justify:"start",itemAlign:"center",gap:2,className:orderlyUi.cn("oui-text-base-contrast-36 oui-cursor-pointer oui-w-full hover:oui-text-base-contrast",r.lineType===n.value&&"oui-text-base-contrast"),onClick:()=>r.changeLineType(n.value),children:[n.icon,jsxRuntime.jsx(orderlyUi.Text,{className:"oui-text-sm",children:n.label})]},n.value))})})})]})},Po=Oo;});var Er={};Be(Er,{MobileTimeInterval:()=>Rr,TimeInterval:()=>Vo});var wr,Vo,No,Rr,Ho,kr=K(()=>{Z();wr=()=>{let{t:r}=orderlyI18n.useTranslation();return {mobileTimeIntervalMoreMap:R.useMemo(()=>[[{value:"3",label:r("tradingView.timeInterval.3m")},{value:"5",label:r("tradingView.timeInterval.5m")},{value:"30",label:r("tradingView.timeInterval.30m")},{value:"120",label:r("tradingView.timeInterval.2h")}],[{value:"360",label:r("tradingView.timeInterval.6h")},{value:"720",label:r("tradingView.timeInterval.12h")},{value:"3d",label:r("tradingView.timeInterval.3d")},{value:"1M",label:r("tradingView.timeInterval.1M")}]],[r])}},Vo=r=>orderlyHooks.useMediaQuery(orderlyTypes.MEDIA_TABLET)?jsxRuntime.jsx(Rr,{...r}):jsxRuntime.jsx(No,{...r}),No=r=>{let{t:e}=orderlyI18n.useTranslation(),t=R.useMemo(()=>[{value:"1",label:e("tradingView.timeInterval.1m")},{value:"3",label:e("tradingView.timeInterval.3m")},{value:"5",label:e("tradingView.timeInterval.5m")},{value:"15",label:e("tradingView.timeInterval.15m")},{value:"30",label:e("tradingView.timeInterval.30m")},{value:"60",label:e("tradingView.timeInterval.1h")},{value:"240",label:e("tradingView.timeInterval.4h")},{value:"720",label:e("tradingView.timeInterval.12h")},{value:"1D",label:e("tradingView.timeInterval.1d")},{value:"1W",label:e("tradingView.timeInterval.1w")},{value:"1M",label:e("tradingView.timeInterval.1M")}],[e]);return jsxRuntime.jsx("div",{className:orderlyUi.cn("oui-text-2xs oui-text-base-contrast-36 oui-flex oui-gap-[2px] oui-items-center oui-mr-3 oui-font-semibold","oui-overflow-hidden"),children:t.map(i=>jsxRuntime.jsx("div",{className:orderlyUi.cn("oui-cursor-pointer oui-px-2","hover:oui-text-base-contrast-80","oui-break-normal oui-whitespace-nowrap",r.interval===i.value&&"oui-text-base-contrast-80 oui-bg-white/[.06] oui-rounded"),id:i.value,onClick:()=>r.changeInterval(i.value),children:i.label},i.value))})},Rr=r=>{let{t:e}=orderlyI18n.useTranslation(),t=R.useMemo(()=>[{value:"1",label:e("tradingView.timeInterval.1m")},{value:"15",label:e("tradingView.timeInterval.15m")},{value:"60",label:e("tradingView.timeInterval.1h")},{value:"240",label:e("tradingView.timeInterval.4h")},{value:"1D",label:e("tradingView.timeInterval.1d")},{value:"1W",label:e("tradingView.timeInterval.1w")}],[e]),{mobileTimeIntervalMoreMap:i}=wr(),o=R.useMemo(()=>{for(let s of i)for(let n of s)if(n.value===r.interval)return n.label;return null},[r.interval,i]);return jsxRuntime.jsxs(orderlyUi.Flex,{justify:"start",itemAlign:"center",gap:3,className:orderlyUi.cn("oui-text-2xs oui-text-base-contrast-36","oui-overflow-hidden"),children:[jsxRuntime.jsx("div",{className:" oui-flex oui-gap-1 oui-items-center oui-mr-3 oui-font-semibold",children:t.map(s=>jsxRuntime.jsx("div",{className:orderlyUi.cn("oui-px-2","oui-break-normal oui-whitespace-nowrap",r.interval===s.value&&"oui-text-base-contrast-80 oui-bg-white/[.06] oui-rounded"),onClick:()=>r.changeInterval(s.value),children:s.label},s.value))}),jsxRuntime.jsx(Ho,{...r,children:o?jsxRuntime.jsx("div",{className:"oui-text-base-contrast-80",children:o}):jsxRuntime.jsx(orderlyUi.Text,{className:"oui-break-normal oui-whitespace-nowrap",children:e("tradingView.timeInterval.more")})})]})},Ho=r=>{let[e,t]=R__default.default.useState(false),{mobileTimeIntervalMoreMap:i}=wr();return jsxRuntime.jsxs(orderlyUi.DropdownMenuRoot,{open:e,onOpenChange:t,children:[jsxRuntime.jsx(orderlyUi.DropdownMenuTrigger,{asChild:true,children:jsxRuntime.jsxs("div",{className:"oui-flex oui-justify-start oui-items-center oui-gap-0.5",children:[r.children,jsxRuntime.jsx($,{className:orderlyUi.cn("oui-w-3 oui-h-3",e&&"oui-text-base-contrast-80 oui-rotate-180")})]})}),jsxRuntime.jsx(orderlyUi.DropdownMenuPortal,{children:jsxRuntime.jsx(orderlyUi.DropdownMenuContent,{onCloseAutoFocus:o=>o.preventDefault(),onClick:o=>o.stopPropagation(),align:"start",alignOffset:0,sideOffset:0,className:orderlyUi.cn("oui-markets-dropdown-menu-content oui-bg-base-9 oui-w-screen oui-flex oui-flex-col oui-gap-2 oui-p-3"),children:i.map((o,s)=>jsxRuntime.jsx("div",{className:"oui-flex oui-gap-2",children:o.map(n=>jsxRuntime.jsx("div",{className:orderlyUi.cn("oui-w-full oui-text-2xs oui-flex oui-items-center oui-justify-center oui-h-6 oui-rounded",n.value===r.interval?"oui-text-base-contrast oui-bg-primary-darken":"oui-text-base-contrast-36 oui-bg-base-5"),onClick:()=>{r.changeInterval(n.value);},children:jsxRuntime.jsx("div",{children:n.label})},n.value))},s))})})]})};});var Mr,Dr=K(()=>{Z();Mr=r=>{let{displayControlState:e,changeDisplayControlState:t}=r,[i,o]=R.useState(false),{t:s}=orderlyI18n.useTranslation(),n=R.useMemo(()=>[{label:s("common.position"),id:"position"},{label:s("tradingView.displayControl.buySell"),id:"buySell"},{label:s("tradingView.displayControl.limitOrders"),id:"limitOrders"},{label:s("tradingView.displayControl.stopOrders"),id:"stopOrders"},{label:s("common.tpsl"),id:"tpsl"},{label:s("tpsl.positionTpsl"),id:"positionTpsl"},{label:s("orderEntry.orderType.trailingStop"),id:"trailingStop"}],[s]);return jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs(orderlyUi.DropdownMenuRoot,{open:i,onOpenChange:o,children:[jsxRuntime.jsx(orderlyUi.DropdownMenuTrigger,{asChild:true,children:jsxRuntime.jsxs(orderlyUi.Flex,{justify:"start",itemAlign:"center",className:"oui-gap-[2px] oui-cursor-pointer oui-text-base-contrast-36 hover:oui-text-base-contrast-80",children:[jsxRuntime.jsx(Ee,{className:orderlyUi.cn("oui-w-[18px] oui-h-[18px] ",i&&"oui-text-base-contrast-80")}),jsxRuntime.jsx($,{className:orderlyUi.cn("oui-w-3 oui-h-3",i&&"oui-text-base-contrast-80 oui-rotate-180")})]})}),jsxRuntime.jsx(orderlyUi.DropdownMenuPortal,{children:jsxRuntime.jsx(orderlyUi.DropdownMenuContent,{onCloseAutoFocus:a=>a.preventDefault(),onClick:a=>a.stopPropagation(),align:"start",className:"oui-bg-base-8",children:jsxRuntime.jsx(orderlyUi.Flex,{direction:"column",gap:4,px:5,py:5,width:240,justify:"start",itemAlign:"start",children:n.map(a=>jsxRuntime.jsxs(orderlyUi.Flex,{justify:"between",itemAlign:"center",className:"oui-w-full",children:[jsxRuntime.jsx(orderlyUi.Text,{className:orderlyUi.cn("oui-text-sm oui-text-base-contrast-80",!e[a.id]&&"oui-text-base-contrast-36"),children:a.label}),jsxRuntime.jsx(orderlyUi.Switch,{className:"oui-h-4 oui-w-8",checked:e[a.id],onCheckedChange:c=>{t({...e,[a.id]:c});}})]},a.id))})})})]})})};});var Ar,Br=K(()=>{Z();Ar=r=>{let[e,t]=R.useState(false),{t:i}=orderlyI18n.useTranslation(),o=R.useMemo(()=>[[{label:i("common.position"),id:"position"},{label:i("tradingView.displayControl.limitOrders"),id:"limitOrders"}],[{label:i("tradingView.displayControl.stopOrders"),id:"stopOrders"},{label:i("common.tpsl"),id:"tpsl"}],[{label:i("tpsl.positionTpsl"),id:"positionTpsl"},{label:i("tradingView.displayControl.buySell"),id:"buySell"}],[{label:i("orderEntry.orderType.trailingStop"),id:"trailingStop"},{}]],[i]);return jsxRuntime.jsxs(orderlyUi.DropdownMenuRoot,{open:e,onOpenChange:t,children:[jsxRuntime.jsx(orderlyUi.DropdownMenuTrigger,{asChild:true,children:jsxRuntime.jsxs("div",{className:orderlyUi.cn("oui-flex oui-items-center oui-justify-center oui-gap-0.5 oui-text-base-contrast-36",e&&"oui-text-base-contrast-8"),children:[jsxRuntime.jsx(Ee,{className:orderlyUi.cn("oui-size-[18px] ",e&&"oui-text-base-contrast-80")}),jsxRuntime.jsx($,{className:orderlyUi.cn("oui-size-3",e&&"oui-rotate-180 oui-text-base-contrast-80")})]})}),jsxRuntime.jsx(orderlyUi.DropdownMenuPortal,{children:jsxRuntime.jsx(orderlyUi.DropdownMenuContent,{onCloseAutoFocus:s=>s.preventDefault(),onClick:s=>s.stopPropagation(),align:"start",alignOffset:0,sideOffset:0,className:orderlyUi.cn("oui-tradingview-display-control-dropdown-menu-content oui-flex oui-w-screen oui-flex-col oui-gap-2 oui-bg-base-9 oui-p-3"),children:o.map((s,n)=>jsxRuntime.jsx("div",{className:"oui-flex oui-gap-2",children:s.map((a,c)=>jsxRuntime.jsx("div",{className:orderlyUi.cn("oui-flex oui-h-6 oui-w-full oui-items-center oui-justify-between","oui-rounded oui-px-2 oui-text-2xs",a.id&&"oui-bg-base-5",r.displayControlState[a.id]?"oui-text-base-contrast":"oui-text-base-contrast-36"),onClick:()=>{a.id&&r.changeDisplayControlState({...r.displayControlState,[a.id]:!r.displayControlState[a.id]});},children:a.id&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{children:a.label}),r.displayControlState[a.id]?jsxRuntime.jsx(br,{className:"oui-size-3"}):jsxRuntime.jsx(fr,{className:"oui-size-3"})]})},a.id||c))},n))})})]})};});var mt={};Be(mt,{DesktopDisplayControl:()=>Mr,MobileDisplayControl:()=>Ar});var gt=K(()=>{Dr();Br();});var ti="#008676",ri="#D92D6B",Ve="#131519",ii="#00B49E",oi="#FF447C",ni="#333948",si="#FFFFFF",ai="#F4F7F9",li="regular 11px Manrope",It={upColor:ti,downColor:ri,chartBG:Ve,pnlUpColor:ii,pnlDownColor:oi,pnlZoreColor:ni,textColor:si,qtyTextColor:ai,font:li,volumeUpColor:"#00E5A0",volumeDownColor:"#FF6B94",closeIcon:"rgba(255, 255, 255, 0.8)"},Lt=(r,e)=>{let t={"paneProperties.background":r.chartBG,"paneProperties.backgroundType":"solid","mainSeriesProperties.candleStyle.upColor":r.upColor,"mainSeriesProperties.candleStyle.downColor":r.downColor,"mainSeriesProperties.candleStyle.borderColor":r.upColor,"mainSeriesProperties.candleStyle.borderUpColor":r.upColor,"mainSeriesProperties.candleStyle.borderDownColor":r.downColor,"mainSeriesProperties.candleStyle.wickUpColor":r.upColor,"mainSeriesProperties.candleStyle.wickDownColor":r.downColor,"paneProperties.separatorColor":"#2B2833","paneProperties.vertGridProperties.color":"#26232F","paneProperties.horzGridProperties.color":"#26232F","scalesProperties.fontSize":e?8:12,"scalesProperties.textColor":"#97969B","paneProperties.legendProperties.showSeriesTitle":!e,"mainSeriesProperties.statusViewStyle.symbolTextSource":"ticker","mainSeriesProperties.statusViewStyle.showExchange":false},i={"volume.volume.color.0":r.volumeDownColor,"volume.volume.color.1":r.volumeUpColor};return {overrides:t,studiesOverrides:i}},Tt="Orderly",Ot="Kodiak",T=r=>r.includes(":")?r.split(":")[1]:r,ce=r=>r.startsWith(`${Tt}:`)?r:`${Tt}:${r}`;var di=(r,e)=>{let i,o=s=>[null,"limit","MARKET","STOP_MARKET","STOP_LIMIT"][s];return {symbolInfo:async s=>(i=e.getSymbolInfo(T(s)),{qty:{min:i?.baseMin??0,max:i?.baseMax??0,step:i?.baseTick??0},pipValue:0,pipSize:i?.quoteTick??0,minTick:i?.quoteTick??0,description:""}),placeOrder:async s=>{let n=["SELL","BUY"][+(s.side>0)],a=s.qty.toString();(s.limitPrice??0).toString();(s.stopPrice??0).toString();let u=T(s.symbol),m=o(s.type);m==="MARKET"?e.sendMarketOrder({side:n,order_quantity:a,symbol:u,order_type:orderlyTypes.OrderType.MARKET}):"LIMIT";},orders:()=>[],positions:()=>[],executions:()=>[],connectionStatus:()=>1,chartContextMenuActions:s=>r.defaultContextMenuActions(s),isTradable:async()=>true,accountManagerInfo:()=>({}),currentAccount:()=>"1",accountsMetainfo:async()=>[{id:"1"}],remove:()=>r?.silentOrdersPlacement().unsubscribe()}},Pt=di;function V(r){return r===void 0?"":typeof r=="string"?r:r.message}var de=class{constructor(e,t,i){this._datafeedUrl=e,this._requester=t,this._limitedServerResponse=i;}getBars(e,t,i){let o={symbol:e.ticker||"",resolution:t,from:i.from,to:i.to};return i.countBack!==void 0&&(o.countback=i.countBack),e.currency_code!==void 0&&(o.currencyCode=e.currency_code),e.unit_id!==void 0&&(o.unitId=e.unit_id),new Promise(async(s,n)=>{try{let a=await this._requester.sendRequest(this._datafeedUrl,"history",o),c=this._processHistoryResponse(a);this._limitedServerResponse&&await this._processTruncatedResponse(c,o),s(c);}catch(a){if(a instanceof Error||typeof a=="string"){let c=V(a);n(c);}}})}async _processTruncatedResponse(e,t){let i=e.bars.length;try{for(;this._limitedServerResponse&&this._limitedServerResponse.maxResponseLength>0&&this._limitedServerResponse.maxResponseLength===i&&t.from<t.to;){t.countback&&(t.countback=t.countback-i),this._limitedServerResponse.expectedOrder==="earliestFirst"?t.from=Math.round(e.bars[e.bars.length-1].time/1e3):t.to=Math.round(e.bars[0].time/1e3);let o=await this._requester.sendRequest(this._datafeedUrl,"history",t),s=this._processHistoryResponse(o);i=s.bars.length,this._limitedServerResponse.expectedOrder==="earliestFirst"?(s.bars[0].time===e.bars[e.bars.length-1].time&&s.bars.shift(),e.bars.push(...s.bars)):(s.bars[s.bars.length-1].time===e.bars[0].time&&s.bars.pop(),e.bars.unshift(...s.bars));}}catch(o){if(o instanceof Error||typeof o=="string"){V(o);}}}_processHistoryResponse(e){if(e.s!=="ok"&&e.s!=="no_data")throw new Error(e.errmsg);let t=[],i={noData:false};if(e.s==="no_data")i.noData=true,i.nextTime=e.nextTime;else {let o=e.v!==void 0,s=e.o!==void 0;for(let n=0;n<e.t.length;++n){let a={time:e.t[n]*1e3,close:parseFloat(e.c[n]),open:parseFloat(e.c[n]),high:parseFloat(e.c[n]),low:parseFloat(e.c[n])};s&&(a.open=parseFloat(e.o[n]),a.high=parseFloat(e.h[n]),a.low=parseFloat(e.l[n])),o&&(a.volume=parseFloat(e.v[n])),t.push(a);}}return {bars:t,meta:i}}};var pe=class{constructor(e){e&&(this._headers=e);}sendRequest(e,t,i){if(i!==void 0){let s=Object.keys(i);s.length!==0&&(t+="?"),t+=s.map(n=>`${encodeURIComponent(n)}=${encodeURIComponent(i[n].toString())}`).join("&");}""+t;let o={credentials:"same-origin"};return this._headers!==void 0&&(o.headers=this._headers),fetch(`${e}/${t}`,o).then(s=>s.text()).then(s=>JSON.parse(s))}};function f(r,e,t,i){let o=r[e];return Array.isArray(o)&&(!i||Array.isArray(o[0]))?o[t]:o}function me(r,e,t){return r+(e!==void 0?"_%|#|%_"+e:"")+(t!==void 0?"_%|#|%_"+t:"")}var ge=class{constructor(e,t,i){this._exchangesList=["Orderly"];this._symbolsInfo={};this._symbolsList=[];this._datafeedUrl=e,this._datafeedSupportedResolutions=t,this._requester=i,this._readyPromise=this._init(),this._readyPromise.catch(o=>{});}resolveSymbol(e,t,i){return this._readyPromise.then(()=>{let o=this._symbolsInfo[me(e,t,i)];return o===void 0?Promise.reject("invalid symbol"):Promise.resolve(o)})}searchSymbols(e,t,i,o){return this._readyPromise.then(()=>{let s=[],n=e.length===0;e=e.toUpperCase();for(let c of this._symbolsList){let l=this._symbolsInfo[c];if(l===void 0||i.length>0&&l.type!==i||t&&t.length>0&&l.exchange!==t)continue;let u=l.name.toUpperCase().indexOf(e),m=l.description.toUpperCase().indexOf(e);if((n||u>=0||m>=0)&&!s.some(h=>h.symbolInfo===l)){let h=u>=0?u:8e3+m;s.push({symbolInfo:l,weight:h});}}let a=s.sort((c,l)=>c.weight-l.weight).slice(0,o).map(c=>{let l=c.symbolInfo;return {symbol:l.name,full_name:`${l.exchange}:${l.name}`,description:l.description,exchange:l.exchange,params:[],type:l.type,ticker:l.name}});return Promise.resolve(a)})}_init(){let e=[],t={};for(let i of this._exchangesList)t[i]||(t[i]=true,e.push(this._requestExchangeData(i)));return Promise.all(e).then(()=>{this._symbolsList.sort();})}_requestExchangeData(e){return new Promise((t,i)=>{this._requester.sendRequest(this._datafeedUrl,"symbol_info",{group:e}).then(o=>{try{this._onExchangeDataReceived(e,o);}catch(s){i(s instanceof Error?s:new Error(`SymbolsStorage: Unexpected exception ${s}`));return}t();}).catch(o=>{`${e}${V(o)}`,t();});})}_onExchangeDataReceived(e,t){let i=0;try{let o=t.symbol.length,s=t.ticker!==void 0;for(;i<o;++i){let n=t.symbol[i],a=f(t,"exchange-listed",i),c=f(t,"exchange-traded",i),l=c+":"+n,u=f(t,"currency-code",i),m=f(t,"unit-id",i),b=s?f(t,"ticker",i):n,h={ticker:b,name:n,base_name:[a+":"+n],listed_exchange:a,exchange:c,currency_code:u,original_currency_code:f(t,"original-currency-code",i),unit_id:m,original_unit_id:f(t,"original-unit-id",i),unit_conversion_types:f(t,"unit-conversion-types",i,!0),description:f(t,"description",i),has_intraday:q(f(t,"has-intraday",i),!1),visible_plots_set:q(f(t,"visible-plots-set",i),"ohlcv"),minmov:f(t,"minmovement",i)||f(t,"minmov",i)||0,minmove2:f(t,"minmove2",i)||f(t,"minmov2",i),fractional:f(t,"fractional",i),pricescale:f(t,"pricescale",i),type:f(t,"type",i),session:f(t,"session-regular",i),session_holidays:f(t,"session-holidays",i),corrections:f(t,"corrections",i),timezone:f(t,"timezone",i),supported_resolutions:q(f(t,"supported-resolutions",i,!0),this._datafeedSupportedResolutions),has_daily:q(f(t,"has-daily",i),!0),intraday_multipliers:q(f(t,"intraday-multipliers",i,!0),["1","5","15","30","60"]),has_weekly_and_monthly:f(t,"has-weekly-and-monthly",i),has_empty_bars:f(t,"has-empty-bars",i),volume_precision:q(f(t,"volume-precision",i),0),format:"price"};this._symbolsInfo[b]=h,this._symbolsInfo[n]=h,this._symbolsInfo[l]=h,(u!==void 0||m!==void 0)&&(this._symbolsInfo[me(b,u,m)]=h,this._symbolsInfo[me(n,u,m)]=h,this._symbolsInfo[me(l,u,m)]=h),this._symbolsList.push(n);}}catch(o){throw new Error(`SymbolsStorage: API error when processing exchange ${e} symbol #${i} (${t.symbol[i]}): ${Object(o).message}`)}}};function q(r,e){return r!==void 0?r:e}var he=class{constructor(e){this._configuration=wt();this._symbolsStorage=null;this._datafeedURL=e,this._requester=new pe,this._historyProvider=new de(e,this._requester),this._configurationReadyPromise=this._requestConfiguration().then(t=>{t===null&&(t=wt()),this._setupWithConfiguration(t);});}getBars(e,t,i,o,s){this._historyProvider.getBars(e,t,i).then(n=>{o(n.bars,n.meta);}).catch(s);}onReady(e){this._configurationReadyPromise.then(()=>{e(this._configuration);});}searchSymbols(e,t,i,o){if(this._symbolsStorage===null)throw new Error("Datafeed: inconsistent configuration (symbols storage)");this._symbolsStorage.searchSymbols(e,t,i,30).then(o).catch(o.bind(null,[]));}resolveSymbol(e,t,i,o){let s=o&&o.currencyCode,n=o&&o.unitId;function c(l){t(l);}if(this._symbolsStorage===null)throw new Error("Datafeed: inconsistent configuration (symbols storage)");this._symbolsStorage.resolveSymbol(e,s,n).then(c).catch(i);}getMarks(){}getTimescaleMarks(){}getServerTime(){}_requestConfiguration(){return this._send("config").catch(e=>(`${V(e)}`,null))}_send(e,t){return this._requester.sendRequest(this._datafeedURL,e,t)}_setupWithConfiguration(e){if(this._configuration=e,e.exchanges===void 0&&(e.exchanges=[]),!e.supports_search&&!e.supports_group_request)throw new Error("Unsupported datafeed configuration. Must either support search, or support group request");(e.supports_group_request||!e.supports_search)&&(this._symbolsStorage=new ge(this._datafeedURL,e.supported_resolutions||[],this._requester)),`${JSON.stringify(e)}`;}};function wt(){return {supports_search:false,supports_group_request:true,supported_resolutions:["1","3","5","15","30","60","120","240","480","720","1D","3D","1W","1M"],supports_marks:false,supports_timescale_marks:false}}var fe=class{constructor(){this.subscribers=new Map;}subscribe(e,t){return this.subscribers.has(e)||this.subscribers.set(e,[]),this.subscribers.get(e).push(t),()=>{this.unsubscribe(e,t);}}unsubscribe(e,t){if(this.subscribers.has(e)){let i=this.subscribers.get(e);this.subscribers.set(e,i.filter(o=>o!==t)),this.subscribers.get(e).length===0&&this.subscribers.delete(e);}}publish(e,t){this.subscribers.has(e)&&this.subscribers.get(e).forEach(o=>{o(t);});}};var Ne=r=>{let e="1d";switch(r){case "1":e="1m";break;case "3":e="3m";break;case "5":e="5m";break;case "15":e="15m";break;case "30":e="30m";break;case "60":e="1h";break;case "120":e="2h";break;case "240":e="4h";break;case "480":e="8h";break;case "720":e="12h";break;case "D":case "1D":e="1d";break;case "3D":e="3d";break;case "1W":e="1w";break;case "1M":e="1M ";break;}return e},N={interval:"TradingviewSDK.lastUsedTimeBasedResolution",lineType:"TradingviewSDK.lastUsedStyle",displayControlSetting:"TradingviewSDK.displaySetting"};var He=(r,e)=>`${r}kline_${e}`,pi=r=>["trade"].map(t=>`${r}@${t}`),k=class k{constructor(e){this.klineSubscribeIdMap=new Map;this.klineOnTickCallback=new Map;this.subscribeCachedTopics=new Map;this.wsInstance=null;this.klineData=new Map;return k._created||(this.wsInstance=e,k._instance=this,k._created=true),k._instance}subscribeKline(e,t,i,o){let s=Ne(i);this.klineSubscribeIdMap.set(e,{symbol:t,resolution:i});let n=He(t,s);if(this.klineOnTickCallback.has(n)){let a=this.klineOnTickCallback.get(n);a[e]=o;}else {this.klineOnTickCallback.set(n,{[e]:o});let a=this.wsInstance?.subscribe({event:"subscribe",topic:`${t}@kline_${s}`,id:`${t}@kline_${s}`,ts:new Date().getTime()},{onMessage:c=>{let{open:l,close:u,high:m,low:b,volume:h,startTime:F}=c,y=He(c.symbol,c.type);this.updateKline(y,{time:F,close:u,open:l,high:m,low:b,volume:h});}});this.subscribeCachedTopics.set(`${t}@kline_${s}`,a);}}unsubscribeKline(e){if(!this.klineSubscribeIdMap.has(e))return;let{symbol:t,resolution:i}=this.klineSubscribeIdMap.get(e),o=Ne(i),s=He(t,o);if(this.klineOnTickCallback.has(s)){let n=this.klineOnTickCallback.get(s);delete n[e],Object.keys(n).length===0&&(this.klineOnTickCallback.delete(s),this.subscribeCachedTopics.get(`${t}@kline_${o}`)());}delete this.klineSubscribeIdMap[e];}subscribeSymbol(e){pi(e).forEach(i=>{if(!this.subscribeCachedTopics.has(i)){let o=this.wsInstance?.subscribe({event:"subscribe",topic:i,id:i,ts:new Date().getTime()},{onMessage:s=>{this.updateKlineByLastPrice(s.symbol,s.price);}});this.subscribeCachedTopics.set(i,o);}});}updateKlineByLastPrice(e,t){this.klineOnTickCallback.forEach((i,o)=>{if(o.startsWith(e)){let s=this.klineData.get(o);s&&this.updateKline(o,{...s,close:t});}});}updateKline(e,t){let i=this.klineOnTickCallback.get(e);i&&t&&(this.klineData.set(e,t),Object.keys(i).forEach(o=>{let s=i[o];s&&typeof s=="function"&&s(t);}));}};k._created=false,k._instance=null;var G=k;var mi=(()=>{let r=0;return ()=>r++})(),be=class extends he{constructor(t,i){let o=`${t}/tv`;super(o);this.bbosMap=new Map;this.tickersMap=new Map;this.eventBus=new fe;this._subscribeQuoteMap=new Map,this._prefixId=mi(),this._publicWs=new G(i),this.bbosMap=new Map,i.on("tickers",s=>{for(let n of s.data)n.change=n.close-n.open,n.perChange=n.open?+(100*n.change/n.open).toFixed(2):0,this.tickersMap.set(n.symbol,n);this.eventBus.publish("tickerUpdate",{message:"ticker"});}),i.subscribe({event:"subscribe",topic:"bbos"},{formatter:s=>s,onMessage:s=>{for(let n of s.data)this.bbosMap.set(n.symbol,{ask:n.ask,bid:n.bid,askSize:n.askSize,bidSize:n.bidSize});this.eventBus.publish("tickerUpdate",{message:"bbos"});}});}remove(){Array.from(this._subscribeQuoteMap.values()).forEach(t=>t?.());}getSubscriptionId(t){return `${this._prefixId}${t}`}subscribeBars(t,i,o,s,n){window.onResetCacheNeededCallback=n,this._publicWs.subscribeKline(`${this._prefixId}${s}`,t.ticker,i,o);}unsubscribeBars(t){this._publicWs.unsubscribeKline(`${this._prefixId}${t}`);}getQuotes(t,i){let o=this.getSubscriptionId("getQuotes");this.unsubscribeQuotes("getQuotes");let s=this.eventBus.subscribe("tickerUpdate",n=>{let a=new Map;t.forEach(c=>{let l=this.bbosMap.get(T(c)),u=this.tickersMap.get(T(c));if(!l||!u)return;let m={...u,ask:l.ask,bid:l.bid};a.set(T(c),m);}),a.size&&i(Array.from(a.values()).map(c=>this._toUDFTicker(c)));});this._subscribeQuoteMap.set(o,s);}subscribeQuotes(t,i,o,s){let n=`${this._prefixId}${s}`;if(t.length>0){this.unsubscribeQuotes(n);let a=this.eventBus.subscribe("tickerUpdate",c=>{let l=new Map;t.forEach(u=>{let m=this.bbosMap.get(T(u)),b=this.tickersMap.get(T(u));if(!m||!b)return;let h={...b,ask:m.ask,bid:m.bid};l.set(T(u),h);}),l.size&&o(Array.from(l.values()).map(u=>this._toUDFTicker(u)));});this._subscribeQuoteMap.set(n,a);}}unsubscribeQuotes(t){let i=this.getSubscriptionId(t),o=this._subscribeQuoteMap.get(i);o&&(o(),this._subscribeQuoteMap.delete(i));}_toUDFTicker(t){return {n:ce(t.symbol),s:"ok",v:{ask:t.ask,bid:t.bid,ch:t.change,chp:t.perChange/100,description:"",exchange:Ot,hight_price:t.high,low_price:t.low,lp:t.close,open_price:t.open,prev_close_price:0,volume:t.volume}}}};var hi=2,fi="--",Ue=["BRACKET","STOP_BRACKET"],ye=["POSITIONAL_TP_SL","TP_SL"];var Ke=r=>r.root_algo_order_id!==r.algo_order_id&&(r.algo_type==="TAKE_PROFIT"||r.algo_type==="STOP_LOSS"),bi=r=>!!r&&Ue.includes(r);var qe=r=>r.type==="CLOSE_POSITION",kt=r=>qe(r)&&r.is_activated,Mt=r=>Ke(r)&&r.is_activated,Ge=r=>r.root_algo_order_algo_type==="TP_SL"||bi(r.root_algo_order_algo_type)&&r.is_activated,Dt=(r,e)=>{let t=r.algo_type,i={TAKE_PROFIT:orderlyI18n.i18n.t("tpsl.takeProfit"),STOP_LOSS:orderlyI18n.i18n.t("tpsl.stopLoss")}[t];return i||null},At=r=>{let e=new Map,t=1;return [...r].reverse().filter(Ge).forEach(i=>{i.root_algo_order_id&&!e.has(i.root_algo_order_id)&&e.set(i.root_algo_order_id,t++);}),e},Bt=(r,e)=>{let t=Math.abs(r.type==="CLOSE_POSITION"?e.balance:r.quantity),i=r.side==="SELL"?1:-1,o=e.open.toString();return {estPnl:new orderlyUtils.Decimal(r.trigger_price).minus(o??0).times(t).times(i).toString(),quantity:t,openPrice:o}},Vt=r=>r!==void 0&&r!==""?new orderlyUtils.Decimal(r).todp(hi,orderlyUtils.Decimal.ROUND_FLOOR):fi;function We(){let[r,{cancelOrder:e,cancelAlgoOrder:t,cancelTPSLChildOrder:i}]=orderlyHooks.useOrderStream({status:orderlyTypes.OrderStatus.INCOMPLETE});return R.useCallback(o=>{if(o.algo_order_id){if(ye.includes(o.root_algo_order_algo_type)){let s=r?.find(a=>a.algo_order_id===o.root_algo_order_id);return s.child_orders.every(a=>!!a.trigger_price)?i(o.algo_order_id,o.root_algo_order_id):t(s.algo_order_id,o.symbol).then()}return t(o.algo_order_id,o.symbol).then()}return e(o.order_id,o.symbol).then()},[e,r])}function Qe(r){orderlyHooks.useEventEmitter();let [,{updateOrder:t,cancelAlgoOrder:i,updateAlgoOrder:o,updateTPSLOrder:s}]=orderlyHooks.useOrderStream({status:orderlyTypes.OrderStatus.INCOMPLETE});return R.useCallback((n,a)=>{if(n.algo_order_id)if(ye.includes(n.root_algo_order_algo_type)){let l=[{order_id:n.algo_order_id,trigger_price:new orderlyUtils.Decimal(a.value).toString()}];return s(n.root_algo_order_id,l).then(u=>{}).catch(u=>{r&&r.error(u.message);})}else {if(Ue.includes(n.algo_type))return o(n.algo_order_id,{order_price:new orderlyUtils.Decimal(a.value).toString()}).then(l=>{}).catch(l=>{r&&r.error(l.message);});{let l={quantity:n.quantity,trigger_price:n.trigger_price,symbol:n.symbol,price:n.price,algo_order_id:n.algo_order_id};return n.order_tag&&(l.order_tag=n.order_tag),n.client_order_id&&(l.client_order_id=n.client_order_id),a.type==="price"&&(l.price=new orderlyUtils.Decimal(a.value).toString()),a.type==="trigger_price"&&(l.trigger_price=new orderlyUtils.Decimal(a.value).toString()),o(n.algo_order_id,l).then(u=>{}).catch(u=>{r&&r.error(u.message);})}}let c={order_price:n.price?.toString(),order_quantity:n.quantity.toString(),symbol:n.symbol,order_type:n.type,side:n.side,visible_quantity:0,reduce_only:n.reduce_only};return new orderlyUtils.Decimal(n.visible_quantity??n.visible??0).eq(n.quantity)&&delete c.visible_quantity,Object.keys(n).includes("reduce_only")||delete c.reduce_only,n.order_tag&&(c.order_tag=n.order_tag),n.client_order_id&&(c.client_order_id=n.client_order_id),a.type==="price"&&(c.order_price=new orderlyUtils.Decimal(a.value).toString()),t(n.order_id,c).then(l=>{}).catch(l=>{r.error(l.message);})},[t])}function $e(r){let {onSubmit:e}=orderlyHooks.useOrderEntry_deprecated({symbol:r,side:orderlyTypes.OrderSide.BUY,order_type:orderlyTypes.OrderType.MARKET},{watchOrderbook:true});return {sendLimitOrder:()=>{},sendMarketOrder:s=>(s.reduce_only=false,e(s).catch(n=>{orderlyUi.toast.error(n);}))}}var Ei=r=>e=>r(e),ki=({closeConfirm:r,colorConfig:e,onToast:t,mode:i,symbol:o})=>{let s=We(),n=Qe(t),a=orderlyHooks.useSymbolsInfo(),c=R.useCallback(h=>r&&r(h),[r]),{sendMarketOrder:l,sendLimitOrder:u}=$e(o),m=R.useCallback(h=>{if(a)return {baseMin:a[h]("base_min"),baseMax:a[h]("base_max"),baseTick:a[h]("base_tick"),quoteTick:a[h]("quote_tick")}},[a]),b=R.useRef({cancelOrder:s,closePosition:c,editOrder:n,colorConfig:e,sendLimitOrder:u,getSymbolInfo:m,sendMarketOrder:Ei(l),mode:i});return R.useEffect(()=>{b.current.getSymbolInfo=m;},[a]),R.useEffect(()=>{b.current.sendLimitOrder=u,b.current.sendMarketOrder=l;},[u,l]),R.useEffect(()=>{b.current.closePosition=c;},[r]),R.useEffect(()=>{b.current.cancelOrder=s;},[s]),b.current},Ht=ki;var Kt={1:{startOf:"minute",period:0},3:{startOf:"hour",period:3*60*1e3},5:{startOf:"hour",period:5*60*1e3},15:{startOf:"hour",period:15*60*1e3},30:{startOf:"hour",period:30*60*1e3},60:{startOf:"hour",period:0},120:{startOf:"day",period:2*60*60*1e3},240:{startOf:"day",period:4*60*60*1e3},480:{startOf:"day",period:8*60*60*1e3},720:{startOf:"day",period:12*60*60*1e3},D:{startOf:"day",period:0},"1D":{startOf:"day",period:0},"3D":{startOf:"year",period:3*24*60*60*1e3},"5D":{startOf:"year",period:5*24*60*60*1e3},"1W":{startOf:"week",period:0},"1M":{startOf:"month",period:0}};function Ut(r,e,t,i){let{startOf:o,period:s}=Kt[t],n=new Date(r.updated_time).getTime(),a=dateFns.startOfSecond(n).getTime();o==="minute"?a=dateFns.startOfMinute(n).getTime():o==="hour"?a=dateFns.startOfHour(n).getTime():o==="day"?a=dateFns.startOfDay(n).getTime():o==="month"?a=dateFns.startOfMonth(n).getTime():o==="year"?a=dateFns.startOfYear(n).getTime():o==="week"?a=dateFns.startOfWeek(n).getTime():o==="month"&&(a=dateFns.startOfMonth(n).getTime());let c=s===0?a:Math.floor((n-a)/s)*s+a;e[c]||(e[c]={BUY:[],SELL:[]}),e[c][r.side].length<5&&(e[c][r.side].push(r),i.push(r));}var qt=(r,e)=>{let t=[],i={};return Kt[e]?(r.forEach(o=>{if(o.child_orders)for(let s of o.child_orders)s.is_activated&&s.algo_status===orderlyTypes.OrderStatus.FILLED&&Ut(s,i,e,t);else Ut(o,i,e,t);}),t):[]};var ve=class r{constructor(e,t){this.interval="1D";this.changeInterval=e=>{let t=()=>{this.renderExecutions(this.filledOrders,this.basePriceDecimal),this.instance.activeChart().onDataLoaded().unsubscribe(null,t);};this.interval=e,this.instance.activeChart().onDataLoaded().subscribe(null,t);};this.instance=e,this.executions=[],this.filledOrders=[],this.basePriceDecimal=0,this.broker=t,this.subscribeIntervalChange();}async subscribeIntervalChange(){this.interval=this.instance.symbolInterval().interval;let e=this.changeInterval;this.instance.activeChart().onIntervalChanged().subscribe(null,e);}renderExecutions(e,t){this.filledOrders=e,this.basePriceDecimal=t,this.interval&&(this.removeAll(),qt(e,this.interval).forEach(i=>{this.executions.push(this.drawExecution(i,t));}));}removeAll(){this.executions.forEach(e=>e.remove()),this.executions=[];}static getExecutionInfo(e,t){let i=e.side,o=e.average_executed_price||e.child_orders?.find(n=>!!n.average_executed_price)?.average_executed_price||0,s=new orderlyUtils.Decimal(o).todp(t,orderlyUtils.Decimal.ROUND_FLOOR).toString();return `${i==="BUY"?orderlyI18n.i18n.t("common.buy"):orderlyI18n.i18n.t("common.sell")} ${e.total_executed_quantity} @${orderlyUtils.commify(s)}`}drawExecution(e,t){let i=e.side,o=e.average_executed_price||e.child_orders?.find(a=>!!a.average_executed_price)?.average_executed_price||0,s=new Date(e.updated_time).getTime()/1e3,n=this.broker.colorConfig;return this.instance.activeChart().createExecutionShape().setArrowHeight(9).setTooltip(r.getExecutionInfo(e,t)).setTime(s).setPrice(o).setArrowColor(i==="BUY"?n.upColor:n.downColor).setDirection(i==="BUY"?"buy":"sell")}unsubscribeIntervalChange(){let e=this.changeInterval;try{this.instance.activeChart().onIntervalChanged().unsubscribe(null,e);}catch(t){t instanceof Error&&t.message;}}destroy(){this.removeAll(),this.unsubscribeIntervalChange();}};var X=r=>{if(r!=null)return r.algo_order_id||r.order_id};var _e=class{constructor(){this.quantityTpslNoMap=new Map,this.tpslPnlMap=new Map,this.positions=null;}getQuantityTpslNoMap(){return this.quantityTpslNoMap}getTpslPnlMap(){return this.tpslPnlMap}getFormattedEstPnl(e){if(this.positions===null)return "";let t=this.positions[0];if(!t)return "";let{estPnl:i}=Bt(e,t);return Vt(i)}prepareTpslPnlMap(e){let t=[];return e.forEach(i=>{let o=X(i);if(o&&Mt(i)){let s=this.tpslPnlMap.get(o),n=this.getFormattedEstPnl(i);s!==n&&(t.push(o),this.tpslPnlMap.set(o,n));}}),t}prepareQuantityTpslNoMap(e){this.quantityTpslNoMap=At(e);}recalculatePnl(e,t){return this.positions=e,this.prepareTpslPnlMap(t)}clear(){this.positions=null,this.quantityTpslNoMap.clear(),this.tpslPnlMap.clear();}};var P=class P{constructor(e,t){this.instance=e,this.pendingOrderLineMap=new Map,this.pendingOrders=[],this.broker=t,this.tpslCalService=new _e;}renderPendingOrders(e){e&&(this.pendingOrders=e),this.cleanOldPendingOrders(this.pendingOrders),this.tpslCalService.prepareTpslPnlMap(this.pendingOrders),this.tpslCalService.prepareQuantityTpslNoMap(this.pendingOrders),this.pendingOrders.forEach(t=>this.renderPendingOrder(t));}updatePositions(e){let t=this.tpslCalService.recalculatePnl(e,this.pendingOrders);this.pendingOrders.filter(i=>t.includes(X(i))).forEach(i=>this.renderPendingOrder(i));}renderPendingOrder(e){let t=P.getOrderId(e);if(!t)return;let i=this.drawOrderLine(t,e);i&&this.pendingOrderLineMap.set(t,i);}cleanOldPendingOrders(e){let t=new Set(e.map(i=>P.getOrderId(i)));this.pendingOrderLineMap.forEach((i,o)=>!t.has(o)&&this.removePendingOrder(o));}removePendingOrder(e){if(e===void 0)return;let t=this.pendingOrderLineMap.get(e);t&&(this.pendingOrderLineMap.delete(e),t.remove());}getBaseOrderLine(){let e=this.broker.colorConfig;return this.instance.activeChart().createOrderLine().setCancelTooltip(orderlyI18n.i18n.t("orders.cancelOrder")).setQuantityTextColor(e.qtyTextColor).setQuantityBackgroundColor(e.chartBG).setBodyBackgroundColor(e.chartBG).setCancelButtonBackgroundColor(e.chartBG).setLineStyle(1).setBodyFont(e.font).setQuantityFont(e.font)}static getCombinationType(e){let{algo_type:t,type:i}=e;if((t==="STOP_LOSS"||t==="TAKE_PROFIT"||t==="STOP")&&i==="LIMIT")return "STOP_LIMIT";if((t==="STOP_LOSS"||t==="TAKE_PROFIT"||t==="STOP")&&i==="MARKET")return "STOP_MARKET";if(t==="BRACKET"){if(i==="LIMIT")return "BRACKET_LIMIT";if(i==="MARKET")return "BRACKET_MARKET"}return t==="TRAILING_STOP"?"TRAILING_STOP":"LIMIT"}static getText(e){let t=P.getCombinationType(e);return t==="STOP_LIMIT"||t==="STOP_MARKET"||t==="STOP_BRACKET_LIMIT"||t==="STOP_BRACKET_MARKET"?e.type==="LIMIT"?`${orderlyI18n.i18n.t("orderEntry.orderType.stopLimit")} ${orderlyUtils.commify(e.price)}`:orderlyI18n.i18n.t("orderEntry.orderType.stopMarket"):t==="TRAILING_STOP"?orderlyI18n.i18n.t("orderEntry.trailing"):orderlyI18n.i18n.t("orderEntry.orderType.limit")}static getOrderPrice(e){return e.algo_type==="TRAILING_STOP"?orderlyUtils.getTrailingStopPrice(e):e.trigger_price||e.price}getTPSLTextWithTpsl(e,t){return X(t),e}getTPSLText(e){let t=Dt(e,this.tpslCalService.getQuantityTpslNoMap());return t?this.getTPSLTextWithTpsl(t,e):null}getOrderQuantity(e){if(e.algo_order_id){if(kt(e)||qe(e))return "100%";if(Ge(e)){let i=new orderlyUtils.Decimal(e.quantity).minus(e.executed??0).div(new orderlyUtils.Decimal(e.position_qty)).mul(100).todp(2).toNumber();return `${Math.min(Math.abs(i),100).toString()}%`}}return orderlyUtils.commify(new orderlyUtils.Decimal(e.quantity).toString())}drawOrderLine(e,t){let i=Ke(t)?this.getTPSLText(t):P.getText(t);if(i===null)return null;let o=this.broker.colorConfig,s=this.pendingOrderLineMap.get(e)??this.getBaseOrderLine(),n=t.side==="BUY"?o.upColor:o.downColor;t.side==="BUY"?o.pnlUpColor:o.pnlDownColor;let c=P.getOrderPrice(t),l=100,u=this.getOrderQuantity(t),m=o.textColor;return s.setText(i).setCancelButtonIconColor(o.closeIcon).setCancelButtonBorderColor(n).setBodyTextColor(m).setBodyBorderColor(n).setQuantityBorderColor(n).setQuantityTextColor(n).setLineColor(n).setLineLength(l).setQuantity(u??"").setPrice(c),this.broker.mode!==3?(s.onCancel(null,()=>this.broker.cancelOrder(t)),this.applyEditOnMove(s,t)):s.setEditable(false).setCancellable(false),s}static getOrderEditKey(e){let t=this.getCombinationType(e);if(["LIMIT","BRACKET_LIMIT"].includes(t))return "price";if(t==="STOP_LIMIT"||t==="STOP_MARKET"||e.rootAlgoOrderAlgoType==="POSITIONAL_TP_SL"||e.rootAlgoOrderAlgoType==="TP_SL"||e.rootAlgoOrderAlgoType==="BRACKET"||e.rootAlgoOrderAlgoType==="STOP_BRACKET")return "trigger_price"}applyEditOnMove(e,t){let i=P.getOrderEditKey(t);i&&e.onMove(()=>{this.broker.editOrder(t,{type:i,value:`${e.getPrice()}`}).then(o=>{o.success||this.renderPendingOrder(t);}).catch(()=>this.renderPendingOrder(t));});}removeAll(){this.pendingOrderLineMap.forEach(e=>e.remove()),this.pendingOrderLineMap.clear(),this.pendingOrders=[],this.tpslCalService.clear();}};P.getOrderId=e=>{if(e!=null)return e.algo_order_id||e.order_id};var Se=P;var Te=class r{constructor(e,t){this.instance=e,this.currentSymbol="",this.broker=t,this.positionLines={},this.lastPositions=null;}renderPositions(e){if(e===null||e.length===0){this.removePositions();return}this.lastPositions?.length!==e.length&&this.removePositions(),e[0].symbol!==this.currentSymbol&&(this.removePositions(),this.currentSymbol=e[0].symbol),e.forEach((t,i)=>this.drawPositionLine(t,i)),this.lastPositions=e;}getBasePositionLine(){return this.instance.activeChart().createPositionLine().setTooltip(orderlyI18n.i18n.t("positions.closePosition")).setQuantityBackgroundColor(this.broker.colorConfig.chartBG).setCloseButtonBackgroundColor(this.broker.colorConfig.chartBG).setBodyTextColor(this.broker.colorConfig.textColor).setQuantityTextColor(this.broker.colorConfig.qtyTextColor).setBodyFont(this.broker.colorConfig.font).setQuantityFont(this.broker.colorConfig.font).setLineLength(100).setLineStyle(1)}static getPositionQuantity(e){return orderlyUtils.commify(new orderlyUtils.Decimal(e).todp(4,orderlyUtils.Decimal.ROUND_DOWN).toString())}static getPositionPnL(e,t){let i=orderlyI18n.i18n.t("tpsl.pnl"),o=new orderlyUtils.Decimal(e).toFixed(t,orderlyUtils.Decimal.ROUND_DOWN);return new orderlyUtils.Decimal(e).eq(0)?`${i} 0`:new orderlyUtils.Decimal(e).greaterThan(0)?`${i} +${orderlyUtils.commify(o)}`:`${i} ${orderlyUtils.commify(o)}`}removePositions(){Object.keys(this.positionLines).forEach(e=>{this.positionLines[Number(e)].remove(),delete this.positionLines[Number(e)];});}drawPositionLine(e,t){let i=this.broker.colorConfig,o=e.unrealPnl>=0,s=e.balance>=0,n=i.pnlZoreColor,a=new orderlyUtils.Decimal(e.unrealPnl);a.greaterThan(0)?n=i.upColor:a.lessThan(0)&&(n=i.downColor);o?i.pnlUpColor:i.pnlDownColor;let l=s?i.upColor:i.downColor,u=new orderlyUtils.Decimal(e.open).toNumber();this.positionLines[t]=this.positionLines[t]??this.getBasePositionLine(),this.positionLines[t].setQuantity(r.getPositionQuantity(e.balance)).setPrice(u).setCloseButtonIconColor(i.closeIcon).setCloseButtonBorderColor(l).setBodyBackgroundColor(n).setQuantityTextColor(l).setBodyBorderColor(n).setLineColor(l).setQuantityBorderColor(l).setText(r.getPositionPnL(e.unrealPnl,e.unrealPnlDecimal)),this.broker.mode!==3&&this.positionLines[t].onClose(null,()=>{this.broker.closePosition(e);});}};var Yt=10;var Ie=class{constructor(e,t){this.interactiveMode=0;this.tpslElRemoveTimer=null;this.currentPosition=null;this.tpslOrderLine=null;this.tpslPnLVerticalLineEntityId=null;this.tpslVerticalLineTime=null;this.tpslStartCircleEntityId=null;this.tpslEndCircleEntityId=null;this.threshold=10;this.lastArgs=null;this.instance=e,this.broker=t,this.lastPositions=null,this.tpslElRemoveTimer=null,this.currentPosition=null,this.bindEvent();}bindEvent(){this.chart.crossHairMoved().subscribe(null,e=>{if(this.lastArgs=e,this.interactiveMode===2){this.clearTpslElRemoveTimer();return}let t=this.getIntersectantPosition(e);if(!(this.currentPosition&&t&&this.currentPosition.symbol===t.symbol)){if(!t){this.clearTPSLElements();return}t&&(this.clearTpslElRemoveTimer(),this.currentPosition=t,this.createTPSLTriggerButton(e));}});}clearTpslElRemoveTimer(){this.tpslElRemoveTimer&&(clearTimeout(this.tpslElRemoveTimer),this.tpslElRemoveTimer=null);}showTPSLDialog(e){let t=new orderlyUtils.Decimal(e.price).minus(this.currentPosition.open).mul(this.currentPosition?.balance??0);orderlyUi.modal.show("TPSLSimpleDialogId",{title:t.gt(0)?orderlyI18n.i18n.t("tpsl.TPOrderConfirm"):orderlyI18n.i18n.t("tpsl.SLOrderConfirm"),triggerPrice:e.price,type:t.gt(0)?"tp":"sl",symbol:this.currentPosition.symbol,onComplete:()=>{this.clearTPSLElements(),this.chart.setScrollEnabled(true),this.chart.setZoomEnabled(true),this.interactiveMode=0;},showAdvancedTPSLDialog:i=>{this.showAdvancedTPSLDialog({type:t.gt(0)?"tp":"sl",triggerPrice:e.price,qty:i.qty});}}).then(()=>{},i=>{}).finally(()=>{this.clearTPSLElements(),this.chart.setScrollEnabled(true),this.chart.setZoomEnabled(true),this.interactiveMode=0;});}showAdvancedTPSLDialog({type:e,triggerPrice:t,qty:i}){orderlyUi.modal.show("TPSLDialogId",{withTriggerPrice:true,type:e,triggerPrice:t,symbol:this.currentPosition?.symbol,qty:i,onComplete:()=>{this.clearTPSLElements(),this.chart.setScrollEnabled(true),this.chart.setZoomEnabled(true),this.interactiveMode=0;}}).then(()=>{},o=>{}).finally(()=>{this.clearTPSLElements(),this.chart.setScrollEnabled(true),this.chart.setZoomEnabled(true),this.interactiveMode=0;});}updatePositions(e){this.lastPositions=e,this.threshold=this.generateThreshold();}generateThreshold(){let e=this.chart.getPanes()[0]?.getRightPriceScales()[0];if(!e)return Yt;let t=e.getVisiblePriceRange();return t?(t.to-t.from)*.02:Yt}drawTPSL(e){let{price:t}=e,i=new orderlyUtils.Decimal(t).minus(this.currentPosition.open).mul(this.currentPosition?.balance??0),{tpslOrderLine:o,verticalLine:s}=this.ensureTPSLElements({price:t,pnl:i}),n=i.gt(0)?orderlyI18n.i18n.t("tpsl.tp"):orderlyI18n.i18n.t("tpsl.sl"),a=i.gt(0)?this.broker.colorConfig.upColor:this.broker.colorConfig.downColor;o?.setText(`${n} ${i.toDecimalPlaces(2).toNumber()}`).setBodyTextColor(a).setBodyBorderColor(a).setLineColor(a),this.tpslVerticalLineTime&&s?.setPoints([{price:this.currentPosition?.open,time:this.tpslVerticalLineTime},{time:this.tpslVerticalLineTime,price:t}]);}ensureTPSLElements(e){let t=this.tpslOrderLine,i;if(t||(this.tpslOrderLine=this.createTPSLOrderLine()),this.tpslPnLVerticalLineEntityId&&(i=this.chart.getShapeById(this.tpslPnLVerticalLineEntityId)),!i){if(!this.currentPosition||!this.tpslVerticalLineTime)return {};this.tpslPnLVerticalLineEntityId=this.chart.createMultipointShape([{price:this.currentPosition.open,time:this.tpslVerticalLineTime},{time:this.tpslVerticalLineTime,price:e.price}],{shape:"trend_line",lock:true,disableSave:true,disableSelection:true,disableUndo:true,zOrder:"top",overrides:{linecolor:"rgba(255,255,255, 0.2)",linewidth:1,rightEnd:1,leftEnd:1}});}return i?.setProperties({linecolor:e.pnl.gt(0)?this.broker.colorConfig.upColor:this.broker.colorConfig.downColor,linewidth:1}),{tpslOrderLine:t,verticalLine:i}}createTPSLTriggerButton(e){this.tpslOrderLine||(this.tpslOrderLine=this.createTPSLOrderLine()),this.tpslOrderLine.onMove(()=>{let t=this.tpslOrderLine?.getPrice();this.showTPSLDialog({price:t??0});}),this.tpslOrderLine.onMoving(()=>{this.interactiveMode=2;let t=this.tpslOrderLine?.getPrice();this.verticalLineTime(),this.drawTPSL({price:t??0});});}createTPSLOrderLine(){return this.chart.createOrderLine().setCancellable(false).setExtendLeft(true).setTooltip(orderlyI18n.i18n.t("tpsl.dragToSet")).setPrice(this.currentPosition.open).setLineLength(-200,"pixel").setText(orderlyI18n.i18n.t("tpsl.advanced.title")).setQuantity("").setBodyTextColor(this.broker.colorConfig.textColor).setBodyBackgroundColor(this.broker.colorConfig.chartBG).setBodyBorderColor(this.broker.colorConfig.pnlZoreColor).setQuantityBackgroundColor(this.broker.colorConfig.chartBG).setQuantityBorderColor(this.broker.colorConfig.pnlZoreColor).setQuantityTextColor(this.broker.colorConfig.qtyTextColor).setBodyFont(this.broker.colorConfig.font).setQuantityFont(this.broker.colorConfig.font).setLineStyle(3)}verticalLineTime(){let e=this.chart.getVisibleRange();this.tpslVerticalLineTime=this.getTimeAtPercentage(e.from,e.to,90);}clearTPSLElements(){this.tpslElRemoveTimer||(this.tpslElRemoveTimer=setTimeout(()=>{this.currentPosition=null,this.tpslOrderLine&&(this.tpslOrderLine.remove(),this.tpslOrderLine=null),this.tpslPnLVerticalLineEntityId&&(this.chart.removeEntity(this.tpslPnLVerticalLineEntityId),this.tpslPnLVerticalLineEntityId=null),this.tpslElRemoveTimer=null;},100));}getIntersectantPosition(e){if(!Array.isArray(this.lastPositions)||this.lastPositions.length===0)return null;let{price:t,time:i}=e,o=null;for(let s of this.lastPositions)if(s&&Math.abs(s.open-t)<this.threshold){o=s;break}return o}get chart(){return this.instance.activeChart()}getTimeAtPercentage(e,t,i){if(typeof e!="number"||typeof t!="number"||typeof i!="number"||i<0||i>100||e>t)return null;let o=t-e,s=i/100,n=o*s,a=e+n;return Math.round(a)}};var Le=class{constructor(e,t,i){this.instance=e,this.positionLineService=new Te(e,i),this.orderLineService=new Se(e,i),this.executionService=new ve(e,i),this.tpslService=new Ie(e,i);}async renderPositions(e){await this.chartReady(),await this.onDataLoaded(),this.positionLineService.renderPositions(e),this.orderLineService.updatePositions(e),this.tpslService.updatePositions(e);}async renderPendingOrders(e){await this.chartReady(),this.orderLineService.renderPendingOrders(e);}async renderFilledOrders(e,t){await this.chartReady(),await this.onDataLoaded(),this.executionService.renderExecutions(e,t);}remove(){this.orderLineService.removeAll(),this.positionLineService.removePositions(),this.executionService.destroy();}onDataLoaded(){return this.instance.activeChart().symbolExt()?Promise.resolve():new Promise(e=>this.instance.activeChart().onDataLoaded().subscribe(null,()=>{e();},true))}chartReady(){return new Promise(e=>this.instance.onChartReady(()=>{try{this.instance.activeChart().dataReady(()=>e());}catch(t){t.toString().includes("tradingViewApi");}}))}};function Je(r,e){let[t,i]=R.useState(),o=R.useRef(),{state:s}=orderlyHooks.useAccount(),[n]=orderlyHooks.useLocalStorage("unPnlPriceBasis","markPrice"),[{rows:a},c]=orderlyHooks.usePositionStream(r,{calcMode:n}),[l]=orderlyHooks.useOrderStream({status:orderlyTypes.OrderStatus.INCOMPLETE,symbol:r}),m=orderlyHooks.useSymbolsInfo()?.[r],b=m("quote_dp"),[h]=orderlyHooks.useOrderStream({symbol:r,status:orderlyTypes.OrderStatus.FILLED,size:500}),F=R.useRef((L,v,A,U)=>{o.current&&o.current.remove(),o.current=new Le(L,v,A),i(o.current);}),y=R.useRef(()=>{o.current?.remove(),o.current=void 0;});return R.useEffect(()=>{if(s.status<orderlyTypes.AccountStatusEnum.EnableTrading&&s.status!==orderlyTypes.AccountStatusEnum.EnableTradingWithoutConnected){t?.renderPositions([]);return}if(!e||!e.position){t?.renderPositions([]);return}let L=(a??[]).filter(v=>v.symbol===r).map(v=>({symbol:v.symbol,open:v.average_open_price,balance:v.position_qty,closablePosition:9999,unrealPnl:v.unrealized_pnl??0,interest:0,unrealPnlDecimal:2,basePriceDecimal:4}));t?.renderPositions(L);},[t,a,r,e,s]),R.useEffect(()=>{if(!e||!e.buySell){t?.renderFilledOrders([],6);return}let L=h?.filter(v=>v.symbol===r);t?.renderFilledOrders(L??[],b??6);},[t,h,r,b,e]),R.useEffect(()=>{let L=[],v=[],A=[],U=[],z=[],B=[];if(s.status<orderlyTypes.AccountStatusEnum.EnableTrading&&s.status!==orderlyTypes.AccountStatusEnum.EnableTradingWithoutConnected){t?.renderPendingOrders([]);return}let j=(a??[]).find(C=>C.symbol===r);l?.forEach(C=>{if(r===C.symbol){if(!C.algo_order_id)A.push(C);else if(C.algo_order_id)if(C.algo_type==="POSITIONAL_TP_SL")for(let S of C.child_orders)S.root_algo_order_algo_type=C.algo_type,S.trigger_price&&S.status!==orderlyTypes.OrderStatus.FILLED&&v.push(S);else if(C.algo_type==="TP_SL"){if(j)for(let S of C.child_orders)S.root_algo_order_algo_type=C.algo_type,S.position_qty=j.position_qty,S.trigger_price&&S.status!==orderlyTypes.OrderStatus.FILLED&&L.push(S);}else C.algo_type==="STOP_LOSS"||C.algo_type==="TAKE_PROFIT"?U.push(C):C.algo_type==="BRACKET"?z.push(C):C.algo_type==="TRAILING_STOP"&&C.is_activated&&C.extreme_price&&B.push(C);}}),e&&(e.positionTpsl||(v=[]),e.tpsl||(L=[]),e.limitOrders||(A=[],z=[]),e.stopOrders||(U=[]),e.trailingStop||(B=[])),t?.renderPendingOrders(L.concat(v).concat(A).concat(U).concat(z).concat(B));},[t,l,r,e,a,s.status]),[F.current,y.current]}function $i(r){r.setBrokerConnectionAdapter=function(e){let t={subscribe:()=>{},unsubscribe:()=>{},unsubscribeAll:()=>{}};Object.defineProperty(e,"_ordersCache",{get:function(){return {start:()=>{},stop:()=>{},update:()=>{},partialUpdate:()=>{},fullUpdate:()=>{},getObjects:async()=>[],updateDelegate:t,partialUpdateDelegate:t}},set:()=>{}}),e._waitForOrderModification=async()=>true,this._adapter=e;};}function Zi(r,e){r.onChartReady(()=>{e.silentOrdersPlacement().subscribe(t=>{t||(e.silentOrdersPlacement().setValue(true),r&&(r._iFrame.contentDocument.querySelector(".wrapper-3X2QgaDd").className="wrapper-3X2QgaDd highButtons-3X2QgaDd"),e.sellBuyButtonsVisibility()?.setValue(false));});});}function Xe(r,e){$i(e),Zi(r,e);}var Xt=(r,e)=>new Promise(t=>{let i=r.querySelector(e);i&&t(i);let o=new MutationObserver(()=>{let s=r.querySelector(e);s&&(t(s),o.disconnect());});o.observe(r,{childList:true,subtree:true});});var xe=class{constructor({iframeDocument:e}){this.iframeDocument=e;}defaultHack(){this.showFavoriteStarByDefault();}showFavoriteStarByDefault(){Xt(this.iframeDocument,".dropdown-2R6OKuTS").then(()=>{this.iframeDocument.querySelectorAll(".toolbox-2IihgTnv.showOnHover-2IihgTnv").forEach(t=>{t.style.opacity="1";});});}};var zi=(r,e=true)=>{let t=["header_symbol_search","trading_account_manager","drawing_templates","open_account_manager","right_toolbar","support_multicharts","header_layouttoggle","order_panel","order_info","trading_notifications","display_market_status","broker_button","add_to_watchlist","chart_crosshair_menu","header_fullscreen_button","header_widget"];return e||t.push("volume_force_overlay"),r===3&&(t=[...t,"left_toolbar","timeframes_toolbar","go_to_date","timezone_menu","create_volume_indicator_by_default","buy_sell_buttons"]),r===0?t=[...t,"header_widget","left_toolbar","timeframes_toolbar","buy_sell_buttons"]:r===1&&(t=[...t,"left_toolbar","timeframes_toolbar","buy_sell_buttons"]),t};function et(r,e,t=true){return {...r,disabled_features:zi(e,t),enabled_features:["hide_left_toolbar_by_default","order_panel_close_button","iframe_loading_compatibility_mode"],auto_save_delay:.1,broker_config:{configFlags:{supportStopLimitOrders:true,supportReversePosition:false}}}}var tt=r=>`${r}_adapter`,we={"trading.chart.proterty":JSON.stringify({showSellBuyButtons:0,noConfirmEnabled:1,qweqrq:0,showPricesWithZeroVolume:1,showSpread:1,orderExecutedSoundParams:'{"enabled":0,"name":"alert/alarm_clock"}'}),"hint.startFocusedZoom":"true"},D=new Map;var ji=(r,e,t)=>{let i=tt(r);try{let o=e,s=o?JSON.parse(o):void 0,n=t?JSON.parse(t):we;return o&&D.set(r,o),t&&D.set(i,t),{savedData:s,adapterSetting:n}}catch{}return {savedData:void 0,adapterSetting:we}},er=async(r,e)=>{let t=tt(r),i=localStorage.getItem(r)||"",o=localStorage.getItem(t)||"";try{if(D.has(r)&&D.has(t))return {savedData:JSON.parse(D.get(r)),adapterSetting:JSON.parse(D.get(t))}}catch{}return ji(r,i,o)},tr=async(r,e,t)=>{e&&(localStorage.setItem(r,e),D.set(r,e));},rr=async(r,e,t)=>{let i=tt(r);e&&(localStorage.setItem(i,e),D.set(i,e));};var ir=(r,e)=>{let t=null,i=(...o)=>{t&&window.clearTimeout(t),t=setTimeout(()=>{r(...o);},e);};return i.cancel=()=>{t&&window.clearTimeout(t),t=null;},i},Yi="chartProp_default",or=300,Re=class{constructor(e){this._instance=null;this._onClick=null;this._datafeed=null;this._chartKey=Yi;this._adapterSetting=we;this._savedData=null;this._isLoggedIn=false;this.debounceSaveChart=ir(()=>{try{this._instance?.save(e=>{Object.is(this._savedData,e)||(this._savedData=e,tr(this._chartKey,JSON.stringify(e),this._isLoggedIn));});}catch{}},or*2);this.debounceSaveChartAdapterSetting=ir(()=>{rr(this._chartKey,JSON.stringify(this._adapterSetting),this._isLoggedIn);},or);this._create(e);}remove(){this.unsubscribeClick(),this._datafeed?.remove(),this._broker?.remove(),this._instance?.remove(),this.debounceSaveChart.cancel(),this.debounceSaveChartAdapterSetting.cancel();}updateOverrides(e){this.instance&&this.instance.applyOverrides(e);}setSymbol(e,t,i){try{this._instance?.onChartReady(()=>{let o=t??this._instance?.symbolInterval()?.interval;o||(o=1),this._instance?.setSymbol(e,o,i);});}catch{}}executeActionById(e){try{this._instance?.onChartReady(()=>{this._instance?.activeChart().executeActionById(e);});}catch{}}changeLineType(e){try{this._instance?.onChartReady(()=>{this._instance?.activeChart().setChartType(e);});}catch{}}subscribeClick(e){this._onClick=e,this._instance?.onChartReady(()=>{this._instance?._iFrame.contentDocument?.addEventListener("click",this._onClick);});}unsubscribeClick(){this._instance?._iFrame.contentDocument?.removeEventListener("click",this._onClick);}get instance(){return this._instance}chartHack(){this._instance?.onChartReady(()=>{let e=this._instance._iFrame.contentWindow.document;new xe({iframeDocument:e}).defaultHack();});}subscribeAutoSave(){this._instance?.onChartReady(()=>{this._instance?.subscribe("onAutoSaveNeeded",()=>{this.debounceSaveChart();}),this._instance?.activeChart().onVisibleRangeChanged().subscribe(null,()=>{this.debounceSaveChart();});});}async _create({options:e,chartKey:t,mode:i,onClick:o}){let s=e.getBroker,n={fullscreen:e.fullscreen??true,autosize:e.autosize??false,timezone:e.timezone,symbol:e.symbol,library_path:e.libraryPath,interval:e.interval??"1",custom_css_url:e.customCssUrl,custom_font_family:e.customFontFamily,datafeed:e.datafeed,studies_overrides:e.studiesOverrides,locale:e.locale,theme:e.theme,loading_screen:e.loadingScreen,overrides:e.overrides,container:e.container,favorites:{intervals:["1","3","5","15","30","60","240","1D","1W","1M"],chartTypes:["Area","Line"]},broker_factory:s?l=>(this._broker&&this._broker.remove(),this._broker=s(this._instance,l),this._broker):void 0};this._datafeed=e.datafeed,t&&(this._chartKey=t);let{savedData:a,adapterSetting:c}=await er(this._chartKey,this._isLoggedIn);this._adapterSetting=c,this._savedData=a,this._instance=new TradingView.widget({...et(n,i,e.showVolumeInSamePane??true),interval:c["chart.lastUsedTimeBasedResolution"]??n.interval,saved_data:a,settings_adapter:{initialSettings:c,setValue:(l,u)=>{this._adapterSetting={...this._adapterSetting,[l]:u},this.debounceSaveChartAdapterSetting();},removeValue:()=>{}}}),this._instance.onChartReady(()=>{e.symbol&&this._instance?.activeChart().symbol()!==T(e.symbol)&&this.setSymbol(e.symbol);}),this.subscribeAutoSave(),this.subscribeClick(o),this.chartHack();}};var co="SDK_Tradingview",uo="SDK_Moblie_Tradingview",po=r=>r?uo:co,mo=r=>r==="id"?"id_ID":r;function nt(r){let{scriptSRC:e,libraryPath:t,customCssUrl:i,overrides:o,studiesOverrides:s,symbol:n,theme:a,loadingScreen:c,mode:l,colorConfig:u,showVolumeInSamePane:m,locale:b=mo,classNames:h}=r,F=orderlyI18n.useLocaleCode(),y=R.useRef(null),L=orderlyHooks.useConfig("apiBaseUrl"),{state:v}=orderlyHooks.useAccount(),[A,U]=R.useState(orderlyTypes.OrderSide.SELL),z=orderlyHooks.useSymbolsInfo(),[B,j]=orderlyHooks.useLocalStorage(orderlyTypes.TradingviewFullscreenKey,false),{onSubmit:C,submitting:S}=orderlyHooks.useOrderEntry_deprecated({symbol:n??"",side:A,order_type:orderlyTypes.OrderType.MARKET},{watchOrderbook:true}),[bt,Hr]=R.useState(()=>{let d=localStorage.getItem(N.displayControlSetting);return d?JSON.parse(d):{position:true,buySell:true,limitOrders:true,stopOrders:true,tpsl:true,positionTpsl:true,trailingStop:true}}),[yt,Fr]=R.useState(()=>{let d=localStorage.getItem(N.interval);return d||"15"}),[Ur,Kr]=R.useState(()=>{let d=localStorage.getItem(N.lineType);return d||"1"}),Me=orderlyHooks.useMediaQuery(orderlyTypes.MEDIA_TABLET),De=R.useMemo(()=>Object.assign({},It,u??{}),[u]),qr=R.useMemo(()=>typeof c=="object"?c:{backgroundColor:Ve},[c]),se=orderlyHooks.useWS(),[Y,Gr]=R.useState(false),Wr=d=>{let ae=z[n];if(!ae)return;let le=new orderlyUtils.Decimal(d.balance).greaterThan(0)?orderlyTypes.OrderSide.SELL:orderlyTypes.OrderSide.BUY,_t={order_quantity:new orderlyUtils.Decimal(d.balance).abs().toNumber(),symbol:n,order_type:orderlyTypes.OrderType.MARKET,side:le,reduce_only:true};U(le),orderlyUi.modal.show("MarketCloseConfirmID",{base:ae("base"),quantity:d.balance,onConfirm:async()=>C(_t).catch(J=>{typeof J=="string"?orderlyUi.toast.error(J):orderlyUi.toast.error(J.message);}),submitting:S});},E=R.useRef(null),Ct=R.useMemo(()=>!(v.status<orderlyTypes.AccountStatusEnum.EnableTrading&&v.status!==orderlyTypes.AccountStatusEnum.EnableTradingWithoutConnected),[v]),vt=Ht({closeConfirm:Wr,colorConfig:De,onToast:orderlyUi.toast,symbol:n??"",mode:l}),[Qr,$r]=Je(n,bt),Zr=()=>{j(!B),r.onFullScreenChange?.(!B);},zr=d=>{y.current&&(localStorage.setItem(N.interval,d),Fr(d),y.current?.setSymbol(n??"",d));},jr=d=>{y.current&&(localStorage.setItem(N.lineType,d),Kr(d),y.current?.changeLineType(Number(d)));},Yr=d=>{localStorage.setItem(N.displayControlSetting,JSON.stringify(d)),Hr(d);},Jr=()=>{y.current&&y.current.executeActionById("chartProperties");},Xr=()=>{y.current&&y.current.executeActionById("insertIndicator");};return R.useEffect(()=>{if(e&&E.current&&!Y){let d=document.createElement("script");d.setAttribute("data-nscript","afterInteractive"),d.src=e,d.async=true,d.type="text/javascript",d.onload=()=>{Gr(true);},d.onerror=()=>{},E.current.appendChild(d);}},[E,Y,e]),R.useEffect(()=>{if(!n||!Y||!e)return;let d=Lt(De,Me),ae=o?Object.assign({},d.overrides,o):d.overrides,le=s?Object.assign({},d.studiesOverrides,s):d.studiesOverrides;if(E.current){let J={options:{fullscreen:false,autosize:true,symbol:ce(n),locale:typeof b=="function"?b(F):b,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,container:E.current,libraryPath:t,customCssUrl:i,interval:yt??"1",theme:a??"dark",loadingScreen:qr??{},showVolumeInSamePane:m,overrides:ae,studiesOverrides:le,datafeed:new be(L,se),contextMenu:{items_processor:async Ae=>Ae},getBroker:(Ae,St)=>(Xe(Ae,St),Pt(St,vt))},chartKey:po(Me),mode:l,onClick:()=>{}};y.current=new Re(J);}return ()=>{y.current?.remove();}},[Y,Me,l,y,E,Y,e,De,b,F,m]),R.useEffect(()=>{se.on("status:change",d=>{!d.isPrivate&&d.isReconnect&&typeof window.onResetCacheNeededCallback=="function"&&(window.onResetCacheNeededCallback(),y.current?.instance&&y.current?.instance.activeChart()?.resetData());},"tradingview");},[se]),R.useEffect(()=>(y.current&&y.current?.instance&&y.current?.instance?.onChartReady(()=>{Ct&&y.current?.instance&&Qr(y.current.instance,void 0,vt,E.current);}),()=>{$r();}),[y.current,Ct]),R.useEffect(()=>{if(!n||!y.current)return;y.current?.setSymbol(n);let d=new G(se);return d.subscribeSymbol(n),()=>{d.unsubscribeKline(n);}},[n]),{tradingViewScriptSrc:e,chartRef:E,changeDisplaySetting:Yr,displayControlState:bt,interval:yt,changeInterval:zr,lineType:Ur,changeLineType:jr,openChartSetting:Jr,openChartIndicators:Xr,symbol:n,onFullScreenChange:Zr,classNames:h,fullscreen:B}}Z();var vr=r=>{let{url:e,children:t}=r;return jsxRuntime.jsx("span",{onClick:()=>window.open(e),className:"oui-cursor-pointer oui-px-0.5 oui-text-primary-light oui-underline",children:t})},_r=()=>{let{t:r}=orderlyI18n.useTranslation();return jsxRuntime.jsx("div",{className:"oui-absolute oui-inset-0 oui-z-0 oui-flex oui-flex-col oui-items-center oui-justify-start oui-p-2 oui-text-base-contrast-80 md:oui-justify-center md:oui-p-10",children:jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("p",{className:"oui-mb-6 oui-text-xs",children:r("tradingView.noScriptSrc")}),jsxRuntime.jsx("p",{className:"oui-mb-3 oui-pl-0 oui-text-2xs oui-text-base-contrast-54 md:oui-pl-2 md:oui-text-base md:oui-text-base-contrast-80",children:jsxRuntime.jsx(orderlyI18n.Trans,{i18nKey:"tradingView.noScriptSrc.1",components:[jsxRuntime.jsx(vr,{url:"https://www.tradingview.com/advanced-charts"},"tradingview-advanced-charts")]})}),jsxRuntime.jsx("p",{className:"oui-pl-0 oui-text-2xs oui-text-base-contrast-54 md:oui-pl-2 md:oui-text-base md:oui-text-base-contrast-80",children:jsxRuntime.jsx(orderlyI18n.Trans,{i18nKey:"tradingView.noScriptSrc.2",components:[jsxRuntime.jsx(vr,{url:"https://orderly.network/docs/sdks/react/components/trading#tradingviewconfig"},"tradingview-config")]})})]})})};var fo=r=>jsxRuntime.jsx("div",{className:"top-toolbar oui-flex oui-h-[44px] oui-justify-between md:oui-justify-start oui-items-center oui-p-2 md:oui-px-3 md:oui-pt-3 md:oui-pb-[14px]",children:r.children}),Sr=fo;var un=R__default.default.lazy(()=>Promise.resolve().then(()=>(xr(),Pr))),Nr=R__default.default.lazy(()=>Promise.resolve().then(()=>(kr(),Er)).then(r=>({default:r.TimeInterval}))),dn=R__default.default.lazy(()=>Promise.resolve().then(()=>(gt(),mt)).then(r=>({default:r.MobileDisplayControl}))),pn=R__default.default.lazy(()=>Promise.resolve().then(()=>(gt(),mt)).then(r=>({default:r.DesktopDisplayControl}))),ht=({children:r,onClick:e})=>jsxRuntime.jsx(orderlyUi.Box,{onClick:e,className:"oui-cursor-pointer oui-w-[18px] oui-h-[18px] oui-text-base-contrast-36 hover:oui-text-base-contrast-80",children:r}),mn=r=>jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18",fill:"currentColor",...r,children:jsxRuntime.jsx("path",{d:"M15.0008 2.24304C14.8088 2.24304 14.6085 2.30755 14.4615 2.4538L11.2508 5.66455V3.74304H9.75079V7.49304C9.75079 7.90704 10.0868 8.24304 10.5008 8.24304H14.2508V6.74304H12.3285L15.54 3.53229C15.8325 3.23904 15.8325 2.74705 15.54 2.4538C15.393 2.30755 15.1928 2.24304 15.0008 2.24304ZM3.7508 9.74303V11.243H5.67231L2.46156 14.4538C2.16906 14.747 2.16906 15.239 2.46156 15.5323C2.75481 15.8248 3.2468 15.8248 3.54005 15.5323L6.7508 12.3215V14.243H8.25079V10.493C8.25079 10.079 7.9148 9.74303 7.5008 9.74303H3.7508Z"})}),gn=r=>jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18",fill:"currentColor",...r,children:jsxRuntime.jsx("path",{d:"M7.49219 9.74304C7.30026 9.74304 7.09964 9.80755 6.95309 9.9538L3.74219 13.1646V11.243H2.24219V14.993C2.24219 15.407 2.57796 15.743 2.99219 15.743H6.74219V14.243H4.82031L8.03121 11.0323C8.32416 10.739 8.32416 10.247 8.03121 9.9538C7.88481 9.80755 7.68404 9.74304 7.49219 9.74304ZM11.2509 2.24304V3.74304H13.1728L9.96186 6.9538C9.66899 7.24705 9.66899 7.73904 9.96186 8.03229C10.2547 8.32479 10.7471 8.32479 11.04 8.03229L14.2509 4.82153V6.74304H15.7509V2.99304C15.7509 2.57904 15.4151 2.24304 15.0009 2.24304H11.2509Z"})}),ft=R.forwardRef((r,e)=>{let{chartRef:t,interval:i,changeDisplaySetting:o,displayControlState:s,tradingViewScriptSrc:n,changeInterval:a,lineType:c,changeLineType:l,openChartSetting:u,openChartIndicators:m,onFullScreenChange:b}=r,h=orderlyHooks.useMediaQuery(orderlyTypes.MEDIA_TABLET);return jsxRuntime.jsx("div",{ref:e,className:orderlyUi.cn("oui-relative oui-size-full",r.classNames?.root),children:n?jsxRuntime.jsxs("div",{className:orderlyUi.cn("oui-absolute oui-inset-0 oui-z-[1] oui-flex oui-flex-col",r.classNames?.content),children:[jsxRuntime.jsx(Sr,{children:h?jsxRuntime.jsxs(orderlyUi.Flex,{gapX:2,width:"100%",justify:"between",className:"oui-hide-scrollbar oui-overflow-x-scroll",children:[jsxRuntime.jsx(R__default.default.Suspense,{fallback:null,children:jsxRuntime.jsx(Nr,{interval:i??"15",changeInterval:a})}),jsxRuntime.jsx(ht,{onClick:m,children:jsxRuntime.jsx(st,{})}),jsxRuntime.jsx(R__default.default.Suspense,{fallback:null,children:jsxRuntime.jsx(dn,{displayControlState:s,changeDisplayControlState:o})})]}):jsxRuntime.jsxs(orderlyUi.Flex,{justify:"between",itemAlign:"center",width:"100%",children:[jsxRuntime.jsxs(orderlyUi.Flex,{children:[jsxRuntime.jsx(R__default.default.Suspense,{fallback:null,children:jsxRuntime.jsx(Nr,{interval:i??"1",changeInterval:a})}),jsxRuntime.jsx(orderlyUi.Divider,{direction:"vertical",className:"oui-h-4",mx:2,intensity:8}),jsxRuntime.jsxs(orderlyUi.Flex,{justify:"start",itemAlign:"center",gap:2,children:[jsxRuntime.jsx(R__default.default.Suspense,{fallback:null,children:jsxRuntime.jsx(pn,{displayControlState:s,changeDisplayControlState:o})}),jsxRuntime.jsx(ht,{onClick:m,children:jsxRuntime.jsx(st,{})}),jsxRuntime.jsx(R__default.default.Suspense,{fallback:null,children:jsxRuntime.jsx(un,{lineType:c,changeLineType:l})}),jsxRuntime.jsx(ht,{onClick:u,children:jsxRuntime.jsx(cr,{})})]})]}),jsxRuntime.jsx(orderlyUi.Flex,{children:r.fullscreen?jsxRuntime.jsx(mn,{className:"oui-text-base-contrast-54 hover:oui-text-base-contrast oui-cursor-pointer",onClick:b}):jsxRuntime.jsx(gn,{className:"oui-text-base-contrast-54 hover:oui-text-base-contrast oui-cursor-pointer",onClick:b})})]})}),jsxRuntime.jsx("div",{ref:t,className:"oui-size-full oui-overflow-hidden"})]}):jsxRuntime.jsx(_r,{})})});var fn=R.forwardRef((r,e)=>{let t=nt(r);return jsxRuntime.jsx(ft,{...t,ref:e})});
|
|
16
|
+
var __defProp = Object.defineProperty;
|
|
17
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
18
|
+
var __esm = (fn, res) => function __init() {
|
|
19
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
20
|
+
};
|
|
21
|
+
var __export = (target, all) => {
|
|
22
|
+
for (var name in all)
|
|
23
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
24
|
+
};
|
|
25
|
+
var CaretIcon, DisplaySettingIcon, IndicatorsIcon, SettingIcon, BarIcon, CandlesIcon, HollowCandlesIcon, LineIcon, AreaIcon, BaseLineIcon, UnSelectIcon, SelectedIcon;
|
|
26
|
+
var init_icons = __esm({
|
|
27
|
+
"src/icons/index.tsx"() {
|
|
28
|
+
CaretIcon = (props) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
29
|
+
"svg",
|
|
30
|
+
{
|
|
31
|
+
viewBox: "0 0 12 12",
|
|
32
|
+
fill: "currentColor",
|
|
33
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
34
|
+
...props,
|
|
35
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("g", { id: "Caret-down", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
36
|
+
"path",
|
|
37
|
+
{
|
|
38
|
+
id: "Vector",
|
|
39
|
+
d: "M3.00349 3.9978C2.59149 3.9978 2.36564 4.4653 2.61289 4.7948C2.98789 5.2948 5.23784 8.29479 5.61289 8.79479C5.81289 9.06128 6.20974 9.06128 6.40974 8.79479L9.40974 4.7948C9.65694 4.4653 9.41554 3.9978 9.00349 3.9978H3.00349Z"
|
|
40
|
+
}
|
|
41
|
+
) })
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
DisplaySettingIcon = (props) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
45
|
+
"svg",
|
|
46
|
+
{
|
|
47
|
+
viewBox: "0 0 18 18",
|
|
48
|
+
fill: "currentColor",
|
|
49
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
50
|
+
...props,
|
|
51
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("g", { id: "Display settings", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
52
|
+
"path",
|
|
53
|
+
{
|
|
54
|
+
id: "Union",
|
|
55
|
+
fillRule: "evenodd",
|
|
56
|
+
clipRule: "evenodd",
|
|
57
|
+
d: "M15.0571 10.9856L11.6295 5.06523L8.71377 10.8968C8.38933 11.5456 7.54464 11.7223 6.98733 11.2579L5.75311 10.2294L2.83709 14.7654L1.57532 13.9543L4.49134 9.41824C4.97892 8.65978 6.0207 8.49981 6.71338 9.07705L7.58387 9.80246L10.5991 3.77192C10.9997 2.97082 12.1302 2.93624 12.579 3.71137L14.6517 7.29147C14.7714 7.03643 15.0305 6.85983 15.3309 6.85983C15.7451 6.85983 16.0809 7.19562 16.0809 7.60983C16.0809 8.02405 15.7451 8.35983 15.3309 8.35983C15.31 8.35983 15.2892 8.35897 15.2687 8.35729L16.3553 10.2341L15.0571 10.9856ZM2.58093 6.85983C2.16672 6.85983 1.83093 7.19562 1.83093 7.60983C1.83093 8.02405 2.16672 8.35983 2.58093 8.35983C2.99515 8.35983 3.33093 8.02405 3.33093 7.60983C3.33093 7.19562 2.99515 6.85983 2.58093 6.85983ZM4.83093 6.85983C4.41672 6.85983 4.08093 7.19562 4.08093 7.60983C4.08093 8.02405 4.41672 8.35983 4.83093 8.35983C5.24515 8.35983 5.58093 8.02405 5.58093 7.60983C5.58093 7.19562 5.24515 6.85983 4.83093 6.85983ZM6.33093 7.60983C6.33093 7.19562 6.66672 6.85983 7.08093 6.85983C7.49515 6.85983 7.83093 7.19562 7.83093 7.60983C7.83093 8.02405 7.49515 8.35983 7.08093 8.35983C6.66672 8.35983 6.33093 8.02405 6.33093 7.60983ZM11.5809 6.85983C11.1667 6.85983 10.8309 7.19562 10.8309 7.60983C10.8309 8.02405 11.1667 8.35983 11.5809 8.35983C11.9951 8.35983 12.3309 8.02405 12.3309 7.60983C12.3309 7.19562 11.9951 6.85983 11.5809 6.85983Z"
|
|
58
|
+
}
|
|
59
|
+
) })
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
IndicatorsIcon = (props) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
63
|
+
"svg",
|
|
64
|
+
{
|
|
65
|
+
viewBox: "0 0 18 18",
|
|
66
|
+
fill: "currentColor",
|
|
67
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
68
|
+
...props,
|
|
69
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("g", { id: "Indicators", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
70
|
+
"path",
|
|
71
|
+
{
|
|
72
|
+
id: "Union",
|
|
73
|
+
fillRule: "evenodd",
|
|
74
|
+
clipRule: "evenodd",
|
|
75
|
+
d: "M9.74483 2.25C8.96145 2.25 8.26885 2.76459 8.04549 3.51818L7.46202 5.48254H5.06262V7.08339H6.98652L5.00539 13.7532L4.31554 13.1112L3.22498 14.2831L4.4777 15.4489C5.08739 16.015 6.08317 15.7469 6.32134 14.945L8.65649 7.08339H11.6032V5.48254H9.13198L9.58033 3.97311C9.60167 3.90112 9.66833 3.85084 9.74483 3.85084H11.69V2.25H9.74483ZM10.6234 11.2354L10.2638 11.5172C10.0153 11.712 9.65591 11.6684 9.46115 11.4199C9.26639 11.1713 9.30998 10.812 9.55852 10.6172L10.1451 10.1575C10.5693 9.82514 11.1868 9.94011 11.4642 10.4005L11.4682 10.407L12.1304 11.5752L13.4594 10.3111C13.6882 10.0935 14.05 10.1025 14.2677 10.3313C14.4853 10.5601 14.4763 10.922 14.2475 11.1396L12.7116 12.6006L13.3897 13.797L13.6482 13.4503C13.8369 13.1972 14.1951 13.145 14.4483 13.3337C14.7014 13.5225 14.7536 13.8807 14.5649 14.1338L13.9917 14.9025L13.94 14.9457C13.5178 15.2981 12.8837 15.1886 12.6003 14.7226L12.5958 14.7151L11.8576 13.4129L10.3563 14.841C10.1275 15.0586 9.76561 15.0495 9.54798 14.8208C9.33036 14.592 9.3394 14.2301 9.56819 14.0125L11.2764 12.3875L10.6234 11.2354Z"
|
|
76
|
+
}
|
|
77
|
+
) })
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
SettingIcon = (props) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
81
|
+
"svg",
|
|
82
|
+
{
|
|
83
|
+
viewBox: "0 0 18 18",
|
|
84
|
+
fill: "currentColor",
|
|
85
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
86
|
+
...props,
|
|
87
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("g", { id: "Setting", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
88
|
+
"path",
|
|
89
|
+
{
|
|
90
|
+
id: "Vector",
|
|
91
|
+
d: "M6.72589 1.84154C5.66239 2.17904 4.74515 2.72954 3.93665 3.48254C3.6869 3.71504 3.6104 4.09604 3.7724 4.39604C4.37315 5.50679 3.74464 6.69554 2.38939 6.76379C2.05789 6.78029 1.76465 7.0263 1.68665 7.34955C1.5524 7.9083 1.49915 8.37629 1.49915 8.98979C1.49915 9.50504 1.55464 10.0885 1.66339 10.6075C1.73089 10.9315 2.0129 11.1648 2.3429 11.1933C3.7064 11.311 4.3814 12.3513 3.7724 13.6773C3.6374 13.972 3.6989 14.3245 3.93665 14.545C4.73315 15.2815 5.64814 15.8013 6.72589 16.1388C7.03339 16.2348 7.38064 16.1185 7.56964 15.8575C8.40364 14.7033 9.6134 14.6995 10.4054 15.8575C10.5921 16.1298 10.9341 16.261 11.2491 16.162C12.2894 15.8343 13.2584 15.277 14.0616 14.545C14.3091 14.3193 14.3744 13.954 14.2259 13.654C13.6019 12.3948 14.3197 11.239 15.6082 11.2165C15.9502 11.2105 16.2547 10.9863 16.3349 10.654C16.4647 10.1163 16.4991 9.64829 16.4991 8.98979C16.4991 8.42429 16.4324 7.86704 16.3116 7.32629C16.2351 6.98354 15.9359 6.74054 15.5849 6.73979C14.3167 6.73754 13.6056 5.49104 14.2259 4.39604C14.3984 4.09154 14.3444 3.71804 14.0849 3.48254C13.2674 2.74004 12.2706 2.15954 11.2259 1.84154C10.9049 1.74404 10.5636 1.86404 10.3821 2.14604C9.65764 3.27179 8.30465 3.29129 7.5929 2.17004C7.41065 1.88204 7.04989 1.73879 6.72589 1.84154ZM11.2844 3.43455C11.7966 3.64905 12.2009 3.8733 12.6651 4.22505C12.1206 5.9478 13.0439 7.73729 14.9564 8.17304C15.0036 8.48279 14.9991 8.67029 14.9991 8.98979C14.9991 9.37154 15.0044 9.50579 14.9609 9.78179C13.0566 10.1763 12.1146 11.9155 12.6449 13.7538C12.1889 14.0845 11.8626 14.314 11.2904 14.5353C9.94639 13.1673 8.0804 13.1073 6.7079 14.5443C6.1724 14.3088 5.76066 14.0995 5.34441 13.7478C5.86041 11.881 4.98815 10.2693 3.05165 9.7803C2.9654 9.4383 2.9999 8.4723 3.0494 8.17905C5.0519 7.69905 5.8409 5.92679 5.34365 4.21979C5.78315 3.88904 6.1784 3.6483 6.69215 3.4398C7.9859 4.75605 9.92839 4.8873 11.2844 3.43455ZM8.99915 5.98979C7.3424 5.98979 5.99915 7.33304 5.99915 8.98979C5.99915 10.6473 7.3424 11.9898 8.99915 11.9898C10.6559 11.9898 11.9991 10.6473 11.9991 8.98979C11.9991 7.33304 10.6559 5.98979 8.99915 5.98979ZM8.99915 7.48979C9.8279 7.48979 10.4991 8.16179 10.4991 8.98979C10.4991 9.81855 9.8279 10.4898 8.99915 10.4898C8.1704 10.4898 7.49915 9.81855 7.49915 8.98979C7.49915 8.16179 8.1704 7.48979 8.99915 7.48979Z"
|
|
92
|
+
}
|
|
93
|
+
) })
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
BarIcon = (props) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
97
|
+
"svg",
|
|
98
|
+
{
|
|
99
|
+
viewBox: "0 0 20 20",
|
|
100
|
+
fill: "currentColor",
|
|
101
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
102
|
+
...props,
|
|
103
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("g", { id: "Bars", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
104
|
+
"path",
|
|
105
|
+
{
|
|
106
|
+
id: "Union",
|
|
107
|
+
fillRule: "evenodd",
|
|
108
|
+
clipRule: "evenodd",
|
|
109
|
+
d: "M12.5 15.5C12.5 15.7761 12.7239 16 13 16H14C14.2761 16 14.5 15.7761 14.5 15.5V14H16C16.2761 14 16.5 13.7761 16.5 13.5V12.5C16.5 12.2239 16.2761 12 16 12H14.5V2.5C14.5 2.22386 14.2761 2 14 2H13C12.7239 2 12.5 2.22386 12.5 2.5V4H11C10.7239 4 10.5 4.22386 10.5 4.5V5.5C10.5 5.77614 10.7239 6 11 6H12.5V15.5ZM5.5 17.5C5.5 17.7761 5.72386 18 6 18H7C7.27614 18 7.5 17.7761 7.5 17.5V10H9C9.27614 10 9.5 9.77614 9.5 9.5V8.5C9.5 8.22386 9.27614 8 9 8H7.5V4.5C7.5 4.22386 7.27614 4 7 4H6C5.72386 4 5.5 4.22386 5.5 4.5V14H4C3.72386 14 3.5 14.2239 3.5 14.5V15.5C3.5 15.7761 3.72386 16 4 16H5.5V17.5Z"
|
|
110
|
+
}
|
|
111
|
+
) })
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
CandlesIcon = (props) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
115
|
+
"svg",
|
|
116
|
+
{
|
|
117
|
+
viewBox: "0 0 20 20",
|
|
118
|
+
fill: "currentColor",
|
|
119
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
120
|
+
...props,
|
|
121
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("g", { id: "Candles", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
122
|
+
"path",
|
|
123
|
+
{
|
|
124
|
+
id: "Union",
|
|
125
|
+
fillRule: "evenodd",
|
|
126
|
+
clipRule: "evenodd",
|
|
127
|
+
d: "M7.25 2.5V4H8.5C8.77614 4 9 4.22386 9 4.5V15.5C9 15.7761 8.77614 16 8.5 16H7.25V17.5C7.25 17.7761 7.02614 18 6.75 18H6.25C5.97386 18 5.75 17.7761 5.75 17.5V16H4.5C4.22386 16 4 15.7761 4 15.5V4.5C4 4.22386 4.22386 4 4.5 4H5.75V2.5C5.75 2.22386 5.97386 2 6.25 2H6.75C7.02614 2 7.25 2.22386 7.25 2.5ZM5.5 5.5V14.5H7.5V5.5H5.5ZM14.25 4.5V7H15.5C15.7761 7 16 7.22386 16 7.5V15.5C16 15.7761 15.7761 16 15.5 16H14.25V17.5C14.25 17.7761 14.0261 18 13.75 18H13.25C12.9739 18 12.75 17.7761 12.75 17.5V16H11.5C11.2239 16 11 15.7761 11 15.5V7.5C11 7.22386 11.2239 7 11.5 7H12.75V4.5C12.75 4.22386 12.9739 4 13.25 4H13.75C14.0261 4 14.25 4.22386 14.25 4.5ZM12.5 8.5V14.5H14.5V8.5H12.5Z"
|
|
128
|
+
}
|
|
129
|
+
) })
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
HollowCandlesIcon = (props) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
133
|
+
"svg",
|
|
134
|
+
{
|
|
135
|
+
viewBox: "0 0 20 20",
|
|
136
|
+
fill: "currentColor",
|
|
137
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
138
|
+
...props,
|
|
139
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("g", { id: "Hollow Candles", children: [
|
|
140
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
141
|
+
"path",
|
|
142
|
+
{
|
|
143
|
+
id: "Subtract",
|
|
144
|
+
fillRule: "evenodd",
|
|
145
|
+
clipRule: "evenodd",
|
|
146
|
+
d: "M5.5 14.5V5.5H7.5V14.5H5.5Z",
|
|
147
|
+
fill: "white",
|
|
148
|
+
fillOpacity: "0.12"
|
|
149
|
+
}
|
|
150
|
+
),
|
|
151
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
152
|
+
"path",
|
|
153
|
+
{
|
|
154
|
+
id: "Union",
|
|
155
|
+
fillRule: "evenodd",
|
|
156
|
+
clipRule: "evenodd",
|
|
157
|
+
d: "M7.25 2.5V4H8.5C8.77614 4 9 4.22386 9 4.5V15.5C9 15.7761 8.77614 16 8.5 16H7.25V17.5C7.25 17.7761 7.02614 18 6.75 18H6.25C5.97386 18 5.75 17.7761 5.75 17.5V16H4.5C4.22386 16 4 15.7761 4 15.5V4.5C4 4.22386 4.22386 4 4.5 4H5.75V2.5C5.75 2.22386 5.97386 2 6.25 2H6.75C7.02614 2 7.25 2.22386 7.25 2.5ZM5.5 5.5V14.5H7.5V5.5H5.5ZM14.25 4.5V7H15.5C15.7761 7 16 7.22386 16 7.5V15.5C16 15.7761 15.7761 16 15.5 16H14.25V17.5C14.25 17.7761 14.0261 18 13.75 18H13.25C12.9739 18 12.75 17.7761 12.75 17.5V16H11.5C11.2239 16 11 15.7761 11 15.5V7.5C11 7.22386 11.2239 7 11.5 7H12.75V4.5C12.75 4.22386 12.9739 4 13.25 4H13.75C14.0261 4 14.25 4.22386 14.25 4.5ZM12.5 8.5V14.5H14.5V8.5H12.5Z"
|
|
158
|
+
}
|
|
159
|
+
)
|
|
160
|
+
] })
|
|
161
|
+
}
|
|
162
|
+
);
|
|
163
|
+
LineIcon = (props) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
164
|
+
"svg",
|
|
165
|
+
{
|
|
166
|
+
viewBox: "0 0 20 20",
|
|
167
|
+
fill: "currentColor",
|
|
168
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
169
|
+
...props,
|
|
170
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("g", { id: "Line", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
171
|
+
"path",
|
|
172
|
+
{
|
|
173
|
+
id: "Vector 16 (Stroke)",
|
|
174
|
+
fillRule: "evenodd",
|
|
175
|
+
clipRule: "evenodd",
|
|
176
|
+
d: "M18.3 2.72288C18.542 2.85596 18.6303 3.15999 18.4972 3.40195L13.495 12.4968C13.0776 13.2557 12.1061 13.5044 11.3754 13.0394L7.19878 10.3816L2.97738 17.558C2.83737 17.796 2.53092 17.8754 2.2929 17.7354L1.43097 17.2284C1.19295 17.0884 1.1135 16.7819 1.25351 16.5439L5.73746 8.92122C6.16792 8.18943 7.1194 7.96045 7.83567 8.41626L11.9995 11.0659L16.7448 2.43811C16.8778 2.19615 17.1819 2.10788 17.4238 2.24096L18.3 2.72288Z"
|
|
177
|
+
}
|
|
178
|
+
) })
|
|
179
|
+
}
|
|
180
|
+
);
|
|
181
|
+
AreaIcon = (props) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
182
|
+
"svg",
|
|
183
|
+
{
|
|
184
|
+
viewBox: "0 0 20 20",
|
|
185
|
+
fill: "currentColor",
|
|
186
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
187
|
+
...props,
|
|
188
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("g", { id: "Area", children: [
|
|
189
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
190
|
+
"path",
|
|
191
|
+
{
|
|
192
|
+
id: "Vector 16 (Stroke)",
|
|
193
|
+
fillRule: "evenodd",
|
|
194
|
+
clipRule: "evenodd",
|
|
195
|
+
d: "M18.3 2.72288C18.542 2.85596 18.6303 3.15999 18.4972 3.40195L13.495 12.4968C13.0776 13.2557 12.1061 13.5044 11.3754 13.0394L7.19878 10.3816L2.97738 17.558C2.83737 17.796 2.53092 17.8754 2.2929 17.7354L1.43097 17.2284C1.19295 17.0884 1.1135 16.7819 1.25351 16.5439L5.73746 8.92122C6.16792 8.18943 7.1194 7.96045 7.83567 8.41626L11.9995 11.0659L16.7448 2.43811C16.8778 2.19615 17.1819 2.10788 17.4238 2.24096L18.3 2.72288Z"
|
|
196
|
+
}
|
|
197
|
+
),
|
|
198
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
199
|
+
"path",
|
|
200
|
+
{
|
|
201
|
+
id: "Subtract",
|
|
202
|
+
fillRule: "evenodd",
|
|
203
|
+
clipRule: "evenodd",
|
|
204
|
+
d: "M2.7608 17.7562C2.84602 17.899 3.00106 18 3.19016 18H16.362C17.4665 18 18.362 17.1046 18.362 16V3.94663C18.362 3.86618 18.3453 3.79397 18.3162 3.73108L13.495 12.4968C13.0776 13.2557 12.1061 13.5044 11.3754 13.0394L7.19881 10.3816L2.9774 17.558C2.92465 17.6477 2.84826 17.7148 2.7608 17.7562Z",
|
|
205
|
+
fill: "white",
|
|
206
|
+
fillOpacity: "0.12"
|
|
207
|
+
}
|
|
208
|
+
)
|
|
209
|
+
] })
|
|
210
|
+
}
|
|
211
|
+
);
|
|
212
|
+
BaseLineIcon = (props) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
213
|
+
"svg",
|
|
214
|
+
{
|
|
215
|
+
viewBox: "0 0 20 20",
|
|
216
|
+
fill: "currentColor",
|
|
217
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
218
|
+
...props,
|
|
219
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("g", { id: "Baseline", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
220
|
+
"path",
|
|
221
|
+
{
|
|
222
|
+
id: "Union",
|
|
223
|
+
fillRule: "evenodd",
|
|
224
|
+
clipRule: "evenodd",
|
|
225
|
+
d: "M6.05938 2.93544C6.55642 1.71198 8.27766 1.68139 8.81785 2.88642L11.4361 8.72723H9.24438L7.4717 4.77279L5.86521 8.72723H3.70647L6.05938 2.93544ZM13.9282 14.2865L13.0051 12.2272H10.8133L12.5586 16.1204C13.088 17.3014 14.7641 17.3026 15.2952 16.1224L17.048 12.2272H14.8549L13.9282 14.2865ZM2.28459 12.2272H4.44333L1.85293 18.6036L0 17.8509L2.28459 12.2272ZM16.4299 8.72723H18.623L19.3384 7.13759L17.5145 6.31686L16.4299 8.72723ZM1.42645 10.2272C1.42645 9.95109 1.65031 9.72723 1.92645 9.72723H2.92645C3.20259 9.72723 3.42645 9.95109 3.42645 10.2272V10.7272C3.42645 11.0034 3.20259 11.2272 2.92645 11.2272H1.92645C1.65031 11.2272 1.42645 11.0034 1.42645 10.7272V10.2272ZM4.42645 10.2272C4.42645 9.95109 4.65031 9.72723 4.92645 9.72723H5.92645C6.20259 9.72723 6.42645 9.95109 6.42645 10.2272V10.7272C6.42645 11.0034 6.20259 11.2272 5.92645 11.2272H4.92645C4.65031 11.2272 4.42645 11.0034 4.42645 10.7272V10.2272ZM7.92645 9.72723C7.65031 9.72723 7.42645 9.95109 7.42645 10.2272V10.7272C7.42645 11.0034 7.65031 11.2272 7.92645 11.2272H8.92645C9.20259 11.2272 9.42645 11.0034 9.42645 10.7272V10.2272C9.42645 9.95109 9.20259 9.72723 8.92645 9.72723H7.92645ZM10.4265 10.2272C10.4265 9.95109 10.6503 9.72723 10.9265 9.72723H11.9265C12.2026 9.72723 12.4265 9.95109 12.4265 10.2272V10.7272C12.4265 11.0034 12.2026 11.2272 11.9265 11.2272H10.9265C10.6503 11.2272 10.4265 11.0034 10.4265 10.7272V10.2272ZM13.9265 9.72723C13.6503 9.72723 13.4265 9.95109 13.4265 10.2272V10.7272C13.4265 11.0034 13.6503 11.2272 13.9265 11.2272H14.9265C15.2026 11.2272 15.4265 11.0034 15.4265 10.7272V10.2272C15.4265 9.95109 15.2026 9.72723 14.9265 9.72723H13.9265ZM16.4265 10.2272C16.4265 9.95109 16.6503 9.72723 16.9265 9.72723H17.9265C18.2026 9.72723 18.4265 9.95109 18.4265 10.2272V10.7272C18.4265 11.0034 18.2026 11.2272 17.9265 11.2272H16.9265C16.6503 11.2272 16.4265 11.0034 16.4265 10.7272V10.2272Z"
|
|
226
|
+
}
|
|
227
|
+
) })
|
|
228
|
+
}
|
|
229
|
+
);
|
|
230
|
+
UnSelectIcon = (props) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
231
|
+
"svg",
|
|
232
|
+
{
|
|
233
|
+
viewBox: "0 0 12 12",
|
|
234
|
+
fill: "currentColor",
|
|
235
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
236
|
+
...props,
|
|
237
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("g", { id: "Unselected", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
238
|
+
"path",
|
|
239
|
+
{
|
|
240
|
+
id: "Vector",
|
|
241
|
+
d: "M6.00684 0.999023C3.24544 0.999023 1.00684 3.23752 1.00684 5.99902C1.00684 8.76051 3.24544 10.999 6.00684 10.999C8.76834 10.999 11.0068 8.76051 11.0068 5.99902C11.0068 3.23752 8.76834 0.999023 6.00684 0.999023ZM6.00684 1.99902C8.21584 1.99902 10.0068 3.79002 10.0068 5.99902C10.0068 8.20801 8.21584 9.99901 6.00684 9.99901C3.79769 9.99901 2.00684 8.20801 2.00684 5.99902C2.00684 3.79002 3.79769 1.99902 6.00684 1.99902Z",
|
|
242
|
+
fill: "white",
|
|
243
|
+
fillOpacity: "0.2"
|
|
244
|
+
}
|
|
245
|
+
) })
|
|
246
|
+
}
|
|
247
|
+
);
|
|
248
|
+
SelectedIcon = (props) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
249
|
+
"svg",
|
|
250
|
+
{
|
|
251
|
+
viewBox: "0 0 12 12",
|
|
252
|
+
fill: "currentColor",
|
|
253
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
254
|
+
...props,
|
|
255
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("g", { id: "Selected-Multiple Choices-fill", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
256
|
+
"path",
|
|
257
|
+
{
|
|
258
|
+
id: "Subtract",
|
|
259
|
+
fillRule: "evenodd",
|
|
260
|
+
clipRule: "evenodd",
|
|
261
|
+
d: "M1.00684 5.99902C1.00684 3.23752 3.24544 0.999023 6.00684 0.999023C8.76834 0.999023 11.0068 3.23752 11.0068 5.99902C11.0068 8.76051 8.76834 10.999 6.00684 10.999C3.24544 10.999 1.00684 8.76051 1.00684 5.99902ZM8.49243 3.65563C8.60602 3.54726 8.76156 3.49957 8.91068 3.49957C9.05981 3.49957 9.21534 3.54726 9.32893 3.65563C9.5567 3.87231 9.5567 4.23649 9.32893 4.45317L5.25362 8.33706C5.02644 8.55374 4.6443 8.55374 4.41712 8.33706L2.67014 6.67253C2.44296 6.45585 2.44296 6.09161 2.67014 5.87499C2.89791 5.65831 3.28004 5.65831 3.50722 5.87499L4.83537 7.1407L8.49243 3.65563Z",
|
|
262
|
+
fill: "#608CFF"
|
|
263
|
+
}
|
|
264
|
+
) })
|
|
265
|
+
}
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
});
|
|
17
269
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
270
|
+
// src/components/lineType/index.tsx
|
|
271
|
+
var lineType_exports = {};
|
|
272
|
+
__export(lineType_exports, {
|
|
273
|
+
default: () => lineType_default
|
|
274
|
+
});
|
|
275
|
+
var LineType, lineType_default;
|
|
276
|
+
var init_lineType = __esm({
|
|
277
|
+
"src/components/lineType/index.tsx"() {
|
|
278
|
+
init_icons();
|
|
279
|
+
LineType = (props) => {
|
|
280
|
+
const [open, setOpen] = React3.useState(false);
|
|
281
|
+
const { t } = orderlyI18n.useTranslation();
|
|
282
|
+
const lineTypeList = React3.useMemo(() => {
|
|
283
|
+
return [
|
|
284
|
+
{
|
|
285
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(BarIcon, { fill: "currentColor", className: "oui-w-5 oui-h-5" }),
|
|
286
|
+
label: t("tradingView.lineType.bars"),
|
|
287
|
+
value: "0"
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(CandlesIcon, { fill: "currentColor", className: "oui-w-5 oui-h-5" }),
|
|
291
|
+
label: t("tradingView.lineType.candles"),
|
|
292
|
+
value: "1"
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(HollowCandlesIcon, { fill: "currentColor", className: "oui-w-5 oui-h-5" }),
|
|
296
|
+
label: t("tradingView.lineType.hollowCandles"),
|
|
297
|
+
value: "9"
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(LineIcon, { fill: "currentColor", className: "oui-w-5 oui-h-5" }),
|
|
301
|
+
label: t("tradingView.lineType.line"),
|
|
302
|
+
value: "2"
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(AreaIcon, { fill: "currentColor", className: "oui-w-5 oui-h-5" }),
|
|
306
|
+
label: t("tradingView.lineType.area"),
|
|
307
|
+
value: "3"
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(BaseLineIcon, { fill: "currentColor", className: "oui-w-5 oui-h-5" }),
|
|
311
|
+
label: t("tradingView.lineType.baseline"),
|
|
312
|
+
value: "10"
|
|
313
|
+
}
|
|
314
|
+
];
|
|
315
|
+
}, [t]);
|
|
316
|
+
const currentLineTypeIcon = React3.useMemo(() => {
|
|
317
|
+
const data = lineTypeList.find((item) => item.value === props.lineType);
|
|
318
|
+
if (data) {
|
|
319
|
+
return data.icon;
|
|
320
|
+
}
|
|
321
|
+
return lineTypeList[1].icon;
|
|
322
|
+
}, [props.lineType]);
|
|
323
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.DropdownMenuRoot, { open, onOpenChange: setOpen, children: [
|
|
324
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
325
|
+
orderlyUi.Box,
|
|
326
|
+
{
|
|
327
|
+
className: orderlyUi.cn(
|
|
328
|
+
"oui-w-[18px] oui-h-[18px] oui-cursor-pointer oui-text-base-contrast-36 hover:oui-text-base-contrast-80",
|
|
329
|
+
open && "oui-text-base-contrast-80"
|
|
330
|
+
),
|
|
331
|
+
children: currentLineTypeIcon
|
|
332
|
+
}
|
|
333
|
+
) }),
|
|
334
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.DropdownMenuPortal, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
335
|
+
orderlyUi.DropdownMenuContent,
|
|
336
|
+
{
|
|
337
|
+
onCloseAutoFocus: (e) => e.preventDefault(),
|
|
338
|
+
onClick: (e) => e.stopPropagation(),
|
|
339
|
+
align: "start",
|
|
340
|
+
sideOffset: 20,
|
|
341
|
+
className: "oui-bg-base-8",
|
|
342
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
343
|
+
orderlyUi.Flex,
|
|
344
|
+
{
|
|
345
|
+
direction: "column",
|
|
346
|
+
gap: 4,
|
|
347
|
+
px: 5,
|
|
348
|
+
py: 5,
|
|
349
|
+
width: 240,
|
|
350
|
+
justify: "start",
|
|
351
|
+
itemAlign: "start",
|
|
352
|
+
children: lineTypeList.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
353
|
+
orderlyUi.Flex,
|
|
354
|
+
{
|
|
355
|
+
justify: "start",
|
|
356
|
+
itemAlign: "center",
|
|
357
|
+
gap: 2,
|
|
358
|
+
className: orderlyUi.cn(
|
|
359
|
+
"oui-text-base-contrast-36 oui-cursor-pointer oui-w-full hover:oui-text-base-contrast",
|
|
360
|
+
props.lineType === item.value && "oui-text-base-contrast"
|
|
361
|
+
),
|
|
362
|
+
onClick: () => props.changeLineType(item.value),
|
|
363
|
+
children: [
|
|
364
|
+
item.icon,
|
|
365
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-text-sm", children: item.label })
|
|
366
|
+
]
|
|
367
|
+
},
|
|
368
|
+
item.value
|
|
369
|
+
))
|
|
370
|
+
}
|
|
371
|
+
)
|
|
372
|
+
}
|
|
373
|
+
) })
|
|
374
|
+
] });
|
|
375
|
+
};
|
|
376
|
+
lineType_default = LineType;
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
// src/components/timeInterval/index.tsx
|
|
381
|
+
var timeInterval_exports = {};
|
|
382
|
+
__export(timeInterval_exports, {
|
|
383
|
+
MobileTimeInterval: () => MobileTimeInterval,
|
|
384
|
+
TimeInterval: () => TimeInterval
|
|
385
|
+
});
|
|
386
|
+
var useMobileTimeIntervalMoreMap, TimeInterval, DesktopTimeInterval, MobileTimeInterval, DropDownTimeInterval;
|
|
387
|
+
var init_timeInterval = __esm({
|
|
388
|
+
"src/components/timeInterval/index.tsx"() {
|
|
389
|
+
init_icons();
|
|
390
|
+
useMobileTimeIntervalMoreMap = () => {
|
|
391
|
+
const { t } = orderlyI18n.useTranslation();
|
|
392
|
+
const mobileTimeIntervalMoreMap = React3.useMemo(() => {
|
|
393
|
+
return [
|
|
394
|
+
[
|
|
395
|
+
{
|
|
396
|
+
value: "3",
|
|
397
|
+
label: t("tradingView.timeInterval.3m")
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
value: "5",
|
|
401
|
+
label: t("tradingView.timeInterval.5m")
|
|
402
|
+
},
|
|
403
|
+
{
|
|
404
|
+
value: "30",
|
|
405
|
+
label: t("tradingView.timeInterval.30m")
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
value: "120",
|
|
409
|
+
label: t("tradingView.timeInterval.2h")
|
|
410
|
+
}
|
|
411
|
+
],
|
|
412
|
+
[
|
|
413
|
+
{
|
|
414
|
+
value: "360",
|
|
415
|
+
label: t("tradingView.timeInterval.6h")
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
value: "720",
|
|
419
|
+
label: t("tradingView.timeInterval.12h")
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
value: "3d",
|
|
423
|
+
label: t("tradingView.timeInterval.3d")
|
|
424
|
+
},
|
|
425
|
+
{
|
|
426
|
+
value: "1M",
|
|
427
|
+
label: t("tradingView.timeInterval.1M")
|
|
428
|
+
}
|
|
429
|
+
]
|
|
430
|
+
];
|
|
431
|
+
}, [t]);
|
|
432
|
+
return { mobileTimeIntervalMoreMap };
|
|
433
|
+
};
|
|
434
|
+
TimeInterval = (props) => {
|
|
435
|
+
const isMobile = orderlyHooks.useMediaQuery(orderlyTypes.MEDIA_TABLET);
|
|
436
|
+
if (isMobile) {
|
|
437
|
+
return /* @__PURE__ */ jsxRuntime.jsx(MobileTimeInterval, { ...props });
|
|
438
|
+
}
|
|
439
|
+
return /* @__PURE__ */ jsxRuntime.jsx(DesktopTimeInterval, { ...props });
|
|
440
|
+
};
|
|
441
|
+
DesktopTimeInterval = (props) => {
|
|
442
|
+
const { t } = orderlyI18n.useTranslation();
|
|
443
|
+
const timeIntervalMap = React3.useMemo(() => {
|
|
444
|
+
return [
|
|
445
|
+
{
|
|
446
|
+
value: "1",
|
|
447
|
+
label: t("tradingView.timeInterval.1m")
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
value: "3",
|
|
451
|
+
label: t("tradingView.timeInterval.3m")
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
value: "5",
|
|
455
|
+
label: t("tradingView.timeInterval.5m")
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
value: "15",
|
|
459
|
+
label: t("tradingView.timeInterval.15m")
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
value: "30",
|
|
463
|
+
label: t("tradingView.timeInterval.30m")
|
|
464
|
+
},
|
|
465
|
+
{
|
|
466
|
+
value: "60",
|
|
467
|
+
label: t("tradingView.timeInterval.1h")
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
value: "240",
|
|
471
|
+
label: t("tradingView.timeInterval.4h")
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
value: "720",
|
|
475
|
+
label: t("tradingView.timeInterval.12h")
|
|
476
|
+
},
|
|
477
|
+
{
|
|
478
|
+
value: "1D",
|
|
479
|
+
label: t("tradingView.timeInterval.1d")
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
value: "1W",
|
|
483
|
+
label: t("tradingView.timeInterval.1w")
|
|
484
|
+
},
|
|
485
|
+
{
|
|
486
|
+
value: "1M",
|
|
487
|
+
label: t("tradingView.timeInterval.1M")
|
|
488
|
+
}
|
|
489
|
+
];
|
|
490
|
+
}, [t]);
|
|
491
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
492
|
+
"div",
|
|
493
|
+
{
|
|
494
|
+
className: orderlyUi.cn(
|
|
495
|
+
"oui-text-2xs oui-text-base-contrast-36 oui-flex oui-gap-[2px] oui-items-center oui-mr-3 oui-font-semibold",
|
|
496
|
+
"oui-overflow-hidden"
|
|
497
|
+
),
|
|
498
|
+
children: timeIntervalMap.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
499
|
+
"div",
|
|
500
|
+
{
|
|
501
|
+
className: orderlyUi.cn(
|
|
502
|
+
"oui-cursor-pointer oui-px-2",
|
|
503
|
+
"hover:oui-text-base-contrast-80",
|
|
504
|
+
"oui-break-normal oui-whitespace-nowrap",
|
|
505
|
+
props.interval === item.value && "oui-text-base-contrast-80 oui-bg-white/[.06] oui-rounded"
|
|
506
|
+
),
|
|
507
|
+
id: item.value,
|
|
508
|
+
onClick: () => props.changeInterval(item.value),
|
|
509
|
+
children: item.label
|
|
510
|
+
},
|
|
511
|
+
item.value
|
|
512
|
+
))
|
|
513
|
+
}
|
|
514
|
+
);
|
|
515
|
+
};
|
|
516
|
+
MobileTimeInterval = (props) => {
|
|
517
|
+
const { t } = orderlyI18n.useTranslation();
|
|
518
|
+
const mobileTimeIntervalDefaultMap = React3.useMemo(() => {
|
|
519
|
+
return [
|
|
520
|
+
{
|
|
521
|
+
value: "1",
|
|
522
|
+
label: t("tradingView.timeInterval.1m")
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
value: "15",
|
|
526
|
+
label: t("tradingView.timeInterval.15m")
|
|
527
|
+
},
|
|
528
|
+
{
|
|
529
|
+
value: "60",
|
|
530
|
+
label: t("tradingView.timeInterval.1h")
|
|
531
|
+
},
|
|
532
|
+
{
|
|
533
|
+
value: "240",
|
|
534
|
+
label: t("tradingView.timeInterval.4h")
|
|
535
|
+
},
|
|
536
|
+
{
|
|
537
|
+
value: "1D",
|
|
538
|
+
label: t("tradingView.timeInterval.1d")
|
|
539
|
+
},
|
|
540
|
+
{
|
|
541
|
+
value: "1W",
|
|
542
|
+
label: t("tradingView.timeInterval.1w")
|
|
543
|
+
}
|
|
544
|
+
];
|
|
545
|
+
}, [t]);
|
|
546
|
+
const { mobileTimeIntervalMoreMap } = useMobileTimeIntervalMoreMap();
|
|
547
|
+
const currentIntervalIsInExpand = React3.useMemo(() => {
|
|
548
|
+
for (const row of mobileTimeIntervalMoreMap) {
|
|
549
|
+
for (const item of row) {
|
|
550
|
+
if (item.value === props.interval) {
|
|
551
|
+
return item.label;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
return null;
|
|
556
|
+
}, [props.interval, mobileTimeIntervalMoreMap]);
|
|
557
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
558
|
+
orderlyUi.Flex,
|
|
559
|
+
{
|
|
560
|
+
justify: "start",
|
|
561
|
+
itemAlign: "center",
|
|
562
|
+
gap: 3,
|
|
563
|
+
className: orderlyUi.cn(
|
|
564
|
+
"oui-text-2xs oui-text-base-contrast-36",
|
|
565
|
+
"oui-overflow-hidden"
|
|
566
|
+
),
|
|
567
|
+
children: [
|
|
568
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: " oui-flex oui-gap-1 oui-items-center oui-mr-3 oui-font-semibold", children: mobileTimeIntervalDefaultMap.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
569
|
+
"div",
|
|
570
|
+
{
|
|
571
|
+
className: orderlyUi.cn(
|
|
572
|
+
"oui-px-2",
|
|
573
|
+
"oui-break-normal oui-whitespace-nowrap",
|
|
574
|
+
props.interval === item.value && "oui-text-base-contrast-80 oui-bg-white/[.06] oui-rounded"
|
|
575
|
+
),
|
|
576
|
+
onClick: () => props.changeInterval(item.value),
|
|
577
|
+
children: item.label
|
|
578
|
+
},
|
|
579
|
+
item.value
|
|
580
|
+
)) }),
|
|
581
|
+
/* @__PURE__ */ jsxRuntime.jsx(DropDownTimeInterval, { ...props, children: currentIntervalIsInExpand ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-text-base-contrast-80", children: currentIntervalIsInExpand }) : /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-break-normal oui-whitespace-nowrap", children: t("tradingView.timeInterval.more") }) })
|
|
582
|
+
]
|
|
583
|
+
}
|
|
584
|
+
);
|
|
585
|
+
};
|
|
586
|
+
DropDownTimeInterval = (props) => {
|
|
587
|
+
const [open, setOpen] = React3__default.default.useState(false);
|
|
588
|
+
const { mobileTimeIntervalMoreMap } = useMobileTimeIntervalMoreMap();
|
|
589
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.DropdownMenuRoot, { open, onOpenChange: setOpen, children: [
|
|
590
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "oui-flex oui-justify-start oui-items-center oui-gap-0.5", children: [
|
|
591
|
+
props.children,
|
|
592
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
593
|
+
CaretIcon,
|
|
594
|
+
{
|
|
595
|
+
className: orderlyUi.cn(
|
|
596
|
+
"oui-w-3 oui-h-3",
|
|
597
|
+
open && "oui-text-base-contrast-80 oui-rotate-180"
|
|
598
|
+
)
|
|
599
|
+
}
|
|
600
|
+
)
|
|
601
|
+
] }) }),
|
|
602
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.DropdownMenuPortal, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
603
|
+
orderlyUi.DropdownMenuContent,
|
|
604
|
+
{
|
|
605
|
+
onCloseAutoFocus: (e) => e.preventDefault(),
|
|
606
|
+
onClick: (e) => e.stopPropagation(),
|
|
607
|
+
align: "start",
|
|
608
|
+
alignOffset: 0,
|
|
609
|
+
sideOffset: 0,
|
|
610
|
+
className: orderlyUi.cn(
|
|
611
|
+
"oui-markets-dropdown-menu-content oui-bg-base-9 oui-w-screen oui-flex oui-flex-col oui-gap-2 oui-p-3"
|
|
612
|
+
),
|
|
613
|
+
children: mobileTimeIntervalMoreMap.map((row, id) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-flex oui-gap-2", children: row.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
614
|
+
"div",
|
|
615
|
+
{
|
|
616
|
+
className: orderlyUi.cn(
|
|
617
|
+
"oui-w-full oui-text-2xs oui-flex oui-items-center oui-justify-center oui-h-6 oui-rounded",
|
|
618
|
+
item.value === props.interval ? "oui-text-base-contrast oui-bg-primary-darken" : "oui-text-base-contrast-36 oui-bg-base-5"
|
|
619
|
+
),
|
|
620
|
+
onClick: () => {
|
|
621
|
+
props.changeInterval(item.value);
|
|
622
|
+
},
|
|
623
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: item.label })
|
|
624
|
+
},
|
|
625
|
+
item.value
|
|
626
|
+
)) }, id))
|
|
627
|
+
}
|
|
628
|
+
) })
|
|
629
|
+
] });
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
var DesktopDisplayControl;
|
|
634
|
+
var init_displayControl_desktop = __esm({
|
|
635
|
+
"src/components/displayControl/displayControl.desktop.tsx"() {
|
|
636
|
+
init_icons();
|
|
637
|
+
DesktopDisplayControl = (props) => {
|
|
638
|
+
const { displayControlState, changeDisplayControlState } = props;
|
|
639
|
+
const [open, setOpen] = React3.useState(false);
|
|
640
|
+
const { t } = orderlyI18n.useTranslation();
|
|
641
|
+
const displayControlMap = React3.useMemo(() => {
|
|
642
|
+
return [
|
|
643
|
+
{
|
|
644
|
+
label: t("common.position"),
|
|
645
|
+
id: "position"
|
|
646
|
+
},
|
|
647
|
+
{
|
|
648
|
+
label: t("tradingView.displayControl.buySell"),
|
|
649
|
+
id: "buySell"
|
|
650
|
+
},
|
|
651
|
+
{
|
|
652
|
+
label: t("tradingView.displayControl.limitOrders"),
|
|
653
|
+
id: "limitOrders"
|
|
654
|
+
},
|
|
655
|
+
{
|
|
656
|
+
label: t("tradingView.displayControl.stopOrders"),
|
|
657
|
+
id: "stopOrders"
|
|
658
|
+
},
|
|
659
|
+
{
|
|
660
|
+
label: t("common.tpsl"),
|
|
661
|
+
id: "tpsl"
|
|
662
|
+
},
|
|
663
|
+
{
|
|
664
|
+
label: t("tpsl.positionTpsl"),
|
|
665
|
+
id: "positionTpsl"
|
|
666
|
+
},
|
|
667
|
+
{
|
|
668
|
+
label: t("orderEntry.orderType.trailingStop"),
|
|
669
|
+
id: "trailingStop"
|
|
670
|
+
}
|
|
671
|
+
];
|
|
672
|
+
}, [t]);
|
|
673
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.DropdownMenuRoot, { open, onOpenChange: setOpen, children: [
|
|
674
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
675
|
+
orderlyUi.Flex,
|
|
676
|
+
{
|
|
677
|
+
justify: "start",
|
|
678
|
+
itemAlign: "center",
|
|
679
|
+
className: "oui-gap-[2px] oui-cursor-pointer oui-text-base-contrast-36 hover:oui-text-base-contrast-80",
|
|
680
|
+
children: [
|
|
681
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
682
|
+
DisplaySettingIcon,
|
|
683
|
+
{
|
|
684
|
+
className: orderlyUi.cn(
|
|
685
|
+
"oui-w-[18px] oui-h-[18px] ",
|
|
686
|
+
open && "oui-text-base-contrast-80"
|
|
687
|
+
)
|
|
688
|
+
}
|
|
689
|
+
),
|
|
690
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
691
|
+
CaretIcon,
|
|
692
|
+
{
|
|
693
|
+
className: orderlyUi.cn(
|
|
694
|
+
"oui-w-3 oui-h-3",
|
|
695
|
+
open && "oui-text-base-contrast-80 oui-rotate-180"
|
|
696
|
+
)
|
|
697
|
+
}
|
|
698
|
+
)
|
|
699
|
+
]
|
|
700
|
+
}
|
|
701
|
+
) }),
|
|
702
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.DropdownMenuPortal, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
703
|
+
orderlyUi.DropdownMenuContent,
|
|
704
|
+
{
|
|
705
|
+
onCloseAutoFocus: (e) => e.preventDefault(),
|
|
706
|
+
onClick: (e) => e.stopPropagation(),
|
|
707
|
+
align: "start",
|
|
708
|
+
className: "oui-bg-base-8",
|
|
709
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
710
|
+
orderlyUi.Flex,
|
|
711
|
+
{
|
|
712
|
+
direction: "column",
|
|
713
|
+
gap: 4,
|
|
714
|
+
px: 5,
|
|
715
|
+
py: 5,
|
|
716
|
+
width: 240,
|
|
717
|
+
justify: "start",
|
|
718
|
+
itemAlign: "start",
|
|
719
|
+
children: displayControlMap.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
720
|
+
orderlyUi.Flex,
|
|
721
|
+
{
|
|
722
|
+
justify: "between",
|
|
723
|
+
itemAlign: "center",
|
|
724
|
+
className: "oui-w-full",
|
|
725
|
+
children: [
|
|
726
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
727
|
+
orderlyUi.Text,
|
|
728
|
+
{
|
|
729
|
+
className: orderlyUi.cn(
|
|
730
|
+
"oui-text-sm oui-text-base-contrast-80",
|
|
731
|
+
!displayControlState[item.id] && "oui-text-base-contrast-36"
|
|
732
|
+
),
|
|
733
|
+
children: item.label
|
|
734
|
+
}
|
|
735
|
+
),
|
|
736
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
737
|
+
orderlyUi.Switch,
|
|
738
|
+
{
|
|
739
|
+
className: "oui-h-4 oui-w-8",
|
|
740
|
+
checked: displayControlState[item.id],
|
|
741
|
+
onCheckedChange: (checked) => {
|
|
742
|
+
changeDisplayControlState({
|
|
743
|
+
...displayControlState,
|
|
744
|
+
[item.id]: checked
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
)
|
|
749
|
+
]
|
|
750
|
+
},
|
|
751
|
+
item.id
|
|
752
|
+
))
|
|
753
|
+
}
|
|
754
|
+
)
|
|
755
|
+
}
|
|
756
|
+
) })
|
|
757
|
+
] }) });
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
});
|
|
761
|
+
var MobileDisplayControl;
|
|
762
|
+
var init_displayControl_mobile = __esm({
|
|
763
|
+
"src/components/displayControl/displayControl.mobile.tsx"() {
|
|
764
|
+
init_icons();
|
|
765
|
+
MobileDisplayControl = (props) => {
|
|
766
|
+
const [open, setOpen] = React3.useState(false);
|
|
767
|
+
const { t } = orderlyI18n.useTranslation();
|
|
768
|
+
const mobileDisplayControlMap = React3.useMemo(() => {
|
|
769
|
+
return [
|
|
770
|
+
[
|
|
771
|
+
{
|
|
772
|
+
label: t("common.position"),
|
|
773
|
+
id: "position"
|
|
774
|
+
},
|
|
775
|
+
{
|
|
776
|
+
label: t("tradingView.displayControl.limitOrders"),
|
|
777
|
+
id: "limitOrders"
|
|
778
|
+
}
|
|
779
|
+
],
|
|
780
|
+
[
|
|
781
|
+
{
|
|
782
|
+
label: t("tradingView.displayControl.stopOrders"),
|
|
783
|
+
id: "stopOrders"
|
|
784
|
+
},
|
|
785
|
+
{
|
|
786
|
+
label: t("common.tpsl"),
|
|
787
|
+
id: "tpsl"
|
|
788
|
+
}
|
|
789
|
+
],
|
|
790
|
+
[
|
|
791
|
+
{
|
|
792
|
+
label: t("tpsl.positionTpsl"),
|
|
793
|
+
id: "positionTpsl"
|
|
794
|
+
},
|
|
795
|
+
{
|
|
796
|
+
label: t("tradingView.displayControl.buySell"),
|
|
797
|
+
id: "buySell"
|
|
798
|
+
}
|
|
799
|
+
],
|
|
800
|
+
[
|
|
801
|
+
{
|
|
802
|
+
label: t("orderEntry.orderType.trailingStop"),
|
|
803
|
+
id: "trailingStop"
|
|
804
|
+
},
|
|
805
|
+
// placeholder
|
|
806
|
+
{}
|
|
807
|
+
]
|
|
808
|
+
];
|
|
809
|
+
}, [t]);
|
|
810
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.DropdownMenuRoot, { open, onOpenChange: setOpen, children: [
|
|
811
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
812
|
+
"div",
|
|
813
|
+
{
|
|
814
|
+
className: orderlyUi.cn(
|
|
815
|
+
"oui-flex oui-items-center oui-justify-center oui-gap-0.5 oui-text-base-contrast-36",
|
|
816
|
+
open && "oui-text-base-contrast-8"
|
|
817
|
+
),
|
|
818
|
+
children: [
|
|
819
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
820
|
+
DisplaySettingIcon,
|
|
821
|
+
{
|
|
822
|
+
className: orderlyUi.cn(
|
|
823
|
+
"oui-size-[18px] ",
|
|
824
|
+
open && "oui-text-base-contrast-80"
|
|
825
|
+
)
|
|
826
|
+
}
|
|
827
|
+
),
|
|
828
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
829
|
+
CaretIcon,
|
|
830
|
+
{
|
|
831
|
+
className: orderlyUi.cn(
|
|
832
|
+
"oui-size-3",
|
|
833
|
+
open && "oui-rotate-180 oui-text-base-contrast-80"
|
|
834
|
+
)
|
|
835
|
+
}
|
|
836
|
+
)
|
|
837
|
+
]
|
|
838
|
+
}
|
|
839
|
+
) }),
|
|
840
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.DropdownMenuPortal, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
841
|
+
orderlyUi.DropdownMenuContent,
|
|
842
|
+
{
|
|
843
|
+
onCloseAutoFocus: (e) => e.preventDefault(),
|
|
844
|
+
onClick: (e) => e.stopPropagation(),
|
|
845
|
+
align: "start",
|
|
846
|
+
alignOffset: 0,
|
|
847
|
+
sideOffset: 0,
|
|
848
|
+
className: orderlyUi.cn(
|
|
849
|
+
"oui-tradingview-display-control-dropdown-menu-content oui-flex oui-w-screen oui-flex-col oui-gap-2 oui-bg-base-9 oui-p-3"
|
|
850
|
+
),
|
|
851
|
+
children: mobileDisplayControlMap.map((row, id) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-flex oui-gap-2", children: row.map((item, index) => {
|
|
852
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
853
|
+
"div",
|
|
854
|
+
{
|
|
855
|
+
className: orderlyUi.cn(
|
|
856
|
+
"oui-flex oui-h-6 oui-w-full oui-items-center oui-justify-between",
|
|
857
|
+
"oui-rounded oui-px-2 oui-text-2xs",
|
|
858
|
+
item.id && "oui-bg-base-5",
|
|
859
|
+
props.displayControlState[item.id] ? "oui-text-base-contrast" : "oui-text-base-contrast-36"
|
|
860
|
+
),
|
|
861
|
+
onClick: () => {
|
|
862
|
+
if (!item.id) {
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
865
|
+
props.changeDisplayControlState({
|
|
866
|
+
...props.displayControlState,
|
|
867
|
+
[item.id]: !props.displayControlState[item.id]
|
|
868
|
+
});
|
|
869
|
+
},
|
|
870
|
+
children: item.id && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
871
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { children: item.label }),
|
|
872
|
+
props.displayControlState[item.id] ? /* @__PURE__ */ jsxRuntime.jsx(SelectedIcon, { className: "oui-size-3" }) : /* @__PURE__ */ jsxRuntime.jsx(UnSelectIcon, { className: "oui-size-3" })
|
|
873
|
+
] })
|
|
874
|
+
},
|
|
875
|
+
item.id || index
|
|
876
|
+
);
|
|
877
|
+
}) }, id))
|
|
878
|
+
}
|
|
879
|
+
) })
|
|
880
|
+
] });
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
});
|
|
884
|
+
|
|
885
|
+
// src/components/displayControl/index.tsx
|
|
886
|
+
var displayControl_exports = {};
|
|
887
|
+
__export(displayControl_exports, {
|
|
888
|
+
DesktopDisplayControl: () => DesktopDisplayControl,
|
|
889
|
+
MobileDisplayControl: () => MobileDisplayControl
|
|
890
|
+
});
|
|
891
|
+
var init_displayControl = __esm({
|
|
892
|
+
"src/components/displayControl/index.tsx"() {
|
|
893
|
+
init_displayControl_desktop();
|
|
894
|
+
init_displayControl_mobile();
|
|
895
|
+
}
|
|
896
|
+
});
|
|
897
|
+
|
|
898
|
+
// src/utils/chart.util.ts
|
|
899
|
+
var upColor = "#008676";
|
|
900
|
+
var downColor = "#D92D6B";
|
|
901
|
+
var chartBG = "#131519";
|
|
902
|
+
var pnlUpColor = "#00B49E";
|
|
903
|
+
var pnlDownColor = "#FF447C";
|
|
904
|
+
var pnlZoreColor = "#333948";
|
|
905
|
+
var textColor = "#FFFFFF";
|
|
906
|
+
var qtyTextColor = "#F4F7F9";
|
|
907
|
+
var font = "regular 11px Manrope";
|
|
908
|
+
var defaultColorConfig = {
|
|
909
|
+
upColor,
|
|
910
|
+
downColor,
|
|
911
|
+
chartBG,
|
|
912
|
+
pnlUpColor,
|
|
913
|
+
pnlDownColor,
|
|
914
|
+
pnlZoreColor,
|
|
915
|
+
textColor,
|
|
916
|
+
qtyTextColor,
|
|
917
|
+
font,
|
|
918
|
+
volumeUpColor: "#00E5A0",
|
|
919
|
+
volumeDownColor: "#FF6B94",
|
|
920
|
+
closeIcon: "rgba(255, 255, 255, 0.8)"
|
|
921
|
+
};
|
|
922
|
+
var getOveriides = (colorConfig, isMobile) => {
|
|
923
|
+
const overrides = {
|
|
924
|
+
"paneProperties.background": colorConfig.chartBG,
|
|
925
|
+
// "paneProperties.background": "#ffff00",
|
|
926
|
+
// "mainSeriesProperties.style": 1,
|
|
927
|
+
"paneProperties.backgroundType": "solid",
|
|
928
|
+
// "paneProperties.background": "#151822",
|
|
929
|
+
"mainSeriesProperties.candleStyle.upColor": colorConfig.upColor,
|
|
930
|
+
"mainSeriesProperties.candleStyle.downColor": colorConfig.downColor,
|
|
931
|
+
"mainSeriesProperties.candleStyle.borderColor": colorConfig.upColor,
|
|
932
|
+
"mainSeriesProperties.candleStyle.borderUpColor": colorConfig.upColor,
|
|
933
|
+
"mainSeriesProperties.candleStyle.borderDownColor": colorConfig.downColor,
|
|
934
|
+
"mainSeriesProperties.candleStyle.wickUpColor": colorConfig.upColor,
|
|
935
|
+
"mainSeriesProperties.candleStyle.wickDownColor": colorConfig.downColor,
|
|
936
|
+
"paneProperties.separatorColor": "#2B2833",
|
|
937
|
+
"paneProperties.vertGridProperties.color": "#26232F",
|
|
938
|
+
"paneProperties.horzGridProperties.color": "#26232F",
|
|
939
|
+
"scalesProperties.fontSize": isMobile ? 8 : 12,
|
|
940
|
+
"scalesProperties.textColor": "#97969B",
|
|
941
|
+
"paneProperties.legendProperties.showSeriesTitle": isMobile ? false : true,
|
|
942
|
+
"mainSeriesProperties.statusViewStyle.symbolTextSource": "ticker",
|
|
943
|
+
"mainSeriesProperties.statusViewStyle.showExchange": false
|
|
944
|
+
};
|
|
945
|
+
const studiesOverrides = {
|
|
946
|
+
"volume.volume.color.0": colorConfig.volumeDownColor,
|
|
947
|
+
"volume.volume.color.1": colorConfig.volumeUpColor
|
|
948
|
+
};
|
|
949
|
+
return {
|
|
950
|
+
overrides,
|
|
951
|
+
studiesOverrides
|
|
952
|
+
};
|
|
953
|
+
};
|
|
954
|
+
var EXCHANGE = "Orderly";
|
|
955
|
+
var withoutExchangePrefix = (symbol) => symbol.includes(":") ? symbol.split(":")[1] : symbol;
|
|
956
|
+
var withExchangePrefix = (symbol) => symbol.startsWith(`${EXCHANGE}:`) ? symbol : `${EXCHANGE}:${symbol}`;
|
|
957
|
+
var getBrokerAdapter = (host, broker) => {
|
|
958
|
+
let _symbolInfo;
|
|
959
|
+
const getOrderCombinationType = (orderType) => {
|
|
960
|
+
return [
|
|
961
|
+
null,
|
|
962
|
+
"limit",
|
|
963
|
+
"MARKET" /* MARKET */,
|
|
964
|
+
"STOP_MARKET" /* STOP_MARKET */,
|
|
965
|
+
"STOP_LIMIT" /* STOP_LIMIT */
|
|
966
|
+
][orderType];
|
|
967
|
+
};
|
|
968
|
+
return {
|
|
969
|
+
symbolInfo: async (symbol2) => {
|
|
970
|
+
_symbolInfo = broker.getSymbolInfo(withoutExchangePrefix(symbol2));
|
|
971
|
+
return {
|
|
972
|
+
qty: {
|
|
973
|
+
min: _symbolInfo?.baseMin ?? 0,
|
|
974
|
+
max: _symbolInfo?.baseMax ?? 0,
|
|
975
|
+
step: _symbolInfo?.baseTick ?? 0
|
|
976
|
+
},
|
|
977
|
+
pipValue: 0,
|
|
978
|
+
pipSize: _symbolInfo?.quoteTick ?? 0,
|
|
979
|
+
minTick: _symbolInfo?.quoteTick ?? 0,
|
|
980
|
+
description: ""
|
|
981
|
+
};
|
|
982
|
+
},
|
|
983
|
+
placeOrder: async (order) => {
|
|
984
|
+
const side = ["SELL" /* SELL */, "BUY" /* BUY */][+(order.side > 0)];
|
|
985
|
+
const quantity = order.qty.toString();
|
|
986
|
+
(order.limitPrice ?? 0).toString();
|
|
987
|
+
(order.stopPrice ?? 0).toString();
|
|
988
|
+
const symbol2 = withoutExchangePrefix(order.symbol);
|
|
989
|
+
const orderCombinationType = getOrderCombinationType(order.type);
|
|
990
|
+
if (orderCombinationType === "MARKET" /* MARKET */) {
|
|
991
|
+
broker.sendMarketOrder({ side, order_quantity: quantity, symbol: symbol2, order_type: orderlyTypes.OrderType.MARKET });
|
|
992
|
+
}
|
|
993
|
+
},
|
|
994
|
+
orders: () => [],
|
|
995
|
+
positions: () => [],
|
|
996
|
+
executions: () => [],
|
|
997
|
+
connectionStatus: () => 1,
|
|
998
|
+
chartContextMenuActions: (context) => host.defaultContextMenuActions(context),
|
|
999
|
+
isTradable: async () => true,
|
|
1000
|
+
accountManagerInfo: () => ({}),
|
|
1001
|
+
currentAccount: () => "1",
|
|
1002
|
+
accountsMetainfo: async () => [{ id: "1" }],
|
|
1003
|
+
remove: () => host?.silentOrdersPlacement().unsubscribe()
|
|
1004
|
+
};
|
|
1005
|
+
};
|
|
1006
|
+
var getBrokerAdapter_default = getBrokerAdapter;
|
|
1007
|
+
function logMessage(message) {
|
|
1008
|
+
}
|
|
1009
|
+
function getErrorMessage(error) {
|
|
1010
|
+
if (error === void 0) {
|
|
1011
|
+
return "";
|
|
1012
|
+
}
|
|
1013
|
+
if (typeof error === "string") {
|
|
1014
|
+
return error;
|
|
1015
|
+
}
|
|
1016
|
+
return error.message;
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
// src/tradingviewAdapter/datafeed/history-provider.ts
|
|
1020
|
+
var HISTORY_PATH = "tv/history";
|
|
1021
|
+
var KLINE_HISTORY_PATH = "v1/tv/kline_history";
|
|
1022
|
+
var _HistoryProvider = class _HistoryProvider {
|
|
1023
|
+
constructor(datafeedUrl, requester, limitedServerResponse) {
|
|
1024
|
+
this._klinePreference = /* @__PURE__ */ new Map();
|
|
1025
|
+
this._datafeedUrl = datafeedUrl;
|
|
1026
|
+
this._requester = requester;
|
|
1027
|
+
this._limitedServerResponse = limitedServerResponse;
|
|
1028
|
+
}
|
|
1029
|
+
/**
|
|
1030
|
+
* Build request parameters for history API calls
|
|
1031
|
+
* @param symbolInfo - Symbol information
|
|
1032
|
+
* @param resolution - Resolution string
|
|
1033
|
+
* @param periodParams - Period parameters with optional countback
|
|
1034
|
+
* @returns Request parameters object
|
|
1035
|
+
*/
|
|
1036
|
+
_buildRequestParams(symbolInfo, resolution, periodParams) {
|
|
1037
|
+
const requestParams = {
|
|
1038
|
+
symbol: symbolInfo.ticker || "",
|
|
1039
|
+
resolution,
|
|
1040
|
+
from: periodParams.from,
|
|
1041
|
+
to: periodParams.to
|
|
1042
|
+
};
|
|
1043
|
+
const countBack = Math.min(periodParams.countBack ?? 0, 1e3);
|
|
1044
|
+
if (periodParams.countBack !== void 0) {
|
|
1045
|
+
requestParams.countback = countBack;
|
|
1046
|
+
}
|
|
1047
|
+
if (symbolInfo.currency_code !== void 0) {
|
|
1048
|
+
requestParams.currencyCode = symbolInfo.currency_code;
|
|
1049
|
+
}
|
|
1050
|
+
if (symbolInfo.unit_id !== void 0) {
|
|
1051
|
+
requestParams.unitId = symbolInfo.unit_id;
|
|
1052
|
+
}
|
|
1053
|
+
return requestParams;
|
|
1054
|
+
}
|
|
1055
|
+
getBars(symbolInfo, resolution, periodParams) {
|
|
1056
|
+
const requestParams = this._buildRequestParams(
|
|
1057
|
+
symbolInfo,
|
|
1058
|
+
resolution,
|
|
1059
|
+
periodParams
|
|
1060
|
+
);
|
|
1061
|
+
const preferenceKey = this._getPreferenceKey(symbolInfo, resolution);
|
|
1062
|
+
const prefersKline = this._klinePreference.get(preferenceKey) === true;
|
|
1063
|
+
const countBack = Math.min(periodParams.countBack ?? 0, 1e3);
|
|
1064
|
+
return new Promise(
|
|
1065
|
+
async (resolve, reject) => {
|
|
1066
|
+
try {
|
|
1067
|
+
let result;
|
|
1068
|
+
let usedHistoryResult = false;
|
|
1069
|
+
if (prefersKline) {
|
|
1070
|
+
result = await this._requestKlineHistory(
|
|
1071
|
+
this._buildKlineParams(requestParams, countBack)
|
|
1072
|
+
);
|
|
1073
|
+
} else {
|
|
1074
|
+
const initialResponse = await this._requestHistory(requestParams);
|
|
1075
|
+
result = this._processHistoryResponse(initialResponse);
|
|
1076
|
+
usedHistoryResult = true;
|
|
1077
|
+
const needsFallback = this._shouldFallbackToKline(
|
|
1078
|
+
initialResponse,
|
|
1079
|
+
countBack
|
|
1080
|
+
);
|
|
1081
|
+
if (needsFallback) {
|
|
1082
|
+
const klineResult = await this._tryKlineFallback(
|
|
1083
|
+
requestParams,
|
|
1084
|
+
countBack
|
|
1085
|
+
);
|
|
1086
|
+
if (klineResult !== null) {
|
|
1087
|
+
result = klineResult;
|
|
1088
|
+
usedHistoryResult = false;
|
|
1089
|
+
this._klinePreference.set(preferenceKey, true);
|
|
1090
|
+
} else {
|
|
1091
|
+
this._klinePreference.set(preferenceKey, false);
|
|
1092
|
+
}
|
|
1093
|
+
} else {
|
|
1094
|
+
this._klinePreference.set(preferenceKey, false);
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
if (usedHistoryResult && this._limitedServerResponse) {
|
|
1098
|
+
await this._processTruncatedResponse(result, { ...requestParams });
|
|
1099
|
+
}
|
|
1100
|
+
resolve(result);
|
|
1101
|
+
} catch (e) {
|
|
1102
|
+
const error = e instanceof Error ? e : typeof e === "string" ? e : void 0;
|
|
1103
|
+
const reasonString = getErrorMessage(error);
|
|
1104
|
+
reject(reasonString || "Error");
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
);
|
|
1108
|
+
}
|
|
1109
|
+
/**
|
|
1110
|
+
* Request kline history using KLINE_HISTORY_PATH endpoint
|
|
1111
|
+
* Handles rate limiting (429 errors) by waiting and retrying
|
|
1112
|
+
* @param requestParams - Request parameters
|
|
1113
|
+
* @param retryCount - Current retry attempt (internal use)
|
|
1114
|
+
* @returns Processed history response
|
|
1115
|
+
*/
|
|
1116
|
+
async _requestKlineHistory(requestParams, retryCount = 0) {
|
|
1117
|
+
const maxRetries = 5;
|
|
1118
|
+
const baseRetryDelay = 2500;
|
|
1119
|
+
const maxRetryDelay = 1e4;
|
|
1120
|
+
const params = {
|
|
1121
|
+
...requestParams,
|
|
1122
|
+
resolution: this._mapToKlineHistoryResolution(
|
|
1123
|
+
requestParams.resolution
|
|
1124
|
+
)
|
|
1125
|
+
};
|
|
1126
|
+
const urlPath = this._buildUrlWithParams(KLINE_HISTORY_PATH, params);
|
|
1127
|
+
const options = { credentials: "same-origin" };
|
|
1128
|
+
const requesterWithHeaders = this._requester;
|
|
1129
|
+
if (requesterWithHeaders._headers !== void 0) {
|
|
1130
|
+
options.headers = requesterWithHeaders._headers;
|
|
1131
|
+
}
|
|
1132
|
+
let response;
|
|
1133
|
+
try {
|
|
1134
|
+
response = await fetch(`${this._datafeedUrl}/${urlPath}`, options);
|
|
1135
|
+
} catch (error) {
|
|
1136
|
+
throw error;
|
|
1137
|
+
}
|
|
1138
|
+
if (response.status === 429) {
|
|
1139
|
+
if (retryCount >= maxRetries) {
|
|
1140
|
+
throw new Error(
|
|
1141
|
+
`Rate limit exceeded: Maximum retry attempts (${maxRetries}) reached`
|
|
1142
|
+
);
|
|
1143
|
+
}
|
|
1144
|
+
const retryDelay = Math.min(
|
|
1145
|
+
baseRetryDelay * Math.pow(2, retryCount),
|
|
1146
|
+
maxRetryDelay
|
|
1147
|
+
);
|
|
1148
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
1149
|
+
const delay = retryAfter ? parseInt(retryAfter, 10) * 1e3 : retryDelay;
|
|
1150
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1151
|
+
return this._requestKlineHistory(requestParams, retryCount + 1);
|
|
1152
|
+
}
|
|
1153
|
+
if (!response.ok) {
|
|
1154
|
+
const errorData = await response.json().catch(() => ({
|
|
1155
|
+
message: response.statusText
|
|
1156
|
+
}));
|
|
1157
|
+
throw new Error(
|
|
1158
|
+
errorData.message || errorData.errmsg || response.statusText
|
|
1159
|
+
);
|
|
1160
|
+
}
|
|
1161
|
+
let data;
|
|
1162
|
+
try {
|
|
1163
|
+
data = await response.json();
|
|
1164
|
+
} catch {
|
|
1165
|
+
throw new Error("Failed to parse response JSON");
|
|
1166
|
+
}
|
|
1167
|
+
return this._processHistoryResponse(data);
|
|
1168
|
+
}
|
|
1169
|
+
/**
|
|
1170
|
+
* Process truncated response by making follow-up requests if needed
|
|
1171
|
+
* @param result - Current result with bars
|
|
1172
|
+
* @param requestParams - Request parameters
|
|
1173
|
+
*/
|
|
1174
|
+
async _processTruncatedResponse(result, requestParams) {
|
|
1175
|
+
let lastResultLength = result.bars.length;
|
|
1176
|
+
try {
|
|
1177
|
+
while (this._limitedServerResponse && this._limitedServerResponse.maxResponseLength > 0 && this._limitedServerResponse.maxResponseLength === lastResultLength && requestParams.from < requestParams.to) {
|
|
1178
|
+
if (requestParams.countback) {
|
|
1179
|
+
requestParams.countback = requestParams.countback - lastResultLength;
|
|
1180
|
+
}
|
|
1181
|
+
if (this._limitedServerResponse.expectedOrder === "earliestFirst") {
|
|
1182
|
+
requestParams.from = Math.round(
|
|
1183
|
+
result.bars[result.bars.length - 1].time / 1e3
|
|
1184
|
+
);
|
|
1185
|
+
} else {
|
|
1186
|
+
requestParams.to = Math.round(result.bars[0].time / 1e3);
|
|
1187
|
+
}
|
|
1188
|
+
const followupResponse = await this._requester.sendRequest(
|
|
1189
|
+
this._datafeedUrl,
|
|
1190
|
+
HISTORY_PATH,
|
|
1191
|
+
requestParams
|
|
1192
|
+
);
|
|
1193
|
+
const followupResult = this._processHistoryResponse(followupResponse);
|
|
1194
|
+
lastResultLength = followupResult.bars.length;
|
|
1195
|
+
if (this._limitedServerResponse.expectedOrder === "earliestFirst") {
|
|
1196
|
+
if (followupResult.bars[0].time === result.bars[result.bars.length - 1].time) {
|
|
1197
|
+
followupResult.bars.shift();
|
|
1198
|
+
}
|
|
1199
|
+
result.bars.push(...followupResult.bars);
|
|
1200
|
+
} else {
|
|
1201
|
+
if (followupResult.bars[followupResult.bars.length - 1].time === result.bars[0].time) {
|
|
1202
|
+
followupResult.bars.pop();
|
|
1203
|
+
}
|
|
1204
|
+
result.bars.unshift(...followupResult.bars);
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
} catch (e) {
|
|
1208
|
+
if (e instanceof Error || typeof e === "string") {
|
|
1209
|
+
getErrorMessage(e);
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
_processHistoryResponse(response) {
|
|
1214
|
+
if (response.s !== "ok" && response.s !== "no_data") {
|
|
1215
|
+
throw new Error(response.errmsg);
|
|
1216
|
+
}
|
|
1217
|
+
const bars = [];
|
|
1218
|
+
const meta = {
|
|
1219
|
+
noData: false
|
|
1220
|
+
};
|
|
1221
|
+
if (response.s === "no_data") {
|
|
1222
|
+
meta.noData = true;
|
|
1223
|
+
meta.nextTime = response.nextTime;
|
|
1224
|
+
} else {
|
|
1225
|
+
const volumePresent = response.v !== void 0;
|
|
1226
|
+
const ohlPresent = response.o !== void 0;
|
|
1227
|
+
for (let i = 0; i < response.t.length; ++i) {
|
|
1228
|
+
const barValue = {
|
|
1229
|
+
time: response.t[i] * 1e3,
|
|
1230
|
+
close: parseFloat(response.c[i]),
|
|
1231
|
+
open: parseFloat(response.c[i]),
|
|
1232
|
+
high: parseFloat(response.c[i]),
|
|
1233
|
+
low: parseFloat(response.c[i])
|
|
1234
|
+
};
|
|
1235
|
+
if (ohlPresent) {
|
|
1236
|
+
barValue.open = parseFloat(
|
|
1237
|
+
response.o[i]
|
|
1238
|
+
);
|
|
1239
|
+
barValue.high = parseFloat(
|
|
1240
|
+
response.h[i]
|
|
1241
|
+
);
|
|
1242
|
+
barValue.low = parseFloat(response.l[i]);
|
|
1243
|
+
}
|
|
1244
|
+
if (volumePresent) {
|
|
1245
|
+
const volume = parseFloat(response.v[i]);
|
|
1246
|
+
if (volume > 0) {
|
|
1247
|
+
barValue.volume = volume;
|
|
1248
|
+
} else {
|
|
1249
|
+
barValue.volume = 1e-10;
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
bars.push(barValue);
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
return {
|
|
1256
|
+
bars,
|
|
1257
|
+
meta
|
|
1258
|
+
};
|
|
1259
|
+
}
|
|
1260
|
+
/**
|
|
1261
|
+
* Maps TradingView resolution format to Kline History API resolution format
|
|
1262
|
+
* @param resolution - TradingView resolution string (e.g., "1", "60", "1D")
|
|
1263
|
+
* @returns Kline History API resolution string (e.g., "1m", "1h", "1d")
|
|
1264
|
+
*/
|
|
1265
|
+
_mapToKlineHistoryResolution(resolution) {
|
|
1266
|
+
return _HistoryProvider._RESOLUTION_MAP.get(resolution) ?? resolution;
|
|
1267
|
+
}
|
|
1268
|
+
_buildUrlWithParams(path, params) {
|
|
1269
|
+
if (!params || Object.keys(params).length === 0) {
|
|
1270
|
+
return path;
|
|
1271
|
+
}
|
|
1272
|
+
const searchParams = new URLSearchParams();
|
|
1273
|
+
Object.keys(params).forEach((key) => {
|
|
1274
|
+
const value = params[key];
|
|
1275
|
+
if (Array.isArray(value)) {
|
|
1276
|
+
value.forEach((item) => searchParams.append(key, item));
|
|
1277
|
+
} else {
|
|
1278
|
+
searchParams.append(key, value.toString());
|
|
1279
|
+
}
|
|
1280
|
+
});
|
|
1281
|
+
const queryString = searchParams.toString();
|
|
1282
|
+
return queryString ? `${path}?${queryString}` : path;
|
|
1283
|
+
}
|
|
1284
|
+
_getPreferenceKey(symbolInfo, resolution) {
|
|
1285
|
+
return `${symbolInfo.ticker ?? ""}|${resolution}`;
|
|
1286
|
+
}
|
|
1287
|
+
_requestHistory(requestParams) {
|
|
1288
|
+
return this._requester.sendRequest(
|
|
1289
|
+
this._datafeedUrl,
|
|
1290
|
+
HISTORY_PATH,
|
|
1291
|
+
requestParams
|
|
1292
|
+
);
|
|
1293
|
+
}
|
|
1294
|
+
_buildKlineParams(requestParams, countBack) {
|
|
1295
|
+
const params = {
|
|
1296
|
+
...requestParams
|
|
1297
|
+
};
|
|
1298
|
+
delete params.countback;
|
|
1299
|
+
if (countBack > 0) {
|
|
1300
|
+
params.limit = countBack;
|
|
1301
|
+
} else {
|
|
1302
|
+
delete params.limit;
|
|
1303
|
+
}
|
|
1304
|
+
return params;
|
|
1305
|
+
}
|
|
1306
|
+
async _tryKlineFallback(requestParams, countBack) {
|
|
1307
|
+
try {
|
|
1308
|
+
const result = await this._requestKlineHistory(
|
|
1309
|
+
this._buildKlineParams(requestParams, countBack)
|
|
1310
|
+
);
|
|
1311
|
+
return result.bars.length > 0 ? result : null;
|
|
1312
|
+
} catch {
|
|
1313
|
+
return null;
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
_shouldFallbackToKline(response, expectedCount) {
|
|
1317
|
+
if (response.s !== "ok") {
|
|
1318
|
+
return false;
|
|
1319
|
+
}
|
|
1320
|
+
const barsCount = response.t.length;
|
|
1321
|
+
if (expectedCount > 0 && barsCount < expectedCount) {
|
|
1322
|
+
return true;
|
|
1323
|
+
}
|
|
1324
|
+
if (this._limitedServerResponse && this._limitedServerResponse.maxResponseLength > 0 && barsCount >= this._limitedServerResponse.maxResponseLength) {
|
|
1325
|
+
return true;
|
|
1326
|
+
}
|
|
1327
|
+
return false;
|
|
1328
|
+
}
|
|
1329
|
+
};
|
|
1330
|
+
/**
|
|
1331
|
+
* Static mapping table for resolution conversion
|
|
1332
|
+
* Maps TradingView resolution format to Kline History API resolution format
|
|
1333
|
+
* Key: TradingView resolution, Value: Kline History API resolution
|
|
1334
|
+
*/
|
|
1335
|
+
_HistoryProvider._RESOLUTION_MAP = /* @__PURE__ */ new Map([
|
|
1336
|
+
["1", "1m"],
|
|
1337
|
+
// 1 minute
|
|
1338
|
+
["3", "3m"],
|
|
1339
|
+
// 3 minutes
|
|
1340
|
+
["5", "5m"],
|
|
1341
|
+
// 5 minutes
|
|
1342
|
+
["15", "15m"],
|
|
1343
|
+
// 15 minutes
|
|
1344
|
+
["30", "30m"],
|
|
1345
|
+
// 30 minutes
|
|
1346
|
+
["60", "1h"],
|
|
1347
|
+
// 1 hour
|
|
1348
|
+
["240", "4h"],
|
|
1349
|
+
// 4 hours
|
|
1350
|
+
["720", "12h"],
|
|
1351
|
+
// 12 hours
|
|
1352
|
+
["1D", "1d"],
|
|
1353
|
+
// 1 day
|
|
1354
|
+
["1W", "1w"],
|
|
1355
|
+
// 1 week
|
|
1356
|
+
["1M", "1mon"]
|
|
1357
|
+
// 1 month (mapped to 1m)
|
|
1358
|
+
]);
|
|
1359
|
+
var HistoryProvider = _HistoryProvider;
|
|
1360
|
+
|
|
1361
|
+
// src/tradingviewAdapter/datafeed/requester.ts
|
|
1362
|
+
var Requester = class {
|
|
1363
|
+
constructor(headers) {
|
|
1364
|
+
if (headers) {
|
|
1365
|
+
this._headers = headers;
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
sendRequest(datafeedUrl, urlPath, params) {
|
|
1369
|
+
if (params !== void 0) {
|
|
1370
|
+
const paramKeys = Object.keys(params);
|
|
1371
|
+
if (paramKeys.length !== 0) {
|
|
1372
|
+
urlPath += "?";
|
|
1373
|
+
}
|
|
1374
|
+
urlPath += paramKeys.map((key) => {
|
|
1375
|
+
return `${encodeURIComponent(key)}=${encodeURIComponent(
|
|
1376
|
+
params[key].toString()
|
|
1377
|
+
)}`;
|
|
1378
|
+
}).join("&");
|
|
1379
|
+
}
|
|
1380
|
+
const options = { credentials: "same-origin" };
|
|
1381
|
+
if (this._headers !== void 0) {
|
|
1382
|
+
options.headers = this._headers;
|
|
1383
|
+
}
|
|
1384
|
+
return fetch(`${datafeedUrl}/${urlPath}`, options).then((response) => response.json()).then((data) => {
|
|
1385
|
+
if (typeof data.success === "undefined") {
|
|
1386
|
+
return data;
|
|
1387
|
+
}
|
|
1388
|
+
if (!data.success) {
|
|
1389
|
+
throw new Error(data.message);
|
|
1390
|
+
}
|
|
1391
|
+
return data;
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1394
|
+
};
|
|
1395
|
+
|
|
1396
|
+
// src/tradingviewAdapter/datafeed/symbol-storage.ts
|
|
1397
|
+
function extractField(data, field, arrayIndex, valueIsArray) {
|
|
1398
|
+
const value = data[field];
|
|
1399
|
+
if (Array.isArray(value) && (!valueIsArray || Array.isArray(value[0]))) {
|
|
1400
|
+
return value[arrayIndex];
|
|
1401
|
+
}
|
|
1402
|
+
return value;
|
|
1403
|
+
}
|
|
1404
|
+
function symbolKey(symbol, currency, unit) {
|
|
1405
|
+
return symbol + (currency !== void 0 ? "_%|#|%_" + currency : "") + (unit !== void 0 ? "_%|#|%_" + unit : "");
|
|
1406
|
+
}
|
|
1407
|
+
var SymbolsStorage = class {
|
|
1408
|
+
constructor(datafeedUrl, datafeedSupportedResolutions, requester) {
|
|
1409
|
+
this._exchangesList = ["Orderly"];
|
|
1410
|
+
this._symbolsInfo = {};
|
|
1411
|
+
this._symbolsList = [];
|
|
1412
|
+
this._datafeedUrl = datafeedUrl;
|
|
1413
|
+
this._datafeedSupportedResolutions = datafeedSupportedResolutions;
|
|
1414
|
+
this._requester = requester;
|
|
1415
|
+
this._readyPromise = this._init();
|
|
1416
|
+
this._readyPromise.catch((error) => {
|
|
1417
|
+
});
|
|
1418
|
+
}
|
|
1419
|
+
// BEWARE: this function does not consider symbol's exchange
|
|
1420
|
+
resolveSymbol(symbolName, currencyCode, unitId) {
|
|
1421
|
+
return this._readyPromise.then(() => {
|
|
1422
|
+
const symbolInfo = this._symbolsInfo[symbolKey(symbolName, currencyCode, unitId)];
|
|
1423
|
+
if (symbolInfo === void 0) {
|
|
1424
|
+
return Promise.reject("invalid symbol");
|
|
1425
|
+
}
|
|
1426
|
+
return Promise.resolve(symbolInfo);
|
|
1427
|
+
});
|
|
1428
|
+
}
|
|
1429
|
+
searchSymbols(searchString, exchange, symbolType, maxSearchResults) {
|
|
1430
|
+
return this._readyPromise.then(() => {
|
|
1431
|
+
const weightedResult = [];
|
|
1432
|
+
const queryIsEmpty = searchString.length === 0;
|
|
1433
|
+
searchString = searchString.toUpperCase();
|
|
1434
|
+
for (const symbolName of this._symbolsList) {
|
|
1435
|
+
const symbolInfo = this._symbolsInfo[symbolName];
|
|
1436
|
+
if (symbolInfo === void 0) {
|
|
1437
|
+
continue;
|
|
1438
|
+
}
|
|
1439
|
+
if (symbolType.length > 0 && symbolInfo.type !== symbolType) {
|
|
1440
|
+
continue;
|
|
1441
|
+
}
|
|
1442
|
+
if (exchange && exchange.length > 0 && symbolInfo.exchange !== exchange) {
|
|
1443
|
+
continue;
|
|
1444
|
+
}
|
|
1445
|
+
const positionInName = symbolInfo.name.toUpperCase().indexOf(searchString);
|
|
1446
|
+
const positionInDescription = symbolInfo.description.toUpperCase().indexOf(searchString);
|
|
1447
|
+
if (queryIsEmpty || positionInName >= 0 || positionInDescription >= 0) {
|
|
1448
|
+
const alreadyExists = weightedResult.some(
|
|
1449
|
+
(item) => item.symbolInfo === symbolInfo
|
|
1450
|
+
);
|
|
1451
|
+
if (!alreadyExists) {
|
|
1452
|
+
const weight = positionInName >= 0 ? positionInName : 8e3 + positionInDescription;
|
|
1453
|
+
weightedResult.push({ symbolInfo, weight });
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
const result = weightedResult.sort(
|
|
1458
|
+
(item1, item2) => item1.weight - item2.weight
|
|
1459
|
+
).slice(0, maxSearchResults).map((item) => {
|
|
1460
|
+
const symbolInfo = item.symbolInfo;
|
|
1461
|
+
return {
|
|
1462
|
+
symbol: symbolInfo.name,
|
|
1463
|
+
full_name: `${symbolInfo.exchange}:${symbolInfo.name}`,
|
|
1464
|
+
description: symbolInfo.description,
|
|
1465
|
+
exchange: symbolInfo.exchange,
|
|
1466
|
+
params: [],
|
|
1467
|
+
type: symbolInfo.type,
|
|
1468
|
+
ticker: symbolInfo.name
|
|
1469
|
+
};
|
|
1470
|
+
});
|
|
1471
|
+
return Promise.resolve(result);
|
|
1472
|
+
});
|
|
1473
|
+
}
|
|
1474
|
+
_init() {
|
|
1475
|
+
const promises = [];
|
|
1476
|
+
const alreadyRequestedExchanges = {};
|
|
1477
|
+
for (const exchange of this._exchangesList) {
|
|
1478
|
+
if (alreadyRequestedExchanges[exchange]) {
|
|
1479
|
+
continue;
|
|
1480
|
+
}
|
|
1481
|
+
alreadyRequestedExchanges[exchange] = true;
|
|
1482
|
+
promises.push(this._requestExchangeData(exchange));
|
|
1483
|
+
}
|
|
1484
|
+
return Promise.all(promises).then(() => {
|
|
1485
|
+
this._symbolsList.sort();
|
|
1486
|
+
});
|
|
1487
|
+
}
|
|
1488
|
+
_requestExchangeData(exchange) {
|
|
1489
|
+
return new Promise(
|
|
1490
|
+
(resolve, reject) => {
|
|
1491
|
+
this._requester.sendRequest(
|
|
1492
|
+
this._datafeedUrl,
|
|
1493
|
+
"tv/symbol_info",
|
|
1494
|
+
{
|
|
1495
|
+
group: exchange
|
|
1496
|
+
}
|
|
1497
|
+
).then((response) => {
|
|
1498
|
+
try {
|
|
1499
|
+
this._onExchangeDataReceived(exchange, response);
|
|
1500
|
+
} catch (error) {
|
|
1501
|
+
reject(
|
|
1502
|
+
error instanceof Error ? error : new Error(`SymbolsStorage: Unexpected exception ${error}`)
|
|
1503
|
+
);
|
|
1504
|
+
return;
|
|
1505
|
+
}
|
|
1506
|
+
resolve();
|
|
1507
|
+
}).catch((reason) => {
|
|
1508
|
+
logMessage(
|
|
1509
|
+
`SymbolsStorage: Request data for exchange '${exchange}' failed, reason=${getErrorMessage(
|
|
1510
|
+
reason
|
|
1511
|
+
)}`
|
|
1512
|
+
);
|
|
1513
|
+
resolve();
|
|
1514
|
+
});
|
|
1515
|
+
}
|
|
1516
|
+
);
|
|
1517
|
+
}
|
|
1518
|
+
_onExchangeDataReceived(exchange, data) {
|
|
1519
|
+
let symbolIndex = 0;
|
|
1520
|
+
try {
|
|
1521
|
+
const symbolsCount = data.symbol.length;
|
|
1522
|
+
const tickerPresent = data.ticker !== void 0;
|
|
1523
|
+
for (; symbolIndex < symbolsCount; ++symbolIndex) {
|
|
1524
|
+
const symbolName = data.symbol[symbolIndex];
|
|
1525
|
+
const listedExchange = extractField(
|
|
1526
|
+
data,
|
|
1527
|
+
"exchange-listed",
|
|
1528
|
+
symbolIndex
|
|
1529
|
+
);
|
|
1530
|
+
const tradedExchange = extractField(
|
|
1531
|
+
data,
|
|
1532
|
+
"exchange-traded",
|
|
1533
|
+
symbolIndex
|
|
1534
|
+
);
|
|
1535
|
+
const fullName = tradedExchange + ":" + symbolName;
|
|
1536
|
+
const currencyCode = extractField(data, "currency-code", symbolIndex);
|
|
1537
|
+
const unitId = extractField(data, "unit-id", symbolIndex);
|
|
1538
|
+
const ticker = tickerPresent ? extractField(data, "ticker", symbolIndex) : symbolName;
|
|
1539
|
+
const symbolInfo = {
|
|
1540
|
+
ticker,
|
|
1541
|
+
name: symbolName,
|
|
1542
|
+
base_name: [listedExchange + ":" + symbolName],
|
|
1543
|
+
listed_exchange: listedExchange,
|
|
1544
|
+
exchange: tradedExchange,
|
|
1545
|
+
currency_code: currencyCode,
|
|
1546
|
+
original_currency_code: extractField(
|
|
1547
|
+
data,
|
|
1548
|
+
"original-currency-code",
|
|
1549
|
+
symbolIndex
|
|
1550
|
+
),
|
|
1551
|
+
unit_id: unitId,
|
|
1552
|
+
original_unit_id: extractField(data, "original-unit-id", symbolIndex),
|
|
1553
|
+
unit_conversion_types: extractField(
|
|
1554
|
+
data,
|
|
1555
|
+
"unit-conversion-types",
|
|
1556
|
+
symbolIndex,
|
|
1557
|
+
true
|
|
1558
|
+
),
|
|
1559
|
+
description: extractField(data, "description", symbolIndex),
|
|
1560
|
+
has_intraday: definedValueOrDefault(
|
|
1561
|
+
extractField(data, "has-intraday", symbolIndex),
|
|
1562
|
+
false
|
|
1563
|
+
),
|
|
1564
|
+
// show volume at the bottom by default: https://github.com/tradingview/charting_library/issues/8306
|
|
1565
|
+
visible_plots_set: definedValueOrDefault(
|
|
1566
|
+
extractField(data, "visible-plots-set", symbolIndex),
|
|
1567
|
+
"ohlcv"
|
|
1568
|
+
),
|
|
1569
|
+
minmov: extractField(data, "minmovement", symbolIndex) || extractField(data, "minmov", symbolIndex) || 0,
|
|
1570
|
+
minmove2: extractField(data, "minmove2", symbolIndex) || extractField(data, "minmov2", symbolIndex),
|
|
1571
|
+
fractional: extractField(data, "fractional", symbolIndex),
|
|
1572
|
+
pricescale: extractField(data, "pricescale", symbolIndex),
|
|
1573
|
+
type: extractField(data, "type", symbolIndex),
|
|
1574
|
+
session: extractField(data, "session-regular", symbolIndex),
|
|
1575
|
+
session_holidays: extractField(data, "session-holidays", symbolIndex),
|
|
1576
|
+
corrections: extractField(data, "corrections", symbolIndex),
|
|
1577
|
+
timezone: extractField(data, "timezone", symbolIndex),
|
|
1578
|
+
supported_resolutions: definedValueOrDefault(
|
|
1579
|
+
extractField(data, "supported-resolutions", symbolIndex, true),
|
|
1580
|
+
this._datafeedSupportedResolutions
|
|
1581
|
+
),
|
|
1582
|
+
has_daily: definedValueOrDefault(
|
|
1583
|
+
extractField(data, "has-daily", symbolIndex),
|
|
1584
|
+
true
|
|
1585
|
+
),
|
|
1586
|
+
intraday_multipliers: definedValueOrDefault(
|
|
1587
|
+
extractField(data, "intraday-multipliers", symbolIndex, true),
|
|
1588
|
+
["1", "5", "15", "30", "60"]
|
|
1589
|
+
),
|
|
1590
|
+
// daily_multipliers:["1"],
|
|
1591
|
+
// has_weekly_and_monthly: extractField(
|
|
1592
|
+
// data,
|
|
1593
|
+
// "has-weekly-and-monthly",
|
|
1594
|
+
// symbolIndex,
|
|
1595
|
+
// ),
|
|
1596
|
+
has_weekly_and_monthly: true,
|
|
1597
|
+
has_empty_bars: extractField(data, "has-empty-bars", symbolIndex),
|
|
1598
|
+
volume_precision: definedValueOrDefault(
|
|
1599
|
+
extractField(data, "volume-precision", symbolIndex),
|
|
1600
|
+
0
|
|
1601
|
+
),
|
|
1602
|
+
format: "price"
|
|
1603
|
+
};
|
|
1604
|
+
this._symbolsInfo[ticker] = symbolInfo;
|
|
1605
|
+
this._symbolsInfo[symbolName] = symbolInfo;
|
|
1606
|
+
this._symbolsInfo[fullName] = symbolInfo;
|
|
1607
|
+
if (currencyCode !== void 0 || unitId !== void 0) {
|
|
1608
|
+
this._symbolsInfo[symbolKey(ticker, currencyCode, unitId)] = symbolInfo;
|
|
1609
|
+
this._symbolsInfo[symbolKey(symbolName, currencyCode, unitId)] = symbolInfo;
|
|
1610
|
+
this._symbolsInfo[symbolKey(fullName, currencyCode, unitId)] = symbolInfo;
|
|
1611
|
+
}
|
|
1612
|
+
this._symbolsList.push(symbolName);
|
|
1613
|
+
}
|
|
1614
|
+
} catch (error) {
|
|
1615
|
+
throw new Error(
|
|
1616
|
+
`SymbolsStorage: API error when processing exchange ${exchange} symbol #${symbolIndex} (${data.symbol[symbolIndex]}): ${Object(error).message}`
|
|
1617
|
+
);
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
};
|
|
1621
|
+
function definedValueOrDefault(value, defaultValue) {
|
|
1622
|
+
return value !== void 0 ? value : defaultValue;
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
// src/tradingviewAdapter/datafeed/abstract-datafeed.ts
|
|
1626
|
+
var AbstractDatafeed = class {
|
|
1627
|
+
constructor(datafeedURL) {
|
|
1628
|
+
this._configuration = defaultConfiguration();
|
|
1629
|
+
this._symbolsStorage = null;
|
|
1630
|
+
this._historyCursor = null;
|
|
1631
|
+
this._datafeedURL = datafeedURL;
|
|
1632
|
+
this._requester = new Requester();
|
|
1633
|
+
this._historyProvider = new HistoryProvider(datafeedURL, this._requester);
|
|
1634
|
+
this._configurationReadyPromise = this._requestConfiguration().then(
|
|
1635
|
+
(configuration) => {
|
|
1636
|
+
if (configuration === null) {
|
|
1637
|
+
configuration = defaultConfiguration();
|
|
1638
|
+
}
|
|
1639
|
+
this._setupWithConfiguration(configuration);
|
|
1640
|
+
}
|
|
1641
|
+
);
|
|
1642
|
+
}
|
|
1643
|
+
getBars(symbolInfo, resolution, periodParams, onResult, onError) {
|
|
1644
|
+
const { to, firstDataRequest } = periodParams;
|
|
1645
|
+
if (firstDataRequest || this._historyCursor === null) {
|
|
1646
|
+
this._historyCursor = to;
|
|
1647
|
+
}
|
|
1648
|
+
const resolutionInSeconds = this._resolutionToSeconds(resolution);
|
|
1649
|
+
const cursor = this._historyCursor ?? to;
|
|
1650
|
+
const maxBarsPerRequest = 1e3;
|
|
1651
|
+
const shouldUseOriginalRange = resolution.toLowerCase?.() === "1m" && periodParams.from !== void 0;
|
|
1652
|
+
const barsToLoad = shouldUseOriginalRange ? periodParams.countBack ?? maxBarsPerRequest : maxBarsPerRequest;
|
|
1653
|
+
const requestTo = shouldUseOriginalRange ? periodParams.to ?? to : cursor;
|
|
1654
|
+
const requestFrom = shouldUseOriginalRange ? periodParams.from : Math.max(requestTo - resolutionInSeconds * barsToLoad, 0);
|
|
1655
|
+
this._historyProvider.getBars(symbolInfo, resolution, {
|
|
1656
|
+
...periodParams,
|
|
1657
|
+
countBack: barsToLoad,
|
|
1658
|
+
from: requestFrom,
|
|
1659
|
+
to: requestTo
|
|
1660
|
+
}).then(
|
|
1661
|
+
(result) => {
|
|
1662
|
+
if (result.bars.length > 0) {
|
|
1663
|
+
this._historyCursor = Math.floor(result.bars[0].time / 1e3) - 1;
|
|
1664
|
+
}
|
|
1665
|
+
onResult(result.bars, result.meta);
|
|
1666
|
+
},
|
|
1667
|
+
(error) => {
|
|
1668
|
+
onError(error);
|
|
1669
|
+
}
|
|
1670
|
+
).catch((error) => {
|
|
1671
|
+
onError(error);
|
|
1672
|
+
});
|
|
1673
|
+
}
|
|
1674
|
+
_resolutionToSeconds(resolution) {
|
|
1675
|
+
switch (resolution) {
|
|
1676
|
+
case "1D":
|
|
1677
|
+
return 86400;
|
|
1678
|
+
case "3D":
|
|
1679
|
+
return 86400 * 3;
|
|
1680
|
+
case "1W":
|
|
1681
|
+
return 86400 * 7;
|
|
1682
|
+
case "1M":
|
|
1683
|
+
return 86400 * 30;
|
|
1684
|
+
}
|
|
1685
|
+
const res = parseInt(resolution);
|
|
1686
|
+
if (!isNaN(res)) {
|
|
1687
|
+
return res * 60;
|
|
1688
|
+
}
|
|
1689
|
+
return 60;
|
|
1690
|
+
}
|
|
1691
|
+
onReady(callback) {
|
|
1692
|
+
this._configurationReadyPromise.then(() => {
|
|
1693
|
+
callback(this._configuration);
|
|
1694
|
+
});
|
|
1695
|
+
}
|
|
1696
|
+
searchSymbols(userInput, exchange, symbolType, onResult) {
|
|
1697
|
+
if (this._symbolsStorage === null) {
|
|
1698
|
+
throw new Error("Datafeed: inconsistent configuration (symbols storage)");
|
|
1699
|
+
}
|
|
1700
|
+
this._symbolsStorage.searchSymbols(
|
|
1701
|
+
userInput,
|
|
1702
|
+
exchange,
|
|
1703
|
+
symbolType,
|
|
1704
|
+
30 /* SearchItemsLimit */
|
|
1705
|
+
).then(onResult).catch(onResult.bind(null, []));
|
|
1706
|
+
}
|
|
1707
|
+
resolveSymbol(symbolName, onResolve, onError, extension) {
|
|
1708
|
+
const currencyCode = extension && extension.currencyCode;
|
|
1709
|
+
const unitId = extension && extension.unitId;
|
|
1710
|
+
function onResultReady(symbolInfo) {
|
|
1711
|
+
onResolve(symbolInfo);
|
|
1712
|
+
}
|
|
1713
|
+
if (this._symbolsStorage === null) {
|
|
1714
|
+
throw new Error("Datafeed: inconsistent configuration (symbols storage)");
|
|
1715
|
+
}
|
|
1716
|
+
this._symbolsStorage.resolveSymbol(symbolName, currencyCode, unitId).then(onResultReady).catch(onError);
|
|
1717
|
+
}
|
|
1718
|
+
getMarks() {
|
|
1719
|
+
}
|
|
1720
|
+
getTimescaleMarks() {
|
|
1721
|
+
}
|
|
1722
|
+
getServerTime() {
|
|
1723
|
+
}
|
|
1724
|
+
_requestConfiguration() {
|
|
1725
|
+
return this._send("tv/config").catch(
|
|
1726
|
+
(reason) => {
|
|
1727
|
+
logMessage(
|
|
1728
|
+
`Datafeed: Cannot get datafeed configuration - use default, error=${getErrorMessage(
|
|
1729
|
+
reason
|
|
1730
|
+
)}`
|
|
1731
|
+
);
|
|
1732
|
+
return null;
|
|
1733
|
+
}
|
|
1734
|
+
);
|
|
1735
|
+
}
|
|
1736
|
+
_send(urlPath, params) {
|
|
1737
|
+
return this._requester.sendRequest(this._datafeedURL, urlPath, params);
|
|
1738
|
+
}
|
|
1739
|
+
_setupWithConfiguration(configurationData) {
|
|
1740
|
+
this._configuration = configurationData;
|
|
1741
|
+
if (configurationData.exchanges === void 0) {
|
|
1742
|
+
configurationData.exchanges = [];
|
|
1743
|
+
}
|
|
1744
|
+
if (!configurationData.supports_search && !configurationData.supports_group_request) {
|
|
1745
|
+
throw new Error(
|
|
1746
|
+
"Unsupported datafeed configuration. Must either support search, or support group request"
|
|
1747
|
+
);
|
|
1748
|
+
}
|
|
1749
|
+
if (configurationData.supports_group_request || !configurationData.supports_search) {
|
|
1750
|
+
this._symbolsStorage = new SymbolsStorage(
|
|
1751
|
+
this._datafeedURL,
|
|
1752
|
+
configurationData.supported_resolutions || [],
|
|
1753
|
+
this._requester
|
|
1754
|
+
);
|
|
1755
|
+
}
|
|
1756
|
+
logMessage(
|
|
1757
|
+
`Datafeed: Initialized with ${JSON.stringify(configurationData)}`
|
|
1758
|
+
);
|
|
1759
|
+
}
|
|
1760
|
+
};
|
|
1761
|
+
function defaultConfiguration() {
|
|
1762
|
+
return {
|
|
1763
|
+
supports_search: false,
|
|
1764
|
+
supports_group_request: true,
|
|
1765
|
+
supported_resolutions: [
|
|
1766
|
+
"1",
|
|
1767
|
+
"3",
|
|
1768
|
+
"5",
|
|
1769
|
+
"15",
|
|
1770
|
+
"30",
|
|
1771
|
+
"60",
|
|
1772
|
+
"120",
|
|
1773
|
+
"240",
|
|
1774
|
+
"480",
|
|
1775
|
+
"720",
|
|
1776
|
+
"1D",
|
|
1777
|
+
"3D",
|
|
1778
|
+
"1W",
|
|
1779
|
+
"1M"
|
|
1780
|
+
],
|
|
1781
|
+
supports_marks: false,
|
|
1782
|
+
supports_timescale_marks: false
|
|
1783
|
+
};
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
// src/tradingviewAdapter/datafeed/eventBus.ts
|
|
1787
|
+
var MultiBroadcastEventBus = class {
|
|
1788
|
+
constructor() {
|
|
1789
|
+
this.subscribers = /* @__PURE__ */ new Map();
|
|
1790
|
+
}
|
|
1791
|
+
subscribe(eventName, callback) {
|
|
1792
|
+
if (!this.subscribers.has(eventName)) {
|
|
1793
|
+
this.subscribers.set(eventName, []);
|
|
1794
|
+
}
|
|
1795
|
+
const callbacks = this.subscribers.get(eventName);
|
|
1796
|
+
callbacks.push(callback);
|
|
1797
|
+
return () => {
|
|
1798
|
+
this.unsubscribe(eventName, callback);
|
|
1799
|
+
};
|
|
1800
|
+
}
|
|
1801
|
+
unsubscribe(eventName, callback) {
|
|
1802
|
+
if (this.subscribers.has(eventName)) {
|
|
1803
|
+
const callbacks = this.subscribers.get(eventName);
|
|
1804
|
+
this.subscribers.set(
|
|
1805
|
+
eventName,
|
|
1806
|
+
callbacks.filter((cb) => cb !== callback)
|
|
1807
|
+
);
|
|
1808
|
+
if (this.subscribers.get(eventName).length === 0) {
|
|
1809
|
+
this.subscribers.delete(eventName);
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
publish(eventName, data) {
|
|
1814
|
+
if (this.subscribers.has(eventName)) {
|
|
1815
|
+
const callbacks = this.subscribers.get(eventName);
|
|
1816
|
+
callbacks.forEach((callback) => {
|
|
1817
|
+
callback(data);
|
|
1818
|
+
});
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
};
|
|
1822
|
+
|
|
1823
|
+
// src/utils/common.util.ts
|
|
1824
|
+
var mapResolution = (resolution) => {
|
|
1825
|
+
let time = "1d";
|
|
1826
|
+
switch (resolution) {
|
|
1827
|
+
case "1" /* RESOLUTION_1m */:
|
|
1828
|
+
time = "1m";
|
|
1829
|
+
break;
|
|
1830
|
+
case "3" /* RESOLUTION_3m */:
|
|
1831
|
+
time = "3m";
|
|
1832
|
+
break;
|
|
1833
|
+
case "5" /* RESOLUTION_5m */:
|
|
1834
|
+
time = "5m";
|
|
1835
|
+
break;
|
|
1836
|
+
case "15" /* RESOLUTION_15m */:
|
|
1837
|
+
time = "15m";
|
|
1838
|
+
break;
|
|
1839
|
+
case "30" /* RESOLUTION_30m */:
|
|
1840
|
+
time = "30m";
|
|
1841
|
+
break;
|
|
1842
|
+
case "60" /* RESOLUTION_60m */:
|
|
1843
|
+
time = "1h";
|
|
1844
|
+
break;
|
|
1845
|
+
case "120" /* RESOLUTION_120m */:
|
|
1846
|
+
time = "2h";
|
|
1847
|
+
break;
|
|
1848
|
+
case "240" /* RESOLUTION_240m */:
|
|
1849
|
+
time = "4h";
|
|
1850
|
+
break;
|
|
1851
|
+
case "480" /* RESOLUTION_480m */:
|
|
1852
|
+
time = "8h";
|
|
1853
|
+
break;
|
|
1854
|
+
case "720" /* RESOLUTION_720m */:
|
|
1855
|
+
time = "12h";
|
|
1856
|
+
break;
|
|
1857
|
+
case "D" /* RESOLUTION_D */:
|
|
1858
|
+
case "1D" /* RESOLUTION_1D */:
|
|
1859
|
+
time = "1d";
|
|
1860
|
+
break;
|
|
1861
|
+
case "3D" /* RESOLUTION_3D */:
|
|
1862
|
+
time = "3d";
|
|
1863
|
+
break;
|
|
1864
|
+
case "1W" /* RESOLUTION_1W */:
|
|
1865
|
+
time = "1w";
|
|
1866
|
+
break;
|
|
1867
|
+
case "1M" /* RESOLUTION_1M */:
|
|
1868
|
+
time = "1M ";
|
|
1869
|
+
break;
|
|
1870
|
+
}
|
|
1871
|
+
return time;
|
|
1872
|
+
};
|
|
1873
|
+
var TradingViewSDKLocalstorageKey = {
|
|
1874
|
+
interval: "TradingviewSDK.lastUsedTimeBasedResolution",
|
|
1875
|
+
lineType: "TradingviewSDK.lastUsedStyle",
|
|
1876
|
+
displayControlSetting: "TradingviewSDK.displaySetting"
|
|
1877
|
+
};
|
|
1878
|
+
|
|
1879
|
+
// src/tradingviewAdapter/datafeed/websocket.service.ts
|
|
1880
|
+
var getKlineKey = (symbol, type) => `${symbol}kline_${type}`;
|
|
1881
|
+
var getSymbolTopics = (symbol) => {
|
|
1882
|
+
const symbolTopics = ["trade"];
|
|
1883
|
+
return symbolTopics.map((topic) => `${symbol}@${topic}`);
|
|
1884
|
+
};
|
|
1885
|
+
var _WebsocketService = class _WebsocketService {
|
|
1886
|
+
constructor(ws) {
|
|
1887
|
+
this.klineSubscribeIdMap = /* @__PURE__ */ new Map();
|
|
1888
|
+
this.klineOnTickCallback = /* @__PURE__ */ new Map();
|
|
1889
|
+
this.subscribeCachedTopics = /* @__PURE__ */ new Map();
|
|
1890
|
+
this.wsInstance = null;
|
|
1891
|
+
this.klineData = /* @__PURE__ */ new Map();
|
|
1892
|
+
if (!_WebsocketService._created) {
|
|
1893
|
+
this.wsInstance = ws;
|
|
1894
|
+
_WebsocketService._instance = this;
|
|
1895
|
+
_WebsocketService._created = true;
|
|
1896
|
+
}
|
|
1897
|
+
return _WebsocketService._instance;
|
|
1898
|
+
}
|
|
1899
|
+
subscribeKline(subscribeId, symbol, resolution, onTickCallback) {
|
|
1900
|
+
const time = mapResolution(resolution);
|
|
1901
|
+
this.klineSubscribeIdMap.set(subscribeId, { symbol, resolution });
|
|
1902
|
+
const klineKey = getKlineKey(symbol, time);
|
|
1903
|
+
if (this.klineOnTickCallback.has(klineKey)) {
|
|
1904
|
+
const value = this.klineOnTickCallback.get(klineKey);
|
|
1905
|
+
value[subscribeId] = onTickCallback;
|
|
1906
|
+
} else {
|
|
1907
|
+
this.klineOnTickCallback.set(klineKey, {
|
|
1908
|
+
[subscribeId]: onTickCallback
|
|
1909
|
+
});
|
|
1910
|
+
const unsub = this.wsInstance?.subscribe(
|
|
1911
|
+
{
|
|
1912
|
+
event: "subscribe",
|
|
1913
|
+
topic: `${symbol}@kline_${time}`,
|
|
1914
|
+
id: `${symbol}@kline_${time}`,
|
|
1915
|
+
ts: (/* @__PURE__ */ new Date()).getTime()
|
|
1916
|
+
},
|
|
1917
|
+
{
|
|
1918
|
+
onMessage: (data) => {
|
|
1919
|
+
const { open, close, high, low, volume, startTime } = data;
|
|
1920
|
+
const key = getKlineKey(data.symbol, data.type);
|
|
1921
|
+
this.updateKline(key, {
|
|
1922
|
+
time: startTime,
|
|
1923
|
+
close,
|
|
1924
|
+
open,
|
|
1925
|
+
high,
|
|
1926
|
+
low,
|
|
1927
|
+
volume
|
|
1928
|
+
});
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
);
|
|
1932
|
+
this.subscribeCachedTopics.set(`${symbol}@kline_${time}`, unsub);
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
unsubscribeKline(subscribeId) {
|
|
1936
|
+
if (!this.klineSubscribeIdMap.has(subscribeId)) {
|
|
1937
|
+
return;
|
|
1938
|
+
}
|
|
1939
|
+
const { symbol, resolution } = this.klineSubscribeIdMap.get(subscribeId);
|
|
1940
|
+
const time = mapResolution(resolution);
|
|
1941
|
+
const klineKey = getKlineKey(symbol, time);
|
|
1942
|
+
if (this.klineOnTickCallback.has(klineKey)) {
|
|
1943
|
+
const value = this.klineOnTickCallback.get(klineKey);
|
|
1944
|
+
delete value[subscribeId];
|
|
1945
|
+
if (Object.keys(value).length === 0) {
|
|
1946
|
+
this.klineOnTickCallback.delete(klineKey);
|
|
1947
|
+
const unsub = this.subscribeCachedTopics.get(`${symbol}@kline_${time}`);
|
|
1948
|
+
unsub();
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
delete this.klineSubscribeIdMap[subscribeId];
|
|
1952
|
+
}
|
|
1953
|
+
subscribeSymbol(symbol) {
|
|
1954
|
+
const symbolTopics = getSymbolTopics(symbol);
|
|
1955
|
+
symbolTopics.forEach((topic) => {
|
|
1956
|
+
if (!this.subscribeCachedTopics.has(topic)) {
|
|
1957
|
+
const unsub = this.wsInstance?.subscribe(
|
|
1958
|
+
{
|
|
1959
|
+
event: "subscribe",
|
|
1960
|
+
topic,
|
|
1961
|
+
id: topic,
|
|
1962
|
+
ts: (/* @__PURE__ */ new Date()).getTime()
|
|
1963
|
+
},
|
|
1964
|
+
{
|
|
1965
|
+
onMessage: (data) => {
|
|
1966
|
+
this.updateKlineByLastPrice(data.symbol, data.price);
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
);
|
|
1970
|
+
this.subscribeCachedTopics.set(topic, unsub);
|
|
1971
|
+
}
|
|
1972
|
+
});
|
|
1973
|
+
}
|
|
1974
|
+
updateKlineByLastPrice(symbol, lastPrice) {
|
|
1975
|
+
this.klineOnTickCallback.forEach((_, key) => {
|
|
1976
|
+
if (key.startsWith(symbol)) {
|
|
1977
|
+
const klineData = this.klineData.get(key);
|
|
1978
|
+
if (klineData) {
|
|
1979
|
+
this.updateKline(key, { ...klineData, close: lastPrice });
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
});
|
|
1983
|
+
}
|
|
1984
|
+
updateKline(key, cbParams) {
|
|
1985
|
+
const onTickCbs = this.klineOnTickCallback.get(key);
|
|
1986
|
+
if (onTickCbs && cbParams) {
|
|
1987
|
+
this.klineData.set(key, cbParams);
|
|
1988
|
+
Object.keys(onTickCbs).forEach((key2) => {
|
|
1989
|
+
const onTickCb = onTickCbs[key2];
|
|
1990
|
+
if (onTickCb && typeof onTickCb === "function") {
|
|
1991
|
+
onTickCb(cbParams);
|
|
1992
|
+
}
|
|
1993
|
+
});
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
};
|
|
1997
|
+
_WebsocketService._created = false;
|
|
1998
|
+
_WebsocketService._instance = null;
|
|
1999
|
+
var WebsocketService = _WebsocketService;
|
|
2000
|
+
|
|
2001
|
+
// src/tradingviewAdapter/datafeed/datafeed.ts
|
|
2002
|
+
var getAutoIncrementId = /* @__PURE__ */ (() => {
|
|
2003
|
+
let id = 0;
|
|
2004
|
+
return () => id++;
|
|
2005
|
+
})();
|
|
2006
|
+
var Datafeed = class extends AbstractDatafeed {
|
|
2007
|
+
constructor(apiUrl, ws) {
|
|
2008
|
+
const datafeedURL = `${apiUrl}`;
|
|
2009
|
+
super(datafeedURL);
|
|
2010
|
+
this.bbosMap = /* @__PURE__ */ new Map();
|
|
2011
|
+
this.tickersMap = /* @__PURE__ */ new Map();
|
|
2012
|
+
this.eventBus = new MultiBroadcastEventBus();
|
|
2013
|
+
this._subscribeQuoteMap = /* @__PURE__ */ new Map();
|
|
2014
|
+
this._prefixId = getAutoIncrementId();
|
|
2015
|
+
this._publicWs = new WebsocketService(ws);
|
|
2016
|
+
this.bbosMap = /* @__PURE__ */ new Map();
|
|
2017
|
+
ws.on("tickers", (message) => {
|
|
2018
|
+
for (const ticker of message.data) {
|
|
2019
|
+
ticker.change = ticker.close - ticker.open;
|
|
2020
|
+
ticker.perChange = ticker.open ? +(100 * ticker.change / ticker.open).toFixed(2) : 0;
|
|
2021
|
+
this.tickersMap.set(ticker.symbol, ticker);
|
|
2022
|
+
}
|
|
2023
|
+
this.eventBus.publish("tickerUpdate", { message: "ticker" });
|
|
2024
|
+
});
|
|
2025
|
+
ws.subscribe(
|
|
2026
|
+
{
|
|
2027
|
+
event: "subscribe",
|
|
2028
|
+
topic: `bbos`
|
|
2029
|
+
},
|
|
2030
|
+
{
|
|
2031
|
+
formatter: (message) => message,
|
|
2032
|
+
onMessage: (message) => {
|
|
2033
|
+
for (const bbo of message.data) {
|
|
2034
|
+
this.bbosMap.set(bbo.symbol, {
|
|
2035
|
+
ask: bbo.ask,
|
|
2036
|
+
bid: bbo.bid,
|
|
2037
|
+
askSize: bbo.askSize,
|
|
2038
|
+
bidSize: bbo.bidSize
|
|
2039
|
+
});
|
|
2040
|
+
}
|
|
2041
|
+
this.eventBus.publish("tickerUpdate", { message: "bbos" });
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2044
|
+
);
|
|
2045
|
+
}
|
|
2046
|
+
remove() {
|
|
2047
|
+
Array.from(this._subscribeQuoteMap.values()).forEach((s) => s?.());
|
|
2048
|
+
}
|
|
2049
|
+
getSubscriptionId(listenerGuid) {
|
|
2050
|
+
return `${this._prefixId}${listenerGuid}`;
|
|
2051
|
+
}
|
|
2052
|
+
subscribeBars(symbolInfo, resolution, onTick, listenerGuid, onResetCacheNeededCallback) {
|
|
2053
|
+
window.onResetCacheNeededCallback = onResetCacheNeededCallback;
|
|
2054
|
+
this._publicWs.subscribeKline(
|
|
2055
|
+
`${this._prefixId}${listenerGuid}`,
|
|
2056
|
+
symbolInfo.ticker,
|
|
2057
|
+
resolution,
|
|
2058
|
+
onTick
|
|
2059
|
+
);
|
|
2060
|
+
}
|
|
2061
|
+
unsubscribeBars(listenerGuid) {
|
|
2062
|
+
this._publicWs.unsubscribeKline(`${this._prefixId}${listenerGuid}`);
|
|
2063
|
+
}
|
|
2064
|
+
getQuotes(symbols, onDataCallback) {
|
|
2065
|
+
const subscriptionId = this.getSubscriptionId("getQuotes");
|
|
2066
|
+
this.unsubscribeQuotes("getQuotes");
|
|
2067
|
+
const unsub = this.eventBus.subscribe("tickerUpdate", (msg) => {
|
|
2068
|
+
const dataMap = /* @__PURE__ */ new Map();
|
|
2069
|
+
symbols.forEach((symbol) => {
|
|
2070
|
+
const bbo = this.bbosMap.get(withoutExchangePrefix(symbol));
|
|
2071
|
+
const ticker = this.tickersMap.get(withoutExchangePrefix(symbol));
|
|
2072
|
+
if (!bbo || !ticker) {
|
|
2073
|
+
return;
|
|
2074
|
+
}
|
|
2075
|
+
const data = {
|
|
2076
|
+
...ticker,
|
|
2077
|
+
ask: bbo.ask,
|
|
2078
|
+
bid: bbo.bid
|
|
2079
|
+
};
|
|
2080
|
+
dataMap.set(withoutExchangePrefix(symbol), data);
|
|
2081
|
+
});
|
|
2082
|
+
if (!dataMap.size) {
|
|
2083
|
+
return;
|
|
2084
|
+
}
|
|
2085
|
+
onDataCallback(
|
|
2086
|
+
Array.from(dataMap.values()).map(
|
|
2087
|
+
(symbolData) => this._toUDFTicker(symbolData)
|
|
2088
|
+
)
|
|
2089
|
+
);
|
|
2090
|
+
});
|
|
2091
|
+
this._subscribeQuoteMap.set(subscriptionId, unsub);
|
|
2092
|
+
}
|
|
2093
|
+
subscribeQuotes(symbols, fastSymbols, onRealtimeCallback, listenerGuid) {
|
|
2094
|
+
const subscriptionId = `${this._prefixId}${listenerGuid}`;
|
|
2095
|
+
if (symbols.length > 0) {
|
|
2096
|
+
this.unsubscribeQuotes(subscriptionId);
|
|
2097
|
+
const unsub = this.eventBus.subscribe("tickerUpdate", (msg) => {
|
|
2098
|
+
const dataMap = /* @__PURE__ */ new Map();
|
|
2099
|
+
symbols.forEach((symbol) => {
|
|
2100
|
+
const bbo = this.bbosMap.get(withoutExchangePrefix(symbol));
|
|
2101
|
+
const ticker = this.tickersMap.get(withoutExchangePrefix(symbol));
|
|
2102
|
+
if (!bbo || !ticker) {
|
|
2103
|
+
return;
|
|
2104
|
+
}
|
|
2105
|
+
const data = {
|
|
2106
|
+
...ticker,
|
|
2107
|
+
ask: bbo.ask,
|
|
2108
|
+
bid: bbo.bid
|
|
2109
|
+
};
|
|
2110
|
+
dataMap.set(withoutExchangePrefix(symbol), data);
|
|
2111
|
+
});
|
|
2112
|
+
if (!dataMap.size) {
|
|
2113
|
+
return;
|
|
2114
|
+
}
|
|
2115
|
+
onRealtimeCallback(
|
|
2116
|
+
Array.from(dataMap.values()).map(
|
|
2117
|
+
(symbolData) => this._toUDFTicker(symbolData)
|
|
2118
|
+
)
|
|
2119
|
+
);
|
|
2120
|
+
});
|
|
2121
|
+
this._subscribeQuoteMap.set(subscriptionId, unsub);
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
unsubscribeQuotes(listenerGuid) {
|
|
2125
|
+
const subscriptionId = this.getSubscriptionId(listenerGuid);
|
|
2126
|
+
const unsub = this._subscribeQuoteMap.get(subscriptionId);
|
|
2127
|
+
if (unsub) {
|
|
2128
|
+
unsub();
|
|
2129
|
+
this._subscribeQuoteMap.delete(subscriptionId);
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2132
|
+
_toUDFTicker(t) {
|
|
2133
|
+
return {
|
|
2134
|
+
n: withExchangePrefix(t.symbol),
|
|
2135
|
+
s: "ok",
|
|
2136
|
+
v: {
|
|
2137
|
+
ask: t.ask,
|
|
2138
|
+
bid: t.bid,
|
|
2139
|
+
ch: t.change,
|
|
2140
|
+
chp: t.perChange / 100,
|
|
2141
|
+
description: "",
|
|
2142
|
+
exchange: EXCHANGE,
|
|
2143
|
+
hight_price: t.high,
|
|
2144
|
+
low_price: t.low,
|
|
2145
|
+
lp: t.close,
|
|
2146
|
+
open_price: t.open,
|
|
2147
|
+
prev_close_price: 0,
|
|
2148
|
+
volume: t.volume
|
|
2149
|
+
}
|
|
2150
|
+
};
|
|
2151
|
+
}
|
|
2152
|
+
};
|
|
2153
|
+
var EST_TPSL_PNL_DECIMAL = 2;
|
|
2154
|
+
var textDash = "--";
|
|
2155
|
+
var BracketAlgoType = ["BRACKET" /* BRACKET */, "STOP_BRACKET" /* STOP_BRACKET */];
|
|
2156
|
+
var TpslAlgoType = ["POSITIONAL_TP_SL" /* POSITIONAL_TP_SL */, "TP_SL" /* TP_SL */];
|
|
2157
|
+
var isTpslOrder = (order) => order.root_algo_order_id !== order.algo_order_id && (order.algo_type === "TAKE_PROFIT" /* TAKE_PROFIT */ || order.algo_type === "STOP_LOSS" /* STOP_LOSS */);
|
|
2158
|
+
var isBracketAlgoType = (algoType) => !!algoType && BracketAlgoType.includes(algoType);
|
|
2159
|
+
var isPositionTpsl = (order) => order.type === "CLOSE_POSITION" /* CLOSE_POSITION */;
|
|
2160
|
+
var isActivatedPositionTpsl = (order) => isPositionTpsl(order) && order.is_activated;
|
|
2161
|
+
var isActivatedTpslOrder = (order) => isTpslOrder(order) && order.is_activated;
|
|
2162
|
+
var isActivatedQuantityTpsl = (order) => order.root_algo_order_algo_type === "TP_SL" /* TP_SL */ || isBracketAlgoType(order.root_algo_order_algo_type) && order.is_activated;
|
|
2163
|
+
var getTpslTag = (order, quantityTpslNoMap) => {
|
|
2164
|
+
const algoType = order.algo_type;
|
|
2165
|
+
const suffix = {
|
|
2166
|
+
["TAKE_PROFIT" /* TAKE_PROFIT */]: orderlyI18n.i18n.t("tpsl.takeProfit"),
|
|
2167
|
+
["STOP_LOSS" /* STOP_LOSS */]: orderlyI18n.i18n.t("tpsl.stopLoss")
|
|
2168
|
+
}[algoType];
|
|
2169
|
+
if (!suffix) {
|
|
2170
|
+
return null;
|
|
2171
|
+
}
|
|
2172
|
+
return suffix;
|
|
2173
|
+
};
|
|
2174
|
+
var buildQuantityTpslNoMap = (orders) => {
|
|
2175
|
+
const quantityTpslNoMap = /* @__PURE__ */ new Map();
|
|
2176
|
+
let idx = 1;
|
|
2177
|
+
[...orders].reverse().filter(isActivatedQuantityTpsl).forEach((order) => {
|
|
2178
|
+
if (order.root_algo_order_id && !quantityTpslNoMap.has(order.root_algo_order_id)) {
|
|
2179
|
+
quantityTpslNoMap.set(order.root_algo_order_id, idx++);
|
|
2180
|
+
}
|
|
2181
|
+
});
|
|
2182
|
+
return quantityTpslNoMap;
|
|
2183
|
+
};
|
|
2184
|
+
var getTpslEstPnl = (tpslOrder, position) => {
|
|
2185
|
+
const quantity = Math.abs(
|
|
2186
|
+
tpslOrder.type === "CLOSE_POSITION" /* CLOSE_POSITION */ ? position.balance : tpslOrder.quantity
|
|
2187
|
+
);
|
|
2188
|
+
const sideFlag = tpslOrder.side === "SELL" /* SELL */ ? 1 : -1;
|
|
2189
|
+
const openPrice = position.open.toString();
|
|
2190
|
+
const estPnl = new orderlyUtils.Decimal(tpslOrder.trigger_price).minus(openPrice ?? 0).times(quantity).times(sideFlag).toString();
|
|
2191
|
+
return { estPnl, quantity, openPrice };
|
|
2192
|
+
};
|
|
2193
|
+
var formatPnl = (pnl) => {
|
|
2194
|
+
return pnl !== void 0 && pnl !== "" ? new orderlyUtils.Decimal(pnl).todp(EST_TPSL_PNL_DECIMAL, orderlyUtils.Decimal.ROUND_FLOOR) : textDash;
|
|
2195
|
+
};
|
|
2196
|
+
function useCancelOrder() {
|
|
2197
|
+
const [
|
|
2198
|
+
pendingOrders,
|
|
2199
|
+
{ cancelOrder, cancelAlgoOrder, cancelTPSLChildOrder }
|
|
2200
|
+
] = orderlyHooks.useOrderStream({
|
|
2201
|
+
status: orderlyTypes.OrderStatus.INCOMPLETE
|
|
2202
|
+
});
|
|
2203
|
+
return React3.useCallback(
|
|
2204
|
+
(order) => {
|
|
2205
|
+
if (order.algo_order_id) {
|
|
2206
|
+
if (TpslAlgoType.includes(order.root_algo_order_algo_type)) {
|
|
2207
|
+
const rootOrder = pendingOrders?.find(
|
|
2208
|
+
(item) => item.algo_order_id === order.root_algo_order_id
|
|
2209
|
+
);
|
|
2210
|
+
const isEditActivated = rootOrder.child_orders.every(
|
|
2211
|
+
(item) => !!item.trigger_price
|
|
2212
|
+
);
|
|
2213
|
+
if (isEditActivated) {
|
|
2214
|
+
return cancelTPSLChildOrder(
|
|
2215
|
+
order.algo_order_id,
|
|
2216
|
+
order.root_algo_order_id
|
|
2217
|
+
);
|
|
2218
|
+
}
|
|
2219
|
+
return cancelAlgoOrder(rootOrder.algo_order_id, order.symbol).then();
|
|
2220
|
+
}
|
|
2221
|
+
return cancelAlgoOrder(order.algo_order_id, order.symbol).then();
|
|
2222
|
+
}
|
|
2223
|
+
return cancelOrder(order.order_id, order.symbol).then();
|
|
2224
|
+
},
|
|
2225
|
+
[cancelOrder, pendingOrders]
|
|
2226
|
+
);
|
|
2227
|
+
}
|
|
2228
|
+
function useEditOrder(onToast) {
|
|
2229
|
+
orderlyHooks.useEventEmitter();
|
|
2230
|
+
const [, { updateOrder, cancelAlgoOrder, updateAlgoOrder, updateTPSLOrder }] = orderlyHooks.useOrderStream({
|
|
2231
|
+
status: orderlyTypes.OrderStatus.INCOMPLETE
|
|
2232
|
+
});
|
|
2233
|
+
return React3.useCallback(
|
|
2234
|
+
(order, lineValue) => {
|
|
2235
|
+
if (order.algo_order_id) {
|
|
2236
|
+
if (TpslAlgoType.includes(order.root_algo_order_algo_type)) {
|
|
2237
|
+
const algoParams = [
|
|
2238
|
+
{
|
|
2239
|
+
order_id: order.algo_order_id,
|
|
2240
|
+
trigger_price: new orderlyUtils.Decimal(lineValue.value).toString()
|
|
2241
|
+
}
|
|
2242
|
+
];
|
|
2243
|
+
return updateTPSLOrder(order.root_algo_order_id, algoParams).then((res) => {
|
|
2244
|
+
}).catch((e) => {
|
|
2245
|
+
if (onToast) {
|
|
2246
|
+
onToast.error(e.message);
|
|
2247
|
+
}
|
|
2248
|
+
});
|
|
2249
|
+
} else if (BracketAlgoType.includes(order.algo_type)) {
|
|
2250
|
+
return updateAlgoOrder(order.algo_order_id, {
|
|
2251
|
+
order_price: new orderlyUtils.Decimal(lineValue.value).toString()
|
|
2252
|
+
}).then((res) => {
|
|
2253
|
+
}).catch((e) => {
|
|
2254
|
+
if (onToast) {
|
|
2255
|
+
onToast.error(e.message);
|
|
2256
|
+
}
|
|
2257
|
+
});
|
|
2258
|
+
} else {
|
|
2259
|
+
const values2 = {
|
|
2260
|
+
quantity: order.quantity,
|
|
2261
|
+
trigger_price: order.trigger_price,
|
|
2262
|
+
symbol: order.symbol,
|
|
2263
|
+
price: order.price,
|
|
2264
|
+
// order_type: order.type,
|
|
2265
|
+
// side: order.side,
|
|
2266
|
+
// reduce_only: Boolean(order.reduce_only),
|
|
2267
|
+
algo_order_id: order.algo_order_id
|
|
2268
|
+
};
|
|
2269
|
+
if (order.order_tag) {
|
|
2270
|
+
values2.order_tag = order.order_tag;
|
|
2271
|
+
}
|
|
2272
|
+
if (order.client_order_id) {
|
|
2273
|
+
values2.client_order_id = order.client_order_id;
|
|
2274
|
+
}
|
|
2275
|
+
if (lineValue.type === "price") {
|
|
2276
|
+
values2.price = new orderlyUtils.Decimal(lineValue.value).toString();
|
|
2277
|
+
}
|
|
2278
|
+
if (lineValue.type === "trigger_price") {
|
|
2279
|
+
values2.trigger_price = new orderlyUtils.Decimal(lineValue.value).toString();
|
|
2280
|
+
}
|
|
2281
|
+
return updateAlgoOrder(order.algo_order_id, values2).then((res) => {
|
|
2282
|
+
}).catch((e) => {
|
|
2283
|
+
if (onToast) {
|
|
2284
|
+
onToast.error(e.message);
|
|
2285
|
+
}
|
|
2286
|
+
});
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
const values = {
|
|
2290
|
+
order_price: order.price?.toString(),
|
|
2291
|
+
order_quantity: order.quantity.toString(),
|
|
2292
|
+
symbol: order.symbol,
|
|
2293
|
+
order_type: order.type,
|
|
2294
|
+
side: order.side,
|
|
2295
|
+
visible_quantity: 0,
|
|
2296
|
+
reduce_only: order.reduce_only
|
|
2297
|
+
};
|
|
2298
|
+
if (new orderlyUtils.Decimal(order.visible_quantity ?? order.visible ?? 0).eq(
|
|
2299
|
+
order.quantity
|
|
2300
|
+
)) {
|
|
2301
|
+
delete values.visible_quantity;
|
|
2302
|
+
}
|
|
2303
|
+
if (!Object.keys(order).includes("reduce_only")) {
|
|
2304
|
+
delete values.reduce_only;
|
|
2305
|
+
}
|
|
2306
|
+
if (order.order_tag) {
|
|
2307
|
+
values.order_tag = order.order_tag;
|
|
2308
|
+
}
|
|
2309
|
+
if (order.client_order_id) {
|
|
2310
|
+
values.client_order_id = order.client_order_id;
|
|
2311
|
+
}
|
|
2312
|
+
if (lineValue.type === "price") {
|
|
2313
|
+
values.order_price = new orderlyUtils.Decimal(lineValue.value).toString();
|
|
2314
|
+
}
|
|
2315
|
+
return updateOrder(order.order_id, values).then((res) => {
|
|
2316
|
+
}).catch((e) => {
|
|
2317
|
+
onToast.error(e.message);
|
|
2318
|
+
});
|
|
2319
|
+
},
|
|
2320
|
+
[updateOrder]
|
|
2321
|
+
);
|
|
2322
|
+
}
|
|
2323
|
+
function useSendOrder(symbol) {
|
|
2324
|
+
const { onSubmit: _sendMarketOrder } = orderlyHooks.useOrderEntry_deprecated(
|
|
2325
|
+
{
|
|
2326
|
+
symbol,
|
|
2327
|
+
side: orderlyTypes.OrderSide.BUY,
|
|
2328
|
+
order_type: orderlyTypes.OrderType.MARKET
|
|
2329
|
+
},
|
|
2330
|
+
{
|
|
2331
|
+
watchOrderbook: true
|
|
2332
|
+
}
|
|
2333
|
+
);
|
|
2334
|
+
const sendLimitOrder = () => {
|
|
2335
|
+
};
|
|
2336
|
+
const sendMarketOrder = (data) => {
|
|
2337
|
+
data.reduce_only = false;
|
|
2338
|
+
return _sendMarketOrder(data).catch((e) => {
|
|
2339
|
+
orderlyUi.toast.error(e);
|
|
2340
|
+
});
|
|
2341
|
+
};
|
|
2342
|
+
return {
|
|
2343
|
+
sendLimitOrder,
|
|
2344
|
+
sendMarketOrder
|
|
2345
|
+
};
|
|
2346
|
+
}
|
|
2347
|
+
var createBrokerMethod = (method) => {
|
|
2348
|
+
return (params) => method(params);
|
|
2349
|
+
};
|
|
2350
|
+
var useBroker = ({
|
|
2351
|
+
closeConfirm,
|
|
2352
|
+
colorConfig,
|
|
2353
|
+
onToast,
|
|
2354
|
+
mode,
|
|
2355
|
+
symbol
|
|
2356
|
+
}) => {
|
|
2357
|
+
const cancelOrder = useCancelOrder();
|
|
2358
|
+
const editOrder = useEditOrder(onToast);
|
|
2359
|
+
const symbolData = orderlyHooks.useSymbolsInfo();
|
|
2360
|
+
const closePosition = React3.useCallback(
|
|
2361
|
+
(position) => closeConfirm && closeConfirm(position),
|
|
2362
|
+
[closeConfirm]
|
|
2363
|
+
);
|
|
2364
|
+
const { sendMarketOrder, sendLimitOrder } = useSendOrder(symbol);
|
|
2365
|
+
const getSymbolInfo = React3.useCallback(
|
|
2366
|
+
(symbol2) => {
|
|
2367
|
+
if (!symbolData) {
|
|
2368
|
+
return;
|
|
2369
|
+
}
|
|
2370
|
+
return {
|
|
2371
|
+
baseMin: symbolData[symbol2]("base_min"),
|
|
2372
|
+
baseMax: symbolData[symbol2]("base_max"),
|
|
2373
|
+
baseTick: symbolData[symbol2]("base_tick"),
|
|
2374
|
+
quoteTick: symbolData[symbol2]("quote_tick")
|
|
2375
|
+
};
|
|
2376
|
+
},
|
|
2377
|
+
[symbolData]
|
|
2378
|
+
);
|
|
2379
|
+
const broker = React3.useRef({
|
|
2380
|
+
cancelOrder,
|
|
2381
|
+
closePosition,
|
|
2382
|
+
editOrder,
|
|
2383
|
+
colorConfig,
|
|
2384
|
+
sendLimitOrder,
|
|
2385
|
+
getSymbolInfo,
|
|
2386
|
+
sendMarketOrder: createBrokerMethod(sendMarketOrder),
|
|
2387
|
+
mode
|
|
2388
|
+
});
|
|
2389
|
+
React3.useEffect(() => {
|
|
2390
|
+
broker.current.getSymbolInfo = getSymbolInfo;
|
|
2391
|
+
}, [symbolData]);
|
|
2392
|
+
React3.useEffect(() => {
|
|
2393
|
+
broker.current.sendLimitOrder = sendLimitOrder;
|
|
2394
|
+
broker.current.sendMarketOrder = sendMarketOrder;
|
|
2395
|
+
}, [sendLimitOrder, sendMarketOrder]);
|
|
2396
|
+
React3.useEffect(() => {
|
|
2397
|
+
broker.current.closePosition = closePosition;
|
|
2398
|
+
}, [closeConfirm]);
|
|
2399
|
+
React3.useEffect(() => {
|
|
2400
|
+
broker.current.cancelOrder = cancelOrder;
|
|
2401
|
+
}, [cancelOrder]);
|
|
2402
|
+
return broker.current;
|
|
2403
|
+
};
|
|
2404
|
+
var useBroker_default = useBroker;
|
|
2405
|
+
var IntervalMap = {
|
|
2406
|
+
1: { startOf: "minute", period: 0 },
|
|
2407
|
+
3: { startOf: "hour", period: 3 * 60 * 1e3 },
|
|
2408
|
+
5: { startOf: "hour", period: 5 * 60 * 1e3 },
|
|
2409
|
+
15: { startOf: "hour", period: 15 * 60 * 1e3 },
|
|
2410
|
+
30: { startOf: "hour", period: 30 * 60 * 1e3 },
|
|
2411
|
+
60: { startOf: "hour", period: 0 },
|
|
2412
|
+
120: { startOf: "day", period: 2 * 60 * 60 * 1e3 },
|
|
2413
|
+
240: { startOf: "day", period: 4 * 60 * 60 * 1e3 },
|
|
2414
|
+
480: { startOf: "day", period: 8 * 60 * 60 * 1e3 },
|
|
2415
|
+
720: { startOf: "day", period: 12 * 60 * 60 * 1e3 },
|
|
2416
|
+
D: { startOf: "day", period: 0 },
|
|
2417
|
+
// default day interval shown as D instead of 1D
|
|
2418
|
+
"1D": { startOf: "day", period: 0 },
|
|
2419
|
+
"3D": { startOf: "year", period: 3 * 24 * 60 * 60 * 1e3 },
|
|
2420
|
+
"5D": { startOf: "year", period: 5 * 24 * 60 * 60 * 1e3 },
|
|
2421
|
+
"1W": { startOf: "week", period: 0 },
|
|
2422
|
+
"1M": { startOf: "month", period: 0 }
|
|
2423
|
+
};
|
|
2424
|
+
function collectionOrders(order, collection, interval, orderList) {
|
|
2425
|
+
const { startOf, period } = IntervalMap[interval];
|
|
2426
|
+
const time = new Date(order.updated_time).getTime();
|
|
2427
|
+
let base = dateFns.startOfSecond(time).getTime();
|
|
2428
|
+
if (startOf === "minute") {
|
|
2429
|
+
base = dateFns.startOfMinute(time).getTime();
|
|
2430
|
+
} else if (startOf === "hour") {
|
|
2431
|
+
base = dateFns.startOfHour(time).getTime();
|
|
2432
|
+
} else if (startOf === "day") {
|
|
2433
|
+
base = dateFns.startOfDay(time).getTime();
|
|
2434
|
+
} else if (startOf === "month") {
|
|
2435
|
+
base = dateFns.startOfMonth(time).getTime();
|
|
2436
|
+
} else if (startOf === "year") {
|
|
2437
|
+
base = dateFns.startOfYear(time).getTime();
|
|
2438
|
+
} else if (startOf === "week") {
|
|
2439
|
+
base = dateFns.startOfWeek(time).getTime();
|
|
2440
|
+
} else if (startOf === "month") {
|
|
2441
|
+
base = dateFns.startOfMonth(time).getTime();
|
|
2442
|
+
}
|
|
2443
|
+
const group = period === 0 ? base : Math.floor((time - base) / period) * period + base;
|
|
2444
|
+
if (!collection[group]) {
|
|
2445
|
+
collection[group] = { ["BUY" /* BUY */]: [], ["SELL" /* SELL */]: [] };
|
|
2446
|
+
}
|
|
2447
|
+
if (collection[group][order.side].length < 5) {
|
|
2448
|
+
collection[group][order.side].push(order);
|
|
2449
|
+
orderList.push(order);
|
|
2450
|
+
}
|
|
2451
|
+
}
|
|
2452
|
+
var limitOrdersByInterval = (orders, interval) => {
|
|
2453
|
+
const res = [];
|
|
2454
|
+
const collection = {};
|
|
2455
|
+
if (!IntervalMap[interval]) {
|
|
2456
|
+
return [];
|
|
2457
|
+
}
|
|
2458
|
+
orders.forEach((order) => {
|
|
2459
|
+
if (order.child_orders) {
|
|
2460
|
+
for (const child of order.child_orders) {
|
|
2461
|
+
if (child.is_activated && child.algo_status === orderlyTypes.OrderStatus.FILLED) {
|
|
2462
|
+
collectionOrders(child, collection, interval, res);
|
|
2463
|
+
}
|
|
2464
|
+
}
|
|
2465
|
+
} else {
|
|
2466
|
+
collectionOrders(order, collection, interval, res);
|
|
2467
|
+
}
|
|
2468
|
+
});
|
|
2469
|
+
return res;
|
|
2470
|
+
};
|
|
2471
|
+
var ExecutionService = class _ExecutionService {
|
|
2472
|
+
constructor(instance, broker) {
|
|
2473
|
+
this.interval = "1D";
|
|
2474
|
+
this.changeInterval = (interval) => {
|
|
2475
|
+
const rerenderExecutions = () => {
|
|
2476
|
+
this.renderExecutions(this.filledOrders, this.basePriceDecimal);
|
|
2477
|
+
this.instance.activeChart().onDataLoaded().unsubscribe(null, rerenderExecutions);
|
|
2478
|
+
};
|
|
2479
|
+
this.interval = interval;
|
|
2480
|
+
this.instance.activeChart().onDataLoaded().subscribe(null, rerenderExecutions);
|
|
2481
|
+
};
|
|
2482
|
+
this.instance = instance;
|
|
2483
|
+
this.executions = [];
|
|
2484
|
+
this.filledOrders = [];
|
|
2485
|
+
this.basePriceDecimal = 0;
|
|
2486
|
+
this.broker = broker;
|
|
2487
|
+
this.subscribeIntervalChange();
|
|
2488
|
+
}
|
|
2489
|
+
async subscribeIntervalChange() {
|
|
2490
|
+
this.interval = this.instance.symbolInterval().interval;
|
|
2491
|
+
const changeInterval = this.changeInterval;
|
|
2492
|
+
this.instance.activeChart().onIntervalChanged().subscribe(null, changeInterval);
|
|
2493
|
+
}
|
|
2494
|
+
renderExecutions(filledOrders, basePriceDecimal) {
|
|
2495
|
+
this.filledOrders = filledOrders;
|
|
2496
|
+
this.basePriceDecimal = basePriceDecimal;
|
|
2497
|
+
if (!this.interval) {
|
|
2498
|
+
return;
|
|
2499
|
+
}
|
|
2500
|
+
this.removeAll();
|
|
2501
|
+
limitOrdersByInterval(filledOrders, this.interval).forEach((order) => {
|
|
2502
|
+
this.executions.push(this.drawExecution(order, basePriceDecimal));
|
|
2503
|
+
});
|
|
2504
|
+
}
|
|
2505
|
+
removeAll() {
|
|
2506
|
+
this.executions.forEach((execution) => execution.remove());
|
|
2507
|
+
this.executions = [];
|
|
2508
|
+
}
|
|
2509
|
+
static getExecutionInfo(order, basePriceDecimal) {
|
|
2510
|
+
const side = order.side;
|
|
2511
|
+
const avgExecPrice = order.average_executed_price || order.child_orders?.find((child) => !!child.average_executed_price)?.average_executed_price || 0;
|
|
2512
|
+
const excutedNumber = new orderlyUtils.Decimal(avgExecPrice).todp(basePriceDecimal, orderlyUtils.Decimal.ROUND_FLOOR).toString();
|
|
2513
|
+
return `${side === "BUY" /* BUY */ ? orderlyI18n.i18n.t("common.buy") : orderlyI18n.i18n.t("common.sell")} ${order.total_executed_quantity} @${orderlyUtils.commify(excutedNumber)}`;
|
|
2514
|
+
}
|
|
2515
|
+
drawExecution(order, basePriceDecimal) {
|
|
2516
|
+
const side = order.side;
|
|
2517
|
+
const avgExecPrice = order.average_executed_price || order.child_orders?.find((child) => !!child.average_executed_price)?.average_executed_price || 0;
|
|
2518
|
+
const timestamp = new Date(order.updated_time).getTime() / 1e3;
|
|
2519
|
+
const colorConfig = this.broker.colorConfig;
|
|
2520
|
+
return this.instance.activeChart().createExecutionShape().setArrowHeight(9).setTooltip(_ExecutionService.getExecutionInfo(order, basePriceDecimal)).setTime(timestamp).setPrice(avgExecPrice).setArrowColor(
|
|
2521
|
+
side === "BUY" /* BUY */ ? colorConfig.upColor : colorConfig.downColor
|
|
2522
|
+
).setDirection(side === "BUY" /* BUY */ ? "buy" : "sell");
|
|
2523
|
+
}
|
|
2524
|
+
unsubscribeIntervalChange() {
|
|
2525
|
+
const changeInterval = this.changeInterval;
|
|
2526
|
+
try {
|
|
2527
|
+
this.instance.activeChart().onIntervalChanged().unsubscribe(null, changeInterval);
|
|
2528
|
+
} catch (e) {
|
|
2529
|
+
if (e instanceof Error && e.message === "Cannot read properties of null (reading 'tradingViewApi')") ;
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
destroy() {
|
|
2533
|
+
this.removeAll();
|
|
2534
|
+
this.unsubscribeIntervalChange();
|
|
2535
|
+
}
|
|
2536
|
+
};
|
|
2537
|
+
|
|
2538
|
+
// src/tradingviewAdapter/renderer/order.util.ts
|
|
2539
|
+
var getOrderId = (order) => {
|
|
2540
|
+
if (order === null || order === void 0) {
|
|
2541
|
+
return void 0;
|
|
2542
|
+
}
|
|
2543
|
+
return order.algo_order_id || order.order_id;
|
|
2544
|
+
};
|
|
2545
|
+
|
|
2546
|
+
// src/tradingviewAdapter/renderer/tpslCal.service.ts
|
|
2547
|
+
var TpslCalService = class {
|
|
2548
|
+
constructor() {
|
|
2549
|
+
this.quantityTpslNoMap = /* @__PURE__ */ new Map();
|
|
2550
|
+
this.tpslPnlMap = /* @__PURE__ */ new Map();
|
|
2551
|
+
this.positions = null;
|
|
2552
|
+
}
|
|
2553
|
+
getQuantityTpslNoMap() {
|
|
2554
|
+
return this.quantityTpslNoMap;
|
|
2555
|
+
}
|
|
2556
|
+
getTpslPnlMap() {
|
|
2557
|
+
return this.tpslPnlMap;
|
|
2558
|
+
}
|
|
2559
|
+
getFormattedEstPnl(tpslOrder) {
|
|
2560
|
+
if (this.positions === null) {
|
|
2561
|
+
return "";
|
|
2562
|
+
}
|
|
2563
|
+
const position = this.positions[0];
|
|
2564
|
+
if (!position) {
|
|
2565
|
+
return "";
|
|
2566
|
+
}
|
|
2567
|
+
const { estPnl } = getTpslEstPnl(tpslOrder, position);
|
|
2568
|
+
return formatPnl(estPnl);
|
|
2569
|
+
}
|
|
2570
|
+
prepareTpslPnlMap(newPendingOrders) {
|
|
2571
|
+
const changed = [];
|
|
2572
|
+
newPendingOrders.forEach((order) => {
|
|
2573
|
+
const orderId = getOrderId(order);
|
|
2574
|
+
if (orderId && isActivatedTpslOrder(order)) {
|
|
2575
|
+
const prevPnl = this.tpslPnlMap.get(orderId);
|
|
2576
|
+
const newPnl = this.getFormattedEstPnl(order);
|
|
2577
|
+
if (prevPnl !== newPnl) {
|
|
2578
|
+
changed.push(orderId);
|
|
2579
|
+
this.tpslPnlMap.set(orderId, newPnl);
|
|
2580
|
+
}
|
|
2581
|
+
}
|
|
2582
|
+
});
|
|
2583
|
+
return changed;
|
|
2584
|
+
}
|
|
2585
|
+
prepareQuantityTpslNoMap(newPendingOrders) {
|
|
2586
|
+
this.quantityTpslNoMap = buildQuantityTpslNoMap(newPendingOrders);
|
|
2587
|
+
}
|
|
2588
|
+
recalculatePnl(positions, pendingOrders) {
|
|
2589
|
+
this.positions = positions;
|
|
2590
|
+
return this.prepareTpslPnlMap(pendingOrders);
|
|
2591
|
+
}
|
|
2592
|
+
clear() {
|
|
2593
|
+
this.positions = null;
|
|
2594
|
+
this.quantityTpslNoMap.clear();
|
|
2595
|
+
this.tpslPnlMap.clear();
|
|
2596
|
+
}
|
|
2597
|
+
};
|
|
2598
|
+
|
|
2599
|
+
// src/tradingviewAdapter/renderer/orderLine.service.ts
|
|
2600
|
+
var _OrderLineService = class _OrderLineService {
|
|
2601
|
+
constructor(instance, broker) {
|
|
2602
|
+
this.instance = instance;
|
|
2603
|
+
this.pendingOrderLineMap = /* @__PURE__ */ new Map();
|
|
2604
|
+
this.pendingOrders = [];
|
|
2605
|
+
this.broker = broker;
|
|
2606
|
+
this.tpslCalService = new TpslCalService();
|
|
2607
|
+
}
|
|
2608
|
+
renderPendingOrders(newPendingOrders) {
|
|
2609
|
+
if (newPendingOrders) {
|
|
2610
|
+
this.pendingOrders = newPendingOrders;
|
|
2611
|
+
}
|
|
2612
|
+
this.cleanOldPendingOrders(this.pendingOrders);
|
|
2613
|
+
this.tpslCalService.prepareTpslPnlMap(this.pendingOrders);
|
|
2614
|
+
this.tpslCalService.prepareQuantityTpslNoMap(this.pendingOrders);
|
|
2615
|
+
this.pendingOrders.forEach((order) => this.renderPendingOrder(order));
|
|
2616
|
+
}
|
|
2617
|
+
updatePositions(positions) {
|
|
2618
|
+
const changed = this.tpslCalService.recalculatePnl(
|
|
2619
|
+
positions,
|
|
2620
|
+
this.pendingOrders
|
|
2621
|
+
);
|
|
2622
|
+
this.pendingOrders.filter((order) => changed.includes(getOrderId(order))).forEach((order) => this.renderPendingOrder(order));
|
|
2623
|
+
}
|
|
2624
|
+
renderPendingOrder(order) {
|
|
2625
|
+
const orderId = _OrderLineService.getOrderId(order);
|
|
2626
|
+
if (!orderId) {
|
|
2627
|
+
return;
|
|
2628
|
+
}
|
|
2629
|
+
const orderLine = this.drawOrderLine(orderId, order);
|
|
2630
|
+
if (orderLine) {
|
|
2631
|
+
this.pendingOrderLineMap.set(orderId, orderLine);
|
|
2632
|
+
}
|
|
2633
|
+
}
|
|
2634
|
+
cleanOldPendingOrders(newPendingOrders) {
|
|
2635
|
+
const newOrderIdSet = new Set(
|
|
2636
|
+
newPendingOrders.map((order) => _OrderLineService.getOrderId(order))
|
|
2637
|
+
);
|
|
2638
|
+
this.pendingOrderLineMap.forEach(
|
|
2639
|
+
(_, orderId) => !newOrderIdSet.has(orderId) && this.removePendingOrder(orderId)
|
|
2640
|
+
);
|
|
2641
|
+
}
|
|
2642
|
+
removePendingOrder(orderId) {
|
|
2643
|
+
if (orderId === void 0) {
|
|
2644
|
+
return;
|
|
2645
|
+
}
|
|
2646
|
+
const orderLine = this.pendingOrderLineMap.get(orderId);
|
|
2647
|
+
if (orderLine) {
|
|
2648
|
+
this.pendingOrderLineMap.delete(orderId);
|
|
2649
|
+
orderLine.remove();
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2652
|
+
getBaseOrderLine() {
|
|
2653
|
+
const colorConfig = this.broker.colorConfig;
|
|
2654
|
+
return this.instance.activeChart().createOrderLine().setCancelTooltip(orderlyI18n.i18n.t("orders.cancelOrder")).setQuantityTextColor(colorConfig.qtyTextColor).setQuantityBackgroundColor(colorConfig.chartBG).setBodyBackgroundColor(colorConfig.chartBG).setCancelButtonBackgroundColor(colorConfig.chartBG).setLineStyle(1).setBodyFont(colorConfig.font).setQuantityFont(colorConfig.font);
|
|
2655
|
+
}
|
|
2656
|
+
static getCombinationType(order) {
|
|
2657
|
+
const { algo_type: algoType, type } = order;
|
|
2658
|
+
if ((algoType === "STOP_LOSS" /* STOP_LOSS */ || algoType === "TAKE_PROFIT" /* TAKE_PROFIT */ || algoType === "STOP" /* STOP */) && type === "LIMIT" /* LIMIT */) {
|
|
2659
|
+
return "STOP_LIMIT" /* STOP_LIMIT */;
|
|
2660
|
+
}
|
|
2661
|
+
if ((algoType === "STOP_LOSS" /* STOP_LOSS */ || algoType === "TAKE_PROFIT" /* TAKE_PROFIT */ || algoType === "STOP" /* STOP */) && type === "MARKET" /* MARKET */) {
|
|
2662
|
+
return "STOP_MARKET" /* STOP_MARKET */;
|
|
2663
|
+
}
|
|
2664
|
+
if (algoType === "BRACKET" /* BRACKET */) {
|
|
2665
|
+
if (type === "LIMIT" /* LIMIT */) {
|
|
2666
|
+
return "BRACKET_LIMIT" /* BRACKET_LIMIT */;
|
|
2667
|
+
}
|
|
2668
|
+
if (type === "MARKET" /* MARKET */) {
|
|
2669
|
+
return "BRACKET_MARKET" /* BRACKET_MARKET */;
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2672
|
+
if (algoType === "TRAILING_STOP" /* TRAILING_STOP */) {
|
|
2673
|
+
return "TRAILING_STOP" /* TRAILING_STOP */;
|
|
2674
|
+
}
|
|
2675
|
+
return "LIMIT" /* LIMIT */;
|
|
2676
|
+
}
|
|
2677
|
+
static getText(pendingOrder) {
|
|
2678
|
+
const orderCombinationType = _OrderLineService.getCombinationType(pendingOrder);
|
|
2679
|
+
if (orderCombinationType === "STOP_LIMIT" /* STOP_LIMIT */ || orderCombinationType === "STOP_MARKET" /* STOP_MARKET */ || orderCombinationType === "STOP_BRACKET_LIMIT" /* STOP_BRACKET_LIMIT */ || orderCombinationType === "STOP_BRACKET_MARKET" /* STOP_BRACKET_MARKET */) {
|
|
2680
|
+
if (pendingOrder.type === "LIMIT" /* LIMIT */) {
|
|
2681
|
+
return `${orderlyI18n.i18n.t("orderEntry.orderType.stopLimit")} ${orderlyUtils.commify(
|
|
2682
|
+
pendingOrder.price
|
|
2683
|
+
)}`;
|
|
2684
|
+
}
|
|
2685
|
+
return orderlyI18n.i18n.t("orderEntry.orderType.stopMarket");
|
|
2686
|
+
}
|
|
2687
|
+
if (orderCombinationType === "TRAILING_STOP" /* TRAILING_STOP */) {
|
|
2688
|
+
return orderlyI18n.i18n.t("orderEntry.trailing");
|
|
2689
|
+
}
|
|
2690
|
+
return orderlyI18n.i18n.t("orderEntry.orderType.limit");
|
|
2691
|
+
}
|
|
2692
|
+
static getOrderPrice(pendingOrder) {
|
|
2693
|
+
if (pendingOrder.algo_type === "TRAILING_STOP" /* TRAILING_STOP */) {
|
|
2694
|
+
return orderlyUtils.getTrailingStopPrice(pendingOrder);
|
|
2695
|
+
}
|
|
2696
|
+
return pendingOrder.trigger_price || pendingOrder.price;
|
|
2697
|
+
}
|
|
2698
|
+
getTPSLTextWithTpsl(text, pendingOrder) {
|
|
2699
|
+
const orderId = getOrderId(pendingOrder);
|
|
2700
|
+
if (!orderId) {
|
|
2701
|
+
return text;
|
|
2702
|
+
}
|
|
2703
|
+
return text;
|
|
2704
|
+
}
|
|
2705
|
+
getTPSLText(pendingOrder) {
|
|
2706
|
+
const tpslTypeText = getTpslTag(
|
|
2707
|
+
pendingOrder,
|
|
2708
|
+
this.tpslCalService.getQuantityTpslNoMap()
|
|
2709
|
+
);
|
|
2710
|
+
if (tpslTypeText) {
|
|
2711
|
+
return this.getTPSLTextWithTpsl(tpslTypeText, pendingOrder);
|
|
2712
|
+
}
|
|
2713
|
+
return null;
|
|
2714
|
+
}
|
|
2715
|
+
getOrderQuantity(pendingOrder) {
|
|
2716
|
+
if (pendingOrder.algo_order_id) {
|
|
2717
|
+
if (isActivatedPositionTpsl(pendingOrder) || isPositionTpsl(pendingOrder)) {
|
|
2718
|
+
return "100%";
|
|
2719
|
+
}
|
|
2720
|
+
if (isActivatedQuantityTpsl(pendingOrder)) {
|
|
2721
|
+
const qty = new orderlyUtils.Decimal(pendingOrder.quantity).minus(
|
|
2722
|
+
pendingOrder.executed ?? 0
|
|
2723
|
+
);
|
|
2724
|
+
const per = qty.div(new orderlyUtils.Decimal(pendingOrder.position_qty)).mul(100).todp(2).toNumber();
|
|
2725
|
+
return `${Math.min(Math.abs(per), 100).toString()}%`;
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
return orderlyUtils.commify(new orderlyUtils.Decimal(pendingOrder.quantity).toString());
|
|
2729
|
+
}
|
|
2730
|
+
drawOrderLine(orderId, pendingOrder) {
|
|
2731
|
+
const text = isTpslOrder(pendingOrder) ? this.getTPSLText(pendingOrder) : _OrderLineService.getText(pendingOrder);
|
|
2732
|
+
if (text === null) {
|
|
2733
|
+
return null;
|
|
2734
|
+
}
|
|
2735
|
+
const colorConfig = this.broker.colorConfig;
|
|
2736
|
+
const orderLine = this.pendingOrderLineMap.get(orderId) ?? this.getBaseOrderLine();
|
|
2737
|
+
const color = pendingOrder.side === "BUY" /* BUY */ ? colorConfig.upColor : colorConfig.downColor;
|
|
2738
|
+
pendingOrder.side === "BUY" /* BUY */ ? colorConfig.pnlUpColor : colorConfig.pnlDownColor;
|
|
2739
|
+
const price = _OrderLineService.getOrderPrice(pendingOrder);
|
|
2740
|
+
const lineLength = 100;
|
|
2741
|
+
const quantity = this.getOrderQuantity(pendingOrder);
|
|
2742
|
+
const textColor2 = colorConfig.textColor;
|
|
2743
|
+
orderLine.setText(text).setCancelButtonIconColor(colorConfig.closeIcon).setCancelButtonBorderColor(color).setBodyTextColor(textColor2).setBodyBorderColor(color).setQuantityBorderColor(color).setQuantityTextColor(color).setLineColor(color).setLineLength(lineLength).setQuantity(quantity ?? "").setPrice(price);
|
|
2744
|
+
if (this.broker.mode !== 3 /* MOBILE */) {
|
|
2745
|
+
orderLine.onCancel(null, () => this.broker.cancelOrder(pendingOrder));
|
|
2746
|
+
this.applyEditOnMove(orderLine, pendingOrder);
|
|
2747
|
+
} else {
|
|
2748
|
+
orderLine.setEditable(false).setCancellable(false);
|
|
2749
|
+
}
|
|
2750
|
+
return orderLine;
|
|
2751
|
+
}
|
|
2752
|
+
static getOrderEditKey(pendingOrder) {
|
|
2753
|
+
const orderCombinationType = this.getCombinationType(pendingOrder);
|
|
2754
|
+
if (["LIMIT" /* LIMIT */, "BRACKET_LIMIT" /* BRACKET_LIMIT */].includes(
|
|
2755
|
+
orderCombinationType
|
|
2756
|
+
)) {
|
|
2757
|
+
return "price";
|
|
2758
|
+
}
|
|
2759
|
+
if (orderCombinationType === "STOP_LIMIT" /* STOP_LIMIT */ || orderCombinationType === "STOP_MARKET" /* STOP_MARKET */ || pendingOrder.rootAlgoOrderAlgoType === "POSITIONAL_TP_SL" /* POSITIONAL_TP_SL */ || pendingOrder.rootAlgoOrderAlgoType === "TP_SL" /* TP_SL */ || pendingOrder.rootAlgoOrderAlgoType === "BRACKET" /* BRACKET */ || pendingOrder.rootAlgoOrderAlgoType === "STOP_BRACKET" /* STOP_BRACKET */) {
|
|
2760
|
+
return "trigger_price";
|
|
2761
|
+
}
|
|
2762
|
+
}
|
|
2763
|
+
applyEditOnMove(orderLine, pendingOrder) {
|
|
2764
|
+
const editKey = _OrderLineService.getOrderEditKey(pendingOrder);
|
|
2765
|
+
if (!editKey) {
|
|
2766
|
+
return;
|
|
2767
|
+
}
|
|
2768
|
+
orderLine.onMove(() => {
|
|
2769
|
+
this.broker.editOrder(pendingOrder, {
|
|
2770
|
+
type: editKey,
|
|
2771
|
+
value: `${orderLine.getPrice()}`
|
|
2772
|
+
}).then((res) => {
|
|
2773
|
+
if (!res.success) {
|
|
2774
|
+
this.renderPendingOrder(pendingOrder);
|
|
2775
|
+
}
|
|
2776
|
+
}).catch(() => this.renderPendingOrder(pendingOrder));
|
|
2777
|
+
});
|
|
2778
|
+
}
|
|
2779
|
+
removeAll() {
|
|
2780
|
+
this.pendingOrderLineMap.forEach((orderLine) => orderLine.remove());
|
|
2781
|
+
this.pendingOrderLineMap.clear();
|
|
2782
|
+
this.pendingOrders = [];
|
|
2783
|
+
this.tpslCalService.clear();
|
|
2784
|
+
}
|
|
2785
|
+
};
|
|
2786
|
+
_OrderLineService.getOrderId = (order) => {
|
|
2787
|
+
if (order === null || order === void 0) {
|
|
2788
|
+
return void 0;
|
|
2789
|
+
}
|
|
2790
|
+
return order.algo_order_id || order.order_id;
|
|
2791
|
+
};
|
|
2792
|
+
var OrderLineService = _OrderLineService;
|
|
2793
|
+
var PositionLineService = class _PositionLineService {
|
|
2794
|
+
constructor(instance, broker) {
|
|
2795
|
+
this.instance = instance;
|
|
2796
|
+
this.currentSymbol = "";
|
|
2797
|
+
this.broker = broker;
|
|
2798
|
+
this.positionLines = {};
|
|
2799
|
+
this.lastPositions = null;
|
|
2800
|
+
}
|
|
2801
|
+
renderPositions(positions) {
|
|
2802
|
+
if (positions === null || positions.length === 0) {
|
|
2803
|
+
this.removePositions();
|
|
2804
|
+
return;
|
|
2805
|
+
}
|
|
2806
|
+
if (this.lastPositions?.length !== positions.length) {
|
|
2807
|
+
this.removePositions();
|
|
2808
|
+
}
|
|
2809
|
+
if (positions[0].symbol !== this.currentSymbol) {
|
|
2810
|
+
this.removePositions();
|
|
2811
|
+
this.currentSymbol = positions[0].symbol;
|
|
2812
|
+
}
|
|
2813
|
+
positions.forEach((position, idx) => this.drawPositionLine(position, idx));
|
|
2814
|
+
this.lastPositions = positions;
|
|
2815
|
+
}
|
|
2816
|
+
getBasePositionLine() {
|
|
2817
|
+
return this.instance.activeChart().createPositionLine().setTooltip(orderlyI18n.i18n.t("positions.closePosition")).setQuantityBackgroundColor(this.broker.colorConfig.chartBG).setCloseButtonBackgroundColor(this.broker.colorConfig.chartBG).setBodyTextColor(this.broker.colorConfig.textColor).setQuantityTextColor(this.broker.colorConfig.qtyTextColor).setBodyFont(this.broker.colorConfig.font).setQuantityFont(this.broker.colorConfig.font).setLineLength(100).setLineStyle(1);
|
|
2818
|
+
}
|
|
2819
|
+
static getPositionQuantity(balance) {
|
|
2820
|
+
return orderlyUtils.commify(new orderlyUtils.Decimal(balance).todp(4, orderlyUtils.Decimal.ROUND_DOWN).toString());
|
|
2821
|
+
}
|
|
2822
|
+
static getPositionPnL(unrealPnl, decimal) {
|
|
2823
|
+
const text = orderlyI18n.i18n.t("tpsl.pnl");
|
|
2824
|
+
const pnl = new orderlyUtils.Decimal(unrealPnl).toFixed(decimal, orderlyUtils.Decimal.ROUND_DOWN);
|
|
2825
|
+
if (new orderlyUtils.Decimal(unrealPnl).eq(0)) {
|
|
2826
|
+
return `${text} 0`;
|
|
2827
|
+
}
|
|
2828
|
+
if (new orderlyUtils.Decimal(unrealPnl).greaterThan(0)) {
|
|
2829
|
+
return `${text} +${orderlyUtils.commify(pnl)}`;
|
|
2830
|
+
}
|
|
2831
|
+
return `${text} ${orderlyUtils.commify(pnl)}`;
|
|
2832
|
+
}
|
|
2833
|
+
removePositions() {
|
|
2834
|
+
Object.keys(this.positionLines).forEach((lineId) => {
|
|
2835
|
+
this.positionLines[Number(lineId)].remove();
|
|
2836
|
+
delete this.positionLines[Number(lineId)];
|
|
2837
|
+
});
|
|
2838
|
+
}
|
|
2839
|
+
drawPositionLine(position, idx) {
|
|
2840
|
+
const colorConfig = this.broker.colorConfig;
|
|
2841
|
+
const isPositiveUnrealPnl = position.unrealPnl >= 0;
|
|
2842
|
+
const isPositiveBalance = position.balance >= 0;
|
|
2843
|
+
let pnlColor = colorConfig.pnlZoreColor;
|
|
2844
|
+
const pnlDecimal = new orderlyUtils.Decimal(position.unrealPnl);
|
|
2845
|
+
if (pnlDecimal.greaterThan(0)) {
|
|
2846
|
+
pnlColor = colorConfig.upColor;
|
|
2847
|
+
} else if (pnlDecimal.lessThan(0)) {
|
|
2848
|
+
pnlColor = colorConfig.downColor;
|
|
2849
|
+
}
|
|
2850
|
+
isPositiveUnrealPnl ? colorConfig.pnlUpColor : colorConfig.pnlDownColor;
|
|
2851
|
+
const sideColor = isPositiveBalance ? colorConfig.upColor : colorConfig.downColor;
|
|
2852
|
+
const price = new orderlyUtils.Decimal(position.open).toNumber();
|
|
2853
|
+
this.positionLines[idx] = this.positionLines[idx] ?? this.getBasePositionLine();
|
|
2854
|
+
this.positionLines[idx].setQuantity(_PositionLineService.getPositionQuantity(position.balance)).setPrice(price).setCloseButtonIconColor(colorConfig.closeIcon).setCloseButtonBorderColor(sideColor).setBodyBackgroundColor(pnlColor).setQuantityTextColor(sideColor).setBodyBorderColor(pnlColor).setLineColor(sideColor).setQuantityBorderColor(sideColor).setText(
|
|
2855
|
+
_PositionLineService.getPositionPnL(
|
|
2856
|
+
position.unrealPnl,
|
|
2857
|
+
position.unrealPnlDecimal
|
|
2858
|
+
)
|
|
2859
|
+
);
|
|
2860
|
+
if (this.broker.mode !== 3 /* MOBILE */) {
|
|
2861
|
+
this.positionLines[idx].onClose(null, () => {
|
|
2862
|
+
this.broker.closePosition(position);
|
|
2863
|
+
});
|
|
2864
|
+
}
|
|
2865
|
+
}
|
|
2866
|
+
};
|
|
2867
|
+
var DEFAULT_THRESHOLD = 10;
|
|
2868
|
+
var TPSLService = class {
|
|
2869
|
+
constructor(instance, broker) {
|
|
2870
|
+
this.interactiveMode = 0 /* NONE */;
|
|
2871
|
+
this.tpslElRemoveTimer = null;
|
|
2872
|
+
this.currentPosition = null;
|
|
2873
|
+
this.tpslOrderLine = null;
|
|
2874
|
+
this.tpslPnLVerticalLineEntityId = null;
|
|
2875
|
+
this.tpslVerticalLineTime = null;
|
|
2876
|
+
this.tpslStartCircleEntityId = null;
|
|
2877
|
+
this.tpslEndCircleEntityId = null;
|
|
2878
|
+
this.threshold = 10;
|
|
2879
|
+
this.lastArgs = null;
|
|
2880
|
+
this.instance = instance;
|
|
2881
|
+
this.broker = broker;
|
|
2882
|
+
this.lastPositions = null;
|
|
2883
|
+
this.tpslElRemoveTimer = null;
|
|
2884
|
+
this.currentPosition = null;
|
|
2885
|
+
this.bindEvent();
|
|
2886
|
+
}
|
|
2887
|
+
bindEvent() {
|
|
2888
|
+
this.chart.crossHairMoved().subscribe(null, (args) => {
|
|
2889
|
+
this.lastArgs = args;
|
|
2890
|
+
if (this.interactiveMode === 2 /* TP_SL_DRAGGING */) {
|
|
2891
|
+
this.clearTpslElRemoveTimer();
|
|
2892
|
+
return;
|
|
2893
|
+
}
|
|
2894
|
+
const position = this.getIntersectantPosition(args);
|
|
2895
|
+
if (this.currentPosition && position && this.currentPosition.symbol === position.symbol) {
|
|
2896
|
+
return;
|
|
2897
|
+
}
|
|
2898
|
+
if (!position) {
|
|
2899
|
+
this.clearTPSLElements();
|
|
2900
|
+
return;
|
|
2901
|
+
}
|
|
2902
|
+
if (position) {
|
|
2903
|
+
this.clearTpslElRemoveTimer();
|
|
2904
|
+
this.currentPosition = position;
|
|
2905
|
+
this.createTPSLTriggerButton(args);
|
|
2906
|
+
}
|
|
2907
|
+
});
|
|
2908
|
+
}
|
|
2909
|
+
clearTpslElRemoveTimer() {
|
|
2910
|
+
if (this.tpslElRemoveTimer) {
|
|
2911
|
+
clearTimeout(this.tpslElRemoveTimer);
|
|
2912
|
+
this.tpslElRemoveTimer = null;
|
|
2913
|
+
}
|
|
2914
|
+
}
|
|
2915
|
+
showTPSLDialog(params) {
|
|
2916
|
+
const pnl = new orderlyUtils.Decimal(params.price).minus(this.currentPosition.open).mul(this.currentPosition?.balance ?? 0);
|
|
2917
|
+
orderlyUi.modal.show("TPSLSimpleDialogId", {
|
|
2918
|
+
title: pnl.gt(0) ? orderlyI18n.i18n.t("tpsl.TPOrderConfirm") : orderlyI18n.i18n.t("tpsl.SLOrderConfirm"),
|
|
2919
|
+
triggerPrice: params.price,
|
|
2920
|
+
type: pnl.gt(0) ? "tp" : "sl",
|
|
2921
|
+
symbol: this.currentPosition.symbol,
|
|
2922
|
+
onComplete: () => {
|
|
2923
|
+
this.clearTPSLElements();
|
|
2924
|
+
this.chart.setScrollEnabled(true);
|
|
2925
|
+
this.chart.setZoomEnabled(true);
|
|
2926
|
+
this.interactiveMode = 0 /* NONE */;
|
|
2927
|
+
},
|
|
2928
|
+
showAdvancedTPSLDialog: (options) => {
|
|
2929
|
+
this.showAdvancedTPSLDialog({
|
|
2930
|
+
type: pnl.gt(0) ? "tp" : "sl",
|
|
2931
|
+
triggerPrice: params.price,
|
|
2932
|
+
qty: options.qty
|
|
2933
|
+
});
|
|
2934
|
+
}
|
|
2935
|
+
}).then(
|
|
2936
|
+
() => {
|
|
2937
|
+
},
|
|
2938
|
+
(err) => {
|
|
2939
|
+
}
|
|
2940
|
+
).finally(() => {
|
|
2941
|
+
this.clearTPSLElements();
|
|
2942
|
+
this.chart.setScrollEnabled(true);
|
|
2943
|
+
this.chart.setZoomEnabled(true);
|
|
2944
|
+
this.interactiveMode = 0 /* NONE */;
|
|
2945
|
+
});
|
|
2946
|
+
}
|
|
2947
|
+
showAdvancedTPSLDialog({
|
|
2948
|
+
type,
|
|
2949
|
+
triggerPrice,
|
|
2950
|
+
qty
|
|
2951
|
+
}) {
|
|
2952
|
+
orderlyUi.modal.show("TPSLDialogId", {
|
|
2953
|
+
withTriggerPrice: true,
|
|
2954
|
+
type,
|
|
2955
|
+
triggerPrice,
|
|
2956
|
+
symbol: this.currentPosition?.symbol,
|
|
2957
|
+
qty,
|
|
2958
|
+
onComplete: () => {
|
|
2959
|
+
this.clearTPSLElements();
|
|
2960
|
+
this.chart.setScrollEnabled(true);
|
|
2961
|
+
this.chart.setZoomEnabled(true);
|
|
2962
|
+
this.interactiveMode = 0 /* NONE */;
|
|
2963
|
+
}
|
|
2964
|
+
}).then(
|
|
2965
|
+
() => {
|
|
2966
|
+
},
|
|
2967
|
+
(err) => {
|
|
2968
|
+
}
|
|
2969
|
+
).finally(() => {
|
|
2970
|
+
this.clearTPSLElements();
|
|
2971
|
+
this.chart.setScrollEnabled(true);
|
|
2972
|
+
this.chart.setZoomEnabled(true);
|
|
2973
|
+
this.interactiveMode = 0 /* NONE */;
|
|
2974
|
+
});
|
|
2975
|
+
}
|
|
2976
|
+
updatePositions(positions) {
|
|
2977
|
+
this.lastPositions = positions;
|
|
2978
|
+
this.threshold = this.generateThreshold();
|
|
2979
|
+
}
|
|
2980
|
+
/**
|
|
2981
|
+
* Generates a threshold value for position intersection detection.
|
|
2982
|
+
* The threshold is calculated as 2% of the visible price range but is capped
|
|
2983
|
+
* to ensure it never exceeds the actual price range (highest - lowest price).
|
|
2984
|
+
*
|
|
2985
|
+
* @returns The calculated threshold value, or DEFAULT_THRESHOLD if calculation fails
|
|
2986
|
+
*/
|
|
2987
|
+
generateThreshold() {
|
|
2988
|
+
const priceScale = this.chart.getPanes()[0]?.getRightPriceScales()[0];
|
|
2989
|
+
if (!priceScale) {
|
|
2990
|
+
return DEFAULT_THRESHOLD;
|
|
2991
|
+
}
|
|
2992
|
+
try {
|
|
2993
|
+
const priceRange = priceScale.getVisiblePriceRange();
|
|
2994
|
+
if (!priceRange) {
|
|
2995
|
+
return DEFAULT_THRESHOLD;
|
|
2996
|
+
}
|
|
2997
|
+
const priceWidth = priceRange.to - priceRange.from;
|
|
2998
|
+
const calculatedThreshold = priceWidth * 0.02;
|
|
2999
|
+
const threshold = Math.min(calculatedThreshold, priceWidth);
|
|
3000
|
+
return threshold;
|
|
3001
|
+
} catch (error) {
|
|
3002
|
+
return DEFAULT_THRESHOLD;
|
|
3003
|
+
}
|
|
3004
|
+
}
|
|
3005
|
+
drawTPSL(params) {
|
|
3006
|
+
const { price } = params;
|
|
3007
|
+
const pnl = new orderlyUtils.Decimal(price).minus(this.currentPosition.open).mul(this.currentPosition?.balance ?? 0);
|
|
3008
|
+
const { tpslOrderLine, verticalLine } = this.ensureTPSLElements({
|
|
3009
|
+
price,
|
|
3010
|
+
pnl
|
|
3011
|
+
});
|
|
3012
|
+
const direction = pnl.gt(0) ? orderlyI18n.i18n.t("tpsl.tp") : orderlyI18n.i18n.t("tpsl.sl");
|
|
3013
|
+
const color = pnl.gt(0) ? this.broker.colorConfig.upColor : this.broker.colorConfig.downColor;
|
|
3014
|
+
tpslOrderLine?.setText(`${direction} ${pnl.toDecimalPlaces(2).toNumber()}`).setBodyTextColor(color).setBodyBorderColor(color).setLineColor(color);
|
|
3015
|
+
if (this.tpslVerticalLineTime) {
|
|
3016
|
+
verticalLine?.setPoints([
|
|
3017
|
+
{ price: this.currentPosition?.open, time: this.tpslVerticalLineTime },
|
|
3018
|
+
{ time: this.tpslVerticalLineTime, price }
|
|
3019
|
+
]);
|
|
3020
|
+
}
|
|
3021
|
+
}
|
|
3022
|
+
ensureTPSLElements(params) {
|
|
3023
|
+
const tpslOrderLine = this.tpslOrderLine;
|
|
3024
|
+
let verticalLine;
|
|
3025
|
+
if (!tpslOrderLine) {
|
|
3026
|
+
this.tpslOrderLine = this.createTPSLOrderLine();
|
|
3027
|
+
}
|
|
3028
|
+
if (this.tpslPnLVerticalLineEntityId) {
|
|
3029
|
+
verticalLine = this.chart.getShapeById(this.tpslPnLVerticalLineEntityId);
|
|
3030
|
+
}
|
|
3031
|
+
if (!verticalLine) {
|
|
3032
|
+
if (!this.currentPosition || !this.tpslVerticalLineTime) {
|
|
3033
|
+
return {};
|
|
3034
|
+
}
|
|
3035
|
+
this.tpslPnLVerticalLineEntityId = this.chart.createMultipointShape(
|
|
3036
|
+
[
|
|
3037
|
+
{
|
|
3038
|
+
price: this.currentPosition.open,
|
|
3039
|
+
time: this.tpslVerticalLineTime
|
|
3040
|
+
},
|
|
3041
|
+
{ time: this.tpslVerticalLineTime, price: params.price }
|
|
3042
|
+
],
|
|
3043
|
+
{
|
|
3044
|
+
shape: "trend_line",
|
|
3045
|
+
// shape: "parallel_channel",
|
|
3046
|
+
lock: true,
|
|
3047
|
+
disableSave: true,
|
|
3048
|
+
disableSelection: true,
|
|
3049
|
+
disableUndo: true,
|
|
3050
|
+
zOrder: "top",
|
|
3051
|
+
overrides: {
|
|
3052
|
+
linecolor: "rgba(255,255,255, 0.2)",
|
|
3053
|
+
linewidth: 1,
|
|
3054
|
+
rightEnd: 1,
|
|
3055
|
+
leftEnd: 1
|
|
3056
|
+
}
|
|
3057
|
+
}
|
|
3058
|
+
);
|
|
3059
|
+
}
|
|
3060
|
+
verticalLine?.setProperties({
|
|
3061
|
+
linecolor: params.pnl.gt(0) ? this.broker.colorConfig.upColor : this.broker.colorConfig.downColor,
|
|
3062
|
+
linewidth: 1
|
|
3063
|
+
});
|
|
3064
|
+
return {
|
|
3065
|
+
tpslOrderLine,
|
|
3066
|
+
verticalLine
|
|
3067
|
+
};
|
|
3068
|
+
}
|
|
3069
|
+
createTPSLTriggerButton(params) {
|
|
3070
|
+
if (!this.tpslOrderLine) {
|
|
3071
|
+
this.tpslOrderLine = this.createTPSLOrderLine();
|
|
3072
|
+
}
|
|
3073
|
+
this.tpslOrderLine.onMove(() => {
|
|
3074
|
+
const price = this.tpslOrderLine?.getPrice();
|
|
3075
|
+
this.showTPSLDialog({ price: price ?? 0 });
|
|
3076
|
+
});
|
|
3077
|
+
this.tpslOrderLine.onMoving(() => {
|
|
3078
|
+
this.interactiveMode = 2 /* TP_SL_DRAGGING */;
|
|
3079
|
+
const price = this.tpslOrderLine?.getPrice();
|
|
3080
|
+
this.verticalLineTime();
|
|
3081
|
+
this.drawTPSL({ price: price ?? 0 });
|
|
3082
|
+
});
|
|
3083
|
+
}
|
|
3084
|
+
createTPSLOrderLine() {
|
|
3085
|
+
return this.chart.createOrderLine().setCancellable(false).setExtendLeft(true).setTooltip(orderlyI18n.i18n.t("tpsl.dragToSet")).setPrice(this.currentPosition.open).setLineLength(-200, "pixel").setText(orderlyI18n.i18n.t("common.tpsl")).setQuantity("").setBodyTextColor(this.broker.colorConfig.textColor).setBodyBackgroundColor(this.broker.colorConfig.chartBG).setBodyBorderColor(this.broker.colorConfig.pnlZoreColor).setQuantityBackgroundColor(this.broker.colorConfig.chartBG).setQuantityBorderColor(this.broker.colorConfig.pnlZoreColor).setQuantityTextColor(this.broker.colorConfig.qtyTextColor).setBodyFont(this.broker.colorConfig.font).setQuantityFont(this.broker.colorConfig.font).setLineStyle(3);
|
|
3086
|
+
}
|
|
3087
|
+
verticalLineTime() {
|
|
3088
|
+
const range = this.chart.getVisibleRange();
|
|
3089
|
+
this.tpslVerticalLineTime = this.getTimeAtPercentage(
|
|
3090
|
+
range.from,
|
|
3091
|
+
range.to,
|
|
3092
|
+
90
|
|
3093
|
+
);
|
|
3094
|
+
}
|
|
3095
|
+
clearTPSLElements() {
|
|
3096
|
+
if (this.tpslElRemoveTimer) {
|
|
3097
|
+
return;
|
|
3098
|
+
}
|
|
3099
|
+
this.tpslElRemoveTimer = setTimeout(() => {
|
|
3100
|
+
this.currentPosition = null;
|
|
3101
|
+
if (this.tpslOrderLine) {
|
|
3102
|
+
this.tpslOrderLine.remove();
|
|
3103
|
+
this.tpslOrderLine = null;
|
|
3104
|
+
}
|
|
3105
|
+
if (this.tpslPnLVerticalLineEntityId) {
|
|
3106
|
+
this.chart.removeEntity(this.tpslPnLVerticalLineEntityId);
|
|
3107
|
+
this.tpslPnLVerticalLineEntityId = null;
|
|
3108
|
+
}
|
|
3109
|
+
this.tpslElRemoveTimer = null;
|
|
3110
|
+
}, 100);
|
|
3111
|
+
}
|
|
3112
|
+
getIntersectantPosition(params) {
|
|
3113
|
+
if (!Array.isArray(this.lastPositions) || this.lastPositions.length === 0) {
|
|
3114
|
+
return null;
|
|
3115
|
+
}
|
|
3116
|
+
const { price, time } = params;
|
|
3117
|
+
let intersectantPosition = null;
|
|
3118
|
+
for (const position of this.lastPositions) {
|
|
3119
|
+
if (position) {
|
|
3120
|
+
if (Math.abs(position.open - price) < this.threshold) {
|
|
3121
|
+
intersectantPosition = position;
|
|
3122
|
+
break;
|
|
3123
|
+
}
|
|
3124
|
+
}
|
|
3125
|
+
}
|
|
3126
|
+
return intersectantPosition;
|
|
3127
|
+
}
|
|
3128
|
+
get chart() {
|
|
3129
|
+
return this.instance.activeChart();
|
|
3130
|
+
}
|
|
3131
|
+
getTimeAtPercentage(startTime, endTime, percentage) {
|
|
3132
|
+
if (typeof startTime !== "number" || typeof endTime !== "number" || typeof percentage !== "number") {
|
|
3133
|
+
return null;
|
|
3134
|
+
}
|
|
3135
|
+
if (percentage < 0 || percentage > 100) {
|
|
3136
|
+
return null;
|
|
3137
|
+
}
|
|
3138
|
+
if (startTime > endTime) {
|
|
3139
|
+
return null;
|
|
3140
|
+
}
|
|
3141
|
+
const duration = endTime - startTime;
|
|
3142
|
+
const factor = percentage / 100;
|
|
3143
|
+
const offset = duration * factor;
|
|
3144
|
+
const targetTime = startTime + offset;
|
|
3145
|
+
return Math.round(targetTime);
|
|
3146
|
+
}
|
|
3147
|
+
};
|
|
3148
|
+
|
|
3149
|
+
// src/tradingviewAdapter/renderer/renderer.ts
|
|
3150
|
+
var Renderer = class {
|
|
3151
|
+
constructor(instance, host, broker) {
|
|
3152
|
+
this.instance = instance;
|
|
3153
|
+
this.positionLineService = new PositionLineService(instance, broker);
|
|
3154
|
+
this.orderLineService = new OrderLineService(instance, broker);
|
|
3155
|
+
this.executionService = new ExecutionService(instance, broker);
|
|
3156
|
+
this.tpslService = new TPSLService(instance, broker);
|
|
3157
|
+
}
|
|
3158
|
+
async renderPositions(positions) {
|
|
3159
|
+
await this.chartReady();
|
|
3160
|
+
await this.onDataLoaded();
|
|
3161
|
+
this.positionLineService.renderPositions(positions);
|
|
3162
|
+
this.orderLineService.updatePositions(positions);
|
|
3163
|
+
this.tpslService.updatePositions(positions);
|
|
3164
|
+
}
|
|
3165
|
+
async renderPendingOrders(pendingOrders) {
|
|
3166
|
+
await this.chartReady();
|
|
3167
|
+
this.orderLineService.renderPendingOrders(pendingOrders);
|
|
3168
|
+
}
|
|
3169
|
+
async renderFilledOrders(filledOrders, basePriceDecimal) {
|
|
3170
|
+
await this.chartReady();
|
|
3171
|
+
await this.onDataLoaded();
|
|
3172
|
+
this.executionService.renderExecutions(filledOrders, basePriceDecimal);
|
|
3173
|
+
}
|
|
3174
|
+
remove() {
|
|
3175
|
+
this.orderLineService.removeAll();
|
|
3176
|
+
this.positionLineService.removePositions();
|
|
3177
|
+
this.executionService.destroy();
|
|
3178
|
+
}
|
|
3179
|
+
onDataLoaded() {
|
|
3180
|
+
if (this.instance.activeChart().symbolExt()) {
|
|
3181
|
+
return Promise.resolve();
|
|
3182
|
+
}
|
|
3183
|
+
return new Promise(
|
|
3184
|
+
(resolve) => this.instance.activeChart().onDataLoaded().subscribe(
|
|
3185
|
+
null,
|
|
3186
|
+
() => {
|
|
3187
|
+
resolve();
|
|
3188
|
+
},
|
|
3189
|
+
true
|
|
3190
|
+
)
|
|
3191
|
+
);
|
|
3192
|
+
}
|
|
3193
|
+
chartReady() {
|
|
3194
|
+
return new Promise(
|
|
3195
|
+
(resolve) => this.instance.onChartReady(() => {
|
|
3196
|
+
try {
|
|
3197
|
+
this.instance.activeChart().dataReady(() => resolve());
|
|
3198
|
+
} catch (err) {
|
|
3199
|
+
if (err.toString().includes("tradingViewApi")) ;
|
|
3200
|
+
}
|
|
3201
|
+
})
|
|
3202
|
+
);
|
|
3203
|
+
}
|
|
3204
|
+
};
|
|
3205
|
+
|
|
3206
|
+
// src/tradingviewAdapter/hooks/useCreateRenderer.ts
|
|
3207
|
+
function useCreateRenderer(symbol, displayControlSetting) {
|
|
3208
|
+
const [renderer, setRenderer] = React3.useState();
|
|
3209
|
+
const rendererRef = React3.useRef();
|
|
3210
|
+
const { state } = orderlyHooks.useAccount();
|
|
3211
|
+
const [unPnlPriceBasis] = orderlyHooks.useLocalStorage("unPnlPriceBasis", "markPrice");
|
|
3212
|
+
const [{ rows: positions }, positionsInfo] = orderlyHooks.usePositionStream(symbol, {
|
|
3213
|
+
calcMode: unPnlPriceBasis
|
|
3214
|
+
});
|
|
3215
|
+
const [pendingOrders] = orderlyHooks.useOrderStream({
|
|
3216
|
+
status: orderlyTypes.OrderStatus.INCOMPLETE,
|
|
3217
|
+
symbol
|
|
3218
|
+
});
|
|
3219
|
+
const config = orderlyHooks.useSymbolsInfo();
|
|
3220
|
+
const symbolInfo = config?.[symbol];
|
|
3221
|
+
const quote_dp = symbolInfo("quote_dp");
|
|
3222
|
+
const [fillOrders] = orderlyHooks.useOrderStream({
|
|
3223
|
+
symbol,
|
|
3224
|
+
status: orderlyTypes.OrderStatus.FILLED,
|
|
3225
|
+
size: 500
|
|
3226
|
+
});
|
|
3227
|
+
const createRenderer = React3.useRef(
|
|
3228
|
+
(instance, host, broker, container) => {
|
|
3229
|
+
if (rendererRef.current) {
|
|
3230
|
+
rendererRef.current.remove();
|
|
3231
|
+
}
|
|
3232
|
+
rendererRef.current = new Renderer(instance, host, broker);
|
|
3233
|
+
setRenderer(rendererRef.current);
|
|
3234
|
+
}
|
|
3235
|
+
);
|
|
3236
|
+
const removeRenderer = React3.useRef(() => {
|
|
3237
|
+
rendererRef.current?.remove();
|
|
3238
|
+
rendererRef.current = void 0;
|
|
3239
|
+
});
|
|
3240
|
+
React3.useEffect(() => {
|
|
3241
|
+
if (state.status < orderlyTypes.AccountStatusEnum.EnableTrading && state.status !== orderlyTypes.AccountStatusEnum.EnableTradingWithoutConnected) {
|
|
3242
|
+
renderer?.renderPositions([]);
|
|
3243
|
+
return;
|
|
3244
|
+
}
|
|
3245
|
+
if (!displayControlSetting || !displayControlSetting.position) {
|
|
3246
|
+
renderer?.renderPositions([]);
|
|
3247
|
+
return;
|
|
3248
|
+
}
|
|
3249
|
+
const positionList = (positions ?? []).filter((_) => _.symbol === symbol).map((item) => {
|
|
3250
|
+
return {
|
|
3251
|
+
symbol: item.symbol,
|
|
3252
|
+
open: item.average_open_price,
|
|
3253
|
+
balance: item.position_qty,
|
|
3254
|
+
closablePosition: 9999,
|
|
3255
|
+
// @ts-ignore
|
|
3256
|
+
unrealPnl: item.unrealized_pnl ?? 0,
|
|
3257
|
+
interest: 0,
|
|
3258
|
+
unrealPnlDecimal: 2,
|
|
3259
|
+
basePriceDecimal: 4
|
|
3260
|
+
};
|
|
3261
|
+
});
|
|
3262
|
+
renderer?.renderPositions(positionList);
|
|
3263
|
+
}, [renderer, positions, symbol, displayControlSetting, state]);
|
|
3264
|
+
React3.useEffect(() => {
|
|
3265
|
+
if (!displayControlSetting || !displayControlSetting.buySell) {
|
|
3266
|
+
renderer?.renderFilledOrders([], 6);
|
|
3267
|
+
return;
|
|
3268
|
+
}
|
|
3269
|
+
const currentSymbolFillOrders = fillOrders?.filter(
|
|
3270
|
+
(item) => item.symbol === symbol
|
|
3271
|
+
);
|
|
3272
|
+
renderer?.renderFilledOrders(currentSymbolFillOrders ?? [], quote_dp ?? 6);
|
|
3273
|
+
}, [renderer, fillOrders, symbol, quote_dp, displayControlSetting]);
|
|
3274
|
+
React3.useEffect(() => {
|
|
3275
|
+
let tpslOrder = [];
|
|
3276
|
+
let positionTpsl = [];
|
|
3277
|
+
let limitOrder = [];
|
|
3278
|
+
let stopOrder = [];
|
|
3279
|
+
let bracketOrder = [];
|
|
3280
|
+
let trailingStopOrder = [];
|
|
3281
|
+
if (state.status < orderlyTypes.AccountStatusEnum.EnableTrading && state.status !== orderlyTypes.AccountStatusEnum.EnableTradingWithoutConnected) {
|
|
3282
|
+
renderer?.renderPendingOrders([]);
|
|
3283
|
+
return;
|
|
3284
|
+
}
|
|
3285
|
+
const symbolPosition = (positions ?? []).find(
|
|
3286
|
+
(item) => item.symbol === symbol
|
|
3287
|
+
);
|
|
3288
|
+
pendingOrders?.forEach((order) => {
|
|
3289
|
+
if (symbol !== order.symbol) {
|
|
3290
|
+
return;
|
|
3291
|
+
}
|
|
3292
|
+
if (!order.algo_order_id) {
|
|
3293
|
+
limitOrder.push(order);
|
|
3294
|
+
} else if (order.algo_order_id) {
|
|
3295
|
+
if (order.algo_type === "POSITIONAL_TP_SL" /* POSITIONAL_TP_SL */) {
|
|
3296
|
+
for (const child_order of order.child_orders) {
|
|
3297
|
+
child_order.root_algo_order_algo_type = order.algo_type;
|
|
3298
|
+
if (child_order.trigger_price && child_order.status !== orderlyTypes.OrderStatus.FILLED) {
|
|
3299
|
+
positionTpsl.push(child_order);
|
|
3300
|
+
}
|
|
3301
|
+
}
|
|
3302
|
+
} else if (order.algo_type === "TP_SL" /* TP_SL */) {
|
|
3303
|
+
if (symbolPosition) {
|
|
3304
|
+
for (const child_order of order.child_orders) {
|
|
3305
|
+
child_order.root_algo_order_algo_type = order.algo_type;
|
|
3306
|
+
child_order.position_qty = symbolPosition.position_qty;
|
|
3307
|
+
if (child_order.trigger_price && child_order.status !== orderlyTypes.OrderStatus.FILLED) {
|
|
3308
|
+
tpslOrder.push(child_order);
|
|
3309
|
+
}
|
|
3310
|
+
}
|
|
3311
|
+
}
|
|
3312
|
+
} else if (order.algo_type === "STOP_LOSS" /* STOP_LOSS */ || order.algo_type === "TAKE_PROFIT" /* TAKE_PROFIT */) {
|
|
3313
|
+
stopOrder.push(order);
|
|
3314
|
+
} else if (order.algo_type === "BRACKET" /* BRACKET */) {
|
|
3315
|
+
bracketOrder.push(order);
|
|
3316
|
+
} else if (order.algo_type === "TRAILING_STOP" /* TRAILING_STOP */) {
|
|
3317
|
+
if (order.is_activated && order.extreme_price) {
|
|
3318
|
+
trailingStopOrder.push(order);
|
|
3319
|
+
}
|
|
3320
|
+
}
|
|
3321
|
+
}
|
|
3322
|
+
});
|
|
3323
|
+
if (displayControlSetting) {
|
|
3324
|
+
if (!displayControlSetting.positionTpsl) {
|
|
3325
|
+
positionTpsl = [];
|
|
3326
|
+
}
|
|
3327
|
+
if (!displayControlSetting.tpsl) {
|
|
3328
|
+
tpslOrder = [];
|
|
3329
|
+
}
|
|
3330
|
+
if (!displayControlSetting.limitOrders) {
|
|
3331
|
+
limitOrder = [];
|
|
3332
|
+
bracketOrder = [];
|
|
3333
|
+
}
|
|
3334
|
+
if (!displayControlSetting.stopOrders) {
|
|
3335
|
+
stopOrder = [];
|
|
3336
|
+
}
|
|
3337
|
+
if (!displayControlSetting.trailingStop) {
|
|
3338
|
+
trailingStopOrder = [];
|
|
3339
|
+
}
|
|
3340
|
+
}
|
|
3341
|
+
renderer?.renderPendingOrders(
|
|
3342
|
+
tpslOrder.concat(positionTpsl).concat(limitOrder).concat(stopOrder).concat(bracketOrder).concat(trailingStopOrder)
|
|
3343
|
+
);
|
|
3344
|
+
}, [
|
|
3345
|
+
renderer,
|
|
3346
|
+
pendingOrders,
|
|
3347
|
+
symbol,
|
|
3348
|
+
displayControlSetting,
|
|
3349
|
+
positions,
|
|
3350
|
+
state.status
|
|
3351
|
+
]);
|
|
3352
|
+
return [createRenderer.current, removeRenderer.current];
|
|
3353
|
+
}
|
|
3354
|
+
|
|
3355
|
+
// src/tradingviewAdapter/renderer/brokerHostHandler.ts
|
|
3356
|
+
function preventDefaultRenderHack(host) {
|
|
3357
|
+
host.setBrokerConnectionAdapter = function(adapter) {
|
|
3358
|
+
const delegate = {
|
|
3359
|
+
subscribe: () => {
|
|
3360
|
+
},
|
|
3361
|
+
unsubscribe: () => {
|
|
3362
|
+
},
|
|
3363
|
+
unsubscribeAll: () => {
|
|
3364
|
+
}
|
|
3365
|
+
};
|
|
3366
|
+
Object.defineProperty(adapter, "_ordersCache", {
|
|
3367
|
+
get: function() {
|
|
3368
|
+
return {
|
|
3369
|
+
start: () => {
|
|
3370
|
+
},
|
|
3371
|
+
stop: () => {
|
|
3372
|
+
},
|
|
3373
|
+
update: () => {
|
|
3374
|
+
},
|
|
3375
|
+
partialUpdate: () => {
|
|
3376
|
+
},
|
|
3377
|
+
fullUpdate: () => {
|
|
3378
|
+
},
|
|
3379
|
+
getObjects: async () => [],
|
|
3380
|
+
updateDelegate: delegate,
|
|
3381
|
+
partialUpdateDelegate: delegate
|
|
3382
|
+
};
|
|
3383
|
+
},
|
|
3384
|
+
set: () => {
|
|
3385
|
+
}
|
|
3386
|
+
});
|
|
3387
|
+
adapter._waitForOrderModification = async () => true;
|
|
3388
|
+
this._adapter = adapter;
|
|
3389
|
+
};
|
|
3390
|
+
}
|
|
3391
|
+
function forceSilentOrdersPlacement(instance, host) {
|
|
3392
|
+
instance.onChartReady(() => {
|
|
3393
|
+
host.silentOrdersPlacement().subscribe((val) => {
|
|
3394
|
+
if (!val) {
|
|
3395
|
+
host.silentOrdersPlacement().setValue(true);
|
|
3396
|
+
if (instance) {
|
|
3397
|
+
instance._iFrame.contentDocument.querySelector(
|
|
3398
|
+
".wrapper-3X2QgaDd"
|
|
3399
|
+
).className = "wrapper-3X2QgaDd highButtons-3X2QgaDd";
|
|
3400
|
+
}
|
|
3401
|
+
host.sellBuyButtonsVisibility()?.setValue(false);
|
|
3402
|
+
}
|
|
3403
|
+
});
|
|
3404
|
+
});
|
|
3405
|
+
}
|
|
3406
|
+
function brokerHostHandler(instance, host) {
|
|
3407
|
+
preventDefaultRenderHack(host);
|
|
3408
|
+
forceSilentOrdersPlacement(instance, host);
|
|
3409
|
+
}
|
|
3410
|
+
|
|
3411
|
+
// src/tradingviewAdapter/widget/util.ts
|
|
3412
|
+
var waitForElm = (iframeDocument, selector) => {
|
|
3413
|
+
return new Promise((resolve) => {
|
|
3414
|
+
const initialIframe = iframeDocument.querySelector(selector);
|
|
3415
|
+
if (initialIframe) {
|
|
3416
|
+
resolve(initialIframe);
|
|
3417
|
+
}
|
|
3418
|
+
const observer = new MutationObserver(() => {
|
|
3419
|
+
const iframe = iframeDocument.querySelector(selector);
|
|
3420
|
+
if (iframe) {
|
|
3421
|
+
resolve(iframe);
|
|
3422
|
+
observer.disconnect();
|
|
3423
|
+
}
|
|
3424
|
+
});
|
|
3425
|
+
observer.observe(iframeDocument, {
|
|
3426
|
+
childList: true,
|
|
3427
|
+
subtree: true
|
|
3428
|
+
});
|
|
3429
|
+
});
|
|
3430
|
+
};
|
|
3431
|
+
|
|
3432
|
+
// src/tradingviewAdapter/widget/chart_hack.ts
|
|
3433
|
+
var ChartHack = class {
|
|
3434
|
+
constructor({ iframeDocument }) {
|
|
3435
|
+
this.iframeDocument = iframeDocument;
|
|
3436
|
+
}
|
|
3437
|
+
defaultHack() {
|
|
3438
|
+
this.showFavoriteStarByDefault();
|
|
3439
|
+
}
|
|
3440
|
+
showFavoriteStarByDefault() {
|
|
3441
|
+
waitForElm(this.iframeDocument, ".dropdown-2R6OKuTS").then(() => {
|
|
3442
|
+
const items = this.iframeDocument.querySelectorAll(
|
|
3443
|
+
".toolbox-2IihgTnv.showOnHover-2IihgTnv"
|
|
3444
|
+
);
|
|
3445
|
+
items.forEach((item) => {
|
|
3446
|
+
item.style.opacity = "1";
|
|
3447
|
+
});
|
|
3448
|
+
});
|
|
3449
|
+
}
|
|
3450
|
+
};
|
|
3451
|
+
|
|
3452
|
+
// src/tradingviewAdapter/widget/option.ts
|
|
3453
|
+
var getDisabledFeatures = (mode) => {
|
|
3454
|
+
let disabledFeatures = [
|
|
3455
|
+
"header_symbol_search",
|
|
3456
|
+
"volume_force_overlay",
|
|
3457
|
+
"trading_account_manager",
|
|
3458
|
+
"drawing_templates",
|
|
3459
|
+
"open_account_manager",
|
|
3460
|
+
"right_toolbar",
|
|
3461
|
+
"support_multicharts",
|
|
3462
|
+
"header_layouttoggle",
|
|
3463
|
+
"order_panel",
|
|
3464
|
+
"order_info",
|
|
3465
|
+
"trading_notifications",
|
|
3466
|
+
"display_market_status",
|
|
3467
|
+
"broker_button",
|
|
3468
|
+
"add_to_watchlist",
|
|
3469
|
+
"chart_crosshair_menu",
|
|
3470
|
+
"header_fullscreen_button",
|
|
3471
|
+
"header_widget"
|
|
3472
|
+
];
|
|
3473
|
+
if (mode === 3 /* MOBILE */) {
|
|
3474
|
+
disabledFeatures = [
|
|
3475
|
+
...disabledFeatures,
|
|
3476
|
+
"left_toolbar",
|
|
3477
|
+
"timeframes_toolbar",
|
|
3478
|
+
"go_to_date",
|
|
3479
|
+
"timezone_menu",
|
|
3480
|
+
// add volume back
|
|
3481
|
+
"create_volume_indicator_by_default",
|
|
3482
|
+
"buy_sell_buttons"
|
|
3483
|
+
];
|
|
3484
|
+
}
|
|
3485
|
+
if (mode === 0 /* BASIC */) {
|
|
3486
|
+
disabledFeatures = [
|
|
3487
|
+
...disabledFeatures,
|
|
3488
|
+
"header_widget",
|
|
3489
|
+
"left_toolbar",
|
|
3490
|
+
"timeframes_toolbar",
|
|
3491
|
+
"buy_sell_buttons"
|
|
3492
|
+
];
|
|
3493
|
+
} else if (mode === 1 /* ADVANCED */) {
|
|
3494
|
+
disabledFeatures = [
|
|
3495
|
+
...disabledFeatures,
|
|
3496
|
+
"left_toolbar",
|
|
3497
|
+
"timeframes_toolbar",
|
|
3498
|
+
"buy_sell_buttons"
|
|
3499
|
+
];
|
|
3500
|
+
}
|
|
3501
|
+
return disabledFeatures;
|
|
3502
|
+
};
|
|
3503
|
+
function getOptions(options, mode, showVolumeInSamePane = true, externalEnabledFeatures, externalDisabledFeatures) {
|
|
3504
|
+
const defaultEnabledFeatures = [
|
|
3505
|
+
"hide_left_toolbar_by_default",
|
|
3506
|
+
"order_panel_close_button",
|
|
3507
|
+
"iframe_loading_compatibility_mode"
|
|
3508
|
+
];
|
|
3509
|
+
const mergedEnabledFeatures = Array.from(
|
|
3510
|
+
/* @__PURE__ */ new Set([...defaultEnabledFeatures, ...externalEnabledFeatures || []])
|
|
3511
|
+
);
|
|
3512
|
+
const defaultDisabledFeatures = getDisabledFeatures(mode);
|
|
3513
|
+
let mergedDisabledFeatures = Array.from(
|
|
3514
|
+
/* @__PURE__ */ new Set([...defaultDisabledFeatures, ...externalDisabledFeatures || []])
|
|
3515
|
+
);
|
|
3516
|
+
if (showVolumeInSamePane) {
|
|
3517
|
+
mergedDisabledFeatures = mergedDisabledFeatures.filter(
|
|
3518
|
+
(feature) => feature !== "volume_force_overlay"
|
|
3519
|
+
);
|
|
3520
|
+
}
|
|
3521
|
+
return {
|
|
3522
|
+
...options,
|
|
3523
|
+
disabled_features: mergedDisabledFeatures,
|
|
3524
|
+
enabled_features: mergedEnabledFeatures,
|
|
3525
|
+
auto_save_delay: 0.1,
|
|
3526
|
+
broker_config: {
|
|
3527
|
+
configFlags: {
|
|
3528
|
+
supportStopLimitOrders: true,
|
|
3529
|
+
supportReversePosition: false
|
|
3530
|
+
}
|
|
3531
|
+
}
|
|
3532
|
+
};
|
|
3533
|
+
}
|
|
3534
|
+
|
|
3535
|
+
// src/tradingviewAdapter/widget/persistUtils.ts
|
|
3536
|
+
var getChartSettingAdapterKey = (chartKey) => `${chartKey}_adapter`;
|
|
3537
|
+
var defaultSettings = {
|
|
3538
|
+
"trading.chart.proterty": JSON.stringify({
|
|
3539
|
+
showSellBuyButtons: 0,
|
|
3540
|
+
noConfirmEnabled: 1,
|
|
3541
|
+
qweqrq: 0,
|
|
3542
|
+
showPricesWithZeroVolume: 1,
|
|
3543
|
+
showSpread: 1,
|
|
3544
|
+
orderExecutedSoundParams: '{"enabled":0,"name":"alert/alarm_clock"}'
|
|
3545
|
+
}),
|
|
3546
|
+
"hint.startFocusedZoom": "true"
|
|
3547
|
+
};
|
|
3548
|
+
var chartCacheMap = /* @__PURE__ */ new Map();
|
|
3549
|
+
var parseAndCacheChartData = (chartKey, savedDataString, adapterSettingString) => {
|
|
3550
|
+
const settingAdapterKey = getChartSettingAdapterKey(chartKey);
|
|
3551
|
+
try {
|
|
3552
|
+
const transformedSavedDataString = savedDataString;
|
|
3553
|
+
const savedData = transformedSavedDataString ? JSON.parse(transformedSavedDataString) : void 0;
|
|
3554
|
+
const adapterSetting = adapterSettingString ? JSON.parse(adapterSettingString) : defaultSettings;
|
|
3555
|
+
if (transformedSavedDataString) {
|
|
3556
|
+
chartCacheMap.set(chartKey, transformedSavedDataString);
|
|
3557
|
+
}
|
|
3558
|
+
if (adapterSettingString) {
|
|
3559
|
+
chartCacheMap.set(settingAdapterKey, adapterSettingString);
|
|
3560
|
+
}
|
|
3561
|
+
return { savedData, adapterSetting };
|
|
3562
|
+
} catch (e) {
|
|
3563
|
+
}
|
|
3564
|
+
return { savedData: void 0, adapterSetting: defaultSettings };
|
|
3565
|
+
};
|
|
3566
|
+
var getChartData = async (chartKey, isLoggedIn) => {
|
|
3567
|
+
const settingAdapterKey = getChartSettingAdapterKey(chartKey);
|
|
3568
|
+
const localStorageSavedData = localStorage.getItem(chartKey) || "";
|
|
3569
|
+
const localStorageAdapterSetting = localStorage.getItem(settingAdapterKey) || "";
|
|
3570
|
+
try {
|
|
3571
|
+
if (chartCacheMap.has(chartKey) && chartCacheMap.has(settingAdapterKey)) {
|
|
3572
|
+
return {
|
|
3573
|
+
savedData: JSON.parse(chartCacheMap.get(chartKey)),
|
|
3574
|
+
adapterSetting: JSON.parse(chartCacheMap.get(settingAdapterKey))
|
|
3575
|
+
};
|
|
3576
|
+
}
|
|
3577
|
+
} catch (e) {
|
|
3578
|
+
}
|
|
3579
|
+
return parseAndCacheChartData(
|
|
3580
|
+
chartKey,
|
|
3581
|
+
localStorageSavedData,
|
|
3582
|
+
localStorageAdapterSetting
|
|
3583
|
+
);
|
|
3584
|
+
};
|
|
3585
|
+
var saveChartData = async (chartKey, setting, isLoggedIn) => {
|
|
3586
|
+
if (setting) {
|
|
3587
|
+
localStorage.setItem(chartKey, setting);
|
|
3588
|
+
chartCacheMap.set(chartKey, setting);
|
|
3589
|
+
}
|
|
3590
|
+
};
|
|
3591
|
+
var saveChartAdapterSetting = async (chartKey, setting, isLoggedIn) => {
|
|
3592
|
+
const settingAdapterKey = getChartSettingAdapterKey(chartKey);
|
|
3593
|
+
if (setting) {
|
|
3594
|
+
localStorage.setItem(settingAdapterKey, setting);
|
|
3595
|
+
chartCacheMap.set(settingAdapterKey, setting);
|
|
3596
|
+
}
|
|
3597
|
+
};
|
|
3598
|
+
|
|
3599
|
+
// src/tradingviewAdapter/widget/index.ts
|
|
3600
|
+
var debounce = (func, delay) => {
|
|
3601
|
+
let timer = null;
|
|
3602
|
+
const debounced = (...args) => {
|
|
3603
|
+
timer && window.clearTimeout(timer);
|
|
3604
|
+
timer = setTimeout(() => {
|
|
3605
|
+
func(...args);
|
|
3606
|
+
}, delay);
|
|
3607
|
+
};
|
|
3608
|
+
debounced.cancel = () => {
|
|
3609
|
+
timer && window.clearTimeout(timer);
|
|
3610
|
+
timer = null;
|
|
3611
|
+
};
|
|
3612
|
+
return debounced;
|
|
3613
|
+
};
|
|
3614
|
+
var DEFAULT_SETTINGS_KEY = "chartProp_default";
|
|
3615
|
+
var DEBOUNCE_SAVE_TIME = 300;
|
|
3616
|
+
var Widget = class {
|
|
3617
|
+
constructor(props) {
|
|
3618
|
+
this._instance = null;
|
|
3619
|
+
this._onClick = null;
|
|
3620
|
+
this._datafeed = null;
|
|
3621
|
+
this._chartKey = DEFAULT_SETTINGS_KEY;
|
|
3622
|
+
this._adapterSetting = defaultSettings;
|
|
3623
|
+
this._savedData = null;
|
|
3624
|
+
this._isLoggedIn = false;
|
|
3625
|
+
this.debounceSaveChart = debounce(() => {
|
|
3626
|
+
try {
|
|
3627
|
+
this._instance?.save((chartProps) => {
|
|
3628
|
+
if (!Object.is(this._savedData, chartProps)) {
|
|
3629
|
+
this._savedData = chartProps;
|
|
3630
|
+
saveChartData(
|
|
3631
|
+
this._chartKey,
|
|
3632
|
+
JSON.stringify(chartProps),
|
|
3633
|
+
this._isLoggedIn
|
|
3634
|
+
);
|
|
3635
|
+
}
|
|
3636
|
+
});
|
|
3637
|
+
} catch (e) {
|
|
3638
|
+
}
|
|
3639
|
+
}, DEBOUNCE_SAVE_TIME * 2);
|
|
3640
|
+
this.debounceSaveChartAdapterSetting = debounce(() => {
|
|
3641
|
+
saveChartAdapterSetting(
|
|
3642
|
+
this._chartKey,
|
|
3643
|
+
JSON.stringify(this._adapterSetting),
|
|
3644
|
+
this._isLoggedIn
|
|
3645
|
+
);
|
|
3646
|
+
}, DEBOUNCE_SAVE_TIME);
|
|
3647
|
+
this._create(props);
|
|
3648
|
+
}
|
|
3649
|
+
remove() {
|
|
3650
|
+
this.unsubscribeClick();
|
|
3651
|
+
this._datafeed?.remove();
|
|
3652
|
+
this._broker?.remove();
|
|
3653
|
+
this._instance?.remove();
|
|
3654
|
+
this.debounceSaveChart.cancel();
|
|
3655
|
+
this.debounceSaveChartAdapterSetting.cancel();
|
|
3656
|
+
}
|
|
3657
|
+
updateOverrides(overrides) {
|
|
3658
|
+
if (!this.instance) {
|
|
3659
|
+
return;
|
|
3660
|
+
}
|
|
3661
|
+
this.instance.applyOverrides(overrides);
|
|
3662
|
+
}
|
|
3663
|
+
setSymbol(symbol, interval, callback) {
|
|
3664
|
+
try {
|
|
3665
|
+
this._instance?.onChartReady(() => {
|
|
3666
|
+
let currentInterval = interval ?? this._instance?.symbolInterval()?.interval;
|
|
3667
|
+
if (!currentInterval) {
|
|
3668
|
+
currentInterval = 1;
|
|
3669
|
+
}
|
|
3670
|
+
this._instance?.setSymbol(symbol, currentInterval, callback);
|
|
3671
|
+
});
|
|
3672
|
+
} catch (e) {
|
|
3673
|
+
}
|
|
3674
|
+
}
|
|
3675
|
+
setResolution(resolution) {
|
|
3676
|
+
if (this._instance) {
|
|
3677
|
+
this._instance.activeChart().setResolution(resolution);
|
|
3678
|
+
}
|
|
3679
|
+
}
|
|
3680
|
+
executeActionById(actionId) {
|
|
3681
|
+
try {
|
|
3682
|
+
this._instance?.onChartReady(() => {
|
|
3683
|
+
this._instance?.activeChart().executeActionById(actionId);
|
|
3684
|
+
});
|
|
3685
|
+
} catch (e) {
|
|
3686
|
+
}
|
|
3687
|
+
}
|
|
3688
|
+
changeLineType(lineType) {
|
|
3689
|
+
try {
|
|
3690
|
+
this._instance?.onChartReady(() => {
|
|
3691
|
+
this._instance?.activeChart().setChartType(lineType);
|
|
3692
|
+
});
|
|
3693
|
+
} catch (e) {
|
|
3694
|
+
}
|
|
3695
|
+
}
|
|
3696
|
+
subscribeClick(onClick) {
|
|
3697
|
+
this._onClick = onClick;
|
|
3698
|
+
this._instance?.onChartReady(() => {
|
|
3699
|
+
this._instance?._iFrame.contentDocument?.addEventListener(
|
|
3700
|
+
"click",
|
|
3701
|
+
this._onClick
|
|
3702
|
+
);
|
|
3703
|
+
});
|
|
3704
|
+
}
|
|
3705
|
+
unsubscribeClick() {
|
|
3706
|
+
this._instance?._iFrame.contentDocument?.removeEventListener(
|
|
3707
|
+
"click",
|
|
3708
|
+
this._onClick
|
|
3709
|
+
);
|
|
3710
|
+
}
|
|
3711
|
+
get instance() {
|
|
3712
|
+
return this._instance;
|
|
3713
|
+
}
|
|
3714
|
+
chartHack() {
|
|
3715
|
+
this._instance?.onChartReady(() => {
|
|
3716
|
+
const iframeDocument = this._instance._iFrame.contentWindow.document;
|
|
3717
|
+
new ChartHack({ iframeDocument }).defaultHack();
|
|
3718
|
+
});
|
|
3719
|
+
}
|
|
3720
|
+
subscribeAutoSave() {
|
|
3721
|
+
this._instance?.onChartReady(() => {
|
|
3722
|
+
this._instance?.subscribe("onAutoSaveNeeded", () => {
|
|
3723
|
+
this.debounceSaveChart();
|
|
3724
|
+
});
|
|
3725
|
+
this._instance?.activeChart().onVisibleRangeChanged().subscribe(null, () => {
|
|
3726
|
+
this.debounceSaveChart();
|
|
3727
|
+
});
|
|
3728
|
+
});
|
|
3729
|
+
}
|
|
3730
|
+
async _create({
|
|
3731
|
+
options,
|
|
3732
|
+
chartKey,
|
|
3733
|
+
mode,
|
|
3734
|
+
onClick,
|
|
3735
|
+
enabled_features,
|
|
3736
|
+
disabled_features
|
|
3737
|
+
}) {
|
|
3738
|
+
const getBroker = options.getBroker;
|
|
3739
|
+
const widgetOptions = {
|
|
3740
|
+
fullscreen: options.fullscreen ?? true,
|
|
3741
|
+
autosize: options.autosize ?? false,
|
|
3742
|
+
timezone: options.timezone,
|
|
3743
|
+
symbol: options.symbol,
|
|
3744
|
+
library_path: options.libraryPath,
|
|
3745
|
+
interval: options.interval ?? "1",
|
|
3746
|
+
custom_css_url: options.customCssUrl,
|
|
3747
|
+
custom_font_family: options.customFontFamily,
|
|
3748
|
+
datafeed: options.datafeed,
|
|
3749
|
+
studies_overrides: options.studiesOverrides,
|
|
3750
|
+
locale: options.locale,
|
|
3751
|
+
theme: options.theme,
|
|
3752
|
+
loading_screen: options.loadingScreen,
|
|
3753
|
+
overrides: options.overrides,
|
|
3754
|
+
container: options.container,
|
|
3755
|
+
favorites: {
|
|
3756
|
+
intervals: [
|
|
3757
|
+
"1",
|
|
3758
|
+
"3",
|
|
3759
|
+
"5",
|
|
3760
|
+
"15",
|
|
3761
|
+
"30",
|
|
3762
|
+
"60",
|
|
3763
|
+
"240",
|
|
3764
|
+
"1d",
|
|
3765
|
+
"1W",
|
|
3766
|
+
"1M"
|
|
3767
|
+
],
|
|
3768
|
+
chartTypes: ["Area", "Line"]
|
|
3769
|
+
},
|
|
3770
|
+
broker_factory: getBroker ? (host) => {
|
|
3771
|
+
if (this._broker) {
|
|
3772
|
+
this._broker.remove();
|
|
3773
|
+
}
|
|
3774
|
+
this._broker = getBroker(
|
|
3775
|
+
this._instance,
|
|
3776
|
+
host
|
|
3777
|
+
);
|
|
3778
|
+
return this._broker;
|
|
3779
|
+
} : void 0
|
|
3780
|
+
};
|
|
3781
|
+
this._datafeed = options.datafeed;
|
|
3782
|
+
if (chartKey) {
|
|
3783
|
+
this._chartKey = chartKey;
|
|
3784
|
+
}
|
|
3785
|
+
const { savedData, adapterSetting } = await getChartData(
|
|
3786
|
+
this._chartKey,
|
|
3787
|
+
this._isLoggedIn
|
|
3788
|
+
);
|
|
3789
|
+
this._adapterSetting = adapterSetting;
|
|
3790
|
+
this._savedData = savedData;
|
|
3791
|
+
this._instance = new TradingView.widget({
|
|
3792
|
+
...getOptions(
|
|
3793
|
+
widgetOptions,
|
|
3794
|
+
mode,
|
|
3795
|
+
options.showVolumeInSamePane ?? true,
|
|
3796
|
+
enabled_features,
|
|
3797
|
+
disabled_features
|
|
3798
|
+
),
|
|
3799
|
+
interval: adapterSetting["chart.lastUsedTimeBasedResolution"] ?? widgetOptions.interval,
|
|
3800
|
+
saved_data: savedData,
|
|
3801
|
+
settings_adapter: {
|
|
3802
|
+
initialSettings: adapterSetting,
|
|
3803
|
+
setValue: (key, value) => {
|
|
3804
|
+
this._adapterSetting = { ...this._adapterSetting, [key]: value };
|
|
3805
|
+
this.debounceSaveChartAdapterSetting();
|
|
3806
|
+
},
|
|
3807
|
+
removeValue: () => {
|
|
3808
|
+
}
|
|
3809
|
+
}
|
|
3810
|
+
});
|
|
3811
|
+
this._instance.onChartReady(() => {
|
|
3812
|
+
if (options.symbol && this._instance?.activeChart().symbol() !== withoutExchangePrefix(options.symbol)) {
|
|
3813
|
+
this.setSymbol(options.symbol);
|
|
3814
|
+
}
|
|
3815
|
+
});
|
|
3816
|
+
this.subscribeAutoSave();
|
|
3817
|
+
this.subscribeClick(onClick);
|
|
3818
|
+
this.chartHack();
|
|
3819
|
+
}
|
|
3820
|
+
};
|
|
3821
|
+
|
|
3822
|
+
// src/components/tradingview.script.ts
|
|
3823
|
+
var CHART_KEY = "SDK_Tradingview";
|
|
3824
|
+
var MOBILE_CHART_KEY = "SDK_Moblie_Tradingview";
|
|
3825
|
+
var getChartKey = (isMobile) => {
|
|
3826
|
+
return isMobile ? MOBILE_CHART_KEY : CHART_KEY;
|
|
3827
|
+
};
|
|
3828
|
+
var defaultLocale = (localeCode) => {
|
|
3829
|
+
return localeCode === "id" ? "id_ID" : localeCode === "tc" ? "zh_TW" : localeCode;
|
|
3830
|
+
};
|
|
3831
|
+
function useTradingviewScript(props) {
|
|
3832
|
+
const {
|
|
3833
|
+
scriptSRC: tradingViewScriptSrc,
|
|
3834
|
+
libraryPath,
|
|
3835
|
+
customCssUrl: tradingViewCustomCssUrl,
|
|
3836
|
+
overrides: customerOverrides,
|
|
3837
|
+
studiesOverrides: customerStudiesOverrides,
|
|
3838
|
+
symbol,
|
|
3839
|
+
theme,
|
|
3840
|
+
loadingScreen: customerLoadingScreen,
|
|
3841
|
+
mode,
|
|
3842
|
+
colorConfig: customerColorConfig,
|
|
3843
|
+
showVolumeInSamePane,
|
|
3844
|
+
locale = defaultLocale,
|
|
3845
|
+
classNames
|
|
3846
|
+
} = props;
|
|
3847
|
+
const localeCode = orderlyI18n.useLocaleCode();
|
|
3848
|
+
const chart = React3.useRef(null);
|
|
3849
|
+
const apiBaseUrl = orderlyHooks.useConfig("apiBaseUrl");
|
|
3850
|
+
const { state: accountState } = orderlyHooks.useAccount();
|
|
3851
|
+
const [side, setSide] = React3.useState(orderlyTypes.OrderSide.SELL);
|
|
3852
|
+
const symbolsInfo = orderlyHooks.useSymbolsInfo();
|
|
3853
|
+
const [fullscreen, setFullscreen] = orderlyHooks.useLocalStorage(
|
|
3854
|
+
orderlyTypes.TradingviewFullscreenKey,
|
|
3855
|
+
false
|
|
3856
|
+
);
|
|
3857
|
+
const { onSubmit, submitting } = orderlyHooks.useOrderEntry_deprecated(
|
|
3858
|
+
{
|
|
3859
|
+
symbol: symbol ?? "",
|
|
3860
|
+
side,
|
|
3861
|
+
order_type: orderlyTypes.OrderType.MARKET
|
|
3862
|
+
},
|
|
3863
|
+
{
|
|
3864
|
+
watchOrderbook: true
|
|
3865
|
+
}
|
|
3866
|
+
);
|
|
3867
|
+
const [displayControlState, setDisplayControlState] = React3.useState(() => {
|
|
3868
|
+
const displaySettingInfo = localStorage.getItem(
|
|
3869
|
+
TradingViewSDKLocalstorageKey.displayControlSetting
|
|
3870
|
+
);
|
|
3871
|
+
if (displaySettingInfo) {
|
|
3872
|
+
return JSON.parse(displaySettingInfo);
|
|
3873
|
+
}
|
|
3874
|
+
return {
|
|
3875
|
+
position: true,
|
|
3876
|
+
buySell: true,
|
|
3877
|
+
limitOrders: true,
|
|
3878
|
+
stopOrders: true,
|
|
3879
|
+
tpsl: true,
|
|
3880
|
+
positionTpsl: true,
|
|
3881
|
+
trailingStop: true
|
|
3882
|
+
};
|
|
3883
|
+
});
|
|
3884
|
+
const [interval, setInterval] = React3.useState(() => {
|
|
3885
|
+
const lastUsedInterval = localStorage.getItem(
|
|
3886
|
+
TradingViewSDKLocalstorageKey.interval
|
|
3887
|
+
);
|
|
3888
|
+
if (!lastUsedInterval) {
|
|
3889
|
+
return "15";
|
|
3890
|
+
}
|
|
3891
|
+
return lastUsedInterval;
|
|
3892
|
+
});
|
|
3893
|
+
const [lineType, setLineType] = React3.useState(() => {
|
|
3894
|
+
const lastUsedLineType = localStorage.getItem(
|
|
3895
|
+
TradingViewSDKLocalstorageKey.lineType
|
|
3896
|
+
);
|
|
3897
|
+
if (!lastUsedLineType) {
|
|
3898
|
+
return "1";
|
|
3899
|
+
}
|
|
3900
|
+
return lastUsedLineType;
|
|
3901
|
+
});
|
|
3902
|
+
const isMobile = orderlyHooks.useMediaQuery(orderlyTypes.MEDIA_TABLET);
|
|
3903
|
+
const colorConfig = React3.useMemo(
|
|
3904
|
+
() => Object.assign({}, defaultColorConfig, customerColorConfig ?? {}),
|
|
3905
|
+
[customerColorConfig]
|
|
3906
|
+
);
|
|
3907
|
+
const loadingScreen = React3.useMemo(() => {
|
|
3908
|
+
if (typeof customerLoadingScreen === "object") {
|
|
3909
|
+
return customerLoadingScreen;
|
|
3910
|
+
}
|
|
3911
|
+
return {
|
|
3912
|
+
backgroundColor: chartBG
|
|
3913
|
+
};
|
|
3914
|
+
}, [customerLoadingScreen]);
|
|
3915
|
+
const ws = orderlyHooks.useWS();
|
|
3916
|
+
const [chartingLibrarySciprtReady, setChartingLibrarySciprtReady] = React3.useState(false);
|
|
3917
|
+
const closePositionConfirmCallback = (data) => {
|
|
3918
|
+
const symbolInfo = symbolsInfo[symbol];
|
|
3919
|
+
if (!symbolInfo) {
|
|
3920
|
+
return;
|
|
3921
|
+
}
|
|
3922
|
+
const side2 = new orderlyUtils.Decimal(data.balance).greaterThan(0) ? orderlyTypes.OrderSide.SELL : orderlyTypes.OrderSide.BUY;
|
|
3923
|
+
const order = {
|
|
3924
|
+
// order_price: undefined,
|
|
3925
|
+
order_quantity: new orderlyUtils.Decimal(data.balance).abs().toNumber(),
|
|
3926
|
+
symbol,
|
|
3927
|
+
order_type: orderlyTypes.OrderType.MARKET,
|
|
3928
|
+
side: side2,
|
|
3929
|
+
reduce_only: true
|
|
3930
|
+
};
|
|
3931
|
+
setSide(side2);
|
|
3932
|
+
orderlyUi.modal.show("MarketCloseConfirmID", {
|
|
3933
|
+
base: symbolInfo("base"),
|
|
3934
|
+
quantity: data.balance,
|
|
3935
|
+
onConfirm: async () => {
|
|
3936
|
+
return onSubmit(order).catch((error) => {
|
|
3937
|
+
if (typeof error === "string") {
|
|
3938
|
+
orderlyUi.toast.error(error);
|
|
3939
|
+
} else {
|
|
3940
|
+
orderlyUi.toast.error(error.message);
|
|
3941
|
+
}
|
|
3942
|
+
});
|
|
3943
|
+
},
|
|
3944
|
+
submitting
|
|
3945
|
+
});
|
|
3946
|
+
};
|
|
3947
|
+
const chartRef = React3.useRef(null);
|
|
3948
|
+
const isLoggedIn = React3.useMemo(() => {
|
|
3949
|
+
if (accountState.status < orderlyTypes.AccountStatusEnum.EnableTrading && accountState.status !== orderlyTypes.AccountStatusEnum.EnableTradingWithoutConnected) {
|
|
3950
|
+
return false;
|
|
3951
|
+
}
|
|
3952
|
+
return true;
|
|
3953
|
+
}, [accountState]);
|
|
3954
|
+
const broker = useBroker_default({
|
|
3955
|
+
closeConfirm: closePositionConfirmCallback,
|
|
3956
|
+
colorConfig,
|
|
3957
|
+
onToast: orderlyUi.toast,
|
|
3958
|
+
symbol: symbol ?? "",
|
|
3959
|
+
mode
|
|
3960
|
+
});
|
|
3961
|
+
const [createRenderer, removeRenderer] = useCreateRenderer(
|
|
3962
|
+
symbol,
|
|
3963
|
+
displayControlState
|
|
3964
|
+
);
|
|
3965
|
+
const onFullScreenChange = () => {
|
|
3966
|
+
if (fullscreen) {
|
|
3967
|
+
setFullscreen(false);
|
|
3968
|
+
} else {
|
|
3969
|
+
setFullscreen(true);
|
|
3970
|
+
}
|
|
3971
|
+
props.onFullScreenChange?.(!fullscreen);
|
|
3972
|
+
};
|
|
3973
|
+
const changeInterval = (newInterval) => {
|
|
3974
|
+
if (!chart.current) {
|
|
3975
|
+
return;
|
|
3976
|
+
}
|
|
3977
|
+
localStorage.setItem(TradingViewSDKLocalstorageKey.interval, newInterval);
|
|
3978
|
+
setInterval(newInterval);
|
|
3979
|
+
chart.current?.setSymbol(symbol ?? "", newInterval);
|
|
3980
|
+
};
|
|
3981
|
+
const changeLineType = (newLineType) => {
|
|
3982
|
+
if (!chart.current) {
|
|
3983
|
+
return;
|
|
3984
|
+
}
|
|
3985
|
+
localStorage.setItem(TradingViewSDKLocalstorageKey.lineType, newLineType);
|
|
3986
|
+
setLineType(newLineType);
|
|
3987
|
+
chart.current?.changeLineType(Number(newLineType));
|
|
3988
|
+
};
|
|
3989
|
+
const changeDisplaySetting = (newSetting) => {
|
|
3990
|
+
localStorage.setItem(
|
|
3991
|
+
TradingViewSDKLocalstorageKey.displayControlSetting,
|
|
3992
|
+
JSON.stringify(newSetting)
|
|
3993
|
+
);
|
|
3994
|
+
setDisplayControlState(newSetting);
|
|
3995
|
+
};
|
|
3996
|
+
const openChartSetting = () => {
|
|
3997
|
+
if (!chart.current) {
|
|
3998
|
+
return;
|
|
3999
|
+
}
|
|
4000
|
+
chart.current.executeActionById("chartProperties");
|
|
4001
|
+
};
|
|
4002
|
+
const openChartIndicators = () => {
|
|
4003
|
+
if (!chart.current) {
|
|
4004
|
+
return;
|
|
4005
|
+
}
|
|
4006
|
+
chart.current.executeActionById("insertIndicator");
|
|
4007
|
+
};
|
|
4008
|
+
React3.useEffect(() => {
|
|
4009
|
+
if (!tradingViewScriptSrc) {
|
|
4010
|
+
return;
|
|
4011
|
+
}
|
|
4012
|
+
if (!chartRef.current) {
|
|
4013
|
+
return;
|
|
4014
|
+
}
|
|
4015
|
+
if (!chartingLibrarySciprtReady) {
|
|
4016
|
+
const script = document.createElement("script");
|
|
4017
|
+
script.setAttribute("data-nscript", "afterInteractive");
|
|
4018
|
+
script.src = tradingViewScriptSrc;
|
|
4019
|
+
script.async = true;
|
|
4020
|
+
script.type = "text/javascript";
|
|
4021
|
+
script.onload = () => {
|
|
4022
|
+
setChartingLibrarySciprtReady(true);
|
|
4023
|
+
};
|
|
4024
|
+
script.onerror = () => {
|
|
4025
|
+
};
|
|
4026
|
+
chartRef.current.appendChild(script);
|
|
4027
|
+
}
|
|
4028
|
+
}, [chartRef, chartingLibrarySciprtReady, tradingViewScriptSrc]);
|
|
4029
|
+
React3.useEffect(() => {
|
|
4030
|
+
if (!symbol) {
|
|
4031
|
+
return;
|
|
4032
|
+
}
|
|
4033
|
+
if (!chartingLibrarySciprtReady || !tradingViewScriptSrc) {
|
|
4034
|
+
return;
|
|
4035
|
+
}
|
|
4036
|
+
const defaultOverrides = getOveriides(colorConfig, isMobile);
|
|
4037
|
+
const overrides = customerOverrides ? Object.assign({}, defaultOverrides.overrides, customerOverrides) : defaultOverrides.overrides;
|
|
4038
|
+
const studiesOverrides = customerStudiesOverrides ? Object.assign(
|
|
4039
|
+
{},
|
|
4040
|
+
defaultOverrides.studiesOverrides,
|
|
4041
|
+
customerStudiesOverrides
|
|
4042
|
+
) : defaultOverrides.studiesOverrides;
|
|
4043
|
+
if (chartRef.current) {
|
|
4044
|
+
const options = {
|
|
4045
|
+
// fullscreen: fullscreen ?? false,
|
|
4046
|
+
fullscreen: false,
|
|
4047
|
+
autosize: true,
|
|
4048
|
+
symbol: withExchangePrefix(symbol),
|
|
4049
|
+
locale: typeof locale === "function" ? locale(localeCode) : locale,
|
|
4050
|
+
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
4051
|
+
container: chartRef.current,
|
|
4052
|
+
libraryPath,
|
|
4053
|
+
customCssUrl: tradingViewCustomCssUrl,
|
|
4054
|
+
interval: interval ?? "1",
|
|
4055
|
+
theme: theme ?? "dark",
|
|
4056
|
+
loadingScreen: loadingScreen ?? {},
|
|
4057
|
+
showVolumeInSamePane,
|
|
4058
|
+
overrides,
|
|
4059
|
+
studiesOverrides,
|
|
4060
|
+
datafeed: new Datafeed(apiBaseUrl, ws),
|
|
4061
|
+
contextMenu: {
|
|
4062
|
+
items_processor: async (defaultItems) => {
|
|
4063
|
+
return defaultItems;
|
|
4064
|
+
}
|
|
4065
|
+
},
|
|
4066
|
+
// todo broker effect sell/buy
|
|
4067
|
+
getBroker: (instance, host) => {
|
|
4068
|
+
brokerHostHandler(instance, host);
|
|
4069
|
+
return getBrokerAdapter_default(host, broker);
|
|
4070
|
+
}
|
|
4071
|
+
// getBroker: undefined,
|
|
4072
|
+
};
|
|
4073
|
+
const chartProps = {
|
|
4074
|
+
options,
|
|
4075
|
+
chartKey: getChartKey(isMobile),
|
|
4076
|
+
mode,
|
|
4077
|
+
onClick: () => {
|
|
4078
|
+
}
|
|
4079
|
+
};
|
|
4080
|
+
chart.current = new Widget(chartProps);
|
|
4081
|
+
}
|
|
4082
|
+
return () => {
|
|
4083
|
+
chart.current?.remove();
|
|
4084
|
+
};
|
|
4085
|
+
}, [
|
|
4086
|
+
chartingLibrarySciprtReady,
|
|
4087
|
+
isMobile,
|
|
4088
|
+
mode,
|
|
4089
|
+
chart,
|
|
4090
|
+
chartRef,
|
|
4091
|
+
chartingLibrarySciprtReady,
|
|
4092
|
+
tradingViewScriptSrc,
|
|
4093
|
+
colorConfig,
|
|
4094
|
+
locale,
|
|
4095
|
+
localeCode,
|
|
4096
|
+
showVolumeInSamePane
|
|
4097
|
+
]);
|
|
4098
|
+
React3.useEffect(() => {
|
|
4099
|
+
ws.on(
|
|
4100
|
+
"status:change",
|
|
4101
|
+
(message) => {
|
|
4102
|
+
if (!message.isPrivate && message.isReconnect) {
|
|
4103
|
+
if (typeof window.onResetCacheNeededCallback === "function") {
|
|
4104
|
+
window.onResetCacheNeededCallback();
|
|
4105
|
+
if (chart.current?.instance) {
|
|
4106
|
+
chart.current?.instance.activeChart()?.resetData();
|
|
4107
|
+
}
|
|
4108
|
+
}
|
|
4109
|
+
}
|
|
4110
|
+
},
|
|
4111
|
+
"tradingview"
|
|
4112
|
+
);
|
|
4113
|
+
}, [ws]);
|
|
4114
|
+
React3.useEffect(() => {
|
|
4115
|
+
if (chart.current && chart.current?.instance) {
|
|
4116
|
+
chart.current?.instance?.onChartReady(() => {
|
|
4117
|
+
if (isLoggedIn && chart.current?.instance) {
|
|
4118
|
+
createRenderer(
|
|
4119
|
+
chart.current.instance,
|
|
4120
|
+
void 0,
|
|
4121
|
+
broker,
|
|
4122
|
+
chartRef.current
|
|
4123
|
+
);
|
|
4124
|
+
}
|
|
4125
|
+
});
|
|
4126
|
+
}
|
|
4127
|
+
return () => {
|
|
4128
|
+
removeRenderer();
|
|
4129
|
+
};
|
|
4130
|
+
}, [chart.current, isLoggedIn]);
|
|
4131
|
+
React3.useEffect(() => {
|
|
4132
|
+
if (!symbol || !chart.current) {
|
|
4133
|
+
return;
|
|
4134
|
+
}
|
|
4135
|
+
chart.current?.setSymbol(symbol);
|
|
4136
|
+
const service = new WebsocketService(ws);
|
|
4137
|
+
service.subscribeSymbol(symbol);
|
|
4138
|
+
return () => {
|
|
4139
|
+
service.unsubscribeKline(symbol);
|
|
4140
|
+
};
|
|
4141
|
+
}, [symbol]);
|
|
4142
|
+
return {
|
|
4143
|
+
tradingViewScriptSrc,
|
|
4144
|
+
chartRef,
|
|
4145
|
+
changeDisplaySetting,
|
|
4146
|
+
displayControlState,
|
|
4147
|
+
interval,
|
|
4148
|
+
changeInterval,
|
|
4149
|
+
lineType,
|
|
4150
|
+
changeLineType,
|
|
4151
|
+
openChartSetting,
|
|
4152
|
+
openChartIndicators,
|
|
4153
|
+
symbol,
|
|
4154
|
+
onFullScreenChange,
|
|
4155
|
+
classNames,
|
|
4156
|
+
fullscreen
|
|
4157
|
+
};
|
|
4158
|
+
}
|
|
4159
|
+
|
|
4160
|
+
// src/components/tradingview.ui.tsx
|
|
4161
|
+
init_icons();
|
|
4162
|
+
var Link = (props) => {
|
|
4163
|
+
const { url, children } = props;
|
|
4164
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4165
|
+
"span",
|
|
4166
|
+
{
|
|
4167
|
+
onClick: () => window.open(url),
|
|
4168
|
+
className: "oui-cursor-pointer oui-px-0.5 oui-text-primary-light oui-underline",
|
|
4169
|
+
children
|
|
4170
|
+
}
|
|
4171
|
+
);
|
|
4172
|
+
};
|
|
4173
|
+
var NoTradingview = () => {
|
|
4174
|
+
const { t } = orderlyI18n.useTranslation();
|
|
4175
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-absolute oui-inset-0 oui-z-0 oui-flex oui-flex-col oui-items-center oui-justify-start oui-p-2 oui-text-base-contrast-80 md:oui-justify-center md:oui-p-10", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
4176
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "oui-mb-6 oui-text-xs", children: t("tradingView.noScriptSrc") }),
|
|
4177
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "oui-mb-3 oui-pl-0 oui-text-2xs oui-text-base-contrast-54 md:oui-pl-2 md:oui-text-base md:oui-text-base-contrast-80", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4178
|
+
orderlyI18n.Trans,
|
|
4179
|
+
{
|
|
4180
|
+
i18nKey: "tradingView.noScriptSrc.1",
|
|
4181
|
+
components: [
|
|
4182
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4183
|
+
Link,
|
|
4184
|
+
{
|
|
4185
|
+
url: "https://www.tradingview.com/advanced-charts"
|
|
4186
|
+
},
|
|
4187
|
+
"tradingview-advanced-charts"
|
|
4188
|
+
)
|
|
4189
|
+
]
|
|
4190
|
+
}
|
|
4191
|
+
) }),
|
|
4192
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "oui-pl-0 oui-text-2xs oui-text-base-contrast-54 md:oui-pl-2 md:oui-text-base md:oui-text-base-contrast-80", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4193
|
+
orderlyI18n.Trans,
|
|
4194
|
+
{
|
|
4195
|
+
i18nKey: "tradingView.noScriptSrc.2",
|
|
4196
|
+
components: [
|
|
4197
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4198
|
+
Link,
|
|
4199
|
+
{
|
|
4200
|
+
url: "https://orderly.network/docs/sdks/react/components/trading#tradingviewconfig"
|
|
4201
|
+
},
|
|
4202
|
+
"tradingview-config"
|
|
4203
|
+
)
|
|
4204
|
+
]
|
|
4205
|
+
}
|
|
4206
|
+
) })
|
|
4207
|
+
] }) });
|
|
4208
|
+
};
|
|
4209
|
+
var TopBar = (props) => {
|
|
4210
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "top-toolbar oui-flex oui-h-[44px] oui-justify-between md:oui-justify-start oui-items-center oui-p-2 md:oui-px-3 md:oui-pt-3 md:oui-pb-[14px]", children: props.children });
|
|
4211
|
+
};
|
|
4212
|
+
var topBar_default = TopBar;
|
|
4213
|
+
var LazyLineType = React3__default.default.lazy(() => Promise.resolve().then(() => (init_lineType(), lineType_exports)));
|
|
4214
|
+
var LazyTimeInterval = React3__default.default.lazy(
|
|
4215
|
+
() => Promise.resolve().then(() => (init_timeInterval(), timeInterval_exports)).then((mod) => ({ default: mod.TimeInterval }))
|
|
4216
|
+
);
|
|
4217
|
+
var LazyMobileDisplayControl = React3__default.default.lazy(
|
|
4218
|
+
() => Promise.resolve().then(() => (init_displayControl(), displayControl_exports)).then((mod) => ({
|
|
4219
|
+
default: mod.MobileDisplayControl
|
|
4220
|
+
}))
|
|
4221
|
+
);
|
|
4222
|
+
var LazyDesktopDisplayControl = React3__default.default.lazy(
|
|
4223
|
+
() => Promise.resolve().then(() => (init_displayControl(), displayControl_exports)).then((mod) => ({
|
|
4224
|
+
default: mod.DesktopDisplayControl
|
|
4225
|
+
}))
|
|
4226
|
+
);
|
|
4227
|
+
var OperateButton = ({ children, onClick }) => {
|
|
4228
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4229
|
+
orderlyUi.Box,
|
|
4230
|
+
{
|
|
4231
|
+
onClick,
|
|
4232
|
+
className: "oui-cursor-pointer oui-w-[18px] oui-h-[18px] oui-text-base-contrast-36 hover:oui-text-base-contrast-80",
|
|
4233
|
+
children
|
|
4234
|
+
}
|
|
4235
|
+
);
|
|
4236
|
+
};
|
|
4237
|
+
var ZoomOutIcon = (props) => {
|
|
4238
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4239
|
+
"svg",
|
|
4240
|
+
{
|
|
4241
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
4242
|
+
width: "18",
|
|
4243
|
+
height: "18",
|
|
4244
|
+
viewBox: "0 0 18 18",
|
|
4245
|
+
fill: "currentColor",
|
|
4246
|
+
...props,
|
|
4247
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M15.0008 2.24304C14.8088 2.24304 14.6085 2.30755 14.4615 2.4538L11.2508 5.66455V3.74304H9.75079V7.49304C9.75079 7.90704 10.0868 8.24304 10.5008 8.24304H14.2508V6.74304H12.3285L15.54 3.53229C15.8325 3.23904 15.8325 2.74705 15.54 2.4538C15.393 2.30755 15.1928 2.24304 15.0008 2.24304ZM3.7508 9.74303V11.243H5.67231L2.46156 14.4538C2.16906 14.747 2.16906 15.239 2.46156 15.5323C2.75481 15.8248 3.2468 15.8248 3.54005 15.5323L6.7508 12.3215V14.243H8.25079V10.493C8.25079 10.079 7.9148 9.74303 7.5008 9.74303H3.7508Z" })
|
|
4248
|
+
}
|
|
4249
|
+
);
|
|
4250
|
+
};
|
|
4251
|
+
var ZoomInIcon = (props) => {
|
|
4252
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4253
|
+
"svg",
|
|
4254
|
+
{
|
|
4255
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
4256
|
+
width: "18",
|
|
4257
|
+
height: "18",
|
|
4258
|
+
viewBox: "0 0 18 18",
|
|
4259
|
+
fill: "currentColor",
|
|
4260
|
+
...props,
|
|
4261
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M7.49219 9.74304C7.30026 9.74304 7.09964 9.80755 6.95309 9.9538L3.74219 13.1646V11.243H2.24219V14.993C2.24219 15.407 2.57796 15.743 2.99219 15.743H6.74219V14.243H4.82031L8.03121 11.0323C8.32416 10.739 8.32416 10.247 8.03121 9.9538C7.88481 9.80755 7.68404 9.74304 7.49219 9.74304ZM11.2509 2.24304V3.74304H13.1728L9.96186 6.9538C9.66899 7.24705 9.66899 7.73904 9.96186 8.03229C10.2547 8.32479 10.7471 8.32479 11.04 8.03229L14.2509 4.82153V6.74304H15.7509V2.99304C15.7509 2.57904 15.4151 2.24304 15.0009 2.24304H11.2509Z" })
|
|
4262
|
+
}
|
|
4263
|
+
);
|
|
4264
|
+
};
|
|
4265
|
+
var TradingviewUI = React3.forwardRef((props, ref) => {
|
|
4266
|
+
const {
|
|
4267
|
+
chartRef,
|
|
4268
|
+
interval,
|
|
4269
|
+
changeDisplaySetting,
|
|
4270
|
+
displayControlState,
|
|
4271
|
+
tradingViewScriptSrc,
|
|
4272
|
+
changeInterval,
|
|
4273
|
+
lineType,
|
|
4274
|
+
changeLineType,
|
|
4275
|
+
openChartSetting,
|
|
4276
|
+
openChartIndicators,
|
|
4277
|
+
onFullScreenChange
|
|
4278
|
+
} = props;
|
|
4279
|
+
const isMobile = orderlyHooks.useMediaQuery(orderlyTypes.MEDIA_TABLET);
|
|
4280
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4281
|
+
"div",
|
|
4282
|
+
{
|
|
4283
|
+
ref,
|
|
4284
|
+
className: orderlyUi.cn("oui-relative oui-size-full", props.classNames?.root),
|
|
4285
|
+
children: !tradingViewScriptSrc ? /* @__PURE__ */ jsxRuntime.jsx(NoTradingview, {}) : /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4286
|
+
"div",
|
|
4287
|
+
{
|
|
4288
|
+
className: orderlyUi.cn(
|
|
4289
|
+
"oui-absolute oui-inset-0 oui-z-[1] oui-flex oui-flex-col",
|
|
4290
|
+
props.classNames?.content
|
|
4291
|
+
),
|
|
4292
|
+
children: [
|
|
4293
|
+
/* @__PURE__ */ jsxRuntime.jsx(topBar_default, { children: isMobile ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4294
|
+
orderlyUi.Flex,
|
|
4295
|
+
{
|
|
4296
|
+
gapX: 2,
|
|
4297
|
+
width: "100%",
|
|
4298
|
+
justify: "between",
|
|
4299
|
+
className: "oui-hide-scrollbar oui-overflow-x-scroll",
|
|
4300
|
+
children: [
|
|
4301
|
+
/* @__PURE__ */ jsxRuntime.jsx(React3__default.default.Suspense, { fallback: null, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4302
|
+
LazyTimeInterval,
|
|
4303
|
+
{
|
|
4304
|
+
interval: interval ?? "15",
|
|
4305
|
+
changeInterval
|
|
4306
|
+
}
|
|
4307
|
+
) }),
|
|
4308
|
+
/* @__PURE__ */ jsxRuntime.jsx(OperateButton, { onClick: openChartIndicators, children: /* @__PURE__ */ jsxRuntime.jsx(IndicatorsIcon, {}) }),
|
|
4309
|
+
/* @__PURE__ */ jsxRuntime.jsx(React3__default.default.Suspense, { fallback: null, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4310
|
+
LazyMobileDisplayControl,
|
|
4311
|
+
{
|
|
4312
|
+
displayControlState,
|
|
4313
|
+
changeDisplayControlState: changeDisplaySetting
|
|
4314
|
+
}
|
|
4315
|
+
) })
|
|
4316
|
+
]
|
|
4317
|
+
}
|
|
4318
|
+
) : /* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { justify: "between", itemAlign: "center", width: "100%", children: [
|
|
4319
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { children: [
|
|
4320
|
+
/* @__PURE__ */ jsxRuntime.jsx(React3__default.default.Suspense, { fallback: null, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4321
|
+
LazyTimeInterval,
|
|
4322
|
+
{
|
|
4323
|
+
interval: interval ?? "1",
|
|
4324
|
+
changeInterval
|
|
4325
|
+
}
|
|
4326
|
+
) }),
|
|
4327
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4328
|
+
orderlyUi.Divider,
|
|
4329
|
+
{
|
|
4330
|
+
direction: "vertical",
|
|
4331
|
+
className: "oui-h-4",
|
|
4332
|
+
mx: 2,
|
|
4333
|
+
intensity: 8
|
|
4334
|
+
}
|
|
4335
|
+
),
|
|
4336
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { justify: "start", itemAlign: "center", gap: 2, children: [
|
|
4337
|
+
/* @__PURE__ */ jsxRuntime.jsx(React3__default.default.Suspense, { fallback: null, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4338
|
+
LazyDesktopDisplayControl,
|
|
4339
|
+
{
|
|
4340
|
+
displayControlState,
|
|
4341
|
+
changeDisplayControlState: changeDisplaySetting
|
|
4342
|
+
}
|
|
4343
|
+
) }),
|
|
4344
|
+
/* @__PURE__ */ jsxRuntime.jsx(OperateButton, { onClick: openChartIndicators, children: /* @__PURE__ */ jsxRuntime.jsx(IndicatorsIcon, {}) }),
|
|
4345
|
+
/* @__PURE__ */ jsxRuntime.jsx(React3__default.default.Suspense, { fallback: null, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4346
|
+
LazyLineType,
|
|
4347
|
+
{
|
|
4348
|
+
lineType,
|
|
4349
|
+
changeLineType
|
|
4350
|
+
}
|
|
4351
|
+
) }),
|
|
4352
|
+
/* @__PURE__ */ jsxRuntime.jsx(OperateButton, { onClick: openChartSetting, children: /* @__PURE__ */ jsxRuntime.jsx(SettingIcon, {}) })
|
|
4353
|
+
] })
|
|
4354
|
+
] }),
|
|
4355
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Flex, { children: props.fullscreen ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
4356
|
+
ZoomOutIcon,
|
|
4357
|
+
{
|
|
4358
|
+
className: "oui-text-base-contrast-54 hover:oui-text-base-contrast oui-cursor-pointer",
|
|
4359
|
+
onClick: onFullScreenChange
|
|
4360
|
+
}
|
|
4361
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
4362
|
+
ZoomInIcon,
|
|
4363
|
+
{
|
|
4364
|
+
className: "oui-text-base-contrast-54 hover:oui-text-base-contrast oui-cursor-pointer",
|
|
4365
|
+
onClick: onFullScreenChange
|
|
4366
|
+
}
|
|
4367
|
+
) })
|
|
4368
|
+
] }) }),
|
|
4369
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { ref: chartRef, className: "oui-size-full oui-overflow-hidden" })
|
|
4370
|
+
]
|
|
4371
|
+
}
|
|
4372
|
+
)
|
|
4373
|
+
}
|
|
4374
|
+
);
|
|
4375
|
+
});
|
|
4376
|
+
var TradingviewWidget = React3.forwardRef((props, ref) => {
|
|
4377
|
+
const state = useTradingviewScript(props);
|
|
4378
|
+
return /* @__PURE__ */ jsxRuntime.jsx(TradingviewUI, { ...state, ref });
|
|
4379
|
+
});
|
|
4380
|
+
|
|
4381
|
+
exports.TradingviewUI = TradingviewUI;
|
|
4382
|
+
exports.TradingviewWidget = TradingviewWidget;
|
|
4383
|
+
exports.useTradingviewScript = useTradingviewScript;
|
|
21
4384
|
//# sourceMappingURL=out.js.map
|
|
22
4385
|
//# sourceMappingURL=index.js.map
|