Giter Club home page Giter Club logo

trader.nodejs's Introduction

node.js trading library for Bitfloor and MtGox

The library is written using a typical node.js event/callback approach. See below for quick usage and the 'examples' directory for more detailed examples. All of the APIs described below are a work in progress and being actively developed. Suggestions are welcome.

##Install##

npm install git://github.com/bitfloor/trader.nodejs.git

##Market Data##

To receive market data all you have to do is use the book builder to create a book for the exchange you want. Level updates will emit events.

var book_builder = require('btctrader').books;

// we can ask the book builder to create a book of any supported type
// as long as the returned book object emits the right events it will work
var bitfloor_book = book_builder.build({
    // common options
    exchange: 'bitfloor', // bitfloor or mtgox
    protocol: 'rest', // only 'rest' is supported for now
    depth: 'L1', // only L1 is supported for now

    // exchange specific
    host: 'api.bitfloor.com',
    product: 1,
});

// errors will be emitted to the typical error event
bitfloor_book.on('error', function(err) {
});

// the L1 book emits a 'changed' event when there is an update
book.on('changed', function(details) {
    details.side; // 0 for BID, 1 for ASK
    details.size; // amount
    details.price; // price
});

##Order Entry##

Setup to enter orders is very similar to the book builder. You initialize a trader for the given exchange. Below is an example for a basic REST based trader.

var trader_builder = require('btctrader').traders;

var trader = trader_builder.build({
    exchange: 'bitfloor',

    // exchange specific
    protocol: 'rest',
    host: 'api.bitfloor.com',
    sec_key: ..., // your bitfloor sec key
    api_key: ..., // your bitfloor api key
});

// send a new order to the exchange
var details = {
    side: 0, // 0 for buy, 1 for sell
    size: 0.0, // amount
    price: 0.0, // price
    product_id: 1, // exchange specific product id
}

trader.new_order(details, function(response) {
});

// cancel an order
var details = {
    order_id: '', // exchange specified order id
    product_id: 1, // exchange specific product id
}

trader.cancel_order = function(details, response) {
});

trader.nodejs's People

Contributors

defunctzombie avatar markstreich avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

trader.nodejs's Issues

can't run examples

Hi,
I'm not able to run examples.

Maybe it depends on the node version

adva-mbp:examples advanced$ node market_data.js 

module.js:356
  Module._extensions[extension](this, filename);
                               ^
Error: Symbol microtime_module not found.
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/advanced/Dropbox/playground/node bitcoin trader/node_modules/btctrader/node_modules/microtime/index.js:9:24)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

Compile issue during npm install

I ran into an issue while trying to install the btctrader (trader.nodejs) module. When npm tries to compile node-decimal it fails with an error and the whole process aborts. I took a look at the node-decimal project on github and noticed in their readme the following line:

You will need libgmp3 development package installed to install node-decimal. On debian systems this is the libgmp3-dev package

I'm using Ubuntu so I installed the libgmp3-dev package using the following command which fixed the problem for me:

sudo apt-get install libgmp3-dev

I wanted to take time to post this here in the issues for this project in case anyone else runs into this problem.

Error on dlopen - Incompatibility with binaries?

Hi guys,

First off, thanks for the killer work on Bitfloor. It's by far the friendliest and most accessible way to buy Bitcoins that I've experienced. Absolutely delightful.

I'm having a little trouble with the API. I think there may be a compatibility issue with the module build and my hardware (OSX 10.7.4 Lion). I'm pasting the console log below, including diagnostic info at the end. It looks like you're using Waf in the build process, so it may be related to nodejs/node-v0.x-archive#3633?

Let me know what you think. Many thanks.

Jen

jen:examples jenrobinson$ node market_data.js

module.js:485
  process.dlopen(filename, module.exports);
          ^
Error: dlopen(/Users/jenrobinson/Sites/btc/node_modules/btctrader/node_modules/microtime/build/Release/microtime.node, 1): no suitable image found.  Did find:
    /Users/jenrobinson/Sites/btc/node_modules/btctrader/node_modules/microtime/build/Release/microtime.node: mach-o, but wrong architecture
    at Object.Module._extensions..node (module.js:485:11)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Object.<anonymous> (/Users/jenrobinson/Sites/btc/node_modules/btctrader/node_modules/microtime/index.js:9:24)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
jen:examples jenrobinson$ node -pe process.arch
x64
jen:examples jenrobinson$ lipo -info /Users/jenrobinson/Sites/btc/node_modules/btctrader/node_modules/microtime/build/Release/microtime.node
Non-fat file: /Users/jenrobinson/Sites/btc/node_modules/btctrader/node_modules/microtime/build/Release/microtime.node is architecture: i386

Here's the log from my installation:

jen:btc jenrobinson$ npm install git://github.com/bitfloor/trader.nodejs.git
npm http GET https://registry.npmjs.org/microtime/0.2.0
npm http GET https://registry.npmjs.org/colors/0.6.0-1
npm http GET https://registry.npmjs.org/num/0.1.2
npm http 304 https://registry.npmjs.org/colors/0.6.0-1
npm http 304 https://registry.npmjs.org/microtime/0.2.0
npm http 304 https://registry.npmjs.org/num/0.1.2

> [email protected] install /Users/jenrobinson/Sites/btc/node_modules/btctrader/node_modules/microtime
> node-waf configure build

npm http GET https://registry.npmjs.org/int/0.1.0
Checking for program g++ or c++          : /usr/bin/g++ 
Checking for program cpp                 : /usr/bin/cpp 
Checking for program ar                  : /usr/bin/ar 
Checking for program ranlib              : /usr/bin/ranlib 
Checking for g++                         : ok  
Checking for node path                   : ok /usr/local/bin/node 
Checking for node prefix                 : ok /usr/local 
'configure' finished successfully (0.058s)
Waf: Entering directory `/Users/jenrobinson/Sites/btc/node_modules/btctrader/node_modules/microtime/build'
[1/2] cxx: src/microtime.cc -> build/Release/src/microtime_1.o
npm http 304 https://registry.npmjs.org/int/0.1.0
[2/2] cxx_link: build/Release/src/microtime_1.o -> build/Release/microtime.node
Waf: Leaving directory `/Users/jenrobinson/Sites/btc/node_modules/btctrader/node_modules/microtime/build'
'build' finished successfully (0.264s)
[email protected] node_modules/btctrader
├── [email protected]
├── [email protected] ([email protected])
└── [email protected]

Market Data example fails

Running node v0.10.4 and microtime 0.3.3. Checked out the code.

$ npm examples/market_data.js

~/trader.nodejs/lib/books/mtgox_rest.js:45
    maybe_update(0, bid, book.bids[book.bids.length - 1]);
                                            ^
TypeError: Cannot read property 'length' of undefined
    at process_new_book (/home/dan/trader.nodejs/lib/books/mtgox_rest.js:45:49)
    at IncomingMessage.<anonymous> (/home/dan/trader.nodejs/lib/books/mtgox_rest.js:68:17)
    at IncomingMessage.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:883:14
    at process._tickCallback (node.js:415:13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.