{"id":13633109,"url":"https://github.com/tiagosiebler/okx-api","last_synced_at":"2026-01-16T12:26:03.282Z","repository":{"id":50394455,"uuid":"512149325","full_name":"tiagosiebler/okx-api","owner":"tiagosiebler","description":"Node.js SDK for the OKX APIs and WebSockets, with TypeScript \u0026 browser support, integration tests, beautification \u0026 more.","archived":false,"fork":false,"pushed_at":"2026-01-10T11:03:51.000Z","size":12653,"stargazers_count":158,"open_issues_count":4,"forks_count":46,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-01-11T03:31:59.689Z","etag":null,"topics":["okx","okx-api","okx-javascript-api","okx-javascript-sdk","okx-node-api","okx-node-sdk","okx-nodejs-api","okx-sdk","okx-websocket-api","rest","websockets"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/okx-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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":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":"2022-07-09T09:48:52.000Z","updated_at":"2026-01-02T02:47:04.000Z","dependencies_parsed_at":"2024-03-25T14:13:39.791Z","dependency_job_id":"903df44c-94cf-4fcf-98df-7e89e7c17558","html_url":"https://github.com/tiagosiebler/okx-api","commit_stats":{"total_commits":168,"total_committers":12,"mean_commits":14.0,"dds":0.625,"last_synced_commit":"0c946fa1db91a5dd964710440645f91e121f49eb"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/tiagosiebler/okx-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiagosiebler%2Fokx-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiagosiebler%2Fokx-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiagosiebler%2Fokx-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiagosiebler%2Fokx-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tiagosiebler","download_url":"https://codeload.github.com/tiagosiebler/okx-api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiagosiebler%2Fokx-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28478642,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["okx","okx-api","okx-javascript-api","okx-javascript-sdk","okx-node-api","okx-node-sdk","okx-nodejs-api","okx-sdk","okx-websocket-api","rest","websockets"],"created_at":"2024-08-01T23:00:27.853Z","updated_at":"2026-01-16T12:26:03.261Z","avatar_url":"https://github.com/tiagosiebler.png","language":"TypeScript","funding_links":["https://github.com/sponsors/tiagosiebler"],"categories":["Market data libraries"],"sub_categories":[],"readme":"# Node.js \u0026 Typescript OKX (OKEX) API \u0026 WebSocket SDK\n\n[![E2E Tests](https://github.com/tiagosiebler/okx-api/actions/workflows/e2etest.yml/badge.svg?branch=master)](https://github.com/tiagosiebler/okx-api/actions/workflows/e2etest.yml)\n[![npm downloads](https://img.shields.io/npm/dt/okx-api)][1]\n[![npm version](https://img.shields.io/npm/v/okx-api)][1]\n[![npm size](https://img.shields.io/bundlephobia/min/okx-api/latest)][1]\n[![last commit](https://img.shields.io/github/last-commit/tiagosiebler/okx-api)][1]\n[![CodeFactor](https://www.codefactor.io/repository/github/tiagosiebler/okx-api/badge)](https://www.codefactor.io/repository/github/tiagosiebler/okx-api)\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/okx-api\"\u003e\n    \u003cpicture\u003e\n      \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://github.com/tiagosiebler/okx-api/blob/master/docs/images/logoDarkMode2.svg?raw=true#gh-dark-mode-only\"\u003e\n      \u003cimg alt=\"SDK Logo\" src=\"https://github.com/tiagosiebler/okx-api/blob/master/docs/images/logoBrightMode2.svg?raw=true#gh-light-mode-only\"\u003e\n    \u003c/picture\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n[1]: https://www.npmjs.com/package/okx-api\n\nComplete, updated \u0026 performant Node.js SDK for the OKX(OKEX) APIs and WebSockets:\n\n- Complete integration with OKX REST APIs, WebSockets \u0026 WebSocket APIs.\n- TypeScript support (with type declarations for most API requests \u0026 responses).\n- Over 100 end-to-end tests making real API calls \u0026 WebSocket connections, validating any changes before they reach npm.\n- Supports all available OKX regions:\n  - OKX Global (www.okx.com), by default.\n  - OKX EEA (my.okx.com), by setting `market: 'EEA'`.\n  - OKX US (app.okx.com), by setting `market: 'US'`.\n- Actively maintained with a modern, promise-driven interface.\n- Robust WebSocket integration\n  - Configurable connection heartbeats (automatically detect failing connections).\n  - Automatic reconnect then resubscribe workflows.\n  - Automatic authentication and heartbeat handling.\n- Supports WebSocket API in all supported regions \u0026 product groups:\n  - Use the WebsocketClient's event-driven `sendWSAPIRequest()` method, or;\n  - Use the WebsocketAPIClient for a REST-like experience.\n    - Use the WebSocket API like a REST API!\n    - Automatic routing to business vs private WebSocket endpoints.\n    - End to end types.\n    - See [examples/ws-api-client.ts](./examples/ws-api-client.ts) for a demonstration.\n- Browser support (via webpack bundle - see \"Browser Usage\" below).\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Issues \u0026 Discussion](#issues--discussion)\n- [Related Projects](#related-projects)\n- [Documentation](#documentation)\n- [Contributions \u0026 Thanks](#contributions--thanks)\n- [Structure](#structure)\n- [Usage](#usage)\n  - [REST Client](#rest-client)\n    - [Requests \u0026 Responses](#requests--responses)\n    - [Example](#example)\n  - [WebSockets](#websockets)\n    - [Sending Orders via WebSockets](#sending-orders-via-websockets)\n    - [Receiving Realtime Data](#receiving-realtime-data)\n    - [Public Events](#public-events)\n    - [Private Events](#private-events)\n- [Browser/Frontend Usage](#browserfrontend-usage)\n  - [Import](#import)\n  - [Webpack](#webpack)\n- [Use with LLMs \u0026 AI](#use-with-llms--ai)\n- [Contributions \u0026 Pull Requests](#contributions--pull-requests)\n- [Used By](#used-by)\n- [Star History](#star-history)\n\n## Installation\n\n```bash\nnpm install okx-api\n```\n\n## Issues \u0026 Discussion\n\n- Issues? Check the [issues tab](https://github.com/tiagosiebler/okx-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- Follow our announcement channel for real-time updates on [X/Twitter](https://x.com/sieblyio)\n\n\u003c!-- template_related_projects --\u003e\n\n## Related Projects\n\nCheck out our JavaScript/TypeScript/Node.js SDKs \u0026 Projects:\n\n- Visit our website: [https://Siebly.io](https://siebly.io/?ref=gh)\n- Try our REST API \u0026 WebSocket SDKs published on npmjs:\n  - [Bybit Node.js SDK: bybit-api](https://www.npmjs.com/package/bybit-api)\n  - [Kraken Node.js SDK: @siebly/kraken-api](https://www.npmjs.com/package/@siebly/kraken-api)\n  - [OKX Node.js SDK: okx-api](https://www.npmjs.com/package/okx-api)\n  - [Binance Node.js SDK: binance](https://www.npmjs.com/package/binance)\n  - [Gate (gate.com) Node.js SDK: gateio-api](https://www.npmjs.com/package/gateio-api)\n  - [Bitget Node.js SDK: bitget-api](https://www.npmjs.com/package/bitget-api)\n  - [Kucoin Node.js SDK: kucoin-api](https://www.npmjs.com/package/kucoin-api)\n  - [Coinbase Node.js SDK: coinbase-api](https://www.npmjs.com/package/coinbase-api)\n  - [Bitmart Node.js SDK: bitmart-api](https://www.npmjs.com/package/bitmart-api)\n- Try my misc utilities:\n  - [OrderBooks Node.js: orderbooks](https://www.npmjs.com/package/orderbooks)\n  - [Crypto Exchange Account State Cache: accountstate](https://www.npmjs.com/package/accountstate)\n- Check out my examples:\n  - [awesome-crypto-examples Node.js](https://github.com/tiagosiebler/awesome-crypto-examples)\n  \u003c!-- template_related_projects_end --\u003e\n\n## Documentation\n\nMost methods accept JS objects. These can be populated using parameters specified by okx's API documentation, or check the type definition in the rest-client class methods.\n\n- [RestClient](src/rest-client.ts)\n- [OKX API Documentation](https://www.okx.com/docs-v5/en/#rest-api)\n- [REST Endpoint Function List](./docs/endpointFunctionList.md)\n\n## Contributions \u0026 Thanks\n\nSupport my efforts to make algo trading accessible to all - register with my referral links:\n\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- [OKX](https://www.okx.com/join/18504944)\n\nFor more ways to give thanks \u0026 support my efforts, visit [Contributions \u0026 Thanks](https://github.com/tiagosiebler/awesome-crypto-examples/wiki/Contributions-\u0026-Thanks)!\n\n## Structure\n\nThis project uses typescript. Resources are stored in 3 key structures:\n\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. This is also the version published to npm.\n- [dist](./dist) - the packed bundle of the project for use in browser environments (manual, using webpack).\n- [examples](./examples) - some implementation examples \u0026 demonstrations. Contributions are welcome!\n\n---\n\n## Usage\n\nCreate API credentials at okx\n\n- [OKX/account/API](https://www.okx.com/account/my-api)\n\n## REST Client\n\n### Requests \u0026 Responses\n\n- If your IDE doesn't have IntelliSense, check the [rest-client.ts](./src/rest-client.ts) for a list of methods, params \u0026 return types.\n- Requests follow the same ordering and format as the categories in the [API docs](https://www.okx.com/docs-v5/en/#rest-api).\n- Responses are parsed automatically for less nesting. Error responses are thrown in full:\n  - If the response looks successful (HTTP 200 and \"code\" in the response body === \"0\"), only the `data` property is directly (without the `code`, `data` \u0026 `msg` properties).\n  - If the response looks like an error (HTTP error OR the \"code\" property in the response does not equal \"0\"), the full response is thrown (including `code` and `msg` properties). See the interface for [APIResponse\u003cT\u003e](./src/types/rest/shared.ts).\n\n### Example\n\n```ts\nimport { RestClient } from 'okx-api';\n\nconst client = new RestClient({\n  apiKey: 'apiKeyHere',\n  apiSecret: 'apiSecretHere',\n  apiPass: 'apiPassHere',\n  // For Global users (www.okx.com), you don't need to set the market.\n  // It will use global by default.\n  // Not needed: market: 'GLOBAL',\n\n  // For EEA users (my.okx.com), set market to \"EEA\":\n  // market: 'EEA',\n\n  // For US users (app.okx.com), set market to \"US\":\n  // market: 'US',\n});\n\n// Submit a buy and sell market order\n(async () =\u003e {\n  try {\n    const allBalances = await client.getBalance();\n    console.log('All balances: ', allBalances);\n\n    const buyResult = await client.submitOrder({\n      instId: 'BTC-USDT',\n      ordType: 'market',\n      side: 'buy',\n      sz: '0.1',\n      tdMode: 'cash',\n      tgtCcy: 'base_ccy',\n    });\n    console.log('buy order result: ', buyResult);\n\n    const sellResult = await client.submitOrder({\n      instId: 'BTC-USDT',\n      ordType: 'market',\n      side: 'sell',\n      sz: '0.1',\n      tdMode: 'cash',\n      tgtCcy: 'base_ccy',\n    });\n    console.log('Sell order result: ', sellResult);\n  } catch (e) {\n    console.error('request failed: ', e);\n  }\n})();\n```\n\n## WebSockets\n\nThis connector includes a high-performance Node.js, TypeScript \u0026 JavaScript WebSocket client for the OKX public \u0026 private WebSocket, including the OKX WebSocket API for order placement. API credentials are optional unless private streams will be used (such as account order updates).\n\n- If your IDE doesn't have IntelliSense, check the [websocket-client.ts](./src/websocket-client.ts) for a list of methods, params \u0026 return types.\n- When subscribing to channels, only the \"args\" should be passed as an object or array when calling the websocket client subcribe() function: [API docs](https://www.okx.com/docs-v5/en/#websocket-api-subscribe).\n- TypeScript recommended (but it is not required) for a richer experience:\n  ![typescript-subscribe](./docs/images/subscribe-with-typescript.gif)\n- The ws client will automatically open connections as needed when subscribing to a channel.\n- If the connection is lost for any reason, the ws client will detect this (via the connection heartbeats). It will then:\n  - Automatically teardown the dead connection.\n  - Automatically respawn a fresh connection.\n  - Automatically reauthenticate, if using private channels.\n  - Automatically resubscribe to previously subscribed topics.\n  - Resume producing events as before, without extra handling needed in your logic.\n- The ws client will automatically authenticate if accounts are provided and a private channel is subscribed to.\n- Up to 100 accounts are supported on the private connection, as per the [API docs](https://www.okx.com/docs-v5/en/#websocket-api-login). Authentication is automatic if accounts are provided.\n- For examples in using the websocket client, check the examples in the repo:\n  - Private channels (account data): [examples/ws-private.ts](./examples/ws-private.ts)\n  - Public chanels (market data): [examples/ws-public.ts](./examples/ws-public.ts)\n  - These examples are written in TypeScript, so can be executed with ts-node for easy testing:\n    `ts-node examples/ws-private.ts`\n  - Or convert them to javascript:\n    - Change the `import { ... } from 'okx-api'` to `const { ... } = require('okx-api');`\n    - Rename the file to `ws-private.js`\n    - And execute with node: `node examples/ws-private.js`\n\n### Sending orders via WebSockets\n\nOKX supports some order management capabilities via a persisted WebSocket connection. This SDK supports this with two convenient approaches.\n\nThe recommended route is to use the dedicated WebsocketAPIClient class, included with this SDK:\n\n- Dedicated functions for every available WebSocket API operation\n- Fully typed requests and responses\n- Asynchronous promisified wrapper around WS API commands.\n\nIt looks \u0026 feels like a REST API client, but uses WebSockets, via the WebsocketClient's sendWSAPIRequest method (which you can use directly if you prefer).\n\nA simple example is below but for a more thorough example, check the example here: [./examples/ws-api-client.ts](./examples/ws-api-client.ts).\n\n```typescript\nimport { WebsocketAPIClient } from 'okx-api';\n// or if you prefer require:\n// const { WebsocketAPIClient } = require(\"okx-api\");\n\n// For private events, all 3 of the following are required (per account):\nconst API_KEY = process.env.API_KEY_COM;\nconst API_SECRET = process.env.API_SECRET_COM;\nconst API_PASSPHRASE = process.env.API_PASSPHRASE_COM;\n\n// If running from CLI in unix, you can pass env vars as such:\n// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/ws-private.ts\n\nconst wsClient = new WebsocketAPIClient({\n  // For Global users (www.okx.com), you don't need to set the market.\n  // It will use global by default.\n  // Not needed: market: 'GLOBAL',\n\n  // For EEA users (my.okx.com), set market to \"EEA\":\n  // market: 'EEA',\n\n  // For US users (app.okx.com), set market to \"US\":\n  // market: 'US',\n\n  accounts: [\n    {\n      apiKey: API_KEY,\n      apiSecret: API_SECRET,\n      apiPass: API_PASSPHRASE,\n    },\n  ],\n});\n\nasync function start() {\n  // Optional: prepare the WebSocket API connection in advance.\n  // This happens automatically but you can do this early before making any API calls, to prevent delays from a cold start.\n  // await wsClient.connectWSAPI();\n\n  /**\n   * OKX's WebSocket API be used like a REST API, through this SDK's WebsocketAPIClient. The WebsocketAPIClient is a utility class wrapped around WebsocketClient's sendWSAPIRequest() capabilities.\n   *\n   * Each request sent via the WebsocketAPIClient will automatically:\n   * - route via the active WS API connection\n   * - return a Promise, which automatically resolves/rejects when a matching response is received\n   */\n\n  /**\n   * Place Order\n   * https://www.okx.com/docs-v5/en/#order-book-trading-trade-ws-place-order\n   */\n  try {\n    const res = await wsClient.submitNewOrder({\n      instId: 'BTC-USDT',\n      tdMode: 'cash',\n      side: 'buy',\n      ordType: 'market',\n      sz: '100',\n    });\n    /**\n      const res = {\n        id: '2',\n        op: 'order',\n        code: '1',\n        msg: '',\n        data: [\n          {\n            tag: '159881cb7207BCDE',\n            ts: '1753714603721',\n            ordId: '',\n            clOrdId: '',\n            sCode: '51008',\n            sMsg: 'Order failed. Insufficient USDT balance in account.'\n          }\n        ],\n        inTime: '1753714603720755',\n        outTime: '1753714603721942',\n        wsKey: 'prodPrivate',\n        isWSAPIResponse: false\n      }\n\n      const res =  {\n        id: '2',\n        op: 'order',\n        code: '1',\n        msg: '',\n        data: [\n          {\n            tag: '159881cb7207BCDE',\n            ts: '1753714567149',\n            ordId: '',\n            clOrdId: '',\n            sCode: '51010',\n            sMsg: \"You can't complete this request under your current account mode.\"\n          }\n        ],\n        inTime: '1753714567149196',\n        outTime: '1753714567149913',\n        wsKey: 'prodPrivate',\n        isWSAPIResponse: false\n      }\n     */\n\n    console.log(new Date(), 'WS API \"submitNewOrder()\" result: ', res);\n  } catch (e) {\n    console.error(new Date(), 'Exception with WS API \"submitNewOrder()\": ', e);\n  }\n\n  /**\n   * Submit multiple orders in a batch\n   * https://www.okx.com/docs-v5/en/#order-book-trading-trade-ws-place-multiple-orders\n   */\n  try {\n    const res = await wsClient.submitMultipleOrders([\n      {\n        instId: 'BTC-USDT',\n        tdMode: 'cash',\n        side: 'buy',\n        ordType: 'market',\n        sz: '100',\n      },\n      {\n        instId: 'BTC-USDT',\n        tdMode: 'cash',\n        side: 'buy',\n        ordType: 'market',\n        sz: '50',\n      },\n    ]);\n    console.log(new Date(), 'WS API \"submitMultipleOrders()\" result: ', res);\n  } catch (e) {\n    console.error(\n      new Date(),\n      'Exception with WS API \"submitMultipleOrders()\": ',\n      e,\n    );\n  }\n}\n\nstart();\n```\n\n### Receiving realtime data\n\nThe below example demonstrates connecting as a consumer, to receive WebSocket events from OKX, using the included WebsocketClient:\n\n```javascript\nimport { WebsocketClient } from 'okx-api';\n// or if you prefer require:\n// const { WebsocketClient } = require(\"okx-api\");\n\n// For private events, all 3 of the following are required (per account):\nconst API_KEY = process.env.API_KEY_COM;\nconst API_SECRET = process.env.API_SECRET_COM;\nconst API_PASSPHRASE = process.env.API_PASSPHRASE_COM;\n\n// If running from CLI in unix, you can pass env vars as such:\n// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/ws-private.ts\n\n// Note the single quotes, preventing special characters such as $ from being incorrectly passed\n\nconst wsClient = new WebsocketClient({\n  // For Global users (www.okx.com), you don't need to set the market.\n  // It will use global by default.\n  // Not needed: market: 'GLOBAL',\n\n  // For EEA users (my.okx.com), set market to \"EEA\":\n  // market: 'EEA',\n\n  // For US users (app.okx.com), set market to \"US\":\n  // market: 'US',\n\n  accounts: [\n    // For private topics, include one or more accounts in an array. Otherwise only public topics will work\n    {\n      apiKey: API_KEY,\n      apiSecret: API_SECRET,\n      apiPass: API_PASSPHRASE,\n    },\n    // {\n    //   apiKey: 'yourApiKeyHere',\n    //   apiSecret: 'yourApiSecretHere',\n    //   apiPass: 'yourApiPassHere',\n    // },\n    // {\n    //   apiKey: 'anotherAccountKey',\n    //   apiSecret: 'anotherAccountSecret',\n    //   apiPass: 'anotherAccountPass',\n    // },\n  ],\n});\n\n// Raw data will arrive on the 'update' event\nwsClient.on('update', (data) =\u003e {\n  console.log('ws update (raw data received)', JSON.stringify(data));\n});\n\nwsClient.on('open', (data) =\u003e {\n  console.log('connection opened open:', data.wsKey);\n});\n\n// Replies (e.g. authenticating or subscribing to channels) will arrive on the 'response' event\nwsClient.on('response', (data) =\u003e {\n  // console.log('ws response: ', JSON.stringify(data, null, 2));\n  console.log('ws response: ', JSON.stringify(data));\n});\n\nwsClient.on('reconnect', ({ wsKey }) =\u003e {\n  console.log('ws automatically reconnecting.... ', wsKey);\n});\nwsClient.on('reconnected', (data) =\u003e {\n  console.log('ws has reconnected ', data?.wsKey);\n});\nwsClient.on('exception', (data) =\u003e {\n  console.error('ws exception: ', data);\n});\n\n/**\n * Simply call subscribe to request the channels that you're interested in.\n *\n * If authentication is required, the WSClient will automatically authenticate with the available credentials.\n */\n\n// Subscribe one event at a time:\nwsClient.subscribe({\n  channel: 'account',\n});\n\n// OR, combine multiple subscription events into one request using an array instead of an object:\nwsClient.subscribe([\n  {\n    channel: 'account',\n  },\n  {\n    channel: 'positions',\n    instType: 'ANY',\n  },\n]);\n\n// Public topics, for comparison. These do not require authentication / api keys:\nwsClient.subscribe([\n  {\n    channel: 'instruments',\n    instType: 'SPOT',\n  },\n  {\n    channel: 'instruments',\n    instType: 'FUTURES',\n  },\n  {\n    channel: 'tickers',\n    instId: 'LTC-BTC',\n  },\n]);\n```\n\n#### Public Events\n\nSee [examples/ws-public.ts](./examples/ws-public.ts) for a full example:\n\n![typescript-events-public](./docs/images/subscribe-events-public.gif)\n\n#### Private Events\n\nSee [examples/ws-private.ts](./examples/ws-private.ts) for a full example:\n\n![typescript-events](./docs/images/subscribe-events.gif)\n\n## Browser/Frontend Usage\n\n### Import\n\nThis is the \"modern\" way, allowing the package to be directly imported into frontend projects with full typescript support.\n\n1. Install these dependencies\n   ```sh\n   npm install crypto-browserify stream-browserify\n   ```\n2. Add this to your `tsconfig.json`\n   ```json\n   {\n     \"compilerOptions\": {\n       \"paths\": {\n         \"crypto\": [\n           \"./node_modules/crypto-browserify\"\n         ],\n         \"stream\": [\n           \"./node_modules/stream-browserify\"\n         ]\n   }\n   ```\n3. Declare this in the global context of your application (ex: in polyfills for angular)\n   ```js\n   (window as any).global = window;\n   ```\n\n### Webpack\n\nThis is the \"old\" way of using this package on webpages. This will build a minified js bundle that can be pulled in using a script tag on a website.\n\nBuild a bundle using webpack:\n\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## Use with LLMs \u0026 AI\n\nThis SDK includes a bundled `llms.txt` file in the root of the repository. If you're developing with LLMs, use the included `llms.txt` with your LLM - it will significantly improve the LLMs understanding of how to correctly use this SDK.\n\nThis file contains AI optimised structure of all the functions in this package, and their parameters for easier use with any learning models or artificial intelligence.\n\n---\n\n\u003c!-- template_contributions --\u003e\n\n### Contributions \u0026 Thanks\n\nHave my projects helped you? Share the love, there are many ways you can show your thanks:\n\n- Star \u0026 share my projects.\n- Are my projects useful? Sponsor me on Github and support my effort to maintain \u0026 improve them: https://github.com/sponsors/tiagosiebler\n- Have an interesting project? Get in touch \u0026 invite me to it.\n- Or buy me all the coffee:\n  - ETH(ERC20): `0xA3Bda8BecaB4DCdA539Dc16F9C54a592553Be06C` \u003c!-- metamask --\u003e\n- Sign up with my referral links:\n  - OKX (receive a 20% fee discount!): https://www.okx.com/join/42013004\n  - Binance (receive a 20% fee discount!): https://accounts.binance.com/register?ref=OKFFGIJJ\n  - HyperLiquid (receive a 4% fee discount!): https://app.hyperliquid.xyz/join/SDK\n  - Gate: https://www.gate.io/signup/NODESDKS?ref_type=103\n\n\u003c!---\nold ones:\n  - BTC: `1C6GWZL1XW3jrjpPTS863XtZiXL1aTK7Jk`\n  - BTC(SegWit): `bc1ql64wr9z3khp2gy7dqlmqw7cp6h0lcusz0zjtls`\n  - ETH(ERC20): `0xe0bbbc805e0e83341fadc210d6202f4022e50992`\n  - USDT(TRC20): `TA18VUywcNEM9ahh3TTWF3sFpt9rkLnnQa\n  - gate: https://www.gate.io/signup/AVNNU1WK?ref_type=103\n\n--\u003e\n\u003c!-- template_contributions_end --\u003e\n\n## Contributions \u0026 Pull Requests\n\nContributions are encouraged, I will review any incoming pull requests. See the issues tab for todo items.\n\n## Used By\n\nThe following represents some of the known public projects that use this SDK on GitHub:\n\n[![Repository Users Preview Image](https://dependents.info/tiagosiebler/okx-api/image)](https://github.com/tiagosiebler/okx-api/network/dependents)\n\n\u003c!-- template_star_history --\u003e\n\n## Star History\n\n[![Star History Chart](https://api.star-history.com/svg?repos=tiagosiebler/bybit-api,tiagosiebler/okx-api,tiagosiebler/binance,tiagosiebler/bitget-api,tiagosiebler/bitmart-api,tiagosiebler/gateio-api,tiagosiebler/kucoin-api,tiagosiebler/coinbase-api,tiagosiebler/orderbooks,tiagosiebler/accountstate,tiagosiebler/awesome-crypto-examples\u0026type=Date)](https://star-history.com/#tiagosiebler/bybit-api\u0026tiagosiebler/okx-api\u0026tiagosiebler/binance\u0026tiagosiebler/bitget-api\u0026tiagosiebler/bitmart-api\u0026tiagosiebler/gateio-api\u0026tiagosiebler/kucoin-api\u0026tiagosiebler/coinbase-api\u0026tiagosiebler/orderbooks\u0026tiagosiebler/accountstate\u0026tiagosiebler/awesome-crypto-examples\u0026Date)\n\n\u003c!-- template_star_history_end --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftiagosiebler%2Fokx-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftiagosiebler%2Fokx-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftiagosiebler%2Fokx-api/lists"}