Share
Embed
Transcript
73 slides
-
໊ؔ ࣮ߦλΠϛϯά ֓ཁ 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࣮ߦޙ νϟʔτԼ෦ϚʔΫઃఆ σʔλϑΟʔυඞਢϝιουҰཡ -
ίϯετϥΫλ ˣ PO3FBEZ ˣ HFU4FSWFS5JNF ˣ SFTPMWF4ZNCPM ˣ DBMDVMBUF)JTUPSZ%FQUI ˣ
HFU#BST ˣ TVCTDSJCF#BST ˣ HFU.BSLT ˣ HFU5JNFTDBMF.BSLT ྫॳظදࣔ -
TFBSDI4ZNCPMT#Z/BNF ˣ SFTPMWF4ZNCPM ˣ VOTVCTDSJCF#BST ˣ DBMDVMBUF)JTUPSZ%FQUI ˣ HFU#BST ˣ
TVCTDSJCF#BST ˣ HFU.BSLT ˣ HFU5JNFTDBMF.BSLT ྫγϯϘϧΓସ͑ -
ίϯετϥΫλྫ 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(); }; -
\ TVQQPSUFE@SFTPMVUJPOT< % % % 8 >
TZNCPMT@UZQFT< \ OBNFશ௨՟ WBMVF ^ \ OBNFओཁ௨՟ WBMVFlNBJO@DVSSFODJFT ^ \ OBNFτʔΫϯ WBMVFUPLFOT ^ > ^ ؆୯ͳશମઃఆͷྫ -
σʔλϑΟʔυ෦ؔͦͷ̍ɿϦΫΤετૹ৴ 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' }); }; -
σʔλϑΟʔυ෦ؔͦͷ̎ɿΠϕϯτൃՐ 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] = []; } }; -
σʔλϑΟʔυ෦ؔͦͷ̏ɿΠϕϯτػ this._on = function(event, callback){ if (!this._callbacks.hasOwnProperty(event)) { this._callbacks[event] =
[]; } this._callbacks[event].push(callback); return this; }; -
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); }); } }; -
HFU4FSWFS5JNFྫ ZaifChart.prototype.getServerTime = function(callback) { this._send(this._datafeedURL + 'time', {}) .done(function(response)
{ callback(+response); }) .fail(function() { }); }; -
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([]); }); }; -
< \ 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: ^ ɾɾɾɾɾɾɾ > ؆қγϯϘϧใϦετͷྫ -
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'); }); }; -
\ UJNF[POF"TJB5PLZP TFTTJPO lOBNFCUD@KQZ UJDLFSCUD@KQZ UZQFNBJO@DVSSFODJFT
TVQQPSUFE@SFTPMVUJPOT< % 8 .> ^ ৄࡉ↓ https://github.com/tradingview/charting_library/wiki/Symbology#symbolinfo-structure ৄࡉγϯϘϧใͷྫ -
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'); }); }; -
දࣔ͢Δ0)-$σʔλΛऔಘ ɹɾҾ ɹɹɹTZNCPM*OGPɿγϯϘϧใ ɹɹɹSFTPMVUJPOɿִؒ ͱ͔%ͱ͔ GSPNɿσʔλ։࢝࣌ࠁ VOJYUJNF UPɿσʔλओྗ࣌ࠁ
VOJYUJNF ɹɹɹPO$BMMCBDLɿઃఆ ɹɹɹPO&SSPS$BMMCBDLɿΤϥʔϝοηʔδ ɹɾҾඵ୯Ґ͕ͩɺPO$BMMCBDLʹ ɹɹϛϦඵ୯ҐͰUJNFΛઃఆ͢Δඞཁ͋Γ -
\ PIMD@EBUB< \ IJHI
MPX UJNF DMPTF PQFO ^ \ IJHI MPX UJNF DMPTF PQFO ^ > ^ -
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); }; -
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); }; -
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); } }; }; -
VOTVCTDSJCF#BSTྫ ZaifChart.prototype.subscribeBars = function(listenerGUID) { this._barsPulseUpdater.unsubscribeDataListener(listenerGUID); };
ZaifChartDataPulseUpdater.prototype.subscribeDataListener = function(listenerGUID) { delete this._subscribers[listenerGUID]; }; -
ͦͷଞ //औಘ͢Δ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 -
(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 ؔΛ࣮ߦ