{"id":22608927,"url":"https://github.com/bitfinexcom/bfx-api-node-models","last_synced_at":"2025-03-23T08:06:23.150Z","repository":{"id":33131126,"uuid":"145868116","full_name":"bitfinexcom/bfx-api-node-models","owner":"bitfinexcom","description":null,"archived":false,"fork":false,"pushed_at":"2024-09-17T10:37:46.000Z","size":1697,"stargazers_count":12,"open_issues_count":18,"forks_count":29,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-12T02:04:03.191Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bitfinexcom.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-23T14:51:38.000Z","updated_at":"2024-09-17T10:37:50.000Z","dependencies_parsed_at":"2024-06-18T15:36:43.133Z","dependency_job_id":"352987a7-29a2-4600-8b0a-a433a9850e13","html_url":"https://github.com/bitfinexcom/bfx-api-node-models","commit_stats":{"total_commits":291,"total_committers":16,"mean_commits":18.1875,"dds":0.6494845360824743,"last_synced_commit":"94eb4a7a1dd3baeda8c49a21b1e4733429de96d2"},"previous_names":[],"tags_count":46,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitfinexcom%2Fbfx-api-node-models","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitfinexcom%2Fbfx-api-node-models/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitfinexcom%2Fbfx-api-node-models/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitfinexcom%2Fbfx-api-node-models/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitfinexcom","download_url":"https://codeload.github.com/bitfinexcom/bfx-api-node-models/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244341099,"owners_count":20437573,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-08T15:10:06.847Z","updated_at":"2025-03-23T08:06:23.124Z","avatar_url":"https://github.com/bitfinexcom.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bitfinex Data Models for Node.JS\n\n[![Build Status](https://travis-ci.org/bitfinexcom/bfx-api-node-models.svg?branch=master)](https://travis-ci.org/bitfinexcom/bfx-api-node-models)\n\nThis repo contains model classes for working with the data structures returned by the Bitfinex REST \u0026 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.\n\nSome models, such as `Order` and `OrderBook` provide higher level methods which operate on the underlying data sets.\n\nAll models provide `serialize()` and `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).\n\n### Features\n\n* Convert between array, object, and class representations of API data\n* Class methods for operating on model data where applicable (i.e. `OrderBook`)\n\nClasses for the following Bitfinex API data types:\n* Alert\n* BalanceInfo\n* Candle\n* Currency\n* FundingCredit\n* FundingInfo\n* FundingLoan\n* FundingOffer\n* FundingTickerHist\n* FundingTicker\n* FundingTrade\n* LedgerEntry\n* Liquidations\n* MarginInfo\n* Movement\n* Notification\n* OrderBook\n* Order\n* Position\n* PublicTrade\n* StatusMessagesDeriv\n* Trade\n* TradingTicker\n* TradingTickerHist\n* UserInfo\n* Wallet\n* WalletHist\n* Currency\n* SymbolDetails\n* TransactionFee\n* AccountSummary\n* AuthPermission\n\n### Installation\n\n```js\nnpm i --save bfx-api-node-models\n```\n\n### Quickstart\n\n```js\nconst { Order } = require('bfx-api-node-models')\n\nconst o = new Order({\n  cid: Date.now(),\n  symbol: 'tBTCUSD',\n  price: 7000.0,\n  amount: -0.02,\n  type: Order.type.EXCHANGE_LIMIT\n})\n\n// Generate an API-compatible order creation packet for later submit\nconsole.log(o.toNewOrderPacket())\n```\n\n### Docs\n\nRefer to the [docs/](https://cdn.statically.io/gh/bitfinexcom/bfx-api-node-models/master/docs/index.html)\nfolder for JSDoc-generated API documentation covering each model class.\n\n### Examples\n\nThe 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.\n\nOrders are matched with their API packets by one/all of `id`, `gid`, and `cid`.\n\nExample usage:\n```js\nconst { Order } = require('bfx-api-node-models')\nconst ws = ... // setup WSv2 instance for order updates/submission\n\n// Build new order\nconst o = new Order({\n  cid: Date.now(),\n  symbol: 'tBTCUSD',\n  price: 7000.0,\n  amount: -0.02,\n  type: Order.type.EXCHANGE_LIMIT\n}, ws) // note WSv2 client passed in here\n\nlet closed = false\n\n// Enable automatic updates\no.registerListeners()\n\no.on('update', () =\u003e {\n  debug('order updated: %j', o.serialize())\n})\n\no.on('close', () =\u003e {\n  debug('order closed: %s', o.status)\n  closed = true\n})\n\ndebug('submitting order %d', o.cid)\n\no.submit().then(() =\u003e {\n  debug('got submit confirmation for order %d [%d]', o.cid, o.id)\n}).catch((err) =\u003e {\n  debug('failed to submit order: %s', err.message)\n})\n```\n\nThe 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 `updateWidth(entry)`.\n\nStatic helpers are also provided for working with array-format order books, in the form of `updateArrayOBWith(ob, entry, raw)`, `arrayOBMidPrice(ob, raw)`, and `checksumArr(ob, raw)`.\n\nChecksums may be calculated for normal books via `checksum()`, for comparison with the checksums reported by the WSv2 API.\n\nExample usage:\n```js\nconst ob = new OrderBook([\n  [140, 1, 10],\n  [145, 1, 10],\n  [148, 1, 10],\n  [149, 1, 10],\n  [151, 1, -10],\n  [152, 1, -10],\n  [158, 1, -10],\n  [160, 1, -10]\n])\n\nob.updateWith([145, 3, 15]) // update bid\nob.updateWith([158, 3, -15]) // update ask\n\nconsole.log(ob.serialize())\n```\n\n### Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitfinexcom%2Fbfx-api-node-models","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitfinexcom%2Fbfx-api-node-models","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitfinexcom%2Fbfx-api-node-models/lists"}