Permalink
Browse files

GRAPHS

  • Loading branch information...
1 parent 706a83d commit 915ddcd931b9ab352620a06ae1baf840944a0381 @airhorns committed Nov 20, 2011
Showing with 17,344 additions and 16,253 deletions.
  1. +5 −1 lib/trade_manager.rb
  2. +2,379 −1,330 public/highcharts.src.js
  3. +14,922 −14,914 public/highstock.src.js
  4. +2 −0 redis_scripts/fill_order.lua
  5. +6 −0 user_server.rb
  6. +27 −8 views/graphs.coffee
  7. +3 −0 views/index.erb
View
6 lib/trade_manager.rb
@@ -8,7 +8,7 @@ def initialize(redis = nil)
end
def trades_since(stock, since_id = 0)
- @redis.zrangebyscore("trades_#{stock}", since_id, '+inf', :limit => [0, 200]).map do |id|
+ @redis.zrangebyscore("trades_#{stock}", since_id, '+inf', :limit => [0, 2000]).map do |id|
convert(id)
end
end
@@ -30,4 +30,8 @@ def get_root(id)
end
order
end
+
+ def stocks
+ $redis.smembers('stocks')
+ end
end
View
3,709 public/highcharts.src.js
2,379 additions, 1,330 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
29,836 public/highstock.src.js
14,922 additions, 14,914 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
2 redis_scripts/fill_order.lua
@@ -2,6 +2,8 @@ local MAX_ID = 100000000
local stock, order_type = KEYS[1], KEYS[2]
local from, shares, price, twilio, broker, created = ARGV[1], tonumber(ARGV[2]), tonumber(ARGV[3]), ARGV[4], ARGV[5], ARGV[6]
+redis.call('SADD', 'stocks', stock)
+
function score(price, id, order_type)
if order_type == 'buy' then
return price * MAX_ID + (MAX_ID - id)
View
6 user_server.rb
@@ -63,6 +63,12 @@
content_type :json
{:trades => TradeManager.new.trades_since(params[:stock], params[:since])}.to_json
end
+
+get '/stocks.json' do
+ content_type :json
+ {:stocks => TradeManager.new.stocks}.to_json
+end
+
get '/reset' do
StockManager.new("").reset!
erb :reset
View
35 views/graphs.coffee
@@ -11,12 +11,15 @@ class ChartView
self = @
object =
+ animation: false
chart:
renderTo: "graph"
events:
load: ->
- series = @series[0]
- window.getNewData = setInterval self.getNewData, self.UPDATE_INTERVAL
+ #window.getNewData = setInterval self.getNewData, self.UPDATE_INTERVAL
+
+ navigator:
+ enabled: false
rangeSelector:
buttons: [
@@ -46,13 +49,16 @@ class ChartView
series: [
name: "#{stock} price"
+ type: "candlestick"
data: []
+ tooltip:
+ yDecimals: 2
]
@chart = new Highcharts.StockChart(object)
@getNewData()
- remove: -> @chart.remove()
+ remove: -> @chart.destroy()
getNewData: =>
$.ajax
@@ -62,17 +68,30 @@ class ChartView
since: @since
success: (data) =>
series = @chart.series[0]
- for execution in data.trades
- series.addPoint
+ points = for execution in data.trades
+ point =
x: Date.parse(execution.created)
y: execution.price
- , false
+ debugger unless point.x > 0 && point.y > 0
+ series.addPoint point, false, false
+ point
+
if data.trades.length > 0
@since = parseInt(data.trades[data.trades.length - 1].id) + 1
- @chart.redraw()
+ @chart.redraw()
true
error: -> console.error(arguments)
$ ->
- window.chart = new ChartView("ABLE")
+ $.ajax
+ url: '/stocks.json'
+ dataType: 'json'
+ success: (data) ->
+ for stock in data.stocks
+ option = $('<option>')
+ option.html(stock)
+ $('#stock').append(option)
+
+ $('#stock').change ->
+ window.chart = new ChartView($("#stock option:selected").html())
View
3 views/index.erb
@@ -3,3 +3,6 @@
<script src="/highstock.src.js" type="text/javascript"></script>
<script src="/graphs.js" type="text/javascript"></script>
<div id="graph"></div>
+<select id="stock">
+ <option val="">Please select a stock ... </option>
+</select>

0 comments on commit 915ddcd

Please sign in to comment.