benjamin
bitcoin trading for the rest of us
getting started
installation
Install the module with: npm install benjamin
dependencies
database
Benjamin uses the sequelize.js ORM as its backing db. You can use with sqlite, mysql, or postgres.
You will need to install your specific database client in addition to benjamin. (e.g. postgres needs pg
, sqlite needs sqlite3
)
API credentials
You will need the following to get started:
- api key for desired btc market (currently only mtgox is supported)
- at least one trading strategy (see below)
creating benjamin
var Benjamin = require('benjamin');
var benjamin = new Benjamin({
api_key: 'MY API KEY',
api_secret: 'MY API SECRET'
});
details
initialization
benjamin can be initialized with the following options
var options = {
market: 'mtgox',
currency: 'USD',
client: {
api_key: 'MY API KEY',
api_secret: 'MY API SECRET'
},
database: {
dialect: 'sqlite',
database: 'database-name',
username: 'username',
password: 'password',
options: {}
}
};
var benjamin = new Benjamin(options);
simulation
You can do dry-runs of trading strategies to see how this would all play out
benjamin.use(require('experimental-trading-strategy'));
benjamin.simulate();
and start from a custom time in the past
var start = moment([2012, 1, 1]).format('X');
benjamin.simulate({
start: start
});
or a custom interval:
var start = moment([2012, 1, 1]).format('X');
var end = moment([2012, 12, 1]).format('X');
benjamin.simulate({
start: start,
end: end
});
trading
running live trades is just as easy
benjamin.use(require('benjamin-buy-low-sell-high'));
var options = {
};
benjamin.start(options);
analytics
Benjamin can also be used as an analytics tool. Since he automatically deals with keeping the
trades database in sync for you, you can write analytics strategies.
Just write you analysis code in the form of a strategy (as shown below), and callback with a suggested
trade amount of 0
.
static trades
benjamin also exposes a common client interface (although only mtgox is currently supported).
this allows you to invoke trade commands directly:
WARNING THESE COMMANDS WILL TRANSFER YOUR BTCs
benjamin.sell(10, function(err, json) {
if(err) {
}
});
benjamin.buy(10, function(err, json) {
if(err) {
}
});
benjamin.send('BITCOIN WALLET ADDRESS', 10, function(err, json) {
if(err) {
}
});
trading strategies
strategies just need to implement three methods in order to work with benjamin.
module.exports = (function() {
Strategy = {
initialize: function() {
},
tick: function(Trades, currentSuggestion, callback) {
},
shouldExit: function() {
}
};
return Strategy;
})();
notes
THERE IS NO WARRANTY
this is young software and it will play around with your money. i take no responsibility for anything that happens. please use common sense, review all source code and
make use of the simulation service before making real trades.
TODO
- Currently all of the timestamps in Benjamin are UNIX-timestamps, which aren't very cool or nice to work with. The reason is that the bitcoin charts API operates using unix timestamps
and this way we don't have to do a ton of conversion. I would like to hide this from the user at some point and allow more conventional time formats as input.
license
The MIT License (MIT)
Copyright (c) 2013 Matthew Conlen
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.