aboutsummaryrefslogtreecommitdiffstats
path: root/public/js/index.coffee
blob: 7db59a66a0f1da1005aa0a4a6bf3d6f30faaf40e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#= require jquery-1.8.2.min.js

$(->
  fetchExchangeRate('ask') 
  fetchExchangeRate('bid') 
)

fetchExchangeRate = (type) ->
  commission = 0.03
  commission *= -1 if type is 'bid'

  $.ajax(
    url: "ticker?symbol=virtexCAD&type=#{type}&amount=1000",
    cache: false,
    success: (exchange) -> 
      if not exchange?
        exchange = '??'

      exchange = exchange - exchange * commission
      $("##{type}").html(exchange.toFixed(2))
    error: -> 
      $("##{type}").html('??')
  )
  setTimeout(fetchExchangeRate, 900000)