• Stars
    star
    134
  • Rank 270,967 (Top 6 %)
  • Language
    JavaScript
  • Created almost 11 years ago
  • Updated almost 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

bitcoin trading bot and analytics platform

benjamin

bitcoin trading bot and analytics platform.

Benjamin is designed to be an easy to use bitcoin trading bot that does all of the tedious work for you. Benjamin does all of the tedious work, you just write a plug-and-play strategy for how to trade.

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({
    client: {
        api_key: 'MY API KEY',
        api_secret: 'MY API SECRET'
    }
});

details

initialization

benjamin can be initialized with the following options

var options = {
    market: 'mtgox', // market name according ot http://api.bitcoincharts.com/v1/markets.json
    currency: 'USD',
    client: {
        api_key: 'MY API KEY',
        api_secret: 'MY API SECRET'
    },
    database: { // sequelize.js options
        dialect: 'sqlite', // sqlite, postgres, or mysql
        database: 'database-name',
        username: 'username',
        password: 'password',
        options: {} // other sequelize options: http://sequelizejs.com/docs/latest/usage#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(); // benjamin prints out trades to console

and start from a custom time in the past

var start = moment([2012, 1, 1]).format('X'); 
benjamin.simulate({
    start: start // UNIX-timestamp
});

or a custom interval:

var start = moment([2012, 1, 1]).format('X');
var end = moment([2012, 12, 1]).format('X');
benjamin.simulate({
    start: start, // UNIX-timestamps
    end: end
});

trading

running live trades is just as easy

benjamin.use(require('benjamin-buy-low-sell-high')); // provide at least one strategy


var options = {
    interval: 15 * 60 // in seconds, defaults to 15 minutes
                      // the interval option defines approximately
                      // how often benjamin will poll strategies
                      // for their suggested trades and then 
                      // subsequently execute the trades.
};

// BE CAREFUL THIS WILL MAKE TRADES
benjamin.start(options); // and we're off!

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

// try to sell 10 BTC
benjamin.sell(10, function(err, json) {
    if(err) {
        // something went wrong
    }
});
// try to buy 10 BTC
benjamin.buy(10, function(err, json) {
    if(err) {
        // something went wrong
    }
});
// try to send 10 BTC to a certain address
benjamin.send('BITCOIN WALLET ADDRESS', 10, function(err, json) {
    if(err) {
        // something went wrong
    }
});

trading strategies

strategies just need to implement three methods in order to work with benjamin.

module.exports = (function() {
    
    Strategy = {

        initialize: function() {
            // do whatever you need to do prepare for trading
        },

        tick: function(Trades, currentSuggestion, callback) {
            // return suggested action
            // in bitcoins
            //
            // if you are using multiple strategies,
            // these functions get chained together,
            // so it is possible to have one strategy
            // influence another.
            //
            // once all strategies give their recommendation
            // benjamin carries out the cumulative recommended 
            // action
            //
            // e.g. 
            //      callback(10); // recommend to buy 10 bitcoins
            //      callback(-10); // recommend to sell 10 bitcoins
            //
            // Trades is a sequelize model object, so you can 
            // access whatever trades you want by doing something
            // like
            //
            // Trades
            //   .findAll({
            //      where: ['timestamp > ?', timestamp]
            //   }).success(function(trades) {
            //      // trades is now all of the btc trades
            //      // that occurred since timestamp
            //      // 
            //      // each trade has timestamp, price and amount
            //      // of bitcoin traded
            //   });
            //
            // benjamin automatically fetches and keeps the 
            // trades up-to-date with the most recent market data
        },

        shouldExit: function() {
            //
            // failsafe for benjamin to quit trading under certain circumstances
            //
            // e.g. 
            //      return false;
        }

    };

    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.

More Repositories

1

premonish

Predict which DOM element a user will interact with next.
JavaScript
1,696
star
2

awesome-visualization-research

A list of recommended research papers and other readings on data visualization
920
star
3

command-exists

node module to check if a command-line command exists
JavaScript
144
star
4

d3moji

First class emoji support for D3
127
star
5

martinet

Distributed job queue for node
JavaScript
120
star
6

kde

Idyll example post about kernel density
JavaScript
97
star
7

requirify

require() npm modules in the browser console
JavaScript
94
star
8

hyperchart

charts for hyperterm
JavaScript
78
star
9

svg-path-generator

generate svg paths without memorizing the svg path spec / shortcodes http://www.w3.org/TR/SVG/paths.html
JavaScript
55
star
10

simple-testing-server

A stupidly simple python server that allows you to test client code before you have a server that actually works
Python
55
star
11

sketch-interactive-export

Plugin to make it easy to use JavaScript to add interactivity to SVGs exported from sketch.
JavaScript
54
star
12

scrolly-gif

Animate a gif as the user scrolls the page
JavaScript
45
star
13

gulp-sass-bulk-import

gulp task to allow importing directories in your SCSS
JavaScript
42
star
14

regl-tween

Automatic in-shader interpolation for regl buffers
JavaScript
31
star
15

swaggerize

Generates swagger model definitions from a sequelize.js object
JavaScript
31
star
16

dimensionality-reduction

An idyll post all about dimensionality reduction.
Jupyter Notebook
28
star
17

boscillate

live sound wave graph for baudio in your terminal
JavaScript
24
star
18

svg-filter

Tool for working with svg filters
JavaScript
24
star
19

hyperterm-window

Window component for hyperterm
JavaScript
24
star
20

react-editable-svg-label

A text element for SVG that you can edit.
JavaScript
21
star
21

react-regl

[Work in Progress, don't use this] React bindings to regl
JavaScript
17
star
22

curve-store

Redux-inspired store for dealing with continuous values
JavaScript
17
star
23

trig

interactive documents related to trigonometry
JavaScript
16
star
24

gulp-sri

Generate SRI hashes in gulp
JavaScript
15
star
25

d3-multiaxis-zoom

d3 plugin to zoom along multiple axes independently
JavaScript
15
star
26

sunrise

visualization of sunrise / sunset times over the course of a year
CSS
15
star
27

idyll

Shared repository for personal idyll posts
JavaScript
14
star
28

onsite

realtime news + twitter + location + filters = automated, reliable firsthand accounts of news as it happens
CSS
13
star
29

python-yelp-v2

A Python wrapper for the Yelp API v2
Python
12
star
30

autopages

Automated compilation and deployment to github pages
JavaScript
11
star
31

browser-man-switch

A Dead Man's Switch to clear your browser history on OSX
Python
9
star
32

three-first-person-controls

Three.js first person controls, adapted from https://github.com/mrdoob/three.js/blob/master/examples/js/controls/FirstPersonControls.js
JavaScript
9
star
33

music-vis

webgl based music visualization
JavaScript
9
star
34

diy-data-fugazi

Idyll post on fugazi
JavaScript
7
star
35

TouchOSC-Web

Use TouchOSC to enable iPhones and Androids as controllers for the web.
JavaScript
6
star
36

dbify

Browserify transform to inline the results of SQL queries
JavaScript
6
star
37

construction

2d and 3d webgl shape primitives
JavaScript
6
star
38

dashcam

Jupyter Notebook
5
star
39

state-bar

d3 experiment
CSS
5
star
40

three-fly-controls

Three.js fly controls, adapted from http://threejs.org/examples/js/controls/FlyControls.js
JavaScript
5
star
41

lorenz

lorenz attractor with regl + idyll
CSS
4
star
42

idyll-book

See https://github.com/idyll-lang/idyll-multipage-example
HTML
4
star
43

gopen

Open the current git repo in your browser
JavaScript
4
star
44

TouchOSC-Mouse

Control your mouse with your iPhone or Android via TouchOSC
Java
4
star
45

how-to-tune-a-guitar

Source code for the "How to: Tune a Guitar" Idyll article
JavaScript
4
star
46

eecs442-finalproject

MATLAB
4
star
47

auto-scroller

Idyll example of stepped scrolling component
JavaScript
3
star
48

datasets-cats

A dataset of cats. Contains info on sex (M/F), body weight (kg), and heart weight (g) for 144 cats.
JavaScript
3
star
49

gulp-transform

A gulp plugin for transforming data, e.g. CSV to JSON, TSV to CSV, etc. (WORK IN PROGRESS)
JavaScript
3
star
50

mathisonian.github.io

My website
JavaScript
3
star
51

processingPhotobooth

A photobooth app for processing, using the kinect
Java
3
star
52

strata-singapore

repo for use during workshop at strata singapore http://conferences.oreilly.com/strata/big-data-conference-sg-2015/public/schedule/detail/45383
3
star
53

covid-19-rate-of-change

Visualizing rate of change of COVID-19 cases in the US.
JavaScript
2
star
54

idyll-interactive-slideshow

JavaScript
2
star
55

gif_space

gif based aesthetic project in node.js
JavaScript
2
star
56

gender-bender

chrome extension to randomly swap gendered pronouns
JavaScript
2
star
57

who-shapes-the-open-web

Analysis of W3C membership
JavaScript
2
star
58

sublime-settings

A git repo for SublimeText user and package settings
2
star
59

observable-idyll

Bindings to Observable notebooks from Idyll - WIP
JavaScript
2
star
60

idyll-comic

Comic example w/ CSS grid + Idyll
JavaScript
2
star
61

hand-drawn-interactive-studies

Place to put experiments with drawing + graphics.
HTML
2
star
62

idyll-vega-lite-test

Test case for idyll/vega-lite interop
JavaScript
2
star
63

idyll-tutorial-triggering-updates

How to achieve interactivity in Idyll by updating properties in response to user input.
JavaScript
1
star
64

collage

A tool for creating and sharing digital media collages online
JavaScript
1
star
65

idyll-slideshow-draft

Basic starter for idyll slideshows
JavaScript
1
star
66

state-adjacency

A function that returns adjacent states
JavaScript
1
star
67

idyll-animation-article

How to use CSS animations and custom tweening to animate elements in Idyll.
JavaScript
1
star
68

chartographer

Make data-driven maps in your browser.
JavaScript
1
star
69

idyll-fixed-scroll

Demo repo for fixed scroller component in idyll
JavaScript
1
star
70

mathisonian-web

The website that powers http://www.mathisonian.com
JavaScript
1
star
71

whisprabbit-android

Java
1
star
72

twitch-experiments

code written while streaming on twitch
JavaScript
1
star
73

scaffolding-interactives

Idyll walkthrough scrollers + steppers
JavaScript
1
star
74

strata-singapore-004-real-world

1
star
75

nested-extent

d3.extent for nested data structures
JavaScript
1
star
76

bezy.ai

Experiments with machine learning and bezier curves
JavaScript
1
star
77

announcing-idyll-pub

JavaScript
1
star
78

spot-light-nightlight

Code to power an interactive nightlight with arduino
C
1
star
79

lightning-dendrite-viewer

WIP - lightning plugin to display movies in 3d space, useful for viewing dendrites
JavaScript
1
star
80

gulp-export

module.export the contents of a file
JavaScript
1
star
81

yobot

node.js library for building bots on yo.app
JavaScript
1
star
82

leaflet.freedraw-browserify

browserify/commonjs version of leaflet.freedraw
JavaScript
1
star
83

idyll-chartjs-example

Idyll chartjs example
JavaScript
1
star
84

sass-boilerplate

CSS
1
star
85

whisprabbit-web

JavaScript
1
star
86

idyll-dynamic-data

Tutorial for dynamically loading data into idyll
JavaScript
1
star
87

nn-view

[WIP] Quickly generate architecture diagrams of PyTorch or Keras models in a notebook.
JavaScript
1
star
88

connect-maybe-login

Set correct session parameters for node pages that can have both logged in & logged out users
JavaScript
1
star
89

idyll-map-example

Idyll + Mapbox
JavaScript
1
star