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) 2.94 kB
import{d as G,u as F,a as L,b as d,t as u,c as C,j as e,B as A,C as w,e as S,f as m,i as Q,k as v,r as y,S as k,D as N,l as z,G as l,x as D,y as E,z as R,R as O,m as T,A as U,n as q,o as H,p as W,s as M,h as J,g as K,q as V,F as X,H as Y,E as Z,w as _}from"./index-Du-vO1Hr.js";import{s as $,a as P,b as ee,c as se,d as te,e as ie,f as ne,F as re,S as ae,A as oe,I as ce,g as de,B as le,h as ue,i as me,G as ge}from"./SimpleGridForm-CGmW235V.js";function he(c){const{gridLines:s,symbolId:t,exchangeAccountId:a,botName:i}=c,{currencyPairSymbol:r}=G(t);return{botId:c.botId,data:{name:i,settings:{gridLines:s},symbol:r,exchangeAccountId:a}}}const pe=()=>{const{showSnackbar:c}=F(),s=L(),t=d($),{mutate:a,isLoading:i}=u.gridBot.update.useMutation({onSuccess(o){c("Bot updated successfully"),setTimeout(()=>{s({to:C("grid-bot/:id",o.id)})},1e3)}}),r=()=>{const o=he(t);a(o)};return e.jsx(A,{color:"primary",disabled:i,onClick:r,startDecorator:i?e.jsx(w,{size:"md"}):null,type:"submit",variant:"outlined",children:"Update"})},be=()=>{const c=S(),s=d(P),{data:t}=u.symbol.getOne.useQuery({symbolId:s},{refetchOnWindowFocus:!1}),a=d(ee),i=d(se),r=d(te),o=d(ie);if([m(a),m(i),m(r),m(o),m(t)].includes(!0)&&t){const n=ne(a,i,r,Number(o),t.filters);c(Q(n))}return e.jsxs(v,{sx:{padding:0},children:[e.jsx(re,{advancedForm:e.jsx(y.Suspense,{fallback:e.jsx(k,{height:60,variant:"rectangular",width:"100%"}),children:e.jsx(oe,{})}),simpleForm:e.jsx(ae,{})}),e.jsx(N,{}),e.jsx(z,{sx:{px:2,pt:1,pb:2},children:e.jsxs(l,{container:!0,spacing:2,children:[e.jsx(l,{xs:12,children:e.jsx(y.Suspense,{fallback:e.jsx(de,{withLabel:!0}),children:e.jsx(ce,{})})}),e.jsx(l,{xs:12,children:e.jsx(le,{})}),e.jsx(l,{xs:12,children:e.jsx(pe,{})})]})})]})};function xe(c){var p,h;const[s]=u.gridBot.getOne.useSuspenseQuery(c),[t]=u.exchangeAccount.getOne.useSuspenseQuery(s.exchangeAccountId),a=D(t.exchangeCode,R(s.symbol),E(s.symbol)),[i]=u.symbol.getOne.useSuspenseQuery({symbolId:a}),[r]=u.symbol.price.useSuspenseQuery({symbolId:i.symbolId}),o=r.price*.3,g=(p=s.settings.gridLines[0])==null?void 0:p.price,n=(h=s.settings.gridLines[s.settings.gridLines.length-1])==null?void 0:h.price;return{bot:s,exchangeAccount:t,symbol:i,currentPrice:r,lowPrice:g||r.price-o,highPrice:n||r.price+o}}function Pe(){var x;const{id:c}=O.useParams(),s=Number(c),{bot:t,exchangeAccount:a,symbol:i,lowPrice:r,highPrice:o,currentPrice:g}=xe(s),n=S();if(T()){const b=(x=i.filters.limits.amount)!=null&&x.min?i.filters.limits.amount.min*10:"",B=U(t.settings.gridLines)||b||"";n(q(a.id)),n(H(a.exchangeCode)),n(W(i.symbolId)),n(M(B.toString())),n(J(r)),n(K(o)),n(V(t.name)),n(X(t.id)),n(Y(t.settings.gridLines))}const h=d(P),j=d(ue),I=b=>n(_(b)),f=d(me);return e.jsx(l,{container:!0,spacing:2,children:e.jsxs(Z,{children:[e.jsx(l,{md:9,children:e.jsx(ge,{barSize:j,defaultPrice:g,gridLines:f,onBarSizeChange:I,symbolId:h})}),e.jsx(l,{md:3,children:e.jsx(be,{})})]})})}export{Pe as default};