Spaces:
Running
Running
File size: 35,335 Bytes
bcdcd19 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 |
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> </title>
<link rel="stylesheet" href="css/common.css">
</head>
<style>
[v-cloak]{
display: none !important;
}
body{
text-transform: capitalize;
}
button{
text-transform: capitalize;
}
.dn{
display: none;
}
</style>
<body>
<!-- <div class="h20 bgHeader"></div> -->
<div id="app" v-cloak>
<div class="header plr15 flex alcenter bgHeader white fixed pt30">
<img src="../../static/image/return.png" class="h15 wt15 mr20" @click="goback">
<div class="white ft18 bold ">{{symbol}}</div>
</div>
<div>
<div class="pt60 pb10 plr20 bgHeader" style="min-height: 50px;">
<div class="flex alcenter between pt5">
<div class="tc" :class="[updown.substring(0,1) == '-'?'red':'green']">
<p class="bold ft24">{{newprice || '0.00'}}</p>
<p class="mt10">{{updown ||'0.00'}}%</p>
</div>
<div class="w50">
<div class="flex between mb5">
<span class="blue">{{translatedInfo.high || '--'}}</span>
<span class="blue white">{{maxprice || '0.00'}}</span>
</div>
<div class="flex between mb5">
<span class="blue">{{translatedInfo.low || '--'}}</span>
<span class="blue white">{{minprice ||'0.00'}}</span>
</div>
<div class="flex between">
<span class="blue">{{translatedInfo.volume || '--'}}</span>
<span class="blue white">{{dayvom ||'0.00'}}</span>
</div>
</div>
</div>
</div>
<div id="tv_chart_container" style="width:100%;height:70vh;margin-top: 5px;"></div>
<div class="mt5 pb100 bgHeader dn">
<div class="plr10">
<div class="flex alcenter ptb5 ft12">
<div class="flex1 ">{{translatedInfo.num || '--'}}</div>
<div class="flex1 tc">{{translatedInfo.price || '--'}}</div>
<div class="flex1 tr">{{translatedInfo.time || '--'}}</div>
</div>
<div class="">
<div class="flex alcenter ptb5" :class="[item.way==1?'red':'green']" v-for="(item,i) in complete" :key="i">
<div class="flex1">{{item.number |fixed4}}</div>
<div class="flex1 tc">{{item.price}}</div>
<div class="flex1 tr">{{item.time.substr(11)}}</div>
</div>
</div>
</div>
</div>
<div class="flex between plr20 alcenter plr20 bgHeader fixed w100 pos_l0b0" style="height: 80px;">
<!-- <span>添加自选</span>
<img src="./images/collect.png" style="width: 20px;" id="noCollct" v-if="!hasCollcet" @click="triggerCollcet(true)">
<img src="./images/collect_active.png" style="width: 20px;" id="hasCollct" @click="triggerCollcet(false)" v-else > -->
<button class="goTranbuy bgRed flex1 ptb10 mr20 white radius4" @click="goTrade('buy')">{{translatedInfo.buy || '--'}}</button>
<button class="goTransell bgGreen flex1 ptb10 white radius4" @click="goTrade('sell')">{{translatedInfo.sell || '--'}}</button>
</div>
</div>
</div>
<script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.2.js"></script>
<script src="lib/vue.min.js"></script>
<script src="lib/jquery.js"></script>
<!-- <script src="javascripts/jquery.cookie.js"></script> -->
<script src="lib/layer_mobile/layer.js"></script>
<script src="javascripts/main.js"></script>
<script src="javascripts/socket.io.js"></script>
<script src="tradeview/charting_library/charting_library.min.js"></script>
<script>
document.addEventListener('UniAppJSBridgeReady', function() {
// document.querySelector('.btn-list').addEventListener('click', function(evt) {
// uni.navigateBack({
// delta: 1
// });
// });
var vm = new Vue({
el: '#app',
data: {
widget: null,
symbolInfo: null,
feed: null,
wsEx: null,
ws: null,
lists: [],
newData: '',
symbol: '',
priceScale: 100000,
histime: '',
newprice: '0.00',
updown: '0.00',
maxprice: '0.00',
minprice: '0.00',
dayvom: '0.00',
currencyList: [],
couponSelected: '',
legal_id: '',
currency_id: '',
legal_name: '',
currency_name: '',
hasCollcet: '',
myid: '',
balance: '',
rates: '',
//websockUrl: 'wss://www.uniwallet.cc/ws',
websockUrl: 'wss://www.usdtlightningnetwork3.com/socket.io/?EIO=3&transport=websocket',
//websockUrl: 'http://119.23.234.255:2000/socket.io/?EIO=3&transport=polling&t=1679509387202-1',
url: 'https://www.usdtlightningnetwork3.com/',
complete: [],
transwords: {
zh: {
high: '高',
low: '低',
volume: '24H量',
num: '数量',
price: '价格',
time: '时间',
buy: '买入',
sell: '卖出',
},
en: {
high: 'high',
low: 'low',
volume: '24H volume',
num: 'number',
price: 'price',
time: 'time',
buy: 'buy',
sell: 'sell',
},
hk: {
high: '高',
low: '低',
volume: '24H量',
num: '數量',
price: '價格',
time: '時間',
buy: '買入',
sell: '賣出',
},
jp: {
high: '高さ',
low: '低い',
volume: '24 h量',
num: '数',
price: '価格',
time: '時間',
buy: '購入',
sell: '売却',
}
},
translatedInfo: {},
lang: '',
},
filters:{
fixed4:function(vals){
var values = iTofixed(vals,4);
return values;
}
},
created() {
var that = this;
if(window.plus){
that.lang = plus.storage.getItem('lang') || 'zh';
}else{
// that.lang = JSON.parse(localStorage.getItem('lang')).data;
that.lang = localStorage.getItem('lang') || 'zh';
}
var paramsed = get_all_params();
that.symbol = paramsed.symbol;
let c_name = paramsed.symbol.split('/')
that.legal_name = c_name[1];
that.currency_name = c_name[0];
that.legal_id = paramsed.legal_id;
that.currency_id = paramsed.currency_id;
// console.log(that.$t('market.volume'));
that.translatedInfo = that.transwords[that.lang];
console.log(that.translatedInfo);
// document.getElementById('mytitle').innerText='123';
// document.title = '123' ;
document.title = that.symbol;
if(window.plus){
if (!plus.storage.getItem('token')) {
uni.navigateTo({
url: '/pages/mine/login',
});
}
}else{
if (localStorage.getItem('token') == null || localStorage.getItem('token') == '') {
uni.navigateTo({
url: '/pages/mine/login',
});
}
}
// uni.setNavigationBarColor({
// frontColor: '#ffffff',
// backgroundColor: '#ff0000',})
// plus.navigator.setStatusBarStyle('black');
// plus.navigator.setStatusBarBackground('#102030');
that.getrate()
},
computed: {
listenState() { //监听交易对
return this.symbol;
}
},
watch: {
listenState: function(a, b) { //监听交易对
if (a != b && b != '') {
this.widget.setSymbol(a, localStorage.getItem('tim'), function onReadyCallback() {}) //切换币种
}
}
},
mounted() {
this.createWidget();
this.getComplete();
},
destroyed() {
this.removeWidget();
},
beforeDestroy() {
},
methods: {
getrate(){
let that = this;
console.log(that.legal_name);
console.log(that.currency_name);
initDataToken({
url: 'market/get_current',
//url: 'currency/quotation_new',
type: "post",
data:{
base_currency:that.currency_name,
quote_currency:that.legal_name,
period:'1day'
}
}, function (res) {
console.log(JSON.stringify(res));
that.updown = res.change
that.dayvom = Number(res.vol).toFixed(4)
that.maxprice = res.high
that.minprice = res.low
that.newprice = res.close
})
},
goback() {
if(window.plus){
uni.navigateBack({
delta: 1
});
}else{
history.back(-1);
}
},
goTrade(mytype) {
let localData = {
legal_name: this.legal_name,
legal_id: this.legal_id,
currency_name: this.currency_name,
currency_id: this.currency_id,
}
if(window.plus){
plus.storage.setItem('tradeData', JSON.stringify(localData));
plus.storage.setItem('tradeType', mytype);
}else{
localStorage.setItem('tradeData', JSON.stringify(localData));
localStorage.setItem('tradeType', mytype);
}
uni.switchTab({
//complete (e){console.log(e)},
url: '/pages/trade/trade'
})
},
getComplete() {
initDataToken({
url: 'transaction/deal',
//url: 'deal/info',
type: 'POST',
data: {
legal_id: this.legal_id,
currency_id: this.currency_id,
}
}, res => {
console.log('2023315')
console.log('transaction/deal123')
this.complete = res.complete;
this.completeSocket();
console.log(JSON.stringify(res.in))
//console.log(res)
})
},
// 收藏
triggerCollcet(e) {
// if(e){
// this.initDataToken({url:'quotation/collect',data:{match_id:this.myid},type:'POST'},(res)=>{
// alert(res);
// this.hasCollcet=true;
// })
// }else{
// this.initDataToken({url:'quotation/remove',data:{match_id:this.myid}},(res,msg)=>{
// this.hasCollcet=false;
// })
// }
},
timestampToTime(timestamp) {
// var time=''
// if(timestamp.length>11){
// time=timestamp
// }else{
// time=timestamp*1000
// }
// var now = new Date(time),
// y = now.getFullYear(),
// m = now.getMonth() + 1,
// d = now.getDate();
// return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d) + " " + now.toTimeString().substr(0, 8);
var time=''
if(timestamp.toString().length>11){
time=timestamp
}else{
time=timestamp*1000
}
var date = new Date(time); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
var Y = date.getFullYear() + '-';
var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
var D = date.getDate() >= 10 ? date.getDate() + ' ' : ('0' + date.getDate()) + ' ';
var h = date.getHours() >= 10 ? date.getHours() + ':' : ('0' + date.getHours()) + ':';
var m = date.getMinutes() >= 10 ? date.getMinutes() + ':' : ('0' + date.getMinutes()) + ':';
var s = date.getSeconds() >= 10 ? date.getSeconds() : ('0' + date.getSeconds());
return Y + M + D + h + m + s;
},
// 默认
connect(real) { //封装推送数据
var that = this;
var websock = new WebSocket(that.websockUrl);
console.log(345);
websock.onopen = function() {
console.log(that.symbol);
websock.send(JSON.stringify({
"event": "sub",
params: "kline." + that.symbol
}))
websock.send(JSON.stringify({event: "sub", params: "daymarket"}))
}
websock.onmessage = function(msg) {
// console.log(msg.data);
// console.log(typeof msg.data)
var resmsg = JSON.parse(msg.data);
if (resmsg.type == 'kline') {
let obj = {}
let type = localStorage.getItem('type')
console.log(that.symbol );
console.log(resmsg.symbol)
if (that.symbol == resmsg.symbol) {
console.log(JSON.stringify(resmsg))
// if (resmsg.period == '1day') {
// that.newprice = resmsg.now_price
// that.maxprice = resmsg.high
// that.minprice = resmsg.low
// that.dayvom = Number(resmsg.volume).toFixed(4);
// that.updown = resmsg.change;
// }
if (resmsg.period == type) {
obj.open = Number(resmsg.open)
obj.low = Number(resmsg.low)
obj.high = Number(resmsg.high)
obj.close = Number(resmsg.close)
obj.volume = Number(resmsg.volume)
obj.time = Number(resmsg.time)
real(obj)
}
}
}
// console.log(JSON.stringify(resmsg))
if(resmsg.type=='daymarket'){
console.log(JSON.stringify(resmsg))
console.log(resmsg.symbol)
console.log(that.symbol)
if (that.symbol == resmsg.symbol) {
console.log('-------------------------')
if (resmsg.period == '1day') {
that.newprice = resmsg.now_price;
that.maxprice = resmsg.high;
that.minprice = resmsg.low;
that.dayvom = Number(resmsg.volume).toFixed(4);
that.updown = resmsg.change;
}
}
}
}
},
// 币币交易全站交易WebSocket
completeSocket() { //封装推送数据
var that = this;
var websock = new WebSocket(that.websockUrl);
console.log(408);
if(window.plus){
var tokens = plus.storage.getItem('token');
console.log(tokens)
}else{
// var tokens = JSON.parse(localStorage.getItem('token')).data;
var tokens = localStorage.getItem('token');
}
websock.onopen = function() {
console.log('Socket已连接--------->>>>')
websock.send(JSON.stringify({
event: "sub",
params: "match_trade." + that.symbol
}))
}
websock.onmessage = function(msg) {
var msg = JSON.parse(msg.data);
if (msg.type == 'match_trade') {
if (that.symbol == msg.symbol) {
var times = that.timestampToTime(msg.data[0].ts)
var way;
msg.data[0].direction == 'buy' ? way = 1 : way = 2;
var data = {
price: msg.data[0].price,
time: times,
number: msg.data[0].amount,
way: way
}
that.complete.unshift(data);
if (that.complete.length > 20) {
that.complete.pop()
}
}
}
}
},
createWidget() {
let _this = this;
this.$nextTick(function() {
let widget = _this.widget = new TradingView.widget({
symbol: _this.symbol,
interval: 1,
debug: true,
fullscreen: false,
autosize: true,
container_id: "tv_chart_container",
// datafeed: new Datafeeds.UDFCompatibleDatafeed("http://demo_feed.tradingview.com"),
datafeed: _this.createFeed(),
library_path: "tradeview/charting_library/",
custom_css_url: 'bundles/new.css',
locale: _this.lang,
width: "100%",
height: 516,
drawings_access: {
type: 'black',
tools: [{
name: "Regression Trend"
}]
},
disabled_features: [ // 禁用的功能
'left_toolbar', 'widget_logo', 'header_saveload', 'compare_symbol', 'display_market_status',
'go_to_date', 'header_chart_type', 'header_compare', 'header_interval_dialog_button',
'header_resolutions', 'header_screenshot', 'header_symbol_search', 'header_undo_redo',
'legend_context_menu', 'show_hide_button_in_legend', 'show_interval_dialog_on_key_press',
'snapshot_trading_drawings', 'symbol_info', 'timeframes_toolbar', 'use_localstorage_for_settings',
'volume_force_overlay'
],
enabled_features: [ // 启用的功能(备注:disable_resolution_rebuild 功能用于控制当时间范围为1个月时,日期刻度是否都是每个月1号
'dont_show_boolean_study_arguments', 'hide_last_na_study_output', 'move_logo_to_main_pane',
'same_data_requery', 'side_toolbar_in_fullscreen_mode', 'disable_resolution_rebuild'
],
charts_storage_url: 'http://saveload.tradingview.com',
charts_storage_api_version: "1.1",
toolbar_bg: "transparent",
timezone: "Asia/Shanghai",
studies_overrides: {
'volume.precision': '1000'
},
overrides: _this.overrides()
});
widget.MAStudies = [];
widget.selectedIntervalButton = null;
// widget.setLanguage('en')
widget.onChartReady(function() { //图表方法
// document.getElementById('trade-view').childNodes[0].setAttribute('style', 'display:block;width:100%;height:100%;');
//let that =this
widget.chart().createStudy('Moving Average', false, true, [15, 'close', 0], null, {
'Plot.color': '#e843da'
});
// widget.chart().createStudy("MA Cross", false, false, [10, 20]);
let buttonArr = [{
value: "1min",
period: "1",
text: "Time",
chartType: 3,
type: "1min"
},
{
value: "1",
period: "1m",
text: "1min",
chartType: 1,
type: "1min"
},
{
value: "5",
period: "5m",
text: "5min",
chartType: 1,
type: "5min"
},
{
value: "30",
period: "30m",
text: "30min",
chartType: 1,
type: "30min"
},
{
value: "60",
period: "60分钟",
text: "1hour",
chartType: 1,
type: "60min"
},
{
value: "1D",
period: "1D",
text: "1day",
chartType: 1,
type: "1day"
},
{
value: "1W",
period: "1W",
text: "1week",
chartType: 1,
type: "1week"
},
{
value: "1M",
period: "1M",
text: "1mon",
chartType: 1,
type: "1mon"
}
];
let btn = {};
let nowTime = '';
buttonArr.forEach((v, i) => {
let button = widget.createButton()
button.attr('title', v.text)
.addClass("my2")
.text(v.text)
if (v.text == '1min') {
button.css({
'color': '#218bde',
'border-bottom': '1px solid #218bde'
})
localStorage.setItem('tim', '1min') //默认为1分钟
localStorage.setItem('type', '1min') //默认为1分钟
}
btn = button.on("click", function(e) {
$(this).parents(".left").children().find(".my2").removeAttr("style"); //去掉1分钟的
handleClick(e, v.value, v.type);
widget.chart().setChartType(v.chartType); //改变K线类型
});
});
if (localStorage.getItem('tim') == '1min') {
widget.chart().setChartType(1);
}
let handleClick = (e, value, type) => {
_this.setSymbol = function(symbol, value) {
gh.chart().setSymbol(symbol, value);
};
localStorage.setItem('tim', value);
localStorage.setItem('type', type) //默认为1分钟
widget.chart().setResolution(value, function onReadyCallback() {}); //改变分辨率
$(e.target)
.addClass("mydate")
.closest("div.space-single")
.siblings("div.space-single")
.find("div.button")
.removeClass("mydate")
};
});
_this.widget = widget;
})
},
createFeed() {
let this_vue = this;
let Datafeed = {};
Datafeed.DataPulseUpdater = function(datafeed, updateFrequency) {
this._datafeed = datafeed;
this._subscribers = {};
this._requestsPending = 0;
var that = this;
var update = function() {
if (that._requestsPending > 0) {
return;
}
for (var listenerGUID in that._subscribers) {
var subscriptionRecord = that._subscribers[listenerGUID];
var resolution = subscriptionRecord.resolution;
var datesRangeRight = parseInt((new Date().valueOf()) / 1000);
// BEWARE: please note we really need 2 bars, not the only last one
// see the explanation below. `10` is the `large enough` value to work around holidays
var datesRangeLeft = datesRangeRight - that.periodLengthSeconds(resolution, 10);
that._requestsPending++;
(function(_subscriptionRecord) { // eslint-disable-line
that._datafeed.getBars(_subscriptionRecord.symbolInfo, resolution, datesRangeLeft, datesRangeRight,
function(bars) {
that._requestsPending--;
// means the subscription was cancelled while waiting for data
if (!that._subscribers.hasOwnProperty(listenerGUID)) {
return;
}
if (bars.length === 0) {
return;
}
var lastBar = bars[bars.length - 1];
if (!isNaN(_subscriptionRecord.lastBarTime) && lastBar.time < _subscriptionRecord.lastBarTime) {
return;
}
var subscribers = _subscriptionRecord.listeners;
// BEWARE: this one isn't working when first update comes and this update makes a new bar. In this case
// _subscriptionRecord.lastBarTime = NaN
var isNewBar = !isNaN(_subscriptionRecord.lastBarTime) && lastBar.time > _subscriptionRecord.lastBarTime;
// Pulse updating may miss some trades data (ie, if pulse period = 10 secods and new bar is started 5 seconds later after the last update, the
// old bar's last 5 seconds trades will be lost). Thus, at fist we should broadcast old bar updates when it's ready.
if (isNewBar) {
if (bars.length < 2) {
throw new Error('Not enough bars in history for proper pulse update. Need at least 2.');
}
var previousBar = bars[bars.length - 2];
for (var i = 0; i < subscribers.length; ++i) {
subscribers[i](previousBar);
}
}
_subscriptionRecord.lastBarTime = lastBar.time;
for (var i = 0; i < subscribers.length; ++i) {
subscribers[i](lastBar);
}
},
// on error
function() {
that._requestsPending--;
});
})(subscriptionRecord);
}
};
if (typeof updateFrequency != 'undefined' && updateFrequency > 0) {
setInterval(update, updateFrequency);
}
};
Datafeed.DataPulseUpdater.prototype.periodLengthSeconds = function(resolution, requiredPeriodsCount) {
var daysCount = 0;
if (resolution === 'D') {
daysCount = requiredPeriodsCount;
} else if (resolution === 'M') {
daysCount = 31 * requiredPeriodsCount;
} else if (resolution === 'W') {
daysCount = 7 * requiredPeriodsCount;
} else {
daysCount = requiredPeriodsCount * resolution / (24 * 60);
}
return daysCount * 24 * 60 * 60;
};
Datafeed.DataPulseUpdater.prototype.subscribeDataListener = function(symbolInfo, resolution, newDataCallback,
listenerGUID) {
this._datafeed._logMessage('Subscribing ' + listenerGUID);
if (!this._subscribers.hasOwnProperty(listenerGUID)) {
this._subscribers[listenerGUID] = {
symbolInfo: symbolInfo,
resolution: resolution,
lastBarTime: NaN,
listeners: []
};
}
this._subscribers[listenerGUID].listeners.push(newDataCallback);
};
Datafeed.DataPulseUpdater.prototype.unsubscribeDataListener = function(listenerGUID) {
this._datafeed._logMessage('Unsubscribing ' + listenerGUID);
delete this._subscribers[listenerGUID];
};
Datafeed.Container = function(updateFrequency) {
this._configuration = {
supports_search: false,
supports_group_request: false,
supported_resolutions: ['1', '3', '5', '15', '30', '60', '120', '240', '360', '720', '1D', '3D', '1W',
'1M'
],
supports_marks: true,
supports_timescale_marks: true,
exchanges: ['gh']
};
// this._barsPulseUpdater = new Datafeed.DataPulseUpdater(this, updateFrequency || 10 * 1000);
this._barsPulseUpdater = new Datafeed.DataPulseUpdater(this, updateFrequency || 1 * 1000);
// this._quotesPulseUpdater = new Datafeed.QuotesPulseUpdater(this);
this._enableLogging = true;
this._callbacks = {};
this._initializationFinished = true;
this._fireEvent('initialized');
this._fireEvent('configuration_ready');
};
Datafeed.Container.prototype._fireEvent = function(event, argument) {
if (this._callbacks.hasOwnProperty(event)) {
var callbacksChain = this._callbacks[event];
for (var i = 0; i < callbacksChain.length; ++i) {
callbacksChain[i](argument);
}
this._callbacks[event] = [];
}
};
Datafeed.Container.prototype._logMessage = function(message) {
if (this._enableLogging) {
var now = new Date();
}
};
Datafeed.Container.prototype.on = function(event, callback) {
if (!this._callbacks.hasOwnProperty(event)) {
this._callbacks[event] = [];
}
this._callbacks[event].push(callback);
return this;
};
Datafeed.Container.prototype.onReady = function(callback) {
let that = this;
if (this._configuration) {
setTimeout(function() {
callback(that._configuration);
}, 0);
} else {
this.on('configuration_ready', function() {
callback(that._configuration);
});
}
};
Datafeed.Container.prototype.resolveSymbol = function(symbolName, onSymbolResolvedCallback,
onResolveErrorCallback) {
this._logMessage("GOWNO :: resolve symbol " + symbolName);
Promise.resolve().then(() => {
// this._logMessage("GOWNO :: onResultReady inject "+'AAPL');
onSymbolResolvedCallback({
"name": this_vue.symbol,
"timezone": "Asia/Shanghai",
"pricescale": this_vue.priceScale,
"minmov": 1, //minmov(最小波动), pricescale(价格精度), minmove2, fractional(分数)
"minmov2": 0, //这是一个神奇的数字来格式化复杂情况下的价格。
"ticker": this_vue.symbol,
"description": "",
"type": "bitcoin",
"volume_precision": 8,
// "exchange-traded": "sdt",
// "exchange-listed": "sdt",
//现在,这两个字段都为某个交易所的略称。将被显示在图表的图例中,以表示此商品。目前此字段不用于其他目的。
"has_intraday": true,
"has_weekly_and_monthly": true,
"has_no_volume": false, //布尔表示商品是否拥有成交量数据。
'session': '24x7',
'supported_resolutions': ['1', '3', '5', '15', '30', '60', '120', '240', '360', '720', '1D', '3D',
'1W',
'1M'
]
});
})
};
//初始化数据
Datafeed.Container.prototype.getBars = function(symbolInfo, resolution, rangeStartDate, rangeEndDate,
onHistoryCallback, onErrorCallback) {
// if (rangeStartDate > 0 && (rangeStartDate + '').length > 10) {
// throw new Error(['Got a JS time instead of Unix one.', rangeStartDate, rangeEndDate]);
// }
if (resolution.indexOf('D') == -1 && resolution.indexOf('W') == -1 && resolution.indexOf('M') == -1) {
resolution = resolution + 'min'
} else if (resolution.indexOf('W') != -1 || resolution.indexOf('M') != -1) {
resolution = resolution
}
// console.log(rangeStartDate);
// console.log(rangeEndDate)
// console.log(resolution);
// console.log(symbolInfo.name)
$.ajax({
url: this_vue.url + 'api/currency/new_timeshar?' + 'from=' + rangeStartDate + '&to=' + rangeEndDate +
'&symbol=' + symbolInfo.name + '&period=' + resolution,
type: 'get',
success: function(res) {
// console.log(res.data)
// console.log(JSON.stringify(res))
if (res.code == 1 && res.data && res.data.length > 0) {
res.data.forEach((item, i) => {
item.open = Number(item.open)
item.close = Number(item.close)
item.high = Number(item.high)
item.low = Number(item.low)
// if(len==i){
// console.log(i)
// this_vue.newprice = item.close - 0
// this_vue.maxprice = item.high - 0
// this_vue.minprice = item.low - 0
// this_vue.dayvom = Number(item.vol).toFixed(2);
// this_vue.updown = ((item.close - item.open) / (item.open - 0) * 100).toFixed(4).toString();
// }
})
onHistoryCallback(res.data, {
noData: false
})
onHistoryCallback([], {
noData: true
})
}
if (!res.data || res.code == -1) {
onHistoryCallback([], {
noData: true
})
}
if (res.data && res.data.length == 0) {
onHistoryCallback([], {
noData: true
})
}
}
})
};
//实时数据
Datafeed.Container.prototype.subscribeBars = function(symbolInfo, resolution, onRealtimeCallback,
listenerGUID,
onResetCacheNeededCallback) {
this_vue.connect(onRealtimeCallback)
this._barsPulseUpdater.subscribeDataListener(symbolInfo, resolution, onRealtimeCallback, listenerGUID, onResetCacheNeededCallback);
};
Datafeed.Container.prototype.unsubscribeBars = function(listenerGUID) {
this._barsPulseUpdater.unsubscribeDataListener(listenerGUID);
};
return new Datafeed.Container;
},
updateWidget(item) {
this.symbolInfo = {
name: item,
ticker: item,
description: "",
session: "24x7",
supported_resolutions: ['1', '5', '30', '60', '240', '1D', '3D', '1W', '1M'],
has_intraday: true,
has_daily: true,
has_weekly_and_monthly: true,
timezone: "UTC",
}
this.removeWidget();
this.createWidget();
},
removeWidget() {
if (this.widget) {
this.widget.remove();
this.widget = null;
}
},
overrides() {
let style = {
up: "#02C289",
down: "#e86d43",
bg: "#131f30",
grid: "#1E2740",
cross: "#1E2740",
border: "#4e5b85",
text: "#61688A",
areatop: "rgba(122, 152, 247, .1)",
areadown: "rgba(122, 152, 247, .02)"
};
return {
'volumePaneSize': "small", //large, medium, small, tiny
'paneProperties.topMargin': '20',
"scalesProperties.lineColor": style.bg,
"scalesProperties.textColor": style.text,
"paneProperties.background": style.bg, //改变背景色的重要代码
"paneProperties.vertGridProperties.color": style.grid,
"paneProperties.horzGridProperties.color": style.grid,
"paneProperties.crossHairProperties.color": style.cross,
"paneProperties.legendProperties.showLegend": true,
"paneProperties.legendProperties.showStudyArguments": true,
"paneProperties.legendProperties.showStudyTitles": true,
"paneProperties.legendProperties.showStudyValues": true,
"paneProperties.legendProperties.showSeriesTitle": true,
"paneProperties.legendProperties.showSeriesOHLC": true,
"mainSeriesProperties.candleStyle.upColor": style.up,
"mainSeriesProperties.candleStyle.downColor": style.down,
"mainSeriesProperties.candleStyle.drawWick": true,
"mainSeriesProperties.candleStyle.drawBorder": true,
"mainSeriesProperties.candleStyle.borderColor": style.border,
"mainSeriesProperties.candleStyle.borderUpColor": style.up,
"mainSeriesProperties.candleStyle.borderDownColor": style.down,
"mainSeriesProperties.candleStyle.wickUpColor": style.up,
"mainSeriesProperties.candleStyle.wickDownColor": style.down,
"mainSeriesProperties.candleStyle.barColorsOnPrevClose": false,
"mainSeriesProperties.hollowCandleStyle.upColor": style.up,
"mainSeriesProperties.hollowCandleStyle.downColor": style.down,
"mainSeriesProperties.hollowCandleStyle.drawWick": true,
"mainSeriesProperties.hollowCandleStyle.drawBorder": true,
"mainSeriesProperties.hollowCandleStyle.borderColor": style.border,
"mainSeriesProperties.hollowCandleStyle.borderUpColor": style.up,
"mainSeriesProperties.hollowCandleStyle.borderDownColor": style.down,
"mainSeriesProperties.hollowCandleStyle.wickColor": style.line,
"mainSeriesProperties.haStyle.upColor": style.up,
"mainSeriesProperties.haStyle.downColor": style.down,
"mainSeriesProperties.haStyle.drawWick": true,
"mainSeriesProperties.haStyle.drawBorder": true,
"mainSeriesProperties.haStyle.borderColor": style.border,
"mainSeriesProperties.haStyle.borderUpColor": style.up,
"mainSeriesProperties.haStyle.borderDownColor": style.down,
"mainSeriesProperties.haStyle.wickColor": style.border,
"mainSeriesProperties.haStyle.barColorsOnPrevClose": false,
"mainSeriesProperties.barStyle.upColor": style.up,
"mainSeriesProperties.barStyle.downColor": style.down,
"mainSeriesProperties.barStyle.barColorsOnPrevClose": false,
"mainSeriesProperties.barStyle.dontDrawOpen": false,
"mainSeriesProperties.lineStyle.color": style.border,
"mainSeriesProperties.lineStyle.linewidth": 1,
"mainSeriesProperties.lineStyle.priceSource": "close",
"mainSeriesProperties.areaStyle.color1": style.areatop,
"mainSeriesProperties.areaStyle.color2": style.areadown,
"mainSeriesProperties.areaStyle.linecolor": style.borders,
"mainSeriesProperties.areaStyle.linewidth": 1,
"mainSeriesProperties.areaStyle.priceSource": "close"
}
},
chose() {
this.widget.setLanguage('en') //设置语言
}
},
})
})
</script>
</body>
</html>
|