SHARE
TWEET

Untitled

a guest Nov 29th, 2018 133 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @TVChartUI = flight.component ->
  2.   @onReady = (callback) ->
  3.     console.log 'onReady'
  4.     setTimeout (->
  5.       console.log 'TV ready function'
  6.       callback
  7.         exchanges: []
  8.         symbols_types: []
  9.         supports_marks: false
  10.         supports_timescale_marks: false
  11.         supports_time: true
  12.         futures_regex: false
  13.         has_daily: false
  14.         has_weekly: false
  15.         supported_resolutions: ['1', '5', '15', '30', '60', '120', '240', '360', '720', '1D', '3D', '1W']
  16.         seconds_multipliers: ['1', '5', '15', '30', '60', '120', '240', '360', '720']
  17.     ), 0
  18.  
  19.   @getBars = (symbolInfo, resolution, from, to, onHistoryCallback, onErrorCallback, firstDataRequest) ->
  20.     console.log 'getBars @ ' + resolution
  21.     if firstDataRequest
  22.       if resolution == '1D'
  23.         resolution = 60 * 24
  24.       if resolution == '3D'
  25.         resolution = 60 * 24 * 3
  26.       if resolution == '1W'
  27.         resolution = 60 * 24 * 7
  28.       @getBarsFrom = from
  29.       @getBarsTo = to
  30.       @getBarsFirstDataRequest = firstDataRequest
  31.       @getBarsCallback = onHistoryCallback
  32.       return @component.trigger(document, 'switch::range_switch', x: resolution)
  33.     return
  34.  
  35.   @searchSymbols = (userInput, exchange, symbolType, onResultReadyCallback) ->
  36.     console.log 'searchSymbols'
  37.     onResultReadyCallback []
  38.  
  39.   @resolveSymbol = (symbolName, onSymbolResolvedCallback, onResolveErrorCallback) ->
  40.     setTimeout (->
  41.       console.log 'resolveSymbol: ' + symbolName
  42.       onSymbolResolvedCallback
  43.         name: symbolName
  44.         ticker: symbolName
  45.         timezone: 'America/New_York'
  46.         minmov: 1
  47.         pricescale: 100000000
  48.         session: '24x7'
  49.         data_status: 'streaming'
  50.         currency_code: symbolName
  51.         has_intraday: true
  52.         has_daily: true
  53.         has_weekly: false
  54.         supported_resolutions: [
  55.           '1'
  56.           '5'
  57.           '15'
  58.           '30'
  59.           '60'
  60.           '120'
  61.           '240'
  62.           '360'
  63.           '720'
  64.           '1D'
  65.           '3D'
  66.           '1W'
  67.         ]
  68.     ), 0
  69.  
  70.   @subscribeBars = (symbolInfo, resolution, onRealtimeCallback, subscriberUID, onResetCacheNeededCallback) ->
  71.     console.log 'subscribeBars'
  72.  
  73.   @unsubscribeBars = (unsubscribeBars) ->
  74.     console.log 'unsubscribeBars'
  75.  
  76.   @getMarks = (symbolInfo, startDate, endDate, onDataCallback, resolution) ->
  77.     console.log 'getMarks'
  78.  
  79.   @getTimescaleMarks = (symbolInfo, startDate, endDate, onDataCallback, resolution) ->
  80.     console.log 'getTimescaleMarks'
  81.  
  82.   @getServerTime = (callback) ->
  83.     console.log 'getServerTime'
  84.  
  85. @TVChartUIComponent = flight.component ->
  86.   @mask = ->
  87.     @$node.find('.mask').show()
  88.  
  89.   @unmask = ->
  90.     @$node.find('.mask').hide()
  91.  
  92.   @request = ->
  93.     @mask()
  94.  
  95.   @init = (event, data) ->
  96.     if @firstBarTime == 0 and data.candlestick.length > 0
  97.       @firstBarTime = data.candlestick[0][0]
  98.     candles = []
  99.     ref = data.candlestick
  100.     for i of ref
  101.       d = ref[i]
  102.       t = d[0]
  103.       st = t / 1000
  104.       if st < window.tvchartui.getBarsFrom
  105.         continue
  106.       if st > window.tvchartui.getBarsTo and !window.tvchartui.getBarsFirstDataRequest
  107.         continue
  108.       candles[candles.length] =
  109.         time: t
  110.         open: d[1]
  111.         high: d[2]
  112.         low: d[3]
  113.         close: d[4]
  114.     console.log JSON.stringify(candles)
  115.     if candles.length > 0
  116.       window.tvchartui.getBarsCallback candles
  117.     else
  118.       window.tvchartui.getBarsCallback candles, noData: true
  119.  
  120.   @updateByTrades = (event, data) ->
  121.     console.log event
  122.     console.log JSON.stringify(data)
  123.  
  124.   @after 'initialize', ->
  125.     @on document, 'trade::populate', @updateByTrades
  126.     @on document, 'market::candlestick::request', @request
  127.     @on document, 'market::candlestick::response', @init
  128.     @on document, 'market::candlestick::trades', @updateByTrades
  129.     @firstBarTime = 0
  130.     window.tvchartui = new TVChartUI
  131.     window.tvchartui.component = this
  132.     tvinit()
  133.     @trigger 'market::candlestick::created'
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top