4
4
<div class =" card-header" >
5
5
<h3 class =" card-title" >Positions</h3 > <span class =" text-muted float-right" ><transition name =" slide-fade" mode =" out-in" ><div :key =" positionsUpdatedAt" >{{ positionsUpdatedAt }}</div ></transition ></span >
6
6
</div >
7
- <!-- /.card-header -->
7
+
8
8
<div class =" card-body" >
9
9
<table class =" table table-bordered table-sm table-hover" >
10
10
<thead >
31
31
</td >
32
32
<td >
33
33
<template v-if =" !! position .currency " >
34
- {{ position.currency|filter_price }}
34
+ {{ formatPrice( position.currency) }}
35
35
</template >
36
36
<template v-if =" !! position .currencyProfit " >
37
- <span class =" text-muted" > / {{ position.currencyProfit|filter_price }}</span >
37
+ <span class =" text-muted" > / {{ formatPrice( position.currencyProfit) }}</span >
38
38
</template >
39
39
</td >
40
40
<td >
41
41
<span v-if =" typeof position.position.profit !== 'undefined'" v-bind:class =" { 'text-success': position.position.profit >= 0, 'text-danger': position.position.profit < 0 }" >
42
- {{ position.position.profit|round( 2) }} %
42
+ {{ round( position.position.profit, 2) }} %
43
43
</span >
44
44
</td >
45
45
<td >
46
46
<template v-if =" !! position .position .entry " >
47
- {{ position.position.entry|filter_price }}
47
+ {{ formatPrice( position.position.entry) }}
48
48
</template >
49
49
</td >
50
50
<td >
51
51
<template v-if =" !! position .position .updatedAt " >
52
- {{ position.position.updatedAt|date( 'd.m.y H:i') }}
52
+ {{ date( position.position.updatedAt, 'd.m.y H:i') }}
53
53
</template >
54
54
</td >
55
55
<td >
56
56
<template v-if =" !! position .position .createdAt " >
57
- {{ position.position.createdAt|date( 'd.m.y H:i') }}
57
+ {{ date( position.position.createdAt, 'd.m.y H:i') }}
58
58
</template >
59
59
</td >
60
60
<td >
77
77
78
78
<div class =" card" >
79
79
<div class =" card-header" >
80
- <h3 class =" card-title" >Orders</h3 > <span class =" text-muted float-right" ><transition name =" slide-fade" mode =" out-in" ><div :key =" positionsUpdatedAt " >{{ ordersUpdatedAt }}</div ></transition ></span >
80
+ <h3 class =" card-title" >Orders</h3 > <span class =" text-muted float-right" ><transition name =" slide-fade" mode =" out-in" ><div :key =" ordersUpdatedAt " >{{ ordersUpdatedAt }}</div ></transition ></span >
81
81
</div >
82
82
<div class =" card-body" >
83
83
<div class =" table-responsive" >
106
106
<td ><a target =" blank" :href =" '/tradingview/' + order.exchange + ':' + order.order.symbol" >{{ order.order.symbol }}</a ></td >
107
107
<td >{{ order.order.type }}</td >
108
108
<td >{{ order.order.id }}</td >
109
- <td >{{ order.order.price }}<span class =" text-muted" v-if =" order.percent_to_price" title =" Percent to current price" > {{ order.percent_to_price|round( 1) }} %</span ></td >
109
+ <td >{{ order.order.price }}<span class =" text-muted" v-if =" order.percent_to_price" title =" Percent to current price" > {{ round( order.percent_to_price, 1) }} %</span ></td >
110
110
<td v-bind:class =" { 'text-success': order.order.amount > 0, 'text-danger': order.order.amount < 0 }" >{{ order.order.amount }}</td >
111
111
<td >{{ order.order.retry }}</td >
112
112
<td >{{ order.order.ourId }}</td >
113
- <td >{{ order.order.createdAt|date( 'd.m.y H:i') }}</td >
114
- <td >{{ order.order.updatedAt|date( 'd.m.y H:i') }}</td >
113
+ <td >{{ date( order.order.createdAt, 'd.m.y H:i') }}</td >
114
+ <td >{{ date( order.order.updatedAt, 'd.m.y H:i') }}</td >
115
115
<td >{{ order.order.status }}</td >
116
116
<td >
117
117
<i v-if =" order.order.side === 'sell'" class =" fas fa-chevron-circle-down text-danger" title =" short" ></i >
130
130
</template >
131
131
132
132
<script >
133
- module .exports = {
134
- data : function () {
133
+ import { ref } from ' vue'
134
+
135
+ export default {
136
+ data () {
137
+ const positionsUpdatedAt = ref (null );
138
+ const ordersUpdatedAt = ref (null );
139
+ const orders = ref ([]);
140
+ const positions = ref ([]);
141
+
135
142
return {
136
- positions : [] ,
137
- orders : [] ,
138
- positionsUpdatedAt : ' ' ,
139
- ordersUpdatedAt : ' '
143
+ positionsUpdatedAt ,
144
+ ordersUpdatedAt ,
145
+ orders ,
146
+ positions
140
147
}
141
148
},
142
- created : function () {
143
- this .fetchPageAsJson ();
144
- this .timer = setInterval (this .fetchPageAsJson , 3000 );
145
- },
146
149
methods: {
147
150
async fetchPageAsJson () {
148
151
const res = await fetch (' /trades.json' );
@@ -155,27 +158,86 @@ module.exports = {
155
158
this .positions = data .positions || [];
156
159
this .orders = data .orders || [];
157
160
161
+ this .positions = [
162
+ {
163
+ ' currency' : 12.12 ,
164
+ ' currencyProfit' : 12 ,
165
+ ' exchange' : ' binance' ,
166
+ ' position' : {
167
+ ' type' : ' long' ,
168
+ ' amount' : 12.12 ,
169
+ ' profit' : 12 ,
170
+ ' entry' : 13.23 ,
171
+ ' updatedAt' : new Date (),
172
+ ' createdAt' : new Date (),
173
+ }
174
+ }
175
+ ]
176
+
177
+ this .orders = [
178
+ {
179
+ ' currency' : 12.12 ,
180
+ ' currencyProfit' : 12 ,
181
+ ' exchange' : ' binance' ,
182
+ ' order' : {
183
+ ' type' : ' ggg' ,
184
+ ' id' : ' aaa' ,
185
+ ' price' : 12.12 ,
186
+ ' percent_to_price' : 4 ,
187
+ ' ourId' : ' 12' ,
188
+ ' entry' : 13.23 ,
189
+ ' side' : ' buy' ,
190
+ ' updatedAt' : new Date (),
191
+ ' createdAt' : new Date (),
192
+ ' status' : ' aaaa' ,
193
+ }
194
+ }
195
+ ];
196
+
158
197
this .positionsUpdatedAt = new Date ().toLocaleTimeString ();
159
198
this .ordersUpdatedAt = new Date ().toLocaleTimeString ();
160
199
},
161
- cancelAutoUpdate () {
162
- clearInterval (this .timer );
200
+ formatPrice (value ) {
201
+ if (parseFloat (value) < 1 ) {
202
+ return Intl .NumberFormat (' en-US' , {
203
+ useGrouping: false ,
204
+ minimumFractionDigits: 2 ,
205
+ maximumFractionDigits: 6
206
+ }).format (value);
207
+ }
208
+
209
+ return Intl .NumberFormat (' en-US' , {
210
+ useGrouping: false ,
211
+ minimumFractionDigits: 2 ,
212
+ maximumFractionDigits: 2
213
+ }).format (value);
214
+ },
215
+ round (value , decimalPlaces = 0 ) {
216
+ return value .toFixed (decimalPlaces);
217
+ },
218
+ date (value ) {
219
+ return new Date (value).toLocaleString ();
163
220
}
164
221
},
165
- beforeDestroy () {
166
- clearInterval (this .timer );
167
- },
222
+ mounted () {
223
+ this .fetchPageAsJson ();
224
+ this .timer = setInterval (this .fetchPageAsJson , 3000 );
225
+ }
168
226
}
227
+
169
228
</script >
170
229
171
- <style >
230
+ <style scoped >
172
231
.slide-fade-enter-active {
173
232
transition : all .3s ease ;
174
233
}
234
+
175
235
.slide-fade-leave-active {
176
236
transition : all .6s cubic-bezier (1.0 , 0.5 , 0.8 , 1.0 );
177
237
}
238
+
178
239
.slide-fade-enter , .slide-fade-leave-to {
179
240
opacity : 0.3 ;
180
241
}
181
242
</style >
243
+
0 commit comments