 |
|
รบกวนสอบเรื่อง socket.io ถ้าจะอัพขึ้นบนเซอร์เวอร์ต้องเปลี่ยนตรงไหนคะ io.connect ต้องเปลี่ยนเป็นอะไรคะ
ไฟล์ kline.js
Code (JavaScript)
const log = console.log;
const api = require('binance');
const express = require('express');
const app = express();
const server = app.listen('4000',() => log(`Kline Data Server started on port 4000`));
const socket = require('socket.io');
const io = socket(server);
const bRest = new api.BinanceRest({
key: "", // Get this from your account on binance.com
secret: "", // Same for this
timeout: 15000, // Optional, defaults to 15000, is the request time out in milliseconds
recvWindow: 20000, // Optional, defaults to 5000, increase if you're getting timestamp errors
disableBeautification: false,
handleDrift: true
});
const binanceWS = new api.BinanceWS(true);
const bws = binanceWS.onKline('BTCUSDT', '1m', (data) => {
io.sockets.emit('KLINE',{time:Math.round(data.kline.startTime/1000),open:parseFloat(data.kline.open),high:parseFloat(data.kline.high),low:parseFloat(data.kline.low),close:parseFloat(data.kline.close)});
});
ไฟล์ index.js
Code (JavaScript)
const log = console.log;
const chartProperties = {
width:1500,
height:600,
timeScale:{
timeVisible:true,
secondsVisible:false,
}
}
const domElement = document.getElementById('tvchart');
const chart = LightweightCharts.createChart(domElement,chartProperties);
const candleSeries = chart.addCandlestickSeries();
fetch(`https://xxx.com`)
.then(res => res.json())
.then(data => {
const cdata = data.map(d => {
return {time:d[0]/1000,open:parseFloat(d[1]),high:parseFloat(d[2]),low:parseFloat(d[3]),close:parseFloat(d[4])}
});
candleSeries.setData(cdata);
})
.catch(err => log(err))
const socket = io.connect('http://127.0.0.1:4000/');
socket.on('KLINE',(pl)=>{
//log(pl);
candleSeries.update(pl);
});
Tag : HTML, JavaScript, jQuery
|
ประวัติการแก้ไข 2021-10-04 23:10:20
|
 |
 |
 |
 |
Date :
2021-10-04 23:08:42 |
By :
nongtoom |
View :
704 |
Reply :
0 |
|
 |
 |
 |
 |
|
|
|
 |