From ce39c3e3a22b35badef21c6e4caa39c6a60c3366 Mon Sep 17 00:00:00 2001 From: McSam Date: Fri, 28 Jun 2019 12:15:22 +0800 Subject: [PATCH 1/5] total profit decimal place --- src/botPage/bot/Interface/MiscInterface.js | 3 ++- src/botPage/bot/TradeEngine/Total.js | 9 +++++++-- .../view/blockly/blocks/tools/total_profit.js | 13 ++++++++++++- static/xml/toolbox.xml | 1 + 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/botPage/bot/Interface/MiscInterface.js b/src/botPage/bot/Interface/MiscInterface.js index 329c503bf5..ff5242f9a2 100644 --- a/src/botPage/bot/Interface/MiscInterface.js +++ b/src/botPage/bot/Interface/MiscInterface.js @@ -29,7 +29,8 @@ export default Interface => notifyTelegram: this.notifyTelegram, getTotalRuns : () => this.tradeEngine.getTotalRuns(), getBalance : type => this.tradeEngine.getBalance(type), - getTotalProfit: () => this.tradeEngine.getTotalProfit(), + getTotalProfit: (...args) => + this.tradeEngine.getTotalProfit(...args, this.tradeEngine.tradeOptions.currency), }; } }; diff --git a/src/botPage/bot/TradeEngine/Total.js b/src/botPage/bot/TradeEngine/Total.js index 355c7c6446..5c81a16234 100644 --- a/src/botPage/bot/TradeEngine/Total.js +++ b/src/botPage/bot/TradeEngine/Total.js @@ -86,9 +86,14 @@ export default Engine => const accountStat = this.getAccountStat(); return accountStat.totalRuns; } - getTotalProfit() { + getTotalProfit(toString = false, currency) { const accountStat = this.getAccountStat(); - return Number(accountStat.totalProfit); + return toString + ? roundBalance({ + currency, + balance: +accountStat.totalProfit, + }) + : +accountStat.totalProfit; } /* eslint-enable */ checkLimits(tradeOption) { diff --git a/src/botPage/view/blockly/blocks/tools/total_profit.js b/src/botPage/view/blockly/blocks/tools/total_profit.js index 87adb27986..6ca5d7d4f1 100644 --- a/src/botPage/view/blockly/blocks/tools/total_profit.js +++ b/src/botPage/view/blockly/blocks/tools/total_profit.js @@ -10,4 +10,15 @@ Blockly.Blocks.total_profit = { this.setHelpUrl('https://github.com/binary-com/binary-bot/wiki'); }, }; -Blockly.JavaScript.total_profit = () => ['Bot.getTotalProfit()', Blockly.JavaScript.ORDER_ATOMIC]; +Blockly.JavaScript.total_profit = () => ['Bot.getTotalProfit(false)', Blockly.JavaScript.ORDER_ATOMIC]; + +Blockly.Blocks.total_profit_string = { + init: function init() { + this.appendDummyInput().appendField(translate('Total Profit String')); + this.setOutput(true, 'String'); + this.setColour('#dedede'); + this.setTooltip(translate('Return the total profit (String)')); + this.setHelpUrl('https://github.com/binary-com/binary-bot/wiki'); + }, +}; +Blockly.JavaScript.total_profit_string = () => ['Bot.getTotalProfit(true)', Blockly.JavaScript.ORDER_ATOMIC]; diff --git a/static/xml/toolbox.xml b/static/xml/toolbox.xml index a5aff41962..f16ef8b7db 100644 --- a/static/xml/toolbox.xml +++ b/static/xml/toolbox.xml @@ -424,6 +424,7 @@ + success From ad6bb0c07eda80fd53c11ededbd7a4921de9eaf9 Mon Sep 17 00:00:00 2001 From: McSam Date: Fri, 28 Jun 2019 12:22:07 +0800 Subject: [PATCH 2/5] jest --- src/botPage/bot/TradeEngine/Total.js | 2 +- src/botPage/bot/__tests__/block-tests/tools-test/Misc.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/botPage/bot/TradeEngine/Total.js b/src/botPage/bot/TradeEngine/Total.js index 5c81a16234..c5e14aa82c 100644 --- a/src/botPage/bot/TradeEngine/Total.js +++ b/src/botPage/bot/TradeEngine/Total.js @@ -86,7 +86,7 @@ export default Engine => const accountStat = this.getAccountStat(); return accountStat.totalRuns; } - getTotalProfit(toString = false, currency) { + getTotalProfit(toString, currency) { const accountStat = this.getAccountStat(); return toString ? roundBalance({ diff --git a/src/botPage/bot/__tests__/block-tests/tools-test/Misc.js b/src/botPage/bot/__tests__/block-tests/tools-test/Misc.js index 5e74115fe7..3e79bb3746 100644 --- a/src/botPage/bot/__tests__/block-tests/tools-test/Misc.js +++ b/src/botPage/bot/__tests__/block-tests/tools-test/Misc.js @@ -17,7 +17,7 @@ describe('Misc. tools', () => { Bot.notify({ message: 'Test', className: 'info'}) watch('before') result.totalRuns = Bot.getTotalRuns(); - result.totalProfit = Bot.getTotalProfit(); + result.totalProfit = Bot.getTotalProfit(false, null); result.balance = Bot.getBalance('NUM') result.balanceStr = Bot.getBalance('STR') ` @@ -47,7 +47,9 @@ describe('Misc. tools', () => { }); it('Notify', () => { - const { notify: { className, message } } = observed; + const { + notify: { className, message }, + } = observed; expect(className).equal('info'); expect(message).equal('Test'); From 7133025ba516916e554bdba70a04d05ab139203b Mon Sep 17 00:00:00 2001 From: McSam Date: Thu, 4 Jul 2019 11:16:43 +0800 Subject: [PATCH 3/5] hide notify when profit is zero --- src/botPage/bot/TradeEngine/Total.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/botPage/bot/TradeEngine/Total.js b/src/botPage/bot/TradeEngine/Total.js index c5e14aa82c..9a338dfb1b 100644 --- a/src/botPage/bot/TradeEngine/Total.js +++ b/src/botPage/bot/TradeEngine/Total.js @@ -88,7 +88,7 @@ export default Engine => } getTotalProfit(toString, currency) { const accountStat = this.getAccountStat(); - return toString + return toString && accountStat.totalProfit !== 0 ? roundBalance({ currency, balance: +accountStat.totalProfit, From c6b1e99c8904e720e7f33eb69e23331740acf7e5 Mon Sep 17 00:00:00 2001 From: sam-binary <51310435+sam-binary@users.noreply.github.com> Date: Fri, 5 Jul 2019 10:42:44 +0800 Subject: [PATCH 4/5] Update src/botPage/bot/Interface/MiscInterface.js Co-Authored-By: Aaron --- src/botPage/bot/Interface/MiscInterface.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/botPage/bot/Interface/MiscInterface.js b/src/botPage/bot/Interface/MiscInterface.js index ff5242f9a2..ed191f08c6 100644 --- a/src/botPage/bot/Interface/MiscInterface.js +++ b/src/botPage/bot/Interface/MiscInterface.js @@ -29,7 +29,7 @@ export default Interface => notifyTelegram: this.notifyTelegram, getTotalRuns : () => this.tradeEngine.getTotalRuns(), getBalance : type => this.tradeEngine.getBalance(type), - getTotalProfit: (...args) => + getTotalProfit: (toString) => this.tradeEngine.getTotalProfit(...args, this.tradeEngine.tradeOptions.currency), }; } From 9c787ecfae11228e966956829ed3a20b8ad96f5f Mon Sep 17 00:00:00 2001 From: McSam Date: Fri, 5 Jul 2019 10:48:49 +0800 Subject: [PATCH 5/5] eslint --- src/botPage/bot/Interface/MiscInterface.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/botPage/bot/Interface/MiscInterface.js b/src/botPage/bot/Interface/MiscInterface.js index ed191f08c6..b3df72b9ae 100644 --- a/src/botPage/bot/Interface/MiscInterface.js +++ b/src/botPage/bot/Interface/MiscInterface.js @@ -29,8 +29,8 @@ export default Interface => notifyTelegram: this.notifyTelegram, getTotalRuns : () => this.tradeEngine.getTotalRuns(), getBalance : type => this.tradeEngine.getBalance(type), - getTotalProfit: (toString) => - this.tradeEngine.getTotalProfit(...args, this.tradeEngine.tradeOptions.currency), + getTotalProfit: toString => + this.tradeEngine.getTotalProfit(toString, this.tradeEngine.tradeOptions.currency), }; } };