{"id":24995393,"url":"https://github.com/compolabs/spark-orderbook-ts-sdk","last_synced_at":"2026-01-02T00:19:10.536Z","repository":{"id":177354358,"uuid":"645110308","full_name":"compolabs/spark-orderbook-ts-sdk","owner":"compolabs","description":null,"archived":false,"fork":false,"pushed_at":"2024-11-06T12:26:10.000Z","size":3811,"stargazers_count":8,"open_issues_count":3,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-15T15:43:26.906Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/compolabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2023-05-25T00:24:12.000Z","updated_at":"2024-11-06T12:26:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"9b0ed97a-f457-4805-8fbe-4430d670eec9","html_url":"https://github.com/compolabs/spark-orderbook-ts-sdk","commit_stats":null,"previous_names":["compolabs/spark-ts-sdk","compolabs/spark-orderbook-ts-sdk"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compolabs%2Fspark-orderbook-ts-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compolabs%2Fspark-orderbook-ts-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compolabs%2Fspark-orderbook-ts-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compolabs%2Fspark-orderbook-ts-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/compolabs","download_url":"https://codeload.github.com/compolabs/spark-orderbook-ts-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248514221,"owners_count":21116903,"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":"2025-02-04T15:37:38.020Z","updated_at":"2026-01-02T00:19:10.510Z","avatar_url":"https://github.com/compolabs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# spark-orderbook-ts-sdk\n\n\u003e [!IMPORTANT]\n\u003e Please note that the current version of the Spark SDK is a beta release. This version is still under active development and may not be stable. Users should expect frequent updates and changes as we work to improve functionality and address issues. As a beta product, this version is intended for testing and feedback purposes only. We encourage users to provide feedback as it will help us refine and enhance the SDK in preparation for a more stable release.\n\n## Introduction\n\nThe spark-orderbook-ts-sdk is a comprehensive solution for interacting with financial markets, offering spot trading functionality. It's built on the Fuels platform, utilizing smart contracts for decentralized transaction processing. This library provides easy-to-use methods for creating and managing orders, handling tokens, and retrieving market data.\n\n## Installation\nTo install the spark-orderbook-ts-sdk, follow these steps:\n\n```bash\nnpm i @compolabs/spark-orderbook-ts-sdk\n```\n\n## Usage\n\nFor the latest usage examples, refer to the `examples` folder.\n\n---\n\n### Folder Structure\n\nThe `examples` folder includes the following files:\n\n- **`config.json`**: Configuration file for the SDK.\n- **`read.ts`**: Demonstrates how to fetch data such as orders, trade volume, and trade events.\n- **`write.ts`**: Includes examples for minting tokens, depositing, creating orders, and canceling orders.\n- **`utils.ts`**: Provides reusable functions for initializing the SDK with the proper configuration.\n\n### Notes\n\n1. **Configuration File**:  \n   Ensure the `config.json` file contains accurate data. Outdated configurations may cause errors. The latest version of the configuration file can always be found [here](https://github.com/compolabs/spark-frontend-config).\n\n2. **React Compatibility**:  \n   Some subscription methods work only in React. Check comments in the `read.ts` file for details.\n\n3. **Wallet Requirement**:  \n   For write operations, ensure your wallet has sufficient ETH to send transactions.\n\n4. **Examples First**:  \n   Always refer to the `read.ts` and `write.ts` files in the `examples` folder for the latest implementation patterns.\n\n---\n\n## Quick Start\n\n### 1. Setup\n\nTo use the SDK, you need to initialize a `SparkOrderbook` instance. Check the implementation in `utils.ts`.\n\n```typescript\nimport { Provider, Wallet } from \"fuels\";\nimport SparkOrderbook, { Asset } from \"../src\";\nimport CONFIG from \"./config.json\";\n\nexport async function initializeSparkOrderbook(wallet?: Wallet) {\n  const provider = await Provider.create(CONFIG.networkUrl);\n  const walletProvider = wallet ?? Wallet.generate({ provider });\n\n  const spark = new SparkOrderbook({\n    networkUrl: CONFIG.networkUrl,\n    contractAddresses: CONFIG.contracts,\n    wallet: walletProvider,\n  });\n\n  spark.setActiveMarket(CONFIG.markets[0].contractId, CONFIG.indexers[CONFIG.markets[0].contractId]);\n  return spark;\n}\n```\n\n### 2. Read Operations\n\nThe `read.ts` file contains examples for fetching and subscribing to market data:\n\n```typescript\nimport SparkOrderbook, { OrderType } from \"../src\";\nimport { initializeSparkOrderbook } from \"./utils\";\n\nasync function main() {\n  const spark = await initializeSparkOrderbook();\n\n  // Fetch active buy orders\n  await spark.fetchActiveOrders(OrderType.Buy, [\"defaultMarket\"], 10);\n\n  // Fetch trade volume\n  await spark.fetchVolume({\n    limit: 100,\n    market: [\"defaultMarket\"],\n  });\n}\n```\n\n### 3. Write Operations\n\nThe `write.ts` file provides examples for write operations like creating and canceling orders:\n\n```typescript\nimport SparkOrderbook, { OrderType } from \"../src\";\nimport { initializeSparkOrderbook } from \"./utils\";\n\nconst PRIVATE_KEY = \"your-private-key\"; // ⚠️ NEVER SHARE YOUR PRIVATE KEY ⚠️\n\nasync function main() {\n  const spark = await initializeSparkOrderbook(Wallet.fromPrivateKey(PRIVATE_KEY));\n\n  // Create a buy order\n  await spark.createOrder({\n    amount: \"0.01\",\n    price: \"7000000000000\",\n    type: OrderType.Buy,\n  });\n\n  // Cancel an order\n  await spark.cancelOrder(\"orderId\");\n}\n```\n\n## Contributing\n\nContributions to improve the spark-orderbook-ts-sdk are welcome. Please feel free to fork the repository, make your changes, and submit a pull request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcompolabs%2Fspark-orderbook-ts-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcompolabs%2Fspark-orderbook-ts-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcompolabs%2Fspark-orderbook-ts-sdk/lists"}