Skip to content

Commit 74ff06d

Browse files
authored
Merge branch 'dev' into illegal-break-statement
2 parents b3cc10c + 925d273 commit 74ff06d

File tree

6 files changed

+109
-58
lines changed

6 files changed

+109
-58
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;

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)
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