Mathieu2301 / TradingView-API

📈 Get real-time stocks from TradingView
1.47k stars 332 forks source link

Connection Freezing After 30 Pings with No Error #236

Open dawadam opened 7 months ago

dawadam commented 7 months ago

Describe the bug I am encountering an issue where the connection appears to freeze after 30 pings. There are no apparent errors or events logged during this process. This behavior persists consistently. I have attempted to troubleshoot the issue, but so far, I have been unable to identify the root cause. Any assistance or guidance on resolving this issue would be greatly appreciated.

To Reproduce

import TradingView from '@mathieuc/tradingview'

const client = new TradingView.Client(); // Creates a websocket client

// événements du client
client.onError((...err) => { // Listen for errors (can avoid crash)
    console.error('Client error:', ...err);
    // Do something...
});

client.onLogged((...args) => {
    console.error('Client logged:', ...args);
});

client.onPing((...args) => {
    console.error('Client ping:', ...args);
});

client.onData((...args) => {
    console.error('Client data:', ...args);
});

client.onEvent((...args) => {
    console.error('Client event:', ...args);
});

client.onConnected((...args) => {
    console.error('Client connected:', ...args);
});

client.onDisconnected((...args) => {
    console.error('Client disconnected:', ...args);
});

const chart = new client.Session.Chart(); // Init a Chart session

chart.setMarket('OANDA:EURUSD', { // Set the market
    timeframe: '1',
    type: 'HeikinAshi',
});

chart.onError((...err) => { // Listen for errors (can avoid crash)
    console.error('Chart error:', ...err);
    // Do something...
});

chart.onSymbolLoaded(() => { // When the symbol is successfully loaded
    console.log(`Market "${chart.infos.description}" loaded !`);
});

chart.onUpdate(() => { // When price changes
    if (!chart.periods[0]) return;
    // console.log(chart.infos)
    // console.log(chart.periods.length)
    console.log(`[${chart.infos.description}]: ${chart.periods[0].close} ${chart.infos.currency_id}`);
});

Expected behavior No freezing

Screenshots no

Environment:

Additional context Last logs :

Client event: ping 28
[EUR/USD]: 1.080445 USD
[EUR/USD]: 1.080445 USD
[EUR/USD]: 1.0804412500000002 USD
[EUR/USD]: 1.0804412500000002 USD
Client ping: 29
Client event: ping 29
[EUR/USD]: 1.0804375000000002 USD
[EUR/USD]: 1.0804375000000002 USD
[EUR/USD]: 1.0804387500000001 USD
[EUR/USD]: 1.0804387500000001 USD
Client ping: 30
Client event: ping 30
[EUR/USD]: 1.08044 USD
[EUR/USD]: 1.08044 USD
[EUR/USD]: 1.0804387500000001 USD
[EUR/USD]: 1.0804387500000001 USD