关于TradingView图表分析插件教程的说明以及简单⽤法
from blog.csdn/q506417225/article/details/79852401
⼤家都知道TradingView是纯英⽂版本APi,去年年底官⽅⽹站已⽀持中⽂浏览,但是api还是全英⽂⽀持。
所以国内使⽤者⼀定遇到很多阅读困惑,同理我也遇到很多⽆法正确理解为汉语意思的地⽅。
由于授权以及官⽅沟通⽅⾯问题,本⼈tradingview⽅⾯的教材暂时停⽌更新。后续不定期会更新⼀些上来,请⼤家见谅。
注意,官⽅的js库必须是以公司名义申请,不允许个⼈名义申请,如果以个⼈名义申请或者你所在⾏业经过中国区经销商了解后不需要⽤到tradingview将⽆法给你提供github的开源代码下载。源码结构如下图:
你取到官⽅授权许可和源码之后你就可以开始使⽤了,如果你⽤不到socket订阅动态更新最新价的话,只需要⽤到datafeed.js。也就是官⽅所说道的UDF加载数据模式(socket的使⽤需要调⽤js api): dataFeed包含了UDF订阅数据的内部结构调⽤⽅法,可在DataFeed.js⽂件中对所有的⽅法进⾏重写,重构。
接下来看下widget对象实例化⼀个图标中最关键的udf数据接⼝指向以及所对应的接⼝:
datafeed: new Datafeeds.UDFCompatibleDatafeed("/tradingview/TradingInterface"),
{\"supports_search\":true,\"supports_group_request\":false,\"supports_marks\":true,\"exchanges\":
[{\"value\":\"\",\"name\":\"All Exchanges\",\"desc\":\"\"},{\"value\":\"XETRA\",\"name\":\"XETRA\",\"desc\":\"XETRA\"}, {\"value\":\"NSE\",\"name\":\"NSE\",\"desc\":\"NSE\"},
{\"value\":\"NasdaqNM\",\"name\":\"NasdaqNM\",\"desc\":\"NasdaqNM\"},
{\"value\":\"NYSE\",\"name\":\"NYSE\",\"desc\":\"NYSE\"},{\"value\":\"CDNX\",\"name\":\"CDNX\",\"desc\":\"CDNX\"}, {\"value\":\"Stuttgart\",\"name\":\"Stuttgart\",\"desc\":\"Stuttgart\"}],\"symbolsTypes\":[{\"name\":\"All
types\",\"value\":\"\"},{\"name\":\"Stock\",\"value\":\"stock\"},
{\"name\":\"Index\",\"value\":\"index\"}],\"supportedResolutions\":
[\"1\",\"2\",\"3\",\"5\",\"15\",\"30\",\"60\",\"90\",\"240\",\"1D\",\"1W\",\"1M\",\"12M\"]}
◦ 解释
▪ supports_search是否⽀持搜索;英⽂解释Set this one =true if your datafeed supportssymbol search and individual symbol resolve logic.
▪ supports_group_request是否⽀持搜索或品种解析;英⽂解释Set this one =true if your datafeed provides full info aboutsymbols group only and is not able to perform symbol search or individualsymbol resolve.
▪ supports_marks
▪ exchanges交易所数组,⾥⾯的value表⽰交易所code,name表⽰交易所名称,desc表⽰交易所描述
▪ symbolsTypes品种所属类型,可属于多个类型
▪supportedResolutions中的值D代表天day,W代表周week,M代表⽉;2D是两天;3W是三周;6M是6个⽉,表⽰⽀持显⽰的哪⼏种图⽇线图、2⽇线
2.history是数据的关键项,这⼀块展⽰⾏情数据结构。具体结构如下:
{\"t\":[],\"c\":[],\"o\":[],\"h\":[],\"l\":[],\"v\":[],\"s\":\"ok\"}
◦ 解释
▪ t表⽰时间,将t的数值补000后就代表毫秒数,⽐如js的(new Date).getTime()
▪ c表⽰close收盘价
▪ o表⽰open开盘价
▪ h表⽰high最⾼价
▪ l表⽰low最低价
▪ v表⽰volume成交量
▪s表⽰状态,返回数据是否成功,ok表⽰成功
3.marks
{"id":[0,1,2,3,4,5],"time":
[1435116211.643,1434770611.643,1434511411.643,1434511411.643,1433820211.643,1432524211.643],"color": ["red","blue","green","red","blue","green"],"text":["Today","4days back","7 days back + Lorem ipsum dolor sit amet, consecteturadipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magnaaliqua.","7 days back once again","15 daysback","30 daysback"],"label":["A","B","CORE","D","EURO","F"],"labelFontColor":
["white","white","red","#FFFFFF","white","#000"],"minSize":[14,28,7,40,7,14]}
◦ 解释
▪ id: unique mark ID
▪ time表⽰秒数,距1970年1⽉1⽇之间的秒数
▪ color: mark color
▪ text: mark popup text. HTML supported
▪ label: mark label, single character
▪ labelFontColor: color of mark label
▪ minSize: minimal size of mark, diameter in pixels
4.search⽀持品种搜索接⼝
[{
"symbol": "APA",
"full_name": "APA",
"description": "Apache Corp.",
"exchange": "NYSE",
"type": "stock"
}, {
"symbol": "APC",
"full_name": "APC",
"description": "Anadarko Petroleum Corporation",
"exchange": "NYSE",
"type": "stock"
}]
◦ 解释
▪ symbol 是品种code
▪ full_name 品种全称
▪ description品种描述
▪ exchanges交易所
▪type类型stock表⽰股票
5.symbols是品种显⽰数据格式化接⼝
{"name":"AAPL","exchange-traded":"NasdaqNM","exchange-
listed":"NasdaqNM","timezone":"America/New_York","minmov":1,"minmov2":0,"pricescale":10,"pointvalue":1,"session":"0930-1630","has_intraday":false,"has_no_volume":false,"ticker":"AAPL","description":"AppleInc.","type":"stock","supported_resolutions": ["D","2D","3D","W","3W","M","6M"]}
▪name品种名称
▪ exchange-traded交易所名称
▪exchange-listed交易所名称
▪ timezone时区
▪ minmov⽤于格式化⽤途
▪ minmov2⽤于格式化⽤途
▪ pricescale是最⼩的显⽰可能出现的价格变化的⼩数部分的分隔符。其计算公式为:MinimalPossiblePriceChange = minmov / pricescale
▪ pointvalue
▪ session开盘时间
▪ has_intrady显⽰符号是否具有历史盘中数据;原⽂解释showing whether symbol has intraday history data
▪ has_no_volume是否有成交量
▪ description描述
▪ type类型,例如stock表⽰股票
▪ supportedResolutions中的值D代表天day,W代表周week,M代表⽉;2D是两天;3W是三周;6M是6个⽉,表⽰⽀持哪些图,如
下:
我们配置好这些对应的接⼝数据后就可以实现udf获取数据展⽰我们想要的个性化Tradingview图表啦。
简单举例(基于最新版本):
<body >
<div id="tv_chart_container">
</div>
</body>
[html]
1. <body >
2. <div id="tv_chart_container">
3. </div>
4. </body>
[html]
1. <script type="text/javascript">
2. function getParameterByName(name) {
3. name = place(/[
]
/, "\\]");
4. var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
5. results = (location.search);
6. return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
7. }
8.
javascript说明9. var _symbolcode = getParameterByName('symbol');
10. _symbolcode = _symbolcode ? _symbolcode : "EURUSD";
11. if (navigator.userAgent.indexOf('Firefox') >= 0)
12. { _symbolcode = encodeURIComponent(_symbolcode); }
13.
14. var _interval = getParameterByName('interval');
15. //_interval = _interval ? _interval : "1D";
16. _interval = _interval ? _interval : "1D"; //30
17.
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论