{"id":13637752,"url":"https://github.com/tiagosiebler/ftx-api","last_synced_at":"2025-04-06T22:12:06.474Z","repository":{"id":39637182,"uuid":"347637248","full_name":"tiagosiebler/ftx-api","owner":"tiagosiebler","description":"Node.js connector for the FTX.com \u0026 FTX.us APIs and WebSockets, with TypeScript \u0026 browser support.","archived":false,"fork":false,"pushed_at":"2023-03-14T15:33:38.000Z","size":772,"stargazers_count":123,"open_issues_count":6,"forks_count":47,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T21:06:44.597Z","etag":null,"topics":["algorithmic-trading","cryptocurrency","cryptocurrency-exchanges","ftx","ftx-apis","ftx-exchange","ftx-websockets","ftxbot","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/ftx-api","language":"TypeScript","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/tiagosiebler.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["tiagosiebler"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2021-03-14T12:57:46.000Z","updated_at":"2025-02-24T21:00:16.000Z","dependencies_parsed_at":"2024-01-12T20:03:48.171Z","dependency_job_id":null,"html_url":"https://github.com/tiagosiebler/ftx-api","commit_stats":{"total_commits":95,"total_committers":15,"mean_commits":6.333333333333333,"dds":0.4842105263157894,"last_synced_commit":"31955e65c386c7e5a43fcf67dbd2daba5e9a451f"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiagosiebler%2Fftx-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiagosiebler%2Fftx-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiagosiebler%2Fftx-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiagosiebler%2Fftx-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tiagosiebler","download_url":"https://codeload.github.com/tiagosiebler/ftx-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247557770,"owners_count":20958047,"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":["algorithmic-trading","cryptocurrency","cryptocurrency-exchanges","ftx","ftx-apis","ftx-exchange","ftx-websockets","ftxbot","typescript"],"created_at":"2024-08-02T01:00:29.178Z","updated_at":"2025-04-06T22:12:06.453Z","avatar_url":"https://github.com/tiagosiebler.png","language":"TypeScript","funding_links":["https://github.com/sponsors/tiagosiebler"],"categories":["TypeScript","Market data libraries"],"sub_categories":[],"readme":"# ftx-api\n[![Tests](https://circleci.com/gh/tiagosiebler/ftx-api.svg?style=shield)](https://circleci.com/gh/tiagosiebler/ftx-api)\n[![npm version](https://img.shields.io/npm/v/ftx-api)][1] [![npm size](https://img.shields.io/bundlephobia/min/ftx-api/latest)][1] [![npm downloads](https://img.shields.io/npm/dt/ftx-api)][1]\n[![last commit](https://img.shields.io/github/last-commit/tiagosiebler/ftx-api)][1]\n[![CodeFactor](https://www.codefactor.io/repository/github/tiagosiebler/ftx-api/badge)](https://www.codefactor.io/repository/github/tiagosiebler/ftx-api)\n\n\n[1]: https://www.npmjs.com/package/ftx-api\n\nNode.js connector for the FTX APIs and WebSockets, with TypeScript \u0026 browser support.\n\n## Installation\n`npm install --save ftx-api`\n\n## Issues \u0026 Discussion\n- Issues? Check the [issues tab](https://github.com/tiagosiebler/ftx-api/issues).\n- Discuss \u0026 collaborate with other node devs? Join our [Node.js Algo Traders](https://t.me/nodetraders) engineering community on telegram.\n\n## Related projects\nCheck out my related projects:\n- Try my connectors:\n  - [binance](https://www.npmjs.com/package/binance)\n  - [bybit-api](https://www.npmjs.com/package/bybit-api)\n  - [okx-api](https://www.npmjs.com/package/okx-api)\n  - [bitget-api](https://www.npmjs.com/package/bitget-api)\n  - [ftx-api](https://www.npmjs.com/package/ftx-api)\n- Try my misc utilities:\n  - [orderbooks](https://www.npmjs.com/package/orderbooks)\n- Check out my examples:\n  - [awesome-crypto-examples](https://github.com/tiagosiebler/awesome-crypto-examples)\n\n## Documentation\nMost methods accept JS objects, except for methods with only one parameter. These can be populated using parameters specified by FTX's API documentation.\n- [FTX REST API Documentation](https://docs.ftx.com/#rest-api).\n- [FTX Websocket API Documentation](https://docs.ftx.com/#websocket-api).\n\n## Structure\nThis project uses typescript. Resources are stored in 3 key structures:\n- [src](./src) - the whole connector written in typescript\n- [lib](./lib) - the javascript version of the project (compiled from typescript). This should not be edited directly, as it will be overwritten with each release.\n- [dist](./dist) - the packed bundle of the project for use in browser environments.\n- [examples](./examples) - demonstrations on various workflows using this library\n\n---\n\n# Usage\nCreate API credentials at FTX\n- [FTX.com](https://ftx.com/#a=ftxapigithub)\n\n## REST API Clients\n\nImport and instance the `RestClient` to access all REST API methods.\n- All methods return promises.\n- Supports subaccounts.\n\n### Example\n\u003cdetails\u003e\u003csummary\u003eTo use the REST APIs, import the `RestClient`. Click here to expand and see full sample:\u003c/summary\u003e\n\n```javascript\nconst { RestClient } = require('ftx-api');\n\nconst restClientOptions = {\n  // override the max size of the request window (in ms)\n  recv_window?: number;\n\n  // how often to sync time drift with FTX servers\n  sync_interval_ms?: number | string;\n\n  // Default: false. Disable above sync mechanism if true.\n  disable_time_sync?: boolean;\n\n  // Default: false. If true, we'll throw errors if any params are undefined\n  strict_param_validation?: boolean;\n\n  // Optionally override API protocol + domain\n  // e.g 'https://ftx.us/api'\n  baseUrl?: string;\n\n  // Default: true. whether to try and post-process request exceptions.\n  parse_exceptions?: boolean;\n\n  // Subaccount nickname URI-encoded\n  subAccountName?: string;\n};\n\nconst API_KEY = 'xxx';\nconst PRIVATE_KEY = 'yyy';\n\nconst client = new RestClient(\n  API_KEY,\n  PRIVATE_KEY,\n\n  // restClientOptions,\n  // requestLibraryOptions\n);\n\nclient.getMarkets()\n  .then(result =\u003e {\n    console.log(\"getMarkets result: \", result);\n  })\n  .catch(err =\u003e {\n    console.error(\"getMarkets error: \", err);\n  });\n\nclient.setAccountLeverage(5)\n  .then(result =\u003e {\n    console.log(\"setAccountLeverage result: \", result);\n  })\n  .catch(err =\u003e {\n    console.error(\"setAccountLeverage error: \", err);\n  });\n```\n\n\u003c/details\u003e\n\nSee [rest-client.ts](./src/rest-client.ts) for further information.\n\n## WebSockets\n- Automatically connect to FTX websockets\n- Automatically authenticate, if key \u0026 secret are provided.\n- Automatically checks connection integrity. If connection stale (no response to pings), automatically reconnects, re-authenticates and resubscribes to previous topics.\n- Supports subaccounts.\n\n\u003cdetails\u003e\u003csummary\u003eWebSocket channels can be subscribed to via the `WebsocketClient`. Click here to expand and see full sample:\u003c/summary\u003e\n\n```javascript\nconst { WebsocketClient } = require('ftx-api');\n\nconst API_KEY = 'xxx';\nconst PRIVATE_KEY = 'yyy';\n\nconst wsConfig = {\n  key: API_KEY,\n  secret: PRIVATE_KEY,\n\n  /*\n    The following parameters are optional:\n  */\n\n  // Subaccount nickname\n  // subAccountName: 'sub1',\n\n  // how long to wait (in ms) before deciding the connection should be terminated \u0026 reconnected\n  // pongTimeout: 1000,\n\n  // how often to check (in ms) that WS connection is still alive\n  // pingInterval: 10000,\n\n  // how long to wait before attempting to reconnect (in ms) after connection is closed\n  // reconnectTimeout: 500,\n\n  // config options sent to RestClient (used for time sync). See RestClient docs.\n  // restOptions: { },\n\n  // config for axios used for HTTP requests. E.g for proxy support\n  // requestOptions: { }\n\n  // override which URL to use for websocket connections\n  // wsUrl: 'wss://example.ftx.com/ws'\n};\n\nconst ws = new WebsocketClient(wsConfig);\n\n// subscribe to multiple topics at once\nws.subscribe(['fills', 'orders']);\n\n// and/or subscribe to individual topics on demand\nws.subscribe('fills');\n\n// and/or subscribe to complex topics on demand, one at a time\nws.subscribe({\n  channel: 'trades',\n  market: 'BTC-PERP'\n});\n\n// or as a list of complex topics\nws.subscribe([\n  {\n    channel: 'trades',\n    market: 'BTC-PERP'\n  },\n  {\n    channel: 'orderbookGrouped',\n    market: 'BTC-PERP',\n    grouping: 500\n  }\n]);\n\n// Listen to events coming from websockets. This is the primary data source\nws.on('update', data =\u003e {\n  console.log('update', data);\n});\n\n// Optional: Listen to websocket connection open event (automatic after subscribing to one or more topics)\nws.on('open', ({ event }) =\u003e {\n  console.log('connection opened');\n});\n\n// Optional: Listen to responses to websocket queries (e.g. the response after subscribing to a topic)\nws.on('response', response =\u003e {\n  console.log('response', response);\n});\n\n// Optional: Listen to connection close event. Unexpected connection closes are automatically reconnected.\nws.on('close', () =\u003e {\n  console.log('connection closed');\n});\n\n// Optional: Listen to raw error events.\n// Note: responses to invalid topics are currently only sent in the \"response\" event.\nws.on('error', err =\u003e {\n  console.error('ERR', err);\n});\n```\n\n\u003c/details\u003e\n\nSee [websocket-client.ts](./src/websocket-client.ts) for further information.\n\n## Examples\n\nMore demonstrations can be found in the [examples](./examples/) folder.\n\n---\n\n## Customise Logging\nPass a custom logger which supports the log methods `silly`, `debug`, `notice`, `info`, `warning` and `error`, or override methods from the default logger as desired.\n\n\u003cdetails\u003e\u003csummary\u003eClick here to expand and see full sample:\u003c/summary\u003e\n\n```javascript\nconst { WebsocketClient, DefaultLogger } = require('ftx-api');\n\n// Disable all logging on the silly level\nDefaultLogger.silly = () =\u003e {};\n\nconst ws = new WebsocketClient(\n  { key: 'xxx', secret: 'yyy' },\n  DefaultLogger\n);\n```\n\n\u003c/details\u003e\n\n## Browser Usage\nBuild a bundle using webpack:\n- `npm install`\n- `npm build`\n- `npm pack`\n\nThe bundle can be found in `dist/`. Altough usage should be largely consistent, smaller differences will exist. Documentation is still TODO.\n\n---\n\n## FTX.US\nThis client also supports the US FTX exchange. Simply set the \"domain\" to \"ftxus\" in both the RestClient and the WebsocketClient. See [examples/ftxus.ts](./examples/ftxus.ts) for a demonstration.\n\n## Contributions \u0026 Thanks\n### Donations\n#### tiagosiebler\nIf you found this project interesting or useful, create accounts with my referral links:\n- [FTX](https://ftx.com/#a=ftxapigithub)\n- [Bybit](https://www.bybit.com/en-US/register?affiliate_id=9410\u0026language=en-US\u0026group_id=0\u0026group_type=1)\n- [Binance](https://www.binance.com/en/register?ref=20983262)\n\nOr buy me a coffee using any of these:\n- BTC: `1C6GWZL1XW3jrjpPTS863XtZiXL1aTK7Jk`\n- ETH (ERC20): `0xd773d8e6a50758e1ada699bb6c4f98bb4abf82da`\n\n### Contributions \u0026 Pull Requests\nContributions are encouraged, I will review any incoming pull requests. See the issues tab for todo items.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftiagosiebler%2Fftx-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftiagosiebler%2Fftx-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftiagosiebler%2Fftx-api/lists"}