{"id":22609003,"url":"https://github.com/bitfinexcom/bitfinex-api-node","last_synced_at":"2025-04-08T04:10:34.867Z","repository":{"id":1617758,"uuid":"43330851","full_name":"bitfinexcom/bitfinex-api-node","owner":"bitfinexcom","description":"BITFINEX NodeJS trading API - Bitcoin, Litecoin, and Ether exchange","archived":false,"fork":false,"pushed_at":"2023-10-02T18:33:25.000Z","size":2261,"stargazers_count":460,"open_issues_count":65,"forks_count":213,"subscribers_count":41,"default_branch":"master","last_synced_at":"2024-05-16T13:42:24.328Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.bitfinex.com/","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}},"created_at":"2015-09-28T22:34:54.000Z","updated_at":"2024-05-16T13:42:24.329Z","dependencies_parsed_at":"2023-10-20T18:27:17.033Z","dependency_job_id":null,"html_url":"https://github.com/bitfinexcom/bitfinex-api-node","commit_stats":{"total_commits":833,"total_committers":42,"mean_commits":"19.833333333333332","dds":0.5594237695078031,"last_synced_commit":"be6596c8208826cb916091158dd57f0757347a23"},"previous_names":[],"tags_count":42,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitfinexcom%2Fbitfinex-api-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitfinexcom%2Fbitfinex-api-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitfinexcom%2Fbitfinex-api-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitfinexcom%2Fbitfinex-api-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitfinexcom","download_url":"https://codeload.github.com/bitfinexcom/bitfinex-api-node/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247773719,"owners_count":20993639,"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:32.855Z","updated_at":"2025-04-08T04:10:34.852Z","avatar_url":"https://github.com/bitfinexcom.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bitfinex WSv2 Trading API for Node.JS - Bitcoin, Ethereum, Ripple and more\n\n[![Build Status](https://travis-ci.org/bitfinexcom/bitfinex-api-node.svg?branch=master)](https://travis-ci.org/bitfinexcom/bitfinex-api-node)\n\nA Node.JS reference implementation of the Bitfinex API\n\n## Features\n\n* Official implementation\n* REST v2 API\n* WebSockets v2 API\n* WebSockets v1 API\n\n## Installation\n\n```bash\n  npm i --save bitfinex-api-node\n```\n\n### Quickstart\n\n```js\nconst { WSv2 } = require('bitfinex-api-node')\nconst ws = new WSv2({ transform: true })\n\n// do something with ws client\n```\n\n### Docs\n\nRefer to the [`docs/`](https://cdn.statically.io/gh/bitfinexcom/bitfinex-api-node/master/docs/index.html)\nfolder for JSDoc-generated HTML documentation, and the [`examples/`](/examples)\nfolder for executable examples covering common use cases.\n\nOfficial API documentation at [https://docs.bitfinex.com/v2/reference](https://docs.bitfinex.com/v2/reference)\n\n### Examples\n\nSending an order \u0026 tracking status:\n\n```js\nconst ws = bfx.ws()\n\nws.on('error', (err) =\u003e console.log(err))\nws.on('open', ws.auth.bind(ws))\n\nws.once('auth', () =\u003e {\n  const o = new Order({\n    cid: Date.now(),\n    symbol: 'tETHUSD',\n    amount: 0.1,\n    type: Order.type.MARKET\n  }, ws)\n\n  // Enable automatic updates\n  o.registerListeners()\n\n  o.on('update', () =\u003e {\n    console.log(`order updated: ${o.serialize()}`)\n  })\n\n  o.on('close', () =\u003e {\n    console.log(`order closed: ${o.status}`)\n    ws.close()\n  })\n\n  o.submit().then(() =\u003e {\n    console.log(`submitted order ${o.id}`)\n  }).catch((err) =\u003e {\n    console.error(err)\n    ws.close()\n  })\n})\n\nws.open()\n```\n\nCancel all open orders\n\n```js\nconst ws = bfx.ws(2)\n\nws.on('error', (err) =\u003e console.log(err))\nws.on('open', ws.auth.bind(ws))\n\nws.onOrderSnapshot({}, (orders) =\u003e {\n  if (orders.length === 0) {\n    console.log('no open orders')\n    return\n  }\n\n  console.log(`recv ${orders.length} open orders`)\n\n  ws.cancelOrders(orders).then(() =\u003e {\n    console.log('cancelled orders')\n  })\n})\n\nws.open()\n```\n\nSubscribe to trades by pair\n\n```js\nconst ws = bfx.ws(2)\n\nws.on('error', (err) =\u003e console.log(err))\nws.on('open', () =\u003e {\n  ws.subscribeTrades('BTCUSD')\n})\n\nws.onTrades({ symbol: 'tBTCUSD' }, (trades) =\u003e {\n  console.log(`trades: ${JSON.stringify(trades)}`)\n})\nws.onTradeEntry({ symbol: 'tBTCUSD' }, (trades) =\u003e {\n  console.log(`te: ${JSON.stringify(trades)}`)\n})\n\nws.open()\n```\n\n## Version 2.0.0 Breaking changes\n\n### constructor takes only an options object now, including the API keys\n\nOld:\n\n```js\nnew BFX(API_KEY, API_SECRET, { version: 2 })\n```\n\nsince 2.0.0:\n\n```js\nnew BFX({ apiKey: '', apiSecret: '' })\n```\n\n### `trade` and `orderbook` snapshots are emitted as nested lists\n\nTo make dealing with snapshots better predictable, snapshots are emitted as an array.\n\n### normalized orderbooks for R0\n\nLists of raw orderbooks (`R0`) are ordered in the same order as `P0`, `P1`,\n`P2`, `P3`\n\n## Testing\n\n```bash\nnpm test\n```\n\n## FAQ\n\n### Order Creation Limits\n\nThe base limit per-user is 1,000 orders per 5 minute interval, and is shared\nbetween all account API connections. It increases proportionally to your trade\nvolume based on the following formula:\n\n`1000 + (TOTAL_PAIRS_PLATFORM * 60 * 5) / (250000000 / USER_VOL_LAST_30d)`\n\nWhere `TOTAL_PAIRS_PLATFORM` is the number of pairs shared between\nEthfinex/Bitfinex (currently ~101) and `USER_VOL_LAST_30d` is in USD.\n\n### 'on' Packet Guarantees\n\nNo; if your order fills immediately, the first packet referencing the order\nwill be an `oc` signaling the order has closed. If the order fills partially\nimmediately after creation, an `on` packet will arrive with a status of\n`PARTIALLY FILLED...`\n\nFor example, if you submit a `LIMIT` buy for 0.2 BTC and it is added to the\norder book, an `on` packet will arrive via ws2. After a partial fill of 0.1\nBTC, an `ou` packet will arrive, followed by a final `oc` after the remaining\n0.1 BTC fills.\n\nOn the other hand, if the order fills immediately for 0.2 BTC, you will only\nreceive an `oc` packet.\n\n### Nonce too small\n\nI make multiple parallel request and I receive an error that the nonce is too\nsmall. What does it mean?\n\nNonces are used to guard against replay attacks. When multiple HTTP requests\narrive at the API with the wrong nonce, e.g. because of an async timing issue,\nthe API will reject the request.\n\nIf you need to go parallel, you have to use multiple API keys right now.\n\n### `te` vs `tu` Messages\n\nA `te` packet is sent first to the client immediately after a trade has been\nmatched \u0026 executed, followed by a `tu` message once it has completed processing.\nDuring times of high load, the `tu` message may be noticably delayed, and as\nsuch only the `te` message should be used for a realtime feed.\n\n### Sequencing\n\nIf you enable sequencing on v2 of the WS API, each incoming packet will have a\npublic sequence number at the end, along with an auth sequence number in the\ncase of channel `0` packets. The public seq numbers increment on each packet,\nand the auth seq numbers increment on each authenticated action (new orders,\netc). These values allow you to verify that no packets have been missed/dropped,\nsince they always increase monotonically.\n\n### Differences Between R* and P* Order Books\n\nOrder books with precision `R0` are considered 'raw' and contain entries for\neach order submitted to the book, whereas `P*` books contain entries for each\nprice level (which aggregate orders).\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%2Fbitfinex-api-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitfinexcom%2Fbitfinex-api-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitfinexcom%2Fbitfinex-api-node/lists"}