From f79580f07cdfb031014abd631bbf6a42e67a76f8 Mon Sep 17 00:00:00 2001 From: Michael Murray Date: Sat, 8 Feb 2014 23:56:11 -0800 Subject: [PATCH 01/13] Added cryptsy and the ability to do trade-percentage in the config file. --- config.js | 21 +-- core/portfolioManager.js | 7 + exchanges.js | 21 +++ exchanges/cryptsy.js | 271 +++++++++++++++++++++++++++++++++++++++ package.json | 1 + 5 files changed, 312 insertions(+), 9 deletions(-) create mode 100644 exchanges/cryptsy.js diff --git a/config.js b/config.js index 30f0e269f..c9280e7cb 100644 --- a/config.js +++ b/config.js @@ -22,9 +22,11 @@ config.debug = false; // for additional logging / debugging // Monitor the live market config.watch = { enabled: true, - exchange: 'Bitstamp', // 'MtGox', 'BTCe', 'Bitstamp', 'cexio' or 'kraken' - currency: 'USD', - asset: 'BTC' + exchange: 'cryptsy', // 'MtGox', 'BTCe', 'Bitstamp', 'cexio', 'cryptsy' or 'kraken' + key: '', + secret: '', + currency: 'BTC', + asset: 'DOGE' } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -42,12 +44,12 @@ config.tradingAdvisor = { config.DEMA = { // EMA weight (α) // the higher the weight, the more smooth (and delayed) the line - short: 10, - long: 21, + short: 11, + long: 31, // amount of candles to remember and base initial EMAs on // the difference between the EMAs (to act as triggers) - sellTreshold: -0.025, - buyTreshold: 0.025 + sellTreshold: -0.35, + buyTreshold: 0.25 }; // MACD settings: @@ -88,7 +90,8 @@ config.PPO = { // Enabling this will activate trades for the market being // watched by config.watch config.trader = { - enabled: false, + enabled: true, + tradePercent: 10, key: '', secret: '', username: '' // your username, only fill in when using bitstamp or cexio @@ -112,7 +115,7 @@ config.profitSimulator = { // only want report after a sell? set to `false`. verbose: false, // how much fee in % does each trade cost? - fee: 0.6, + fee: 0.03, // how much slippage should Gekko assume per trade? slippage: 0.05 } diff --git a/core/portfolioManager.js b/core/portfolioManager.js index d4af4b203..765a44b91 100644 --- a/core/portfolioManager.js +++ b/core/portfolioManager.js @@ -42,6 +42,7 @@ var Manager = function(conf) { }); this.minimalOrder = this.marketConfig.minimalOrder; + this.tradePercent = conf.tradePercent; this.currency = conf.currency; this.asset = conf.asset; } @@ -138,6 +139,9 @@ Manager.prototype.trade = function(what) { else price = this.ticker.ask; + if(this.tradePercent) + amount = amount * this.tradePercent / 100; + this.buy(amount, price); } else if(what === 'SELL') { @@ -153,6 +157,9 @@ Manager.prototype.trade = function(what) { price = false; else price = this.ticker.bid; + + if(this.tradePercent) + amount = amount * this.tradePercent / 100; this.sell(amount, price); } diff --git a/exchanges.js b/exchanges.js index 7158cf259..b7e5ffced 100644 --- a/exchanges.js +++ b/exchanges.js @@ -184,6 +184,27 @@ var exchanges = [ requires: ['key', 'secret', 'username'], providesHistory: false }, + { + name: 'Cryptsy', + slug: 'cryptsy', + direct: false, + infinityOrder: false, + currencies: ['BTC', 'LTC'], + assets: ['DOGE', 'DVC', 'PPC' ], + markets: [ + { + pair: ['BTC', 'DOGE'], market_id: 132, minimalOrder: { amount: 100, unit: 'asset' } + }, + { + pair: ['LTC', 'DOGE'], minimalOrder: { amount: 1, unit: 'asset' } + }, + { + pair: ['BTC', 'DVC'], minimalOrder: { amount: 100, unit: 'asset' } + } + ], + requires: ['key', 'secret'], + providesHistory: false + }, { name: 'Kraken', slug: 'kraken', diff --git a/exchanges/cryptsy.js b/exchanges/cryptsy.js new file mode 100644 index 000000000..0eecf6b36 --- /dev/null +++ b/exchanges/cryptsy.js @@ -0,0 +1,271 @@ +var cryptsy = require("cryptsy-api"); + moment = require('moment'), + async = require('async'), + _ = require('lodash'), + util = require('../core/util'), + log = require('../core/log'); + + +var Trader = function(config) { + this.key = config.key; + this.secret = config.secret; + this.currency = config.currency; + this.asset = config.asset; + this.pair = config.asset.toUpperCase() + config.currency.toUpperCase(); + + if( config.market_id ) + this.market_id = config.market_id; + + this.name = 'Cryptsy'; + + this.cryptsy = new cryptsy( + this.key, + this.secret + ); + + this.market = this.pair; + + + log.debug('Configuring Cryptsy with key', this.key, ', secret', this.secret); + log.debug('Grabbing Cryptsy info for market', this.market, 'with id', this.market_id); + + _.bindAll(this); +} + + +Trader.prototype.return_trades = function(market, callback) { + + var m_id; + var main_trades; + var client = this.cryptsy; + + //log.debug('client is ', client); + client.getmarketid(market, function(market_id) { + //log.debug('id is', market_id); + // Display user's trades in that market + client.markettrades(market_id, function(trades) { + m_id = market_id; + //log.debug("Grabbing trades for id ", market_id); + if(trades.length) { + log.debug("There are ", trades.length, 'trades'); + var full_array = []; + trades.forEach( function(trade) { + // convert to int + trade.amount = Number(trade.quantity); + trade.price = Number(trade.tradeprice); + trade.tid = Number(trade.tradeid); + trade.date = moment(Date.parse(trade.datetime)).subtract('hours', 3).unix(); + full_array.push(trade); + }); + + callback(null, full_array); + } + }); + }); + //this.market_id = m_id; +} + + +Trader.prototype.get_bid_ask = function(market, callback) { + + var m_id; + var main_trades; + var client = this.cryptsy; + + //log.debug('client is ', client); + client.getmarketid(market, function(market_id) { + //log.debug('id is', market_id); + // Display user's trades in that market + client.markettrades(market_id, function(trades) { + //log.debug("Grabbing trades for id ", market_id); + if(trades.length) { + var data_output = { }; + trades = trades.reverse(); + trades.forEach( function(trade) { + // convert to int + if(trade.initiate_ordertype == 'Sell') + data_output.ask = Number(trade.tradeprice); + else + data_output.bid = Number(trade.tradeprice); + data_output.datetime = trade.datetime; + }); + + callback(null, data_output); + } + }); + }); + //this.market_id = m_id; +} + +Trader.prototype.return_mkt_id = function(market, callback) { + + var client = this.cryptsy; + + //log.debug('client is ', client); + client.getmarketid(market, function(market_id) { + callback(null, market_id); + }); + //this.market_id = m_id; +} + + +Trader.prototype.getTrades = function(since, callback, descending) { + var args = _.toArray(arguments); + var mkt_id = this.market; + + var process = function(err, trades) { + //log.debug("Err is ", err, 'and length of trades is', trades); + if(err || !trades || trades.length === 0) + return this.retry(this.getTrades, args, err); + + var f = parseFloat; + + if(descending) + callback(null, trades); + else + callback(null, trades.reverse()); + }; + + this.return_trades(mkt_id, _.bind(process, this)); + +} + + + +Trader.prototype.buy = function(amount, price, callback) { + + var mkt_name = this.market; + + log.debug('BUY', amount, this.asset, ' @', price, this.currency); + this.place_order(mkt_name, 'buy', amount, price, _.bind(callback, this)); +} + + +Trader.prototype.sell = function(amount, price, callback) { + + var mkt_name = this.market; + + log.debug('BUY', amount, this.assset, ' @', price, this.currency); + this.place_order(mkt_name, 'sell', amount, price, _.bind(callback, this)); +} + + +Trader.prototype.place_order = function(market_name, trans_type, amount, price, callback) { + + var client = this.cryptsy; + + log.debug(trans_type, 'order placed for ', amount, this.assset, ' @', price, this.currency); + + //log.debug('client is ', client); + client.getmarketid(market_name, function(market_id) { + //log.debug('id is', market_id); + client.createorder(market_id, trans_type, amount, price, function(orderid) { + callback(null, orderid); + + }); + }); +} + + +Trader.prototype.retry = function(method, args, err) { + var wait = +moment.duration(10, 'seconds'); + log.debug(this.name, 'returned an error in method', method.name, ', retrying..', err, 'waiting for', wait, 'ms'); + + if (!_.isFunction(method)) { + log.error(this.name, 'failed to retry, no method supplied.'); + return; + } + + var self = this; + + // make sure the callback (and any other fn) + // is bound to Trader + _.each(args, function(arg, i) { + if(_.isFunction(arg)) + args[i] = _.bind(arg, self); + }); + + // run the failed method again with the same + // arguments after wait + setTimeout( + function() { method.apply(self, args) }, + wait + ); +} + +Trader.prototype.getPortfolio = function(callback) { + var args = _.toArray(arguments); + var curr = this.currency; + var asst = this.asset; + log.debug('Get Portfolio with asset ', asst, 'and currency ', curr); + var calculate = function(data) { + balances = data.balances_available; + holds = data.balances_hold; + + curr_balance = parseFloat(balances[curr]) + if(parseFloat(holds[curr])){ + curr_balance -= parseFloat(holds[curr]) + } + asst_balance = parseFloat(balances[asst]); + if( parseFloat(holds[asst])){ + asst_balance -= parseFloat(holds[asst]); + } + + var portfolio = []; + portfolio.push({name: curr, amount: curr_balance}); + portfolio.push({name: asst, amount: asst_balance}); + callback(null, portfolio); + } + log.debug('Get Portfolio running getinfo'); + + this.cryptsy.getinfo(_.bind(calculate, this)); +} + +Trader.prototype.getTicker = function(callback) { + + var mkt_name = this.market; + log.debug('Get Ticker'); + var set = function(err, data) { + log.debug('Timestamp is', data.datetime, 'with bid ', data.bid, 'and ask ', data.ask); + var ticker = { + ask: data.ask, + bid: data.bid + }; + callback(err, ticker); + } + this.get_bid_ask(mkt_name, _.bind(set, this)); +} + +Trader.prototype.getFee = function(callback) { + callback(false, 0.03); +} + +Trader.prototype.checkOrder = function(order, callback) { + var check = function(err, result) { + + if(err) + callback(false, true); + + var exists = false; + _.forEach(result, function(entry) { + if(entry.orderid === order) { + exists = true; return; + } + }); + callback(err, !exists); + }; + + this.cryptsy.allmyorders(_.bind(check, this)); +} + +Trader.prototype.cancelOrder = function(order) { + var check= function(err, result) { + if(err) + log.error('cancel order failed:', err); + if(typeof(result) !== 'undefined' && result.error) + log.error('cancel order failed:', result.error); + } + this.cryptsy.cancelorder(order, check); +} + +module.exports = Trader; diff --git a/package.json b/package.json index f96818f5f..52acc1f8d 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ }, "author": "Mike van Rossum ", "dependencies": { + "cryptsy-api": "0.1.x", "mtgox-apiv2": "1.0.x", "lodash": "2.x", "moment": "2.4.x", From 117cde76233aaab3476ac6b8aa109568fabd20e9 Mon Sep 17 00:00:00 2001 From: Michael Murray Date: Sun, 9 Feb 2014 11:40:04 -0800 Subject: [PATCH 02/13] Added the idea of a "total balance" in case we want to modify the amount to equal that --- .gitignore | 3 +++ core/portfolioManager.js | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 410e87b53..49dedbdb7 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,8 @@ *.vi *~ *.sass-cache +gekko-conf* + # OS or Editor folders .DS_Store @@ -38,4 +40,5 @@ dwsync.xml node_modules candles.csv cexio.db +cryptsy.db history diff --git a/core/portfolioManager.js b/core/portfolioManager.js index 765a44b91..69334f40d 100644 --- a/core/portfolioManager.js +++ b/core/portfolioManager.js @@ -123,7 +123,9 @@ Manager.prototype.trade = function(what) { return; var act = function() { - var amount, price; + var amount, price, total_balance; + + total_balance = this.getBalance(this.currency) + this.getBalance(this.asset) * this.ticker.bid; if(what === 'BUY') { From 05cd928a192d643f5cc5942bc91de5d800092776 Mon Sep 17 00:00:00 2001 From: Michael Murray Date: Sun, 9 Feb 2014 14:12:32 -0800 Subject: [PATCH 03/13] Fixed some typos, and fixed the insufficient funds error on selling --- core/portfolioManager.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/portfolioManager.js b/core/portfolioManager.js index 69334f40d..363e8bcfd 100644 --- a/core/portfolioManager.js +++ b/core/portfolioManager.js @@ -192,7 +192,7 @@ Manager.prototype.buy = function(amount, price) { var currency = this.getFund(this.currency); var minimum = this.getMinimum(price); var availabe = this.getBalance(this.currency) / price; - + log.debug('Buying ', amount, 'with ', availabe, 'available, and a minimum of', minimum); // if not suficient funds if(amount > availabe) { return log.info( @@ -204,12 +204,12 @@ Manager.prototype.buy = function(amount, price) { ); } - // if order to small + // if order too small if(amount < minimum) { return log.info( 'wanted to buy', this.asset, - 'but the amount is to small', + 'but the amount is too small', '(' + amount + ')', 'at', this.exchange.name @@ -238,9 +238,9 @@ Manager.prototype.sell = function(amount, price) { var minimum = this.getMinimum(price); var availabe = this.getBalance(this.asset); - + log.debug('Selling ', amount, 'with ', availabe, 'available, and a minimum of', minimum); // if not suficient funds - if(amount < availabe) { + if(amount > availabe) { return log.info( 'wanted to buy but insufficient', this.asset, @@ -250,12 +250,12 @@ Manager.prototype.sell = function(amount, price) { ); } - // if order to small + // if order too small if(amount < minimum) { return log.info( 'wanted to buy', this.currency, - 'but the amount is to small', + 'but the amount is too small', '(' + amount + ')', 'at', this.exchange.name From 465f4790a5016fc799801ee297ce960d1e74feec Mon Sep 17 00:00:00 2001 From: Michael Murray Date: Sun, 9 Feb 2014 14:14:12 -0800 Subject: [PATCH 04/13] Working on cleaning up the cryptsy code More debug statements to try and find out WTF is going on with the parser error that keeps crashing the bot. Also, added a small hack to make Cryptsy orders complete more effectively. --- exchanges/cryptsy.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/exchanges/cryptsy.js b/exchanges/cryptsy.js index 0eecf6b36..6e61ecde9 100644 --- a/exchanges/cryptsy.js +++ b/exchanges/cryptsy.js @@ -51,10 +51,14 @@ Trader.prototype.return_trades = function(market, callback) { var full_array = []; trades.forEach( function(trade) { // convert to int + log.debug("Parsing trade id", trade.tradeid); trade.amount = Number(trade.quantity); trade.price = Number(trade.tradeprice); trade.tid = Number(trade.tradeid); + log.debug("Parsing date for trade ", trade.tradeid); + // ISSUE: this assumes that the local machine is in PDT trade.date = moment(Date.parse(trade.datetime)).subtract('hours', 3).unix(); + log.debug("Pushing trade in to array for", trade.tradeid); full_array.push(trade); }); @@ -83,10 +87,13 @@ Trader.prototype.get_bid_ask = function(market, callback) { trades = trades.reverse(); trades.forEach( function(trade) { // convert to int - if(trade.initiate_ordertype == 'Sell') + if(trade.initiate_ordertype.toLowerCase() == 'sell') { + log.debug("Sell with initiate_ordertype", trade.initiate_ordertype, 'so using the price as the ask'); data_output.ask = Number(trade.tradeprice); - else + } else { + log.debug("Buy with initiate_ordertype", trade.initiate_ordertype, 'so using the price as the bid'); data_output.bid = Number(trade.tradeprice); + } data_output.datetime = trade.datetime; }); @@ -135,6 +142,9 @@ Trader.prototype.getTrades = function(since, callback, descending) { Trader.prototype.buy = function(amount, price, callback) { var mkt_name = this.market; + // [MM]: Something about cryptsy's orders seems to be behind the actual market, which causes orders to go unfilled. + // Make the amount slightly on the upside of the actual price. + price = price * 1.003; log.debug('BUY', amount, this.asset, ' @', price, this.currency); this.place_order(mkt_name, 'buy', amount, price, _.bind(callback, this)); @@ -144,8 +154,11 @@ Trader.prototype.buy = function(amount, price, callback) { Trader.prototype.sell = function(amount, price, callback) { var mkt_name = this.market; + // [MM]: Something about cryptsy's orders seems to be behind the actual market, which causes orders to go unfilled. + // Make the amount slightly on the downside of the actual price. + price = price * 0.997; - log.debug('BUY', amount, this.assset, ' @', price, this.currency); + log.debug('SELL', amount, this.asset, ' @', price, this.currency); this.place_order(mkt_name, 'sell', amount, price, _.bind(callback, this)); } @@ -154,7 +167,7 @@ Trader.prototype.place_order = function(market_name, trans_type, amount, price, var client = this.cryptsy; - log.debug(trans_type, 'order placed for ', amount, this.assset, ' @', price, this.currency); + //log.debug(trans_type, 'order placed for ', amount, this.asset, ' @', price, this.currency); //log.debug('client is ', client); client.getmarketid(market_name, function(market_id) { From 7a8912a9898bb39d4b036cd814a52f38298c2ba3 Mon Sep 17 00:00:00 2001 From: Michael Murray Date: Sun, 9 Feb 2014 17:49:27 -0800 Subject: [PATCH 05/13] Added an extra line so we know what min and max are --- core/candleManager.js | 1 + 1 file changed, 1 insertion(+) diff --git a/core/candleManager.js b/core/candleManager.js index 1687fb96a..366829c56 100644 --- a/core/candleManager.js +++ b/core/candleManager.js @@ -793,6 +793,7 @@ Manager.prototype.addEmtpyCandles = function(candles, start, end) { if(min > max) { console.log('c', candles, 's', start, 'e', end); + console.log('min', min, 'max', max); throw 'Weird error 2'; } From 58bd7cb98c3f5fcd1b22910dc61ace721e6c52a5 Mon Sep 17 00:00:00 2001 From: Michael Murray Date: Sun, 9 Feb 2014 17:50:59 -0800 Subject: [PATCH 06/13] Fixed Bid / Ask being backwards, and added in a bit more error handling --- exchanges/cryptsy.js | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/exchanges/cryptsy.js b/exchanges/cryptsy.js index 6e61ecde9..e0ab76884 100644 --- a/exchanges/cryptsy.js +++ b/exchanges/cryptsy.js @@ -48,17 +48,15 @@ Trader.prototype.return_trades = function(market, callback) { //log.debug("Grabbing trades for id ", market_id); if(trades.length) { log.debug("There are ", trades.length, 'trades'); - var full_array = []; + var full_array = []; + //trades = trades.reverse(); trades.forEach( function(trade) { // convert to int - log.debug("Parsing trade id", trade.tradeid); trade.amount = Number(trade.quantity); trade.price = Number(trade.tradeprice); trade.tid = Number(trade.tradeid); - log.debug("Parsing date for trade ", trade.tradeid); // ISSUE: this assumes that the local machine is in PDT trade.date = moment(Date.parse(trade.datetime)).subtract('hours', 3).unix(); - log.debug("Pushing trade in to array for", trade.tradeid); full_array.push(trade); }); @@ -88,11 +86,11 @@ Trader.prototype.get_bid_ask = function(market, callback) { trades.forEach( function(trade) { // convert to int if(trade.initiate_ordertype.toLowerCase() == 'sell') { - log.debug("Sell with initiate_ordertype", trade.initiate_ordertype, 'so using the price as the ask'); - data_output.ask = Number(trade.tradeprice); - } else { - log.debug("Buy with initiate_ordertype", trade.initiate_ordertype, 'so using the price as the bid'); + //log.debug("Sell with initiate_ordertype", trade.initiate_ordertype, 'so using the price as the ask'); data_output.bid = Number(trade.tradeprice); + } else { + //log.debug("Buy with initiate_ordertype", trade.initiate_ordertype, 'so using the price as the bid'); + data_output.ask = Number(trade.tradeprice); } data_output.datetime = trade.datetime; }); @@ -208,28 +206,34 @@ Trader.prototype.retry = function(method, args, err) { Trader.prototype.getPortfolio = function(callback) { var args = _.toArray(arguments); + var curr_balance, asst_balance; var curr = this.currency; var asst = this.asset; log.debug('Get Portfolio with asset ', asst, 'and currency ', curr); var calculate = function(data) { + if(!data) + return this.retry(this.getPortfolio, args, null); balances = data.balances_available; holds = data.balances_hold; curr_balance = parseFloat(balances[curr]) - if(parseFloat(holds[curr])){ - curr_balance -= parseFloat(holds[curr]) - } asst_balance = parseFloat(balances[asst]); - if( parseFloat(holds[asst])){ - asst_balance -= parseFloat(holds[asst]); - } + if(holds) { + if(parseFloat(holds[curr])){ + curr_balance -= parseFloat(holds[curr]) + } + + if( parseFloat(holds[asst])){ + asst_balance -= parseFloat(holds[asst]); + } + } + var portfolio = []; portfolio.push({name: curr, amount: curr_balance}); portfolio.push({name: asst, amount: asst_balance}); callback(null, portfolio); } - log.debug('Get Portfolio running getinfo'); this.cryptsy.getinfo(_.bind(calculate, this)); } From b70a951f189006623cf8a74df179bb42bf8e2bef Mon Sep 17 00:00:00 2001 From: Michael Murray Date: Sun, 9 Feb 2014 20:57:30 -0800 Subject: [PATCH 07/13] Fixed that stupid hack by making everything refer back to UTC --- exchanges/cryptsy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exchanges/cryptsy.js b/exchanges/cryptsy.js index e0ab76884..0a7604b08 100644 --- a/exchanges/cryptsy.js +++ b/exchanges/cryptsy.js @@ -56,7 +56,7 @@ Trader.prototype.return_trades = function(market, callback) { trade.price = Number(trade.tradeprice); trade.tid = Number(trade.tradeid); // ISSUE: this assumes that the local machine is in PDT - trade.date = moment(Date.parse(trade.datetime)).subtract('hours', 3).unix(); + trade.date = moment(Date.parse(trade.datetime)).utc().unix(); full_array.push(trade); }); From 795ad54654b81c66d31f2fccf9c712610f85d22f Mon Sep 17 00:00:00 2001 From: Michael Murray Date: Mon, 10 Feb 2014 10:10:02 -0800 Subject: [PATCH 08/13] Figure out why my CEX.io isn't respecting TradePercent --- core/portfolioManager.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/portfolioManager.js b/core/portfolioManager.js index 363e8bcfd..25579cd39 100644 --- a/core/portfolioManager.js +++ b/core/portfolioManager.js @@ -141,8 +141,10 @@ Manager.prototype.trade = function(what) { else price = this.ticker.ask; - if(this.tradePercent) + if(this.tradePercent) { + log.debug('Trade Percent: adjusting amount', amount, 'by ', this.tradePercent, '%'); amount = amount * this.tradePercent / 100; + } this.buy(amount, price); @@ -160,8 +162,10 @@ Manager.prototype.trade = function(what) { else price = this.ticker.bid; - if(this.tradePercent) + if(this.tradePercent) { + log.debug('Trade Percent: adjusting amount', amount, 'by ', this.tradePercent, '%'); amount = amount * this.tradePercent / 100; + } this.sell(amount, price); } From 9f2da0eff02ed0a2da1ac0fd461279bc760876f5 Mon Sep 17 00:00:00 2001 From: Michael Murray Date: Mon, 10 Feb 2014 16:00:05 -0800 Subject: [PATCH 09/13] A couple of log cleanups --- exchanges/cryptsy.js | 3 +-- plugins/trader.js | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/exchanges/cryptsy.js b/exchanges/cryptsy.js index 0a7604b08..7ca66df94 100644 --- a/exchanges/cryptsy.js +++ b/exchanges/cryptsy.js @@ -209,7 +209,7 @@ Trader.prototype.getPortfolio = function(callback) { var curr_balance, asst_balance; var curr = this.currency; var asst = this.asset; - log.debug('Get Portfolio with asset ', asst, 'and currency ', curr); + var calculate = function(data) { if(!data) return this.retry(this.getPortfolio, args, null); @@ -241,7 +241,6 @@ Trader.prototype.getPortfolio = function(callback) { Trader.prototype.getTicker = function(callback) { var mkt_name = this.market; - log.debug('Get Ticker'); var set = function(err, data) { log.debug('Timestamp is', data.datetime, 'with bid ', data.bid, 'and ask ', data.ask); var ticker = { diff --git a/plugins/trader.js b/plugins/trader.js index 9d9f35e84..c8ebcc4d1 100644 --- a/plugins/trader.js +++ b/plugins/trader.js @@ -16,14 +16,14 @@ Trader.prototype.processAdvice = function(advice) { log.info( 'Trader', 'Received advice to go long', - 'Buying ', config.trader.asset + 'Buying', config.trader.asset ); } else if(advice.recommandation == 'short') { this.manager.trade('SELL'); log.info( 'Trader', 'Received advice to go short', - 'Selling ', config.trader.asset + 'Selling', config.trader.asset ); } } From 4e934547cb6ca5954494138d81ff19fc5f0ae85d Mon Sep 17 00:00:00 2001 From: Michael Murray Date: Mon, 10 Feb 2014 16:00:19 -0800 Subject: [PATCH 10/13] Added logging so I can create the "null" trend fix --- methods/DEMA.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/methods/DEMA.js b/methods/DEMA.js index c757d4ff9..f396433e6 100644 --- a/methods/DEMA.js +++ b/methods/DEMA.js @@ -50,7 +50,8 @@ TradingMethod.prototype.calculateAdvice = function() { var price = this.lastPrice; var message = '@ ' + price.toFixed(8) + ' (' + diff.toFixed(5) + ')'; - + log.debug('We are currently in the trend ', this.currentTrend); + if(diff > settings.buyTreshold) { log.debug('we are currently in uptrend', message); From 567e9f2468b87ee2a9ef43f4fa3d779c5d446bd5 Mon Sep 17 00:00:00 2001 From: Michael Murray Date: Mon, 10 Feb 2014 17:10:49 -0800 Subject: [PATCH 11/13] Removed some extra debug statements --- exchanges/cryptsy.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/exchanges/cryptsy.js b/exchanges/cryptsy.js index 7ca66df94..7d5c51830 100644 --- a/exchanges/cryptsy.js +++ b/exchanges/cryptsy.js @@ -25,10 +25,6 @@ var Trader = function(config) { this.market = this.pair; - - log.debug('Configuring Cryptsy with key', this.key, ', secret', this.secret); - log.debug('Grabbing Cryptsy info for market', this.market, 'with id', this.market_id); - _.bindAll(this); } @@ -47,7 +43,7 @@ Trader.prototype.return_trades = function(market, callback) { m_id = market_id; //log.debug("Grabbing trades for id ", market_id); if(trades.length) { - log.debug("There are ", trades.length, 'trades'); + //log.debug("There are ", trades.length, 'trades'); var full_array = []; //trades = trades.reverse(); trades.forEach( function(trade) { From 4d984a89afac002f056576aba9ce12e8c7a08ec2 Mon Sep 17 00:00:00 2001 From: Michael Murray Date: Mon, 10 Feb 2014 17:11:06 -0800 Subject: [PATCH 12/13] Fixed that every time we start the software it trades a position because DEMA is undefined --- methods/DEMA.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/methods/DEMA.js b/methods/DEMA.js index f396433e6..211beb8ee 100644 --- a/methods/DEMA.js +++ b/methods/DEMA.js @@ -51,8 +51,16 @@ TradingMethod.prototype.calculateAdvice = function() { var message = '@ ' + price.toFixed(8) + ' (' + diff.toFixed(5) + ')'; log.debug('We are currently in the trend ', this.currentTrend); - - if(diff > settings.buyTreshold) { + + if (this.currentTrend == undefined ) { + // We just started the program and we don't have a trend, so set it and wait until next time. + if (diff > settings.buyTreshold) + this.currentTrend = 'up'; + else + this.currentTrend = 'down'; + this.advice(); + + } else if(diff > settings.buyTreshold) { log.debug('we are currently in uptrend', message); if(this.currentTrend !== 'up') { From 322885892230d586e7f4e9e19efb20027dcabea4 Mon Sep 17 00:00:00 2001 From: Michael Murray Date: Mon, 10 Feb 2014 20:11:48 -0800 Subject: [PATCH 13/13] Removed the debugging message I put in to fix DEMA on startup --- methods/DEMA.js | 1 - 1 file changed, 1 deletion(-) diff --git a/methods/DEMA.js b/methods/DEMA.js index 211beb8ee..b26db1442 100644 --- a/methods/DEMA.js +++ b/methods/DEMA.js @@ -50,7 +50,6 @@ TradingMethod.prototype.calculateAdvice = function() { var price = this.lastPrice; var message = '@ ' + price.toFixed(8) + ' (' + diff.toFixed(5) + ')'; - log.debug('We are currently in the trend ', this.currentTrend); if (this.currentTrend == undefined ) { // We just started the program and we don't have a trend, so set it and wait until next time.