-
Notifications
You must be signed in to change notification settings - Fork 6
/
bots.df31ac96411d7fac0610.js
1 lines (1 loc) · 50.9 KB
/
bots.df31ac96411d7fac0610.js
1
"use strict";(this.webpackChunkRuDEX3_light=this.webpackChunkRuDEX3_light||[]).push([[851],{99123:(e,t,a)=>{a.r(t),a.d(t,{default:()=>K});var s=a(67294),n=a(99111),l=a(55420);const o={db:new Proxy(l.Apis,{get:(e,t)=>function(){return e.instance().db_api().exec(t,[...arguments])}}),history:new Proxy(l.Apis,{get:(e,t)=>function(){return e.instance().history_api().exec(t,[...arguments])}}),network:new Proxy(l.Apis,{get:(e,t)=>function(){return e.instance().network_api().exec(t,[...arguments])}}),crypto:new Proxy(l.Apis,{get:(e,t)=>function(){return e.instance().crypto_api().exec(t,[...arguments])}}),orders:new Proxy(l.Apis,{get:(e,t)=>function(){return e.instance().orders_api().exec(t,[...arguments])}})},i=new Proxy({},class{static get(e,t){return this[t]?this[t]:/^1\.3\.\d+$/.test(t)||!isNaN(t)?this.id(t):this.getAsset(t)}static async getAsset(e){let t=e.toUpperCase();if(this.map=this.map||{},this.map[t])return this.map[t];let a=(await o.db.list_assets(t,1))[0];if(!a||a.symbol!==t)throw new Error(`Not found asset ${t}! Blockchain return ${a?a.symbol:a}`);return this.map[t]=new this(a),this.map[t]}static async id(e){this.map=this.map||{};let t=Object.keys(this.map).find((t=>this.map[t].id==e));if(t)return this.map[t];if(t=(await o.db.get_assets([e]))[0],!t)throw new Error(`Not found asset by id ${e}!`);return this.map[t.symbol]=new this(t),this.map[t.symbol]}static async fromParam(e){return{amount:e.amount,asset:await this.id(e.asset_id)}}static async update(){this.map=this.map||{},(await o.db.get_assets(Object.keys(this.map).map((e=>this.map[e].id)))).forEach((e=>Object.assign(this.map[e.symbol],e)))}constructor(e){Object.assign(this,e)}toParam(e=0){return{amount:e,asset_id:this.id}}fee(){return this.options.market_fee_percent/100/100}async update(){Object.assign(this,(await o.db.get_assets([this.id]))[0])}});var r=a(3894),c=a(60820),m=a(60567),d=a(112),h=a.n(d);class u extends s.Component{state={name:null};hidePrefix=e=>{let t=e.split(".");return(0,m.S2)().includes(`${t[0]}.`)&&t.shift(),t.join(".")};UNSAFE_componentWillMount(){this.setAssetName(this.props.name)}UNSAFE_componentWillReceiveProps(e){e.name!==this.props.name&&this.setAssetName(e.name)}setAssetName=async e=>{let t=await i[e];this.setState({name:t.bitasset_data_id?`gp${e}`:e})};render(){return s.createElement("div",null,s.createElement(r.Z,{replaceNoneToBts:!1,maxWidth:30,name:this.props.name}),this.hidePrefix(this.state.name||this.props.name))}}var b=(0,m.sY)().map((e=>({value:e,label:s.createElement(u,{name:e})})));class p extends s.Component{componentDidMount(){this.promiseOptions=(0,n.Z)(this.promiseOptions,200)}onChange=e=>{console.log("onChange",e),this.props.onChange({target:{name:this.props.name,value:e?e.value:""}})};promiseOptions=async e=>{if(e=e.toUpperCase(),0===b.filter((t=>t.value==e)).length&&e){let t=(await o.db.list_assets(e,1))[0];t&&!b.find((e=>e.value==t.symbol))&&b.push({value:t.symbol,label:s.createElement(u,{name:t.symbol})})}return{options:b}};render(){let e=b.find((e=>e.value===this.props.value));return s.createElement("div",{style:{marginBottom:30}},s.createElement(c.Z,{value:e,onChange:this.onChange,loadOptions:this.promiseOptions,searchPromptText:h().translate("bots.asset_selector.wait"),placeholder:h().translate("bots.asset_selector.placeholder")}))}}const g=p;var v=a(58074),E=a.n(v);class f extends s.Component{state={name:"",quoteAsset:"GPH",baseAsset:"RUDEX.USDT",quoteAmount:500,baseAmount:10,baseSpread:10,quoteSpread:10,quoteBalance:5e3,baseBalance:100,percentQuoteAmount:!1,percentBaseAmount:!1,validate:["name"],fromMarket:!1};componentDidMount(){this.assetValidate=(0,n.Z)(this.assetValidate,200)}assetValidate=async e=>{let t=this.state[e],a=(await o.db.list_assets(t,1))[0],s=this.state.validate;t!==a.symbol?s.push(e):s=s.filter((t=>t!==e)),this.setState({validate:s}),this.props.enableCreate(0==this.state.validate.length)};handleChange=e=>{let t=e.target.name,a="checkbox"===e.target.type?e.target.checked:e.target.value;console.log(t,a),["baseAsset","quoteAsset"].includes(t)&&(a=a.toUpperCase()),this.setState({[t]:a},(()=>this.validate(t,a)))};validate=(e,t)=>{let a=this.state.validate;switch(e){case"name":!/^\w+$/.test(t)||W.hasBot(this.props.account,this.props.name,t)?(a.push(e),this.setState({validate:a})):this.setState({validate:a.filter((t=>t!==e))});break;case"baseAsset":case"quoteAsset":0!==t.length?this.assetValidate(e):(a.push(e),this.setState({validate:a}));break;case"baseBalance":case"quoteBalance":"-"!==t&&isNaN(+t)?(a.push(e),this.setState({validate:a})):this.setState({validate:a.filter((t=>t!==e))});break;case"baseAmount":case"quoteAmount":case"baseSpread":case"quoteSpread":""===t||isNaN(+t)?(a.push(e),this.setState({validate:a})):this.setState({validate:a.filter((t=>t!==e))});break;case"defaultPrice":isNaN(+t)?(a.push(e),this.setState({validate:a})):this.setState({validate:a.filter((t=>t!==e))})}console.log(this.state.validate),this.props.enableCreate(0==this.state.validate.length)};render(){return s.createElement("div",null,s.createElement("div",{className:"content-block"},s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.common.name"})),s.createElement("input",{name:"name",id:"name",type:"text",ref:"input",value:this.state.name,onChange:this.handleChange,autoComplete:"name",style:{border:this.state.validate.includes("name")?"1px solid red":"none"}})),s.createElement("div",{className:"grid-block horizontal"},s.createElement("div",{className:"content-block",style:{marginLeft:50}},s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.common.quote"})),s.createElement(g,{name:"quoteAsset",value:this.state.quoteAsset,onChange:this.handleChange}),s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.common.balance"})),s.createElement("input",{name:"quoteBalance",id:"quoteBalance",type:"text",ref:"input",value:this.state.quoteBalance,onChange:this.handleChange,autoComplete:"quoteBalance",style:{marginBottom:30,border:this.state.validate.includes("quoteBalance")?"1px solid red":"none"}}),s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.common.amount"})),s.createElement("div",{onChange:this.handleChange},s.createElement("input",{type:"radio",value:!0,name:"percentQuoteAmount"})," ",s.createElement(E(),{content:"bots.spread_trade.balance_percent"}),s.createElement("br",null),s.createElement("input",{type:"radio",value:!1,name:"percentQuoteAmount",defaultChecked:!0})," ",s.createElement(E(),{content:"bots.spread_trade.balance_value"})),s.createElement("input",{name:"quoteAmount",id:"quoteAmount",type:"text",ref:"input",value:this.state.quoteAmount,onChange:this.handleChange,autoComplete:"quoteAmount",style:{marginBottom:30,border:this.state.validate.includes("quoteAmount")?"1px solid red":"none"}}),s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.spread_trade.spread"})),s.createElement("input",{name:"quoteSpread",id:"quoteSpread",type:"text",ref:"input",value:this.state.quoteSpread,onChange:this.handleChange,autoComplete:"quoteSpread",style:{marginBottom:30,border:this.state.validate.includes("quoteSpread")?"1px solid red":"none"}})),s.createElement("div",{className:"content-block",style:{marginLeft:50}},s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.common.base"})),s.createElement(g,{name:"baseAsset",value:this.state.baseAsset,onChange:this.handleChange}),s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.common.balance"})),s.createElement("input",{name:"baseBalance",id:"baseBalance",type:"text",ref:"input",value:this.state.baseBalance,onChange:this.handleChange,autoComplete:"baseBalance",style:{marginBottom:30,border:this.state.validate.includes("baseBalance")?"1px solid red":"none"}}),s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.common.amount"})),s.createElement("div",{onChange:this.handleChange},s.createElement("input",{type:"radio",value:!0,name:"percentBaseAmount"})," ",s.createElement(E(),{content:"bots.spread_trade.balance_percent"}),s.createElement("br",null),s.createElement("input",{type:"radio",value:!1,name:"percentBaseAmount",defaultChecked:!0})," ",s.createElement(E(),{content:"bots.spread_trade.balance_value"})),s.createElement("input",{name:"baseAmount",id:"baseAmount",type:"text",ref:"input",value:this.state.baseAmount,onChange:this.handleChange,autoComplete:"baseAmount",style:{marginBottom:30,border:this.state.validate.includes("baseAmount")?"1px solid red":"none"}}),s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.spread_trade.spread"})),s.createElement("input",{name:"baseSpread",id:"baseSpread",type:"text",ref:"input",value:this.state.baseSpread,onChange:this.handleChange,autoComplete:"baseSpread",style:{marginBottom:30,border:this.state.validate.includes("baseSpread")?"1px solid red":"none"}}))),s.createElement("div",{className:"content-block"},s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.spread_trade.default_price"})),s.createElement("input",{name:"defaultPrice",id:"defaultPrice",type:"text",ref:"input",value:this.state.defaultPrice,onChange:this.handleChange,autoComplete:"defaultPrice",style:{border:this.state.validate.includes("defaultPrice")?"1px solid red":"none"}})),s.createElement("div",{className:"content-block"},s.createElement("label",null,s.createElement("input",{type:"checkbox",name:"fromMarket",onChange:this.handleChange,checked:this.state.fromMarket}),s.createElement(E(),{content:"bots.spread_trade.get_price_from_market"}))))}}const y=f;var _=a(43129);class C extends s.Component{UNSAFE_componentWillMount(){this.setState(Object.assign({validate:[]},this.props.bot.storage.read()))}handleChange=e=>{let t,a,s=e.target.name,n=e.target.value;switch(s){case"baseAmount":t=this.state.base,t.amount=n,this.setState({base:t});break;case"percentBaseAmount":t=this.state.base,t.percent="true"==n,this.setState({base:t});break;case"baseBalance":t=this.state.base,t.balance=n,this.setState({base:t});break;case"baseSpread":t=this.state.base,t.spread=n,this.setState({base:t});break;case"quoteAmount":a=this.state.quote,a.amount=n,this.setState({quote:a});break;case"percentQuoteAmount":a=this.state.quote,a.percent="true"==n,this.setState({quote:a});break;case"quoteBalance":a=this.state.quote,a.balance=n,this.setState({quote:a});break;case"quoteSpread":a=this.state.quote,a.spread=n,this.setState({quote:a});break;case"defaultPrice":this.setState({defaultPrice:n});break;case"fromMarket":this.setState({fromMarket:e.target.checked})}};handleUpdateBot=()=>{let e=this.props.bot.storage.read();this.state.base.order=e.base.order,this.state.quote.order=e.quote.order,this.props.bot.storage.write(this.state)};render(){return s.createElement("div",null,s.createElement("div",{className:"grid-block horizontal"},s.createElement("div",{className:"content-block",style:{marginLeft:50,marginTop:30}},s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.common.quote"})),s.createElement(_.ZP,{style:{marginBottom:30},name:"quoteAsset",value:{value:this.state.quote.asset,label:s.createElement(u,{name:this.state.quote.asset})},clearable:!1,searchable:!1,disabled:!0}),s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.common.balance"})),s.createElement("input",{name:"quoteBalance",type:"text",ref:"input",value:this.state.quote.balance,onChange:this.handleChange,disabled:this.props.bot.run,style:{marginBottom:30,border:this.state.validate.includes("quoteBalance")?"1px solid red":"none"}}),s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.common.amount"})),s.createElement("div",null,s.createElement("input",{type:"radio",value:!0,name:"percentQuoteAmount",checked:this.state.quote.percent,onChange:this.handleChange})," ",s.createElement(E(),{content:"bots.spread_trade.balance_percent"}),s.createElement("br",null),s.createElement("input",{type:"radio",value:!1,name:"percentQuoteAmount",checked:!this.state.quote.percent,onChange:this.handleChange})," ",s.createElement(E(),{content:"bots.spread_trade.balance_value"})),s.createElement("input",{name:"quoteAmount",type:"text",ref:"input",value:this.state.quote.amount,onChange:this.handleChange,disabled:this.props.bot.run,style:{marginBottom:30,border:this.state.validate.includes("quoteAmount")?"1px solid red":"none"}}),s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.spread_trade.spread"})),s.createElement("input",{name:"quoteSpread",type:"text",ref:"input",value:this.state.quote.spread,onChange:this.handleChange,disabled:this.props.bot.run,style:{marginBottom:30,border:this.state.validate.includes("quoteSpread")?"1px solid red":"none"}})),s.createElement("div",{className:"content-block",style:{marginLeft:50,marginTop:30}},s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.common.base"})),s.createElement(_.ZP,{style:{marginBottom:30},name:"baseAsset",value:{value:this.state.base.asset,label:s.createElement(u,{name:this.state.base.asset})},clearable:!1,searchable:!1,disabled:!0}),s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.common.balance"})),s.createElement("input",{name:"baseBalance",type:"text",ref:"input",value:this.state.base.balance,onChange:this.handleChange,disabled:this.props.bot.run,style:{marginBottom:30,border:this.state.validate.includes("baseBalance")?"1px solid red":"none"}}),s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.common.amount"})),s.createElement("div",null,s.createElement("input",{type:"radio",value:!0,name:"percentBaseAmount",checked:this.state.base.percent,onChange:this.handleChange})," ",s.createElement(E(),{content:"bots.spread_trade.balance_percent"}),s.createElement("br",null),s.createElement("input",{type:"radio",value:!1,name:"percentBaseAmount",checked:!this.state.base.percent,onChange:this.handleChange})," ",s.createElement(E(),{content:"bots.spread_trade.balance_value"})),s.createElement("input",{name:"baseAmount",type:"text",ref:"input",value:this.state.base.amount,onChange:this.handleChange,disabled:this.props.bot.run,style:{marginBottom:30,border:this.state.validate.includes("baseAmount")?"1px solid red":"none"}}),s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.spread_trade.spread"})),s.createElement("input",{name:"baseSpread",type:"text",ref:"input",value:this.state.base.spread,onChange:this.handleChange,disabled:this.props.bot.run,style:{marginBottom:30,border:this.state.validate.includes("baseSpread")?"1px solid red":"none"}}))),s.createElement("div",{className:"content-block"},s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.spread_trade.default_price"})),s.createElement("input",{name:"defaultPrice",type:"text",ref:"input",value:this.state.defaultPrice,onChange:this.handleChange,disabled:this.props.bot.run,style:{border:this.state.validate.includes("defaultPrice")?"1px solid red":"none"}})),s.createElement("div",{className:"content-block"},s.createElement("label",null,s.createElement("input",{type:"checkbox",name:"fromMarket",onChange:this.handleChange,checked:this.state.fromMarket,disabled:this.props.bot.run}),s.createElement(E(),{content:"bots.spread_trade.get_price_from_market"}))),s.createElement("button",{className:"button",onClick:this.handleUpdateBot,disabled:this.props.bot.run,style:{marginLeft:50,marginBottom:30}},s.createElement(E(),{content:"bots.common.update"})))}}const q=C;var N=a(905),A=a(30806),k=a(41075),w=a(56934);var S=a(55294);const x=class{static create=null;state=null;constructor(e,t,a){this.account=new class{constructor(e,t="GPH"){this.promise=Promise.all([o.db.get_account_by_name(e),i[t]]).then((([e,t])=>{this.acc=e,this.feeAsset=t}))}async cancelOrder(e){return await this.promise,this.sendTransaction("limit_order_cancel",{fee:this.feeAsset.toParam(),fee_paying_account:this.acc.id,order:e,extensions:[]})}async buy(e,t,a,s,n=!1,l="2099-01-01T00:00:00"){await this.promise;let r=await i["object"==typeof e?e.asset_id:e],c=await i["object"==typeof t?t.asset_id:t],m=Math.floor((0,N.Z)("object"==typeof e?e.amount:a).times(10**r.precision).toString()),d=Math.floor(("object"==typeof t?(0,N.Z)(t.amount):(0,N.Z)(a).times(s)).times(10**c.precision).toString());if(0==m||0==d)throw new Error("Amount equal 0!");let h=await this.sendTransaction("limit_order_create",{fee:this.feeAsset.toParam(),seller:this.acc.id,amount_to_sell:c.toParam(d),min_to_receive:r.toParam(m),expiration:l,fill_or_kill:n,extensions:[]});return(await o.db.get_objects([h[0].trx.operation_results[0][1]]))[0]}async sell(e,t,a,s,n=!1,l="2099-01-01T00:00:00"){await this.promise;let r=await i["object"==typeof e?e.asset_id:e],c=await i["object"==typeof t?t.asset_id:t],m=Math.floor((0,N.Z)("object"==typeof e?e.amount:a).times(10**r.precision).toString()),d=Math.floor(("object"==typeof t?(0,N.Z)(t.amount):(0,N.Z)(a).times(s)).times(10**c.precision).toString());if(0==d||0==m)throw new Error("Amount equal 0!");let h=await this.sendTransaction("limit_order_create",{fee:this.feeAsset.toParam(),seller:this.acc.id,amount_to_sell:r.toParam(m),min_to_receive:c.toParam(d),expiration:l,fill_or_kill:n,extensions:[]});return(await o.db.get_objects([h[0].trx.operation_results[0][1]]))[0]}async balances(){return await this.promise,o.db.get_account_balances(this.acc.id,[...arguments])}async sendTransaction(e,t){let a=new A.TransactionBuilder;a.add_type_operation(e,t),await a.set_required_fees(),await w.Z.unlock();let s=k.Z.getPrivateKey(this.acc.active.key_auths[0][0]);return a.add_signer(s,s.toPublicKey().toPublicKeyString()),a.broadcast()}}(e),this.storage=t,this.name=t.read().name,this.logger=console,this.queueEvents=Promise.resolve(),this.run=!1}async initStartData(){}async checkOrders(){this.storage.read(),console.log("checkOrders")}async start(){await this.initStartData(),await w.Z.unlock(),S.Z.changeSetting({setting:"walletLockTimeout",value:0}),A.ChainStore.subscribe(this.queue),this.run=!0}async stop(){A.ChainStore.unsubscribe(this.queue),this.run=!1,await this.queueEvents}async delete(){this.storage.delete()}queue=()=>{this.queueEvents=this.queueEvents.then(this.checkOrders).catch(this.logger.error.bind(this.logger))}};N.Z.config({ERRORS:!1});class B extends s.Component{state={name:"",sellAsset:"GPH",getAsset:"RUDEX.USDT",amount:1e3,minAmount:1,stoploss:.01,percent:10,validate:["name"]};componentDidMount(){this.assetValidate=(0,n.Z)(this.assetValidate,200)}handleChange=e=>{let t=e.target.name,a=e.target.value;["sellAsset","getAsset"].includes(t)&&(a=a.toUpperCase()),"minAmount"===t?this.setState({minAmount:a,stoploss:a/this.state.amount},(()=>this.validate(t,a))):"stoploss"===t?this.setState({minAmount:this.state.amount*a,stoploss:a},(()=>this.validate(t,a))):"amount"===t?this.setState({amount:a,minAmount:a*this.state.stoploss},(()=>this.validate(t,a))):this.setState({[t]:a},(()=>this.validate(t,a)))};assetValidate=async e=>{let t=this.state[e],a=(await o.db.list_assets(t,1))[0],s=this.state.validate;t!==a.symbol?s.push(e):s=s.filter((t=>t!==e)),this.setState({validate:s}),this.props.enableCreate(0==this.state.validate.length)};validate=(e,t)=>{let a=this.state.validate;switch(e){case"name":!/^\w+$/.test(t)||W.hasBot(this.props.account,this.props.name,t)?(a.push(e),this.setState({validate:a})):this.setState({validate:a.filter((t=>t!==e))});break;case"sellAsset":case"getAsset":0!==t.length?this.assetValidate(e):(a.push(e),this.setState({validate:a}));break;case"amount":case"minAmount":case"pecent":case"stoploss":""===t||isNaN(+t)?(a.push(e),this.setState({validate:a})):this.setState({validate:a.filter((t=>t!==e))})}console.log(this.state.validate),this.props.enableCreate(0==this.state.validate.length)};render(){return s.createElement("div",null,s.createElement("div",{className:"content-block"},s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.common.name"})),s.createElement("input",{name:"name",id:"name",type:"text",ref:"input",value:this.state.name,onChange:this.handleChange,style:{border:this.state.validate.includes("name")?"1px solid red":"none"}})),s.createElement("div",{className:"grid-block horizontal"},s.createElement("div",{className:"content-block",style:{marginLeft:50}},s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.trailing_stop.sell_asset"})),s.createElement(g,{name:"sellAsset",value:this.state.sellAsset,onChange:this.handleChange}),s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.trailing_stop.amount"})),s.createElement("input",{name:"amount",id:"amount",type:"text",ref:"input",value:this.state.amount,onChange:this.handleChange,style:{marginBottom:30,border:this.state.validate.includes("amount")?"1px solid red":"none"}})),s.createElement("div",{className:"content-block",style:{marginLeft:50}},s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.trailing_stop.get_asset"})),s.createElement(g,{name:"getAsset",value:this.state.getAsset,onChange:this.handleChange}),s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.trailing_stop.min_amount"})),s.createElement("input",{name:"minAmount",id:"minAmount",type:"text",ref:"input",value:this.state.minAmount,onChange:this.handleChange,style:{marginBottom:30,border:this.state.validate.includes("minAmount")?"1px solid red":"none"}}))),s.createElement("div",{className:"content-block"},s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.trailing_stop.stoploss"})),s.createElement("input",{name:"stoploss",id:"stoploss",type:"text",ref:"input",value:this.state.stoploss,onChange:this.handleChange,style:{marginBottom:30,border:this.state.validate.includes("stoploss")?"1px solid red":"none"}}),s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.trailing_stop.trailing_percent"})),s.createElement("input",{name:"percent",id:"percent",type:"text",ref:"input",value:this.state.percent,onChange:this.handleChange,style:{marginBottom:30,border:this.state.validate.includes("percent")?"1px solid red":"none"}})))}}const Z=B;class $ extends s.Component{state={validate:[]};UNSAFE_componentWillMount(){let e=this.props.bot.storage.read();e.stoploss=e.minAmount/e.amount,this.setState(e)}handleChange=e=>{let t=e.target.name,a=e.target.value;["sellAsset","getAsset"].includes(t)&&(a=a.toUpperCase()),"minAmount"===t?this.setState({minAmount:a,stoploss:a/this.state.amount},(()=>this.validate(t,a))):"stoploss"===t?this.setState({minAmount:this.state.amount*a,stoploss:a},(()=>this.validate(t,a))):"amount"===t?this.setState({amount:a,minAmount:a*this.state.stoploss},(()=>this.validate(t,a))):this.setState({[t]:a},(()=>this.validate(t,a))),this.setState({[t]:a})};validate=(e,t)=>{};handleUpdateBot=()=>{this.props.bot.storage.write(this.state)};render(){return s.createElement("div",null,s.createElement("div",{className:"grid-block horizontal",style:{marginLeft:50,marginTop:50}},s.createElement("div",{className:"content-block"},s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.trailing_stop.sell_asset"})),s.createElement(_.ZP,{style:{marginBottom:30},name:"sellAsset",value:{value:this.state.sellAsset,label:s.createElement(u,{name:this.state.sellAsset})},clearable:!1,searchable:!1,disabled:!0}),s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.trailing_stop.amount"})),s.createElement("input",{name:"amount",id:"amount",type:"text",ref:"input",value:this.state.amount,onChange:this.handleChange,disabled:this.props.bot.run,style:{marginBottom:30,border:this.state.validate.includes("amount")?"1px solid red":"none"}})),s.createElement("div",{className:"content-block",style:{marginLeft:50}},s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.trailing_stop.get_asset"})),s.createElement(_.ZP,{style:{marginBottom:30},name:"getAsset",value:{value:this.state.getAsset,label:s.createElement(u,{name:this.state.getAsset})},clearable:!1,searchable:!1,disabled:!0}),s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.trailing_stop.min_amount"})),s.createElement("input",{name:"minAmount",id:"minAmount",type:"text",ref:"input",value:this.state.minAmount,onChange:this.handleChange,disabled:this.props.bot.run,style:{marginBottom:30,border:this.state.validate.includes("minAmount")?"1px solid red":"none"}}))),s.createElement("div",{className:"content-block"},s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.trailing_stop.stoploss"})),s.createElement("input",{name:"stoploss",id:"stoploss",type:"text",ref:"input",value:this.state.stoploss,onChange:this.handleChange,disabled:this.props.bot.run,style:{marginBottom:30,border:this.state.validate.includes("stoploss")?"1px solid red":"none"}}),s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.trailing_stop.trailing_percent"})),s.createElement("input",{name:"percent",id:"percent",type:"text",ref:"input",value:this.state.percent,onChange:this.handleChange,disabled:this.props.bot.run,style:{marginBottom:30,border:this.state.validate.includes("percent")?"1px solid red":"none"}})),s.createElement("button",{className:"button",onClick:this.handleUpdateBot,disabled:this.props.bot.run,style:{marginLeft:50,marginBottom:30}},s.createElement(E(),{content:"bots.common.update"})))}}const P=$;function O(){return O=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var s in a)Object.prototype.hasOwnProperty.call(a,s)&&(e[s]=a[s])}return e},O.apply(this,arguments)}class M extends s.Component{render(){let{name:e,value:t,onChange:a,border:n,...l}=this.props;return s.createElement("input",O({name:e,id:e,type:"text",ref:"input",value:t,onChange:a,style:{marginBottom:30,border:n?"1px solid red":"none"}},l))}}const j=M;class L extends s.Component{state={name:"",base:"GPH",quote:"RUDEX.USDT",amount:1e3,percentAmount:!1,balance:"5000",spread:2,distance:4,validate:["name"],fromMarket:!1};componentDidMount(){this.assetValidate=(0,n.Z)(this.assetValidate,200)}assetValidate=async e=>{let t=this.state[e],a=(await o.db.list_assets(t,1))[0],s=this.state.validate;t!==a.symbol?s.push(e):s=s.filter((t=>t!==e)),this.setState({validate:s}),this.props.enableCreate(0==this.state.validate.length)};handleChange=e=>{let t=e.target.name,a=e.target.value;["base","quote"].includes(t)&&(a=a.toUpperCase()),this.setState({[t]:a},(()=>this.validate(t,a)))};validate=(e,t)=>{let a=this.state.validate;switch(e){case"name":!/^\w+$/.test(t)||W.hasBot(this.props.account,this.props.name,t)?(a.push(e),this.setState({validate:a})):this.setState({validate:a.filter((t=>t!==e))});break;case"base":case"quote":0!==t.length?this.assetValidate(e):(a.push(e),this.setState({validate:a}));break;case"balance":"-"!==t&&isNaN(+t)?(a.push(e),this.setState({validate:a})):this.setState({validate:a.filter((t=>t!==e))});break;case"spread":case"distance":""===t||isNaN(+t)?(a.push(e),this.setState({validate:a})):this.setState({validate:a.filter((t=>t!==e))})}console.log(a),this.props.enableCreate(0==a.length)};render(){let{validate:e,name:t,amount:a,balance:n,spread:l,distance:o}=this.state;return s.createElement("div",null,s.createElement("div",{className:"content-block"},s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.common.name"})),s.createElement(j,{name:"name",value:t,onChange:this.handleChange,border:e.includes("name")})),s.createElement("div",{className:"grid-block horizontal",style:{marginLeft:50}},s.createElement("div",{className:"content-block"},s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.percent_up.sell_asset"})),s.createElement(g,{name:"base",value:this.state.base,onChange:this.handleChange}),s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.common.amount"})),s.createElement("div",{onChange:this.handleChange},s.createElement("input",{type:"radio",value:!0,name:"percentAmount"})," ",s.createElement(E(),{content:"bots.common.balance_percent"}),s.createElement("br",null),s.createElement("input",{type:"radio",value:!1,name:"percentAmount",defaultChecked:!0})," ",s.createElement(E(),{content:"bots.common.balance_value"})),s.createElement(j,{name:"amount",value:a,onChange:this.handleChange,border:e.includes("amount")}),s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.common.balance"})),s.createElement(j,{name:"balance",value:n,onChange:this.handleChange,border:e.includes("balance")})),s.createElement("div",{className:"content-block",style:{marginLeft:50}},s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.percent_up.get_asset"})),s.createElement(g,{name:"quote",value:this.state.quote,onChange:this.handleChange}),s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.common.spread"})),s.createElement(j,{name:"spread",value:l,onChange:this.handleChange,border:e.includes("spread")}),s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.percent_up.distance"})),s.createElement(j,{name:"distance",value:o,onChange:this.handleChange,border:e.includes("distance")}))))}}const T=L;class U extends s.Component{UNSAFE_componentWillMount(){this.setState(Object.assign({validate:[]},this.props.bot.storage.read()))}handleChange=e=>{let t=e.target.name,a=e.target.value;["base","quote"].includes(t)&&(a=a.toUpperCase()),this.setState({[t]:a},(()=>this.validate(t,a)))};validate=(e,t)=>{let a=this.state.validate;switch(e){case"name":!/^\w+$/.test(t)||BotManager.hasBot(this.props.account,this.props.name,t)?(a.push(e),this.setState({validate:a})):this.setState({validate:a.filter((t=>t!==e))});break;case"base":case"quote":0!==t.length?this.assetValidate(e):(a.push(e),this.setState({validate:a}));break;case"balance":"-"!==t&&isNaN(+t)?(a.push(e),this.setState({validate:a})):this.setState({validate:a.filter((t=>t!==e))});break;case"spread":case"distance":""===t||isNaN(+t)?(a.push(e),this.setState({validate:a})):this.setState({validate:a.filter((t=>t!==e))})}};handleUpdateBot=()=>{let e=this.props.bot.storage.read();this.props.bot.storage.write({...e,...this.state})};render(){let{validate:e,amount:t,balance:a,spread:n,distance:l}=this.state;return s.createElement("div",null,s.createElement("div",{className:"grid-block horizontal",style:{marginLeft:50}},s.createElement("div",{className:"content-block"},s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.percent_up.sell_asset"})),s.createElement(_.ZP,{style:{marginBottom:30},name:"base",value:{value:this.state.base,label:s.createElement(u,{name:this.state.base})},clearable:!1,searchable:!1,disabled:!0}),s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.common.amount"})),s.createElement("div",{onChange:this.handleChange},s.createElement("input",{type:"radio",value:!0,name:"percentAmount",checked:"true"==this.state.percentAmount})," ",s.createElement(E(),{content:"bots.common.balance_percent"}),s.createElement("br",null),s.createElement("input",{type:"radio",value:!1,name:"percentAmount",checked:"false"==this.state.percentAmount})," ",s.createElement(E(),{content:"bots.common.balance_value"})),s.createElement(j,{name:"amount",value:t,onChange:this.handleChange,border:e.includes("amount")}),s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.common.balance"})),s.createElement(j,{name:"balance",value:a,onChange:this.handleChange,border:e.includes("balance")})),s.createElement("div",{className:"content-block",style:{marginLeft:50}},s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.percent_up.get_asset"})),s.createElement(_.ZP,{style:{marginBottom:30},name:"quote",value:{value:this.state.quote,label:s.createElement(u,{name:this.state.quote})},clearable:!1,searchable:!1,disabled:!0}),s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.common.spread"})),s.createElement(j,{name:"spread",value:n,onChange:this.handleChange,border:e.includes("spread")}),s.createElement("label",{className:"left-label"},s.createElement(E(),{content:"bots.percent_up.distance"})),s.createElement(j,{name:"distance",value:l,onChange:this.handleChange,border:e.includes("distance")}))),s.createElement("button",{className:"button",onClick:this.handleUpdateBot,disabled:this.props.bot.run,style:{marginLeft:50,marginBottom:30}},s.createElement(E(),{content:"bots.common.update"})))}}const D=U;var F=(0,a(19602).ZP)("__bots__");const R=class{static getAccountBot(e){let t=new RegExp(`^__bots__${e}::`);return Object.keys(localStorage).filter((e=>t.test(e)))}static has(e){return F.has(e)}constructor(e){this.name=e}init(e){F.has(name)||F.set(this.name,e)}read(){return F.get(this.name)}write(e){F.set(this.name,e)}delete(){F.remove(this.name)}};var V={};const W={strategies:{SpreadTrade:class extends x{static create=y;state=q;constructor(e,t,a){a&&t.init({name:a.name,base:{asset:a.baseAsset,balance:a.baseBalance,spread:a.baseSpread,amount:a.baseAmount,percent:a.percentBaseAmount,order:{}},quote:{asset:a.quoteAsset,balance:a.quoteBalance,spread:a.quoteSpread,amount:a.quoteAmount,percent:a.percentQuoteAmount,order:{}},fromMarket:a.fromMarket,defaultPrice:a.defaultPrice}),super(e,t,a)}async initStartData(){let e=this.storage.read();this.base=await i[e.base.asset],this.quote=await i[e.quote.asset],[this.base.issuer,this.quote.issuer].includes("1.2.0")?[this.base.id,this.quote.id].includes("1.3.0")?this.getFeed=this.getCoreFeed:this.base.issuer==this.quote.issuer?this.getFeed=this.getSmartFeed:this.getFeed=this.getUIAFeed:this.getFeed=this.getUIAFeed}async delete(){let e=this.storage.read();try{this.logger.info(`delete orderId: ${e.quote.order.id}`),await this.account.cancelOrder(e.quote.order.id),this.logger.info(`delete orderId: ${e.base.order.id}`),await this.account.cancelOrder(e.base.order.id)}catch(t){this.logger.error(t),e.base.order.id=void 0}this.storage.delete()}checkOrders=async()=>{let e=this.storage.read(),t=await o.db.get_ticker(this.base.symbol,this.quote.symbol);this.defaultPrice=e.defaultPrice;let a=e.fromMarket?(0,N.Z)(t.latest):await this.getFeed(),s=a.times(1-e.base.spread/100).toNumber(),n=a.times(1+e.quote.spread/100).toNumber();if(a=a.toNumber(),0==a)return;let l=e.base.order.id?(await o.db.get_objects([e.base.order.id]))[0]:e.base.order.id,i=e.quote.order.id?(await o.db.get_objects([e.quote.order.id]))[0]:e.quote.order.id,r=(await this.account.balances(this.base.id,this.quote.id)).reduce(((e,t)=>(this.base.id===t.asset_id?e.base=(0,N.Z)(t.amount).div(10**this.base.precision).toNumber():e.quote=(0,N.Z)(t.amount).div(10**this.quote.precision).toNumber(),e)),{}),c="-"===e.base.balance?0:""===e.base.balance?r.base:Math.min(r.base,e.base.balance),m="-"===e.quote.balance?0:""===e.quote.balance?r.quote:Math.min(r.quote,e.quote.balance),d="true"==e.base.percent?(0,N.Z)(c).times(e.base.amount).div(100).toNumber():e.base.amount,h="true"==e.quote.percent?(0,N.Z)(m).times(e.quote.amount).div(100).toNumber():e.quote.amount;if(l){if(console.log(`check buyOrder: move=${Math.abs(s-e.base.order.price)>Math.abs(a-s)/2}, fill=${t.lowest_ask<=s}`),Math.abs(s-e.base.order.price)>Math.abs(a-s)/2&&t.lowest_ask>s){this.logger.info(`move buy order: ${s} ${this.quote.symbol}/${this.base.symbol}`),await this.account.cancelOrder(e.base.order.id);let t=(0,N.Z)(l.for_sale).div(10**this.base.precision).toNumber();!["","-"].includes(e.base.balance)&&(e.base.balance=Number(e.base.balance)+t),e.base.order.amount>t&&!["","-"].incudes(e.quote.balance)&&(e.quote.balance=(0,N.Z)(e.base.order.amount-t).div(e.base.order.price).plus(e.quote.balance).toNumber());let a=Math.min(c,d);try{let t=await this.account.sell(this.base.symbol,this.quote.symbol,a,(0,N.Z)(1).div(s).toNumber());e.base.order={id:t?t.id:"1.7.0",price:s,amount:a},!["","-"].includes(e.base.balance)&&(e.base.balance-=a)}catch(t){this.logger.error(t),e.base.order.id=void 0}}}else if(/^1.7.\d*$/.test(e.base.order.id)&&(!["","-"].includes(e.quote.balance)&&(e.quote.balance=(0,N.Z)(e.base.order.amount).div(e.base.order.price).plus(e.quote.balance).toNumber()),e.base.order.id=void 0),console.log(`create buyOrder: balance=${c>=d}, fill=${t.lowest_ask<=s}`),c>=d&&t.lowest_ask>s){this.logger.info(`buy: ${s} ${this.quote.symbol}/${this.base.symbol}`);try{let t=await this.account.sell(this.base.symbol,this.quote.symbol,d,(0,N.Z)(1).div(s).toNumber());e.base.order={id:t?t.id:"1.7.0",price:s,amount:d},!["","-"].includes(e.base.balance)&&(e.base.balance-=d)}catch(e){this.logger.error(e)}}if(i){if(console.log(`check sellOrder: move=${Math.abs(n-e.quote.order.price)>Math.abs(a-n)/2}, fill=${t.highest_bid>=n}`),Math.abs(n-e.quote.order.price)>Math.abs(a-n)/2&&t.highest_bid<n){this.logger.info(`move sell order: ${n} ${this.quote.symbol}/${this.base.symbol}`),await this.account.cancelOrder(e.quote.order.id);let t=(0,N.Z)(i.for_sale).div(10**this.quote.precision).toNumber();!["","-"].includes(e.quote.balance)&&(e.quote.balance=Number(e.quote.balance)+t),e.quote.order.amount>t&&!["","-"].includes(e.base.balance)&&(e.base.balance=(0,N.Z)(e.quote.order.amount-t).times(e.quote.order.price).plus(e.base.balance).toNumber());let a=Math.min(m,h);try{let t=await this.account.sell(this.quote.symbol,this.base.symbol,a,n);e.quote.order={id:t?t.id:"1.7.0",price:n,amount:a},!["","-"].includes(e.quote.balance)&&(e.quote.balance-=a)}catch(t){this.logger.error(t),e.quote.order.id=void 0}}}else if(/^1.7.\d*$/.test(e.quote.order.id)&&(!["","-"].includes(e.base.balance)&&(e.base.balance=(0,N.Z)(e.quote.order.amount).times(e.quote.order.price).plus(e.base.balance).toNumber()),e.quote.order.id=void 0),console.log(`create sellOrder: balance=${m>=h}, fill=${t.highest_bid>=n}`),m>=h&&t.highest_bid<n){this.logger.info(`sell: ${n} ${this.quote.symbol}/${this.base.symbol}`);try{let t=await this.account.sell(this.quote.symbol,this.base.symbol,h,n);e.quote.order={id:t?t.id:"1.7.0",price:n,amount:h},!["","-"].includes(e.quote.balance)&&(e.quote.balance-=h)}catch(e){this.logger.error(e)}}this.storage.write(e)};async getCoreFeed(){let e;"1.3.0"==this.base.id?(await this.quote.update(),e=this.quote.options.core_exchange_rate):(await this.base.update(),e=this.base.options.core_exchange_rate);let[t,a]=e.base.asset_id==this.base.id?[e.base,e.quote]:[e.quote,e.base];return(0,N.Z)(t.amount).div(10**this.base.precision).div((0,N.Z)(a.amount).div(10**this.quote.precision))}async getSmartFeed(){let e=await i.gph;await this.base.update();let t=this.base.options.core_exchange_rate,[a,s]="1.3.0"==t.base.asset_id?[t.base,t.quote]:[t.quote,t.base],n=(0,N.Z)(a.amount).div(10**e.precision).div((0,N.Z)(s.amount).div(10**this.base.precision));return await this.quote.update(),t=this.quote.options.core_exchange_rate,"1.3.0"==t.base.asset_id?(a=t.base,s=t.quote):(a=t.quote,s=t.base),(0,N.Z)(a.amount).div(10**e.precision).div((0,N.Z)(s.amount.toString()).div(10**this.quote.precision)).div(n)}async getUIAFeed(){return this.defaultPrice?(0,N.Z)(this.defaultPrice.toString()):await this.binancePrice(this.base.symbol,this.quote.symbol)}async binancePrice(e,t){let a=`${t.split(".").slice(-1)[0]}${e.split(".").slice(-1)[0]}`.toUpperCase().replace("USD","USDT");console.log(`get asset: ${a}`),this.priceArray=this.priceArray||[];try{let e=await fetch(`https://api.binance.com/api/v1/trades?symbol=${a}&limit=1`),t=await e.json();this.priceArray.push(t[0].price)}catch(e){this.logger.error(`Error Binance request: ${a}, error: ${e}`)}return this.priceArray.length>10&&this.priceArray.shift(),this.priceArray.length>0?this.priceArray.reduce(((e,t)=>e.plus(t)),(0,N.Z)(0)).div(this.priceArray.length):(0,N.Z)(0)}},TrailingStop:class extends x{static create=Z;state=P;constructor(e,t,a){a&&t.init({name:a.name,sellAsset:a.sellAsset,getAsset:a.getAsset,amount:a.amount,minAmount:a.minAmount,percent:a.percent}),super(e,t,a)}async initStartData(){let e=this.storage.read();this.sellAsset=await i[e.sellAsset],this.getAsset=await i[e.getAsset]}checkOrders=async()=>{let e=this.storage.read();console.log("checkOrders");let t=await o.db.get_ticker(this.getAsset.symbol,this.sellAsset.symbol),a=(0,N.Z)(t.latest),s=a.times(1-e.percent/100),n=a.times(1-2*e.percent/3/100),l=(0,N.Z)(e.minAmount).div(e.amount);console.log(a.toNumber(),s.toNumber(),n.toNumber(),l.toNumber()),s.gt(l)?(console.log("up minAmount"),e.minAmount=s.times(e.amount).toNumber(),this.storage.write(e)):n.lt(l)&&(console.log("create limit order"),await this.account.sell(this.sellAsset.symbol,this.getAsset.symbol,e.amount,l.toNumber()),await this.stop())}},PercentUp:class extends x{static create=T;state=D;constructor(e,t,a){if(a){let{name:e,base:s,quote:n,amount:l,percentAmount:o,balance:i,spread:r,distance:c}=a;t.init({name:e,base:s,quote:n,amount:l,percentAmount:o,balance:i,spread:r,distance:c,orders:[]})}super(e,t,a)}async initStartData(){let e=this.storage.read();this.base=await i[e.base],this.quote=await i[e.quote]}checkOrders=async()=>{let e=this.storage.read(),t=(...t)=>this.logger.log(`[${e.name}]`,...t),a=(await this.account.balances(this.base.id,this.quote.id)).reduce(((e,t)=>(this.base.id===t.asset_id?e.base=(0,N.Z)(t.amount).div(10**this.base.precision).toNumber():e.quote=(0,N.Z)(t.amount).div(10**this.quote.precision).toNumber(),e)),{}),s="-"===e.balance?0:""===e.balance?a.base:Math.min(a.base,e.balance),n="true"==e.percentAmount.toString()?(0,N.Z)(s).times(e.amount).div(100).toNumber():e.amount,l=(await o.db.get_objects(e.orders.map((e=>e.id)).filter((e=>e)))).map((e=>e&&e.id)).filter((e=>e)),i=e.orders.filter((e=>!l.includes(e.id))),r=(0,N.Z)((await o.db.get_global_properties()).parameters.current_fees.parameters[1][1].fee).div(10**5).toNumber();i.length>0&&await this.base.update();let c=i.map((async s=>{if("buy"===s.state){if(s.id=null,!["","-"].includes(e.balance)){let t=Math.floor((0,N.Z)(this.base.options.market_fee_percent).div(1e4).times(s.base).times(10**this.base.precision).toString());e.balance=Number(e.balance)+Number(s.base)-(0!==t?(0,N.Z)(t).div(10**this.base.precision).toNumber():0!==this.base.options.market_fee_percent?10**-this.base.precision:0)}}else{let n="GPH"===this.quote.symbol?(isNaN(s.fee)?r:s.fee)+r:0,l="GPH"===this.base.symbol?(isNaN(s.fee)?r:s.fee)+r:0,o={asset_id:this.quote.id,amount:Math.min(Number(a.quote),Number(s.quote))-n},i=(0,N.Z)(this.base.options.market_fee_percent).div(1e4),c={asset_id:this.base.id,amount:(0,N.Z)(s.base).times(1+Number(e.spread)/100+i.toNumber()).plus(l)};t(`buy ${this.base.symbol}: amount=${c.amount.toNumber()} price=${(0,N.Z)(o.amount).div(c.amount).toNumber()} ${this.base.symbol}/${this.quote.symbol}`);let m=await this.account.sell(o,c);s.state="buy",s.id=m?m.id:"1.7.0",s.base=c.amount.toNumber()}}));await Promise.all(c);let m=await o.db.get_order_book(this.quote.symbol,this.base.symbol,50),d=(0,N.Z)(0),h=(0,N.Z)(0);for(let e=0;e<m.asks.length;e++){let t=m.asks[e],a=(0,N.Z)(t.base),s=(0,N.Z)(t.quote),l=(0,N.Z)(n).minus(h);if(s.isEqualTo(l)){d=d.plus(a),h=h.plus(s);break}if(s.isLessThan(l))d=d.plus(a),h=h.plus(s);else if(s.isGreaterThan(l)){h=h.plus(l),d=d.plus((0,N.Z)(t.price).times(l));break}}let u=d.div(h),b=null;e.orders.forEach((e=>{let t=(0,N.Z)(e.quote).div(e.base);b&&!t.minus(u).abs().isLessThan(b.minus(u).abs())||(b=t)}));let p=!!b&&b.minus(u).abs().div(b).times(100).isGreaterThan(e.distance);if(t(`Orders exists: ${!!b}, balance > amount: ${s>n}, lowPrice - price > distance: ${p}`),s>n&&(!b||p)){let a={asset_id:this.base.id,amount:n},s={asset_id:this.quote.id,amount:d},l=await this.account.buy(s,a),o={state:"sell",base:n,quote:s.amount.toNumber(),id:l?l.id:"1.7.0",fee:r};e.orders.push(o),t(`sell ${this.base.symbol}: amount=${n}, price=${u.toNumber()} ${this.base.symbol}/${this.quote.symbol}`),["","-"].includes(e.balance)||(e.balance=Number(e.balance)-n)}e.orders=e.orders.filter((e=>null!==e.id)),this.storage.write(e)};async delete(){this.storage.read().orders.forEach((async e=>{try{this.logger.info(`delete orderId: ${e.id}`),await this.account.cancelOrder(e.id)}catch(e){this.logger.error(e)}})),this.storage.delete()}}},create(e,t,a){let s=new R(`${t}::${e}[${a.name}]`),n=new this.strategies[e](t,s,a);return V[`__bots__${s.name}`]=n,n},async delete(e){let t=`__bots__${e.storage.name}`;await V[t].delete(),delete V[t]},getBots(e){return R.getAccountBot(e).map((t=>{if(V[t])return V[t];let[a,s]=t.replace(/^__bots__(.+)::(\w+)\[(\w+)\]/,"$2,$3").split(",");if(!a||!s)return null;let n=new R(`${e}::${a}[${s}]`),l=new this.strategies[a](e,n);return V[t]=l,l})).filter((e=>e))},hasBot:(e,t,a)=>(console.log("check name stategy",e,t,a),R.has(`${e}::${t}[${a}]`))};var G=a(32793),z=a(89449),Q=a(73727),H=a(5977),I=a(91684);class X extends s.Component{constructor(e){super(e),this.strategies=W.strategies,this.state={selectStrategy:Object.keys(this.strategies)[0],bots:[],selectBot:0,enableCreate:!1,botRun:!1}}componentDidMount(){let e=W.getBots(this.props.currentAccount);this._upd(e)}_upd(e){this.setState({bots:e,selectBot:0,botRun:!!e[0]&&e[0].run})}handleChangeStrategy=e=>{this.setState({selectStrategy:e.target.value})};handleChangeBot=e=>{let t=e.target.value;this.setState({selectBot:t,botRun:this.state.bots[t].run})};handleCreate=e=>{e.preventDefault();let t=this.state.bots;t.push(W.create(this.state.selectStrategy,this.props.currentAccount,this.createForm.state)),this.setState({bots:t}),this.createForm.validate&&this.createForm.validate("name",this.createForm.state.name)};handleEnableCreate=e=>{this.state.enableCreate!=e&&this.setState({enableCreate:e})};handleStartBot=async()=>{let e=this.state.bots[this.state.selectBot];await e.start(),this.setState({botRun:e.run})};handleStopBot=async()=>{let e=this.state.bots[this.state.selectBot];await e.stop(),this.setState({botRun:e.run})};handleDeleteBot=async()=>{await W.delete(this.state.bots[this.state.selectBot]),this.setState({bots:W.getBots(this.props.currentAccount),selectBot:0})};render(){if(null===this.props.currentAccount)return s.createElement(H.l_,{to:"/"});let e=this.strategies[this.state.selectStrategy].create,t=this.state.bots[this.state.selectBot]||null;return s.createElement("div",{className:"grid-block vertical"},s.createElement("div",{className:"grid-block shrink vertical medium-horizontal"},s.createElement("form",{style:{paddingBottom:20,overflow:"visible"},className:"grid-content small-12 medium-6 large-5 large-offset-1 full-width-content",onSubmit:this.handleCreate,noValidate:!0},s.createElement("div",{className:"left-label",style:{marginTop:30}},s.createElement("span",{style:{paddingRight:5,position:"relative",top:9}},s.createElement(Q.rU,{to:"/help/bots/introduction"},s.createElement(I.Z,{name:"question-circle",title:"icons.question_circle",size:"2x"}))),s.createElement(E(),{content:"bots.common.select_strategy"})),s.createElement("div",{className:"content-block"},s.createElement("div",{className:"content-block"},s.createElement("select",{className:"form-control bts-select ",value:this.state.selectStrategy,onChange:this.handleChangeStrategy},Object.keys(this.strategies).map((e=>s.createElement("option",{key:e,value:e},e)))))),s.createElement("hr",null),s.createElement("div",{className:"content-block"},s.createElement(e,{ref:e=>{this.createForm=e},account:this.props.currentAccount,name:this.state.selectStrategy,enableCreate:this.handleEnableCreate}),s.createElement("button",{className:"button no-margin",type:"submit",disabled:!this.state.enableCreate},s.createElement(E(),{content:"bots.common.create"})))),s.createElement("div",{className:"content-block"},s.createElement("div",{className:"left-label",style:{marginTop:30}},s.createElement(E(),{content:"bots.common.bot_state"})),s.createElement("select",{className:"form-control bts-select",value:this.state.selectBot,onChange:this.handleChangeBot},this.state.bots.map(((e,t)=>s.createElement("option",{key:e.name,value:t},`${e.name} (${e.constructor.name})`)))),s.createElement("div",{className:"content-block"},t?s.createElement("div",null,s.createElement(t.state,{key:t.name,bot:t}),s.createElement("button",{className:"button",onClick:this.handleStartBot,disabled:this.state.botRun,style:{marginLeft:50}},s.createElement(E(),{content:"bots.common.start"})),s.createElement("button",{className:"button",onClick:this.handleStopBot,disabled:!this.state.botRun,style:{marginLeft:50}},s.createElement(E(),{content:"bots.common.stop"})),s.createElement("button",{className:"button",onClick:this.handleDeleteBot,disabled:this.state.botRun,style:{marginLeft:50}},s.createElement(E(),{content:"bots.common.delete"}))):s.createElement("p",null,s.createElement(E(),{content:"bots.common.select_bot"}))))))}}const K=(0,z.$)(X,{listenTo:()=>[G.Z],getProps:()=>({currentAccount:G.Z.getState().currentAccount||G.Z.getState().passwordAccount})})},3894:(e,t,a)=>{a.d(t,{Z:()=>b});var s=a(67294),n=a(13863),l=a(23037),o=a(82267),i=a(43393);class r extends s.Component{static propTypes={dos:l.Z.ChainObjectsList};static defaultProps={dos:(0,i.List)()};constructor(){super(),this.getDynamicObject=this.getDynamicObject.bind(this)}getDynamicObject(e){return this.props.dos.find((t=>t&&t.get("id")===e))}render(){return s.cloneElement(s.Children.only(this.props.children),{...this.props,getDynamicObject:this.getDynamicObject})}}r=(0,o.Z)(r);var c=a(45697),m=a.n(c),d=a(60567);function h(){return h=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var s in a)Object.prototype.hasOwnProperty.call(a,s)&&(e[s]=a[s])}return e},h.apply(this,arguments)}class u extends s.Component{static propTypes={replaceNoneToBts:m().bool,maxWidth:m().number};static defaultProps={replaceNoneToBts:!0,maxWidth:20};constructor(e){super(e),this.state={imgError:!1}}shouldComponentUpdate(e,t){return this.props.asset!==e.asset||this.props.maxWidth!==e.maxWidth||this.props.whiteList!==e.whiteList||this.state.imgError!==t.imgError}_onError(e){this.state.imgError||(this.props.replaceNoneToBts?this.refs[e.toLowerCase()].src="asset-symbols/unknown.png":this.refs[e.toLowerCase()].remove(),this.setState({imgError:!0}))}render(){let{asset:e}=this.props;const t=function(e){if(null===e)return"unknown";let t=e.get("symbol");return(0,d.sA)(t)}(e);return s.createElement("img",{ref:t.toLowerCase(),className:"column-hide-small",onError:this._onError.bind(this,t),style:{maxWidth:this.props.maxWidth,marginRight:5,marginTop:"-3px"},src:`asset-symbols/${t.toLowerCase()}.png`})}}u=function(e,t={}){t.propNames=t.propNames||[t.asList?"assets":"asset"];const a=t.propNames.reduce(((e,a)=>(e[a]=t.asList?l.Z.ChainAssetsList:l.Z.ChainAsset.isRequired,e)),{});let c=Object.keys(a).reduce(((e,a)=>{let s=t.defaultProps&&t.defaultProps[a];return e[a]=t.asList?(0,i.List)(s||[]):s||"1.3.0",e}),{});t.defaultProps&&t.defaultProps.tempComponent&&(c.tempComponent=t.defaultProps.tempComponent);class m extends s.Component{static propTypes=a;static defaultProps=c;render(){let e={},a={},n=(0,i.List)();Object.keys(this.props).forEach((s=>{this.props[s]&&-1!==t.propNames.indexOf(s)?(t.withDynamic&&(t.asList?this.props[s].forEach((e=>{e&&(n=n.push(e.get("dynamic_asset_data_id")))})):n=n.push(this.props[s].get("dynamic_asset_data_id"))),e[s]=t.asList?this.props[s].filter((e=>!!e)):this.props[s]):a[s]=this.props[s]}));let l=s.cloneElement(s.Children.only(this.props.children),{...a,...e});return t.withDynamic?s.createElement(r,{dos:n},l):l}}m=(0,o.Z)(m);class d extends s.Component{render(){return s.createElement(m,this.props,s.createElement(e,{ref:"bound_component"}))}}return d.displayName=`Wrapper(${(0,n.G)(e)})`,d}(u);class b extends s.Component{render(){return s.createElement(u,h({},this.props,{asset:this.props.name}))}}}}]);