Giter Site home page Giter Site logo

anthbs / bitfinex-api-node Goto Github PK

View Code? Open in Web Editor NEW

This project forked from f3rno/bitfinex-api-node

0.0 2.0 0.0 1.96 MB

BITFINEX NodeJS trading API - Bitcoin, Litecoin, and Ether exchange

Home Page: https://www.bitfinex.com/

License: MIT License

JavaScript 100.00%

bitfinex-api-node's Introduction

Bitfinex Trading API for Node.JS. Bitcoin, Ether and Litecoin trading

Build Status

A Node.JS reference implementation of the Bitfinex API. See the full docs at http://bitfinexcom.github.io/bitfinex-api-node/

  • Official implementation
  • REST API
  • WebSockets API

Installation

  npm install bitfinex-api-node

Usage

Version 1.0.0 supports the new v2 Websocket and Rest API. As Network calls are slow, the data is sent as lists.

In order to reconstruct key / value pairs, set opts.transform to true.

const BFX = require('bitfinex-api-node')

const API_KEY = 'secret'
const API_SECRET = 'secret'

const opts = {
  version: 2,
  transform: true
}

const bws = new BFX(API_KEY, API_SECRET, opts).ws

bws.on('auth', () => {
  // emitted after .auth()
  // needed for private api endpoints

  console.log('authenticated')
  // bws.submitOrder ...
})

bws.on('open', () => {
  bws.subscribeTicker('BTCUSD')
  bws.subscribeOrderBook('BTCUSD')
  bws.subscribeTrades('BTCUSD')

  // authenticate
  // bws.auth()
})

bws.on('orderbook', (pair, book) => {
  console.log('Order book:', book)
})

bws.on('trade', (pair, trade) => {
  console.log('Trade:', trade)
})

bws.on('ticker', (pair, ticker) => {
  console.log('Ticker:', ticker)
})

bws.on('error', console.error)

new BFX(API_KEY, API_SECRET, opts)

Where opts can be:

const opts = {
  // use v1 or v2 of the API, values: 1, 2
  version: 2,
  // transform lists for the v2 API. values: true, false, function
  transform: true
}

Version 1.0.0 Breaking changes:

constructor takes an options object now, instead of version number:

Old:

new BFX(API_KEY, API_SECRET, 2)

since 1.0.0:

new BFX(API_KEY, API_SECRET, { version: 2 })

Note version must be of type Number.

trade and orderbook snapshots are emitted as nested lists

To make dealing with snapshots better predictable, snapshots are emitted as an array.

normalized orderbooks for R0

Lists of raw orderbooks (R0) are ordered in the same order as P0, P1, P2, P3

Tests

npm test

FAQ

nonce too small

I make multiple parallel request and I receive an error that the nonce is too small. What does it mean?

Nonces are used to guard against replay attacks. When multiple HTTP requests arrive at the API with the wrong nonce, e.g. because of an async timing issue, the API will reject the request.

If you need to go parallel, you have to use multiple API keys right now.

Contributors

bitfinex-api-node's People

Contributors

acterry avatar androng avatar belfordz avatar cameronlockey avatar dutu avatar joshuarossi avatar maxsvargal avatar mjesuele avatar motocarota avatar prdn avatar robertkowalski avatar silentrob avatar spro avatar tetradeca avatar yagop avatar

Watchers

 avatar  avatar

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.