Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/botPage/bot/TradeEngine/Proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export default Engine =>
}

return {
id : toBuy.id,
askPrice: toBuy.ask_price,
proposal: toBuy,
currency: this.tradeOption.currency,
};
}
renewProposalsOnPurchase() {
Expand Down
17 changes: 13 additions & 4 deletions src/botPage/bot/TradeEngine/Purchase.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,25 @@ export default Engine =>
return Promise.resolve();
}

const { id, askPrice } = this.selectProposal(contractType);

const { currency, proposal } = this.selectProposal(contractType);
const onSuccess = r => {
const { buy } = r;

contractStatus({
id : 'contract.purchase_recieved',
data: buy.transaction_id,
proposal,
currency,
});

this.subscribeToOpenContract(buy.contract_id);
this.store.dispatch(purchaseSuccessful());
this.renewProposalsOnPurchase();

delayIndex = 0;

notify('info', `${translate('Bought')}: ${buy.longcode} (${translate('ID')}: ${buy.transaction_id})`);

info({
accountID : this.accountInfo.loginid,
totalRuns : this.updateAndReturnTotalRuns(),
Expand All @@ -37,13 +42,17 @@ export default Engine =>
});
};

const action = () => this.api.buyContract(id, askPrice);
this.isSold = false;

contractStatus({
id : 'contract.purchase_sent',
data: askPrice,
data: proposal.ask_price,
proposal,
currency,
});

const action = () => this.api.buyContract(proposal.id, proposal.ask_price);

if (!this.options.timeMachineEnabled) {
return doUntilDone(action).then(onSuccess);
}
Expand Down
132 changes: 83 additions & 49 deletions src/botPage/view/TradeInfoPanel/TradeTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import json2csv from 'json2csv';
import React, { Component } from 'react';
import ReactDataGrid from 'react-data-grid';
import { observer as globalObserver } from '../../../common/utils/observer';
import { appendRow, updateRow, saveAs } from '../shared';
import { appendRow, updateRow, saveAs, ticksService } from '../shared';
import { translate } from '../../../common/i18n';
import { roundBalance } from '../../common/tools';
import * as style from '../style';
Expand Down Expand Up @@ -57,6 +57,27 @@ export default class TradeTable extends Component {
{ key: 'contract_status', width: 70, resizable: true, name: translate('Status'), formatter: StatusFormat },
];
}

static getTradeObject(pipSizes, contract) {
const symbolPipSize = pipSizes[contract.underlying];
const tradeObj = {
...contract,
reference: `${contract.transaction_ids.buy}`,
buy_price: roundBalance({ balance: contract.buy_price, currency: contract.currency }),
timestamp: getTimestamp(contract.date_start),
};

if (contract.entry_tick) {
tradeObj.entry_tick = (+contract.entry_tick).toFixed(symbolPipSize);
}

if (contract.exit_tick) {
tradeObj.exit_tick = (+contract.exit_tick).toFixed(symbolPipSize);
}

return tradeObj;
}

componentWillMount() {
const { api } = this.props;

Expand All @@ -66,44 +87,50 @@ export default class TradeTable extends Component {
this.export();
}
});

globalObserver.register('summary.clear', () => {
this.setState({ [this.props.accountID]: { ...this.state.initial } });
globalObserver.emit('summary.disable_clear');
});

globalObserver.register('bot.stop', () => {
const accountData = this.state[this.props.accountID];
if (accountData && accountData.rows.length > 0) {
globalObserver.emit('summary.enable_clear');
}
});
globalObserver.register('bot.contract', info => {
if (!info) {

globalObserver.register('bot.contract', contract => {
if (!contract) {
return;
}
const timestamp = getTimestamp(info.date_start);
const tradeObj = { reference: info.transaction_ids.buy, ...info, timestamp };
const { accountID } = tradeObj;

const trade = {
...tradeObj,
profit : getProfit(tradeObj),
contract_status : translate('Pending'),
contract_settled: false,
};

const accountStat = this.getAccountStat(accountID);

const { rows } = accountStat;
const prevRowIndex = rows.findIndex(t => t.reference === trade.reference);

if (trade.is_expired && trade.is_sold && !trade.exit_tick) trade.exit_tick = '-';
ticksService.requestPipSizes().then(pipSizes => {
const tradeObj = TradeTable.getTradeObject(pipSizes, contract);
const trade = {
...tradeObj,
profit : getProfit(tradeObj),
contract_status : translate('Pending'),
contract_settled: false,
};

const { accountID } = tradeObj;
const accountStat = this.getAccountStat(accountID);
const { rows } = accountStat;
const prevRowIndex = rows.findIndex(t => t.reference === trade.reference);

if (trade.is_expired && trade.is_sold && !trade.exit_tick) {
trade.exit_tick = '-';
}

if (prevRowIndex >= 0) {
this.setState({ [accountID]: updateRow(prevRowIndex, trade, accountStat) });
} else {
this.setState({ [accountID]: appendRow(trade, accountStat) });
}
if (prevRowIndex >= 0) {
this.setState({ [accountID]: updateRow(prevRowIndex, trade, accountStat) });
} else {
this.setState({ [accountID]: appendRow(trade, accountStat) });
}
});
});

globalObserver.register('contract.settled', contract => {
const contractID = contract.contract_id;
this.settleContract(api, contractID);
Expand Down Expand Up @@ -139,40 +166,47 @@ export default class TradeTable extends Component {

refreshContract(api, contractID) {
return api.getContractInfo(contractID).then(r => {
const contract = r.proposal_open_contract;
const timestamp = getTimestamp(contract.date_start);
const tradeObj = { reference: contract.transaction_ids.buy, ...contract, timestamp };
const { accountID } = this.props;

const trade = {
...tradeObj,
profit: getProfit(tradeObj),
};

if (trade.is_expired && trade.is_sold && !trade.exit_tick) trade.exit_tick = '-';

const { id } = this.state[accountID];
const rows = this.state[accountID].rows.slice();
const updatedRows = rows.map(row => {
const { reference } = row;
if (reference === trade.reference) {
return {
contract_status : translate('Settled'),
contract_settled: true,
reference,
...trade,
};
ticksService.requestPipSizes().then(pipSizes => {
const contract = r.proposal_open_contract;
const tradeObj = TradeTable.getTradeObject(pipSizes, contract);
const trade = {
...tradeObj,
profit: getProfit(tradeObj),
};

if (trade.is_expired && trade.is_sold && !trade.exit_tick) {
trade.exit_tick = '-';
}
return row;

const { accountID } = this.props;
const { id } = this.state[accountID];
const rows = this.state[accountID].rows.slice();

const updatedRows = rows.map(row => {
const { reference } = row;

if (reference === trade.reference) {
return {
contract_status : translate('Settled'),
contract_settled: true,
reference,
...trade,
};
}
return row;
});

this.setState({ [accountID]: { id, rows: updatedRows } });
});
this.setState({ [accountID]: { id, rows: updatedRows } });
});
}

rowGetter(i) {
const { accountID } = this.props;
const { rows } = this.state[accountID];
return rows[rows.length - 1 - i];
}

export() {
const { accountID } = this.props;

Expand Down
11 changes: 10 additions & 1 deletion src/botPage/view/TradeInfoPanel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Summary from './Summary';
import TradeTable from './TradeTable';
import RunButton from './RunButton';
import ClearButton from './ClearButton';
import { roundBalance } from '../../common/tools';

const resetAnimation = () => {
$('.circle-wrapper')
Expand Down Expand Up @@ -71,7 +72,14 @@ class AnimateTrade extends Component {
if (contractStatus.id === 'contract.purchase_sent') {
resetAnimation();
activateStage(0);
this.setState({ buy_price: contractStatus.data, stopMessage: this.indicatorMessages.stopping });

this.setState({
buy_price: roundBalance({
balance : contractStatus.proposal.ask_price,
currency: contractStatus.currency,
}),
stopMessage: this.indicatorMessages.stopping,
});
} else if (contractStatus.id === 'contract.purchase_recieved') {
$('.line').addClass('active');
activateStage(1);
Expand All @@ -81,6 +89,7 @@ class AnimateTrade extends Component {
activateStage(2);
this.setState({ sell_id: contractStatus.data, stopMessage: this.indicatorMessages.stopped });
}

activateStage(contractStatus.id);
}
render() {
Expand Down
2 changes: 1 addition & 1 deletion src/botPage/view/blockly/blocks/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ export const getPredictionForContracts = (contracts, selectedContractType) => {
if (contract && contract.last_digit_range) {
predictionRange.push(...contract.last_digit_range);
} else {
predictionRange.push(0);
predictionRange.push(1, 2, 3, 4, 5);
}
}
return predictionRange;
Expand Down
1 change: 0 additions & 1 deletion static/xml/toolbox.xml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@
<block type="controls_whileUntil"></block>
<block type="controls_for"></block>
<block type="controls_forEach"></block>
<block type="controls_for"></block>
<block type="controls_flow_statements"></block>
</category>
</category>
Expand Down