Skip to content

Commit c1ea1b4

Browse files
authored
Merge pull request binary-com#1629 from sam-binary/contract-pip-size
Contract pip size
2 parents 29af92f + e41ca28 commit c1ea1b4

File tree

9 files changed

+60
-17
lines changed

9 files changed

+60
-17
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/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/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/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];

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,16 @@ Blockly.Blocks.ticks = {
1414
mainScope(this, ev, 'Ticks List');
1515
},
1616
};
17-
Blockly.JavaScript.ticks = () => ['Bot.getTicks()', Blockly.JavaScript.ORDER_ATOMIC];
17+
Blockly.JavaScript.ticks = () => ['Bot.getTicks(false)', Blockly.JavaScript.ORDER_ATOMIC];
18+
19+
Blockly.Blocks.ticks_string = {
20+
init: function init() {
21+
this.appendDummyInput().appendField(translate('Ticks String List'));
22+
this.setOutput(true, 'Array');
23+
this.setColour('#f2f2f2');
24+
this.setTooltip(translate('Returns the list of tick values (String)'));
25+
this.setHelpUrl('https://github.com/binary-com/binary-bot/wiki');
26+
},
27+
onchange: Blockly.Blocks.ticks.onchange,
28+
};
29+
Blockly.JavaScript.ticks_string = () => ['Bot.getTicks(true)', Blockly.JavaScript.ORDER_ATOMIC];

src/botPage/view/logger.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const isNewError = isNewMessage();
3737
const notify = ({ className, message, position = 'left', sound = 'silent' }) => {
3838
if (message && (position === 'left' || isNewNotification(message))) {
3939
log(className, message);
40+
4041
$.notify(message, { position: `bottom ${position}`, className });
4142
if (sound !== 'silent') {
4243
$(`#${sound}`)

static/xml/toolbox.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@
281281
<category name="Tick Analysis" i18n-text="Tick Analysis">
282282
<block type="tick_analysis"></block>
283283
<block type="tick"></block>
284+
<block type="tick_string"></block>
284285
<block type="last_digit"></block>
285286
<block type="read_ohlc">
286287
<field name="OHLCFIELD_LIST">open</field>
@@ -300,6 +301,7 @@
300301
</value>
301302
</block>
302303
<block type="ticks"></block>
304+
<block type="ticks_string"></block>
303305
<block type="lastDigitList"></block>
304306
<block type="ohlc"></block>
305307
<block type="ohlc_values"></block>

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