Permalink
Browse files

First cut of cleaned TradeSpring::Chart.

  • Loading branch information...
clkao committed Oct 1, 2011
1 parent b1a1982 commit bc8615257981d8103f7e429b04307926d7940769
Showing with 28,751 additions and 0 deletions.
  1. +11 −0 .gitignore
  2. +2 −0 .shipit
  3. +5 −0 Changes
  4. +52 −0 Makefile.PL
  5. +33 −0 README
  6. +19 −0 app.psgi
  7. +100 −0 coffee/tschart-ui.coffee
  8. +382 −0 coffee/tschart-widget.coffee
  9. +649 −0 coffee/tschart.coffee
  10. +194 −0 coffee/tsdraw.coffee
  11. +386 −0 coffee/tsorder.coffee
  12. +16 −0 etc/chart.conf
  13. +561 −0 lib/TradeSpring/Chart.pm
  14. +154 −0 lib/TradeSpring/Chart/Indicator.pm
  15. +24 −0 lib/TradeSpring/Chart/JSFiles.pm
  16. +157 −0 lib/TradeSpring/Chart/Order.pm
  17. +19 −0 lib/TradeSpring/Chart/Session.pm
  18. +86 −0 lib/TradeSpring/Chart/Session/GT.pm
  19. +167 −0 lib/TradeSpring/Chart/Session/PAGM.pm
  20. +223 −0 lib/TradeSpring/Chart/Session/Sim.pm
  21. +65 −0 lib/TradeSpring/Chart/View.pm
  22. +41 −0 lib/TradeSpring/I/External.pm
  23. BIN share/static/images/help.gif
  24. BIN share/static/images/important.gif
  25. BIN share/static/images/info.gif
  26. BIN share/static/images/title.gif
  27. +1,055 −0 share/static/iscroll.js
  28. +8,981 −0 share/static/jquery-1.6.2.js
  29. +57 −0 share/static/jquery.alerts.css
  30. +235 −0 share/static/jquery.alerts.js
  31. +221 −0 share/static/jquery.contextMenu.js
  32. +96 −0 share/static/jquery.cookie.js
  33. +6,554 −0 share/static/jquery.dataTables.js
  34. +78 −0 share/static/jquery.mousewheel.js
  35. +1,961 −0 share/static/jquery.transform.js
  36. +789 −0 share/static/jquery.ui.js
  37. +88 −0 share/static/plugins/raphael.path.methods.js
  38. +99 −0 share/static/plugins/raphael.primitives.js
  39. +3,725 −0 share/static/raphael.js
  40. +270 −0 share/static/screen.css
  41. +651 −0 share/static/timezone.js
  42. +268 −0 share/static/tschart.css
  43. +64 −0 share/templates/base_home.tx
  44. +191 −0 share/templates/base_session.tx
  45. +1 −0 share/templates/home.tx
  46. +1 −0 share/templates/session.tx
  47. +9 −0 t/00-load.t
  48. +11 −0 utils/build.pl
View
@@ -0,0 +1,11 @@
+META.yml
+MYMETA.yml
+Makefile
+inc/
+etc/site_chart.conf
+share/static/gen
+pm_to_blib
+*~
+*.bak
+*.old
+var
View
@@ -0,0 +1,2 @@
+steps = FindVersion, ChangeVersion, CheckChangeLog, DistTest, Commit, Tag, MakeDist, UploadCPAN
+git.push_to = origin
View
@@ -0,0 +1,5 @@
+Revision history for Finance-GeniusTrader-Chart
+
+0.01 Date/time
+ First version, released on an unsuspecting world.
+
View
@@ -0,0 +1,52 @@
+use inc::Module::Install;
+
+name 'TradeSpring-Chart';
+all_from 'lib/TradeSpring/Chart.pm';
+readme_from 'lib/TradeSpring/Chart.pm';
+author q{Chia-liang Kao <clkao@clkao.org>};
+license 'perl';
+
+build_requires 'Test::More';
+
+requires 'Try::Tiny';
+requires 'Plack';
+requires 'Twiggy';
+requires 'Plack::Middleware::JSConcat';
+requires 'Plack::Middleware::Session';
+requires 'Plack::Middleware::Expires';
+requires 'Plack::Middleware::Deflater';
+
+requires 'Text::MicroTemplate::Extended';
+requires 'Set::IntSpan';
+requires 'Web::Hippie';
+requires 'Try::Tiny';
+requires 'JSON';
+requires 'Finance::GeniusTrader::CLI'; # XXX requires my branch
+
+requires 'Plack::Middleware::Session';
+requires 'CHI';
+requires 'CHI::Driver::Memcached';
+requires 'App::Cache';
+
+requires 'Redis::hiredis';
+requires 'Finance::TW::TAIFEX';
+requires 'Cache::Memcached';
+
+requires 'TradeSpring';
+requires 'TradeSpring::Broker';
+
+auto_include_deps;
+author_tests('xt');
+auto_set_repository;
+install_share;
+
+clean_files "share/static/gen/*.js";
+
+WriteAll;
+
+sub MY::postamble {
+ return <<'MAKE_FRAG';
+buildjs:
+ $(PERL) utils/build.pl
+MAKE_FRAG
+}
View
33 README
@@ -0,0 +1,33 @@
+NAME
+ TradeSpring::Chart - raphaeljs-based charting for TradeSpring
+
+SYNOPSIS
+ # to use:
+ # install the TradeSpring branch of Finance::GeniusTrade from
+ # http://github.com/TradeSpring/Finance-Geniustrader
+ # install TradeSpring and TradeSpring::Broker from http://github.com/TradeSpring
+
+ # setup your gt database and configure etc/site_chart.conf (see etc/chart.conf for example)
+
+ % plackup -p 3997
+ # visit http://localhost:3997/
+
+AUTHOR
+ Chia-liang Kao, "<clkao at clkao.org>"
+
+BUGS
+SUPPORT
+ You can find documentation for this module with the perldoc command.
+
+ perldoc TradeSpring::Chart
+
+ACKNOWLEDGEMENTS
+COPYRIGHT & LICENSE
+ Copyright 2009-2011 Chia-liang Kao.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of either: the GNU General Public License as published
+ by the Free Software Foundation; or the Artistic License.
+
+ See http://dev.perl.org/licenses/ for more information.
+
View
@@ -0,0 +1,19 @@
+#!/usr/bin/perl
+package main;
+use strict;
+use warnings;
+
+use Plack::Request;
+use Plack::Session::Store::Cache;
+use TradeSpring::Chart;
+
+my $chart = TradeSpring::Chart->new;
+
+sub js_files { $chart->js_files }
+
+my $app = $chart->default_app;
+
+$app = $chart->wrap_app($app);
+
+$chart->init;
+return $app;
View
@@ -0,0 +1,100 @@
+exports ?= this
+TradeSpring = exports.TradeSpring ?= {}
+day_high = null
+day_low = null;
+
+class TradeSpring.ChartUI
+ @init = (view, d, h) ->
+ startScrolling = (callback) ->
+ return unless scrolling
+ callback()
+ setTimeout (->
+ startScrolling callback
+ ), (if new Date - scrolling < 1000 then 50 else 10)
+ scrolling = false
+ $("#right").mousedown(->
+ scrolling = new Date
+ startScrolling ->
+ view.scroll_right()
+ ).mouseup ->
+ scrolling = false
+
+ $("#left").mousedown(->
+ scrolling = new Date
+ startScrolling ->
+ view.scroll_left()
+ ).mouseup ->
+ scrolling = false
+
+ last_x = undefined
+ last_center = undefined
+ view.chart_view.mousewheel (ev, delta) ->
+ center_item = (if last_x and last_x == ev.clientX then last_center else Math.floor(ev.offsetX / 10 + 0.5))
+ last_x = ev.clientX
+ last_center = center_item
+ if delta > 0
+ view.zoomin center_item
+ else view.zoomout center_item if delta < 0
+ false
+
+ $("#zoomin").click ->
+ view.zoomin()
+
+ $("#zoomout").click ->
+ view.zoomout()
+
+ $("#end").click ->
+ view.init_width()
+ view.on_view_change()
+
+ $('.prev', h).text(d.start_price);
+
+
+ @init_connection_status = (hpipe) ->
+ timer_update = undefined
+ status = $("#connection-status")
+ $(hpipe).bind("connected", ->
+ status.addClass("connected").text "Connected"
+ clearTimeout timer_update if timer_update
+ $("form.chat-action input").removeAttr "disabled"
+ ).bind("disconnected", ->
+ status.removeClass("connected").text "Server disconnected. "
+ $("form.chat-action input").attr "disabled", "disabled"
+ ).bind "reconnecting", (e, data) ->
+ retry = new Date(new Date().getTime() + data.after * 1000)
+ try_now = $("<span/>").text("Try now").click(data.try_now)
+ timer = $("<span/>")
+ do_timer_update = ->
+ timer.text Math.ceil((retry - new Date()) / 1000) + "s. "
+ timer_update = window.setTimeout(do_timer_update, 1000)
+
+ status.text("Server disconnected. retry in ").append(timer).append try_now
+ do_timer_update()
+
+ @init_live_events = (view, hpipe, h) ->
+ $(hpipe).bind("message.tick", (e, d) ->
+ view.on_new_event(d);
+ if h
+ change = d.prices[CLOSE] - parseFloat($('.prev', h).text())
+ $('.datetime', h).text(d.datetime)
+ $('.current', h).text(d.prices[CLOSE])
+ $('.change', h).text((if change >= 0 then '+' else '') + change.toString())
+ $('.volume', h).text(d.cumvol)
+ if d.prices[CLOSE] > parseFloat($('.prev', h).text())
+ $('.current', h).addClass('up').removeClass('down')
+ $('.change', h).addClass('up').removeClass('down')
+ else
+ $('.current', h).removeClass('up').addClass('down')
+ $('.change', h).removeClass('up').addClass('down')
+ if !day_high || d.prices[HIGH] > day_high
+ day_high = d.prices[HIGH]
+ $('.high', h).text(day_high)
+ view.price_label_high.text(day_high).css('top', view.candle_zone.val_to_y(day_high))
+
+ if !day_low || d.prices[LOW] < day_low
+ day_low = d.prices[LOW]
+ $('.low', h).text(day_low);
+ view.price_label_low.text(day_low).css('top', view.candle_zone.val_to_y(day_low))
+ ).bind("message.bar", (e, d) ->
+ view.on_new_event(d)
+ )
Oops, something went wrong.

0 comments on commit bc86152

Please sign in to comment.