Permalink
Browse files

initial project structure, and some unstable code

  • Loading branch information...
0 parents commit 1ec2c0dca27fdac772fb70e529e56940c852889e @webholics committed Jan 7, 2013
@@ -0,0 +1,28 @@
+/node_modules
+
+# OSX
+.DS_Store
+._*
+.Spotlight-V100
+.Trashes
+
+# vim
+.*.sw[a-z]
+*.un~
+Session.vim
+
+# SublimeText project files
+/*.sublime-project
+*.sublime-workspace
+/sftp-config.json
+
+# others
+.project
+*.tmp
+*~
+*.bak
+local.properties
+.settings
+.classpath
+.loadpath
+
@@ -0,0 +1 @@
+.git*
22 LICENSE
@@ -0,0 +1,22 @@
+(The MIT License)
+
+Copyright (c) 2013 Mario Volke
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,130 @@
+#!/usr/bin/env node
+
+(function() {
+ var ProgressBar, Table, program, trader;
+
+ trader = require('../lib/trader.js');
+
+ ProgressBar = require('progress');
+
+ Table = require('easy-table');
+
+ program = require('commander');
+
+ program.version('0.0.1').option('-p, --progress', 'show a progress bar if possible (do not use progress if you want to pipe the output)').option('-e, --endpoint <endpoint>', 'endpoint to fetch data from [finanzennet]', String, 'finanzennet').option('-o, --output <format>', 'choose output format [table]', String, 'table');
+
+ program.command('indices').description('list available stock indices').action(function() {
+ var endpoint;
+ endpoint = trader.loadEndpoint(program.endpoint);
+ return endpoint.getIndices(function(err, indices) {
+ var table,
+ _this = this;
+ if (err) {
+ process.stderr.write(err.message);
+ process.exit(1);
+ }
+ table = new Table;
+ indices.forEach(function(row) {
+ table.cell('id', row.id);
+ table.cell('name', row.name);
+ return table.newRow();
+ });
+ process.stdout.write(table.print(indices));
+ return process.exit(0);
+ });
+ });
+
+ program.command('search <terms>').description('search one or multiple equities separated by comma (only the first result for each search term is returned)').action(function(terms) {
+ var bar, cbCounter, endpoint, i, makeCb, output, results, term, _i, _len, _results;
+ terms = terms.split(/\s*,\s*/);
+ endpoint = trader.loadEndpoint(program.endpoint);
+ output = trader.loadOutputFormatter(program.output);
+ bar = null;
+ if (program.progress && terms.length > 0) {
+ bar = new ProgressBar('[:bar] :percent', {
+ total: terms.length,
+ width: 20,
+ complete: '=',
+ incomplete: ' '
+ });
+ bar.tick(0);
+ }
+ results = [];
+ cbCounter = 0;
+ makeCb = function(i) {
+ return function(err, equity) {
+ var cleanResults, result, _i, _len;
+ if (err) {
+ process.stderr.write(err.message + '\n');
+ process.exit(1);
+ }
+ results[i] = equity;
+ cbCounter++;
+ if (bar) {
+ bar.tick();
+ }
+ if (cbCounter === terms.length) {
+ if (bar) {
+ process.stdout.write('\n');
+ }
+ cleanResults = [];
+ for (_i = 0, _len = results.length; _i < _len; _i++) {
+ result = results[_i];
+ if (result) {
+ cleanResults.push(result);
+ }
+ }
+ if (cleanResults.length === 0) {
+ process.stderr.write("No results found.");
+ }
+ process.stdout.write(output.equitiesToString(cleanResults));
+ return process.exit(0);
+ }
+ };
+ };
+ _results = [];
+ for (i = _i = 0, _len = terms.length; _i < _len; i = ++_i) {
+ term = terms[i];
+ _results.push(endpoint.searchEquity(term, makeCb(i)));
+ }
+ return _results;
+ });
+
+ program.command('index <index>').description('get all equities by index (one of the indices returned by `trader indices`)').action(function(index) {
+ var bar, cb, endpoint, lastProgress, output, tick;
+ endpoint = trader.loadEndpoint(program.endpoint);
+ output = trader.loadOutputFormatter(program.output);
+ tick = null;
+ if (program.progress) {
+ bar = null;
+ lastProgress = 0;
+ tick = function(progress, total) {
+ if (!bar) {
+ bar = new ProgressBar('[:bar] :percent', {
+ total: total,
+ width: 20,
+ complete: '=',
+ incomplete: ' '
+ });
+ }
+ bar.tick(progress - lastProgress);
+ return lastProgress = progress;
+ };
+ }
+ cb = function(err, equities) {
+ if (tick) {
+ process.stdout.write('\n');
+ }
+ if (err) {
+ process.stderr.write(err.message + '\n');
+ process.exit(1);
+ }
+ process.stdout.write(output.equitiesToString(equities));
+ return process.exit(0);
+ };
+ return endpoint.getEquitiesByIndex(index, cb, tick);
+ });
+
+ program.parse(process.argv);
+
+}).call(this);
@@ -0,0 +1,40 @@
+/*global module:false*/
+
+'use strict';
+
+module.exports = function(grunt) {
+ grunt.initConfig({
+ meta: {
+ shebang: "#!/usr/bin/env node"
+ },
+ coffee: {
+ module: {
+ src: ['src/**/*.coffee'],
+ dest: '.',
+ options: {
+ bare: false,
+ preserve_dirs: true,
+ base_path: 'src'
+ }
+ }
+ },
+ concat: {
+ bin: {
+ src: ['<banner:meta.shebang>', 'bin/cli.js'],
+ dest: 'bin/cli.js'
+ }
+ },
+ clean: {
+ js: ['bin/*', 'lib/*']
+ },
+ watch: {
+ files: ['src/**/*.coffee'],
+ tasks: 'default'
+ }
+ });
+
+ grunt.loadNpmTasks('grunt-coffee');
+ grunt.loadNpmTasks('grunt-contrib-clean');
+
+ grunt.registerTask('default', 'coffee concat');
+};
@@ -0,0 +1 @@
+module.exports = require("./lib/trader");
@@ -0,0 +1,93 @@
+
+/*
+ Abstract data endpoint to fetch equity Data
+
+ Equity:
+ ---------
+ An equity object must contain the following attributes:
+ {
+ isin: The ISIN unique equity id
+ name: The name of the equity
+ }
+
+ The following attributes are optional:
+ {
+ wkn: The WKN unique equity id
+ }
+
+ Index:
+ --------
+ An index object must contain the following attributes:
+ {
+ id: Some id for the index.
+ name: The name of the index.
+ currentPrice: The current price (as realtime as possible)
+ monthlyPrices: [...] Array of monthly prices of the first day in each month of the last 12 months starting with the price at the beginning of the current month.
+ dailyPrices: [...] Array of daily prices at the beginning of each day in the last 30 trading(!) days starting with the price of today.
+ }
+ An endpoint may deliver more attributes.
+*/
+
+
+(function() {
+ var Endpoint;
+
+ Endpoint = (function() {
+
+ function Endpoint() {}
+
+ /*
+ Retrieve a single index by some search.
+ This method always returns only one result. The one that fits the search term best.
+ */
+
+
+ Endpoint.prototype.searchIndex = function(name, cb) {
+ cb(null, null);
+ return this;
+ };
+
+ /*
+ Retrieve a single equity by ISIN
+ */
+
+
+ Endpoint.prototype.getEquityByIsin = function(isin, cb) {
+ cb(null, null);
+ return this;
+ };
+
+ /*
+ Retrieve a single equity by some search.
+ This method always returns only one result. The one that fits the search term best.
+ */
+
+
+ Endpoint.prototype.searchEquity = function(name, cb) {
+ cb(null, null);
+ return this;
+ };
+
+ /*
+ Retrieve all equities of an index
+
+ Index is searched via searchIndex()!
+
+ tick is an optional function which is called with two arguments (progress and total).
+ Both arguments are integers. Total gives the total steps until getEquitiesByIndex finishes,
+ whereas progress gives the number of steps already finished. The tick callback is useful to generate a progress bar.
+ */
+
+
+ Endpoint.prototype.getEquitiesByIndex = function(index, cb, tick) {
+ cb(null, []);
+ return this;
+ };
+
+ return Endpoint;
+
+ })();
+
+ module.exports = Endpoint;
+
+}).call(this);
Oops, something went wrong.

0 comments on commit 1ec2c0d

Please sign in to comment.