Bitfinex Data Models for Node.JS
This repo contains model classes for working with the data structures returned by the Bitfinex REST & WebSocket APIs. The models can all be initialized with an array-format payload as returned by an API call, and can be unserialized back to the array format when needed.
Some models, such as
OrderBook provide higher level methods which operate on the underlying data sets.
All models provide
unserialize() methods, which convert to/from array-format payloads respectively. All model constructors can take either array-format payloads, or objects/other model instances. A helper
toJS() method is also provided for converting models to plain JS objects (POJOs).
- Convert between array, object, and class representations of API data
- Class methods for operating on model data where applicable (i.e.
Classes for the following Bitfinex API data types:
npm i --save bfx-api-node-models
const Order =const o =cid: Datesymbol: 'tBTCUSD'price: 70000amount: -002type: OrdertypeEXCHANGE_LIMIT// Generate an API-compatible order creation packet for later submitconsole
Refer to the docs/ folder for JSDoc-generated API documentation covering each model class.
The order model provides helper methods for order submission, updates, and cancellation. These methods are compatible with version 2.0.0 of
bitfinex-api-node, and return promises which resolve upon receival of the relevant success/error notifications.
Orders are matched with their API packets by one/all of
const Order =const ws = ... // setup WSv2 instance for order updates/submission// Build new orderconst o =cid: Datesymbol: 'tBTCUSD'price: 70000amount: -002type: OrdertypeEXCHANGE_LIMITws // note WSv2 client passed in herelet closed = false// Enable automatic updatesoooo
The order book model constructor takes either entire book snapshots as returned by the WSv2 API, or individual update packets with single bids/asks. Once constructed, order books may be updated either with complete snapshots via
updateFromSnapshot(snapshot) or individual update packets via
Static helpers are also provided for working with array-format order books, in the form of
updateArrayOBWith(ob, entry, raw),
arrayOBMidPrice(ob, raw), and
Checksums may be calculated for normal books via
checksum(), for comparison with the checksums reported by the WSv2 API.
const ob =140 1 10145 1 10148 1 10149 1 10151 1 -10152 1 -10158 1 -10160 1 -10ob // update bidob // update askconsole
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create a new Pull Request