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

Commit 2f023d9

Browse files
authored
Merge branch 'dev' into webhook-blocks
2 parents 3d995d8 + 0e89265 commit 2f023d9

File tree

9 files changed

+138
-60
lines changed

9 files changed

+138
-60
lines changed

src/botPage/bot/TradeEngine/Proposal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ export default Engine =>
3434
}
3535

3636
return {
37-
id : toBuy.id,
38-
askPrice: toBuy.ask_price,
37+
proposal: toBuy,
38+
currency: this.tradeOption.currency,
3939
};
4040
}
4141
renewProposalsOnPurchase() {

src/botPage/bot/TradeEngine/Purchase.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,25 @@ export default Engine =>
1414
return Promise.resolve();
1515
}
1616

17-
const { id, askPrice } = this.selectProposal(contractType);
18-
17+
const { currency, proposal } = this.selectProposal(contractType);
1918
const onSuccess = r => {
2019
const { buy } = r;
20+
2121
contractStatus({
2222
id : 'contract.purchase_recieved',
2323
data: buy.transaction_id,
24+
proposal,
25+
currency,
2426
});
2527

2628
this.subscribeToOpenContract(buy.contract_id);
2729
this.store.dispatch(purchaseSuccessful());
2830
this.renewProposalsOnPurchase();
31+
2932
delayIndex = 0;
33+
3034
notify('info', `${translate('Bought')}: ${buy.longcode} (${translate('ID')}: ${buy.transaction_id})`);
35+
3136
info({
3237
accountID : this.accountInfo.loginid,
3338
totalRuns : this.updateAndReturnTotalRuns(),
@@ -37,13 +42,17 @@ export default Engine =>
3742
});
3843
};
3944

40-
const action = () => this.api.buyContract(id, askPrice);
4145
this.isSold = false;
46+
4247
contractStatus({
4348
id : 'contract.purchase_sent',
44-
data: askPrice,
49+
data: proposal.ask_price,
50+
proposal,
51+
currency,
4552
});
4653

54+
const action = () => this.api.buyContract(proposal.id, proposal.ask_price);
55+
4756
if (!this.options.timeMachineEnabled) {
4857
return doUntilDone(action).then(onSuccess);
4958
}

src/botPage/view/TradeInfoPanel/TradeTable.js

Lines changed: 83 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import json2csv from 'json2csv';
33
import React, { Component } from 'react';
44
import ReactDataGrid from 'react-data-grid';
55
import { observer as globalObserver } from '../../../common/utils/observer';
6-
import { appendRow, updateRow, saveAs } from '../shared';
6+
import { appendRow, updateRow, saveAs, ticksService } from '../shared';
77
import { translate } from '../../../common/i18n';
88
import { roundBalance } from '../../common/tools';
99
import * as style from '../style';
@@ -57,6 +57,27 @@ export default class TradeTable extends Component {
5757
{ key: 'contract_status', width: 70, resizable: true, name: translate('Status'), formatter: StatusFormat },
5858
];
5959
}
60+
61+
static getTradeObject(pipSizes, contract) {
62+
const symbolPipSize = pipSizes[contract.underlying];
63+
const tradeObj = {
64+
...contract,
65+
reference: `${contract.transaction_ids.buy}`,
66+
buy_price: roundBalance({ balance: contract.buy_price, currency: contract.currency }),
67+
timestamp: getTimestamp(contract.date_start),
68+
};
69+
70+
if (contract.entry_tick) {
71+
tradeObj.entry_tick = (+contract.entry_tick).toFixed(symbolPipSize);
72+
}
73+
74+
if (contract.exit_tick) {
75+
tradeObj.exit_tick = (+contract.exit_tick).toFixed(symbolPipSize);
76+
}
77+
78+
return tradeObj;
79+
}
80+
6081
componentWillMount() {
6182
const { api } = this.props;
6283

@@ -66,44 +87,50 @@ export default class TradeTable extends Component {
6687
this.export();
6788
}
6889
});
90+
6991
globalObserver.register('summary.clear', () => {
7092
this.setState({ [this.props.accountID]: { ...this.state.initial } });
7193
globalObserver.emit('summary.disable_clear');
7294
});
95+
7396
globalObserver.register('bot.stop', () => {
7497
const accountData = this.state[this.props.accountID];
7598
if (accountData && accountData.rows.length > 0) {
7699
globalObserver.emit('summary.enable_clear');
77100
}
78101
});
79-
globalObserver.register('bot.contract', info => {
80-
if (!info) {
102+
103+
globalObserver.register('bot.contract', contract => {
104+
if (!contract) {
81105
return;
82106
}
83-
const timestamp = getTimestamp(info.date_start);
84-
const tradeObj = { reference: info.transaction_ids.buy, ...info, timestamp };
85-
const { accountID } = tradeObj;
86-
87-
const trade = {
88-
...tradeObj,
89-
profit : getProfit(tradeObj),
90-
contract_status : translate('Pending'),
91-
contract_settled: false,
92-
};
93107

94-
const accountStat = this.getAccountStat(accountID);
95-
96-
const { rows } = accountStat;
97-
const prevRowIndex = rows.findIndex(t => t.reference === trade.reference);
98-
99-
if (trade.is_expired && trade.is_sold && !trade.exit_tick) trade.exit_tick = '-';
108+
ticksService.requestPipSizes().then(pipSizes => {
109+
const tradeObj = TradeTable.getTradeObject(pipSizes, contract);
110+
const trade = {
111+
...tradeObj,
112+
profit : getProfit(tradeObj),
113+
contract_status : translate('Pending'),
114+
contract_settled: false,
115+
};
116+
117+
const { accountID } = tradeObj;
118+
const accountStat = this.getAccountStat(accountID);
119+
const { rows } = accountStat;
120+
const prevRowIndex = rows.findIndex(t => t.reference === trade.reference);
121+
122+
if (trade.is_expired && trade.is_sold && !trade.exit_tick) {
123+
trade.exit_tick = '-';
124+
}
100125

101-
if (prevRowIndex >= 0) {
102-
this.setState({ [accountID]: updateRow(prevRowIndex, trade, accountStat) });
103-
} else {
104-
this.setState({ [accountID]: appendRow(trade, accountStat) });
105-
}
126+
if (prevRowIndex >= 0) {
127+
this.setState({ [accountID]: updateRow(prevRowIndex, trade, accountStat) });
128+
} else {
129+
this.setState({ [accountID]: appendRow(trade, accountStat) });
130+
}
131+
});
106132
});
133+
107134
globalObserver.register('contract.settled', contract => {
108135
const contractID = contract.contract_id;
109136
this.settleContract(api, contractID);
@@ -139,40 +166,47 @@ export default class TradeTable extends Component {
139166

140167
refreshContract(api, contractID) {
141168
return api.getContractInfo(contractID).then(r => {
142-
const contract = r.proposal_open_contract;
143-
const timestamp = getTimestamp(contract.date_start);
144-
const tradeObj = { reference: contract.transaction_ids.buy, ...contract, timestamp };
145-
const { accountID } = this.props;
146-
147-
const trade = {
148-
...tradeObj,
149-
profit: getProfit(tradeObj),
150-
};
151-
152-
if (trade.is_expired && trade.is_sold && !trade.exit_tick) trade.exit_tick = '-';
153-
154-
const { id } = this.state[accountID];
155-
const rows = this.state[accountID].rows.slice();
156-
const updatedRows = rows.map(row => {
157-
const { reference } = row;
158-
if (reference === trade.reference) {
159-
return {
160-
contract_status : translate('Settled'),
161-
contract_settled: true,
162-
reference,
163-
...trade,
164-
};
169+
ticksService.requestPipSizes().then(pipSizes => {
170+
const contract = r.proposal_open_contract;
171+
const tradeObj = TradeTable.getTradeObject(pipSizes, contract);
172+
const trade = {
173+
...tradeObj,
174+
profit: getProfit(tradeObj),
175+
};
176+
177+
if (trade.is_expired && trade.is_sold && !trade.exit_tick) {
178+
trade.exit_tick = '-';
165179
}
166-
return row;
180+
181+
const { accountID } = this.props;
182+
const { id } = this.state[accountID];
183+
const rows = this.state[accountID].rows.slice();
184+
185+
const updatedRows = rows.map(row => {
186+
const { reference } = row;
187+
188+
if (reference === trade.reference) {
189+
return {
190+
contract_status : translate('Settled'),
191+
contract_settled: true,
192+
reference,
193+
...trade,
194+
};
195+
}
196+
return row;
197+
});
198+
199+
this.setState({ [accountID]: { id, rows: updatedRows } });
167200
});
168-
this.setState({ [accountID]: { id, rows: updatedRows } });
169201
});
170202
}
203+
171204
rowGetter(i) {
172205
const { accountID } = this.props;
173206
const { rows } = this.state[accountID];
174207
return rows[rows.length - 1 - i];
175208
}
209+
176210
export() {
177211
const { accountID } = this.props;
178212

src/botPage/view/TradeInfoPanel/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Summary from './Summary';
55
import TradeTable from './TradeTable';
66
import RunButton from './RunButton';
77
import ClearButton from './ClearButton';
8+
import { roundBalance } from '../../common/tools';
89

910
const resetAnimation = () => {
1011
$('.circle-wrapper')
@@ -71,7 +72,14 @@ class AnimateTrade extends Component {
7172
if (contractStatus.id === 'contract.purchase_sent') {
7273
resetAnimation();
7374
activateStage(0);
74-
this.setState({ buy_price: contractStatus.data, stopMessage: this.indicatorMessages.stopping });
75+
76+
this.setState({
77+
buy_price: roundBalance({
78+
balance : contractStatus.proposal.ask_price,
79+
currency: contractStatus.currency,
80+
}),
81+
stopMessage: this.indicatorMessages.stopping,
82+
});
7583
} else if (contractStatus.id === 'contract.purchase_recieved') {
7684
$('.line').addClass('active');
7785
activateStage(1);
@@ -81,6 +89,7 @@ class AnimateTrade extends Component {
8189
activateStage(2);
8290
this.setState({ sell_id: contractStatus.data, stopMessage: this.indicatorMessages.stopped });
8391
}
92+
8493
activateStage(contractStatus.id);
8594
}
8695
render() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ export const getPredictionForContracts = (contracts, selectedContractType) => {
404404
if (contract && contract.last_digit_range) {
405405
predictionRange.push(...contract.last_digit_range);
406406
} else {
407-
predictionRange.push(0);
407+
predictionRange.push(1, 2, 3, 4, 5);
408408
}
409409
}
410410
return predictionRange;

src/botPage/view/blockly/customBlockly.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,21 @@ Blockly.Toolbox.TreeNode.prototype.onClick_ = function(_e) {
358358
}
359359
this.updateRow();
360360
};
361+
362+
/**
363+
* Preload all the audio files so that they play quickly when asked for.
364+
* @package
365+
*/
366+
Blockly.WorkspaceAudio.prototype.preload = function() {
367+
for (var name in this.SOUNDS_) {
368+
var sound = this.SOUNDS_[name];
369+
sound.volume = 0.01;
370+
sound.play().catch(function() {});
371+
sound.pause();
372+
// iOS can only process one sound at a time. Trying to load more than one
373+
// corrupts the earlier ones. Just load one and leave the others uncached.
374+
if (goog.userAgent.IPAD || goog.userAgent.IPHONE) {
375+
break;
376+
}
377+
}
378+
};

src/botPage/view/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import View from './View';
55
import '../../common/binary-ui/dropdown';
66
import Elevio from '../../common/elevio';
77
import GTM from '../../common/gtm';
8+
import { isProduction } from '../../common/utils/tools';
89

910
$.ajaxSetup({
1011
cache: false,
@@ -14,7 +15,7 @@ $.ajaxSetup({
1415
window._trackJs = {
1516
token : '346262e7ffef497d85874322fff3bbf8',
1617
application: 'binary-bot',
17-
enabled : window.location.hostname !== 'localhost',
18+
enabled : isProduction(),
1819
console : {
1920
display: false,
2021
},

static/css/_panel.scss

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,14 @@ $disabled-color: #F2F2F2;
5959
font-size: 11px;
6060
color: lightgray;
6161
}
62+
#current-trade-status{
63+
margin-top: 3.5em;
64+
}
6265
.stage {
6366
display: inline-block;
6467
margin: 0 8.68% 0 8.68%;
68+
vertical-align: top;
69+
max-width: 120px;
6570
.stage-tooltip .triangle {
6671
margin-top: 0.7em;
6772
margin-left: 50%;
@@ -75,11 +80,13 @@ $disabled-color: #F2F2F2;
7580
}
7681
.stage-tooltip.top {
7782
margin-bottom: 0.5em;
83+
margin-top: -2.5em;
84+
position: absolute;
7885
}
7986
.stage-tooltip p {
8087
font-size: 11px;
8188
text-align: center;
82-
margin-top: -0.9em;
89+
margin-top: -0.91em;
8390
padding: 0.5em;
8491
border-radius: 0.5em;
8592
background-color: #fef1cf;
@@ -101,6 +108,7 @@ $disabled-color: #F2F2F2;
101108
.stage-label {
102109
text-align: center;
103110
font-size: 11px;
111+
min-height: 24px;
104112
}
105113
.circle-wrapper {
106114
width: $static-circle-diameter;

static/xml/toolbox.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@
241241
<block type="controls_whileUntil"></block>
242242
<block type="controls_for"></block>
243243
<block type="controls_forEach"></block>
244-
<block type="controls_for"></block>
245244
<block type="controls_flow_statements"></block>
246245
</category>
247246
</category>

0 commit comments

Comments
 (0)