Skip to content

Commit aa96ccf

Browse files
authored
Merge pull request #181 from Polygant/release/1.3.8
Release/1.3.8
2 parents faa54e3 + e3167b4 commit aa96ccf

File tree

9 files changed

+158
-118
lines changed

9 files changed

+158
-118
lines changed

src/api/TradingView/index.js

Lines changed: 78 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -15,85 +15,88 @@ const supportedResolutions = [
1515
const config = {
1616
supported_resolutions: supportedResolutions,
1717
};
18-
export default {
19-
onReady: (cb) => {
20-
setTimeout(() => cb(config), 0);
21-
},
22-
resolveSymbol: (symbolName, onSymbolResolvedCallback) => {
23-
var splitData = symbolName.split(/[:/]/);
24-
var projectTitle = localStorage.getItem("project_title");
25-
if (!projectTitle) {
26-
projectTitle = "Crypto exchange";
27-
}
28-
var symbolStub = {
29-
name: symbolName,
30-
description: "",
31-
type: "crypto",
32-
session: "24x7",
33-
timezone: "Etc/UTC",
34-
has_empty_bars: true,
35-
ticker: symbolName,
36-
exchange: projectTitle,
37-
minmov: 1,
38-
pricescale: 100000,
39-
has_intraday: true,
40-
intraday_multipliers: ["1", "60"],
41-
supported_resolution: supportedResolutions,
42-
volume_precision: 8,
43-
data_status: "streaming",
44-
};
45-
if (splitData[1].match(/USD|EUR|RUB|JPY|AUD|GBP|KRW|CNY/)) {
46-
symbolStub.pricescale = 100;
47-
}
48-
setTimeout(function () {
49-
onSymbolResolvedCallback(symbolStub);
50-
}, 0);
51-
},
52-
getBars: function (symbolInfo, resolution, periodParams, onHistoryCallback) {
53-
historyProvider
54-
.getBars(symbolInfo, resolution, periodParams.from, periodParams.to)
55-
.then(async (data) => {
56-
let ohlc = [];
57-
let dataLength = data.data["records"].length;
58-
let i = 0;
59-
for (i; i < dataLength; i += 1) {
60-
if (data.data["records"][i][1] > 0) {
61-
ohlc.push({
62-
time: data.data["records"][i][0], // the date
63-
open: data.data["records"][i][4], // open
64-
high: data.data["records"][i][1], // high
65-
low: data.data["records"][i][2], // low
66-
close: data.data["records"][i][5], // close
67-
volume: data.data["records"][i][3], // volume
68-
});
18+
export default (precision = null) => {
19+
return {
20+
onReady: (cb) => {
21+
setTimeout(() => cb(config), 0);
22+
},
23+
resolveSymbol: (symbolName, onSymbolResolvedCallback) => {
24+
var projectTitle = localStorage.getItem("project_title");
25+
if (!projectTitle) {
26+
projectTitle = "Crypto exchange";
27+
}
28+
var symbolStub = {
29+
name: symbolName,
30+
description: "",
31+
type: "crypto",
32+
session: "24x7",
33+
timezone: "Etc/UTC",
34+
has_empty_bars: true,
35+
ticker: symbolName,
36+
exchange: projectTitle,
37+
minmov: 1,
38+
pricescale: Math.round(1 / (precision || 0.01)),
39+
has_intraday: true,
40+
intraday_multipliers: ["1", "60"],
41+
supported_resolution: supportedResolutions,
42+
volume_precision: 8,
43+
data_status: "streaming",
44+
};
45+
setTimeout(function () {
46+
onSymbolResolvedCallback(symbolStub);
47+
}, 0);
48+
},
49+
getBars: function (
50+
symbolInfo,
51+
resolution,
52+
periodParams,
53+
onHistoryCallback
54+
) {
55+
historyProvider
56+
.getBars(symbolInfo, resolution, periodParams.from, periodParams.to)
57+
.then(async (data) => {
58+
let ohlc = [];
59+
let dataLength = data.data["records"].length;
60+
let i = 0;
61+
for (i; i < dataLength; i += 1) {
62+
if (data.data["records"][i][1] > 0) {
63+
ohlc.push({
64+
time: data.data["records"][i][0], // the date
65+
open: data.data["records"][i][4], // open
66+
high: data.data["records"][i][1], // high
67+
low: data.data["records"][i][2], // low
68+
close: data.data["records"][i][5], // close
69+
volume: data.data["records"][i][3], // volume
70+
});
71+
}
72+
}
73+
historyProvider.history[symbolInfo.name] = {
74+
lastBar: ohlc[ohlc.length - 1],
75+
};
76+
if (ohlc.length) {
77+
onHistoryCallback(ohlc, { noData: false });
78+
} else {
79+
onHistoryCallback(ohlc, { noData: true });
6980
}
70-
}
71-
historyProvider.history[symbolInfo.name] = {
72-
lastBar: ohlc[ohlc.length - 1],
73-
};
74-
if (ohlc.length) {
75-
onHistoryCallback(ohlc, { noData: false });
76-
} else {
77-
onHistoryCallback(ohlc, { noData: true });
78-
}
79-
});
80-
},
81-
subscribeBars: (
82-
symbolInfo,
83-
resolution,
84-
onRealtimeCallback,
85-
subscribeUID,
86-
onResetCacheNeededCallback
87-
) => {
88-
stream.subscribeBars(
81+
});
82+
},
83+
subscribeBars: (
8984
symbolInfo,
9085
resolution,
9186
onRealtimeCallback,
9287
subscribeUID,
9388
onResetCacheNeededCallback
94-
);
95-
},
96-
unsubscribeBars: () => {
97-
stream.unsubscribeBars();
98-
},
89+
) => {
90+
stream.subscribeBars(
91+
symbolInfo,
92+
resolution,
93+
onRealtimeCallback,
94+
subscribeUID,
95+
onResetCacheNeededCallback
96+
);
97+
},
98+
unsubscribeBars: () => {
99+
stream.unsubscribeBars();
100+
},
101+
};
99102
};

src/components/layout/Base.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ input[type="password"],
248248
.address-text-field,
249249
.currency-list .currency-table .table tbody tr.active,
250250
.wallet-list .currency-table .table tbody tr.active,
251+
.nav-tabs .nav-link:not(.active),
251252
.alert-container,
252253
.footer {
253254
background-color: v-bind(mainBackgroundLocal) !important;

src/mixins/getFixedDecimal.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ function addSpace(number) {
4848
*/
4949

5050
function getFixedDecimal(val, precision = 8, toClosest = false) {
51+
console.log(val, precision);
52+
if (val === Infinity) debugger;
5153
return val
5254
? new Decimal(
5355
new Decimal(val).toFixed(

src/modules/trade/components/LimitsList.vue

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,9 @@
7575
/>
7676
<div class="limit-list__row mt-3 limit-list__caption">
7777
<span>{{ $t("common.fee") }}:</span>
78-
<span
79-
>{{ noExponents(fee) }}
80-
{{ operation == "buy" ? baseCurrency : quoteCurrency }}</span
81-
>
78+
<span>
79+
{{ fee }} {{ operation == "buy" ? baseCurrency : quoteCurrency }}
80+
</span>
8281
</div>
8382
<button
8483
class="limit-list__submit-button mt-4"
@@ -258,14 +257,14 @@ export default {
258257
case "buy":
259258
this.lastEditedField = FIELDS.SUM;
260259
this.resultedQuoteSum =
261-
this.addSpaceFixDecimal(
260+
this.getFixedDecimal(
262261
this.getCoolBalance(this.quoteCurrency) * fraction,
263262
this.coins[this.quoteCurrency].decimals
264263
) + "";
265264
break;
266265
case "sell":
267266
this.operationData.quantity =
268-
this.addSpaceFixDecimal(
267+
this.getFixedDecimal(
269268
this.getCoolBalance(this.baseCurrency) * fraction,
270269
this.coins[this.baseCurrency].decimals
271270
) + "";
@@ -276,28 +275,30 @@ export default {
276275
updateResultedSum: debounce(function () {
277276
if (this.lastEditedField === FIELDS.QUANTITY)
278277
this.resultedQuoteSum = String(
279-
this.addSpaceFixDecimal(
278+
this.getFixedDecimal(
280279
this.operationData.price * this.operationData.quantity,
281280
this.coins[this.quoteCurrency].decimals
282281
)
283282
);
283+
284+
console.log({ updateResultedSum: this.resultedQuoteSum });
284285
}, 500),
285286
286287
updateOperationQuantity: debounce(function () {
287-
console.log("updateOperationQuantity");
288-
if (this.lastEditedField === FIELDS.SUM)
288+
if (this.lastEditedField === FIELDS.SUM) {
289289
if (
290290
!Number.isNaN(Number(this.operationData.price)) &&
291291
Number(this.operationData.price) !== 0 &&
292292
!Number.isNaN(this.resultedQuoteSum)
293293
)
294294
this.operationData.quantity = String(
295-
this.addSpaceFixDecimal(
295+
this.getFixedDecimal(
296296
this.resultedQuoteSum / this.operationData.price || 0,
297297
this.coins[this.baseCurrency].decimals
298298
)
299299
);
300300
else this.operationData.quantity = "0";
301+
}
301302
}, 500),
302303
303304
getMax8Digits(x) {

src/modules/trade/components/TradeGraphic.vue

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,22 @@
44

55
<script>
66
import { mapGetters } from "vuex";
7-
import Datafeed from "~/api/TradingView";
7+
import getDatafeed from "~/api/TradingView";
88
import { widget } from "~/assets/TradingView/charting_library/charting_library.esm.js";
99
import localConfig from "~/local_config";
1010
1111
export default {
12+
// eslint-disable-next-line vue/require-prop-types
13+
props: {
14+
precision: {
15+
type: Number,
16+
required: true,
17+
},
18+
},
1219
data() {
1320
return {
1421
tvWidget: null,
22+
datafeed: null,
1523
};
1624
},
1725
computed: {
@@ -32,11 +40,24 @@ export default {
3240
watch: {
3341
lang() {
3442
try {
43+
this.setGraphColor();
3544
this.makeChart();
3645
} catch (e) {
3746
console.log(e);
3847
}
3948
},
49+
precision: {
50+
immediate: true,
51+
handler(value) {
52+
if (!value) return;
53+
try {
54+
this.setGraphColor();
55+
this.makeChart();
56+
} catch (e) {
57+
console.log(e);
58+
}
59+
},
60+
},
4061
currentTheme() {
4162
this.setGraphColor();
4263
this.makeChart();
@@ -58,7 +79,7 @@ export default {
5879
},
5980
6081
beforeUnmount() {
61-
Datafeed.unsubscribeBars();
82+
if (this.datafeed) this.datafeed.unsubscribeBars();
6283
},
6384
6485
methods: {
@@ -73,6 +94,10 @@ export default {
7394
}, 1000);
7495
},
7596
makeChart() {
97+
if (this.datafeed) {
98+
this.datafeed.unsubscribeBars();
99+
}
100+
this.datafeed = getDatafeed(this.precision);
76101
const intervalFromLocalStorage =
77102
localStorage.getItem("chart_interval") || "5",
78103
tvWidget = new widget({
@@ -81,7 +106,7 @@ export default {
81106
timezone: "Etc/UTC",
82107
container: this.$refs.graphic,
83108
locale: this.lang,
84-
datafeed: Datafeed,
109+
datafeed: this.datafeed,
85110
library_path: "/public/TV/charting_library/",
86111
autosize: true,
87112
toolbar_bg: "#f6f6f8",

src/modules/trade/components/orders/Orders-sell-buy.vue

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ export default {
7676
name: "OrdersSellBuy",
7777
mixins: [getCoolTrade, getFixedDecimal],
7878
79+
// eslint-disable-next-line vue/require-prop-types
80+
props: ["precision"],
81+
7982
data() {
8083
return {
8184
currentPriceStakan: 0,
@@ -104,24 +107,19 @@ export default {
104107
getPriceForStakan() {
105108
const price = this.currentPriceStakan;
106109
107-
if (this.isFiat(this.currentQuoteCurrency)) {
108-
if (price >= 100000) {
109-
return this.addSpaceFixDecimal(price, 0);
110-
} else {
111-
return this.addSpaceFixDecimal(price, 2);
112-
}
110+
if (price >= 10000) {
111+
return this.addSpaceFixDecimal(price, 0);
112+
} else if (price >= 1000) {
113+
return this.addSpaceFixDecimal(price, 1);
114+
} else if (price >= 100) {
115+
return this.addSpaceFixDecimal(price, 2);
116+
} else if (price >= 10) {
117+
return this.addSpaceFixDecimal(price, 3);
113118
} else {
114-
if (price >= 10000) {
115-
return this.addSpaceFixDecimal(price, 0);
116-
} else if (price >= 1000) {
117-
return this.addSpaceFixDecimal(price, 1);
118-
} else if (price >= 100) {
119-
return this.addSpaceFixDecimal(price, 2);
120-
} else if (price >= 10) {
121-
return this.addSpaceFixDecimal(price, 3);
122-
} else {
123-
return this.addSpaceFixDecimal(price, 4);
124-
}
119+
return this.addSpaceFixDecimal(
120+
price,
121+
-Math.round(Math.log(this.precision || 0.01) / Math.log(10))
122+
);
125123
}
126124
},
127125
},

0 commit comments

Comments
 (0)