@@ -3,7 +3,7 @@ import json2csv from 'json2csv';
3
3
import React , { Component } from 'react' ;
4
4
import ReactDataGrid from 'react-data-grid' ;
5
5
import { observer as globalObserver } from '../../../common/utils/observer' ;
6
- import { appendRow , updateRow , saveAs } from '../shared' ;
6
+ import { appendRow , updateRow , saveAs , ticksService } from '../shared' ;
7
7
import { translate } from '../../../common/i18n' ;
8
8
import { roundBalance } from '../../common/tools' ;
9
9
import * as style from '../style' ;
@@ -57,6 +57,27 @@ export default class TradeTable extends Component {
57
57
{ key : 'contract_status' , width : 70 , resizable : true , name : translate ( 'Status' ) , formatter : StatusFormat } ,
58
58
] ;
59
59
}
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
+
60
81
componentWillMount ( ) {
61
82
const { api } = this . props ;
62
83
@@ -66,44 +87,50 @@ export default class TradeTable extends Component {
66
87
this . export ( ) ;
67
88
}
68
89
} ) ;
90
+
69
91
globalObserver . register ( 'summary.clear' , ( ) => {
70
92
this . setState ( { [ this . props . accountID ] : { ...this . state . initial } } ) ;
71
93
globalObserver . emit ( 'summary.disable_clear' ) ;
72
94
} ) ;
95
+
73
96
globalObserver . register ( 'bot.stop' , ( ) => {
74
97
const accountData = this . state [ this . props . accountID ] ;
75
98
if ( accountData && accountData . rows . length > 0 ) {
76
99
globalObserver . emit ( 'summary.enable_clear' ) ;
77
100
}
78
101
} ) ;
79
- globalObserver . register ( 'bot.contract' , info => {
80
- if ( ! info ) {
102
+
103
+ globalObserver . register ( 'bot.contract' , contract => {
104
+ if ( ! contract ) {
81
105
return ;
82
106
}
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
- } ;
93
107
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
+ }
100
125
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
+ } ) ;
106
132
} ) ;
133
+
107
134
globalObserver . register ( 'contract.settled' , contract => {
108
135
const contractID = contract . contract_id ;
109
136
this . settleContract ( api , contractID ) ;
@@ -139,40 +166,47 @@ export default class TradeTable extends Component {
139
166
140
167
refreshContract ( api , contractID ) {
141
168
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 = '-' ;
165
179
}
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 } } ) ;
167
200
} ) ;
168
- this . setState ( { [ accountID ] : { id, rows : updatedRows } } ) ;
169
201
} ) ;
170
202
}
203
+
171
204
rowGetter ( i ) {
172
205
const { accountID } = this . props ;
173
206
const { rows } = this . state [ accountID ] ;
174
207
return rows [ rows . length - 1 - i ] ;
175
208
}
209
+
176
210
export ( ) {
177
211
const { accountID } = this . props ;
178
212
0 commit comments