我目前正在尝试实现交易视图嵌入式图表功能。
问题是需要比交易视图支持更多对的网站,因此这对'BTCUSD'显示图表并且工作得很好,但是不太流行的加密货币对(例如'MDTUSD')返回的图表内部没有数据。 / p>
有没有一种方法可以检查该配对是否受支持?
交易视图嵌入代码
<!-- TradingView Widget BEGIN -->
<div class="tradingview-widget-container">
<div id="tradingview_a9055"></div>
<div class="tradingview-widget-copyright"><a href="https://www.tradingview.com/symbols/BTCUSD/" rel="noopener" target="_blank"><span class="blue-text">AAPL chart</span></a> by TradingView</div>
<script type="text/javascript" src="https://s3.tradingview.com/tv.js"></script>
<script type="text/javascript">
new TradingView.widget(
{
"width": 1000,
"height": 500,
"symbol": "BTCUSD",
"interval": "D",
"timezone": "Etc/UTC",
"theme": "Light",
"style": "1",
"locale": "en",
"toolbar_bg": "#f1f3f6",
"enable_publishing": true,
"withdateranges": true,
"hide_side_toolbar": false,
"save_image": false,
"studies": [
"MASimple@tv-basicstudies"
],
"container_id": "tradingview_a9055"
}
);
</script>
</div>
<!-- TradingView Widget END -->
认为我可以做这样的事情
<script type="text/javascript">
if (new TradingView.widget(
{
"width": 1000,
"height": 500,
"symbol": "MDTUSD",
"interval": "D",
"timezone": "Etc/UTC",
"theme": "Light",
"style": "1",
"locale": "en",
"toolbar_bg": "#f1f3f6",
"enable_publishing": true,
"withdateranges": true,
"hide_side_toolbar": false,
"save_image": false,
"studies": [
"MASimple@tv-basicstudies"
],
"container_id": "tradingview_a9055"
}
)) {
new TradingView.widget(
{
"width": 1000,
"height": 500,
"symbol": "MDTUSD",
"interval": "D",
"timezone": "Etc/UTC",
"theme": "Light",
"style": "1",
"locale": "en",
"toolbar_bg": "#f1f3f6",
"enable_publishing": true,
"withdateranges": true,
"hide_side_toolbar": false,
"save_image": false,
"studies": [
"MASimple@tv-basicstudies"
],
"container_id": "tradingview_a9055"
}
);
} else {
alert("NO CHART");
}
</script>