Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Commit b9b5bde

Browse files
authored
Merge branch 'dev' into decimal-missing
2 parents 7a690d6 + 3356d2b commit b9b5bde

File tree

23 files changed

+1539
-39
lines changed

23 files changed

+1539
-39
lines changed

src/botPage/bot/Interface/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default class Interface extends ToolsInterface(TicksInterface(class {}))
3737
};
3838
}
3939
getBotInterface() {
40-
const getDetail = i => createDetails(this.get('contract'))[i];
40+
const getDetail = (i, pipSize) => createDetails(this.get('contract'), pipSize)[i];
4141

4242
return {
4343
init : (...args) => this.tradeEngine.init(...args),
@@ -50,7 +50,7 @@ export default class Interface extends ToolsInterface(TicksInterface(class {}))
5050
sellAtMarket : () => this.tradeEngine.sellAtMarket(),
5151
getSellPrice : () => this.getSellPrice(),
5252
isResult : result => getDetail(10) === result,
53-
readDetails : i => getDetail(i - 1),
53+
readDetails : i => getDetail(i - 1, this.tradeEngine.getPipSize()),
5454
};
5555
}
5656
sleep(arg = 1) {

src/botPage/bot/Interpreter.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,10 @@ export default class Interpreter {
149149
}
150150
terminateSession() {
151151
this.$scope.api.disconnect();
152-
globalObserver.emit('bot.stop');
153152
this.stopped = true;
153+
154+
globalObserver.emit('bot.stop');
155+
globalObserver.setState({ isRunning: false });
154156
}
155157
stop() {
156158
if (this.bot.tradeEngine.isSold === false && !this.isErrorTriggered) {

src/botPage/bot/TradeEngine/Ticks.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,30 @@ export default Engine =>
3131
tickListenerKey = key;
3232
}
3333
}
34-
getTicks() {
35-
return new Promise(resolve =>
36-
this.$scope.ticksService
37-
.request({ symbol: this.symbol })
38-
.then(ticks => resolve(ticks.map(o => o.quote)))
39-
);
34+
getTicks(toString = false) {
35+
return new Promise(resolve => {
36+
this.$scope.ticksService.request({ symbol: this.symbol }).then(ticks => {
37+
const pipSize = this.getPipSize();
38+
const ticksList = ticks.map(o => {
39+
if (toString) {
40+
return o.quote.toFixed(pipSize);
41+
}
42+
return o.quote;
43+
});
44+
45+
resolve(ticksList);
46+
});
47+
});
4048
}
41-
getLastTick(raw) {
49+
getLastTick(raw, toString = false) {
4250
return new Promise(resolve =>
43-
this.$scope.ticksService
44-
.request({ symbol: this.symbol })
45-
.then(ticks => resolve(raw ? getLast(ticks) : getLast(ticks).quote))
51+
this.$scope.ticksService.request({ symbol: this.symbol }).then(ticks => {
52+
let lastTick = raw ? getLast(ticks) : getLast(ticks).quote;
53+
if (toString && !raw) {
54+
lastTick = lastTick.toFixed(this.getPipSize());
55+
}
56+
resolve(lastTick);
57+
})
4658
);
4759
}
4860
getLastDigit() {

src/botPage/bot/TradeEngine/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export default class TradeEngine extends Balance(Purchase(Sell(OpenContract(Prop
9292
}
9393

9494
globalObserver.emit('bot.running');
95+
globalObserver.setState({ isRunning: true });
9596

9697
this.tradeOptions = expectTradeOptions(tradeOptions);
9798

src/botPage/bot/tools.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export const doUntilDone = (f, types) => {
134134
});
135135
};
136136

137-
export const createDetails = contract => {
137+
export const createDetails = (contract, pipSize) => {
138138
const { sell_price: sellPrice, buy_price: buyPrice, currency } = contract;
139139
const profit = Number(roundBalance({ currency, balance: sellPrice - buyPrice }));
140140
const result = profit < 0 ? 'loss' : 'win';
@@ -151,6 +151,8 @@ export const createDetails = contract => {
151151
+contract.exit_tick,
152152
+(contract.barrier ? contract.barrier : 0),
153153
result,
154+
(+contract.entry_tick).toFixed(pipSize),
155+
(+contract.exit_tick).toFixed(pipSize),
154156
];
155157
};
156158

src/botPage/common/const.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ const config = {
2121
[translate('contract type'), '5'],
2222
[translate('entry spot'), '6'],
2323
[translate('entry value'), '7'],
24+
[translate('entry value string'), '12'],
2425
[translate('exit spot'), '8'],
2526
[translate('exit value'), '9'],
27+
[translate('exit value string'), '13'],
2628
[translate('barrier'), '10'],
2729
[translate('result'), '11'],
2830
],

src/botPage/view/TradeInfoPanel/TradeTable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ export default class TradeTable extends Component {
5050
{ key: 'timestamp', width: 192, resizable: true, name: translate('Timestamp') },
5151
{ key: 'reference', width: 110, resizable: true, name: translate('Reference') },
5252
{ key: 'contract_type', width: 70, resizable: true, name: translate('Trade type') },
53-
{ key: 'entry_tick', width: 75, resizable: true, name: translate('Entry spot') },
54-
{ key: 'exit_tick', width: 75, resizable: true, name: translate('Exit spot') },
53+
{ key: 'entry_tick', width: 82, resizable: true, name: translate('Entry spot') },
54+
{ key: 'exit_tick', width: 82, resizable: true, name: translate('Exit spot') },
5555
{ key: 'buy_price', width: 80, resizable: true, name: translate('Buy price') },
5656
{ key: 'profit', width: 80, resizable: true, name: translate('Profit/Loss'), formatter: ProfitColor },
5757
{ key: 'contract_status', width: 70, resizable: true, name: translate('Status'), formatter: StatusFormat },

src/botPage/view/View.js

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,9 @@ export default class View {
455455
};
456456

457457
const showSummary = () => {
458-
$('#summaryPanel').dialog('open');
458+
$('#summaryPanel')
459+
.dialog('option', 'minWidth', 770)
460+
.dialog('open');
459461
addExportButtonToPanel('summaryPanel');
460462
};
461463

@@ -511,11 +513,19 @@ export default class View {
511513
});
512514

513515
const startBot = limitations => {
514-
const $runButtons = $('#runButton, #summaryRunButton');
515-
const $stopButtons = $('#stopButton, #summaryStopButton');
516-
$stopButtons.show();
517-
$runButtons.hide();
518-
$runButtons.prop('disabled', true);
516+
const elRunButtons = document.querySelectorAll('#runButton, #summaryRunButton');
517+
const elStopButtons = document.querySelectorAll('#stopButton, #summaryStopButton');
518+
519+
elRunButtons.forEach(el => {
520+
const elRunButton = el;
521+
elRunButton.style.display = 'none';
522+
elRunButton.setAttributeNode(document.createAttribute('disabled'));
523+
});
524+
elStopButtons.forEach(el => {
525+
const elStopButton = el;
526+
elStopButton.style.display = 'inline-block';
527+
});
528+
519529
globalObserver.emit('summary.disable_clear');
520530
showSummary();
521531
this.blockly.run(limitations);
@@ -627,31 +637,54 @@ export default class View {
627637
this.blockly.stop();
628638
}
629639
addEventHandlers() {
640+
const getRunButtonElements = () => document.querySelectorAll('#runButton, #summaryRunButton');
641+
const getStopButtonElements = () => document.querySelectorAll('#stopButton, #summaryStopButton');
642+
630643
window.addEventListener('storage', e => {
631644
window.onbeforeunload = null;
632645
if (e.key === 'activeToken' && !e.newValue) window.location.reload();
633646
if (e.key === 'realityCheckTime') hideRealityCheck();
634647
});
635648

636649
globalObserver.register('Error', error => {
637-
$('#runButton, #summaryRunButton').prop('disabled', false);
650+
getRunButtonElements().forEach(el => {
651+
const elRunButton = el;
652+
elRunButton.removeAttribute('disabled');
653+
});
654+
638655
if (error.error && error.error.error.code === 'InvalidToken') {
639656
removeAllTokens();
640657
updateTokenList();
641658
this.stop();
642659
}
643660
});
644661

662+
globalObserver.register('bot.running', () => {
663+
getRunButtonElements().forEach(el => {
664+
const elRunButton = el;
665+
elRunButton.style.display = 'none';
666+
elRunButton.setAttributeNode(document.createAttribute('disabled'));
667+
});
668+
getStopButtonElements().forEach(el => {
669+
const elStopButton = el;
670+
elStopButton.style.display = 'inline-block';
671+
elStopButton.removeAttribute('disabled');
672+
});
673+
});
674+
645675
globalObserver.register('bot.stop', () => {
646-
const $runButtons = $('#runButton, #summaryRunButton');
647-
const $stopButtons = $('#stopButton, #summaryStopButton');
648-
if ($runButtons.is(':visible') || $stopButtons.is(':visible')) {
649-
$runButtons.show();
650-
$stopButtons.hide();
651-
652-
$stopButtons.prop('disabled', false);
653-
$runButtons.prop('disabled', false);
654-
}
676+
// Enable run button, this event is emitted after the interpreter
677+
// killed the API connection.
678+
getStopButtonElements().forEach(el => {
679+
const elStopButton = el;
680+
elStopButton.style.display = null;
681+
elStopButton.removeAttribute('disabled');
682+
});
683+
getRunButtonElements().forEach(el => {
684+
const elRunButton = el;
685+
elRunButton.style.display = null;
686+
elRunButton.removeAttribute('disabled');
687+
});
655688
});
656689

657690
globalObserver.register('bot.info', info => {

src/botPage/view/blockly/blocks/shared.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,21 @@ export const getPredictionForContracts = (contracts, selectedContractType) => {
410410
return predictionRange;
411411
};
412412

413-
export const disableRunButton = isDisabled => {
414-
$('#runButton, #summaryRunButton').attr('disabled', isDisabled);
413+
export const disableRunButton = shouldDisable => {
414+
const elRunButtons = document.querySelectorAll('#runButton, #summaryRunButton');
415+
const isRunning = globalObserver.getState('isRunning');
416+
417+
elRunButtons.forEach(elRunButton => {
418+
if (isRunning) {
419+
if (shouldDisable) {
420+
elRunButton.setAttributeNode(document.createAttribute('disabled'));
421+
} else {
422+
// Do not enable. The bot is running.
423+
}
424+
} else if (shouldDisable) {
425+
elRunButton.setAttributeNode(document.createAttribute('disabled'));
426+
} else {
427+
elRunButton.removeAttribute('disabled');
428+
}
429+
});
415430
};

src/botPage/view/blockly/blocks/ticks/tick.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,16 @@ Blockly.Blocks.tick = {
1414
mainScope(this, ev, 'Tick Value');
1515
},
1616
};
17-
Blockly.JavaScript.tick = () => ['Bot.getLastTick()', Blockly.JavaScript.ORDER_ATOMIC];
17+
Blockly.JavaScript.tick = () => ['Bot.getLastTick(false, false)', Blockly.JavaScript.ORDER_ATOMIC];
18+
19+
Blockly.Blocks.tick_string = {
20+
init: function init() {
21+
this.appendDummyInput().appendField(translate('Last Tick String'));
22+
this.setOutput(true, 'Number');
23+
this.setColour('#f2f2f2');
24+
this.setTooltip(translate('Returns the tick value received by a before purchase block (String)'));
25+
this.setHelpUrl('https://github.com/binary-com/binary-bot/wiki');
26+
},
27+
onchange: Blockly.Blocks.tick.onchange,
28+
};
29+
Blockly.JavaScript.tick_string = () => ['Bot.getLastTick(false, true)', Blockly.JavaScript.ORDER_ATOMIC];

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy