UNPKG

opentrader

Version:

OpenTrader is a powerful open-source crypto trading bot designated to automate your trading strategies on various cryptocurrency exchanges.

2 lines (1 loc) 12.5 kB
import{I as h,X as y,J as O,K as Y,r as u,L as ee,M as te,_ as v,N as ne,O as se,P as re,Q as ae,T as oe,U as ie,V as le,j as s,W as w,Y as ce,e as f,t as b,b as m,Z as ue,n as de,o as he,$ as me,a0 as xe,S as F,a1 as pe,a2 as ge,a3 as fe,a4 as be,a5 as ye,l as je,a6 as ve,a7 as Ce,a8 as Se,a9 as Pe,aa as $,ab as Fe,ac as Ie,ad as L,ae as N,af as T,ag as we,ah as Be,ai as M,aj as V,v as Ge,B as W,ak as Le,al as A,am as Ne,an as H,ao as Te,G as g,ap as Ae,d as _,aq as qe,ar as Ee,as as ze,at as Qe}from"./index-Du-vO1Hr.js";function ke(e,n,t){return h(e).minus(n).div(t-1).toNumber()}function Re(e,n,t,r){const a=ke(e,n,t);return Array.from({length:t}).map((i,o)=>({price:h(n).plus(h(a).mul(o)).toNumber(),quantity:r}))}function U(e,n){return e=String(e),n!=null&&n.ignoreTrailingZeros&&(e=new h(e).toString()),e.includes(".")?e.split(".")[1].length:0}function G(e,n){const t=n.decimals.price,r=U(e,{ignoreTrailingZeros:!0});return t===void 0?new h(e).toFixed(r):r>t?new h(e).toFixed(t,h.roundDown):new h(e).toFixed(r)}function $e(e,n){const t=n.decimals.amount,r=U(e,{ignoreTrailingZeros:!0});return t===void 0?new h(e).toFixed(r):r>t?new h(e).toFixed(t,h.roundDown):new h(e).toFixed(r)}function St(e,n,t,r,a){return Re(e,n,t,r).map(o=>{const l=G(o.price,a);return{...o,price:new h(l).toNumber()}})}function Ve(e){const n=e.reduce((r,a)=>a.buy.status===y.Filled&&a.sell.status===y.Idle?h(r).plus(a.sell.quantity).toNumber():r,0),t=e.reduce((r,a)=>{if(a.buy.status===y.Idle&&a.sell.status===y.Idle){const o=h(a.buy.quantity).times(a.buy.price);return h(r).plus(o).toNumber()}return r},0);return{baseCurrencyAmount:n,quoteCurrencyAmount:t}}function De(e,n,t){const r=n.findIndex(c=>c.price===e.price&&c.quantity===e.quantity);if(r===-1)throw new Error(`Cannot find grid line index of { price: ${e.price}, quantity: ${e.quantity} }`);const a=n[r],i=n[r-1],o=n[r+1],l=h(t).minus(a.price).abs();if(i){const c=h(t).minus(i.price).abs();if(h(c).lt(l))return!1}if(o){const c=h(t).minus(o.price).abs();if(h(c).lte(l))return!1}return!0}function Oe(e,n){const t=e[n+1];if(!t)throw new Error(`nextGridLinePrice: Grid line at index ${n} doesn't exists`);return t.price}function Me(e,n){return e.flatMap((t,r)=>{if(r===e.length-1)return[];const a=Oe(e,r);return De(t,e,n)||t.price>n?[{buy:{price:t.price,quantity:t.quantity,status:y.Filled},sell:{price:a,quantity:t.quantity,status:y.Idle}}]:[{buy:{price:t.price,quantity:t.quantity,status:y.Idle},sell:{price:a,quantity:t.quantity,status:y.Idle}}]})}function We(e,n,t){const r=Me(n,t),{baseCurrencyAmount:a,quoteCurrencyAmount:i}=Ve(r),o=i+a*t;return{baseCurrencyAmount:$e(a,e.filters),quoteCurrencyAmount:G(i,e.filters),totalInQuoteCurrency:G(o,e.filters)}}const Pt=e=>e.gridBotForm,He=e=>e.gridBotForm.type,_e=e=>e.gridBotForm.exchangeAccountId,Ue=e=>e.gridBotForm.exchangeCode,j=e=>e.gridBotForm.symbolId,Ze=e=>e.gridBotForm.highPrice,Je=e=>e.gridBotForm.lowPrice,Xe=e=>e.gridBotForm.gridLinesNumber,Ke=e=>e.gridBotForm.quantityPerGrid,Ye=e=>e.gridBotForm.botName,q=e=>e.gridBotForm.gridLines,Z=e=>n=>n.gridBotForm.gridLines[e],Ft=e=>e.gridBotForm.barSize;function et(e){return e.size}function tt(e){const{value:n,id:t,rootRef:r}=e,a=O();if(a===null)throw new Error("No TabContext provided");const{value:i,getTabId:o}=a,l=Y(t),c=u.useRef(null),d=ee(c,r),p=u.useMemo(()=>({id:l,ref:c}),[l]),{id:x}=te(n??et,p),C=x!==i,I=x!==void 0?o(x):void 0;return{hidden:C,getRootProps:(B={})=>v({"aria-labelledby":I??void 0,hidden:C,id:l??void 0},B,{ref:d}),rootRef:d}}function nt(e){return ne("MuiTabPanel",e)}se("MuiTabPanel",["root","hidden","sizeSm","sizeMd","sizeLg","horizontal","vertical","colorPrimary","colorNeutral","colorDanger","colorSuccess","colorWarning","colorContext","variantPlain","variantOutlined","variantSoft","variantSolid"]);const st=["children","value","component","color","variant","size","slots","slotProps","keepMounted"],rt=e=>{const{hidden:n,size:t,variant:r,color:a,orientation:i}=e,o={root:["root",n&&"hidden",t&&`size${w(t)}`,i,r&&`variant${w(r)}`,a&&`color${w(a)}`,t&&`size${w(t)}`]};return ce(o,nt,{})},at=le("div",{name:"JoyTabPanel",slot:"Root",overridesResolver:(e,n)=>n.root})(({theme:e,ownerState:n})=>{var t;return v({display:n.hidden?"none":"block",padding:"var(--Tabs-spacing)",flexGrow:1,fontFamily:e.vars.fontFamily.body},e.typography[`body-${n.size}`],(t=e.variants[n.variant])==null?void 0:t[n.color])}),D=u.forwardRef(function(n,t){const r=re({props:n,name:"JoyTabPanel"}),{orientation:a}=O()||{orientation:"horizontal"},i=u.useContext(ae),{children:o,value:l=0,component:c,color:d="neutral",variant:p="plain",size:x,slots:C={},slotProps:I={},keepMounted:E=!1}=r,B=oe(r,st),{hidden:z,getRootProps:J}=tt(v({},r,{value:l})),Q=v({},r,{orientation:a,hidden:z,size:x??i,color:d,variant:p}),X=rt(Q),K=v({},B,{component:c,slots:C,slotProps:I}),[k,R]=ie("root",{ref:t,elementType:at,getSlotProps:J,externalForwardedProps:K,additionalProps:{role:"tabpanel",ref:t,as:c},ownerState:Q,className:X.root});return E?s.jsx(k,v({},R,{children:o})):s.jsx(k,v({},R,{children:!z&&o}))}),ot=({disabled:e})=>{const n=f(),[t]=b.exchangeAccount.list.useSuspenseQuery(),r=m(_e),a=o=>{if(o===null)throw new Error("ExchangeAccountField: Cannot reset exchange account input");n(de(o.id)),n(he(o.exchangeCode))},i=t.find(o=>o.id===r);return s.jsx(ue,{onChange:a,value:i,disabled:e})},it=({disabled:e})=>{const n=f(),t=m(Ue),[r]=b.symbol.list.useSuspenseQuery(t),a=m(j),i=l=>{if(l===null)throw new Error("PairField: Cannot reset symbol input");n(xe(l.symbolId))},o=r.find(l=>l.symbolId===a);return s.jsx(me,{exchangeCode:t,onChange:i,value:o||null,disabled:e})},lt=36,P=({width:e="100%",withLabel:n})=>{const t=s.jsx(F,{animation:"wave",height:lt,variant:"rectangular",width:e});return n?s.jsxs(s.Fragment,{children:[s.jsx(F,{animation:"wave",height:20,sx:{mb:"6px"},variant:"text",width:72}),t]}):t};function ct(e,n){if(e.length===0)return-1;if(e.length===1)return e[0];const t=e.map(i=>Math.abs(i-n)),r=Math.min(...t),a=t.indexOf(r);return e[a]}function ut(e,n){const t=e.map(a=>a.price),r=ct(t,n);return t.map(a=>pe(a,t,r))}const It=({symbolId:e,barSize:n,onBarSizeChange:t,gridLines:r,defaultPrice:a})=>{const i=u.useDeferredValue(e),o=e!==i,{data:{price:l}}=b.symbol.price.useQuery({symbolId:e},{initialData:a}),c=u.useMemo(()=>ut(r,l),[r,l]),[d,p]=u.useState(!0);return s.jsx(u.Suspense,{fallback:s.jsx(F,{animation:"wave",height:Ce,variant:"rectangular",width:"100%"}),children:s.jsxs(ge,{barSize:n,dimmed:o,priceLines:c,showPriceLines:d,symbolId:i,children:[s.jsx(u.Suspense,{fallback:s.jsx(P,{width:232}),children:s.jsx(ot,{})}),s.jsx(u.Suspense,{fallback:s.jsx(P,{width:232}),children:s.jsx(it,{})}),s.jsx(fe,{onChange:x=>{t&&t(x)},value:n,whitelist:be}),s.jsx(ye,{}),s.jsx(je,{display:"flex",children:s.jsx(ve,{gridVisible:d,hideTradesButton:!0,onGridVisibleChange:p})})]})})},S={simple:"simple",advanced:"advanced"},wt=({simpleForm:e,advancedForm:n})=>{const t=m(He),r=f(),a=(i,o)=>{o!==null&&r(Ie(o))};return s.jsxs(Se,{defaultValue:S.simple,onChange:(i,o)=>{a(i,o)},sx:{borderRadius:"md",overflow:"auto",boxShadow:"sm"},value:t,children:[s.jsxs(Pe,{disableUnderline:!0,sx:{[`& .${Fe.root}`]:{bgcolor:"background.backdrop",'&[aria-selected="true"]':{bgcolor:"background.surface",fontWeight:"lg"}}},tabFlex:"auto",children:[s.jsx($,{disableIndicator:!0,value:S.simple,children:"Easy form"}),s.jsx($,{disableIndicator:!0,value:S.advanced,children:"Advanced form"})]}),s.jsx(D,{value:S.simple,children:e}),s.jsx(D,{value:S.advanced,children:n})]})},Bt=()=>{const e=f(),n=m(Ye),[t,r]=u.useState(n);u.useEffect(()=>{r(n)},[n]);const a=c=>{r(c.target.value)},i=()=>{t.length>0?e(V(t)):r(n)},o=()=>{e(V(Ge()))},l=t.length===0?"Must be defined":null;return s.jsxs(L,{error:!!l,children:[s.jsx(N,{children:"Bot name"}),s.jsx(T,{endDecorator:s.jsx(we,{onClick:o,children:s.jsx(Be,{})}),onBlur:i,onChange:a,value:t}),l?s.jsx(M,{children:l}):null]})},dt=e=>{const{className:n,gridLineIndex:t}=e,r=f(),a=()=>{r(Le(t))};return s.jsx(W,{className:n,color:"danger",onClick:a,size:"sm",children:"Remove"})},ht=e=>{const{className:n,gridLineIndex:t}=e,r=f(),{price:a}=m(Z(t)),[i,o]=u.useState(String(a));u.useEffect(()=>{o(`${a}`)},[a]);const l=m(j),[c]=b.symbol.getOne.useSuspenseQuery({symbolId:l}),d=x=>{o(x.target.value)},p=()=>{i.length>0?r(Ne({gridLineIndex:t,price:Number(i)})):o(String(a))};return s.jsx(A,{className:n,filter:c.filters,fullWidth:!0,label:"Price",onBlur:p,onChange:d,size:"sm",value:i})},mt=e=>{const{className:n,gridLineIndex:t,disabled:r}=e,a=f(),i=m(j),[o]=b.symbol.getOne.useSuspenseQuery({symbolId:i}),{quantity:l}=m(Z(t)),[c,d]=u.useState(`${l}`);u.useEffect(()=>{d(`${l}`)},[l]);const p=C=>{d(C.target.value)},x=()=>{isNaN(Number(c))?d(`${l}`):a(Te({gridLineIndex:t,quantity:Number(c)}))};return s.jsx(H,{className:n,disabled:r,filter:o.filters,fullWidth:!0,label:"Quantity",onBlur:x,onChange:p,size:"sm",value:c})},xt=e=>{const{gridLineIndex:n}=e,t=m(q),r=n===t.length-1;return s.jsxs(g,{alignItems:"flex-end",container:!0,spacing:2,children:[s.jsx(g,{xs:!0,children:s.jsx(u.Suspense,{fallback:s.jsx(F,{height:36,variant:"rectangular",width:200}),children:s.jsx(ht,{gridLineIndex:n})})}),s.jsx(g,{xs:!0,children:s.jsx(u.Suspense,{fallback:s.jsx(F,{height:36,variant:"rectangular",width:200}),children:s.jsx(mt,{disabled:r,gridLineIndex:n})})}),s.jsx(g,{xs:"auto",children:s.jsx(dt,{gridLineIndex:n})})]})},Gt=()=>{const e=f(),n=m(q),t=()=>{e(Ae({price:1,quantity:1}))},r=a=>n.length-1-a;return s.jsxs(g,{container:!0,spacing:2,children:[s.jsx(g,{xs:12,children:n.map((a,i)=>s.jsx(xt,{gridLineIndex:r(i)},i))}),s.jsx(g,{xs:12,children:s.jsx(W,{onClick:t,children:"Add"})})]})},pt=({baseCurrencyAmount:e,quoteCurrencyAmount:n,totalInQuoteCurrency:t})=>{const r=m(j),{baseCurrency:a,quoteCurrency:i}=_(r);return s.jsxs(M,{children:[s.jsxs("span",{children:[e," ",a]}),s.jsx("span",{children:" + "}),s.jsxs("span",{children:[n," ",i]}),s.jsx("span",{children:" ≈ "}),s.jsxs("span",{children:[t," ",i]})]})},Lt=e=>{const{className:n}=e,t=m(j),{quoteCurrency:r}=_(t),[a]=b.symbol.price.useSuspenseQuery({symbolId:t}),[i]=b.symbol.getOne.useSuspenseQuery({symbolId:t}),o=m(q),{baseCurrencyAmount:l,quoteCurrencyAmount:c,totalInQuoteCurrency:d}=We(i,o,a.price),p="investment-field";return s.jsxs(L,{className:n,children:[s.jsx(N,{htmlFor:p,children:"Investment"}),s.jsx(T,{disabled:!0,endDecorator:s.jsx(s.Fragment,{children:r}),id:p,type:"number",value:d}),s.jsx(pt,{baseCurrencyAmount:l,quoteCurrencyAmount:c,totalInQuoteCurrency:d})]})},gt=e=>{const{disabled:n,readOnly:t}=e,r=m(j),[a]=b.symbol.getOne.useSuspenseQuery({symbolId:r}),i=f(),o=m(Ke),[l,c]=u.useState(o);u.useEffect(()=>{c(o)},[o]);const d=x=>{c(x.target.value)},p=()=>{isNaN(Number(l))?c(o):i(qe(l))};return s.jsx(H,{disabled:n,filter:a.filters,fullWidth:!0,label:"Quantity per grid",onBlur:p,onChange:d,readOnly:t,required:!0,value:l})},ft="gridLevels",bt=e=>{const{disabled:n,readOnly:t}=e,r=f(),a=m(Xe),[i,o]=u.useState(a),l=d=>{o(d.target.valueAsNumber)},c=()=>{Number.isInteger(i)?r(Ee(i)):o(a)};return s.jsxs(L,{children:[s.jsx(N,{children:"Grid levels"}),s.jsx(T,{autoComplete:"off",disabled:n,name:ft,onBlur:c,onChange:l,readOnly:t,required:!0,type:"number",value:i})]})},yt=e=>{const{disabled:n,readOnly:t}=e,r=m(j),[a]=b.symbol.getOne.useSuspenseQuery({symbolId:r}),i=f(),o=m(Ze),[l,c]=u.useState(`${o}`);u.useEffect(()=>{c(`${o}`)},[o]);const d=x=>{c(x.target.value)},p=()=>{l.length>0?i(ze(Number(l))):c(`${o}`)};return s.jsx(A,{disabled:n,filter:a.filters,fullWidth:!0,label:"High price",onBlur:p,onChange:d,readOnly:t,value:l})},jt=e=>{const{disabled:n,readOnly:t}=e,r=m(j),[a]=b.symbol.getOne.useSuspenseQuery({symbolId:r}),i=f(),o=m(Je),[l,c]=u.useState(`${o}`);u.useEffect(()=>{c(`${o}`)},[o]);const d=x=>{c(x.target.value)},p=()=>{l.length>0?i(Qe(Number(l))):c(`${o}`)};return s.jsx(A,{disabled:n,filter:a.filters,fullWidth:!0,label:"Low price",onBlur:p,onChange:d,readOnly:t,value:l})},Nt=()=>s.jsxs(g,{container:!0,spacing:2,children:[s.jsx(g,{md:6,xs:12,children:s.jsx(u.Suspense,{fallback:s.jsx(P,{withLabel:!0}),children:s.jsx(yt,{})})}),s.jsx(g,{md:6,xs:12,children:s.jsx(u.Suspense,{fallback:s.jsx(P,{withLabel:!0}),children:s.jsx(jt,{})})}),s.jsx(g,{md:6,xs:12,children:s.jsx(u.Suspense,{fallback:s.jsx(P,{withLabel:!0}),children:s.jsx(gt,{})})}),s.jsx(g,{md:6,xs:12,children:s.jsx(bt,{})})]});export{Gt as A,Bt as B,wt as F,It as G,Lt as I,Nt as S,j as a,Ze as b,Je as c,Xe as d,Ke as e,St as f,P as g,Ft as h,q as i,Pt as s};