title: TradingView JS API websocket request response?
body: <p>I'm trying to use the tradingview chart widget for my own datasets and I'm a little confused as to how to get it working viawebsocket (all the examples I've found use REST). My confusion is in the 'binanceSymbols()' method. The example shows a REST call but I want to request the symbols via the open websocket connection and parse the response. What is the equivalent to the fetch/then when doing a websocket request and waiting for an response?</p>
  
  <p>I'm using <a href="https://github.com/bergusman/tradingview-jsapi-binance" rel="nofollow noreferrer">https://github.com/bergusman/tradingview-jsapi-binance</a> as a reference to try to figure it out.  </p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;body&gt;
   &lt;div id="tv_chart_container" class="chart_panel"&gt;&lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>JS:</p>
  
  <pre><code>class DataFeed
  {
  console.log("Datafeed:Loaded");
      this.binanceHost='http://localhost:8080'
      this.debug =options.debug ||false
  
      onReady(callback) {
          this.binanceSymbols().then((symbols) =&gt; {
              this.symbols = symbols
              callback({
                  supports_marks: false,
                  supports_timescale_marks: false,
                  supports_time: true,
                  supported_resolutions: [
                      '1', '3', '5', '15', '30', '60', '120', '240', '360', '480', '720', '1D', '3D', '1W', '1M'
                  ]
              })
          }).catch(err =&gt; {
              console.error(err)
          })
      }
  
    binanceSymbols() {
  
          return fetch(this.binanceHost + '/api/v1/exchangeInfo').then(res =&gt; {
              return res.json()
          }).then(json =&gt; {
              return json.symbols
          })
      }
  
  
  }
  
  var websocket = new WebSocket('ws://localhost:80080');
  websocket.onmessage = function processMsg(evt)
  {
  var json = evt.data;
  responseHandler(json);
  }
  
  function responseHandler(inmsg)
  {
  inmsg = JSON.parse(inmsg);
  if(inmsg.response[0].event=="login_success")
  {
  LoadChart();
  }
  function LoadChart()
  {
  
  
              TradingView.onready(function()
              {
              var config = {
              debug:true,
              exchanges:[],
              symbols_types:[],
              supported_resolutions:[],
              supports_marks:false,
              supports_timescale_marks:false,
              supports_time:false,
              futures_regex:'/^(.+)([12]!|[FGHJKMNQUVXZ]\d{1,2})$/',
  
              }
  
              var _widget = window.tvWidget = new TradingView.widget({
                    symbol: 'AAPL',
                    fullscreen:true,
                    interval: '15',
                    container_id: "tv_chart_container",
                    datafeed: new Datafeed(config),
                    library_path: "charting_library/",
                    locale: getParameterByName('lang') || "en",
                    disabled_features: ["use_localstorage_for_settings", "header_symbol_search", "symbol_search_hot_key"],
                    debug: false,
                    loading_screen: { backgroundColor: "#000000", foregroundColor:"#29e2bd" },
                    overrides: {
                      "paneProperties.background": "#222222",
                      "paneProperties.vertGridProperties.color": "#454545",
                      "paneProperties.horzGridProperties.color": "#454545",
                      "symbolWatermarkProperties.transparency": 90,
                      "scalesProperties.textColor": "#AAA"
                    }
                  });
  
  
              });
  }
  
  }
  </code></pre>