How_To_ Introduce_TradingView

6dbe360915689b269ab4fa510743762b?s=47 英 谷口
October 25, 2017
510

How_To_ Introduce_TradingView

6dbe360915689b269ab4fa510743762b?s=128

英 谷口

October 25, 2017
Tweet

Transcript

  1. αʔόαΠυΤϯδχΞ͕ +BWB4DSJQUΛॻ͍ͯ 5SBEJOH7JFXΛಋೖͨ͠࿩ ୩ޱӳ ౦ژ/PEFֶԂࡇ 

  2. ࣗݾ঺հ

  3. ໊લɿ୩ޱӳ ϝΠϯݴޠɿ1ZUIPO Yܥ  !IPSPCJ@HFOHFS "LJSB5BOJHVDIJ BLJSBUBOJHVDIJ

  4. None
  5. ࠷ۙؾʹͯ͠Δ͜ͱ

  6. ʮ4MBDL͕͚ͦͬͳ͍ʯ ͬͯݴΘΕͨ

  7. +BWB4DSJQUͷܦݧ

  8. ϑϧελοΫ ͱ ݴ͍͍͙ͬͯΒ͍ͷ͜ͱ͸ Ͱ͖Δ͔΋ ɹ+2VFSZͱ͔ɺ3FBDUͱ͔Λ ɹͪΐ͍ͪΐ͍࢖͏

  9. ࠷ۙ ݄ि໨͝Ζ ͔Β /PEFΛۀ຿Ͱ࢖͏Α͏ʹ ΍ͬͯΔ͜ͱɿ ɹϒϩοΫνΣʔϯͷղੳ ɹτʔΫϯɾτϥϯβΫγϣϯൃߦ

  10. ॴଐɿςοΫϏϡʔϩגࣜձࣾ

  11. ɾ;BJG ɹ҉߸௨՟औҾॴ ɾNJKJO ɹϓϥΠϕʔτϒϩοΫνΣʔϯ ɾ$0.4" ɹ*$0ϓϥοτϑΥʔϜ

  12. None
  13. 5SBEJOH7JFXͱ͸ʁ

  14. None
  15. ɹɹνϟʔτϥΠϒϥϦ ɾΠϯσΟέʔλ ɾ4/4࿈ܞ ɾΞΠσΞڞ༗ ɹͳͲͳͲɺͱΓ͋͑ͣ௒ଟػೳ

  16. ໰୊఺

  17. ໰୊఺ ೔ຊޠͰղઆ͞Εͨࢿྉ͕ ΄΅ແ͍

  18. ຊ೔ͷ࣋ͪؼΕΔ৘ใ ɾ5SBEJOH7JFXಋೖํ๏ ɾ1ZUIPOJTUB͔ΒΈͨ ɹ+BWB4DSJQUʹࢥ͏ͱ͜Ζ

  19. 5SBEJOH7JFXಋೖํ๏

  20. ̍ϥΠϒϥϦͷ഑ஔ ̎σʔλϑΟʔυ࡞੒ ̏νϟʔτىಈ

  21. ̍ϥΠϒϥϦͷ഑ஔ ̎σʔλϑΟʔυ࡞੒ ̏νϟʔτىಈ

  22. None
  23. None
  24. HJUDMPOFIUUQTHJUIVCDPNUSBEJOHWJFXDIBSUJOH@MJCSBSZHJU DEDIBSUJOH@MJCSBSZ DQSGDIBSUJOH@MJCSBSZdQSPKFDUIUNM

  25. ̍ϥΠϒϥϦͷ഑ஔ ̎σʔλϑΟʔυ࡞੒ ̏νϟʔτىಈ

  26. σʔλϑΟʔυͱ͸ʁ

  27. 5SBEJOH7JFXˡˠαʔό σʔλͷ΍ΓऔΓΛ͢ΔΫϥε

  28. ಠࣗσʔλΛද͍ࣔͨ͠৔߹͸ ಠ࣮ࣗ૷͢Δඞཁ͋Γ

  29. ؔ਺໊ ࣮ߦλΠϛϯά ֓ཁ PO3FBEZ ىಈ࣌ શମઃఆσʔλऔಘ HFU4FSWFS5JNF PO3FBEZ࣮ߦޙ αʔό࣌ࠁऔಘ TFBSDI4ZNCPMT#Z/BNF

    γϯϘϧมߋ࣌ γϯϘϧݕࡧ݁Ռσʔλऔಘ SFTPMWF4ZNCPM γϯϘϧܾఆ࣌ γϯϘϧৄࡉσʔλऔಘ DBMDVMBUF)JTUPSZ%FQUI HFU#BST࣮ߦલ σʔλಡΈࠐΈظؒઃఆ HFU#BST σʔλදࣔ࣌ PIMDσʔλσʔλऔಘ TVCTDSJCF#BST ॳճHFU#BST࣮ߦޙ ϦΞϧλΠϜσʔλऔಘ VOTVCTDSJCF#BST γϯϘϧมߋલ ϦΞϧλΠϜσʔλऔಘղআ HFU.BSLT HFU#BST࣮ߦޙ νϟʔτϚʔΫઃఆ HFU5JNFTDBMF.BSLT HFU#BST࣮ߦޙ νϟʔτԼ෦ϚʔΫઃఆ σʔλϑΟʔυඞਢϝιουҰཡ
  30. ίϯετϥΫλ ˣ PO3FBEZ ˣ HFU4FSWFS5JNF ˣ SFTPMWF4ZNCPM ˣ DBMDVMBUF)JTUPSZ%FQUI ˣ

    HFU#BST ˣ TVCTDSJCF#BST ˣ HFU.BSLT ˣ HFU5JNFTDBMF.BSLT ྫॳظදࣔ
  31. TFBSDI4ZNCPMT#Z/BNF ˣ SFTPMWF4ZNCPM ˣ VOTVCTDSJCF#BST ˣ DBMDVMBUF)JTUPSZ%FQUI ˣ HFU#BST ˣ

    TVCTDSJCF#BST ˣ HFU.BSLT ˣ HFU5JNFTDBMF.BSLT ྫγϯϘϧ੾Γସ͑
  32. αʔόଆ΋࣮૷͕ඞཁ ࠓճ͸লུ  جຊ KTPOΛฦ٫͢Δ8FC"1* ޷͖ͳݴޠͰͲ͏ͧ

  33. ࠓճ͸&4Ͱઆ໌ &4Ͱ΋େৎ෉

  34. ίϯετϥΫλྫ ZaifChart = function() {
 this._datafeedURL = location.protocol + '//'

    + location.hostname + '/zaif_chart_api/v1/';
 this._configuration = {};
 this._callbacks = {};
 this._initialize = function(){
 var that = this;
 this._send(this._datafeedURL + 'config', {})
 .done(function(response) {
 $.each( JSON.parse(response), function( key, value ) {
 that._configuration[key] = value;
 });
 that._fireEvent('configuration_ready');
 })
 .fail(function(reason) {
 that.logMessage(reason);
 throw new Error(reason)
 });
 }; this._initialize(); };
  35. αʔό͔ΒશମઃఆΛऔಘ ɹɾશମઃఆ͸KTʹ௚ॻ͖Ͱ΋Մೳ ɹɹɾͦͷ৔߹࣮૷͸ෆཁ

  36. \ TVQQPSUFE@SFTPMVUJPOT< %  %  %  8 >

     TZNCPMT@UZQFT< \ OBNFશ௨՟  WBMVF ^  \ OBNFओཁ௨՟  WBMVFlNBJO@DVSSFODJFT ^  \ OBNFτʔΫϯ  WBMVFUPLFOT ^ > ^ ؆୯ͳશମઃఆͷྫ
  37. IUUQTEFNP@GFFEUSBEJOHWJFXDPNDPOpH ؾʹͳΔํ͸Լه"1*Λୟ͍ͯΈ͍ͯͩ͘͞

  38. σʔλϑΟʔυ಺෦ؔ਺ͦͷ̍ɿϦΫΤετૹ৴ this._send = function(url, params) {
 var request = url;


    if (params) {
 for (var i = 0; i < Object.keys(params).length; ++i) {
 var key = Object.keys(params)[i];
 var value = encodeURIComponent(params[key]);
 request += (i === 0 ? '?' : '&') + key + '=' + value;
 }
 }
 this.logMessage('request url:' + request);
 return $.ajax({
 type: 'GET',
 url: request,
 contentType: 'text/plain'
 });
 };
  39. σʔλϑΟʔυ಺෦ؔ਺ͦͷ̎ɿΠϕϯτൃՐ this._fireEvent = function(event, argument) {
 if (this._callbacks.hasOwnProperty(event)) {
 var

    callbacksChain = this._callbacks[event];
 for (var i = 0; i < callbacksChain.length; ++i) {
 callbacksChain[i](argument);
 }
 this._callbacks[event] = [];
 }
 };
  40. σʔλϑΟʔυ಺෦ؔ਺ͦͷ̏ɿΠϕϯτ଴ػ this._on = function(event, callback){
 if (!this._callbacks.hasOwnProperty(event)) {
 this._callbacks[event] =

    [];
 }
 
 this._callbacks[event].push(callback);
 return this;
 };
  41. PO3FBEZྫ ZaifChart.prototype.onReady = function(callback) {
 var that = this;
 if

    (this._configuration) {
 setTimeout(function() {
 callback(that._configuration);
 }, 0);
 } else {
 this._on('configuration_ready', function() {
 callback(that._configuration);
 });
 }
 };
  42. શମઃఆΛ5SBEJOH7JFXʹηοτ͍ͯ͠Δ ɹɾίϯετϥΫλͰશମઃఆΛαʔό͔Β ɹɹऔಘ͢Δ৔߹ɺ଴ػॲཧ͕ඞཁ ɹɾKT௚ॻͷ৔߹΋TFU5JNFPVUͰғ·ͳ͍ͱ ɹɹ5SBEJOH7JFX͕ܯࠂΛग़͢ͷͰ஫ҙ

  43. HFU4FSWFS5JNFྫ ZaifChart.prototype.getServerTime = function(callback) {
 this._send(this._datafeedURL + 'time', {})
 .done(function(response)

    {
 callback(+response);
 })
 .fail(function() {
 });
 };
  44. αʔό࣌ࠁΛ5SBEJOH7JFXʹઃఆ͍ͯ͠Δ ɹɾKTPOͰ͸ͳ͘਺஋Λͦͷ··౉͢

  45. TFSDI4ZNCPM#Z/BNFྫ 
 ZaifChart.prototype.searchSymbolsByName = function(userInput, exchange, symbolType, onResultReadyCallback) {
 this._send(this._datafeedURL

    + 'search', {
 user_input: userInput,
 symbol_type: symbolType
 })
 .done(function(response) {
 var data = JSON.parse(response);
 onResultReadyCallback(data);
 })
 .fail(function(reason) {
 this.logMessage('searchSymbolsByName error:’ + reason);
 onResultReadyCallback([]);
 });
 };
  46. ೖྗ஋ʹ֘౰͢Δ؆қγϯϘϧ৘ใϦετΛऔಘ ɹɾҾ਺ ɹɹɹVTFS*OQVUɿೖྗγϯϘϧ໊ ɹɹɹFYDIBOHFɿೖྗऔҾॴ໊ ɹɹɹTZNCPM5ZQFɿೖྗγϯϘϧλΠϓ ɹɹɹPO3FTVMU3FBEZ$BMMCBDLɿ஋ઃఆ ɹɾΤϥʔͷ࣌͸ۭ഑ྻΛ౉͢

  47. < \  UZQFNBJO@DVSSFODJFT   TZNCPM#5$@+1:   UJDLFSCUD@KQZ

      EFTDSJQUJPOϏοτίΠϯ೔ຊԁऔҾ   GVMM@OBNF#5$@+1: ^  \  UZQFUPLFO   TZNCPM1&1&$"4)@+1:   UJDLFSQFQFDBTI@KQZ   EFTDSJQUJPO1&1&$"4)೔ຊԁऔҾ   GVMM@OBNF1&1&$"4)@+1: ^  ɾɾɾɾɾɾɾ > ؆қγϯϘϧ৘ใϦετͷྫ
  48. SFTPMWF4ZNCPMྫ 
 ZaifChart.prototype.resolveSymbol = function(symbolName, onCallback, onErrorCallback) {
 this._send(this._datafeedURL +

    'symbols', {symbol: symbolName})
 .done(function(response) {
 var data = JSON.parse(response);
 onCallback(data);
 })
 .fail(function(reason) {
 this.logMessage('resolveSymbol error:’ + reason);
 onErrorCallback('unknown_symbol');
 });
 };
  49. Ҿ਺ʹ֘౰͢ΔৄࡉͳγϯϘϧ৘ใΛऔಘ ɹɾҾ਺ ɹɹɹTZNCPM/BNFɿγϯϘϧ໊ ɹɹɹPO$BMMCBDLɿ஋ઃఆ ɹɹɹPO&SSPS$BMMCBDLɿΤϥʔϝοηʔδ ɹɾγϯϘϧ໊͸γεςϜશମͰ ɹɹҰҙͷ΋ͷʹ͓ͯ͘͜͠ͱ

  50. \ UJNF[POF"TJB5PLZP  TFTTJPO  lOBNFCUD@KQZ  UJDLFSCUD@KQZ  UZQFNBJO@DVSSFODJFT

     TVQQPSUFE@SFTPMVUJPOT<  % 8 .> ^ ৄࡉ͸↓ https://github.com/tradingview/charting_library/wiki/Symbology#symbolinfo-structure ৄࡉγϯϘϧ৘ใͷྫ
  51. HFU#BSTྫ 
 ZaifChart.prototype.getBars = function(symbolInfo, resolution, from, to, onCallback, onErrorCallback)

    {
 var that = this;
 this._send(this._datafeedURL + 'history', {
 symbol: symbolInfo.name,
 resolution: resolution,
 from: from,
 to: to
 })
 .done(function(response) {
 var data = JSON.parse(response);
 var noData = data.ohlc_data.length === 0;
 var bars = [];
 var barsCount = noData ? 0 : data.ohlc_data.length;
 for (var i = 0; i < barsCount; ++i) {
 var barValue = {
 time: data.ohlc_data[i].time,
 close: data.ohlc_data[i].close,
 open: data.ohlc_data[i].open,
 high: data.ohlc_data[i].high,
 low: data.ohlc_data[i].low,
 volume: data.ohlc_data[i].volume
 };
 bars.push(barValue);
 }
 onCallback(bars, { noData: noData});
 })
 .fail(function(reason) {
 that.logMessage('getBars error:'+ reason);
 onErrorCallback(‘network error');
 });
 };
  52. දࣔ͢Δ0)-$σʔλΛऔಘ ɹɾҾ਺ ɹɹɹTZNCPM*OGPɿγϯϘϧ৘ใ ɹɹɹSFTPMVUJPOɿִؒ ͱ͔%ͱ͔  GSPNɿσʔλ։࢝࣌ࠁ VOJYUJNF  UPɿσʔλओྗ࣌ࠁ

    VOJYUJNF  ɹɹɹPO$BMMCBDLɿ஋ઃఆ ɹɹɹPO&SSPS$BMMCBDLɿΤϥʔϝοηʔδ ɹɾҾ਺͸ඵ୯Ґ͕ͩɺPO$BMMCBDLʹ͸ ɹɹϛϦඵ୯ҐͰUJNFΛઃఆ͢Δඞཁ͋Γ
  53. \  PIMD@EBUB<  \   IJHI  

     MPX    UJNF    DMPTF    PQFO  ^   \   IJHI    MPX    UJNF    DMPTF    PQFO  ^  > ^
  54. TVCTDSJCF#BSTྫ //ίϯετϥΫλͰνϟʔτσʔλΛߋ৽͢ΔΫϥεΛ࢓ࠐΜͰ͓͘
 ZaifChart = function() { ɾɾɾɾɾɾ
 this._barsPulseUpdater = new

    ZaifChartDataPulseUpdater(this, 1000); ɹɹɾɾɾɾɾɾ }; 
 ZaifChart.prototype.subscribeBars = function(symbolInfo, resolution, onRealtimeCallback, listenerGUID, onResetCallback) {
 this._barsPulseUpdater.subscribeDataListener(symbolInfo, resolution, onRealtimeCallback, listenerGUID, onResetCallback);
 };
  55. ZaifChartDataPulseUpdater = function(datafeed, interval) {
 this._datafeed = datafeed;
 this._subscribers =

    {};
 this._requestsPending = false;
 setInterval(_update, interval);
 };
 
 ZaifChartDataPulseUpdater.prototype.subscribeDataListener = function(symbolInfo, resolution, newDataCallback, listenerGUID) {
 this._datafeed.logMessage('Subscribing ' + listenerGUID);
 
 if (!this._subscribers.hasOwnProperty(listenerGUID)) {
 this._subscribers[listenerGUID] = {
 symbolInfo: symbolInfo,
 resolution: resolution,
 lastBarTime: NaN,
 listeners: []
 };
 }
 
 this._subscribers[listenerGUID].listeners.push(newDataCallback);
 };

  56. ZaifChartDataPulseUpdater = function(datafeed, interval) {
 var that = this;
 var

    _update = function() {
 for (var listenerGUID in that._subscribers) {
 var subscriptionRecord = that._subscribers[listenerGUID];
 var resolution = subscriptionRecord.resolution;
 (function(_subscript) {
 that._datafeed.getBars(_subscript.symbolInfo, resolution, null, null, function(bars, updateBarsFlg) {
 that._requestsPending = false;
 var lastBar = bars[bars.length - 1];
 var subscribers = _subscript.listeners;
 var isNewBar = lastBar.time > _subscript.lastBarTime;
 if (isNewBar) {
 var previousBar = bars[bars.length - 2];
 for (var i = 0; i < subscribers.length; ++i) {
 subscribers[i](previousBar);
 }
 }
 _subscript.lastBarTime = lastBar.time;
 for (var i = 0; i < subscribers.length; ++i) {
 subscribers[i](lastBar);
 }
 },
 function() {
 }, null);
 })(subscriptionRecord);
 }
 };
 };
  57. ϦΞϧλΠϜσʔλΛऔಘ ɹɾҾ਺ ɹɹɹTZNCPM*OGPɿγϯϘϧ৘ใ ɹɹɹSFTPMVUJPOɿִؒ ͱ͔%ͱ͔  PO3FBMUJNF$BMMCBDL৽نσʔληοτ MJTUFOFS(6*%Ұҙͷจࣈྻ ɹɹɹPO3FTFU$BMMCBDLɿσʔλมߋ࣌ؔ਺ ɹɾHFU#BSTؔ਺Λఆظతʹ

    ɹɹ࣮ߦ͢Δ࢓૊ΈΛ࡞੒͢Δ
  58. VOTVCTDSJCF#BSTྫ 
 
 ZaifChart.prototype.subscribeBars = function(listenerGUID) {
 this._barsPulseUpdater.unsubscribeDataListener(listenerGUID);
 };
 


    ZaifChartDataPulseUpdater.prototype.subscribeDataListener = function(listenerGUID) {
 delete this._subscribers[listenerGUID];
 };

  59. ϦΞϧλΠϜσʔλऔಘॲཧΛఀࢭ ɹɾҾ਺ MJTUFOFS(6*%Ұҙͷจࣈྻ

  60. ͦͷଞ //औಘ͢ΔOHLCσʔλͷൣғΛมߋ͢Δ ZaifChart.prototype.calculateHistoryDepth = function(resolution, resolutionBack, intervalBack) {
 };
 //νϟʔτϚʔΫදࣔ


    ZaifChart.prototype.getMarks = function(symbolInfo, startDate, endDate, onDataCallback, resolution) {
 onDataCallback([]);
 };
 //νϟʔτԼ෦ϚʔΫදࣔ
 ZaifChart.prototype.getTimescaleMarks = function(symbolInfo, startDate, endDate, onDataCallback, resolution) {
 onDataCallback([]);
 };
 ৄࡉ͸↓ https://github.com/tradingview/charting_library/wiki/JS-Api#getmarkssymbolinfo-startdate-enddate- ondatacallback-resolution-optional
  61. ̍ϥΠϒϥϦͷ഑ஔ ̎σʔλϑΟʔυ࡞੒ ̏νϟʔτىಈ

  62. <script type="text/javascript" src=“/js/charting_library/charting_library.min.js"> </script> ϥΠϒϥϦΛಡΈࠐΉ

  63. <div id="trading-view-area"></div>
 νϟʔτΤϦΞΛઃఆ

  64. (function() {
 TradingView.onready(function () { //४උ͕Ͱ͖͔ͯΒ࣮ߦ͞ΕΔ
 new TradingView.widget({ //֤ΦϓγϣϯΛઃఆ
 fullscreen:

    true,
 symbol: ‘btc_jpy’,
 interval: 'D',
 container_id: 'trading-view-area',
 datafeed: new ZaifChart(),
 library_path: '/js/charting_library/',
 locale: 'ja',
 disabled_features: ["use_localstorage_for_settings"],
 enabled_features: ["study_templates"],
 charts_storage_url: 'http://saveload.tradingview.com',
 charts_storage_api_version: "1.1",
 client_id: 'tradingview.com',
 user_id: 'public_user_id'
 });
 });
 })(); ৄࡉ͸Լه↓ https://github.com/tradingview/charting_library/wiki/Widget-Constructor ؔ਺Λ࣮ߦ
  65. fullscreen:booleanɺtrueͷ৔߹શը໘දࣔ interval:νϟʔτͷִؒΛࢦఆɺҰ೔ͷ৔߹͸D౳ locale:ja΍enͳͲදࣔ͢Δݴޠ৘ใΛઃఆ datafeed:σʔλϑΟʔυΫϥεΠϯελϯε locale:ݴޠઃఆ symbol:දࣔͤ͞Δ௨՟ϖΞ Φϓγϣϯྫ

  66. ͓ΊͰͱ͏͍͟͝·͢

  67. ଞʹ΋ ɾ"1*Λ࢖ͬͯ֎෦͔ΒػೳΛݺͼग़͢ ɾΧελϜͯ͠ಠࣗΠϯσΟέʔλΛදࣔ ͳΜͯ͜ͱ͕Ͱ͖Δ ࠓ೔͸࣌ؒͷ౎߹Ͱলུɻɻ

  68. ࠓ೔ͷ಺༰͸Լهʹ΋هࡌ 2JJUB5SBEJOH7JFX֮ॻ IUUQTRJJUBDPN"LJSB5BOJHVDIJJUFNT BDEGGBECCCEGFE ʮRJJUB5SBEJOH7JFXʯͰάά͍ͬͯͩ͘͞

  69. ࠷ޙʹ 1ZUIPOJTUB͔Βݟͨ +BWB4DSJQU ͱ͍͏͔/PEF ͷࢥ͏ͱ͜Ζ

  70. (PPE ҉߸௨՟ܥͷϥΠϒϥϦ͕ଟ͍ OFNTEL XFC

  71. 1SPCMFN ॻ͍ͨͱ͓Γʹಈ͍ͯ͘Εͳ͍ UIFO 1SPNJTFͷཧղ͕ඞਢ BXBJU BTZODόϯβΠ ׳ΕΕ͹໰୊ͳ͍

  72. (PPE OQNͷήʔδ͕͔͍͍ͬ͜

  73. ऴΘΓ