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

Commit 5be905d

Browse files
author
Aaron
authored
Merge pull request #2550 from aaron-binary/entry-exit-rounding
aaron/Entry exit rounding
2 parents 7bb8fa8 + ef03d25 commit 5be905d

File tree

4 files changed

+88
-69
lines changed

4 files changed

+88
-69
lines changed

gulpfile.babel.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ gulp.task(
1212
gulp.series(done => {
1313
connect.server({
1414
root : 'www',
15-
port : 8080,
15+
port : 80,
1616
livereload: true,
1717
});
1818
done();
@@ -24,7 +24,7 @@ gulp.task(
2424
gulp.series(done => {
2525
gulp.src('www/index.html').pipe(
2626
open({
27-
uri: 'http://localhost:8080/',
27+
uri: 'http://localhost:80/',
2828
})
2929
);
3030
done();

src/botPage/common/TicksService.js

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Map } from 'immutable';
22
import { historyToTicks, getLast } from 'binary-utils';
33
import { observer as globalObserver } from '../../common/utils/observer';
44
import { doUntilDone, getUUID } from '../bot/tools';
5+
import { getTokenList, removeAllTokens } from '../../common/utils/storageManager';
56

67
const parseTick = tick => ({
78
epoch: +tick.epoch,
@@ -54,13 +55,30 @@ export default class TicksService {
5455
}
5556

5657
return new Promise(resolve => {
57-
this.api.getActiveSymbolsBrief().then(r => {
58-
const { active_symbols: symbols } = r;
59-
this.pipSizes = symbols
60-
.reduce((s, i) => s.set(i.symbol, +(+i.pip).toExponential().substring(3)), new Map())
61-
.toObject();
62-
resolve(this.pipSizes);
63-
});
58+
const getActiveSymbols = () => {
59+
this.api.getActiveSymbolsBrief().then(r => {
60+
const { active_symbols: symbols } = r;
61+
this.pipSizes = symbols.reduce((accumulator, currSymbol) => {
62+
// eslint-disable-next-line no-param-reassign
63+
accumulator[currSymbol.symbol] = `${currSymbol.pip}`.length - 2;
64+
return accumulator;
65+
}, {});
66+
resolve(this.pipSizes);
67+
});
68+
};
69+
70+
const tokenList = getTokenList();
71+
if (tokenList.length) {
72+
this.api
73+
.authorize(tokenList[0].token)
74+
.then(() => getActiveSymbols())
75+
.catch(() => {
76+
removeAllTokens();
77+
getActiveSymbols();
78+
});
79+
} else {
80+
getActiveSymbols();
81+
}
6482
});
6583
}
6684
request(options) {
@@ -173,7 +191,10 @@ export default class TicksService {
173191
}
174192
observe() {
175193
this.api.events.on('tick', r => {
176-
const { tick, tick: { symbol, id } } = r;
194+
const {
195+
tick,
196+
tick: { symbol, id },
197+
} = r;
177198

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

184205
this.api.events.on('ohlc', r => {
185-
const { ohlc, ohlc: { symbol, granularity, id } } = r;
206+
const {
207+
ohlc,
208+
ohlc: { symbol, granularity, id },
209+
} = r;
186210

187211
if (this.candles.hasIn([symbol, Number(granularity)])) {
188212
this.subscriptions = this.subscriptions.setIn(['ohlc', symbol, Number(granularity)], id);

src/botPage/view/Dialogs/Chart.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ChartContent extends PureComponent {
5454

5555
componentDidMount() {
5656
globalObserver.register('bot.init', s => {
57-
if (this.state.symbol !== s) {
57+
if (s && this.state.symbol !== s) {
5858
this.setState({ symbol: s });
5959
}
6060
});

src/botPage/view/TradeInfoPanel/TradeTable.js

Lines changed: 52 additions & 57 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, ticksService } from '../shared';
6+
import { appendRow, updateRow, saveAs } from '../shared';
77
import { translate } from '../../../common/i18n';
88
import { roundBalance } from '../../common/tools';
99
import * as style from '../style';
@@ -58,8 +58,7 @@ export default class TradeTable extends Component {
5858
];
5959
}
6060

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

7069
if (contract.entry_tick) {
71-
tradeObj.entry_tick = (+contract.entry_tick).toFixed(symbolPipSize);
70+
tradeObj.entry_tick = contract.entry_spot_display_value;
7271
}
7372

7473
if (contract.exit_tick) {
75-
tradeObj.exit_tick = (+contract.exit_tick).toFixed(symbolPipSize);
74+
tradeObj.exit_tick = contract.exit_tick_display_value;
7675
}
7776

7877
return tradeObj;
@@ -105,30 +104,28 @@ export default class TradeTable extends Component {
105104
return;
106105
}
107106

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-
}
107+
const tradeObj = TradeTable.getTradeObject(contract);
108+
const trade = {
109+
...tradeObj,
110+
profit : getProfit(tradeObj),
111+
contract_status : translate('Pending'),
112+
contract_settled: false,
113+
};
114+
115+
const { accountID } = tradeObj;
116+
const accountStat = this.getAccountStat(accountID);
117+
const { rows } = accountStat;
118+
const prevRowIndex = rows.findIndex(t => t.reference === trade.reference);
119+
120+
if (trade.is_expired && trade.is_sold && !trade.exit_tick) {
121+
trade.exit_tick = '-';
122+
}
125123

126-
if (prevRowIndex >= 0) {
127-
this.setState({ [accountID]: updateRow(prevRowIndex, trade, accountStat) });
128-
} else {
129-
this.setState({ [accountID]: appendRow(trade, accountStat) });
130-
}
131-
});
124+
if (prevRowIndex >= 0) {
125+
this.setState({ [accountID]: updateRow(prevRowIndex, trade, accountStat) });
126+
} else {
127+
this.setState({ [accountID]: appendRow(trade, accountStat) });
128+
}
132129
});
133130

134131
globalObserver.register('contract.settled', contract => {
@@ -166,38 +163,36 @@ export default class TradeTable extends Component {
166163

167164
refreshContract(api, contractID) {
168165
return api.getContractInfo(contractID).then(r => {
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 = '-';
179-
}
166+
const contract = r.proposal_open_contract;
167+
const tradeObj = TradeTable.getTradeObject(contract);
168+
const trade = {
169+
...tradeObj,
170+
profit: getProfit(tradeObj),
171+
};
172+
173+
if (trade.is_expired && trade.is_sold && !trade.exit_tick) {
174+
trade.exit_tick = '-';
175+
}
180176

181-
const { accountID } = this.props;
182-
const { id } = this.state[accountID];
183-
const rows = this.state[accountID].rows.slice();
177+
const { accountID } = this.props;
178+
const { id } = this.state[accountID];
179+
const rows = this.state[accountID].rows.slice();
184180

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 } });
181+
const updatedRows = rows.map(row => {
182+
const { reference } = row;
183+
184+
if (reference === trade.reference) {
185+
return {
186+
contract_status : translate('Settled'),
187+
contract_settled: true,
188+
reference,
189+
...trade,
190+
};
191+
}
192+
return row;
200193
});
194+
195+
this.setState({ [accountID]: { id, rows: updatedRows } });
201196
});
202197
}
203198

0 commit comments

Comments
 (0)