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 gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ gulp.task(
gulp.series(done => {
connect.server({
root : 'www',
port : 8080,
port : 80,
livereload: true,
});
done();
Expand All @@ -24,7 +24,7 @@ gulp.task(
gulp.series(done => {
gulp.src('www/index.html').pipe(
open({
uri: 'http://localhost:8080/',
uri: 'http://localhost:80/',
})
);
done();
Expand Down
42 changes: 33 additions & 9 deletions src/botPage/common/TicksService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Map } from 'immutable';
import { historyToTicks, getLast } from 'binary-utils';
import { observer as globalObserver } from '../../common/utils/observer';
import { doUntilDone, getUUID } from '../bot/tools';
import { getTokenList, removeAllTokens } from '../../common/utils/storageManager';

const parseTick = tick => ({
epoch: +tick.epoch,
Expand Down Expand Up @@ -54,13 +55,30 @@ export default class TicksService {
}

return new Promise(resolve => {
this.api.getActiveSymbolsBrief().then(r => {
const { active_symbols: symbols } = r;
this.pipSizes = symbols
.reduce((s, i) => s.set(i.symbol, +(+i.pip).toExponential().substring(3)), new Map())
.toObject();
resolve(this.pipSizes);
});
const getActiveSymbols = () => {
this.api.getActiveSymbolsBrief().then(r => {
const { active_symbols: symbols } = r;
this.pipSizes = symbols.reduce((accumulator, currSymbol) => {
// eslint-disable-next-line no-param-reassign
accumulator[currSymbol.symbol] = `${currSymbol.pip}`.length - 2;
return accumulator;
}, {});
resolve(this.pipSizes);
});
};

const tokenList = getTokenList();
if (tokenList.length) {
this.api
.authorize(tokenList[0].token)
.then(() => getActiveSymbols())
.catch(() => {
removeAllTokens();
getActiveSymbols();
});
} else {
getActiveSymbols();
}
});
}
request(options) {
Expand Down Expand Up @@ -173,7 +191,10 @@ export default class TicksService {
}
observe() {
this.api.events.on('tick', r => {
const { tick, tick: { symbol, id } } = r;
const {
tick,
tick: { symbol, id },
} = r;

if (this.ticks.has(symbol)) {
this.subscriptions = this.subscriptions.setIn(['tick', symbol], id);
Expand All @@ -182,7 +203,10 @@ export default class TicksService {
});

this.api.events.on('ohlc', r => {
const { ohlc, ohlc: { symbol, granularity, id } } = r;
const {
ohlc,
ohlc: { symbol, granularity, id },
} = r;

if (this.candles.hasIn([symbol, Number(granularity)])) {
this.subscriptions = this.subscriptions.setIn(['ohlc', symbol, Number(granularity)], id);
Expand Down
2 changes: 1 addition & 1 deletion src/botPage/view/Dialogs/Chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ChartContent extends PureComponent {

componentDidMount() {
globalObserver.register('bot.init', s => {
if (this.state.symbol !== s) {
if (s && this.state.symbol !== s) {
this.setState({ symbol: s });
}
});
Expand Down
109 changes: 52 additions & 57 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, ticksService } from '../shared';
import { appendRow, updateRow, saveAs } from '../shared';
import { translate } from '../../../common/i18n';
import { roundBalance } from '../../common/tools';
import * as style from '../style';
Expand Down Expand Up @@ -58,8 +58,7 @@ export default class TradeTable extends Component {
];
}

static getTradeObject(pipSizes, contract) {
const symbolPipSize = pipSizes[contract.underlying];
static getTradeObject(contract) {
const tradeObj = {
...contract,
reference: `${contract.transaction_ids.buy}`,
Expand All @@ -68,11 +67,11 @@ export default class TradeTable extends Component {
};

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

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

return tradeObj;
Expand Down Expand Up @@ -105,30 +104,28 @@ export default class TradeTable extends Component {
return;
}

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 = '-';
}
const tradeObj = TradeTable.getTradeObject(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 => {
Expand Down Expand Up @@ -166,38 +163,36 @@ export default class TradeTable extends Component {

refreshContract(api, contractID) {
return api.getContractInfo(contractID).then(r => {
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 = '-';
}
const contract = r.proposal_open_contract;
const tradeObj = TradeTable.getTradeObject(contract);
const trade = {
...tradeObj,
profit: getProfit(tradeObj),
};

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

const { accountID } = this.props;
const { id } = this.state[accountID];
const rows = this.state[accountID].rows.slice();
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 } });
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 } });
});
}

Expand Down